def __processBackClick(self, ctx=None): if self._previewBackCb: self._previewBackCb() elif self._backAlias == VIEW_ALIAS.LOBBY_RESEARCH: event_dispatcher.showResearchView(self._vehicleCD) elif self._backAlias == VIEW_ALIAS.VEHICLE_PREVIEW: entity = ctx.get('entity', None) if ctx else None if entity: descriptor = entity.typeDescriptor event_dispatcher.showVehiclePreview( descriptor.type.compactDescr, previewAlias=self._previousBackAlias) else: event_dispatcher.showHangar() elif self._backAlias == VIEW_ALIAS.LOBBY_STORE: if isIngameShopEnabled(): showWebShop(url=getBuyVehiclesUrl()) else: showOldShop( ctx={ 'tabId': STORE_TYPES.SHOP, 'component': STORE_CONSTANTS.VEHICLE }) else: event = g_entitiesFactories.makeLoadEvent(self._backAlias, {'isBackEvent': True}) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) return
def __init__(self, *args, **kwargs): super(BuyVehicleView, self).__init__(R.views.buyVehicleView, ViewFlags.COMPONENT, BuyVehicleViewModel, *args, **kwargs) self.__shop = self.itemsCache.items.shop self.__stats = self.itemsCache.items.stats ctx = kwargs['ctx'] if ctx is not None: self.__nationID = ctx.get('nationID') self.__inNationID = ctx.get('itemID') self.__previousAlias = ctx.get('previousAlias') else: self.__nationID = None self.__inNationID = None self.__previousAlias = '' self.__selectedCardIdx = 0 self.__isWithoutCommander = False self.__vehicle = self.itemsCache.items.getItem(GUI_ITEM_TYPE.VEHICLE, self.__nationID, self.__inNationID) self.__tradeOffVehicle = None self.__selectedRentTerm = self.__RENT_NOT_SELECTED_IDX if self.__vehicle.isRestoreAvailable(): self.__selectedRentIdx = self.__RENT_NOT_SELECTED_IDX else: self.__selectedRentIdx = self.__RENT_UNLIM_IDX self.__isGoldAutoPurhaseEnabled = isIngameShopEnabled() self.__isGoldAutoPurhaseEnabled &= self.wallet.isAvailable self.__isRentVisible = self.__vehicle.hasRentPackages and not self.__isTradeIn( ) self.__popoverIsAvailable = True self.__tradeinInProgress = False self.__successOperation = False self.__purchaseInProgress = False return
def changeTankmanPassport(self, inventoryID, firstNameID, firstNameGroup, lastNameID, lastNameGroup, iconID, iconGroup): items = self.itemsCache.items tankman = items.getTankman(inventoryID) if tankman.descriptor.isFemale: passportChangeCost = items.shop.passportFemaleChangeCost else: passportChangeCost = items.shop.passportChangeCost currentGold = self.itemsCache.items.stats.gold if currentGold < passportChangeCost and isIngameShopEnabled(): showBuyGoldForCrew(passportChangeCost) return def checkFlashInt(value): return None if value == -1 else value firstNameID = checkFlashInt(firstNameID) lastNameID = checkFlashInt(lastNameID) iconID = checkFlashInt(iconID) tankman = self.itemsCache.items.getTankman(int(inventoryID)) result = yield TankmanChangePassport(tankman, firstNameID, firstNameGroup, lastNameID, lastNameGroup, iconID, iconGroup).request() if result.userMsg: SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType)
def __getBtnDataUnlockedVehicle(self, vehicle): money = self.itemsCache.items.stats.money money = self.tradeIn.addTradeInPriceIfNeeded(vehicle, money) tooltip = '' exchangeRate = self.itemsCache.items.shop.exchangeRate price = getGUIPrice(vehicle, money, exchangeRate) currency = price.getCurrency(byWeight=True) action = getActionPriceData(vehicle) mayObtainForMoney = self.__isHeroTank or vehicle.mayObtainWithMoneyExchange( money, exchangeRate) isBuyingAvailable = not vehicle.isHidden or vehicle.isRentable or vehicle.isRestorePossible( ) if currency == Currency.GOLD: if not mayObtainForMoney: if isBuyingAvailable: tooltip = _buildBuyButtonTooltip('notEnoughGold') if isIngameShopEnabled(): mayObtainForMoney = True elif not mayObtainForMoney and isBuyingAvailable: tooltip = _buildBuyButtonTooltip('notEnoughCredits') if self._disableBuyButton: mayObtainForMoney = False return _ButtonState( mayObtainForMoney, [currency, price.getSignValue(currency)], VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_RESTORE if vehicle.isRestorePossible() else VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_BUY, action, tooltip, self.__packTitle)
def onButtonClick(self, buttonID): if buttonID != DIALOG_BUTTON_ID.SUBMIT: self.destroy() return if self.__enoughCurrency(Currency.GOLD): super(DemountDeviceDialog, self).onButtonClick(buttonID) elif isIngameShopEnabled(): showBuyGoldForEquipment(self.__price.get(Currency.GOLD, 0))
def __buySlot(self): price = self.itemsCache.items.shop.getVehicleSlotsPrice( self.itemsCache.items.stats.vehicleSlots) availableMoney = self.itemsCache.items.stats.money if price and availableMoney.gold < price and isIngameShopEnabled(): showBuyGoldForSlot(price) else: ActionsFactory.doAction(ActionsFactory.BUY_VEHICLE_SLOT)
def navigateToStore(self): if isIngameShopEnabled(): showWebShop(getBuyVehiclesUrl()) else: showOldShop(ctx={ 'tabId': STORE_TYPES.SHOP, 'component': STORE_CONSTANTS.VEHICLE })
def submit(self, operationId): if operationId in self.AVAILABLE_OPERATIONS: _, cost = self.getCrewTrainInfo(int(operationId)) currentGold = self.itemsCache.items.stats.gold if currentGold < cost.get(Currency.GOLD, 0) and isIngameShopEnabled(): showBuyGoldForCrew(cost.get(Currency.GOLD)) return self.__processCrewRetrianing(operationId) self.destroy()
def showBoostersWindow(tabID=None): if isIngameShopEnabled(): showStorage(STORAGE_CONSTANTS.PERSONAL_RESERVES) else: ctx = {'tabID': tabID} if tabID is not None else {} g_eventBus.handleEvent( events.LoadViewEvent(VIEW_ALIAS.BOOSTERS_WINDOW, ctx=ctx), EVENT_BUS_SCOPE.LOBBY) return
def openBoostersWindow(self, idx): slotID = self.components.get(VIEW_ALIAS.BOOSTERS_PANEL).getBoosterSlotID(idx) settings = self.lobbyContext.getServerSettings() shouldOpenStorage = isIngameShopEnabled() and settings.isIngameStorageEnabled() if shouldOpenStorage: showStorage(defaultSection=STORAGE_CONSTANTS.PERSONAL_RESERVES) else: self.fireEvent(events.LoadViewEvent(VIEW_ALIAS.BOOSTERS_WINDOW, ctx={'slotID': slotID}), EVENT_BUS_SCOPE.LOBBY) self.destroy()
def buyBerths(self): price, _ = self.itemsCache.items.shop.getTankmanBerthPrice( self.itemsCache.items.stats.tankmenBerthsCount) availableMoney = self.itemsCache.items.stats.money if price and availableMoney.gold < price.gold and isIngameShopEnabled( ): showBuyGoldForBerth(price.gold) else: ActionsFactory.doAction(ActionsFactory.BUY_BERTHS)
def _populate(self): super(ExchangeXPWindow, self)._populate() self.__xpForFree = self.itemsCache.items.shop.freeXPConversionLimit self.as_setPrimaryCurrencyS(self.itemsCache.items.stats.actualGold) self.__setRates() self.as_totalExperienceChangedS( self.itemsCache.items.stats.actualFreeXP) self.__isIngameShopEnabled = isIngameShopEnabled() self.__prepareAndPassVehiclesData() self.as_setWalletStatusS(self.wallet.status, self.__isIngameShopEnabled)
def onOpenShop(self): if isIngameShopEnabled(): url = getBonsUrl() showWebShop(url) else: showOldShop( ctx={ 'tabId': STORE_CONSTANTS.SHOP, 'component': STORE_CONSTANTS.BATTLE_BOOSTER }) self.destroy()
def __onServerSettingChanged(self, diff): if 'ingameShop' in diff: storageEnabled = self.lobbyContext.getServerSettings( ).isIngameStorageEnabled() if isIngameShopEnabled(): if not storageEnabled and not self.__showDummyScreen: showHangar() if storageEnabled and self.__showDummyScreen: self.__showDummyScreen = False self.__initialize() else: showHangar()
def buyTank(self): if isIngameShopEnabled(): self.fireEvent(events.LoadViewEvent(VIEW_ALIAS.LOBBY_TECHTREE), EVENT_BUS_SCOPE.LOBBY) else: ctx = { 'tabId': STORE_TYPES.SHOP, 'component': STORE_CONSTANTS.VEHICLE } self.fireEvent( events.LoadViewEvent(VIEW_ALIAS.LOBBY_STORE_OLD, ctx=ctx), EVENT_BUS_SCOPE.LOBBY)
def __init__(self, ctx=None): super(VehicleBuyWindow, self).__init__() self.nationID = ctx.get('nationID') self.inNationID = ctx.get('itemID') self.vehicle = None self.tradeOffVehicle = None self.__state = VehicleBuyWindowState(False, False, -1, -1) self.__isGoldAutoPurhaseEnabled = isIngameShopEnabled() if ctx.get('isTradeIn', False): self.selectedTab = _TABS.TRADE else: self.selectedTab = _TABS.UNDEFINED return
def retrainingTankman(self, inventoryID, tankmanCostTypeIdx): operationCost = self.itemsCache.items.shop.tankmanCost[ tankmanCostTypeIdx].get('gold', 0) currentGold = self.itemsCache.items.stats.gold if currentGold < operationCost and isIngameShopEnabled(): showBuyGoldForCrew(operationCost) return tankman = self.itemsCache.items.getTankman(int(inventoryID)) proc = TankmanRetraining(tankman, self.vehicle, tankmanCostTypeIdx) result = yield proc.request() if result.userMsg: SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType)
def restoreTank(self): serverSettings = self.lobbyContext.getServerSettings() storageEnabled = serverSettings.isIngameStorageEnabled() shopEnabled = isIngameShopEnabled() if storageEnabled and shopEnabled: showStorage(STORAGE_CONSTANTS.IN_HANGAR, STORAGE_CONSTANTS.VEHICLES_TAB_RESTORE) else: ctx = { 'tabId': STORE_TYPES.SHOP, 'component': STORE_CONSTANTS.RESTORE_VEHICLE } showOldShop(ctx=ctx)
def _buildSupplyItems(self): self._supplyItems = [] items = self._itemsCache.items slots = items.stats.vehicleSlots vehicles = self.getTotalVehiclesCount() slotPrice = items.shop.getVehicleSlotsPrice(slots) defaultSlotPrice = items.shop.defaults.getVehicleSlotsPrice(slots) if slotPrice != defaultSlotPrice: discount = packActionTooltipData(ACTION_TOOLTIPS_TYPE.ECONOMICS, 'slotsPrices', True, Money(gold=slotPrice), Money(gold=defaultSlotPrice)) else: discount = None self._emptySlotsCount = slots - vehicles smallBuySlotString, buySlotString = getStatusStrings('buySlot') smallBuyTankString, buyTankString = getStatusStrings('buyTank') smallEmptySlotsString, emptySlotsString = getStatusStrings( 'buyTankEmptyCount', style=text_styles.main, ctx={'count': self._emptySlotsCount}) self._supplyItems.append({ 'buyTank': True, 'smallInfoText': text_styles.concatStylesToMultiLine(smallBuyTankString, smallEmptySlotsString), 'infoText': text_styles.concatStylesToMultiLine(buyTankString, emptySlotsString), 'icon': RES_ICONS.MAPS_ICONS_LIBRARY_TANKITEM_BUY_TANK, 'tooltip': TOOLTIPS.TANKS_CAROUSEL_BUY_VEHICLE_NEW if isIngameShopEnabled() else TOOLTIPS.TANKS_CAROUSEL_BUY_VEHICLE }) buySlotVO = { 'buySlot': True, 'slotPrice': slotPrice, 'icon': RES_ICONS.MAPS_ICONS_LIBRARY_TANKITEM_BUY_SLOT, 'infoText': buySlotString, 'smallInfoText': smallBuySlotString, 'hasSale': discount is not None, 'tooltip': TOOLTIPS.TANKS_CAROUSEL_BUY_SLOT } if discount is not None: buySlotVO.update({'slotPriceActionData': discount}) self._supplyItems.append(buySlotVO) return
def changeRole(self, role, vehicleId): changeRoleCost = self.itemsCache.items.shop.changeRoleCost actualGold = self.itemsCache.items.stats.gold if changeRoleCost > actualGold and isIngameShopEnabled(): showBuyGoldForCrew(changeRoleCost) return result = yield TankmanChangeRole(self.__tankman, role, int(vehicleId)).request() if result.userMsg: SystemMessages.pushMessage(result.userMsg, type=result.sysMsgType) if result.auxData: SystemMessages.pushMessage(result.auxData.userMsg, type=result.auxData.sysMsgType) if result.success: self.onWindowClose()
def __doSellVehicle(self, vehicle, shells, eqs, optDevicesToSell, inventory, isDismissCrew): vehicleSeller = VehicleSeller(vehicle, shells, eqs, optDevicesToSell, inventory, isDismissCrew) currentMoneyGold = self.itemsCache.items.stats.money.get( Currency.GOLD, 0) spendMoneyGold = vehicleSeller.spendMoney.get(Currency.GOLD, 0) if isIngameShopEnabled() and currentMoneyGold < spendMoneyGold: showBuyGoldForEquipment(spendMoneyGold) else: result = yield vehicleSeller.request() if result.userMsg: SystemMessages.pushMessage(result.userMsg, type=result.sysMsgType) self.destroy()
def moneyWithIcon(money, currType=None, statsMoney=None): from gui.Scaleform.daapi.view.lobby.store.browser.ingameshop_helpers import isIngameShopEnabled if currType is None: currType = money.getCurrency() if statsMoney and not isIngameShopEnabled() and statsMoney.get(currType) < money.get(currType): style = getattr(text_styles, 'error') else: style = getattr(text_styles, currType) icon = getattr(icons, currType) value = money.get(currType) formatter = getBWFormatter(currType) if style is not None and icon is not None and value is not None: return style(formatter(value)) + icon() else: _logger.error('Unsupported currency for displaying with icon: %s', currType) return formatter(value)
def canBuyGoldForVehicleThroughWeb(vehicle, itemsCache=None, tradeIn=None): if isIngameShopEnabled() and vehicle.isUnlocked: money = itemsCache.items.stats.money money = tradeIn.addTradeInPriceIfNeeded(vehicle, money) exchangeRate = itemsCache.items.shop.exchangeRate price = getGUIPrice(vehicle, money, exchangeRate) currency = price.getCurrency(byWeight=True) mayObtainForMoney = vehicle.mayObtainWithMoneyExchange( money, exchangeRate) isBuyingAvailable = not vehicle.isHidden or vehicle.isRentable or vehicle.isRestorePossible( ) if currency == Currency.GOLD: if not mayObtainForMoney: if isBuyingAvailable: return True return False
def dropSkills(self, dropSkillCostIdx): tankman = self.itemsCache.items.getTankman(self.tmanInvID) dropSkillCost = self.itemsCache.items.shop.dropSkillsCost[ dropSkillCostIdx].get(Currency.GOLD, 0) currentGold = self.itemsCache.items.stats.gold if currentGold < dropSkillCost and isIngameShopEnabled(): showBuyGoldForCrew(dropSkillCost) return proc = TankmanDropSkills(tankman, dropSkillCostIdx) result = yield proc.request() if result.userMsg: SystemMessages.pushMessage(result.userMsg, type=result.sysMsgType) if result.success: self.onWindowClose() self.fireEvent( events.SkillDropEvent( events.SkillDropEvent.SKILL_DROPPED_SUCCESSFULLY))
def buy(self): if self.__moneyState is _MoneyForPurchase.NOT_ENOUGH: if isIngameShopEnabled(): cart = getTotalPurchaseInfo(self.__purchaseItems) totalPriceGold = cart.totalPrice.price.get(Currency.GOLD, 0) showBuyGoldForCustomization(totalPriceGold) return if self.__moneyState is _MoneyForPurchase.ENOUGH_WITH_EXCHANGE: if self.__isStyle: item = self.__purchaseItems[0].item meta = ExchangeCreditsSingleItemMeta(item.intCD) else: itemsCDs = [ purchaseItem.item.intCD for purchaseItem in self.__purchaseItems ] meta = ExchangeCreditsMultiItemsMeta(itemsCDs, CartInfoItem()) yield DialogsInterface.showDialog(meta) return self.__ctx.applyItems(self.__purchaseItems) self.close()
def _getTrainingButtonsForTankman(costsActual, costsDefault, currentMoney, vehicle=None, tankman=None): ingameShopEnabled = isIngameShopEnabled() trainingButtonsData = [] defaults = vehicle is None or tankman is None roleLevel = 0 sameVehicle = True sameVehicleType = True if not defaults: roleLevel = tankman.roleLevel sameVehicle = vehicle.intCD == tankman.vehicleNativeDescr.type.compactDescr sameVehicleType = sameVehicle if sameVehicle else vehicle.type == tankman.vehicleNativeType for costActual, costDefault in zip(costsActual, costsDefault): moneyDefault = Money(credits=costDefault[Currency.CREDITS] or None, gold=costDefault[Currency.GOLD] or None) moneyActual = Money(credits=costActual[Currency.CREDITS] or None, gold=costActual[Currency.GOLD] or None) trainingLevel = defaultTrainingLevel = costActual['roleLevel'] buttonState = moneyActual <= currentMoney or moneyActual.get( Currency.GOLD) is not None and ingameShopEnabled if not defaults: baseRoleLoss = costActual['baseRoleLoss'] classChangeRoleLoss = costActual['classChangeRoleLoss'] if sameVehicle: trainingLossMultiplier = 0.0 elif sameVehicleType: trainingLossMultiplier = baseRoleLoss else: trainingLossMultiplier = baseRoleLoss + classChangeRoleLoss trainingLevel = roleLevel - roleLevel * trainingLossMultiplier if trainingLevel < defaultTrainingLevel or sameVehicle: trainingLevel = defaultTrainingLevel buttonState = buttonState and ( trainingLevel > roleLevel if sameVehicle else trainingLevel >= defaultTrainingLevel) trainingButtonsData.append( _ButtonData(moneyDefault, moneyActual, trainingLevel, buttonState, sameVehicle)) return trainingButtonsData
def buyTankman(self, nationID, vehTypeID, role, studyType, slot): studyTypeIdx = int(studyType) studyGoldCost = self.itemsCache.items.shop.tankmanCost[studyTypeIdx][ Currency.GOLD] or 0 currentMoney = self.itemsCache.items.stats.money if currentMoney.gold < studyGoldCost and isIngameShopEnabled(): showBuyGoldForCrew(studyGoldCost) return else: if slot is not None and slot != -1: vehicle = self.itemsCache.items.getVehicle( self._currentVehicleInvId) yield self.__buyAndEquipTankman(vehicle, int(slot), studyTypeIdx) else: yield self.__buyTankman(int(nationID), int(vehTypeID), role, studyTypeIdx) self.onWindowClose() return
def getDocumentsData(self, callback): items = self.itemsCache.items tankman = items.getTankman(self.tmanInvID) config = tankmen.getNationConfig(tankman.nationID) if tankman.descriptor.isFemale: shopPrice = items.shop.passportFemaleChangeCost defaultPrice = items.shop.defaults.passportFemaleChangeCost else: shopPrice = items.shop.passportChangeCost defaultPrice = items.shop.defaults.passportChangeCost currentGold = self.itemsCache.items.stats.gold enableSubmitButton = shopPrice <= currentGold or isIngameShopEnabled() action = None if shopPrice != defaultPrice: action = packActionTooltipData(ACTION_TOOLTIPS_TYPE.ECONOMICS, 'passportChangeCost', True, Money(gold=shopPrice), Money(gold=defaultPrice)) callback({ 'money': items.stats.money.toMoneyTuple(), 'passportChangeCost': shopPrice, 'action': action, 'firstnames': self.__getDocGroupValues(tankman, config, operator.attrgetter('firstNamesList'), config.getFirstName), 'lastnames': self.__getDocGroupValues(tankman, config, operator.attrgetter('lastNamesList'), config.getLastName), 'icons': self.__getDocGroupValues(tankman, config, operator.attrgetter('iconsList'), config.getIcon, sortNeeded=False), 'enableSubmitButton': enableSubmitButton }) return
def _populate(self): super(CrystalsPromoWindow, self)._populate() self.as_setDataS({ 'windowTitle': MENU.CRYSTALS_PROMOWINDOW_TITLE, 'headerTF': MENU.CRYSTALS_PROMOWINDOW_HEADER, 'subTitle0': MENU.CRYSTALS_PROMOWINDOW_SUBTITLE0, 'subDescr0': MENU.CRYSTALS_PROMOWINDOW_SUBDESCR0, 'subTitle1': MENU.CRYSTALS_PROMOWINDOW_SUBTITLE1, 'subDescr1': MENU.CRYSTALS_PROMOWINDOW_SUBDESCR1, 'subTitle2': MENU.CRYSTALS_PROMOWINDOW_SUBTITLE2, 'subDescr2': MENU.CRYSTALS_PROMOWINDOW_SUBDESCR2, 'closeBtn': MENU.CRYSTALS_PROMOWINDOW_CLOSEBTN, 'openShopBtnLabel': MENU.CRYSTALS_PROMOWINDOW_OPENSHOPBTNLABEL, 'image0': RES_ICONS.MAPS_ICONS_BATTLETYPES_64X64_RANKED_EPICRANDOM, 'image1': RES_ICONS.MAPS_ICONS_LIBRARY_CRYSTAL_80X80, 'image2': RES_ICONS.MAPS_ICONS_MODULES_LISTOVERLAYSMALL, 'bg': RES_ICONS.MAPS_ICONS_WINDOWS_CRYSTALSPROMOBG, 'showOpenShopBtn': isIngameShopEnabled() })
def packTraining(vehicle, crew=None, itemsCache=None): items = itemsCache.items currentMoney = items.stats.money trainingCostsActual = items.shop.tankmanCost trainingCostsDefault = items.shop.defaults.tankmanCost if crew is not None: tankmansTrainingData = (_getTrainingButtonsForTankman( trainingCostsActual, trainingCostsDefault, currentMoney, vehicle, tankman) for tankman in crew) else: tankmansTrainingData = (_getTrainingButtonsForTankman( trainingCostsActual, trainingCostsDefault, currentMoney), ) result = [] for buttons in zip(*tankmansTrainingData): defaultPrice = min((button.moneyDefault for button in buttons)) actualPrice = max((button.moneyActual for button in buttons)) buttonMinLevel = min((button.trainingLevel for button in buttons)) buttonMaxLevel = max((button.trainingLevel for button in buttons)) buttonState = any((button.state for button in buttons)) allNative = all((button.nativeVehicle for button in buttons)) isRange = crew is not None and len( crew) > 1 and buttonMinLevel != buttonMaxLevel currency = actualPrice.getCurrency() price = actualPrice.getSignValue(actualPrice.getCurrency()) result.append({ 'level': _formatLevel(buttonMinLevel, buttonMaxLevel, isRange), 'enabled': buttonState, 'price': [currency, price], 'isMoneyEnough': currentMoney >= actualPrice or currency == Currency.GOLD and isIngameShopEnabled(), 'isNativeVehicle': allNative, 'nation': vehicle.nationName if vehicle is not None else None, 'showAction': actualPrice != defaultPrice }) return result