Esempio n. 1
0
 def closeWindow(self):
     purchaseItems = self.getPurchaseItems()
     cart = getTotalPurchaseInfo(purchaseItems)
     if cart.numTotal or any(self._cleanSettings(self._currentSettings).itervalues()):
         DialogsInterface.showDialog(I18nConfirmDialogMeta('customization/close'), self.__onConfirmCloseWindow)
     else:
         self.__onConfirmCloseWindow(proceed=True)
    def __onItemsBought(self, purchaseItems, results):
        errorCount = 0
        for result in results:
            if not result.success:
                errorCount += 1
            if result.userMsg:
                SystemMessages.pushI18nMessage(result.userMsg,
                                               type=result.sysMsgType)

        if not errorCount:
            cart = getTotalPurchaseInfo(purchaseItems)
            if cart.totalPrice != ITEM_PRICE_EMPTY:
                msgCtx = {
                    'money': formatPrice(cart.totalPrice.price),
                    'count': cart.numSelected
                }
                SystemMessages.pushI18nMessage(
                    MESSENGER.
                    SERVICECHANNELMESSAGES_SYSMSG_CONVERTER_CUSTOMIZATIONSBUY,
                    type=CURRENCY_TO_SM_TYPE.get(
                        cart.totalPrice.getCurrency(byWeight=True),
                        SM_TYPE.PurchaseForGold),
                    **msgCtx)
            else:
                SystemMessages.pushI18nMessage(
                    MESSENGER.
                    SERVICECHANNELMESSAGES_SYSMSG_CONVERTER_CUSTOMIZATIONS,
                    type=SM_TYPE.Information)
            self.__onCloseWindow(proceed=True)
 def closeWindow(self):
     purchaseItems = self.getPurchaseItems()
     cart = getTotalPurchaseInfo(purchaseItems)
     if cart.numTotal:
         DialogsInterface.showDialog(I18nConfirmDialogMeta('customization/close'), self.__onConfirmCloseWindow)
     else:
         self.__onConfirmCloseWindow(proceed=True)
