def _populate(self): super(Barracks, self)._populate() self.app.component.wg_inputKeyMode = 1 self.startGlobalListening() g_itemsCache.onSyncCompleted += self.__updateTankmen g_clientUpdateManager.addCallbacks({'inventory.8': self.__updateTankmen, 'stats.berths': self.__updateTankmen, 'recycleBin.tankmen': self.__updateTankmen}) getRestoreController().onTankmenBufferUpdated += self.__updateDismissedTankmen self.setTankmenFilter()
def __showDismissedTankmen(self, criteria): tankmen = getRestoreController().getDismissedTankmen() tankmenList = list() for tankman in tankmen: if not criteria(tankman): continue skillsList = [] for skill in tankman.skills: skillsList.append({'tankmanID': tankman.invID, 'id': str(tankman.skills.index(skill)), 'name': skill.userName, 'desc': skill.description, 'icon': skill.icon, 'level': skill.level, 'active': skill.isEnable and skill.isActive}) newSkillsCount, lastNewSkillLvl = tankman.newSkillCount if newSkillsCount > 0: skillsList.append({'buy': True, 'buyCount': newSkillsCount - 1, 'tankmanID': tankman.invID, 'level': lastNewSkillLvl}) restoreInfo = getTankmenRestoreInfo(tankman) actionBtnTooltip = makeTooltip(TOOLTIPS.BARRACKS_TANKMEN_RECOVERYBTN_HEADER, getRecoveryStatusText(restoreInfo)) tankmanData = _packTankmanData(tankman) tankmanData.update({'isRankNameVisible': False, 'recoveryPeriodText': _makeRecoveryPeriodText(restoreInfo), 'actionBtnLabel': MENU.BARRACKS_BTNRECOVERY, 'actionBtnTooltip': actionBtnTooltip, 'skills': skillsList, 'isSkillsVisible': True}) tankmenList.append(tankmanData) tankmenCountStr = _ms(MENU.BARRACKS_DISMISSEDTANKMENCOUNT, curValue=len(tankmenList), total=len(tankmen)) placeCount = getRestoreController().getMaxTankmenBufferLength() placeCountStr = _ms(MENU.BARRACKS_RECOVERYCOUNT, total=placeCount, info=icons.info()) noInfoData = None hasNoInfoData = len(tankmenList) == 0 if hasNoInfoData: if len(tankmen) == 0: tankmenRestoreConfig = g_itemsCache.items.shop.tankmenRestoreConfig freeDays = tankmenRestoreConfig.freeDuration / time_utils.ONE_DAY creditsDays = tankmenRestoreConfig.creditsDuration / time_utils.ONE_DAY - freeDays noInfoData = {'title': text_styles.highTitle(MENU.BARRACKS_NORECOVERYTANKMEN_TITLE), 'message': text_styles.main(_ms(MENU.BARRACKS_NORECOVERYTANKMEN_MESSAGE, price=moneyWithIcon(tankmenRestoreConfig.cost), totalDays=freeDays + creditsDays, freeDays=freeDays, paidDays=creditsDays))} else: noInfoData = {'message': text_styles.main(MENU.BARRACKS_NOFILTEREDRECOVERYTANKMEN_MESSAGE)} placesCountTooltip = makeTooltip(TOOLTIPS.BARRACKS_PLACESCOUNT_DISMISS_HEADER, _ms(TOOLTIPS.BARRACKS_PLACESCOUNT_DISMISS_BODY, placeCount=placeCount)) self.as_setTankmenS({'tankmenCount': text_styles.playerOnline(tankmenCountStr), 'placesCount': text_styles.playerOnline(placeCountStr), 'placesCountTooltip': placesCountTooltip, 'tankmenData': tankmenList, 'hasNoInfoData': hasNoInfoData, 'noInfoData': noInfoData}) return
def _buildVO(self): from gui.game_control import getRestoreController restoreController = getRestoreController() deletedTankmen = restoreController.getTankmenBeingDeleted() alertImgSrc = '' alertText = '' alertTooltip = '' if not self._tankman.isRestorable(): alertText = text_styles.alert( icons.alert() + _ms(DIALOGS.PROTECTEDDISMISSTANKMAN_ALERT)) alertTooltip = TOOLTIPS.DISMISSTANKMANDIALOG_CANTRESTORALERT elif len(deletedTankmen) > 0: alertImgSrc = RES_ICONS.MAPS_ICONS_LIBRARY_ALERTICON alertTooltip = makeTooltip( TOOLTIPS.DISMISSTANKMANDIALOG_BUFFERISFULL_HEADER, _ms(TOOLTIPS.DISMISSTANKMANDIALOG_BUFFERISFULL_BODY, placeCount=restoreController.getMaxTankmenBufferLength(), currCount=len(restoreController.getDismissedTankmen()), tankmanNew=self._tankman.fullUserName, tankmanOld=formatDeletedTankmanStr(deletedTankmen[0]))) return { 'alertText': alertText, 'alertTooltip': alertTooltip, 'alertImgSrc': alertImgSrc, 'questionText': text_styles.main(_ms(DIALOGS.DISMISSTANKMAN_MESSAGE)) }
def __init__(self, vehicle, dismantlingGoldCost, shells = [], eqs = [], optDevs = [], inventory = [], isCrewDismiss = False): self.gainMoney, self.spendMoney = self.__getGainSpendMoney(vehicle, shells, eqs, optDevs, inventory, dismantlingGoldCost) barracksBerthsNeeded = len(filter(lambda (idx, item): item is not None, vehicle.crew)) bufferOverflowCtx = {} isBufferOverflowed = False if isCrewDismiss: tankmenGoingToBuffer, deletedTankmen = getRestoreController().getTankmenDeletedBySelling(vehicle) countOfDeleted = len(deletedTankmen) if countOfDeleted > 0: isBufferOverflowed = True bufferOverflowCtx['deleted'] = deletedTankmen[-1] bufferOverflowCtx['dismissed'] = tankmenGoingToBuffer[-1] if countOfDeleted > 1: bufferOverflowCtx['multiple'] = True bufferOverflowCtx['extraCount'] = countOfDeleted - 1 super(VehicleSeller, self).__init__(vehicle, (plugins.VehicleValidator(vehicle, False, prop={'isBroken': True, 'isLocked': True}), plugins.VehicleSellValidator(vehicle), plugins.MoneyValidator(self.spendMoney), plugins.VehicleSellsLeftValidator(vehicle, not (vehicle.isRented and vehicle.rentalIsOver)), plugins.BarracksSlotsValidator(barracksBerthsNeeded, isEnabled=not isCrewDismiss), plugins.BufferOverflowConfirmator(bufferOverflowCtx, isEnabled=isBufferOverflowed), _getUniqueVehicleSellConfirmator(vehicle))) self.vehicle = vehicle self.shells = shells self.eqs = eqs self.optDevs = optDevs self.inventory = inventory self.isCrewDismiss = isCrewDismiss self.isDismantlingForGold = self.__dismantlingForGoldDevicesCount(vehicle, optDevs) > 0 self.isRemovedAfterRent = vehicle.isRented
def __init__(self, tankman): vehicle = None if tankman.vehicleInvID > 0: vehicle = g_itemsCache.items.getVehicle(tankman.vehicleInvID) confirmator = plugins.TankmanOperationConfirmator('protectedDismissTankman', tankman) super(TankmanDismiss, self).__init__(tankman, [confirmator, plugins.VehicleValidator(vehicle, isEnabled=tankman.vehicleInvID > 0)]) deletedTankmen = getRestoreController().getTankmenBeingDeleted() if len(deletedTankmen) > 0 and tankman.isRestorable(): self.addPlugin(plugins.BufferOverflowConfirmator({'dismissed': tankman, 'deleted': deletedTankmen[0]})) return
def _buildVO(self): from gui.game_control import getRestoreController restoreController = getRestoreController() deletedTankmen = restoreController.getTankmenBeingDeleted() alertImgSrc = '' alertText = '' alertTooltip = '' if not self._tankman.isRestorable(): alertText = text_styles.alert(icons.alert() + _ms(DIALOGS.PROTECTEDDISMISSTANKMAN_ALERT)) alertTooltip = TOOLTIPS.DISMISSTANKMANDIALOG_CANTRESTORALERT elif len(deletedTankmen) > 0: alertImgSrc = RES_ICONS.MAPS_ICONS_LIBRARY_ALERTICON alertTooltip = makeTooltip(TOOLTIPS.DISMISSTANKMANDIALOG_BUFFERISFULL_HEADER, _ms(TOOLTIPS.DISMISSTANKMANDIALOG_BUFFERISFULL_BODY, placeCount=restoreController.getMaxTankmenBufferLength(), currCount=len(restoreController.getDismissedTankmen()), tankmanNew=self._tankman.fullUserName, tankmanOld=formatDeletedTankmanStr(deletedTankmen[0]))) return {'alertText': alertText, 'alertTooltip': alertTooltip, 'alertImgSrc': alertImgSrc, 'questionText': text_styles.main(_ms(DIALOGS.DISMISSTANKMAN_MESSAGE))}
def _populate(self): super(VehicleSellDialog, self)._populate() g_clientUpdateManager.addCallbacks({'stats.gold': self.onSetGoldHndlr}) g_itemsCache.onSyncCompleted += self.__shopResyncHandler items = g_itemsCache.items vehicle = items.getVehicle(self.vehInvID) sellPrice = vehicle.sellPrice sellForGold = sellPrice.gold > 0 priceTextColor = CURRENCIES_CONSTANTS.GOLD_COLOR if sellForGold else CURRENCIES_CONSTANTS.CREDITS_COLOR priceTextValue = _ms(DIALOGS.VEHICLESELLDIALOG_PRICE_SIGN_ADD) + _ms(BigWorld.wg_getIntegralFormat(sellPrice.gold if sellForGold else sellPrice.credits)) currencyIcon = CURRENCIES_CONSTANTS.GOLD if sellForGold else CURRENCIES_CONSTANTS.CREDITS invVehs = items.getVehicles(REQ_CRITERIA.INVENTORY) if vehicle.isPremium or vehicle.level >= 3: self.as_visibleControlBlockS(True) self.__initCtrlQuestion() else: self.as_visibleControlBlockS(False) modules = items.getItems(criteria=REQ_CRITERIA.VEHICLE.SUITABLE([vehicle]) | REQ_CRITERIA.INVENTORY).values() shells = items.getItems(criteria=REQ_CRITERIA.VEHICLE.SUITABLE([vehicle], [GUI_ITEM_TYPE.SHELL]) | REQ_CRITERIA.INVENTORY).values() otherVehsShells = set() for invVeh in invVehs.itervalues(): if invVeh.invID != self.vehInvID: for shot in invVeh.descriptor.gun['shots']: otherVehsShells.add(shot['shell']['compactDescr']) vehicleAction = None if sellPrice != vehicle.defaultSellPrice: vehicleAction = packItemActionTooltipData(vehicle, False) if vehicle.isElite: description = TOOLTIPS.tankcaruseltooltip_vehicletype_elite(vehicle.type) else: description = DIALOGS.vehicleselldialog_vehicletype(vehicle.type) levelStr = text_styles.concatStylesWithSpace(text_styles.stats(int2roman(vehicle.level)), text_styles.main(_ms(DIALOGS.VEHICLESELLDIALOG_VEHICLE_LEVEL))) restoreController = getRestoreController() tankmenGoingToBuffer, deletedTankmen = restoreController.getTankmenDeletedBySelling(vehicle) deletedCount = len(deletedTankmen) if deletedCount > 0: recoveryBufferFull = True deletedStr = formatDeletedTankmanStr(deletedTankmen[0]) maxCount = restoreController.getMaxTankmenBufferLength() currCount = len(restoreController.getDismissedTankmen()) if deletedCount == 1: crewTooltip = text_styles.concatStylesToMultiLine(text_styles.middleTitle(_ms(TOOLTIPS.VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_HEADER)), text_styles.main(_ms(TOOLTIPS.VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_BODY, maxVal=maxCount, curVal=currCount, sourceName=tankmenGoingToBuffer[-1].fullUserName, targetInfo=deletedStr))) else: crewTooltip = text_styles.concatStylesToMultiLine(text_styles.middleTitle(_ms(TOOLTIPS.VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_HEADER)), text_styles.main(_ms(TOOLTIPS.DISMISSTANKMANDIALOG_BUFFERISFULLMULTIPLE_BODY, deletedStr=deletedStr, extraCount=deletedCount - 1, maxCount=maxCount, currCount=currCount))) else: crewTooltip = None recoveryBufferFull = False barracksDropDownData = [{'label': _ms(MENU.BARRACKS_BTNUNLOAD)}, {'label': _ms(MENU.BARRACKS_BTNDISSMISS)}] sellVehicleData = {'intCD': vehicle.intCD, 'userName': vehicle.userName, 'icon': vehicle.icon, 'level': vehicle.level, 'isElite': vehicle.isElite, 'isPremium': vehicle.isPremium, 'type': vehicle.type, 'nationID': vehicle.nationID, 'sellPrice': sellPrice, 'priceTextValue': priceTextValue, 'priceTextColor': priceTextColor, 'currencyIcon': currencyIcon, 'action': vehicleAction, 'hasCrew': vehicle.hasCrew, 'isRented': vehicle.isRented, 'description': description, 'levelStr': levelStr, 'priceLabel': _ms(DIALOGS.VEHICLESELLDIALOG_VEHICLE_EMPTYSELLPRICE), 'crewLabel': _ms(DIALOGS.VEHICLESELLDIALOG_CREW_LABEL), 'crewTooltip': crewTooltip, 'barracksDropDownData': barracksDropDownData, 'crewRecoveryBufferFull': recoveryBufferFull} onVehicleOptionalDevices = [] for o in vehicle.optDevices: if o is not None: action = None if o.sellPrice != o.defaultSellPrice: action = packItemActionTooltipData(o, False) data = {'intCD': o.intCD, 'isRemovable': o.isRemovable, 'userName': o.userName, 'sellPrice': o.sellPrice, 'toInventory': True, 'action': action} onVehicleOptionalDevices.append(data) onVehicleoShells = [] for shell in vehicle.shells: if shell is not None: action = None if shell.sellPrice != shell.defaultSellPrice: action = packItemActionTooltipData(shell, False) data = {'intCD': shell.intCD, 'count': shell.count, 'sellPrice': shell.sellPrice, 'userName': shell.userName, 'kind': shell.type, 'toInventory': shell in otherVehsShells or shell.isPremium, 'action': action} onVehicleoShells.append(data) onVehicleEquipments = [] for equipmnent in vehicle.eqs: if equipmnent is not None: action = None if equipmnent.sellPrice != equipmnent.defaultSellPrice: action = packItemActionTooltipData(equipmnent, False) data = {'intCD': equipmnent.intCD, 'userName': equipmnent.userName, 'sellPrice': equipmnent.sellPrice, 'toInventory': True, 'action': action} onVehicleEquipments.append(data) inInventoryModules = [] for m in modules: inInventoryModules.append({'intCD': m.intCD, 'inventoryCount': m.inventoryCount, 'toInventory': True, 'sellPrice': m.sellPrice}) inInventoryShells = [] for s in shells: action = None if s.sellPrice != s.defaultSellPrice: action = packItemActionTooltipData(s, False) inInventoryShells.append({'intCD': s.intCD, 'count': s.inventoryCount, 'sellPrice': s.sellPrice, 'userName': s.userName, 'kind': s.type, 'toInventory': s in otherVehsShells or s.isPremium, 'action': action}) removePrice = items.shop.paidRemovalCost removePrices = Money(gold=removePrice) defRemovePrice = Money(gold=items.shop.defaults.paidRemovalCost) removeAction = None if removePrices != defRemovePrice: removeAction = packActionTooltipData(ACTION_TOOLTIPS_TYPE.ECONOMICS, 'paidRemovalCost', True, removePrices, defRemovePrice) settings = self.getDialogSettings() isSlidingComponentOpened = settings['isOpened'] self.as_setDataS({'accountGold': items.stats.gold, 'sellVehicleVO': sellVehicleData, 'optionalDevicesOnVehicle': onVehicleOptionalDevices, 'shellsOnVehicle': onVehicleoShells, 'equipmentsOnVehicle': onVehicleEquipments, 'modulesInInventory': inInventoryModules, 'shellsInInventory': inInventoryShells, 'removeActionPrice': removeAction, 'removePrice': removePrice, 'isSlidingComponentOpened': isSlidingComponentOpened}) return
def _populate(self): super(VehicleSellDialog, self)._populate() g_clientUpdateManager.addCallbacks({'stats.gold': self.onSetGoldHndlr}) g_itemsCache.onSyncCompleted += self.__shopResyncHandler items = g_itemsCache.items vehicle = items.getVehicle(self.vehInvID) sellPrice = vehicle.sellPrice sellForGold = sellPrice.gold > 0 priceTextColor = CURRENCIES_CONSTANTS.GOLD_COLOR if sellForGold else CURRENCIES_CONSTANTS.CREDITS_COLOR priceTextValue = _ms(DIALOGS.VEHICLESELLDIALOG_PRICE_SIGN_ADD) + _ms( BigWorld.wg_getIntegralFormat( sellPrice.gold if sellForGold else sellPrice.credits)) currencyIcon = CURRENCIES_CONSTANTS.GOLD if sellForGold else CURRENCIES_CONSTANTS.CREDITS invVehs = items.getVehicles(REQ_CRITERIA.INVENTORY) if vehicle.isPremium or vehicle.level >= 3: self.as_visibleControlBlockS(True) self.__initCtrlQuestion() else: self.as_visibleControlBlockS(False) modules = items.getItems( criteria=REQ_CRITERIA.VEHICLE.SUITABLE([vehicle]) | REQ_CRITERIA.INVENTORY).values() shells = items.getItems(criteria=REQ_CRITERIA.VEHICLE.SUITABLE( [vehicle], [GUI_ITEM_TYPE.SHELL]) | REQ_CRITERIA.INVENTORY).values() otherVehsShells = set() for invVeh in invVehs.itervalues(): if invVeh.invID != self.vehInvID: for shot in invVeh.descriptor.gun['shots']: otherVehsShells.add(shot['shell']['compactDescr']) vehicleAction = None if sellPrice != vehicle.defaultSellPrice: vehicleAction = packItemActionTooltipData(vehicle, False) if vehicle.isElite: description = TOOLTIPS.tankcaruseltooltip_vehicletype_elite( vehicle.type) else: description = DIALOGS.vehicleselldialog_vehicletype(vehicle.type) levelStr = text_styles.concatStylesWithSpace( text_styles.stats(int2roman(vehicle.level)), text_styles.main(_ms(DIALOGS.VEHICLESELLDIALOG_VEHICLE_LEVEL))) restoreController = getRestoreController() tankmenGoingToBuffer, deletedTankmen = restoreController.getTankmenDeletedBySelling( vehicle) deletedCount = len(deletedTankmen) if deletedCount > 0: recoveryBufferFull = True deletedStr = formatDeletedTankmanStr(deletedTankmen[0]) maxCount = restoreController.getMaxTankmenBufferLength() currCount = len(restoreController.getDismissedTankmen()) if deletedCount == 1: crewTooltip = text_styles.concatStylesToMultiLine( text_styles.middleTitle( _ms(TOOLTIPS. VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_HEADER)), text_styles.main( _ms(TOOLTIPS. VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_BODY, maxVal=maxCount, curVal=currCount, sourceName=tankmenGoingToBuffer[-1].fullUserName, targetInfo=deletedStr))) else: crewTooltip = text_styles.concatStylesToMultiLine( text_styles.middleTitle( _ms(TOOLTIPS. VEHICLESELLDIALOG_CREW_ALERTICON_RECOVERY_HEADER)), text_styles.main( _ms(TOOLTIPS. DISMISSTANKMANDIALOG_BUFFERISFULLMULTIPLE_BODY, deletedStr=deletedStr, extraCount=deletedCount - 1, maxCount=maxCount, currCount=currCount))) else: crewTooltip = None recoveryBufferFull = False barracksDropDownData = [{ 'label': _ms(MENU.BARRACKS_BTNUNLOAD) }, { 'label': _ms(MENU.BARRACKS_BTNDISSMISS) }] sellVehicleData = { 'intCD': vehicle.intCD, 'userName': vehicle.userName, 'icon': vehicle.icon, 'level': vehicle.level, 'isElite': vehicle.isElite, 'isPremium': vehicle.isPremium, 'type': vehicle.type, 'nationID': vehicle.nationID, 'sellPrice': sellPrice, 'priceTextValue': priceTextValue, 'priceTextColor': priceTextColor, 'currencyIcon': currencyIcon, 'action': vehicleAction, 'hasCrew': vehicle.hasCrew, 'isRented': vehicle.isRented, 'description': description, 'levelStr': levelStr, 'priceLabel': _ms(DIALOGS.VEHICLESELLDIALOG_VEHICLE_EMPTYSELLPRICE), 'crewLabel': _ms(DIALOGS.VEHICLESELLDIALOG_CREW_LABEL), 'crewTooltip': crewTooltip, 'barracksDropDownData': barracksDropDownData, 'crewRecoveryBufferFull': recoveryBufferFull } onVehicleOptionalDevices = [] for o in vehicle.optDevices: if o is not None: action = None if o.sellPrice != o.defaultSellPrice: action = packItemActionTooltipData(o, False) data = { 'intCD': o.intCD, 'isRemovable': o.isRemovable, 'userName': o.userName, 'sellPrice': o.sellPrice, 'toInventory': True, 'action': action } onVehicleOptionalDevices.append(data) onVehicleoShells = [] for shell in vehicle.shells: if shell is not None: action = None if shell.sellPrice != shell.defaultSellPrice: action = packItemActionTooltipData(shell, False) data = { 'intCD': shell.intCD, 'count': shell.count, 'sellPrice': shell.sellPrice, 'userName': shell.userName, 'kind': shell.type, 'toInventory': shell in otherVehsShells or shell.isPremium, 'action': action } onVehicleoShells.append(data) onVehicleEquipments = [] for equipmnent in vehicle.eqs: if equipmnent is not None: action = None if equipmnent.sellPrice != equipmnent.defaultSellPrice: action = packItemActionTooltipData(equipmnent, False) data = { 'intCD': equipmnent.intCD, 'userName': equipmnent.userName, 'sellPrice': equipmnent.sellPrice, 'toInventory': True, 'action': action } onVehicleEquipments.append(data) inInventoryModules = [] for m in modules: inInventoryModules.append({ 'intCD': m.intCD, 'inventoryCount': m.inventoryCount, 'toInventory': True, 'sellPrice': m.sellPrice }) inInventoryShells = [] for s in shells: action = None if s.sellPrice != s.defaultSellPrice: action = packItemActionTooltipData(s, False) inInventoryShells.append({ 'intCD': s.intCD, 'count': s.inventoryCount, 'sellPrice': s.sellPrice, 'userName': s.userName, 'kind': s.type, 'toInventory': s in otherVehsShells or s.isPremium, 'action': action }) removePrice = items.shop.paidRemovalCost removePrices = Money(gold=removePrice) defRemovePrice = Money(gold=items.shop.defaults.paidRemovalCost) removeAction = None if removePrices != defRemovePrice: removeAction = packActionTooltipData( ACTION_TOOLTIPS_TYPE.ECONOMICS, 'paidRemovalCost', True, removePrices, defRemovePrice) settings = self.getDialogSettings() isSlidingComponentOpened = settings['isOpened'] self.as_setDataS({ 'accountGold': items.stats.gold, 'sellVehicleVO': sellVehicleData, 'optionalDevicesOnVehicle': onVehicleOptionalDevices, 'shellsOnVehicle': onVehicleoShells, 'equipmentsOnVehicle': onVehicleEquipments, 'modulesInInventory': inInventoryModules, 'shellsInInventory': inInventoryShells, 'removeActionPrice': removeAction, 'removePrice': removePrice, 'isSlidingComponentOpened': isSlidingComponentOpened }) return
def _dispose(self): getRestoreController().onTankmenBufferUpdated -= self.__updateDismissedTankmen g_clientUpdateManager.removeObjectCallbacks(self) g_itemsCache.onSyncCompleted -= self.__updateTankmen self.stopGlobalListening() super(LobbySubView, self)._dispose()