def updateList(self): directions = [] openedDirectionsCount = len(self.fortCtrl.getFort().getOpenedDirections()) fightsForDirections = self.fortCtrl.getFort().getDirectionsInBattle() for direction in range(1, g_fortCache.maxDirections + 1): buildings = self.fortCtrl.getFort().getBuildingsByDirections().get(direction) isOpened = buildings is not None inBattle = direction in fightsForDirections canBeClosed = isOpened and not inBattle and findFirst(lambda b: b is not None, buildings) is None buildingsData = [] if isOpened: for building in buildings: data = None if building is not None: uid = self.getBuildingUIDbyID(building.typeID) data = {'uid': uid, 'progress': self._getProgress(building.typeID, building.level), 'toolTipData': [i18n.makeString('#fortifications:Buildings/buildingName/%s' % uid), self.getCommonBuildTooltipData(building)], 'iconSource': FortViewHelper.getSmallIconSource(uid, building.level)} buildingsData.append(data) directions.append({'uid': direction, 'fullName': i18n.makeString('#fortifications:General/direction', value=i18n.makeString('#fortifications:General/directionName%d' % direction)), 'isOpened': isOpened, 'canBeClosed': canBeClosed, 'closeButtonVisible': isOpened and openedDirectionsCount > 1, 'buildings': buildingsData}) self.as_setDirectionsS(directions) return
def __listFields(self, id, name, shortDescr, status, buildingStatus, isNewItem): return {'buildingID': id, 'buildingName': name, 'shortDescr': shortDescr, 'statusLbl': status, 'buildingStatus': buildingStatus, 'isNewItem': isNewItem, 'buildingIcon': FortViewHelper.getSmallIconSource(id, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxFortLevel)}
def __listFields(self, id, name, shortDescr, status, buildingStatus, isNewItem): return {'buildingID': id, 'buildingName': name, 'shortDescr': shortDescr, 'statusLbl': status, 'buildingStatus': buildingStatus, 'isNewItem': isNewItem, 'buildingIcon': FortViewHelper.getSmallIconSource(id, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxFortLevel)}
def updateList(self): directions = [] openedDirectionsCount = len( self.fortCtrl.getFort().getOpenedDirections()) fightsForDirections = self.fortCtrl.getFort().getDirectionsInBattle() for direction in range(1, g_fortCache.maxDirections + 1): buildings = self.fortCtrl.getFort().getBuildingsByDirections().get( direction) isOpened = buildings is not None inBattle = direction in fightsForDirections canBeClosed = isOpened and not inBattle and findFirst( lambda b: b is not None, buildings) is None buildingsData = [] if isOpened: for building in buildings: data = None if building is not None: uid = self.getBuildingUIDbyID(building.typeID) data = { 'uid': uid, 'progress': self._getProgress(building.typeID, building.level), 'toolTipData': [ i18n.makeString( '#fortifications:Buildings/buildingName/%s' % uid), self.getCommonBuildTooltipData(building) ], 'iconSource': FortViewHelper.getSmallIconSource( uid, building.level) } buildingsData.append(data) directions.append({ 'uid': direction, 'fullName': i18n.makeString('#fortifications:General/direction', value=i18n.makeString( '#fortifications:General/directionName%d' % direction)), 'isOpened': isOpened, 'canBeClosed': canBeClosed, 'closeButtonVisible': isOpened and openedDirectionsCount > 1, 'buildings': buildingsData }) self.as_setDirectionsS(directions) return
def __makeBuildingData(self, buildingID, isAttack, level, isLooted, isAvailable): (curBuildingId, _, _), curBuildingIsAttack = self.__currentBuilding fort = self.fortCtrl.getFort() inProcess, _ = fort.getDefenceHourProcessing() isDefenceOn = fort.isDefenceHourEnabled() or inProcess uid = self.getBuildingUIDbyID(buildingID) return {'uid': uid, 'progress': self._getProgress(buildingID, level), 'buildingLevel': level, 'underAttack': curBuildingId == buildingID and curBuildingIsAttack == isAttack, 'looted': isLooted, 'isAvailable': isAvailable, 'iconSource': FortViewHelper.getSmallIconSource(uid, level, isDefenceOn)}
def __getDirectionBuildings(self, direction): buildings = [None, None] for buildingID, buildingData in self.__item.getDictBuildingsBrief().iteritems(): dir = getDirectionFromDirPos(buildingData['dirPosByte']) if direction == dir: pos = getPositionFromDirPos(buildingData['dirPosByte']) level = buildingData['level'] uid = self.getBuildingUIDbyID(buildingID) buildings[pos] = {'uid': uid, 'progress': self._getProgress(buildingID, level), 'buildingLevel': level, 'iconSource': FortViewHelper.getSmallIconSource(uid, level)} return buildings
def __makeBuildingData(self, buildingID, isAttack, level, isLooted, isAvailable): (curBuildingId, _, _), curBuildingIsAttack = self.__currentBuilding fort = self.fortCtrl.getFort() inProcess, _ = fort.getDefenceHourProcessing() isDefenceOn = fort.isDefenceHourEnabled() or inProcess uid = self.getBuildingUIDbyID(buildingID) return { "uid": uid, "progress": self._getProgress(buildingID, level), "buildingLevel": level, "underAttack": curBuildingId == buildingID and curBuildingIsAttack == isAttack, "looted": isLooted, "isAvailable": isAvailable, "iconSource": FortViewHelper.getSmallIconSource(uid, level, isDefenceOn), }
def __makeSettingsBlockVO(self, isTopBlock): if isTopBlock: minFortLevel = FORT_BATTLE_DIVISIONS.CHAMPION.minFortLevel maxFortLevel = FORT_BATTLE_DIVISIONS.CHAMPION.maxFortLevel defenceTankIcon = attackTankIconTop = self.__makeTankIconVO( False, FORT_BATTLE_DIVISIONS.CHAMPION.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_USA_A12_T32, fort_formatters.getIconLevel( FORT_BATTLE_DIVISIONS.CHAMPION.iconLevel), FORT_BATTLE_DIVISIONS.CHAMPION.divisionID) attackTankIconBottom = self.__makeTankIconVO( True, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_USSR_T62A, fort_formatters.getIconLevel( FORT_BATTLE_DIVISIONS.ABSOLUTE.iconLevel), FORT_BATTLE_DIVISIONS.ABSOLUTE.divisionID) else: minFortLevel = FORT_BATTLE_DIVISIONS.ABSOLUTE.minFortLevel maxFortLevel = FORT_BATTLE_DIVISIONS.ABSOLUTE.maxFortLevel defenceTankIcon = attackTankIconTop = self.__makeTankIconVO( False, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_USSR_T62A, fort_formatters.getIconLevel( FORT_BATTLE_DIVISIONS.ABSOLUTE.iconLevel), FORT_BATTLE_DIVISIONS.ABSOLUTE.divisionID) attackTankIconBottom = self.__makeTankIconVO( True, FORT_BATTLE_DIVISIONS.CHAMPION.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_USA_A12_T32, fort_formatters.getIconLevel( FORT_BATTLE_DIVISIONS.CHAMPION.iconLevel), FORT_BATTLE_DIVISIONS.CHAMPION.divisionID) return { 'startLvlSrc': fort_formatters.getIconLevel(minFortLevel), 'endLvlSrc': fort_formatters.getIconLevel(maxFortLevel), 'buildingIcon': FortViewHelper.getSmallIconSource( FORTIFICATION_ALIASES.FORT_BASE_BUILDING, maxFortLevel), 'lvlDashTF': text_styles.stats('-'), 'defenceTankIcon': defenceTankIcon, 'attackTankIconTop': attackTankIconTop, 'attackTankIconBottom': attackTankIconBottom }
def __makeSettingsBlockVO(self, isTopBlock): if isTopBlock: minFortLevel = FORT_BATTLE_DIVISIONS.CHAMPION.minFortLevel maxFortLevel = FORT_BATTLE_DIVISIONS.CHAMPION.maxFortLevel defenceTankIcon = attackTankIconTop = self.__makeTankIconVO(False, FORT_BATTLE_DIVISIONS.CHAMPION.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_USA_A12_T32, fort_formatters.getIconLevel(FORT_BATTLE_DIVISIONS.CHAMPION.iconLevel), FORT_BATTLE_DIVISIONS.CHAMPION.divisionID) attackTankIconBottom = self.__makeTankIconVO(True, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_USSR_T62A, fort_formatters.getIconLevel(FORT_BATTLE_DIVISIONS.ABSOLUTE.iconLevel), FORT_BATTLE_DIVISIONS.ABSOLUTE.divisionID) else: minFortLevel = FORT_BATTLE_DIVISIONS.ABSOLUTE.minFortLevel maxFortLevel = FORT_BATTLE_DIVISIONS.ABSOLUTE.maxFortLevel defenceTankIcon = attackTankIconTop = self.__makeTankIconVO(False, FORT_BATTLE_DIVISIONS.ABSOLUTE.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_USSR_T62A, fort_formatters.getIconLevel(FORT_BATTLE_DIVISIONS.ABSOLUTE.iconLevel), FORT_BATTLE_DIVISIONS.ABSOLUTE.divisionID) attackTankIconBottom = self.__makeTankIconVO(True, FORT_BATTLE_DIVISIONS.CHAMPION.maxCombatants, RES_ICONS.MAPS_ICONS_LIBRARY_USA_A12_T32, fort_formatters.getIconLevel(FORT_BATTLE_DIVISIONS.CHAMPION.iconLevel), FORT_BATTLE_DIVISIONS.CHAMPION.divisionID) return {'startLvlSrc': fort_formatters.getIconLevel(minFortLevel), 'endLvlSrc': fort_formatters.getIconLevel(maxFortLevel), 'buildingIcon': FortViewHelper.getSmallIconSource(FORTIFICATION_ALIASES.FORT_BASE_BUILDING, maxFortLevel), 'lvlDashTF': text_styles.stats('-'), 'defenceTankIcon': defenceTankIcon, 'attackTankIconTop': attackTankIconTop, 'attackTankIconBottom': attackTankIconBottom}
def _updateDirections(self): directions = [] selectedDirection = -1 fort = self.fortCtrl.getFort() inProcess, _ = fort.getDefenceHourProcessing() isDefenceOn = fort.isDefenceHourEnabled() or inProcess enemyBuildings = [None, None] for buildingID, buildingData in self.__item.getDictBuildingsBrief( ).iteritems(): dirId = getDirectionFromDirPos(buildingData['dirPosByte']) if self.__direction == dirId: pos = getPositionFromDirPos(buildingData['dirPosByte']) level = buildingData['level'] if 0 <= level < 5: isAvailable = False else: isAvailable = self.__isBuildingAvailableForAttack( buildingData['hp'], g_fortCache.buildings[buildingID].levels[level].hp) uid = self.getBuildingUIDbyID(buildingID) enemyBuildings[pos] = { 'uid': uid, 'progress': self._getProgress(buildingID, level), 'buildingLevel': level, 'isAvailable': isAvailable, 'iconSource': FortViewHelper.getSmallIconSource(uid, level, isDefenceOn) } enemyDirection = { 'name': _ms('#fortifications:General/directionName%d' % self.__direction), 'isMine': False, 'buildings': enemyBuildings } for direction in range(1, g_fortCache.maxDirections + 1): isOpened = fort.isDirectionOpened(direction) isBusy = False availableTime = None name = _ms('#fortifications:General/directionName%d' % direction) ttHeader = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_HEADER) ttBody = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_BODY) infoMessage = '' allieBuildings = [] if isOpened: for building in fort.getBuildingsByDirections().get( direction, ()): data = None if building is not None: buildingTypeId = building.typeID uid = self.getBuildingUIDbyID(buildingTypeId) level = building.level data = { 'uid': uid, 'progress': self._getProgress(buildingTypeId, level), 'buildingLevel': level, 'isAvailable': self.__isBuildingAvailableForAttack( building.hp, building.levelRef.hp), 'iconSource': FortViewHelper.getSmallIconSource( uid, level, isDefenceOn) } allieBuildings.append(data) eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction availableTime, _, _ = fort.events.get(eventTypeID, (None, None, None)) if availableTime <= self.__selectedDayStart: availableTime = None if availableTime is None: attackerClanName = None todayAttacks = fort.getAttacks( filterFunc=lambda a: self.__selectedDayStart <= a. getStartTime( ) <= self.__selectedDayFinish and a.isPlanned()) roamingDateAttacks = fort.getAttacks( filterFunc=lambda a: a.getStartTime() - time_utils. ONE_DAY < self.__defHourStart < a.getStartTime( ) + time_utils.ONE_DAY and a.isPlanned()) for attack in todayAttacks + roamingDateAttacks: if direction == attack.getDirection(): isBusy = True _, defClanAbbrev, _ = attack.getOpponentClanInfo() attackerClanName = '[%s]' % defClanAbbrev if isBusy: ttHeader = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_HEADER ) ttBody = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_BODY, clanName=attackerClanName) else: clanForAttackTag = '[%s]' % self.__item.getClanAbbrev() ttHeader = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_HEADER, direction=name) ttBody = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_BODY, direction=name, clanName=clanForAttackTag) else: infoMessage = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_DIRECTION_NOTAVAILABLE, date=BigWorld.wg_getShortDateFormat(availableTime)) ttHeader = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_HEADER ) ttBody = _ms( FORTIFICATIONS. FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_BODY, date=BigWorld.wg_getShortDateFormat(availableTime)) if not isBusy and selectedDirection == -1: selectedDirection = direction directions.append({ 'leftDirection': { 'name': name, 'uid': direction, 'isOpened': isOpened, 'isBusy': isBusy or availableTime is not None, 'buildings': allieBuildings, 'ttHeader': ttHeader, 'ttBody': ttBody, 'infoMessage': infoMessage }, 'rightDirection': enemyDirection, 'connectionIcon': RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_OFFENCE }) self.as_setDirectionsS(directions) self.as_selectDirectionS(selectedDirection) return
def _updateDirections(self): directions = [] selectedDirection = -1 fort = self.fortCtrl.getFort() inProcess, _ = fort.getDefenceHourProcessing() isDefenceOn = fort.isDefenceHourEnabled() or inProcess enemyBuildings = [None, None] for buildingID, buildingData in self.__item.getDictBuildingsBrief().iteritems(): dirId = getDirectionFromDirPos(buildingData['dirPosByte']) if self.__direction == dirId: pos = getPositionFromDirPos(buildingData['dirPosByte']) level = buildingData['level'] if 0 <= level < 5: isAvailable = False else: isAvailable = self.__isBuildingAvailableForAttack(buildingData['hp'], g_fortCache.buildings[buildingID].levels[level].hp) uid = self.getBuildingUIDbyID(buildingID) enemyBuildings[pos] = {'uid': uid, 'progress': self._getProgress(buildingID, level), 'buildingLevel': level, 'isAvailable': isAvailable, 'iconSource': FortViewHelper.getSmallIconSource(uid, level, isDefenceOn)} enemyDirection = {'name': _ms('#fortifications:General/directionName%d' % self.__direction), 'isMine': False, 'buildings': enemyBuildings} for direction in range(1, g_fortCache.maxDirections + 1): isOpened = fort.isDirectionOpened(direction) isBusy = False availableTime = None name = _ms('#fortifications:General/directionName%d' % direction) ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_HEADER) ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_BODY) infoMessage = '' allieBuildings = [] if isOpened: for building in fort.getBuildingsByDirections().get(direction, ()): data = None if building is not None: buildingTypeId = building.typeID uid = self.getBuildingUIDbyID(buildingTypeId) level = building.level data = {'uid': uid, 'progress': self._getProgress(buildingTypeId, level), 'buildingLevel': level, 'isAvailable': self.__isBuildingAvailableForAttack(building.hp, building.levelRef.hp), 'iconSource': FortViewHelper.getSmallIconSource(uid, level, isDefenceOn)} allieBuildings.append(data) eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction availableTime, _, _ = fort.events.get(eventTypeID, (None, None, None)) if availableTime <= self.__selectedDayStart: availableTime = None if availableTime is None: attackerClanName = None todayAttacks = fort.getAttacks(filterFunc=lambda a: self.__selectedDayStart <= a.getStartTime() <= self.__selectedDayFinish and a.isPlanned()) roamingDateAttacks = fort.getAttacks(filterFunc=lambda a: a.getStartTime() - time_utils.ONE_DAY < self.__defHourStart < a.getStartTime() + time_utils.ONE_DAY and a.isPlanned()) for attack in todayAttacks + roamingDateAttacks: if direction == attack.getDirection(): isBusy = True _, defClanAbbrev, _ = attack.getOpponentClanInfo() attackerClanName = '[%s]' % defClanAbbrev if isBusy: ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_HEADER) ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_BODY, clanName=attackerClanName) else: clanForAttackTag = '[%s]' % self.__item.getClanAbbrev() ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_HEADER, direction=name) ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_BODY, direction=name, clanName=clanForAttackTag) else: infoMessage = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_DIRECTION_NOTAVAILABLE, date=BigWorld.wg_getShortDateFormat(availableTime)) ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_HEADER) ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_BODY, date=BigWorld.wg_getShortDateFormat(availableTime)) if not isBusy and selectedDirection == -1: selectedDirection = direction directions.append({'leftDirection': {'name': name, 'uid': direction, 'isOpened': isOpened, 'isBusy': isBusy or availableTime is not None, 'buildings': allieBuildings, 'ttHeader': ttHeader, 'ttBody': ttBody, 'infoMessage': infoMessage}, 'rightDirection': enemyDirection, 'connectionIcon': RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_OFFENCE}) self.as_setDirectionsS(directions) self.as_selectDirectionS(selectedDirection) return