def getFilterRadioButtons(): result = [{'label': NY.getNationFilterLabel('all')}] for settingName in SORTED_NATIONS_SETTINGS: locKey = SETTINGS_TO_LOCALIZATIONS_MAP.get(settingName, settingName) result.append({'label': NY.getNationFilterLabel(locKey)}) return result
def __onSysMsgReceived(self, _, message): if message.type == _TOKEN_SYS_MSG_TYPE: if 'completedQuestIDs' in message.data: completedQuestIDs = message.data['completedQuestIDs'] collectionRewardsSet = set(self.__nyCtrl.collectionRewardsBySettingID) passedCollectionRewards = completedQuestIDs.intersection(collectionRewardsSet) if passedCollectionRewards: _ms = i18n.makeString for reward in passedCollectionRewards: settingName = NATIONAL_SETTINGS[self.__nyCtrl.collectionRewardsBySettingID.index(reward)] self.__nyCtrl.proto.serviceChannel.pushClientMessage('', SCH_CLIENT_MSG_TYPE.NY_SETTING_COLLECTED, auxData=makeHtmlString('html_templates:newYear/sysMsgs', 'settingCollectedBody', {'setting': _ms(NY.system_messages_setting_name(settingName)), 'styles': _ms(VEHICLE_CUSTOMIZATION.getStyleName(settingName)), 'titles': _ms(NY.system_messages_setting_collected_titles(settingName)), 'emblem': _ms(NY.system_messages_setting_collected_emblem(settingName))}))
def __updateData(self): data = _DATA_TEMPLATE data['rewardsTotal'] = 'x{}'.format( self.__rewardsTotal) if self.__rewardsTotal > 1 else '' if self.__setting in NATIONAL_SETTINGS: windowTitle = NY.MISSIONREWARDWINDOW_TITLE_SETTING header = NY.MISSIONREWARDWINDOW_HEADER_SETTING boxName = _ms(NY.missionrewardwindow_boxname(self.__setting)) if constants.IS_SINGAPORE: description = _ms( NY.MISSIONREWARDWINDOW_ASIA_DESCRIPTION_SETTING, boxName=boxName) else: description = _ms(NY.MISSIONREWARDWINDOW_DESCRIPTION_SETTING, boxName=boxName) else: windowTitle = NY.MISSIONREWARDWINDOW_TITLE_ANY header = NY.MISSIONREWARDWINDOW_HEADER_ANY description = NY.MISSIONREWARDWINDOW_DESCRIPTION_ANY hasBoxes = self._newYearController.boxStorage.getItemIDBySetting( self.__setting) data['windowTitle'] = windowTitle data['header'] = header data['description'] = description data['setting'] = self.__setting data[ 'warningLabel'] = '' if hasBoxes else NY.MISSIONREWARDWINDOW_WARNING_NOITEMS self.as_setDataS(data)
def __makeVO(self, slotID, item): toys = self.newYearController.getToysForSlot(slotID) toysCount = sum((toy.count for toy in toys)) toyNewCount = sum((toy.newCount for toy in toys)) slotType = g_cache.slots[slotID].type res = { 'id': slotID, 'slotType': slotType, 'availableToysCount': toysCount, 'newToyCount': toyNewCount, 'tooltip': makeTooltip(_ms(NY.decorations_tooltip_empty_header(slotType)), _ms(NY.DECORATIONS_TOOLTIP_EMPTY_BODY)) } if item.id != INVALID_TOY_ID: res.update({ 'toyIcon': item.icon or item.slotIcon, 'toyId': str(item.id), 'toyLevel': item.rank, 'settings': item.setting }) return res
def __updateDataByLevel(self, rank): outcome = [] alreadyReceived = self._newYearController.receivedToysCollection receivedCount, totalCount, toysBySetting = self.__settingData bonuses = self._newYearController.getBonusesForSetting( NATIONAL_SETTINGS_IDS_BY_NAME[self.__selectedSetting]) bonus = int(bonuses[0] * 100.0) if bonuses else 0 for toy in toysBySetting: if toy.rank == rank: outcome.append({ 'id': toy.id, 'icon': toy.icon, 'isReceived': toy.id in alreadyReceived }) progress = _ms(NY.COLLECTIONS_STATUS, value=text_styles.stats(str(receivedCount)), max=totalCount) bonusCount = makeHtmlString('html_templates:newYear/collectionBonus', 'big', {'bonus': bonus}) levelData = { 'progress': progress, 'setting': self.__selectedSetting, 'title': _ms(NY.COLLECTIONS_TITLE, setting=_ms(NY.collections_title(self.__selectedSetting))), 'subTitle': NY.collections_level(rank), 'toys': outcome, 'bonusCount': bonusCount, 'isCollected': totalCount == receivedCount } self.as_setLevelDataS(levelData)
def __commonResponseHandler(self, response, ctx): """ Processes common errors. :param response: gui.shared.utils.requesters.abstract.Response :param ctx: new_year.requester.ny_contexts.CommonNYContext :return: True if error has been successfully processed, otherwise False """ if not response.isSuccess(): if response.getCode() == RES_FAILURE: errMsg = NY.system_messages_request_error( response.getTxtString()) if errMsg: SystemMessages.pushI18nMessage( errMsg, type=SystemMessages.SM_TYPE.Error) return True else: return False
def _buildBlocks(self, setting): nyLevelMax = 10 nationId = NATIONAL_SETTINGS_IDS_BY_NAME[setting] settingsIcon = TOOLTIP_SETTINGS_ICON_BY_NATION_ID[nationId] bonuses = self._newYearController.getBonusesForSetting( NATIONAL_SETTINGS_IDS_BY_NAME[setting]) nyLevel, _, nyProgress, nyBound = self._newYearController.getProgress() currentLevel = self._newYearController.getCollectionLevelForNation( nationId) nextLevel = currentLevel + 1 if currentLevel < len( BOUND_COLLECTION_RATING_BY_LEVEL) else len( BOUND_COLLECTION_RATING_BY_LEVEL) currentRating = self._newYearController.getCollectionRatingForNation( nationId) nextRating = BOUND_COLLECTION_RATING_BY_LEVEL[nextLevel - 1] decorationsAmount = nextRating - currentRating if nextRating > currentRating else 0 bonusValue = self._newYearController.calculateBonusesForCollectionLevel( nextLevel)[0] * 100 headerBlock = [ formatters.packImageTextBlockData( img=settingsIcon, title=text_styles.highTitle( NY.collections_tooltip_bonusinfo_header(setting)), desc=text_styles.standard( _ms(NY.COLLECTIONS_TOOLTIP_BONUSINFO_DESCR)), imgPadding=formatters.packPadding(left=4, top=-3), txtGap=-2, txtOffset=65, padding=formatters.packPadding(top=0, bottom=16)), self.__makeBonusBlock( bonuses[0], RES_ICONS.MAPS_ICONS_NY_ICONS_ICON_BUTTONS_ADD_EXP, NY.COLLECTIONS_TOOLTIP_BONUSINFO_BONUSES_VEHICLE), self.__makeBonusBlock( bonuses[3], RES_ICONS.MAPS_ICONS_NY_ICONS_ICON_BUTTONS_ADD_CREDITS, NY.COLLECTIONS_TOOLTIP_BONUSINFO_BONUSES_CREDITS), self.__makeBonusBlock( bonuses[1], RES_ICONS.MAPS_ICONS_NY_ICONS_ICON_BUTTONS_ADD_EXP_CREW, NY.COLLECTIONS_TOOLTIP_BONUSINFO_BONUSES_CREW) ] bottomBlock = list() bottomBlock.append( formatters.packTextBlockData(text=text_styles.middleTitle( NY.COLLECTIONS_TOOLTIP_BONUSINFO_BOTTOM_HEADER))) gotDecorations = decorationsAmount > 0 if gotDecorations: bottomBlock.append( formatters.packTextBlockData(text=text_styles.main( _ms(NY.COLLECTIONS_TOOLTIP_BONUSINFO_BOTTOM_LINE1, bonus=bonusValue, count=text_styles.neutral( _ms(NY. COLLECTIONS_TOOLTIP_BONUSINFO_BOTTOM_DECORATIONS, count=decorationsAmount)))))) reachedMaxLevel = nyLevel >= nyLevelMax if not reachedMaxLevel: bottomBlock.append( formatters.packTextBlockData(text=text_styles.main( _ms(NY.COLLECTIONS_TOOLTIP_BONUSINFO_BOTTOM_LINE2, level=nyLevel)))) items = list() items.append(formatters.packBuildUpBlockData(headerBlock)) items.append( formatters.packBuildUpBlockData( _makeNationBlock( NY.COLLECTIONS_TOOLTIP_BONUSINFO_NATIONS_HEADER, setting), linkage=BLOCKS_TOOLTIP_TYPES. TOOLTIP_BUILDUP_BLOCK_WHITE_BG_LINKAGE, padding=formatters.packPadding(left=65))) if gotDecorations or not reachedMaxLevel: items.append( formatters.packBuildUpBlockData( bottomBlock, padding=formatters.packPadding(left=65))) return items
def __onBoxesCountChanged(self, _, __, addedInfo): descriptors = self.__nyCtrl.boxStorage.getDescriptors() for k, v in addedInfo.iteritems(): boxDescr = descriptors.get(k) if boxDescr: if boxDescr.present: self.__nyCtrl.proto.serviceChannel.pushClientMessage('', SCH_CLIENT_MSG_TYPE.NY_PRESENT_BOX_RECEIVED, auxData=makeHtmlString('html_templates:newYear/sysMsgs', 'presentFromFriendBody', {'setting': i18n.makeString(NY.system_messages_presentbox_setting_name(boxDescr.setting)), 'count': v})) else: LOG_WARNING("Couldn't find descriptor for box '{}'".format(k))
def __getRewardsVO(self): rewards = [] chests_decrs = sorted( self._newYearController.chestStorage.getDescriptors().itervalues(), key=lambda v: v.level) hidden_quests = self._eventsCache.getHiddenQuests() for chestDescr in chests_decrs: quest_id = chestDescr.id hasChests = self._newYearController.chestStorage.hasItem( chestDescr.id) nyQuest = hidden_quests.get(quest_id, None) if nyQuest is None: LOG_ERROR('Quest "{}" has not been found!'.format(quest_id)) return [] lvl = chestDescr.level bonuses = nyQuest.getBonuses() state = self.__getStateByLevel(lvl) isLevelMax = lvl == self.__nyMaxLevel vehicleName = '' tankIcon = '' vehicleUnknown = False tooltipBody = '' tooltipHeader = '' vehicleLevel = _ms(TOOLTIPS.level(lvl)) vehDiscountStatus = NY_CONSTANTS.NY_VEHICLE_DISCOUNT_NOT_AVAILABLE vehDiscount = self._newYearController.vehDiscountsStorage.extractDiscountValueByLevel( lvl) if lvl == 1: vehDiscountStatus = NY_CONSTANTS.NY_VEHICLE_DISCOUNT_AVAILABLE if hasChests else NY_CONSTANTS.NY_VEHICLE_DISCOUNT_APPLIED for idx, bonus in enumerate(bonuses): if isinstance(bonus, VehiclesBonus): vehicle = bonus.getVehicles()[0][0] vehicleName = vehicle.shortUserName vehicleLevel = _ms(TOOLTIPS.level(vehicle.level)) tankIcon = vehicle.icon tooltipHeader = _ms( NY.REWARDSSCREEN_TOOLTIP_GIFT_VEHICLE_HEADER) tooltipBody = _ms( NY.REWARDSSCREEN_TOOLTIP_GIFT_VEHICLE_BODY, name=vehicleName, level=vehicleLevel) bonuses.pop(idx) break else: if vehDiscount is not None: hasVehicleDiscounts = self._newYearController.vehDiscountsStorage.getDiscounts( ).get(self.__getVariadicDiscountIdByLvl(lvl), 0) > 0 levelAchieved = state != NY_CONSTANTS.REWARDS_LEVEL_NEXT if levelAchieved: vehDiscountStatus = self.__getVehicleDiscountStatus( hasChests, hasVehicleDiscounts) tankDiscountApplied = levelAchieved and not hasVehicleDiscounts and not hasChests if tankDiscountApplied: discountVehicle = self.__getPersonalDiscountVehicle( self._newYearController.vehDiscountsStorage. getClientDiscountsCache()[lvl - 1]) if discountVehicle is not None: vehicleName = discountVehicle.shortUserName tankIcon = discountVehicle.icon else: discountVehicle = self._newYearController.vehDiscountsStorage.getBoughtVehicle( lvl - 1) if discountVehicle: vehicleName = discountVehicle.shortUserName tankIcon = discountVehicle.icon else: tankIcon = RES_ICONS.MAPS_ICONS_NY_REWARDS_NY_REWARD_UNKNOWN_TANK vehicleUnknown = True else: tankIcon = RES_ICONS.MAPS_ICONS_NY_REWARDS_NY_REWARD_UNKNOWN_TANK else: tankDiscountApplied = True vehDiscountStatus = NY_CONSTANTS.NY_VEHICLE_DISCOUNT_APPLIED if tankDiscountApplied: if vehicleUnknown: tooltipBody = _ms( NY. REWARDSSCREEN_TOOLTIP_VEHICLEUNKNOWN_APPLIED_BODY, discount=vehDiscount) else: tooltipBody = _ms( NY.REWARDSSCREEN_TOOLTIP_VEHICLE_APPLIED_BODY, discount=vehDiscount, name=vehicleName) else: tooltipBody = _ms(NY.REWARDSSCREEN_TOOLTIP_VEHICLE_BODY, discount=vehDiscount, level=vehicleLevel) tooltipHeader = _ms(NY.REWARDSSCREEN_TOOLTIP_VEHICLE_HEADER, level=vehicleLevel) data = { 'state': state, 'level': lvl, 'levelStr': NY.atmosphere_level(lvl), 'isLevelMax': isLevelMax, 'vehicleLevel': vehicleLevel, 'vehicleName': vehicleName, 'discount': vehDiscount, 'tankIcon': tankIcon, 'vehDiscountStatus': vehDiscountStatus, 'tankWoman': self.__getTankWoman(lvl, not hasChests), 'bonuses': _BONUS_FORMATTER.getFormattedBonuses(bonuses), 'tooltip': makeTooltip(tooltipHeader, tooltipBody) } rewards.append(data) return rewards