Esempio n. 4
0
 def __confirmHeaderNavigation(self, callback):
     purchaseItems = self.getPurchaseItems()
     cart = getTotalPurchaseInfo(purchaseItems)
     if cart.numTotal:
         result = yield DialogsInterface.showI18nConfirmDialog('customization/close')
     else:
         result = True
     callback(result)
 def showBuyWindow(self):
     self.__releaseItemSound()
     self.soundManager.playInstantSound(SOUNDS.SELECT)
     purchaseItems = self.getPurchaseItems()
     cart = getTotalPurchaseInfo(purchaseItems)
     if cart.totalPrice == ITEM_PRICE_EMPTY:
         self.buyAndExit(purchaseItems)
     else:
         self.as_hideAnchorPropertySheetS()
         self.fireEvent(events.LoadViewEvent(VIEW_ALIAS.CUSTOMIZATION_PURCHASE_WINDOW), EVENT_BUS_SCOPE.LOBBY)
 def showBuyWindow(self):
     self.changeVisible(False)
     self.__releaseItemSound()
     self.soundManager.playInstantSound(SOUNDS.SELECT)
     purchaseItems = self.__ctx.getPurchaseItems()
     cart = getTotalPurchaseInfo(purchaseItems)
     if cart.totalPrice == ITEM_PRICE_EMPTY:
         self.__ctx.applyItems(purchaseItems)
     else:
         self.fireEvent(
             events.LoadViewEvent(VIEW_ALIAS.CUSTOMIZATION_PURCHASE_WINDOW),
             EVENT_BUS_SCOPE.LOBBY)
    def __setBottomPanelBillData(self, *_):
        purchaseItems = self.__ctx.getPurchaseItems()
        cartInfo = getTotalPurchaseInfo(purchaseItems)
        totalPriceVO = getItemPricesVO(cartInfo.totalPrice)
        if cartInfo.totalPrice != ITEM_PRICE_EMPTY:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_BUY)
        else:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_APPLY)
        tooltip = VEHICLE_CUSTOMIZATION.CUSTOMIZATION_BUYDISABLED_BODY
        fromStorageCount = 0
        toByeCount = 0
        for item in purchaseItems:
            if item.isFromInventory:
                fromStorageCount += 1
            if not item.isDismantling:
                toByeCount += 1

        if fromStorageCount > 0 or toByeCount > 0:
            self.__showBill()
        else:
            self.__hideBill()
            tooltip = VEHICLE_CUSTOMIZATION.CUSTOMIZATION_NOTSELECTEDITEMS
        fromStorageCount = text_styles.stats('({})'.format(fromStorageCount))
        toByeCount = text_styles.stats('({})'.format(toByeCount))
        outfitsModified = self.__ctx.isOutfitsModified()
        self.as_setBottomPanelPriceStateS({
            'buyBtnEnabled':
            outfitsModified,
            'buyBtnLabel':
            label,
            'buyBtnTooltip':
            tooltip,
            'isHistoric':
            self.__ctx.currentOutfit.isHistorical(),
            'billVO': {
                'title':
                text_styles.highlightText(
                    _ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_RESULT)),
                'priceLbl':
                text_styles.main('{} {}'.format(
                    _ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_PRICE), toByeCount)),
                'fromStorageLbl':
                text_styles.main('{} {}'.format(
                    _ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_FROMSTORAGE),
                    fromStorageCount)),
                'isEnoughStatuses':
                getMoneyVO(
                    Money(outfitsModified, outfitsModified, outfitsModified)),
                'pricePanel':
                totalPriceVO[0]
            }
        })
    def buyAndExit(self, purchaseItems):
        self.itemsCache.onSyncCompleted -= self.__onCacheResync
        cart = getTotalPurchaseInfo(purchaseItems)
        groupHasItems = {AdditionalPurchaseGroups.STYLES_GROUP_ID: False,
         SeasonType.WINTER: False,
         SeasonType.SUMMER: False,
         SeasonType.DESERT: False}
        modifiedOutfits = {season:outfit.copy() for season, outfit in self._modifiedOutfits.iteritems()}
        results = []
        for pItem in purchaseItems:
            if not pItem.selected:
                if pItem.slot:
                    slot = modifiedOutfits[pItem.group].getContainer(pItem.areaID).slotFor(pItem.slot)
                    slot.remove(pItem.regionID)
            groupHasItems[pItem.group] = True

        if self._mode == C11nMode.CUSTOM:
            groupHasItems[self._currentSeason] = True
        empty = self.service.getEmptyOutfit()
        for season in SeasonType.COMMON_SEASONS:
            if groupHasItems[season]:
                yield OutfitApplier(g_currentVehicle.item, empty, season).request()

        for season in SeasonType.COMMON_SEASONS:
            if groupHasItems[season]:
                outfit = modifiedOutfits[season]
                result = yield OutfitApplier(g_currentVehicle.item, outfit, season).request()
                results.append(result)

        if groupHasItems[AdditionalPurchaseGroups.STYLES_GROUP_ID]:
            result = yield StyleApplier(g_currentVehicle.item, self._modifiedStyle).request()
            results.append(result)
        errorCount = 0
        for result in results:
            if not result.success:
                errorCount += 1
            if result.userMsg:
                SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType)

        if not errorCount:
            if cart.totalPrice != ITEM_PRICE_EMPTY:
                msgCtx = {'money': formatPrice(cart.totalPrice.price),
                 'count': cart.numSelected}
                SystemMessages.pushI18nMessage(MESSENGER.SERVICECHANNELMESSAGES_SYSMSG_CONVERTER_CUSTOMIZATIONSBUY, type=CURRENCY_TO_SM_TYPE.get(cart.totalPrice.getCurrency(byWeight=True), SM_TYPE.PurchaseForGold), **msgCtx)
            else:
                SystemMessages.pushI18nMessage(MESSENGER.SERVICECHANNELMESSAGES_SYSMSG_CONVERTER_CUSTOMIZATIONS, type=SM_TYPE.Information)
            self.__onConfirmCloseWindow(proceed=True)
        else:
            self.__onCacheResync()
        self.itemsCache.onSyncCompleted += self.__onCacheResync
