def init(self): result = super(BattleLayout, self).init() if result: g_sessionProvider.getCtx().setNormalizePlayerName(normalizePlayerName) g_tutorialWeaver.weave('gui.WindowsManager', 'WindowsManager', '^showBattle$', aspects=[ShowBattleAspect]) g_tutorialWeaver.weave('gui.Scaleform.Minimap', 'Minimap', '^getStoredMinimapSize|storeMinimapSize$', aspects=[MinimapDefaultSizeAspect(self.uiHolder)]) return result
def init(self): result = super(BattleLayout, self).init() if result: g_sessionProvider.getCtx().setPlayerFullNameFormatter(TutorialFullNameFormatter()) g_tutorialWeaver.weave('gui.app_loader', '_AppLoader', '^showBattle$', aspects=(ShowBattleAspect,)) g_tutorialWeaver.weave('gui.Scaleform.Minimap', 'Minimap', '^getStoredMinimapSize|storeMinimapSize$', aspects=(MinimapDefaultSizeAspect(self.uiHolder),)) return result
def fini(self, isItemsRevert = True): g_sessionProvider.getCtx().resetNormalizePlayerName() dispatcher = self.getDispatcher() if dispatcher is not None: dispatcher.dispossessUI() dispatcher.clearGUI() super(BattleLayout, self).fini(isItemsRevert=isItemsRevert)
def init(self): """ Initializes GUI. :return: True if gui proxy is inited, otherwise - False. """ result = False addListener = g_eventBus.addListener addListener(_Event.COMPONENT_REGISTERED, self.__onComponentRegistered, scope=EVENT_BUS_SCOPE.GLOBAL) addListener(_Event.COMPONENT_UNREGISTERED, self.__onComponentUnregistered, scope=EVENT_BUS_SCOPE.GLOBAL) if self.app is not None: proxy = weakref.proxy(self.app) for effect in self.__effects.filterByName(GUI_EFFECT_NAME.SHOW_DIALOG): effect.setApplication(proxy) self.__markersManager = _MarkerManagerProxy(proxy) addSettings = g_entitiesFactories.addSettings try: for item in self.getViewSettings(): addSettings(item) result = True except Exception: LOG_CURRENT_EXCEPTION() if result: g_sessionProvider.getCtx().setPlayerFullNameFormatter(TutorialFullNameFormatter()) return result
def fini(self): if self.__minimap is not None: self.__minimap.clear() self.__minimap = None g_sessionProvider.getCtx().resetPlayerFullNameFormatter() dispatcher = self.getDispatcher() if dispatcher is not None: dispatcher.dispossessUI() dispatcher.clearGUI() super(BattleLayout, self).fini() return
def __handleUiUpdated(self, _): self._stopUIListening() yield lambda callback: callback(True) from gui.battle_control import g_sessionProvider if g_sessionProvider.getCtx().wasInBattle: return graphicsStatus = graphics.getStatus() if not self.__graphicsResetShown and graphicsStatus.isReset(): isOk = yield self.__showI18nDialog('resetGraphics') self.__graphicsResetShown = True if isOk: self.__showSettingsWindow(_GRAPHICS_SETTINGS_TAB_IDX) elif graphicsStatus.isShowWarning(): self.__showSettingsWindow(_GRAPHICS_SETTINGS_TAB_IDX) isOk = yield self.__showI18nDialog('changeGraphics') if isOk: self.__updatePresetSetting() elif self.__isNeedToShowPresetChangingDialog(): self.__showSettingsWindow(_GRAPHICS_SETTINGS_TAB_IDX) isOk = yield self.__showI18nDialog('lowFpsWarning') if isOk: BigWorld.callback(0.001, lambda : self.__downgradePresetIndex()) else: self.__updateLowFpsDialogVersion() graphicsStatus.markProcessed() self.__clearCurrentFpsInfo()
def __addEntryLit(self, id, matrix, visible = True): battleCtx = g_sessionProvider.getCtx() if battleCtx.isObserver(id): return if matrix is None: return mp = Math.WGReplayAwaredSmoothTranslationOnlyMP() mp.source = matrix scaledMatrix = None if self.__markerScale is not None: scaleMatrix = Matrix() scaleMatrix.setScale(Vector3(self.__markerScale, self.__markerScale, self.__markerScale)) scaledMatrix = mathUtils.MatrixProviders.product(scaleMatrix, mp) if scaledMatrix is None: handle = self.__ownUI.addEntry(mp, self.zIndexManager.getVehicleIndex(id)) else: handle = self.__ownUI.addEntry(scaledMatrix, self.zIndexManager.getVehicleIndex(id)) entry = {'matrix': mp, 'handle': handle} arena = BigWorld.player().arena entryVehicle = arena.vehicles[id] entityName = battleCtx.getPlayerEntityName(id, entryVehicle.get('team')) markerType = entityName.base entryName = entityName.name() self.__entrieLits[id] = entry vName = entryVehicle['vehicleType'].type.shortUserString self.__ownUI.entryInvoke(entry['handle'], ('init', [markerType, entryName, 'lastLit', '', vName])) if not visible: self.__ownUI.entryInvoke(entry['handle'], ('setVisible', [visible])) if self.__markerScale is None: self.__parentUI.call('minimap.entryInited', [])
def notifyVehicleStop(self, vehicleId): if not self.__isStarted: if vehicleId in self.__vehiclesWaitStart: self.__vehiclesWaitStart.remove(vehicleId) return if vehicleId == self.__playerVehicleID: return info = BigWorld.player().arena.vehicles.get(vehicleId) if info is None or not info['isAlive']: return entries = self.__entries if vehicleId in entries: location = entries[vehicleId]['location'] if location == VehicleLocation.AOI: ownPos = Math.Matrix(BigWorld.camera().invViewMatrix).translation entryPos = Math.Matrix(entries[vehicleId]['matrix']).translation inAoI = bool(abs(ownPos.x - entryPos.x) < self.__AOI_ESTIMATE and abs(ownPos.z - entryPos.z) < self.__AOI_ESTIMATE) if self.__permanentNamesShow or self.__onAltNamesShow: battleCtx = g_sessionProvider.getCtx() if not battleCtx.isObserver(self.__playerVehicleID): if entries[vehicleId]['matrix'] is not None: if type(entries[vehicleId]['matrix']) == Math.WGTranslationOnlyMP: self.__addEntryLit(vehicleId, Math.Matrix(entries[vehicleId]['matrix'].source), not self.__onAltNamesShow) else: mp = Math.WGTranslationOnlyMP() mp.source = Math.Matrix(entries[vehicleId]['matrix']) self.__addEntryLit(vehicleId, mp, not self.__onAltNamesShow) self.__delEntry(vehicleId) if not inAoI: self.__addEntry(vehicleId, VehicleLocation.AOI_TO_FAR, False) else: LOG_DEBUG('notifyVehicleOnStop, unknown minimap entry location', location)
def __addDyncSquadInfo(self, options): make = self._makeItem ctx = g_sessionProvider.getCtx() if not ctx.isInvitationEnabled() or ctx.hasSquadRestrictions(): return options elif not self.__userInfo.isAlly: return options else: contact = self.usersStorage.getUser(self.__userInfo.databaseID) isIgnored = contact is not None and contact.isIgnored() status = self.__vInfo.invitationDeliveryStatus if status & _D_STATUS.FORBIDDEN_BY_RECEIVER > 0 or status & _D_STATUS.SENT_TO > 0 and not status & _D_STATUS.SENT_INACTIVE: optionID = DYN_SQUAD_OPTION_ID.SENT_INVITATION isEnabled = False elif status & _D_STATUS.RECEIVED_FROM > 0 and not status & _D_STATUS.RECEIVED_INACTIVE: optionID = None elif self.__vInfo.isSquadMan(): optionID = DYN_SQUAD_OPTION_ID.IN_SQUAD isEnabled = False else: optionID = DYN_SQUAD_OPTION_ID.SENT_INVITATION isEnabled = not isIgnored if optionID is not None: options.append(self._makeItem(optionID, MENU.contextmenu(optionID), optInitData=self._getOptionInitData(optionID, isEnabled))) if status & _D_STATUS.RECEIVED_FROM > 0 and not status & _D_STATUS.RECEIVED_INACTIVE: options.append(make(DYN_SQUAD_OPTION_ID.ACCEPT_INVITATION, MENU.contextmenu(DYN_SQUAD_OPTION_ID.ACCEPT_INVITATION), optInitData=self._getOptionInitData(DYN_SQUAD_OPTION_ID.ACCEPT_INVITATION, not isIgnored))) options.append(make(DYN_SQUAD_OPTION_ID.REJECT_INVITATION, MENU.contextmenu(DYN_SQUAD_OPTION_ID.REJECT_INVITATION), optInitData=self._getOptionInitData(DYN_SQUAD_OPTION_ID.REJECT_INVITATION, not isIgnored))) return options
def _getTarget(self): from gui.battle_control import g_sessionProvider target = g_sessionProvider.getCtx().getPlayerFullName(vID=self.getFirstTargetID()) if self.isReceiver(): target = g_settings.battle.targetFormat % {"target": target} return target
def _populate(self): super(LoginView, self)._populate() if self.__onLoadCallback is not None: self.__onLoadCallback() self.__setupDispatcherHandlers(True) self.__loginDispatcher.create() self.__enableInputsIfModalViewsNotExisting() self.__loadVersion() self.__setCopyright() Waiting.close() MusicController.g_musicController.stopAmbient() MusicController.g_musicController.play( MusicController.MUSIC_EVENT_LOGIN) self.__loadRandomBgImage() if constants.IS_DEVELOPMENT: try: tmp_fil = open('GUIUnitTest.ut', 'r') if tmp_fil.readline().strip() != '': tmp_fil.close() sys.path.append('../../gui_unit_test/scripts') import GUIUnitTest else: tmp_fil.close() except IOError: pass self.__capsLockCallback = BigWorld.callback(0.1, self.__checkUserInputState) g_sessionProvider.getCtx().lastArenaUniqueID = None self.__showRequiredLoginScreen()
def onSetDisplayObject(self, cid, moviePath): """ Setting to this python class corresponded flash component. Called from flash by external interface. @param cid: callback id @param moviePath: path of the display object in flash """ try: self.flashDO = self.uiHolder.getMember(moviePath) self.flashDO.script = self self.uiHolder.respond([cid, True, g_sessionProvider.getCtx().isInBattle]) except Exception: LOG_ERROR('There is error while getting moving text display object') LOG_CURRENT_EXCEPTION() self.uiHolder.respond([cid, False, g_sessionProvider.getCtx().isInBattle])
def getVehicleTypeAmount(self): from Statistics import Statistics player = BigWorld.player() vehicles = player.arena.vehicles if player.playerVehicleID not in vehicles: return curVeh = vehicles[player.playerVehicleID] Statistics.getInfos(curVeh['accountDBID']) vehicles[player.playerVehicleID]['team'] amounts = {VEHICLE_CLASS_NAME.HEAVY_TANK:{'ally':0,'enemy':0}, VEHICLE_CLASS_NAME.MEDIUM_TANK:{'ally':0,'enemy':0}, VEHICLE_CLASS_NAME.LIGHT_TANK:{'ally':0,'enemy':0}, VEHICLE_CLASS_NAME.AT_SPG:{'ally':0,'enemy':0}, VEHICLE_CLASS_NAME.SPG:{'ally':0,'enemy':0}} tiers = [] for accountDBID,entityObj in Statistics.getEmo().getAll().iteritems(): vID = g_sessionProvider.getCtx().getVehIDByAccDBID(accountDBID) if vID in vehicles: v_info = vehicles[vID] tiers.append(v_info['vehicleType'].level) if not BattleUtils.isMyTeam(v_info['team']): tag = 'enemy' else: tag = 'ally' for vehicleType in VEHICLE_TYPES_ORDER: if vehicleType in v_info['vehicleType'].type.tags: amounts[vehicleType][tag] += 1 currentTier = curVeh['vehicleType'].level return (amounts,tiers,currentTier)
def _getTarget(self): from gui.battle_control import g_sessionProvider target = g_sessionProvider.getCtx().getPlayerFullName( vID=self.getFirstTargetID()) if self.isReceiver(): target = g_settings.battle.targetFormat % {'target': target} return target
def setName(self, dbID, pName=None): if pName is not None: pName = i18n.encodeUtf8(pName) name = g_sessionProvider.getCtx().getPlayerFullName(accID=dbID, pName=pName) self._ctx['playerName'] = unicode(name, 'utf-8') return self
def onSetDisplayObject(self, cid, moviePath): """ Setting to this python class corresponded flash component. Called from flash by external interface. @param cid: callback id @param moviePath: path of the display object in flash """ try: self.flashDO = self.uiHolder.getMember(moviePath) self.flashDO.script = self self.uiHolder.respond([cid, True, g_sessionProvider.getCtx().isInBattle]) except Exception: LOG_ERROR("There is error while getting moving text display object") LOG_CURRENT_EXCEPTION() self.uiHolder.respond([cid, False, g_sessionProvider.getCtx().isInBattle])
def __onPostMortemSwitched(self): LogitechMonitor.onScreenChange('postmortem') if self.radialMenu is not None: self.radialMenu.forcedHide() if not g_sessionProvider.getCtx().isPlayerObserver(): self.__callEx('showPostmortemTips', [1.0, 5.0, 1.0]) return
def addDefMessage(message): mColor = g_settings.getColorScheme('battle/message').getHexStr('unknown') pColor = g_settings.getColorScheme('battle/player').getHexStr('unknown') return g_settings.battle.messageFormat % {'playerColor': pColor, 'playerName': unicode(g_sessionProvider.getCtx().getFullPlayerName(accID=message.originator), 'utf-8', errors='ignore'), 'messageColor': mColor, 'messageText': message.data}
def altVoicesPreview(self, soundMode): if not self.__altVoiceSetting.isOptionEnabled(): return True if not g_sessionProvider.getCtx().isInBattle: SoundGroups.g_instance.enableVoiceSounds(True) self.__altVoiceSetting.preview(soundMode) return self.__altVoiceSetting.playPreviewSound(self.uiHolder.soundManager)
def _populate(self): super(LoginView, self)._populate() if self.__onLoadCallback is not None: self.__onLoadCallback() self.__setupDispatcherHandlers(True) self.__loginDispatcher.create() self.__enableInputsIfModalViewsNotExisting() self.__loadVersion() self.__setCopyright() Waiting.close() MusicController.g_musicController.stopAmbient() MusicController.g_musicController.play(MusicController.MUSIC_EVENT_LOGIN) self.__loadRandomBgImage() if constants.IS_DEVELOPMENT: try: tmp_fil = open('GUIUnitTest.ut', 'r') if tmp_fil.readline().strip() != '': tmp_fil.close() sys.path.append('../../gui_unit_test/scripts') import GUIUnitTest else: tmp_fil.close() except IOError: pass self.__capsLockCallback = BigWorld.callback(0.1, self.__checkUserInputState) g_sessionProvider.getCtx().lastArenaUniqueID = None self.__showRequiredLoginScreen()
def getFullPlayerName(self, chatAction): pName = None try: pName = i18n.encodeUtf8(chatAction.originatorNickName) except UnicodeError: LOG_ERROR('Can not encode nick name', chatAction) return g_sessionProvider.getCtx().getFullPlayerName(accID=chatAction.originator, pName=pName)
def _makeTargetedCommandMessage(self, command): from gui.battle_control import g_sessionProvider target = g_sessionProvider.getCtx().getFullPlayerName(vID=self.getFirstTargetID()) text = command.msgText if self.isReceiver(): target = g_settings.battle.targetFormat % {'target': target} return i18n.makeString(text, target=target)
def addVehicleMarker(self, vProxy, vInfo, guiProps): vTypeDescr = vProxy.typeDescriptor maxHealth = vTypeDescr.maxHealth mProv = vProxy.model.node('HP_gui') isAlly = guiProps.isFriend speaking = False if GUI_SETTINGS.voiceChat: speaking = VoiceChatInterface.g_instance.isPlayerSpeaking(vInfo.player.accountDBID) hunting = VehicleActions.isHunting(vInfo.events) markerID = self._createVehicleMarker(isAlly, mProv) self.__markers[vInfo.vehicleID] = _VehicleMarker(markerID, vProxy, self.__ownUIProxy) battleCtx = g_sessionProvider.getCtx() result = battleCtx.getPlayerFullNameParts(vProxy.id) vType = vInfo.vehicleType teamIdx = -1 if arena_info.isFalloutMultiTeam() and vInfo.isSquadMan(): teamIdx = g_sessionProvider.getArenaDP().getMultiTeamsIndexes()[vInfo.team] self.invokeMarker(markerID, 'init', [vType.classTag, vType.iconPath, result.vehicleName, vType.level, result.playerFullName, result.playerName, result.clanAbbrev, result.regionCode, vProxy.health, maxHealth, guiProps.name(), speaking, hunting, guiProps.base, g_ctfManager.getVehicleCarriedFlagID(vInfo.vehicleID) is not None, teamIdx]) return markerID
def _update(self): if self.__vID is not None: vehicle = BigWorld.entity(self.__vID) if vehicle is not None: playerName = g_sessionProvider.getCtx().getFullPlayerName(vID=self.__vID, showVehShortName=False) type = Vehicle.getUserName(vehicleType=vehicle.typeDescriptor.type, textPrefix=True) healthPercent = math.ceil(100.0 * max(0, vehicle.health) / vehicle.typeDescriptor.maxHealth) self.__setText(playerName, type, healthPercent)
def _updatePlayerInfo(self, value): """ Updates player information on panel. :param value: ID of vehicle. """ parts = g_sessionProvider.getCtx().getFullPlayerNameWithParts(vID=value, showVehShortName=False) self.as_setPlayerInfoS(*parts)
def _dispose(self): if not g_sessionProvider.getCtx().isInBattle: SoundGroups.g_instance.enableVoiceSounds(False) g_guiResetters.discard(self.onRecreateDevice) BigWorld.wg_setAdapterOrdinalNotifyCallback(None) VibroManager.g_instance.onConnect -= self.onVibroManagerConnect VibroManager.g_instance.onDisconnect -= self.onVibroManagerDisconnect super(SettingsWindow, self)._dispose()
def start(self): super(BattleResultsEnv, self).start() lastWinStatus = g_sessionProvider.getCtx().extractLastArenaWinStatus() if lastWinStatus is not None: SOUND_DEBUG('There is last arena win status need to be processed', lastWinStatus) self._music = self._sounds.get(lastWinStatus.getStatus(), EmptySound()) self._music.onFinished += self._onMusicFinished return
def addVehicleInfo(self, vInfo, arenaDP): vehicleID = vInfo.vehicleID if vehicleID != self.__playerVehicleID: active = self.__isVehicleActive(vehicleID) vehicle = BigWorld.entity(vehicleID) if vehicle: guiProps = g_sessionProvider.getCtx().getPlayerGuiProps(vehicleID, vInfo.team) self.__addOrUpdateVehicleMarker(vehicle.proxy, vInfo, guiProps, active)
def setTeamKiller(self, vID): if vID not in self.__vehiclesMarkers: return handle = self.__vehiclesMarkers[vID].getMarkerID() ctx = g_sessionProvider.getCtx() if not ctx.isTeamKiller(vID=vID) or ctx.isSquadMan(vID=vID): return self._invokeMarker(handle, 'setEntityName', [PLAYER_GUI_PROPS.teamKiller.name()])
def setTeamKiller(self, vID): if vID not in self.__markers: return marker = self.__markers[vID] ctx = g_sessionProvider.getCtx() if not ctx.isTeamKiller(vID=vID) or ctx.isSquadMan(vID=vID) and not arena_info.isFalloutBattle(): return self.invokeMarker(marker.id, 'setEntityName', [PLAYER_GUI_PROPS.teamKiller.name()])
def _updatePlayerInfo(self, value): """ Updates player information on panel. :param value: ID of vehicle. """ result = g_sessionProvider.getCtx().getPlayerFullNameParts(vID=value, showVehShortName=False) self.as_setPlayerInfoS(result.playerFullName, result.playerName, result.clanAbbrev, result.regionCode, result.vehicleName)
def __formatEntity(self, entityID): ctx = g_sessionProvider.getCtx() vTypeInfoVO = ctx.getArenaDP().getVehicleInfo(entityID).vehicleType playerName = ctx.getPlayerFullName(entityID, showVehShortName=False) iconTag = _VEHICLE_TYPE_FORMATTER.format(vTypeInfoVO.classTag) playerInfo = '%s%s%s' % (playerName, iconTag, vTypeInfoVO.shortNameWithPrefix) entityInfo = self.__styleFormatter.format(playerInfo) return entityInfo
def __onCombatEquipmentUsed(self, shooterID, eqID): battleCxt = g_sessionProvider.getCtx() if not battleCxt.isCurrentPlayer(shooterID): equipment = vehicles.g_cache.equipments().get(eqID) getFullName = battleCxt.getFullPlayerName if equipment is not None: postfix = equipment.name.split('_')[0].upper() self.showMessage('COMBAT_EQUIPMENT_USED', {'player': getFullName(shooterID, showClan=False)}, extra=(('player', shooterID),), postfix=postfix)
def __getFlagMarkerStateByVehicle(self, vehicleID): battleCtx = g_sessionProvider.getCtx() if battleCtx.isObserver(vehicleID): state = _F_STATES.NEUTRAL else: vehicle_team = self._arenaDP.getVehicleInfo(vehicleID).team state = _F_STATES.ENEMY if self._arenaDP.isEnemyTeam(vehicle_team) else _F_STATES.ALLY return state