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 __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 _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) if GUI_ITEM_ECONOMY_CODE.isMoneyError(reason): return installReason or reason return installReason