Esempio n. 9
0
 def __setBuyingPanelData(self, *_):
     purchaseItems = self.getPurchaseItems()
     cartInfo = getTotalPurchaseInfo(purchaseItems)
     totalPriceVO = getItemPricesVO(cartInfo.totalPrice)
     cleanSettings = self._cleanSettings(self._currentSettings, checkSeasons=False)
     keys = []
     if cartInfo.numTotal:
         keys.append('install')
     if cartInfo.totalPrice != ITEM_PRICE_EMPTY:
         self.as_showBuyingPanelS()
     else:
         self.as_hideBuyingPanelS()
     if any(cleanSettings.itervalues()) or not keys:
         keys.append('apply')
     label = g_config.i18n['UI_flash_commit_' + '_and_'.join(keys)]
     isApplyEnabled = bool(cartInfo.numTotal) or any(cleanSettings.itervalues())
     shortage = self.itemsCache.items.stats.money.getShortage(cartInfo.totalPrice.price)
     self.as_setBottomPanelHeaderS({'buyBtnEnabled': isApplyEnabled,
                                    'buyBtnLabel': label,
                                    'enoughMoney': getItemPricesVO(ItemPrice(shortage, shortage))[0],
                                    'pricePanel': totalPriceVO[0]})
    def __setBuyingPanelData(self, *_):
        purchaseItems = self.getPurchaseItems()
        cartInfo = getTotalPurchaseInfo(purchaseItems)
        totalPriceVO = getItemPricesVO(cartInfo.totalPrice)
        accountMoney = self.itemsCache.items.stats.money
        if cartInfo.totalPrice != ITEM_PRICE_EMPTY:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_BUY)
            self.as_showBuyingPanelS()
        else:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_APPLY)
            self.as_hideBuyingPanelS()
        isAtLeastOneOufitNotEmpty = False
        for season in SeasonType.COMMON_SEASONS:
            if not self._modifiedOutfits[season].isEmpty():
                isAtLeastOneOufitNotEmpty = True
                break

        isApplyEnabled = cartInfo.minPriceItem.isDefined() and cartInfo.minPriceItem <= accountMoney or cartInfo.isAtLeastOneItemFromInventory or cartInfo.isAtLeastOneItemDismantled or self._mode == C11nMode.CUSTOM and not self._originalOutfits[self._currentSeason].isInstalled() and isAtLeastOneOufitNotEmpty
        shortage = self.itemsCache.items.stats.money.getShortage(cartInfo.totalPrice.price)
        self.as_setBottomPanelHeaderS({'buyBtnEnabled': isApplyEnabled,
         'buyBtnLabel': label,
         'enoughMoney': getItemPricesVO(ItemPrice(shortage, shortage))[0],
         'pricePanel': totalPriceVO[0]})
    def __setBottomPanelBillData(self, *_):
        purchaseItems = self.__ctx.getPurchaseItems()
        cartInfo = getTotalPurchaseInfo(purchaseItems)
        totalPriceVO = getItemPricesVO(cartInfo.totalPrice)
        if cartInfo.totalPrice != ITEM_PRICE_EMPTY:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_BUY)
        else:
            label = _ms(VEHICLE_CUSTOMIZATION.COMMIT_APPLY)
        money = self.itemsCache.items.stats.money
        exchangeRate = self.itemsCache.items.shop.exchangeRate
        moneyExchanged = money.exchange(Currency.GOLD, Currency.CREDITS, exchangeRate, default=0)
        minPriceItemAvailable = cartInfo.minPriceItem.isDefined() and (cartInfo.minPriceItem <= money or cartInfo.minPriceItem <= moneyExchanged)
        isApplyEnabled = (minPriceItemAvailable or not cartInfo.minPriceItem.isDefined()) and self.__ctx.isOutfitsModified()
        shortage = money.getShortage(cartInfo.totalPrice.price)
        fromStorageCount = 0
        toByeCount = 0
        for item in purchaseItems:
            if item.isFromInventory:
                fromStorageCount += 1
            if not item.isDismantling:
                toByeCount += 1

        if fromStorageCount > 0 or toByeCount > 0:
            self.__showBill()
        else:
            self.__hideBill()
        fromStorageCount = text_styles.stats('({})'.format(fromStorageCount))
        toByeCount = text_styles.stats('({})'.format(toByeCount))
        self.as_setBottomPanelPriceStateS({'buyBtnEnabled': isApplyEnabled,
         'buyBtnLabel': label,
         'isHistoric': self.__ctx.currentOutfit.isHistorical(),
         'billVO': {'title': text_styles.highlightText(_ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_RESULT)),
                    'priceLbl': text_styles.main('{} {}'.format(_ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_PRICE), toByeCount)),
                    'fromStorageLbl': text_styles.main('{} {}'.format(_ms(VEHICLE_CUSTOMIZATION.BUYPOPOVER_FROMSTORAGE), fromStorageCount)),
                    'enoughMoney': getItemPricesVO(ItemPrice(shortage, shortage))[0],
                    'pricePanel': totalPriceVO[0]}})
