def __updateAmmo(self): shells = [] stateWarning = False if g_currentVehicle.isPresent(): vehicle = g_currentVehicle.item stateWarning = vehicle.isBroken or not vehicle.isAmmoFull or not g_currentVehicle.isAutoLoadFull( ) or not g_currentVehicle.isAutoEquipFull() for shell in vehicle.shells: if shell.isHidden: continue shells.append({ 'id': str(shell.intCD), 'type': shell.type, 'label': ITEM_TYPES.shell_kindsabbreviation(shell.type), 'icon': '../maps/icons/ammopanel/ammo/%s' % shell.descriptor['icon'][0], 'count': shell.count, 'tooltip': '', 'tooltipType': TOOLTIPS_CONSTANTS.HANGAR_SHELL }) self.as_setAmmoS(shells, stateWarning)
def __updateAmmo(self, shellsData=None, historicalBattleID=-1): shells = [] stateWarning = False if g_currentVehicle.isPresent(): vehicle = g_currentVehicle.item isAmmoFull = vehicle.isAmmoFull or historicalBattleID != -1 stateWarning = vehicle.isBroken or not isAmmoFull or not g_currentVehicle.isAutoLoadFull( ) or not g_currentVehicle.isAutoEquipFull() if shellsData is None: shellsData = map(lambda shell: (shell, shell.count), vehicle.shells) for shell, count in shellsData: shells.append({ 'id': shell.intCD, 'ammunitionType': shell.type, 'label': ITEM_TYPES.shell_kindsabbreviation(shell.type), 'icon': '../maps/icons/ammopanel/ammo/%s' % shell.descriptor['icon'][0], 'count': count, 'historicalBattleID': historicalBattleID, 'tooltip': '', 'tooltipType': TOOLTIPS_CONSTANTS.HANGAR_SHELL }) self.as_setAmmoS(shells, stateWarning)
def __updateDevices(self, vehicle): shells = [] stateWarning = False if g_currentVehicle.isPresent(): stateWarning = vehicle.isBroken or not vehicle.isAmmoFull or not g_currentVehicle.isAutoLoadFull( ) or not g_currentVehicle.isAutoEquipFull() shells = getAmmo(vehicle.shells) self.as_setAmmoS(shells, stateWarning) self.as_setModulesEnabledS(True) self.as_setVehicleHasTurretS(vehicle.hasTurrets) slotsRange = self.__getSlotsRange() devices = getFittingSlotsData(vehicle, slotsRange, VoClass=HangarFittingSlotVO) self.as_setDataS({'devices': devices}) if slotsRange == HANGAR_FITTING_SLOTS and self.itemsCache.items.getItems( GUI_ITEM_TYPE.BATTLE_ABILITY, REQ_CRITERIA.UNLOCKED): showAlert = True for slot in devices: if slot['slotType'] in _ABILITY_SLOTS and slot['id'] != -1: showAlert = False break self.as_showBattleAbilitiesAlertS(showAlert) else: self.as_showBattleAbilitiesAlertS(False)
def checkAmmoLevel(callback): """ Check ammo for current vehicle, if it is lower then 20% shows message dialog Example: isAmmoOk = yield checkAmmoLevel() if isAmmoOk: do something... @return: True if ammo level is ok or user confirm, False otherwise """ showAmmoWarning = False from CurrentVehicle import g_currentVehicle if g_currentVehicle.isReadyToFight(): vehicle = g_currentVehicle.item if not g_currentVehicle.isAutoLoadFull( ) or not g_currentVehicle.isAutoEquipFull(): from gui import SystemMessages from gui.shared.gui_items.processors.vehicle import VehicleLayoutProcessor shellsLayout = [] eqsLayout = [] for shell in vehicle.shells: shellsLayout.append(shell.intCD if not shell.isBoughtForCredits else -shell.intCD) shellsLayout.append(shell.defaultCount) for eq in vehicle.eqsLayout: if eq is not None: eqsLayout.append( eq.intCD if not eq.isBoughtForCredits else -eq.intCD) eqsLayout.append(1) else: eqsLayout.append(0) eqsLayout.append(0) LOG_DEBUG('setVehicleLayouts', shellsLayout, eqsLayout) result = yield VehicleLayoutProcessor(vehicle, shellsLayout, eqsLayout).request() if result and result.auxData: for m in result.auxData: SystemMessages.g_instance.pushI18nMessage( m.userMsg, type=m.sysMsgType) if result and len(result.userMsg): SystemMessages.g_instance.pushI18nMessage( result.userMsg, type=result.sysMsgType) showAmmoWarning = not g_currentVehicle.item.isAmmoFull if showAmmoWarning: from gui import DialogsInterface success = yield DialogsInterface.showI18nConfirmDialog('lowAmmo') callback(success) else: yield lambda callback: callback(None) callback(True) return
def checkAmmoLevel(callback): """ Check ammo for current vehicle, if it is lower then 20% shows message dialog Example: isAmmoOk = yield checkAmmoLevel() if isAmmoOk: do something... @return: True if ammo level is ok or user confirm, False otherwise """ showAmmoWarning = False from CurrentVehicle import g_currentVehicle if g_currentVehicle.isReadyToFight(): vehicle = g_currentVehicle.item if not g_currentVehicle.isAutoLoadFull() or not g_currentVehicle.isAutoEquipFull(): from gui import SystemMessages from gui.shared.gui_items.processors.vehicle import VehicleLayoutProcessor shellsLayout = [] eqsLayout = [] for shell in vehicle.shells: shellsLayout.append(shell.intCD if not shell.isBoughtForCredits else -shell.intCD) shellsLayout.append(shell.defaultCount) for eq in vehicle.eqsLayout: if eq is not None: eqsLayout.append(eq.intCD if not eq.isBoughtForCredits else -eq.intCD) eqsLayout.append(1) else: eqsLayout.append(0) eqsLayout.append(0) LOG_DEBUG('setVehicleLayouts', shellsLayout, eqsLayout) result = yield VehicleLayoutProcessor(vehicle, shellsLayout, eqsLayout).request() if result and result.auxData: for m in result.auxData: SystemMessages.g_instance.pushI18nMessage(m.userMsg, type=m.sysMsgType) if result and len(result.userMsg): SystemMessages.g_instance.pushI18nMessage(result.userMsg, type=result.sysMsgType) showAmmoWarning = not g_currentVehicle.item.isAmmoFull if showAmmoWarning: from gui import DialogsInterface success = yield DialogsInterface.showI18nConfirmDialog('lowAmmo') callback(success) else: yield lambda callback: callback(None) callback(True) return
def __updateDevices(self, vehicle): shells = [] stateWarning = False if g_currentVehicle.isPresent(): stateWarning = vehicle.isBroken or not vehicle.isAmmoFull or not g_currentVehicle.isAutoLoadFull( ) or not g_currentVehicle.isAutoEquipFull() shells = getAmmo(vehicle.shells) self.as_setAmmoS(shells, stateWarning) self.as_setModulesEnabledS(True) self.as_setVehicleHasTurretS(vehicle.hasTurrets) self.as_setDataS({ 'devices': getFittingSlotsData(vehicle, HANGAR_FITTING_SLOTS, VoClass=HangarFittingSlotVO) })
def __updateAmmo(self, shellsData = None): shells = [] stateWarning = False if g_currentVehicle.isPresent(): vehicle = g_currentVehicle.item stateWarning = vehicle.isBroken or not vehicle.isAmmoFull or not g_currentVehicle.isAutoLoadFull() or not g_currentVehicle.isAutoEquipFull() if shellsData is None: shellsData = map(lambda shell: (shell, shell.count), vehicle.shells) for shell, count in shellsData: shells.append({'id': str(shell.intCD), 'type': shell.type, 'label': ITEM_TYPES.shell_kindsabbreviation(shell.type), 'icon': '../maps/icons/ammopanel/ammo/%s' % shell.descriptor['icon'][0], 'count': count, 'historicalBattleID': -1, 'tooltip': '', 'tooltipType': TOOLTIPS_CONSTANTS.HANGAR_SHELL}) self.as_setAmmoS(shells, stateWarning) return
def __updateAmmo(self, shellsData = None, historicalBattleID = -1): ammo = {'gunName': '', 'maxAmmo': 0, 'defaultAmmoCount': 0, 'vehicleLocked': True, 'shells': [], 'stateWarning': 0} if g_currentVehicle.isPresent(): vehicle = g_currentVehicle.item default_ammo_count = 0 default_ammo = dict(((s.intCD, s.defaultCount) for s in vehicle.shells)) isAmmoFull = vehicle.isAmmoFull or historicalBattleID != -1 stateWarning = vehicle.isBroken or not isAmmoFull or not g_currentVehicle.isAutoLoadFull() or not g_currentVehicle.isAutoEquipFull() for compactDescr, count in default_ammo.iteritems(): default_ammo_count += count ammo.update({'gunName': vehicle.gun.longUserName, 'maxAmmo': vehicle.ammoMaxSize, 'defaultAmmoCount': default_ammo_count, 'vehicleLocked': g_currentVehicle.isLocked(), 'stateWarning': int(stateWarning)}) if shellsData is None: shellsData = map(lambda shell: (shell, shell.count), vehicle.shells) shells = ammo.get('shells') for shell, count in shellsData: shells.append({'id': str(shell.intCD), 'type': shell.type, 'label': ITEM_TYPES.shell_kindsabbreviation(shell.type), 'icon': '../maps/icons/ammopanel/ammo/%s' % shell.descriptor['icon'][0], 'count': count, 'historicalBattleID': historicalBattleID}) self.as_setAmmoS(ammo)
def __updateAmmo(self): Waiting.show('updateAmmo') credits = g_itemsCache.items.stats.credits shopRqs = yield ShopRequester().request() ammo = {'gunName': '', 'maxAmmo': 0, 'reserved1': False, 'reserved2': False, 'defaultAmmoCount': 0, 'reserved3': 0, 'vehicleLocked': True, 'stateMsg': '', 'stateLevel': 'info', 'shells': [], 'stateWarning': 0} if g_currentVehicle.isPresent(): vehicle = g_currentVehicle.item default_ammo_count = 0 default_ammo = dict(((s.intCD, s.defaultCount) for s in vehicle.shells)) stateWarning = vehicle.isBroken or not vehicle.isCrewFull or not vehicle.isAmmoFull or not g_currentVehicle.isAutoLoadFull() or not g_currentVehicle.isAutoEquipFull() for compactDescr, count in default_ammo.iteritems(): default_ammo_count += count msg, msgLvl = g_currentVehicle.getHangarMessage() ammo.update({'gunName': vehicle.gun.longUserName, 'maxAmmo': vehicle.ammoMaxSize, 'reserved1': not g_currentVehicle.isLocked(), 'reserved2': not g_currentVehicle.isBroken(), 'defaultAmmoCount': default_ammo_count, 'reserved3': 0, 'vehicleLocked': g_currentVehicle.isLocked(), 'stateMsg': msg, 'stateLevel': msgLvl, 'stateWarning': int(stateWarning)}) iAmmo = yield Requester('shell').getFromInventory() sAmmo = yield Requester('shell').getFromShop() iVehicles = yield Requester('vehicle').getFromInventory() oldStyleVehicle = None for v in iVehicles: if v.inventoryId == vehicle.invID: oldStyleVehicle = v break shells = ammo.get('shells') for shell in oldStyleVehicle.shells: shopShell = sAmmo[sAmmo.index(shell)] if shell in sAmmo else None goldAmmoForCredits = shopRqs.isEnabledBuyingGoldShellsForCredits if shopShell: iCount = iAmmo[iAmmo.index(shell)].count if shell in iAmmo else 0 sPrice = (yield shopShell.getPrice()) if shell is not shopShell else (0, 0) if goldAmmoForCredits: shopShell.priceOrder = (sPrice[0] + sPrice[1] * shopRqs.exchangeRateForShellsAndEqs, sPrice[1]) shells.append({'id': gui_items.compactItem(shopShell), 'type': shell.type, 'label': ITEM_TYPES.shell_kindsabbreviation(shell.type), 'icon': '../maps/icons/ammopanel/ammo/%s' % shell.descriptor['icon'][0], 'count': shell.count, 'defaultCount': shell.default, 'inventoryCount': iCount, 'price': sPrice[0 if not sPrice[1] else 1], 'currentcy': 'credits' if not sPrice[1] else 'gold', 'ammoName': shell.longName, 'tableName': shell.tableName}) self.as_setAmmoS(ammo) Waiting.hide('updateAmmo') return