def _buildModuleData(self, module, isInstalledInSlot, stats): itemPrice = module.buyPrices.itemPrice inInventory = module.isInInventory isInstalled = module.isInstalled(self._vehicle) isBought = inInventory or isInstalled if module.itemTypeID == GUI_ITEM_TYPE.OPTIONALDEVICE and not isInstalled and module.hasSimilarDevicesInstalled(self._vehicle): isFit, reason = False, GUI_ITEM_ECONOMY_CODE.ITEM_IS_DUPLICATED elif isBought: isFit, reason = module.mayInstall(self._vehicle, self._slotIndex) if reason == 'already installed' or isFit: isFit, reason = True, GUI_ITEM_ECONOMY_CODE.UNDEFINED else: isFit, reason = module.mayPurchase(stats['money']) if not isFit: if GUI_ITEM_ECONOMY_CODE.isMoneyError(reason): isFit = module.mayPurchaseWithExchange(stats['money'], stats['exchangeRate']) if isFit and reason != GUI_ITEM_ECONOMY_CODE.UNLOCK_ERROR: reason = _getInstallReason(module, self._vehicle, reason, self._slotIndex) moduleData = self._buildCommonModuleData(module, reason) moduleData.update({'targetVisible': isBought, 'showPrice': not isBought, 'isSelected': isInstalledInSlot, 'disabled': not isFit or isInstalled and not isInstalledInSlot, 'removeButtonLabel': MENU.MODULEFITS_REMOVENAME, 'removeButtonTooltip': MENU.MODULEFITS_REMOVETOOLTIP, 'itemPrices': getItemPricesVO(itemPrice)}) return moduleData
def _buildModuleData(self, vehicleModule, isInstalledInSlot, stats): itemPrice = vehicleModule.buyPrices.itemPrice inInventory = vehicleModule.isInInventory isInstalled = vehicleModule.isInstalled(self._vehicle) isBought = inInventory or isInstalled isEnoughMoney, purchaseReason = vehicleModule.mayPurchase(stats['money']) if isBought: isFit, reason = vehicleModule.mayInstall(self._vehicle, self._slotIndex) if reason == 'already installed' or isFit: isFit, reason = True, GUI_ITEM_ECONOMY_CODE.UNDEFINED else: isFit, reason = isEnoughMoney, purchaseReason if not isFit: if GUI_ITEM_ECONOMY_CODE.isCurrencyError(reason): isFit = vehicleModule.mayPurchaseWithExchange(stats['money'], stats['exchangeRate']) if reason != GUI_ITEM_ECONOMY_CODE.UNLOCK_ERROR: installReason = _getInstallReason(vehicleModule, self._vehicle, reason, self._slotIndex) else: installReason = reason self._checkCounters(vehicleModule) moduleData = self._buildCommonModuleData(vehicleModule, installReason) moduleData.update({'targetVisible': isBought, 'showPrice': not isBought, 'isSelected': isInstalledInSlot, 'disabled': not isFit or isInstalled and not isInstalledInSlot, 'removeButtonLabel': MENU.MODULEFITS_REMOVENAME, 'removeButtonTooltip': MENU.MODULEFITS_REMOVETOOLTIP, 'itemPrices': getItemPricesVOWithReason(reason, itemPrice)}) return moduleData
def __getTechTreeVehicleStatus(self, config, vehicle): nodeState = int(config.node.state) tooltip, level = None, Vehicle.VEHICLE_STATE_LEVEL.WARNING parentCD = None if config.node is not None: parentCD = config.node.unlockProps.parentID _, _, need2Unlock = getUnlockPrice(vehicle.intCD, parentCD) if not nodeState & NODE_STATE_FLAGS.UNLOCKED: if not nodeState & NODE_STATE_FLAGS.NEXT_2_UNLOCK: tooltip = TOOLTIPS.RESEARCHPAGE_VEHICLE_STATUS_PARENTMODULEISLOCKED elif need2Unlock > 0: tooltip = TOOLTIPS.RESEARCHPAGE_MODULE_STATUS_NOTENOUGHXP level = Vehicle.VEHICLE_STATE_LEVEL.CRITICAL else: if nodeState & NODE_STATE_FLAGS.IN_INVENTORY: return self.__getVehicleStatus(False, vehicle) mayObtain, reason = vehicle.mayObtainForMoney(self.itemsCache.items.stats.money) if not mayObtain: level = Vehicle.VEHICLE_STATE_LEVEL.CRITICAL if GUI_ITEM_ECONOMY_CODE.isMoneyError(reason): tooltip = _makeModuleFitTooltipError(reason) else: tooltip = TOOLTIPS.MODULEFITS_OPERATION_ERROR header, text = getComplexStatus(tooltip) if header is None and text is None: return else: return {'header': header, 'text': text, 'level': level}
def getMoneyVOWithReason(errorMsg, moneyObj): result = [] for c, v in moneyObj.iteritems(): if errorMsg == GUI_ITEM_ECONOMY_CODE.getCurrencyError(c): result.append(('%sError' % c, v)) result.append((c, v)) return tuple(result)
def _isEnoughMoney(cls, price, money): if not price.isDefined(): return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE) shortage = money.getShortage(price) if shortage: currency = shortage.getCurrency(byWeight=True) return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency)) return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)
def _validate(self): stats = self.itemsCache.items.stats shortage = stats.money.getShortage(self.price) if shortage: currency = shortage.getCurrency(byWeight=False) if currency == Currency.GOLD and not stats.mayConsumeWalletResources: error = GUI_ITEM_ECONOMY_CODE.WALLET_NOT_AVAILABLE else: error = GUI_ITEM_ECONOMY_CODE.getMoneyError(currency) return makeError(error) return makeSuccess()
def _isEnoughMoney(cls, prices, money): shortage = MONEY_UNDEFINED for itemPrice in prices: need = money.getShortage(itemPrice.price) if need: shortage += need return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED) if shortage: currency = shortage.getCurrency(byWeight=True) return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency)) return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)
def getMoneyVOWithReason(errorMsg, moneyObj): """ Same as getMoneyVO but includes currency reason error """ result = [] for c, v in moneyObj.iteritems(): if errorMsg == GUI_ITEM_ECONOMY_CODE.getMoneyError(c): result.append(('%sError' % c, v)) else: result.append((c, v)) return tuple(result)
def _isEnoughMoney(cls, price, money): """ Determines if the given money enough for buying/restoring an item with the given price. Note that the method should NOT check if the given price is defined and will return (True, '') if the price is undefined (see Money class, isDefined method). :param price: item price represented by Money :param money: money for buying, see Money :return: tuple(can be installed <bool>, error msg <str>), also see GUI_ITEM_ECONOMY_CODE """ if not price.isDefined(): return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE) shortage = money.getShortage(price) if shortage: currency = shortage.getCurrency(byWeight=True) return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency)) return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)
def _isEnoughMoney(cls, prices, money): """ Determines if the given money enough for buying the booster for a price. :param prices: item prices represented by ItemPrices :param money: money for buying, see Money :return: tuple(can be installed <bool>, error msg <str>), also see GUI_ITEM_ECONOMY_CODE """ shortage = MONEY_UNDEFINED for itemPrice in prices: need = money.getShortage(itemPrice.price) if need: shortage += need else: return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED) if shortage: currency = shortage.getCurrency(byWeight=True) return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency)) return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)
def _getStatus(self): block = [] module = self.module configuration = self.configuration vehicle = configuration.vehicle slotIdx = configuration.slotIdx eqs = configuration.eqs checkBuying = configuration.checkBuying isEqOrDev = module.itemTypeID in GUI_ITEM_TYPE.ARTEFACTS isFit = True reason = '' titleFormatter = text_styles.middleTitle cachedEqs = RegularEquipmentConsumables() currentVehicleEqs = RegularEquipmentConsumables() if vehicle is not None and vehicle.isInInventory: if vehicle is not None and vehicle.isInInventory: currentVehicleEqs = vehicle.equipment.regularConsumables vehicle.equipment.setRegularConsumables(RegularEquipmentConsumables()) if eqs: for i, e in enumerate(eqs): if e is not None: intCD = int(e) eq = self.itemsCache.items.getItemByCD(intCD) cachedEqs[i] = eq vehicle.equipment.setRegularConsumables(cachedEqs) isFit, reason = module.mayInstall(vehicle, slotIdx) vehicle.equipment.setRegularConsumables(currentVehicleEqs) inventoryVehicles = self.itemsCache.items.getVehicles(REQ_CRITERIA.INVENTORY).itervalues() totalInstalledVehicles = map(lambda x: x.shortUserName, module.getInstalledVehicles(inventoryVehicles)) installedVehicles = totalInstalledVehicles[:self.MAX_INSTALLED_LIST_LEN] tooltipHeader = None tooltipText = None if not isFit: reason = reason.replace(' ', '_') tooltipHeader, tooltipText = getComplexStatus('#tooltips:moduleFits/%s' % reason) if reason == 'not_with_installed_equipment': if vehicle is not None: vehicle.equipment.setRegularConsumables(cachedEqs) conflictEqs = module.getConflictedEquipments(vehicle) tooltipText %= {'eqs': ', '.join([ _ms(e.userName) for e in conflictEqs ])} vehicle.equipment.setRegularConsumables(currentVehicleEqs) elif reason == 'already_installed' and isEqOrDev and installedVehicles: tooltipHeader, _ = getComplexStatus('#tooltips:deviceFits/already_installed' if module.itemTypeName == GUI_ITEM_TYPE.OPTIONALDEVICE else '#tooltips:moduleFits/already_installed') tooltipText = ', '.join(installedVehicles) elif installedVehicles: tooltipHeader, _ = getComplexStatus('#tooltips:deviceFits/already_installed' if module.itemTypeName == GUI_ITEM_TYPE.OPTIONALDEVICE else '#tooltips:moduleFits/already_installed') tooltipText = ', '.join(installedVehicles) if tooltipHeader is not None or tooltipText is not None: if len(totalInstalledVehicles) > self.MAX_INSTALLED_LIST_LEN: hiddenVehicleCount = len(totalInstalledVehicles) - self.MAX_INSTALLED_LIST_LEN hiddenTxt = '%s %s' % (text_styles.main(TOOLTIPS.SUITABLEVEHICLE_HIDDENVEHICLECOUNT), text_styles.stats(hiddenVehicleCount)) tooltipText = '%s\n%s' % (tooltipText, hiddenTxt) block.append(self._packStatusBlock(tooltipHeader, tooltipText, titleFormatter)) if checkBuying: isFit, reason = module.mayPurchase(self.itemsCache.items.stats.money) if not isFit: reason = reason.replace(' ', '_') if GUI_ITEM_ECONOMY_CODE.isMoneyError(reason): titleFormatter = text_styles.critical tooltipHeader, tooltipText = getComplexStatus('#tooltips:moduleFits/%s' % reason) if tooltipHeader is not None or tooltipText is not None: if block: padding = formatters.packPadding(bottom=15) block.insert(0, self._packStatusBlock(tooltipHeader, tooltipText, titleFormatter, padding)) else: block.append(self._packStatusBlock(tooltipHeader, tooltipText, titleFormatter)) return block
def _getInstallReason(module, vehicle, reason, slotIdx=None): _, installReason = module.mayInstall(vehicle, slotIdx) return installReason or reason if GUI_ITEM_ECONOMY_CODE.isCurrencyError(reason) else installReason
def _getInstallReason(module, vehicle, reason, slotIdx=None): _, installReason = module.mayInstall(vehicle, slotIdx) if GUI_ITEM_ECONOMY_CODE.isMoneyError(reason): return installReason or reason return installReason