Esempio n. 12
0
 def buyAndExit(self, purchaseItems):
     self._currentSettings = self._cleanSettings(self._currentSettings)
     for itemsKey in self._currentSettings:
         for camoName in self._currentSettings[itemsKey]:
             g_config.camouflages[itemsKey].setdefault(camoName, {}).update(self._currentSettings[itemsKey][camoName])
     if self._currentSettings['remap']:
         newSettings = {'disable': g_config.disable,
                        'remap': g_config.camouflages['remap']}
         loadJson(g_config.ID, 'settings', newSettings, g_config.configPath, True)
     if self._currentSettings['custom']:
         for confFolderName in g_config.configFolders:
             configFolder = g_config.configFolders[confFolderName]
             loadJson(g_config.ID, 'settings', {key: g_config.camouflages['custom'][key] for key in configFolder},
                      g_config.configPath + 'camouflages/' + confFolderName + '/', True, False)
     if any(self._currentSettings.itervalues()):
         from ..processors import collectCamouflageData
         collectCamouflageData()
     self.itemsCache.onSyncCompleted -= self.__onCacheResync
     boughtOutfits = {season: self.service.getCustomOutfit(season) for season in SeasonType.COMMON_SEASONS}
     cart = getTotalPurchaseInfo(purchaseItems)
     nationName, vehicleName = g_currentVehicle.item.descriptor.name.split(':')
     vehConfig = g_config.outfitCache.get(nationName, {}).get(vehicleName, {})
     for pItem in (x for x in purchaseItems if x.selected):
         seasonName = SEASON_TYPE_TO_NAME[pItem.group]
         if pItem.slot == GUI_ITEM_TYPE.CAMOUFLAGE:
             bItem, bComp = boughtOutfits[pItem.group].getContainer(pItem.areaID).slotFor(pItem.slot)._items.get(
                 pItem.regionID, (None, None))
             component = self._modifiedOutfits[pItem.group].getContainer(pItem.areaID).slotFor(pItem.slot).getComponent(
                 pItem.regionID)
             if pItem.isDismantling and (not bItem or not bComp) or not pItem.isDismantling and pItem.item == bItem and \
                     component.palette == bComp.palette and component.patternSize == bComp.patternSize:
                 vehConfig.get(seasonName, {}).get('camo', {}).pop(TankPartIndexes.getName(pItem.areaID), [])
             else:
                 g_config.outfitCache.setdefault(nationName, {}).setdefault(vehicleName, {}).setdefault(
                     seasonName, {}).setdefault('camo', {})[TankPartIndexes.getName(pItem.areaID)] = (
                     [pItem.item.id, component.palette, component.patternSize] if not pItem.isDismantling else [])
             g_config.hangarCamoCache.get(nationName, {}).get(vehicleName, {}).get(seasonName, {}).pop(
                 TankPartIndexes.getName(pItem.areaID), {})
         else:
             typeName = GUI_ITEM_TYPE_NAMES[pItem.slot]
             bItem = boughtOutfits[pItem.group].getContainer(pItem.areaID).slotFor(pItem.slot).getItem(pItem.regionID)
             if pItem.isDismantling and not bItem or not pItem.isDismantling and pItem.item == bItem:
                 vehConfig.get(seasonName, {}).get(typeName, {}).get(
                     TankPartIndexes.getName(pItem.areaID) if pItem.areaID < 4 else 'misc',
                     {}).pop(str(pItem.regionID), None)
             else:
                 g_config.outfitCache.setdefault(nationName, {}).setdefault(vehicleName, {}).setdefault(
                     seasonName, {}).setdefault(typeName, {}).setdefault(
                     TankPartIndexes.getName(pItem.areaID) if pItem.areaID < 4 else 'misc', {})[
                     str(pItem.regionID)] = (pItem.item.id if not pItem.isDismantling else None)
     for nationName in g_config.outfitCache.keys():
         for vehicleName in g_config.outfitCache[nationName].keys():
             for season in g_config.outfitCache[nationName][vehicleName].keys():
                 for itemType in g_config.outfitCache[nationName][vehicleName][season].keys():
                     if itemType == 'camo':
                         if g_currentVehicle.item.turret.isGunCarriage:
                             g_config.outfitCache[nationName][vehicleName][season][itemType].pop('turret', None)
                     else:
                         for areaName in g_config.outfitCache[nationName][vehicleName][season][itemType].keys():
                             if not g_config.outfitCache[nationName][vehicleName][season][itemType][areaName]:
                                 del g_config.outfitCache[nationName][vehicleName][season][itemType][areaName]
                     if not g_config.outfitCache[nationName][vehicleName][season][itemType]:
                         del g_config.outfitCache[nationName][vehicleName][season][itemType]
                 if not g_config.outfitCache[nationName][vehicleName][season]:
                     del g_config.outfitCache[nationName][vehicleName][season]
             if not g_config.outfitCache[nationName][vehicleName]:
                 del g_config.outfitCache[nationName][vehicleName]
         if not g_config.outfitCache[nationName]:
             del g_config.outfitCache[nationName]
     loadJson(g_config.ID, 'outfitCache', g_config.outfitCache, g_config.configPath, True)
     if cart.totalPrice != ITEM_PRICE_EMPTY:
         msgCtx = {'money': formatPrice(cart.totalPrice.price),
                   'count': cart.numSelected}
         SystemMessages.pushMessage(g_config.i18n['UI_flashCol_applied_money'] % msgCtx,
                                    type=CURRENCY_TO_SM_TYPE.get(cart.totalPrice.getCurrency(byWeight=True),
                                                                 SM_TYPE.PurchaseForGold))
     else:
         SystemMessages.pushI18nMessage(MESSENGER.SERVICECHANNELMESSAGES_SYSMSG_CONVERTER_CUSTOMIZATIONS,
                                        type=SM_TYPE.Information)
     self.__onCacheResync()
     self.itemsCache.onSyncCompleted += self.__onCacheResync