Ejemplo n.º 1
0
class WebViewTransparent(WebView):

    def __init__(self, ctx=None):
        super(WebViewTransparent, self).__init__(ctx)
        self._browserParams = (ctx or {}).get('browserParams', makeBrowserParams(bgAlpha=0.67))
        self.__blur = None
        return

    def onEscapePress(self):
        self.destroy()

    def _populate(self):
        super(WebViewTransparent, self)._populate()
        self.__blur = CachedBlur(enabled=True, ownLayer=APP_CONTAINERS_NAMES.TOP_SUB_VIEW, layers=(APP_CONTAINERS_NAMES.SUBVIEW,
         APP_CONTAINERS_NAMES.WINDOWS,
         APP_CONTAINERS_NAMES.DIALOGS,
         APP_CONTAINERS_NAMES.IME,
         APP_CONTAINERS_NAMES.SERVICE_LAYOUT,
         APP_CONTAINERS_NAMES.MARKER,
         APP_CONTAINERS_NAMES.VIEWS,
         APP_CONTAINERS_NAMES.SYSTEM_MESSAGES))

    def _dispose(self):
        super(WebViewTransparent, self)._dispose()
        if self.__blur is not None:
            self.__blur.fini()
        return
class WebViewTransparent(WebView):
    __sound_env__ = HangarOverlayEnv

    def __init__(self, ctx=None):
        super(WebViewTransparent, self).__init__(ctx)
        self._browserParams = makeBrowserParams(bgAlpha=0.67)
        self._browserParams.update((ctx or {}).get('browserParams', {}))
        self.__blur = None
        self.__hiddenLayers = (ctx or {}).get('hiddenLayers', ())
        return

    def _populate(self):
        super(WebViewTransparent, self)._populate()
        if self.__hiddenLayers:
            containerManager = self.app.containerManager
            containerManager.hideContainers(self.__hiddenLayers, 0)

    def setParentWindow(self, window):
        super(WebViewTransparent, self).setParentWindow(window)
        self.__blur = CachedBlur(enabled=True, ownLayer=window.layer)

    def onEscapePress(self):
        self.destroy()

    def _dispose(self):
        if self.__blur is not None:
            self.__blur.fini()
        if self.__hiddenLayers:
            containerManager = self.app.containerManager
            containerManager.showContainers(self.__hiddenLayers, 0)
        super(WebViewTransparent, self)._dispose()
        return
class MultipleAwardsViewWindow(LobbyNotificationWindow):
    __slots__ = ('__blur', )

    def __init__(self, rewards, tooltips, productCode):
        super(MultipleAwardsViewWindow, self).__init__(
            content=self._getContentView(rewards, tooltips, productCode))
        self.__blur = None
        return

    def load(self):
        if self.__blur is None:
            self.__blur = CachedBlur(enabled=True, ownLayer=self.layer - 1)
        super(MultipleAwardsViewWindow, self).load()
        return

    @classmethod
    def _getContentView(cls, rewards, tooltips, productCode):
        return MultipleAwardsView(rewards=rewards,
                                  tooltips=tooltips,
                                  productCode=productCode)

    def _finalize(self):
        if self.__blur is not None:
            self.__blur.fini()
            self.__blur = None
        super(MultipleAwardsViewWindow, self)._finalize()
        return
Ejemplo n.º 4
0
class _CommonCongratsView(ViewImpl):
    def __init__(self, context):
        settings = ViewSettings(R.views.lobby.common.congrats.
                                common_congrats_view.CommonCongratsView())
        settings.model = CommonCongratsViewModel()
        super(_CommonCongratsView, self).__init__(settings)
        self.__ctx = context

    @property
    def viewModel(self):
        return super(_CommonCongratsView, self).getViewModel()

    def _initialize(self, *args, **kwargs):
        super(_CommonCongratsView, self)._initialize()
        self.__updateVM()
        self.__addListeners()
        self._blur = CachedBlur(enabled=True)

    def _finalize(self):
        self._blur.fini()
        self.__removeListeners()
        super(_CommonCongratsView, self)._finalize()

    def __updateVM(self):
        with self.viewModel.transaction() as vm:
            vm.setBackground(self.__ctx.background)
            vm.setTitle(self.__ctx.title)
            vm.setDescription(self.__ctx.description)
            vm.setImage(self.__ctx.image)
            vm.setImageAlt(self.__ctx.imageAlt)
            vm.setConfirmLbl(self.__ctx.confirmLabel)
            vm.setBackLbl(self.__ctx.backLabel)

    def __addListeners(self):
        self.viewModel.onConfirmClick += self.__onConfirm
        self.viewModel.onBackClick += self.__onBack
        self.viewModel.onCloseClick += self.__onClose

    def __removeListeners(self):
        self.viewModel.onCloseClick -= self.__onClose
        self.viewModel.onBackClick -= self.__onBack
        self.viewModel.onConfirmClick -= self.__onConfirm

    def __onConfirm(self):
        self.__destroyWindow()
        self.__ctx.onConfirm()

    def __onBack(self):
        self.__destroyWindow()
        self.__ctx.onBack()

    def __onClose(self):
        self.__destroyWindow()
        self.__ctx.onConfirm()

    def __destroyWindow(self):
        self.viewModel.setNeedReset(True)
        self.destroyWindow()
class BattlePassDailyQuestsIntroWindow(WindowImpl):
    __slots__ = ('__blur', )

    def __init__(self, parent=None):
        super(BattlePassDailyQuestsIntroWindow,
              self).__init__(WindowFlags.WINDOW,
                             content=BattlePassDailyQuestsIntroView(),
                             parent=parent)
        self.__blur = CachedBlur(enabled=True,
                                 ownLayer=WindowLayer.TOP_SUB_VIEW)

    def _finalize(self):
        self.__blur.fini()
        super(BattlePassDailyQuestsIntroWindow, self)._finalize()
Ejemplo n.º 6
0
class BootcampProgressView(ViewImpl):
    __slots__ = ('__blur', '__tooltipData')
    uiBootcampLogger = BootcampLogger(
        BCLogKeys.BC_CURRENT_PROGRESS_WIDGET.value)

    def __init__(self, layoutID, *args, **kwargs):
        settings = ViewSettings(layoutID)
        settings.model = BootcampProgressModel()
        settings.args = args
        settings.kwargs = kwargs
        self.__blur = None
        self.__tooltipData = {}
        super(BootcampProgressView, self).__init__(settings)
        return

    @property
    def viewModel(self):
        return super(BootcampProgressView, self).getViewModel()

    def createToolTip(self, event):
        if event.contentID == R.views.common.tooltip_window.backport_tooltip_content.BackportTooltipContent(
        ):
            tooltipId = event.getArgument('tooltipId')
            if tooltipId:
                tooltipData = self.__tooltipData[int(tooltipId)]
                window = BackportTooltipWindow(tooltipData,
                                               self.getParentWindow())
                if window:
                    window.load()
                return window

    def _initialize(self):
        super(BootcampProgressView, self)._initialize()
        window = self.getParentWindow()
        self.__blur = CachedBlur(enabled=True, ownLayer=window.layer - 1)

    def _onLoading(self, *args, **kwargs):
        super(BootcampProgressView, self)._onLoading(*args, **kwargs)
        with self.viewModel.transaction() as model:
            g_bootcamp.fillProgressBar(model, self.__tooltipData,
                                       ICON_SIZE.BIG)

    def _finalize(self):
        self.uiBootcampLogger.log(BCLogActions.CLOSE.value)
        self.__blur.fini()
        super(BootcampProgressView, self)._finalize()
Ejemplo n.º 7
0
class _HangarVehicleInfoIntroWindow(LobbyWindow):
    __slots__ = ('__blur', )

    def __init__(self, *args, **kwargs):
        super(_HangarVehicleInfoIntroWindow, self).__init__(
            wndFlags=WindowFlags.WINDOW | WindowFlags.WINDOW_FULLSCREEN,
            decorator=None,
            content=_HangarVehicleInfoIntroView(
                R.views.lobby.battleRoyale.vehicle_info_intro_overlay.
                VehicleInfoIntroOverlay(), *args, **kwargs))
        self.__blur = CachedBlur(enabled=True, ownLayer=self.layer)
        return

    def _finalize(self):
        self.__blur.fini()
        self.__blur = None
        super(_HangarVehicleInfoIntroWindow, self)._finalize()
        return
Ejemplo n.º 8
0
class _HangarVehicleInfoIntroView(ViewImpl):
    __slots__ = ('__vehicle', '__firstView', '__blur')

    def __init__(self, layoutID, ctx=None, *args, **kwargs):
        super(_HangarVehicleInfoIntroView,
              self).__init__(layoutID, ViewFlags.OVERLAY_VIEW,
                             VehicleInfoIntroOverlayModel, *args, **kwargs)
        self.__vehicle = ctx.get('vehicle')
        self.__firstView = ctx.get('firstView', False)
        self.__blur = CachedBlur(enabled=True,
                                 ownLayer=APP_CONTAINERS_NAMES.OVERLAY,
                                 layers=[
                                     APP_CONTAINERS_NAMES.VIEWS,
                                     APP_CONTAINERS_NAMES.SUBVIEW,
                                     APP_CONTAINERS_NAMES.TOP_SUB_VIEW,
                                     APP_CONTAINERS_NAMES.WINDOWS,
                                     APP_CONTAINERS_NAMES.BROWSER,
                                     APP_CONTAINERS_NAMES.DIALOGS
                                 ])

    def _initialize(self):
        super(_HangarVehicleInfoIntroView, self)._initialize()
        with self.getViewModel().transaction() as viewModel:
            viewModel.setVehicleTag(
                Vehicle.getIconResourceName(self.__vehicle.name))
            viewModel.setIsFirstView(self.__firstView)
            viewModel.onSubmitBtnClick += self.__onSubmitClicked

    def _finalize(self):
        if self.__firstView:
            AccountSettings.setSettings(
                BATTLE_ROYALE_HANGAR_BOTTOM_PANEL_VIEWED, True)
        self.getViewModel().onSubmitBtnClick -= self.__onSubmitClicked
        self.__vehicle = None
        self.__blur.fini()
        self.__blur = None
        super(_HangarVehicleInfoIntroView, self)._finalize()
        return

    def __onSubmitClicked(self):
        self.destroyWindow()
Ejemplo n.º 9
0
class MapsTrainingView(MapsTrainingBaseView, IGlobalListener):
    __slots__ = ('__selectedMap', '__selectedScenario', '__ctxVehicleType',
                 '__ctxSide', '__ctxShowAnimation', '__tooltipData',
                 '__account', '__mapsConfig', '__isDataLoaded', '__blur',
                 '__blurRectId', '__packer', '__hangarCameraManager',
                 '__tickCallback', '__preferences', '__markerPosOffset',
                 '__finalizationInProgress')
    _TACTICAL_MAPS_CONFIG_PATH = 'scripts/maps_training_tactical_maps.xml'
    _SCENARIO_COUNT = len(VEHICLE_TYPE.ALL_TYPES) * len(VEHICLE_TYPE.ALL_TEAMS)
    _UPDATE_TICK_RATE = 0.1
    _MEDIUM_TANK_OFFSET = 1.26959
    _MAX_MAP_DIFFICULTY = 3
    _DEFAULT_MAP_DIFFICULTY = 3
    _DISABLED_MAP_GROUP_ID = 2
    _COMMON_SOUND_SPACE = MAPS_TRAINING_SOUND_SPACE
    lobbyContext = dependency.descriptor(ILobbyContext)
    itemsCache = dependency.descriptor(IItemsCache)
    mapsTrainingController = dependency.descriptor(IMapsTrainingController)
    hangarSpace = dependency.descriptor(IHangarSpace)
    c11nService = dependency.descriptor(ICustomizationService)

    def __init__(self, *args, **kwargs):
        super(MapsTrainingView, self).__init__(
            viewResource=R.views.lobby.maps_training.MapsTrainingPage(),
            viewModel=MapsTrainingViewModel())
        self.__selectedMap = None
        self.__selectedScenario = 0
        self.__ctxVehicleType = ''
        self.__ctxSide = 0
        self.__ctxShowAnimation = False
        self.__tooltipData = {}
        self.__account = BigWorld.player()
        self.__mapsConfig = TacticalMapsConfigReader.readXml(
            self._TACTICAL_MAPS_CONFIG_PATH)
        self.__isDataLoaded = False
        self.__blur = CachedBlur(blurAnimRepeatCount=1, blurRadius=0.1)
        self.__blurRectId = None
        self.__packer = getDefaultBonusPacker()
        self.__hangarCameraManager = None
        self.__tickCallback = None
        self.__preferences = self.mapsTrainingController.preferences
        self.__markerPosOffset = 0.0
        self.__finalizationInProgress = False
        self.__initFromCtx(kwargs.get('ctx', {}))
        return

    def showByCtx(self, ctx):
        self.__initFromCtx(ctx)
        if self.__isDataLoaded and self.__selectedMap:
            with self.viewModel.transaction() as model:
                self.__updateAllSelections(model)
        self.show()

    def createToolTipContent(self, event, contentID):
        if contentID == R.views.lobby.maps_training.ScenarioTooltip():
            geometryID = ArenaType.g_geometryNamesToIDs[self.__selectedMap]
            data = self.__account.mapsTraining.getGeometryData(geometryID)
            mapConfig = self.__mapsConfig.getMapConfig(self.__selectedMap)
            scenario = mapConfig.scenarios[int(event.getArgument('scenario'))]
            _, vehicleName = self.__getVehicleForScenario(scenario)
            return ScenarioTooltip(
                scenario.vehicleType, scenario.team, self.__selectedMap,
                list(self.__getTargets(scenario)), vehicleName,
                data[scenario.vehicleType][scenario.team]['completed'],
                self.__getRewards(geometryID, 'scenarioComplete'))
        return super(MapsTrainingView,
                     self).createToolTipContent(event=event,
                                                contentID=contentID)

    def createToolTip(self, event):
        tooltipId = event.getArgument('tooltipId', '')
        if not tooltipId:
            return super(MapsTrainingView, self).createToolTip(event)
        window = backport.BackportTooltipWindow(
            self.__tooltipData.get(tooltipId), self.getParentWindow())
        window.load()
        return window

    def _onLoading(self, *args, **kwargs):
        super(MapsTrainingView, self)._onLoading(*args, **kwargs)
        self.__finalizationInProgress = False
        if self.hangarSpace.spaceInited:
            self.__hangarCameraManager = self.hangarSpace.space.getCameraManager(
            )
        self.mapsTrainingController.requestInitialDataFromServer(
            self.__fillData)

    def _finalize(self):
        self.__finalizationInProgress = True
        self.__blur.fini()
        if self.__tickCallback is not None:
            BigWorld.cancelCallback(self.__tickCallback)
        if not self.__selectedMap:
            MapsTrainingSound.onSelectedMap(True)
        if self.prbEntity is not None and not self.prbEntity.isInQueue():
            g_currentPreviewVehicle.selectNoVehicle()
            g_currentPreviewVehicle.resetAppearance()
        super(MapsTrainingView, self)._finalize()
        return

    def __initFromCtx(self, ctx):
        selectedMap = ctx.get('map', '')
        self.__ctxVehicleType = ctx.get('vehicleType', '')
        self.__ctxSide = ctx.get('side', 0)
        self.__ctxShowAnimation = ctx.get('showAnimation', False)
        if self.__selectedMap != selectedMap and not selectedMap:
            MapsTrainingSound.onSelectedMap(False)
        self.__selectedMap = selectedMap

    def _addListeners(self):
        super(MapsTrainingView, self)._addListeners()
        self.viewModel.onMenu += self.__onMenu
        self.viewModel.onSelect += self.__onSelect
        self.viewModel.onScenarioSelect += self.__onScenarioSelect
        self.viewModel.onBack += self.__onBack
        self.viewModel.onBlurRectUpdated += self.__onBlurRectUpdated
        self.startGlobalListening()
        self.viewModel.onFilteringChange += self.__filterChangeHandler
        self.viewModel.onInfoClicked += self.__clickInfoHandler
        self.hangarSpace.onSpaceCreate += self.__onHangarSpaceCreate
        g_currentPreviewVehicle.onChangeStarted += self.__onPreviewVehicleChangeStarted
        g_currentPreviewVehicle.onChanged += self.__onPreviewVehicleChanged
        self.c11nService.onVisibilityChanged += self.__onC11nVisibilityChanged

    def _removeListeners(self):
        super(MapsTrainingView, self)._removeListeners()
        self.stopGlobalListening()
        self.viewModel.onMenu -= self.__onMenu
        self.viewModel.onSelect -= self.__onSelect
        self.viewModel.onScenarioSelect -= self.__onScenarioSelect
        self.viewModel.onBack -= self.__onBack
        self.viewModel.onBlurRectUpdated -= self.__onBlurRectUpdated
        self.viewModel.onFilteringChange -= self.__filterChangeHandler
        self.viewModel.onInfoClicked -= self.__clickInfoHandler
        self.hangarSpace.onSpaceCreate -= self.__onHangarSpaceCreate
        g_currentPreviewVehicle.onChangeStarted -= self.__onPreviewVehicleChangeStarted
        g_currentPreviewVehicle.onChanged -= self.__onPreviewVehicleChanged
        self.c11nService.onVisibilityChanged -= self.__onC11nVisibilityChanged

    def __onHangarSpaceCreate(self):
        self.__hangarCameraManager = self.hangarSpace.space.getCameraManager()

    def __onBack(self):
        self.__selectedMap = ''
        self.__selectedScenario = 0
        self.__blur.disable()
        with self.viewModel.transaction() as model:
            model.setIsMapSelected(False)
            model.setIncompleteFilter(self.__preferences.incompleteFilter)
            model.setTitleFilter(self.__preferences.titleFilter)
        MapsTrainingSound.onSelectedMap(False)
        self.mapsTrainingController.reset()

    @staticmethod
    def __onMenu():
        g_eventBus.handleEvent(events.LoadViewEvent(
            SFViewLoadParams(VIEW_ALIAS.LOBBY_MENU)),
                               scope=EVENT_BUS_SCOPE.LOBBY)

    def __onSelect(self, args):
        self.__selectedMap = str(args.get('id'))
        with self.viewModel.transaction() as model:
            model.setIsMapSelected(True)
            MapsTrainingSound.onSelectedMap(True)
            self.__updateAllSelections(model)

    def __onScenarioSelect(self, args):
        self.__selectedScenario = int(args.get('id'))
        with self.viewModel.transaction() as model:
            self.__updateSelectedScenario(model)

    def __updateSelectedMap(self, model):
        isMapSelected = bool(self.__selectedMap)
        model.setIsMapSelected(isMapSelected)
        if isMapSelected:
            mapConfig = self.__mapsConfig.getMapConfig(self.__selectedMap)
            geometryID = ArenaType.g_geometryNamesToIDs[self.__selectedMap]
            data = self.__account.mapsTraining.getGeometryData(geometryID)
            serverConfig = self.mapsTrainingController.getConfig()
            trainingMaps = serverConfig['maps']
            mapModel = model.selectedMapModel
            mapModel.setId(self.__selectedMap)
            mapModel.setImage(
                R.images.gui.maps.icons.map.dyn('c_{}'.format(
                    self.__selectedMap))())
            mapModel.setGroupId(trainingMaps[geometryID] - 1)
            scenarioModels = mapModel.getScenarios()
            scenarioModels.clear()
            for scenario in mapConfig.scenarios:
                scenarioModel = MapsTrainingScenarioModel()
                scenarioModel.setTeam(scenario.team)
                scenarioModel.setScenarioNum(
                    SCENARIO_INDEXES[scenario.team, scenario.vehicleType])
                scenarioModel.setVehicleType(scenario.vehicleType)
                scenarioModel.setIsComplete(
                    data[scenario.vehicleType][scenario.team]['completed'])
                scenarioBonuses = self.__getRewards(geometryID,
                                                    'scenarioComplete')
                bonusArray = scenarioModel.getRewards()
                self.__fillBonusArray(bonusArray, scenarioBonuses)
                scenarioModels.addViewModel(scenarioModel)

            isNotComplete = any(
                (not data[scenario.vehicleType][scenario.team]['completed']
                 for scenario in mapConfig.scenarios))
            mapBonuses = self.__getRewards(geometryID, 'mapComplete')
            finalBonusArray = mapModel.getRewards()
            finalBonusArray.clear()
            if isNotComplete:
                self.__fillBonusArray(finalBonusArray, mapBonuses)
        self.mapsTrainingController.setSelectedMap(self.__selectedMap)

    def __getRewards(self, geometryID, stage):
        config = self.mapsTrainingController.getConfig()
        finalBonuses = []
        mapRewardsConfig = config['rewards'][geometryID][stage]
        for rewardName, rewardData in mapRewardsConfig.iteritems():
            finalBonuses.extend(getNonQuestBonuses(rewardName, rewardData))

        return finalBonuses

    def __fillBonusArray(self, bonusArray, bonusesData):
        for bonus in bonusesData:
            bonusList = self.__packer.pack(bonus)
            bonusTooltipList = self.__packer.getToolTip(bonus)
            for bonusIndex, item in enumerate(bonusList):
                item.setIndex(bonusIndex)
                tooltipId = str(len(self.__tooltipData))
                item.setTooltipId(tooltipId)
                bonusArray.addViewModel(item)
                self.__tooltipData[tooltipId] = bonusTooltipList[bonusIndex]

    def __updateSelectedScenario(self, model):
        mapConfig = self.__mapsConfig.getMapConfig(self.__selectedMap)
        scenario = mapConfig.scenarios[self.__selectedScenario]
        if scenario.team != self.mapsTrainingController.getSelectedTeam():
            self.mapsTrainingController.setSelectedTeam(scenario.team)
        self.__markerPosOffset = self._MEDIUM_TANK_OFFSET if scenario.vehicleType == VEHICLE_TYPE.MEDIUM else 0.0
        vehicle, vehicleName = self.__getVehicleForScenario(scenario)
        if vehicle != self.mapsTrainingController.getSelectedVehicle(
        ) or g_currentPreviewVehicle.intCD != vehicle:
            self.mapsTrainingController.setSelectedVehicle(vehicle)
        selectedMapModel = model.selectedMapModel
        selectedMapModel.setSelectedScenario(self.__selectedScenario)
        selectedMapModel.setVehicleName(vehicleName)
        imageResource = R.images.gui.maps.icons.mapsTraining.minimap.scenarios.dyn(
            'c_{}_team{}_{}'.format(self.__selectedMap, scenario.team,
                                    scenario.vehicleType))
        selectedMapModel.setScenarioImage(
            imageResource() if imageResource.isValid() else R.invalid())
        points = selectedMapModel.getPoints()
        points.clear()
        teamData = mapConfig.teams[scenario.team]
        for teamId, teamForBaseData in mapConfig.teams.iteritems():
            teamPointModel = self.__createPointModel(
                'team{}'.format(teamId), [], teamForBaseData.isLeft,
                teamForBaseData.tooltipImage, teamForBaseData.position,
                MapsTrainingMinimapPoint.POINT_TYPE_BASE
                if teamId == scenario.team else
                MapsTrainingMinimapPoint.POINT_TYPE_ENEMY_BASE)
            points.addViewModel(teamPointModel)

        pointsData = teamData.scenarioPoints[scenario.vehicleType]
        for pointData in pointsData:
            pointModel = self.__createPointModel(
                pointData.id, pointData.textKeys, pointData.isLeft,
                pointData.tooltipImage, pointData.position,
                MapsTrainingMinimapPoint.POINT_TYPE_DEFAULT)
            points.addViewModel(pointModel)

        selectedMapModel.setIsShowCompleteAnimation(self.__ctxShowAnimation)
        self.__ctxShowAnimation = False

    @staticmethod
    def __createPointModel(pointId, textKeys, isLeft, tooltipImage, position,
                           pointType):
        pointModel = MapsTrainingMinimapPoint()
        pointModel.setId(pointId)
        textKeysModel = pointModel.getTextKeys()
        for textKey in textKeys:
            textKeysModel.addString(textKey)

        pointModel.setIsLeft(isLeft)
        if tooltipImage:
            pointModel.setIsShowTooltip(True)
            pointModel.setTooltipImage(
                R.images.gui.maps.icons.mapsTraining.minimap.tooltips.dyn(
                    tooltipImage)())
        pointModel.setPositionX(position.x)
        pointModel.setPositionY(position.y)
        pointModel.setType(pointType)
        return pointModel

    def __getVehicleForScenario(self, scenario):
        configuration = self.mapsTrainingController.getConfig()
        mapId = ArenaType.g_geometryNamesToIDs[self.__selectedMap]
        for vehCompDescr in configuration['vehicles'][mapId]:
            vehDescr = vehicles.VehicleDescr(
                typeID=vehicles.parseIntCompactDescr(vehCompDescr)[1:])
            vehicleData = self.itemsCache.items.getStockVehicle(vehCompDescr)
            if scenario.vehicleType == vehicleData.type:
                return (vehDescr.name, vehicleData.userName)

    def __getTargets(self, scenario):
        goals = self.__getScenarioConfig(scenario.vehicleType,
                                         scenario.team)['goals']
        for vehCls in VEHICLE_CLASSES_ORDER:
            for _ in xrange(goals[vehCls]):
                yield vehCls

    def __getScenarioConfig(self, vehType, team):
        mapId = ArenaType.g_geometryNamesToIDs[self.__selectedMap]
        config = self.mapsTrainingController.getConfig()
        return config.get('scenarios',
                          {}).get(mapId, {}).get(team, {}).get(vehType, {})

    def __filterChangeHandler(self, kwargs):
        incompleteFilter = kwargs.get('incompleteFilter', False)
        if incompleteFilter != self.__preferences.incompleteFilter:
            self.__preferences.incompleteFilter = incompleteFilter
            self.__preferences.save()
        titleFilter = kwargs.get('titleFilter', '')
        if titleFilter != self.__preferences.titleFilter:
            self.__preferences.titleFilter = titleFilter

    def __clickInfoHandler(self):
        from gui.shared.event_dispatcher import showBrowserOverlayView
        url = GUI_SETTINGS.infoPageMapsTraining
        showBrowserOverlayView(url, VIEW_ALIAS.BROWSER_OVERLAY)

    def __fillData(self):
        configuration = self.mapsTrainingController.getConfig()
        trainingMaps = configuration['maps']
        availableMaps = []
        mapIDs = self.lobbyContext.getServerSettings().getPreferredMapsConfig(
        )['mapIDs']
        for geometryID in mapIDs:
            if geometryID not in ArenaType.g_geometryCache:
                continue
            geometryType = ArenaType.g_geometryCache[geometryID]
            availableMaps.append(geometryType)

        with self.viewModel.transaction() as model:
            model.setIncompleteFilter(self.__preferences.incompleteFilter)
            model.setTitleFilter(self.__preferences.titleFilter)
            groupArray = model.getGroups()
            groupArray.clear()
            for groupId in range(self._MAX_MAP_DIFFICULTY):
                groupVM = MapsTrainingGroupModel()
                groupArray.addViewModel(groupVM)
                groupVM.setGroupId(groupId)
                groupVM.setGroupTitle(
                    backport.text(
                        R.strings.maps_training.mapSelection.groupTitle.num(
                            groupId)()))
                groupVM.setIsGroupDisabled(
                    groupId == self._DISABLED_MAP_GROUP_ID)

            mapsModel = model.getMaps()
            mapsModel.clear()
            for geometryType in availableMaps:
                slotModel = MapsTrainingMapModel()
                mapName = geometryType.geometryName
                mapId = geometryType.geometryID
                slotModel.setId(mapName)
                slotModel.setIsEnabled(mapId in trainingMaps)
                data = self.__account.mapsTraining.getGeometryData(mapId)
                slotModel.setIsCompleted(data['total'] >= self._SCENARIO_COUNT)
                slotModel.setGroupId(
                    trainingMaps.get(mapId, self._DEFAULT_MAP_DIFFICULTY) - 1)
                slotModel.setTitle(
                    R.strings.arenas.dyn('c_{}'.format(mapName)).name())
                slotModel.setImage(
                    R.images.gui.maps.icons.map.dyn('c_{}'.format(mapName))())
                mapsModel.addViewModel(slotModel)

            if self.__selectedMap:
                if g_currentPreviewVehicle.isPresent(
                ) and self.__tickCallback is None:
                    self.__onPreviewVehicleChanged()
                self.__updateAllSelections(model)
        self.__isDataLoaded = True
        return

    def __updateAllSelections(self, model):
        self.__selectScenario()
        self.__updateSelectedMap(model)
        self.__updateSelectedScenario(model)

    def __selectScenario(self):
        if not self.__selectedMap:
            return
        scenarios = self.__mapsConfig.getMapConfig(
            self.__selectedMap).scenarios
        if self.__ctxVehicleType and self.__ctxSide:
            self.__selectedScenario = next(
                (index for index, scenario in enumerate(scenarios)
                 if scenario.team == self.__ctxSide
                 and self.__ctxVehicleType == scenario.vehicleType), 0)
            self.__ctxVehicleType = ''
            self.__ctxSide = 0
        else:
            geometryID = ArenaType.g_geometryNamesToIDs[self.__selectedMap]
            data = self.__account.mapsTraining.getGeometryData(geometryID)
            self.__selectedScenario = next((
                index for index, scenario in enumerate(scenarios)
                if not data[scenario.vehicleType][scenario.team]['completed']),
                                           0)

    def __onBlurRectUpdated(self, args):
        viewX, viewY = self.getParentWindow().globalPosition
        blurRect = Math.Vector4(
            int(args.get('left')) + viewX,
            int(args.get('top')) + viewY,
            int(args.get('right')) + viewX,
            int(args.get('bottom')) + viewY)
        if not self.__blur.enabled:
            self.__blur.enable()
        if self.__blurRectId:
            self.__blur.changeRect(self.__blurRectId, blurRect)
        else:
            self.__blurRectId = self.__blur.addRect(blurRect)

    def __onPreviewVehicleChangeStarted(self):
        if self.__tickCallback is not None and not self.__finalizationInProgress:
            BigWorld.cancelCallback(self.__tickCallback)
            self.__tickCallback = None
        return

    def __onPreviewVehicleChanged(self):
        if self.__tickCallback is None and not self.__finalizationInProgress:
            self.__tickCallback = BigWorld.callback(self._UPDATE_TICK_RATE,
                                                    self.__tick)
        return

    def __onC11nVisibilityChanged(self, _):
        vehCompDescr = self.mapsTrainingController.getSelectedVehicle()
        if self.__selectedMap and vehCompDescr:
            g_currentPreviewVehicle.selectNoVehicle()
            g_currentPreviewVehicle.selectVehicle(vehCompDescr)

    def __updateMarkerPosition(self):
        if self.__selectedMap and self.viewModel.isBound(
        ) and self.hangarSpace.spaceInited:
            vehEntity = self.hangarSpace.space.getVehicleEntity()
            if not vehEntity or not vehEntity.model:
                return
            guiNode = vehEntity.model.node(TankNodeNames.GUI)
            mat = Math.Matrix(guiNode)
            markerWorldPos = mat.applyToOrigin()
            markerWorldPos.y += self.__markerPosOffset
            pos = self.worldToScreenPos(markerWorldPos)
            if pos:
                self.viewModel.vehicleMarker.setTop(pos.y)

    def worldToScreenPos(self, worldPos):
        screenWidth, screenHeight = self.getParentWindow().size
        viewProjMatrix = getViewProjectionMatrix()
        clipPos = viewProjMatrix.applyV4Point(
            Math.Vector4(worldPos.x, worldPos.y, worldPos.z, 1.0))
        if clipPos.w <= 0.0:
            return None
        else:
            ndcPos = Math.Vector2()
            ndcPos.x = clipPos.x / clipPos.w
            ndcPos.y = clipPos.y / clipPos.w
            if abs(ndcPos.x) > 1.0 or abs(ndcPos.y) > 1.0:
                return None
            halfScreenWidth = screenWidth / 2.0
            halfScreenHeight = screenHeight / 2.0
            screenPosX = halfScreenWidth * (ndcPos.x + 1.0)
            screenPosY = halfScreenHeight * (1.0 - ndcPos.y)
            return Math.Vector2(screenPosX, screenPosY)

    def __tick(self):
        self.__updateMarkerPosition()
        self.__tickCallback = BigWorld.callback(self._UPDATE_TICK_RATE,
                                                self.__tick)
Ejemplo n.º 10
0
class ProgressiveItemsView(ViewImpl):
    __slots__ = ('__c11nView', '_itemsProgressData', '_possibleItems',
                 '_vehicle', '__blur', '__layoutID', '__urlMacros',
                 '__guiSettings')
    __lobbyContext = dependency.descriptor(ILobbyContext)
    __itemsCache = dependency.descriptor(IItemsCache)
    __customizationService = dependency.descriptor(ICustomizationService)
    __appLoader = dependency.descriptor(IAppLoader)
    __settingsCore = dependency.descriptor(ISettingsCore)

    def __init__(self, layoutID, c11nView, *args, **kwargs):
        settings = ViewSettings(layoutID)
        settings.args = args
        settings.kwargs = kwargs
        settings.flags = ViewFlags.LOBBY_TOP_SUB_VIEW
        settings.model = ProgressiveItemsViewModel()
        super(ProgressiveItemsView, self).__init__(settings)
        self._itemsProgressData = None
        self._possibleItems = None
        self._vehicle = None
        self.__blur = CachedBlur()
        self.__layoutID = layoutID
        self.__c11nView = c11nView
        self.__urlMacros = URLMacros()
        self.__guiSettings = GUI_SETTINGS.progressiveItems.get(
            'tutorialVideo', {})
        return

    def createToolTip(self, event):
        if event.contentID == R.views.common.tooltip_window.backport_tooltip_content.BackportTooltipContent(
        ):
            intCD = int(event.getArgument('id'))
            level = int(event.getArgument('level'))
            window = BackportTooltipWindow(
                self.__getTooltipData(intCD, event.getArgument('tooltip'),
                                      level), self.getParentWindow())
            window.load()
            return window
        return super(ProgressiveItemsView, self).createToolTip(event)

    @property
    def viewModel(self):
        return super(ProgressiveItemsView, self).getViewModel()

    def _initialize(self, *args, **kwargs):
        super(ProgressiveItemsView, self)._initialize(*args, **kwargs)
        if self.__c11nView is not None:
            self.__c11nView.changeVisible(False)
        self.viewModel.onSelectItem += self._onSelectItem
        self.viewModel.tutorial.showVideo += self._showVideoPage
        return

    def _finalize(self):
        super(ProgressiveItemsView, self)._finalize()
        if self.__c11nView is not None:
            self.__c11nView.changeVisible(True)
            self.__c11nView = None
        self.__blur.fini()
        self.viewModel.onSelectItem -= self._onSelectItem
        self.viewModel.tutorial.showVideo -= self._showVideoPage
        return

    def _onLoading(self, *args, **kwargs):
        self._vehicle = g_currentVehicle.item
        self._possibleItems = self._getPossibleItemsForVehicle()
        self._itemsProgressData = self.__itemsCache.items.inventory.getC11nProgressionDataForVehicle(
            self._vehicle.intCD)
        itemIntCD = kwargs.get('itemIntCD')
        with self.getViewModel().transaction() as model:
            model.setTankName(self._vehicle.userName)
            model.setTankLevel(int2roman(self._vehicle.level))
            model.setTankType(self._vehicle.typeBigIconResource())
            self.__setItems(model)
            model.setIsRendererPipelineDeferred(isRendererPipelineDeferred())
            model.setItemToScroll(0 if itemIntCD is None else itemIntCD)
        return

    def _onLoaded(self, *args, **kwargs):
        self.__blur.enable()
        self.__settingsCore.serverSettings.setOnceOnlyHintsSettings(
            {OnceOnlyHints.C11N_PROGRESSION_VIEW_HINT: HINT_SHOWN_STATUS})

    def _onSelectItem(self, args=None):
        if args is not None:
            intCD = int(args['intCD'])
            level = int(args['level'])
            item = self.__customizationService.getItemByCD(intCD)
            ctx = self.__customizationService.getCtx()

            def changeTabAndGetItemToHand():
                ctx.changeModeWithProgressionDecal(intCD)
                ctx.events.onGetItemBackToHand(item, level, scrollToItem=True)
                noveltyCount = self._vehicle.getC11nItemNoveltyCounter(
                    proxy=self.__itemsCache.items, item=item)
                if noveltyCount:
                    BigWorld.callback(
                        0.0, lambda: ctx.resetItemsNovelty([item.intCD]))

            BigWorld.callback(0.0, changeTabAndGetItemToHand)
        self.destroyWindow()
        return

    def _showVideoPage(self, args=None):
        self.__showVideo()

    @process
    def __showVideo(self):
        url = yield self.__urlMacros.parse(self.__guiSettings.get('url'))
        webHandlers = webApiCollection(ui_web_api.CloseViewWebApi,
                                       sound_web_api.SoundWebApi,
                                       sound_web_api.HangarSoundWebApi)
        ctx = {'url': url, 'webHandlers': webHandlers}
        showProgressiveItemsBrowserView(ctx)

    def _getPossibleItemsForVehicle(self):
        customizationCache = vehicles.g_cache.customization20()
        vehicleType = self._vehicle.descriptor.type
        sortedItems = sorted(
            customizationCache.customizationWithProgression.itervalues(),
            key=lambda i: i.id)
        return [
            item.compactDescr for item in sortedItems
            if item.filter.matchVehicleType(vehicleType)
        ]

    def __setItems(self, model):
        for intCD in self._possibleItems:
            itemModel = ItemModel()
            item = self.__customizationService.getItemByCD(intCD)
            itemModel.setItemId(intCD)
            itemModel.setItemUserString(item.userName)
            itemModel.setMaxLevel(item.getMaxProgressionLevel())
            itemModel.setScaleFactor(item.formfactor)
            latestOpenedLevel = item.getLatestOpenedProgressionLevel(
                self._vehicle)
            itemModel.setCurrentLevel(1 if latestOpenedLevel ==
                                      -1 else latestOpenedLevel + 1)
            self.__setEachLevelInfo(itemModel, item)
            model.progressiveItems.addViewModel(itemModel)

    def __setEachLevelInfo(self, model, item):
        for level in xrange(1, model.getMaxLevel() + 1):
            levelInfo = ItemLevelInfoModel()
            levelInfo.setLevel(level)
            levelInfo.setLevelText(getProgressionItemStatusText(level))
            levelInfo.setUnlocked(level < model.getCurrentLevel())
            icon = item.iconUrlByProgressionLevel(
                level, _PREVIEW_ICON_SIZE,
                _PREVIEW_ICON_INNER_SIZE.get(item.formfactor))
            levelInfo.setIcon(icon)
            if level == model.getCurrentLevel():
                levelInfo.setInProgress(True)
                levelInfo.progressBlock.setUnlockCondition(
                    _ms(
                        item.progressionConditions.get(level, {})[0].get(
                            'description', '')))
                currProgress = int(
                    item.getCurrentProgressOnCurrentLevel(self._vehicle))
                currProgress = currProgress if currProgress > 0 else 0
                maxProgress = int(
                    item.progressionConditions.get(level,
                                                   {})[0].get('value', '1'))
                if maxProgress > 1:
                    levelInfo.progressBlock.setProgressionVal(currProgress)
                    levelInfo.progressBlock.setMaxProgressionVal(maxProgress)
                else:
                    levelInfo.progressBlock.setHideProgressBarAndString(True)
            model.eachLevelInfo.addViewModel(levelInfo)

    @staticmethod
    def __getTooltipData(intCD, tooltip, level):
        return createTooltipData(isSpecial=True,
                                 specialAlias=tooltip,
                                 specialArgs=CustomizationTooltipContext(
                                     itemCD=intCD,
                                     level=level,
                                     showOnlyProgressBlock=True))
class BattleStrongholdsQueue(BattleStrongholdsQueueMeta, LobbySubView, ClanEmblemsHelper, IGlobalListener):
    __sound_env__ = BattleQueueEnv
    itemsCache = dependency.descriptor(IItemsCache)
    ANIMATION_DEFAULT_DURATION = 5

    def __init__(self, _=None):
        super(BattleStrongholdsQueue, self).__init__()
        self.__timerCallback = None
        self.__startAnimationTime = None
        self.__animationDuration = self.ANIMATION_DEFAULT_DURATION
        self.__groups = []
        self.__battleQueueVO = {}
        self.__imagesFetchCoordinator = ImagesFetchCoordinator()
        self._blur = CachedBlur()
        return

    @prbEntityProperty
    def prbEntity(self):
        return None

    def exitClick(self):
        self.prbEntity.exitFromQueue()

    def onClanEmblem32x32Received(self, clanDbID, emblem):
        clanEmblem = getTextureLinkByID(self.getMemoryTexturePath(emblem)) if emblem else None
        self.__battleQueueVO['myClanIcon'] = clanEmblem or ''
        self.as_setTypeInfoS(self.__battleQueueVO)
        self.prbEntity.getMatchmakingInfo(callback=self.__onMatchmakingInfo)
        return

    def onEscape(self):
        dialogsContainer = self.app.containerManager.getContainer(WindowLayer.TOP_WINDOW)
        if not dialogsContainer.getView(criteria={POP_UP_CRITERIA.VIEW_ALIAS: VIEW_ALIAS.LOBBY_MENU}):
            self.fireEvent(events.LoadViewEvent(SFViewLoadParams(VIEW_ALIAS.LOBBY_MENU)), scope=EVENT_BUS_SCOPE.LOBBY)

    def onStartBattle(self):
        self.__stopUpdateScreen()

    def onStrongholdMaintenance(self, showWindow):
        self.__showBattleRoom()

    def onUnitFlagsChanged(self, flags, timeLeft):
        if not self.prbEntity.canShowStrongholdsBattleQueue():
            self.__showBattleRoom()

    def onUpdateHeader(self, header, isFirstBattle, isUnitFreezed):
        self.__battleQueueVO['title'] = self.__getTitle()
        self.as_setTypeInfoS(self.__battleQueueVO)
        self.__requestClanIcon()

    def _populate(self):
        super(BattleStrongholdsQueue, self)._populate()
        self._blur.enable()
        self.addListener(events.GameEvent.SHOW_EXTERNAL_COMPONENTS, self._onShowExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self.addListener(events.GameEvent.HIDE_EXTERNAL_COMPONENTS, self._onHideExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self.startPrbListening()
        self.addListener(events.StrongholdEvent.STRONGHOLD_ON_TIMER, self.__onMatchmakingTimerChanged, scope=EVENT_BUS_SCOPE.STRONGHOLD)
        g_playerEvents.onArenaCreated += self.onStartBattle
        if self.prbEntity is not None:
            permissions = self.prbEntity.getPermissions()
            self.as_showExitS(permissions.canStopBattleQueue())
        self.as_showWaitingS('')
        self.__battleQueueVO = self.__getBattleQueueVO()
        self.__requestClanIcon()
        MusicControllerWWISE.play()
        return

    def _dispose(self):
        self.__stopUpdateScreen()
        g_playerEvents.onArenaCreated -= self.onStartBattle
        self.stopPrbListening()
        self.removeListener(events.StrongholdEvent.STRONGHOLD_ON_TIMER, self.__onMatchmakingTimerChanged, scope=EVENT_BUS_SCOPE.STRONGHOLD)
        self.__imagesFetchCoordinator.fini()
        self.removeListener(events.GameEvent.SHOW_EXTERNAL_COMPONENTS, self._onShowExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self.removeListener(events.GameEvent.HIDE_EXTERNAL_COMPONENTS, self._onHideExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self._blur.fini()
        super(BattleStrongholdsQueue, self)._dispose()

    def __getBattleQueueVO(self):
        return {'iconLabel': constants.ARENA_GUI_TYPE_LABEL.LABELS[constants.ARENA_GUI_TYPE.SORTIE_2],
         'title': self.__getTitle(),
         'leagueIcon': '',
         'myClanIcon': '',
         'myClanName': '',
         'myClanElo': text_styles.highTitleDisabled('--'),
         'myClanRating': ''}

    def __requestClanIcon(self):
        myClanIcon = self.__battleQueueVO['myClanIcon']
        if not myClanIcon:
            entity = self.prbEntity
            if entity is not None and entity.isStrongholdSettingsValid():
                clan = entity.getStrongholdSettings().getHeader().getClan()
                self.requestClanEmblem32x32(clan.getId())
                self.__battleQueueVO['myClanName'] = getClanTag(clan.getTag(), clan.getColor())
        return

    def __getTitle(self):
        entity = self.prbEntity
        if entity is not None and entity.isStrongholdSettingsValid():
            header = entity.getStrongholdSettings().getHeader()
            if header.isSortie():
                level = int2roman(header.getMaxLevel())
                title = makeString(FORTIFICATIONS.STRONGHOLDINFO_SORTIE) % {'level': level}
            else:
                direction = vo_converters.getDirection(header.getDirection())
                title = makeString(FORTIFICATIONS.STRONGHOLDINFO_STRONGHOLD) % {'direction': direction}
        else:
            title = ''
        return title

    @async
    @process
    def __parseClanData(self, clanData, serviceLeaguesEnabled, callback):
        updateData = {}
        myClanName = getClanTag(clanData.get('tag'), clanData.get('color') or '')
        if myClanName:
            updateData['myClanName'] = myClanName
        myClanIcon = yield self.__imagesFetchCoordinator.fetchImageByUrl(clanData.get('emblem'), oneUse=False)
        if myClanIcon:
            updateData['myClanIcon'] = myClanIcon
        leagueIcon = yield self.__imagesFetchCoordinator.fetchImageByUrl(clanData.get('back_emblem'), oneUse=False)
        if leagueIcon:
            updateData['leagueIcon'] = leagueIcon
        if serviceLeaguesEnabled:
            myClanRating = clanData.get('position')
            if isinstance(myClanRating, int):
                textStyle = text_styles.highTitle
                updateData['myClanRating'] = textStyle(backport.getNiceNumberFormat(myClanRating))
            else:
                textStyle = text_styles.highTitleDisabled
                updateData['myClanRating'] = textStyle('--')
        else:
            textStyle = text_styles.highTitleDisabled
        myClanElo = clanData.get('elo')
        if isinstance(myClanElo, int):
            updateData['myClanElo'] = textStyle(backport.getNiceNumberFormat(myClanElo))
        callback(updateData)

    @async
    @process
    def __parseGroupsData(self, groupsData, callback):
        groups = []
        for group in groupsData:
            clans = []
            for clan in group.get('clans', []):
                clanVO = {'title': makeString(FORTIFICATIONS.BATTLEQUEUE_CLANPOSITION, position='--'),
                 'clanName': getClanTag(clan.get('tag'), clan.get('color') or ''),
                 'clanElo': '--',
                 'tooltip': ''}
                leagueIconUrl = clan.get('back_emblem')
                if leagueIconUrl:
                    clanVO['leagueIcon'] = yield self.__imagesFetchCoordinator.fetchImageByUrl(clan.get('back_emblem'), oneUse=False)
                    if not clanVO['leagueIcon']:
                        callback([])
                        return
                clanVO['clanIcon'] = yield self.__imagesFetchCoordinator.fetchImageByUrl(clan.get('emblem'), oneUse=False)
                if not clanVO['clanIcon']:
                    callback([])
                    return
                elo = clan.get('elo')
                if isinstance(elo, int):
                    clanVO['clanElo'] = backport.getNiceNumberFormat(elo)
                position = clan.get('position')
                if isinstance(position, int):
                    position = backport.getNiceNumberFormat(position)
                    clanVO['title'] = makeString(FORTIFICATIONS.BATTLEQUEUE_CLANPOSITION, position=position)
                clans.append(clanVO)

            groups.append({'title': group.get('title'),
             'leagues': clans})

        callback(groups)

    @process
    def __onMatchmakingInfo(self, response):
        if response.getCode() == ResponseCodes.NO_ERRORS and response.getData():
            data = response.getData()
            self.__animationDuration = data.get('animation_time', self.ANIMATION_DEFAULT_DURATION)
            groupsData = data.get('groups', [])
            updateData = yield self.__parseClanData(data.get('clan', {}), bool(groupsData))
            self.__battleQueueVO.update(updateData)
            self.as_setTypeInfoS(self.__battleQueueVO)
            self.__groups = yield self.__parseGroupsData(groupsData)

    def __stopUpdateScreen(self):
        if self.__timerCallback is not None:
            BigWorld.cancelCallback(self.__timerCallback)
            self.__timerCallback = None
        return

    def __onMatchmakingTimerChanged(self, event):
        data = event.ctx
        if data['dtime'] > 0 and data['textid'] in (TOOLTIPS.STRONGHOLDS_TIMER_SQUADINQUEUE, FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON):
            timerLabel = i18n.makeString(FORTIFICATIONS.BATTLEQUEUE_WAITBATTLE)
            currentTime = data['dtime']
        else:
            _, unit = self.prbEntity.getUnit()
            currentTime = 0
            if unit:
                timestamp = unit.getModalTimestamp()
                if timestamp:
                    currentTime = max(0, int(time_utils.getServerUTCTime() - timestamp))
            if data['isSortie'] or data['isFirstBattle']:
                timerLabel = i18n.makeString(FORTIFICATIONS.BATTLEQUEUE_SEARCHENEMY)
            else:
                timerLabel = i18n.makeString(FORTIFICATIONS.BATTLEQUEUE_WAITBATTLE)
        timeLabel = '%d:%02d' % divmod(currentTime, 60)
        self.as_setTimerS(timerLabel, timeLabel)
        n = len(self.__groups)
        if n != 0:
            self.as_hideWaitingS()
            if self.__startAnimationTime is None:
                self.__startAnimationTime = time_utils.getCurrentTimestamp()
            i, r = divmod(int(time_utils.getCurrentTimestamp() - self.__startAnimationTime), self.__animationDuration)
            if r == 0:
                self.as_setLeaguesS(self.__groups[i % n])
        return

    @staticmethod
    def __showBattleRoom():
        g_eventDispatcher.loadStrongholds()
        g_eventDispatcher.loadHangar()

    def _onHideExternals(self, _):
        self._blur.disable()

    def _onShowExternals(self, _):
        self._blur.enable()
class BattleQueue(BattleQueueMeta, LobbySubView):
    __sound_env__ = BattleQueueEnv

    def __init__(self, _=None):
        super(BattleQueue, self).__init__()
        self.__createTime = 0
        self.__timerCallback = None
        self.__provider = None
        self._blur = CachedBlur()
        return

    @prbEntityProperty
    def prbEntity(self):
        return None

    def onEscape(self):
        dialogsContainer = self.app.containerManager.getContainer(WindowLayer.TOP_WINDOW)
        if not dialogsContainer.getView(criteria={POP_UP_CRITERIA.VIEW_ALIAS: VIEW_ALIAS.LOBBY_MENU}):
            self.fireEvent(events.LoadViewEvent(SFViewLoadParams(VIEW_ALIAS.LOBBY_MENU)), scope=EVENT_BUS_SCOPE.LOBBY)

    def startClick(self):
        if self.__provider is not None:
            self.__provider.forceStart()
        return

    def exitClick(self):
        self.prbEntity.exitFromQueue()

    def onStartBattle(self):
        self.__stopUpdateScreen()

    def _populate(self):
        super(BattleQueue, self)._populate()
        self._blur.enable()
        self.addListener(events.GameEvent.SHOW_EXTERNAL_COMPONENTS, self._onShowExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self.addListener(events.GameEvent.HIDE_EXTERNAL_COMPONENTS, self._onHideExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        g_playerEvents.onArenaCreated += self.onStartBattle
        self.__updateQueueInfo()
        self.__updateTimer()
        self.__updateClientState()
        MusicControllerWWISE.play()

    def _dispose(self):
        self.__stopUpdateScreen()
        g_playerEvents.onArenaCreated -= self.onStartBattle
        self.removeListener(events.GameEvent.SHOW_EXTERNAL_COMPONENTS, self._onShowExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self.removeListener(events.GameEvent.HIDE_EXTERNAL_COMPONENTS, self._onHideExternals, scope=EVENT_BUS_SCOPE.GLOBAL)
        self._blur.fini()
        super(BattleQueue, self)._dispose()

    def __updateClientState(self):
        if self.prbEntity is None:
            return
        else:
            permissions = self.prbEntity.getPermissions()
            if not permissions.canExitFromQueue():
                self.as_showExitS(False)
            guiType = prb_getters.getArenaGUIType(queueType=self.__provider.getQueueType())
            title = MENU.loading_battletypes(guiType)
            description = MENU.loading_battletypes_desc(guiType)
            if guiType != constants.ARENA_GUI_TYPE.UNKNOWN and guiType in constants.ARENA_GUI_TYPE_LABEL.LABELS:
                iconlabel = constants.ARENA_GUI_TYPE_LABEL.LABELS[guiType]
            else:
                iconlabel = 'neutral'
            if self.__provider.needAdditionalInfo():
                additional = self.__provider.additionalInfo()
            else:
                additional = ''
            vehicle = g_currentVehicle.item
            textLabel = self.__provider.getTankInfoLabel()
            tankName = vehicle.shortUserName
            iconPath = self.__provider.getTankIcon(vehicle)
            layoutStr = self.__provider.getLayoutStr()
            self.as_setTypeInfoS({'iconLabel': iconlabel,
             'title': title,
             'description': description,
             'additional': additional,
             'tankLabel': text_styles.main(textLabel),
             'tankIcon': iconPath,
             'tankName': tankName,
             'layoutStr': layoutStr})
            return

    def __stopUpdateScreen(self):
        if self.__timerCallback is not None:
            BigWorld.cancelCallback(self.__timerCallback)
            self.__timerCallback = None
        if self.__provider is not None:
            self.__provider.stop()
            self.__provider = None
        return

    def __updateQueueInfo(self):
        if self.prbEntity is None:
            return
        else:
            qType = self.prbEntity.getQueueType()
            self.__provider = _providerFactory(self, qType)
            self.__provider.start()
            return

    def __updateTimer(self):
        self.__timerCallback = None
        self.__timerCallback = BigWorld.callback(1, self.__updateTimer)
        textLabel = text_styles.main(makeString(MENU.PREBATTLE_TIMERLABEL))
        timeLabel = '%d:%02d' % divmod(self.__createTime, 60)
        if self.__provider is not None and self.__provider.needAdditionalInfo():
            timeLabel = text_styles.concatStylesToSingleLine(timeLabel, '*')
        self.as_setTimerS(textLabel, timeLabel)
        self.__createTime += 1
        return

    def _getProvider(self):
        return self.__provider

    def _onHideExternals(self, _):
        self._blur.disable()

    def _onShowExternals(self, _):
        self._blur.enable()
class BuyVehicleView(ViewImpl, EventSystemEntity):
    __itemsCache = dependency.descriptor(IItemsCache)
    __rentals = dependency.descriptor(IRentalsController)
    __tradeIn = dependency.descriptor(ITradeInController)
    __wallet = dependency.descriptor(IWalletController)
    __restore = dependency.descriptor(IRestoreController)
    __bootcamp = dependency.descriptor(IBootcampController)
    __eventProgression = dependency.descriptor(IEventProgressionController)
    __RENT_NOT_SELECTED_IDX = -2
    __RENT_UNLIM_IDX = -1
    __CREW_NOT_SELECTED_IDX = -1
    __TRADE_OFF_NOT_SELECTED = -1

    def __init__(self, **kwargs):
        settings = ViewSettings(
            R.views.lobby.shop.buy_vehicle_view.BuyVehicleView())
        settings.model = BuyVehicleViewModel()
        super(BuyVehicleView, self).__init__(settings)
        self.__shop = self.__itemsCache.items.shop
        self.__stats = self.__itemsCache.items.stats
        ctx = kwargs.get('ctx')
        if ctx is not None:
            self.__nationID = ctx.get('nationID')
            self.__inNationID = ctx.get('itemID')
            self.__previousAlias = ctx.get('previousAlias')
            self.__actionType = ctx.get('actionType')
            self.__showOnlyCongrats = ctx.get('showOnlyCongrats')
            self.__congratsViewSettings = ctx.get(
                'congratulationsViewSettings')
        else:
            self.__nationID = None
            self.__inNationID = None
            self.__previousAlias = ''
            self.__actionType = VehicleBuyActionTypes.DEFAULT
            self.__showOnlyCongrats = False
            self.__congratsViewSettings = {}
        self.__selectedCardIdx = 0 if not self.__bootcamp.isInBootcamp(
        ) else _ACADEMY_SLOT
        self.__isWithoutCommander = False
        self.__vehicle = self.__itemsCache.items.getItem(
            GUI_ITEM_TYPE.VEHICLE, self.__nationID, self.__inNationID)
        self.__tradeOffVehicle = self.__tradeIn.getActiveTradeOffVehicle()
        if self.__vehicle.isRestoreAvailable():
            self.__selectedRentID = self.__RENT_NOT_SELECTED_IDX
            self.__selectedRentIdx = self.__RENT_NOT_SELECTED_IDX
        else:
            self.__selectedRentID = self.__RENT_UNLIM_IDX
            self.__selectedRentIdx = self.__RENT_UNLIM_IDX
        self.__isGoldAutoPurchaseEnabled = self.__wallet.isAvailable
        self.__isRentVisible = self.__vehicle.hasRentPackages and not self.__isTradeIn(
        )
        self.__popoverIsAvailable = True
        self.__tradeInInProgress = False
        self.__purchaseInProgress = False
        return

    @property
    def viewModel(self):
        return super(BuyVehicleView, self).getViewModel()

    def createToolTip(self, event):
        if event.contentID == R.views.common.tooltip_window.backport_tooltip_content.BackportTooltipContent(
        ):
            tooltipData = self.__getBackportTooltipData(event)
            if tooltipData is None:
                return
            window = BackportTooltipWindow(tooltipData, self.getParentWindow())
            if window is None:
                return
            window.load()
            return window
        else:
            return super(BuyVehicleView, self).createToolTip(event)

    def showCongratulations(self):
        self.__showHangar()
        if self.__isRenting():
            self.__onWindowClose()
        else:
            self.__showCongratulationsView()

    def _initialize(self, *args, **kwargs):
        super(BuyVehicleView, self)._initialize()
        self._blur = CachedBlur(enabled=True)
        self.__addListeners()
        isElite = self.__vehicle.isElite
        vehType = self.__vehicle.type.replace('-', '_')
        isRestore = self.__vehicle.isRestoreAvailable()
        if self.__showOnlyCongrats:
            self.viewModel.setIsContentHidden(True)
        with self.viewModel.transaction() as vm:
            vm.setIsRestore(isRestore)
            vm.setBgSource(
                R.images.gui.maps.icons.store.shop_2_background_arsenal())
            vm.setTankType('{}_elite'.format(vehType) if isElite else vehType)
            vehicleTooltip = i18n.makeString(
                getTypeUserName(self.__vehicle.type, isElite))
            noCrewLabelPath = R.strings.store.buyVehicleWindow.checkBox
            vm.setVehicleNameTooltip(vehicleTooltip)
            vm.setNation(nations.NAMES[self.__vehicle.nationID])
            vm.setNoCrewCheckboxLabel(noCrewLabelPath.restore.withoutCrew(
            ) if isRestore else noCrewLabelPath.buy.withoutCrew())
            vm.setTankLvl(int2roman(self.__vehicle.level))
            vm.setTankName(self.__vehicle.shortUserName)
            vm.setCountCrew(len(self.__vehicle.crew))
            vm.setBuyVehicleIntCD(self.__vehicle.intCD)
            vm.setIsElite(isElite)
            if self.__vehicle.hasCrew:
                vm.setWithoutCommanderAltText(
                    R.strings.store.buyVehicleWindow.crewInVehicle())
            equipmentBlock = vm.equipmentBlock
            equipmentBlock.setIsRentVisible(self.__isRentVisible)
            equipmentBlock.setTradeInIsEnabled(self.__isTradeIn())
            emtySlotAvailable = self.__itemsCache.items.inventory.getFreeSlots(
                self.__stats.vehicleSlots) > 0
            equipmentBlock.setEmtySlotAvailable(emtySlotAvailable)
            equipmentBlock.setIsRestore(isRestore)
            if self.__vehicle.hasRentPackages and (
                    not isRestore
                    or self.__actionType == VehicleBuyActionTypes.RENT
            ) and self.__actionType != VehicleBuyActionTypes.BUY:
                self.__selectedRentIdx = 0
                self.__selectedRentID = self.__vehicle.rentPackages[
                    self.__selectedRentIdx]['rentID']
            self.__updateCommanderCards()
            self.__updateSlotPrice()
            self.__updateAmmoPrice()
            self.__updateTradeInInfo()
            self.__updateRentInfo()
            self.__updateBuyBtnLabel()
            totalPriceArray = equipmentBlock.totalPrice.getItems()
            self.__addVMsInActionPriceList(
                totalPriceArray,
                ItemPrice(price=Money(credits=0, gold=0),
                          defPrice=Money(credits=0, gold=0)))
            self.__updateTotalPrice()

    def _finalize(self):
        self._blur.fini()
        self.__removeListeners()
        super(BuyVehicleView, self)._finalize()

    def __addListeners(self):
        self.addListener(ShopEvent.CONFIRM_TRADE_IN, self.__onTradeInConfirmed,
                         EVENT_BUS_SCOPE.LOBBY)
        self.addListener(ShopEvent.SELECT_RENT_TERM, self.__onRentTermSelected,
                         EVENT_BUS_SCOPE.LOBBY)
        self.addListener(VehicleBuyEvent.VEHICLE_SELECTED,
                         self.__onTradeOffVehicleSelected)
        g_clientUpdateManager.addMoneyCallback(self.__updateIsEnoughStatus)
        self.__wallet.onWalletStatusChanged += self.__onWalletStatusChanged
        self.viewModel.onCloseBtnClick += self.__onWindowClose
        self.viewModel.onInHangarClick += self.__onInHangar
        self.viewModel.onCheckboxWithoutCrewChanged += self.__onCheckboxWithoutCrewChanged
        self.viewModel.onBuyBtnClick += self.__onBuyBtnClick
        self.viewModel.onCommanderLvlChange += self.__onCommanderLvlChange
        self.viewModel.onBackClick += self.__onWindowClose
        equipmentBlock = self.viewModel.equipmentBlock
        equipmentBlock.onSelectTradeOffVehicle += self.__onSelectTradeOffVehicle
        equipmentBlock.onCancelTradeOffVehicle += self.__onCancelTradeOffVehicle
        equipmentBlock.slot.onSelectedChange += self.__onSelectedChange
        equipmentBlock.ammo.onSelectedChange += self.__onSelectedChange
        self.__restore.onRestoreChangeNotify += self.__onRestoreChange
        self.__itemsCache.onSyncCompleted += self.__onItemCacheSyncCompleted

    def __removeListeners(self):
        self.removeListener(ShopEvent.CONFIRM_TRADE_IN,
                            self.__onTradeInConfirmed, EVENT_BUS_SCOPE.LOBBY)
        self.removeListener(ShopEvent.SELECT_RENT_TERM,
                            self.__onRentTermSelected, EVENT_BUS_SCOPE.LOBBY)
        self.removeListener(VehicleBuyEvent.VEHICLE_SELECTED,
                            self.__onTradeOffVehicleSelected)
        g_clientUpdateManager.removeObjectCallbacks(self)
        self.__wallet.onWalletStatusChanged -= self.__onWalletStatusChanged
        self.viewModel.onCloseBtnClick -= self.__onWindowClose
        self.viewModel.onInHangarClick -= self.__onInHangar
        self.viewModel.onCheckboxWithoutCrewChanged -= self.__onCheckboxWithoutCrewChanged
        self.viewModel.onBuyBtnClick -= self.__onBuyBtnClick
        self.viewModel.onCommanderLvlChange -= self.__onCommanderLvlChange
        self.viewModel.onBackClick -= self.__onWindowClose
        equipmentBlock = self.viewModel.equipmentBlock
        equipmentBlock.onSelectTradeOffVehicle -= self.__onSelectTradeOffVehicle
        equipmentBlock.onCancelTradeOffVehicle -= self.__onCancelTradeOffVehicle
        equipmentBlock.slot.onSelectedChange -= self.__onSelectedChange
        equipmentBlock.ammo.onSelectedChange -= self.__onSelectedChange
        self.__restore.onRestoreChangeNotify -= self.__onRestoreChange
        self.__itemsCache.onSyncCompleted -= self.__onItemCacheSyncCompleted

    def __onItemCacheSyncCompleted(self, *_):
        if self.__purchaseInProgress or self.viewModel is None or self.viewModel.proxy is None:
            return
        else:
            self.__vehicle = self.__itemsCache.items.getItem(
                GUI_ITEM_TYPE.VEHICLE, self.__nationID, self.__inNationID)
            self.__shop = self.__itemsCache.items.shop
            self.__stats = self.__itemsCache.items.stats
            if self.viewModel.getIsRestore():
                self.__selectedRentIdx = self.__RENT_NOT_SELECTED_IDX
                self.__selectedRentID = self.__RENT_NOT_SELECTED_IDX
            elif self.__vehicle.hasRentPackages and self.__vehicle.rentPackages:
                self.__selectedRentIdx = 0
                self.__selectedRentID = self.__vehicle.rentPackages[
                    self.__selectedRentIdx]['rentID']
            else:
                self.__selectedRentIdx = self.__RENT_UNLIM_IDX
                self.__selectedRentID = self.__RENT_NOT_SELECTED_IDX
            self.__updateCommanderCards()
            self.__updateSlotPrice()
            self.__updateAmmoPrice()
            self.__updateTradeInInfo()
            self.__updateRentInfo()
            self.__updateTotalPrice()
            return

    def __onInHangar(self, *_):
        event_dispatcher.selectVehicleInHangar(self.__vehicle.intCD)
        self.__destroyWindow()

    def __onCheckboxWithoutCrewChanged(self, args):
        self.__isWithoutCommander = args['selected']
        with self.viewModel.transaction() as vm:
            cardVMs = vm.commanderLvlCards.getItems()
            for cVm in cardVMs:
                cVm.setSlotIsEnabled(not self.__isWithoutCommander)

            if not self.__isWithoutCommander:
                self.__updateIsEnoughStatus()
        self.__updateTotalPrice()

    def __onBuyBtnClick(self):
        if self.__tradeInInProgress:
            return
        if self.viewModel.getIsContentHidden():
            self.__onInHangar()
            return
        totalPrice = self.__getTotalItemPrice().price
        if self.__isAvailablePrice(totalPrice):
            availableGold = self.__stats.money.gold
            requiredGold = totalPrice.gold
            if availableGold < requiredGold:
                showBuyGoldForVehicleWebOverlay(requiredGold,
                                                self.__vehicle.intCD)
                return
        self.__requestForMoneyObtain()

    def __onSelectedChange(self, *_):
        self.__updateTotalPrice()

    def __onCommanderLvlChange(self, args):
        cardModels = self.viewModel.commanderLvlCards.getItems()
        cardModels[self.__selectedCardIdx].setIsSelected(False)
        self.__selectedCardIdx = int(args['value'])
        cardModels[self.__selectedCardIdx].setIsSelected(True)
        self.__updateTotalPrice()

    def __onToggleRentAndTradeIn(self):
        self.__isRentVisible = not self.__isRentVisible
        self.__updateTradeOffVehicleIntCD()
        with self.viewModel.equipmentBlock.transaction() as equipmentBlockVm:
            tradeInVisible = not self.__isRentVisible and self.__isTradeIn(
            ) and self.__tradeOffVehicle is None
            equipmentBlockVm.vehicleTradeInBtn.setIsVisible(tradeInVisible)
            equipmentBlockVm.vehicleBtn.setVisible(tradeInVisible)
            equipmentBlockVm.vehicleRentBtn.setIsVisible(self.__isRentVisible)
            equipmentBlockVm.setIsRentVisible(self.__isRentVisible)
            if self.__isRentVisible:
                equipmentBlockVm.setPopoverIsAvailable(False)
            else:
                equipmentBlockVm.setPopoverIsAvailable(
                    self.__popoverIsAvailable)
            self.__updateSlotPrice()
            self.__updateTotalPrice()
        self.__updateBuyBtnLabel()
        return

    def __onSelectTradeOffVehicle(self, _=None):
        showTradeOffOverlay(self.__vehicle.level)

    def __onWalletStatusChanged(self, *_):
        self.__isGoldAutoPurchaseEnabled &= self.__wallet.isAvailable
        self.__updateTotalPrice()

    def __onTradeOffVehicleSelected(self, _=None):
        self.__tradeOffVehicle = self.__tradeIn.getActiveTradeOffVehicle()
        if self.__tradeOffVehicle is not None:
            self.__updateTradeInInfo()
            self.__updateSlotPrice()
            self.__updateTotalPrice()
        self.__updateBuyBtnLabel()
        return

    def __onCancelTradeOffVehicle(self, _=None):
        self.__tradeOffVehicle = None
        self.__tradeIn.setActiveTradeOffVehicleCD(UNDEFINED_ITEM_CD)
        self.__updateTradeInInfo()
        self.__updateTotalPrice()
        self.__updateSlotPrice()
        self.__updateBuyBtnLabel()
        return

    def __onTradeInConfirmed(self, *_):
        self.__requestForMoneyObtain()

    def __onRestoreChange(self, _):
        vehicle = self.__itemsCache.items.getItem(GUI_ITEM_TYPE.VEHICLE,
                                                  self.__nationID,
                                                  self.__inNationID)
        if vehicle and not vehicle.isRestoreAvailable():
            self.__onWindowClose()
            SystemMessages.pushI18nMessage(
                SYSTEM_MESSAGES.VEHICLE_RESTORE_FINISHED,
                vehicleName=vehicle.userName)

    def __onRentTermSelected(self, event):
        itemIdx = event.ctx
        self.__selectedRentIdx = itemIdx
        if self.__selectedRentIdx == self.__RENT_UNLIM_IDX:
            if self.viewModel.getIsRestore():
                self.__selectedRentIdx = self.__RENT_NOT_SELECTED_IDX
                self.__selectedRentID = self.__RENT_NOT_SELECTED_IDX
            else:
                self.__selectedRentID = self.__selectedRentIdx
        else:
            self.__selectedRentID = self.__vehicle.rentPackages[
                self.__selectedRentIdx]['rentID']
        self.viewModel.hold()
        self.__updateRentInfo()
        self.__updateTotalPrice()
        self.__updateBuyBtnLabel()
        self.__updateSlotPrice()
        self.viewModel.commit()

    def __onWindowClose(self, *_):
        self.__destroyWindow()

    def __destroyWindow(self):
        self.viewModel.congratulationAnim.setResetAnimTrgigger(True)
        self.destroyWindow()

    def __showHangar(self):
        if not self.__bootcamp.isInBootcamp():
            if self.__previousAlias in _VP_SHOW_HANGAR_ON_SUCCESS_ALIASES:
                event_dispatcher.selectVehicleInHangar(self.__vehicle.intCD)
            elif self.__previousAlias == VIEW_ALIAS.EVENT_PROGRESSION_VEHICLE_PREVIEW:
                self.__eventProgression.showCustomScreen(
                    EventProgressionScreens.MAIN)

    def __playSlotAnimation(self):
        if self.viewStatus != ViewStatus.LOADED:
            _logger.warning(
                'Can not show slot animation! The view is not loaded anymore.')
            return
        self.viewModel.equipmentBlock.setIsSlotAnimPlaying(True)

    def __showCongratulationsView(self):
        if self.viewStatus != ViewStatus.LOADED:
            _logger.warning(
                'Can not show congratulations! The view is not loaded anymore.'
            )
            return
        else:
            self.viewModel.setIsContentHidden(True)
            with self.viewModel.congratulationAnim.transaction() as vm:
                vehicleType = '{}_elite'.format(
                    self.__vehicle.type
                ) if self.__vehicle.isElite else self.__vehicle.type
                image = func_utils.makeFlashPath(
                    self.__vehicle.getShopIcon(
                        size=STORE_CONSTANTS.ICON_SIZE_LARGE))
                defaultImage = RES_SHOP.getVehicleIcon(
                    STORE_CONSTANTS.ICON_SIZE_LARGE, 'empty_tank')
                settings = self.__congratsViewSettings
                if settings and 'bgSource' in settings:
                    self.viewModel.setBgSource(settings['bgSource'])
                if settings and 'backBtnEnabled' in settings:
                    vm.setNeedBackBtn(settings['backBtnEnabled'])
                if settings and 'backBtnLabel' in settings:
                    vm.setBackBtnLbl(settings['backBtnLabel'])
                vm.setIsElite(self.__vehicle.isElite)
                vm.setIsCollectible(self.__vehicle.isCollectible)
                vm.setVehicleType(vehicleType)
                vm.setLvl(int2roman(self.__vehicle.level))
                vm.setVName(self.__vehicle.userName)
                vm.setImage(image if image is not None else defaultImage)
                vm.setImageAlt(defaultImage)
                vm.setTitle(R.strings.store.congratulationAnim.restoreLabel(
                ) if self.viewModel.getIsRestore() else R.strings.store.
                            congratulationAnim.buyingLabel())
                vm.setBtnLbl(
                    R.strings.store.congratulationAnim.showPreviewBtnLabel())
            return

    @decorators.process('buyItem')
    def __requestForMoneyObtain(self):
        equipmentBlock = self.viewModel.equipmentBlock
        isTradeIn = self.__isTradeIn(
        ) and self.__tradeOffVehicle is not None and not self.__isRentVisible
        isWithSlot = equipmentBlock.slot.getIsSelected()
        isWithAmmo = equipmentBlock.ammo.getIsSelected()
        if self.__isWithoutCommander:
            crewType = self.__CREW_NOT_SELECTED_IDX
        else:
            crewType = self.__selectedCardIdx
        result = None
        self.__purchaseInProgress = False
        if isTradeIn:
            confirmationType = 'tradeInConfirmation'
            addition = ''
            operations = []
            if self.__tradeOffVehicle.hasCrew:
                operations.append('crew')
            if self.__tradeOffVehicle.hasShells:
                operations.append('shells')
            if self.__tradeOffVehicle.hasConsumables:
                operations.append('equipments')
            if self.__tradeOffVehicle.hasOptionalDevices:
                operations.append('optionalDevices')
            if operations:
                operationsStr = [
                    i18n.makeString('#dialogs:%s/message/%s' %
                                    (confirmationType, o)) for o in operations
                ]
                addition = i18n.makeString('#dialogs:%s/message/addition' %
                                           confirmationType,
                                           operations=', '.join(operationsStr))
            ctx = {
                'vehName': neutral(self.__tradeOffVehicle.userName),
                'addition': addition
            }
            self.__tradeInInProgress = True
            result = yield showI18nConfirmDialog(
                confirmationType,
                meta=I18nConfirmDialogMeta(confirmationType, ctx, ctx),
                focusedID=DIALOG_BUTTON_ID.SUBMIT)
            if not result or self.isDisposed():
                return
            result = yield VehicleTradeInProcessor(self.__vehicle,
                                                   self.__tradeOffVehicle,
                                                   isWithSlot, isWithAmmo,
                                                   crewType).request()
            if result.userMsg:
                SystemMessages.pushI18nMessage(result.userMsg,
                                               type=result.sysMsgType)
            if self.isDisposed():
                return
            self.__tradeInInProgress = False
            if not result.success:
                self.__onWindowClose()
                return
        else:
            self.__purchaseInProgress = True
        if isWithSlot:
            result = yield VehicleSlotBuyer(showConfirm=False,
                                            showWarning=False).request()
            if result.userMsg:
                SystemMessages.pushI18nMessage(result.userMsg,
                                               type=result.sysMsgType)
            if not result.success or self.isDisposed():
                self.__purchaseInProgress = False
                return
        if not isTradeIn:
            emptySlotAvailable = self.__itemsCache.items.inventory.getFreeSlots(
                self.__stats.vehicleSlots) > 0
            if self.__isBuying():
                if self.viewModel.getIsRestore():
                    result = yield self.__getRestoreVehicleProcessor(
                        crewType).request()
                else:
                    result = yield self.__getObtainVehicleProcessor(
                        crewType).request()
                if not emptySlotAvailable and not isWithSlot and not self.isDisposed(
                ):
                    self.__playSlotAnimation()
            else:
                result = yield VehicleRenter(self.__vehicle,
                                             self.__selectedRentID, isWithAmmo,
                                             crewType).request()
            if result.userMsg:
                SystemMessages.pushI18nMessage(result.userMsg,
                                               type=result.sysMsgType)
            self.__purchaseInProgress = False
        if result and result.success and not self.isDisposed():
            self.__startTutorial()
            self.showCongratulations()
        return

    def __updateActionPriceArray(self, priceArray, itemPrice):
        for priceModel in priceArray:
            self.__updatePriceModel(priceModel, itemPrice)

    def __updatePriceModel(self, priceModel, itemPrice):
        numberFormat = self.gui.systemLocale.getNumberFormat
        statsMoney = self.__stats.money
        price = itemPrice.price
        defPrice = itemPrice.defPrice
        currencyType = priceModel.getType()
        currencyValue = price.get(currencyType)
        if currencyValue is not None:
            priceModel.setPrice(numberFormat(currencyValue))
            priceModel.setDefPrice(numberFormat(defPrice.get(currencyType, 0)))
        else:
            for currencyType in Currency.ALL:
                currencyValue = price.get(currencyType)
                if currencyValue:
                    priceModel.setType(currencyType)
                    priceModel.setPrice(numberFormat(currencyValue))
                    break

        priceModel.setAction(itemPrice.getActionPrc())
        if self.__isPurchaseCurrencyAvailable(currencyType):
            isEnough = True
        else:
            isEnough = statsMoney.get(currencyType) >= currencyValue
        priceModel.setIsEnough(isEnough)
        hasAction = itemPrice.getActionPrcAsMoney().get(
            currencyType) is not None
        priceModel.setIsWithAction(hasAction)
        if hasAction:
            updateActionInViewModel(currencyType, priceModel, itemPrice)
        priceModel.setIsBootcamp(self.__bootcamp.isInBootcamp())
        return

    def __updateSlotPrice(self):
        slotItemPrice = self.__shop.getVehicleSlotsItemPrice(
            self.__stats.vehicleSlots)
        with self.viewModel.equipmentBlock.slot.transaction() as slotVm:
            listArray = slotVm.actionPrices.getItems()
            isAvailable = self.__getSlotIsAvailable(slotItemPrice.price)
            slotVm.setIsDisabledTooltip(self.__selectedRentIdx >= 0
                                        and self.__isRentVisible)
            slotVm.setIsEnabled(isAvailable)
            if not isAvailable:
                slotVm.setIsSelected(False)
            isInit = len(listArray) == 0
            if isInit:
                self.__addVMsInActionPriceList(
                    listArray,
                    slotItemPrice,
                    not self.__isGoldAutoPurchaseEnabled,
                    tooltipData=_TooltipExtraData(
                        'slotsPrices', ACTION_TOOLTIPS_TYPE.ECONOMICS))
            else:
                self.__updateActionPriceArray(listArray, slotItemPrice)

    def __updateAmmoPrice(self):
        ammoItemPrice = self.__getAmmoItemPrice()
        with self.viewModel.equipmentBlock.ammo.transaction() as ammoVm:
            isAvailable = self.__getAmmoIsAvailable(ammoItemPrice.price)
            ammoVm.setIsDisabledTooltip(self.__vehicle.isAmmoFull)
            ammoVm.setIsEnabled(isAvailable)
            if not isAvailable:
                ammoVm.setIsSelected(False)
            listArray = ammoVm.actionPrices.getItems()
            isInit = len(listArray) == 0
            if isInit:
                self.__addVMsInActionPriceList(listArray, ammoItemPrice)
            else:
                self.__updateActionPriceArray(listArray, ammoItemPrice)

    def __updateCommanderCards(self):
        commanderLvlsCost = self.__shop.getTankmanCostItemPrices()
        listArray = self.viewModel.commanderLvlCards.getItems()
        isInit = len(listArray) == 0
        countLvls = len(commanderLvlsCost)
        commanderLvlPercents = CrewTypes.CREW_AVAILABLE_SKILLS
        for idx in xrange(countLvls):
            commanderItemPrice = commanderLvlsCost[idx]
            commanderItemPrice *= len(self.__vehicle.crew)
            if isInit:
                commanderLvlModel = CommanderSlotModel()
                commanderLvlModel.setIdx(idx)
                commanderLvlModel.setPercents(commanderLvlPercents[idx])
                commanderLvlModel.setTitle(
                    i18n.makeString(STORE.BUYVEHICLEWINDOW_SLOT_ENUM[idx]))
                commanderLvlModel.setIsBootcamp(self.__bootcamp.isInBootcamp())
                if not self.__vehicle.hasCrew:
                    commanderLvlModel.setIsSelected(
                        idx == self.__selectedCardIdx)
            else:
                commanderLvlModel = listArray[idx]
            commanderLvlModel.setDiscount(commanderItemPrice.getActionPrc())
            isFree = commanderItemPrice.price <= ZERO_MONEY and commanderItemPrice.getActionPrc(
            ) == 0
            commanderLvlModel.setIsFree(isFree)
            if self.__vehicle.hasCrew:
                isEnabled = False
            elif self.__bootcamp.isInBootcamp():
                isEnabled = idx == _ACADEMY_SLOT
            elif not isFree:
                isEnabled = self.__isAvailablePrice(commanderItemPrice.price)
            else:
                isEnabled = True
            commanderLvlModel.setSlotIsEnabled(
                isEnabled and not self.__isWithoutCommander)
            commanderActionPriceArray = commanderLvlModel.actionPrice.getItems(
            )
            if isInit:
                self.__addVMsInActionPriceList(
                    commanderActionPriceArray,
                    commanderItemPrice,
                    not isEnabled,
                    tooltipData=_TooltipExtraData(
                        _TANKMAN_KEYS[idx], ACTION_TOOLTIPS_TYPE.ECONOMICS))
                listArray.addViewModel(commanderLvlModel)
            self.__updateActionPriceArray(commanderActionPriceArray,
                                          commanderItemPrice)

    def __updateTradeInInfo(self):
        self.__updateTradeOffVehicleIntCD()
        with self.viewModel.transaction() as vm:
            vm.equipmentBlock.setTradeOffWidgetEnabled(
                bool(self.__tradeIn.getTradeOffVehicles()))
            vm.equipmentBlock.setBuyVehicleIntCD(self.__vehicle.intCD)
            with vm.equipmentBlock.vehicleTradeInBtn.transaction(
            ) as vehicleTradeInBtnVm:
                if self.__isTradeIn():
                    vehicleTradeInBtnVm.setIcon(
                        R.images.gui.maps.icons.library.trade_in())
                    vehicleTradeInBtnVm.setLabel(
                        R.strings.store.buyVehicleWindow.tradeInBtnLabel())
                isTradeIn = not self.__isRentVisible and self.__isTradeIn()
                vehicleTradeInBtnVm.setIsVisible(
                    isTradeIn and self.__tradeOffVehicle is None)
            self.__updateTradeOffVehicleBtnData()
        return

    def __updateTradeOffVehicleIntCD(self):
        with self.viewModel.transaction() as vm:
            self.__tradeOffVehicle = self.__tradeIn.getActiveTradeOffVehicle()
            if self.__isTradeIn(
            ) and self.__tradeOffVehicle is not None and not self.__isRentVisible:
                vm.setTradeOffVehicleIntCD(self.__tradeOffVehicle.intCD)
                vm.equipmentBlock.setTradeOffVehicleIntCD(
                    self.__tradeOffVehicle.intCD)
            else:
                vm.setTradeOffVehicleIntCD(self.__TRADE_OFF_NOT_SELECTED)
                vm.equipmentBlock.setTradeOffVehicleIntCD(
                    self.__TRADE_OFF_NOT_SELECTED)
        return

    def __updateRentInfo(self):
        with self.viewModel.transaction() as vm:
            vm.setIsRentSelected(self.__selectedRentID >= 0)
        with self.viewModel.equipmentBlock.transaction() as equipmentBlockVm:
            selectedRentDays = 0
            selectedRentSeason = 0
            if self.__selectedRentID >= 0:
                rentType, packageID = parseRentID(self.__selectedRentID)
                rentPackage = self.__vehicle.rentPackages[
                    self.__selectedRentIdx]
                if rentType == constants.RentType.TIME_RENT:
                    selectedRentDays = packageID
                elif rentType in (constants.RentType.SEASON_RENT,
                                  constants.RentType.SEASON_CYCLE_RENT):
                    selectedRentSeason = rentPackage['seasonType']
            else:
                rentType = constants.RentType.NO_RENT
            equipmentBlockVm.setSelectedRentID(self.__selectedRentID)
            equipmentBlockVm.setSelectedRentType(rentType)
            equipmentBlockVm.setSelectedRentDays(selectedRentDays)
            equipmentBlockVm.setSelectedRentSeason(selectedRentSeason)
            with equipmentBlockVm.vehicleRentBtn.transaction(
            ) as vehicleRentBtnVm:
                if self.__vehicle.hasRentPackages:
                    vehicleRentBtnVm.setIcon(
                        R.images.gui.maps.icons.library.rent_ico_big())
                rentBtnAvailable = self.__isToggleRentAndTradeInState(
                ) and self.__isRentVisible
                rentBtnAvailable |= not self.__isToggleRentAndTradeInState(
                ) and self.__vehicle.hasRentPackages
                vehicleRentBtnVm.setIsVisible(rentBtnAvailable)

    def __updateTradeOffVehicleBtnData(self):
        with self.viewModel.equipmentBlock.vehicleBtn.transaction(
        ) as vehicleBtnVm:
            isTradeIn = not self.__isRentVisible and self.__isTradeIn()
            vehicleBtnVm.setVisible(isTradeIn
                                    and self.__tradeOffVehicle is not None)
            if self.__isTradeIn() and self.__tradeOffVehicle is not None:
                vehicleBtnVm.setFlag(self.__tradeOffVehicle.nationName)
                vehicleBtnVm.setVehType(
                    getTypeSmallIconPath(self.__tradeOffVehicle.type,
                                         self.__tradeOffVehicle.isPremium))
                vehicleBtnVm.setVehLvl(
                    getLevelSmallIconPath(self.__tradeOffVehicle.level))
                vehicleBtnVm.setVehIcon(
                    getSmallIconPath(self.__tradeOffVehicle.name))
                vehicleBtnVm.setVehName(self.__tradeOffVehicle.shortUserName)
        return

    def __updateIsEnoughStatus(self, *_):
        if not self.__vehicle.isRented:
            with self.viewModel.transaction() as vm:
                ammoPriceModel = vm.equipmentBlock.ammo.actionPrices.getItems()
                ammoPrice = self.__getAmmoItemPrice()
                self.__updateActionPriceArray(ammoPriceModel,
                                              self.__getAmmoItemPrice())
                slotPriceModel = vm.equipmentBlock.slot.actionPrices.getItems()
                slotItemPrice = self.__shop.getVehicleSlotsItemPrice(
                    self.__stats.vehicleSlots)
                self.__updateActionPriceArray(slotPriceModel, slotItemPrice)
                equipmentBlock = vm.equipmentBlock
                equipmentBlock.ammo.setIsEnabled(
                    self.__getAmmoIsAvailable(ammoPrice.price))
                equipmentBlock.slot.setIsEnabled(
                    self.__getSlotIsAvailable(slotItemPrice.price))
                idx = 0
                commanderCards = vm.commanderLvlCards.getItems()
                for commanderCardModel in commanderCards:
                    commanderLvlsCost = self.__shop.getTankmanCostItemPrices()
                    commanderPriceModel = commanderCardModel.actionPrice.getItems(
                    )
                    commanderItemPrice = commanderLvlsCost[idx]
                    commanderItemPrice *= len(self.__vehicle.crew)
                    self.__updateActionPriceArray(commanderPriceModel,
                                                  commanderItemPrice)
                    isEnabled = self.__isAvailablePrice(
                        commanderItemPrice.price)
                    commanderCardModel.setSlotIsEnabled(
                        isEnabled and not self.__isWithoutCommander)
                    idx += 1

            self.__updateTotalPrice()

    def __updateTotalPrice(self):
        totalPrice = self.__getTotalItemPrice()
        with self.viewModel.equipmentBlock.transaction() as equipmentBlockVm:
            if self.__isTradeIn():
                equipmentBlockVm.setConfirmGoldPrice(
                    totalPrice.price.get(Currency.GOLD))
                popoverIsAvailable = totalPrice.price.get(
                    Currency.GOLD) <= self.__stats.money.get(Currency.GOLD)
                self.__popoverIsAvailable = popoverIsAvailable
                equipmentBlockVm.setPopoverIsAvailable(
                    popoverIsAvailable and not self.__isRentVisible)
            totalPriceArray = equipmentBlockVm.totalPrice.getItems()
            for model in totalPriceArray:
                currencyType = model.getType()
                currencyValue = int(totalPrice.price.get(currencyType, 0))
                currencyDefValue = int(totalPrice.defPrice.get(
                    currencyType, 0))
                model.setPrice(
                    self.gui.systemLocale.getNumberFormat(currencyValue))
                model.setDefPrice(getIntegralFormat(currencyDefValue))
                if not self.__isPurchaseCurrencyAvailable(currencyType):
                    model.setIsEnough(
                        currencyValue <= self.__stats.money.get(currencyType))
                isAction = totalPrice.getActionPrcAsMoney().get(
                    currencyType
                ) is not None and currencyValue < currencyDefValue
                model.setShowOldValue(isAction)
                model.setIsWithAction(
                    isAction and (self.__tradeOffVehicle is None
                                  or not self.__isValidTradeOffSelected()))
                model.setIsBootcamp(self.__bootcamp.isInBootcamp())
                if isAction:
                    updateActionInViewModel(currencyType, model, totalPrice)

            self.__updateBuyBtnStatus(totalPrice)
        return

    def __updateBuyBtnStatus(self, totalPrice):
        totalPriceMoney = totalPrice.price
        statsMoney = self.__stats.money
        isEnabled = True
        for currency in Currency.ALL:
            if not self.__isPurchaseCurrencyAvailable(currency):
                isEnabled &= totalPriceMoney.get(currency) <= statsMoney.get(
                    currency)

        if self.__isTradeIn() and self.__tradeOffVehicle is not None:
            isEnabled &= self.__isValidTradeOffSelected(
            ) and self.__tradeOffVehicle.isReadyToTradeOff
        self.viewModel.equipmentBlock.setBuyBtnIsEnabled(isEnabled)
        return

    def __updateBuyBtnLabel(self):
        if self.__selectedRentIdx == self.__RENT_NOT_SELECTED_IDX:
            label = R.strings.store.buyVehicleWindow.restore()
        elif self.__isTradeIn(
        ) and self.__tradeOffVehicle is not None and not self.__isRentVisible:
            label = R.strings.store.buyVehicleWindow.exchange()
        elif self.__selectedRentID >= 0:
            label = R.strings.store.buyVehicleWindow.rentBtn()
        else:
            label = R.strings.store.buyVehicleWindow.buyBtn()
        self.viewModel.equipmentBlock.setBuyBtnLabel(label)
        return

    def __getAmmoItemPrice(self):
        ammoPrice = ITEM_PRICE_EMPTY
        for shell in self.__vehicle.gun.defaultAmmo:
            ammoPrice += shell.buyPrices.itemPrice * shell.count

        return ammoPrice

    def __getAmmoIsAvailable(self, ammoPrice):
        return not self.__vehicle.isAmmoFull and self.__isAvailablePrice(
            ammoPrice)

    def __getSlotIsAvailable(self, slotPrice):
        isSlotForRent = self.__selectedRentIdx >= 0 and self.__isRentVisible
        isSlotForTradeIn = self.__isTradeIn(
        ) and self.__tradeOffVehicle is not None and not self.__isRentVisible
        return not isSlotForRent and not isSlotForTradeIn and self.__isAvailablePrice(
            slotPrice)

    def __getTotalItemPrice(self):
        price = defPrice = ZERO_MONEY
        if self.__isTradeIn(
        ) and self.__tradeOffVehicle is not None and not self.__isRentVisible:
            tradeInPrice = self.__tradeIn.getTradeInPrice(self.__vehicle)
            price = tradeInPrice.price
            defPrice = tradeInPrice.defPrice
        elif self.__selectedRentIdx >= 0 and self.__isRentVisible:
            price += self.__vehicle.rentPackages[
                self.__selectedRentIdx]['rentPrice']
        elif self.viewModel.getIsRestore():
            price += self.__vehicle.restorePrice
        else:
            price += self.__vehicle.buyPrices.itemPrice.price
            defPrice += self.__vehicle.buyPrices.itemPrice.defPrice
        if not self.__isWithoutCommander:
            commanderCardsPrices = self.__shop.getTankmanCostItemPrices()
            commanderItemPrice = commanderCardsPrices[self.__selectedCardIdx]
            commanderItemPrice *= len(self.__vehicle.crew)
            price += commanderItemPrice.price
        if self.viewModel.equipmentBlock.slot.getIsSelected():
            vehSlots = self.__stats.vehicleSlots
            price += self.__shop.getVehicleSlotsItemPrice(vehSlots).price
        if self.viewModel.equipmentBlock.ammo.getIsSelected():
            price += self.__getAmmoItemPrice().price
        if defPrice is ZERO_MONEY:
            defPrice = price
        return ItemPrice(price=price, defPrice=defPrice)

    def __getObtainVehicleProcessor(self, crewType):
        equipmentBlock = self.viewModel.equipmentBlock
        isWithAmmo = equipmentBlock.ammo.getIsSelected()
        isWithSlot = equipmentBlock.slot.getIsSelected()
        return VehicleBuyer(self.__vehicle, isWithSlot, isWithAmmo, crewType)

    def __getRestoreVehicleProcessor(self, crewType):
        equipmentBlock = self.viewModel.equipmentBlock
        isWithAmmo = equipmentBlock.ammo.getIsSelected()
        isWithSlot = equipmentBlock.slot.getIsSelected()
        return VehicleRestoreProcessor(self.__vehicle, isWithSlot, isWithAmmo,
                                       crewType)

    def __getBackportTooltipData(self, event):
        tooltipId = event.getArgument('tooltipId')
        if not tooltipId:
            return
        else:
            if tooltipId in (TOOLTIPS_CONSTANTS.TRADE_IN_INFO,
                             TOOLTIPS_CONSTANTS.TRADE_IN_INFO_NOT_AVAILABLE):
                args = (self.__tradeIn.getAllowedVehicleLevels(
                    self.__vehicle.level), )
            elif tooltipId == TOOLTIPS_CONSTANTS.TRADE_IN_STATE_NOT_AVAILABLE:
                args = (self.__tradeOffVehicle, )
            elif tooltipId == TOOLTIPS_CONSTANTS.SELECTED_VEHICLE_TRADEOFF:
                args = (self.__tradeOffVehicle.intCD, )
            elif tooltipId == TOOLTIPS_CONSTANTS.ACTION_PRICE:
                args = (event.getArgument('tooltipType'),
                        event.getArgument('key'),
                        (event.getArgument('newCredits'),
                         event.getArgument('newGold'),
                         event.getArgument('newCrystal')),
                        (event.getArgument('oldCredits'),
                         event.getArgument('oldGold'),
                         event.getArgument('oldCrystal')),
                        event.getArgument('isBuying'))
            else:
                args = None
            return TooltipData(tooltip=tooltipId,
                               isSpecial=True,
                               specialAlias=tooltipId,
                               specialArgs=args)

    def __addVMsInActionPriceList(self,
                                  listArray,
                                  itemPrice,
                                  fontNotEnoughIsEnabled=True,
                                  tooltipData=None):
        actionPriceModels = getItemPricesViewModel(
            self.__stats.money,
            itemPrice,
            isBootcamp=self.__bootcamp.isInBootcamp())[0]
        for model in actionPriceModels:
            if tooltipData is not None:
                model.setKey(tooltipData.key)
                model.setTooltipType(tooltipData.itemType)
            listArray.addViewModel(model)
            if self.__isPurchaseCurrencyAvailable(model.getType()):
                model.setFontNotEnoughIsEnabled(fontNotEnoughIsEnabled)

        return

    def __isAvailablePrice(self, money):
        isPurchaseCurrencyAvailable = money.isDefined()
        statsMoney = self.__stats.money
        for currency in Currency.ALL:
            currencyValue = money.get(currency)
            if currencyValue and currencyValue > statsMoney.get(currency):
                isPurchaseCurrencyAvailable &= self.__isPurchaseCurrencyAvailable(
                    currency)

        return self.__stats.money >= money or isPurchaseCurrencyAvailable

    def __isPurchaseCurrencyAvailable(self, currencyType):
        return currencyType == Currency.GOLD and self.__isGoldAutoPurchaseEnabled

    def __isTradeIn(self):
        isBuyingAllowed = not self.__vehicle.isDisabledForBuy and not self.__vehicle.isHidden
        return bool(self.__tradeIn.isEnabled() and self.__vehicle.canTradeIn
                    and isBuyingAllowed)

    def __isToggleRentAndTradeInState(self):
        return False if not self.__vehicle else self.__isTradeIn(
        ) and self.__vehicle.hasRentPackages

    def __isValidTradeOffSelected(self):
        tradeOffVehicles = self.__tradeIn.getTradeOffVehicles(
            self.__vehicle.level)
        return tradeOffVehicles is not None and self.__tradeOffVehicle.intCD in tradeOffVehicles

    def __isRenting(self):
        return not self.__isBuying()

    def __isBuying(self):
        return self.__selectedRentIdx in (
            self.__RENT_UNLIM_IDX,
            self.__RENT_NOT_SELECTED_IDX) or not self.__isRentVisible

    def __startTutorial(self):
        if not self.__vehicle.isCollectible:
            return
        collectibleVehicles = set(getCollectibleVehiclesInInventory().keys())
        if len(collectibleVehicles
               ) == 1 and self.__vehicle.intCD in collectibleVehicles:
            event_dispatcher.runSalesChain(_COLLECTIBLE_VEHICLE_TUTORIAL)
class HangarVehicleInfo(BattleRoyaleVehicleInfoMeta, IGlobalListener):
    __itemsCache = dependency.descriptor(IItemsCache)
    __battleRoyaleController = dependency.descriptor(IBattleRoyaleController)
    _COMMON_SOUND_SPACE = BATTLE_ROYALE_VEHICLE_INFO_SOUND_SPACE

    def __init__(self, ctx=None):
        super(HangarVehicleInfo, self).__init__(ctx)
        self.__guiVehConfigurator = None
        self.__vehicle = self.__itemsCache.items.getItemByCD(
            g_currentVehicle.item.intCD)
        self.__introPage = None
        self.__blur = CachedBlur(enabled=True)
        return

    def getSelectedVehicle(self):
        return self.__vehicle

    def onClose(self):
        self.fireEvent(events.LoadViewEvent(
            SFViewLoadParams(VIEW_ALIAS.LOBBY_HANGAR)),
                       scope=EVENT_BUS_SCOPE.LOBBY)

    def onPrbEntitySwitching(self):
        if self.prbEntity is None:
            return
        else:
            switchedFromBR = bool(self.prbEntity.getModeFlags()
                                  & FUNCTIONAL_FLAG.BATTLE_ROYALE)
            if switchedFromBR and not self.isDisposed():
                self.onClose()
                self.destroy()
            return

    def onPrbEntitySwitched(self):
        if not self.__battleRoyaleController.isBattleRoyaleMode():
            self.onClose()

    def _populate(self):
        super(HangarVehicleInfo, self)._populate()
        self.__battleRoyaleController.onUpdated += self.__onBattleRoyaleEnabledChanged
        self.startGlobalListening()
        self.as_setDataS({
            'btnCloseLabel':
            backport.text(
                R.strings.battle_royale.hangarVehicleInfo.closeBtn()),
            'infoIconSource':
            backport.image(R.images.gui.maps.icons.library.info()),
            'infoText':
            text_styles.highlightText(
                backport.text(
                    R.strings.battle_royale.hangarVehicleInfo.moduleTreeTip(),
                    key=text_styles.neutral(
                        br_helpers.getHotKeyString(
                            CommandMapping.CMD_UPGRADE_PANEL_SHOW)))),
            'vehTitle':
            text_styles.grandTitle(self.__vehicle.shortUserName),
            'vehTypeIcon':
            getTypeBigIconPath(self.__vehicle.type),
            'tutorialText':
            backport.text(
                R.strings.battle_royale.hangarVehicleInfo.tutorialText())
        })

    def _onRegisterFlashComponent(self, viewPy, alias):
        if isinstance(viewPy, HangarVehicleModulesConfigurator):
            viewPy.setVehicle(self.__vehicle)
            self.__guiVehConfigurator = viewPy
        super(HangarVehicleInfo, self)._onRegisterFlashComponent(viewPy, alias)

    def _dispose(self):
        if self.__introPage is not None:
            self.__introPage.destroy()
        self.__battleRoyaleController.onUpdated -= self.__onBattleRoyaleEnabledChanged
        self.stopGlobalListening()
        self.__blur.fini()
        self.__blur = None
        self.__vehicle = None
        self.__guiVehConfigurator = None
        super(HangarVehicleInfo, self)._dispose()
        return

    def __onBattleRoyaleEnabledChanged(self):
        isEnabled = self.__battleRoyaleController.isEnabled()
        if not isEnabled:
            self.onClose()
class BootcampExitView(ViewImpl):
    __slots__ = ('__blur', '__tooltipData', '__callback', '__isInBattle')
    __appLoader = dependency.descriptor(IAppLoader)
    __bootcampController = dependency.descriptor(IBootcampController)
    uiBootcampLogger = BootcampLogger(BCLogKeys.BC_EXIT_VIEW.value)

    def __init__(self, callback, isInBattle, *args, **kwargs):
        settings = ViewSettings(R.views.lobby.bootcamp.BootcampExitView())
        settings.model = BootcampExitModel()
        settings.args = args
        settings.kwargs = kwargs
        self.__blur = None
        self.__tooltipData = {}
        self.__callback = callback
        self.__isInBattle = isInBattle
        super(BootcampExitView, self).__init__(settings)
        return

    @property
    def viewModel(self):
        return super(BootcampExitView, self).getViewModel()

    def createToolTip(self, event):
        if event.contentID == R.views.common.tooltip_window.backport_tooltip_content.BackportTooltipContent(
        ):
            tooltipId = event.getArgument('tooltipId')
            if tooltipId:
                tooltipData = self.__tooltipData[int(tooltipId)]
                window = BackportTooltipWindow(tooltipData,
                                               self.getParentWindow())
                if window is None:
                    return
                window.load()
                return window
        return

    def _initialize(self):
        super(BootcampExitView, self)._initialize()
        window = self.getParentWindow()
        if self.__isInBattle:
            app = self.__appLoader.getApp()
            app.enterGuiControlMode(self.uniqueID, True, False)
        else:
            self.__blur = CachedBlur(enabled=True, ownLayer=window.layer - 1)

    @uiBootcampLogger.dLog(BCLogActions.SHOW.value)
    def _onLoading(self, *args, **kwargs):
        super(BootcampExitView, self)._onLoading(*args, **kwargs)
        with self.viewModel.transaction() as model:
            model.onLeaveBootcamp += self.__onLeave
            model.setIsInBattle(self.__isInBattle)
            model.setIsNeedAwarding(self.__bootcampController.needAwarding())
            model.setIsReferral(self.__bootcampController.isReferralEnabled())
            g_bootcamp.fillProgressBar(model, self.__tooltipData)

    @uiBootcampLogger.dLog(BCLogActions.CLOSE.value)
    def _finalize(self):
        self.viewModel.onLeaveBootcamp -= self.__onLeave
        if self.__isInBattle:
            app = self.__appLoader.getApp()
            app.leaveGuiControlMode(self.uniqueID)
        g_eventBus.handleEvent(events.LoadViewEvent(
            SFViewLoadParams(VIEW_ALIAS.LOBBY_MENU)),
                               scope=EVENT_BUS_SCOPE.LOBBY)
        if self.__blur:
            self.__blur.fini()
        super(BootcampExitView, self)._finalize()

    @uiBootcampLogger.dLog(BCLogActions.LEAVE.value)
    def __onLeave(self):
        self.__callback()
        self.destroyWindow()
class CustomizationStyleInfo(CustomizationStyleInfoMeta, CallbackDelayer):
    service = dependency.descriptor(ICustomizationService)
    itemsCache = dependency.descriptor(IItemsCache)

    @property
    def visible(self):
        return self.__visible

    def __init__(self):
        CustomizationStyleInfoMeta.__init__(self)
        CallbackDelayer.__init__(self)
        self.__ctx = None
        self.__blur = None
        self.__blurRectId = None
        self.__visible = False
        self.__prevStyle = None
        self.__selectedStyle = None
        self.__paramsDOF = None
        self.__blurParams = None
        return

    def _populate(self):
        self.__ctx = self.service.getCtx()
        self.__blur = CachedBlur()
        g_clientUpdateManager.addMoneyCallback(self.updateButton)
        g_currentVehicle.onChangeStarted += self.__onVehicleChangeStarted
        self.__ctx.events.onUpdateStyleInfoDOF += self.__onUpdateStyleInfoDOF
        self.service.onCustomizationHelperRecreated += self.__onCustomizationHelperRecreated
        self.__setBackgroundAlpha()

    def _dispose(self):
        g_clientUpdateManager.removeObjectCallbacks(self)
        g_currentVehicle.onChangeStarted -= self.__onVehicleChangeStarted
        self.__ctx.events.onUpdateStyleInfoDOF -= self.__onUpdateStyleInfoDOF
        self.service.onCustomizationHelperRecreated -= self.__onCustomizationHelperRecreated
        self.__ctx = None
        if self.__blur is not None:
            self.__blur.fini()
        return

    def show(self, style=None):
        self.__prevStyle = self.__ctx.mode.modifiedStyle
        self.__selectedStyle = style or self.__ctx.mode.modifiedStyle
        if self.__selectedStyle is None:
            return
        else:
            if self.__prevStyle is None or self.__selectedStyle != self.__prevStyle:
                self.__installStyle(self.__selectedStyle)
            styleInfoVO = self.__makeVO(self.__selectedStyle)
            self.as_setDataS(styleInfoVO)
            self.updateButton()
            self.as_showS()
            self.__visible = True
            self.delayCallback(STYLE_INFO_BLUR_DELAY, self.__enableBlur)
            self.__ctx.mode.unselectSlot()
            return

    def updateButton(self, *_):
        if self.__selectedStyle:
            buttonVO = self.__makeButtonVO(self.__selectedStyle)
            self.as_buttonUpdateS(buttonVO)

    def onClose(self):
        self.__ctx.events.onHideStyleInfo()
        self.disableBlur()
        self.__visible = False
        self.__selectedStyle = None
        if self.__prevStyle is None:
            slotId = C11nId(areaId=Area.MISC,
                            slotType=GUI_ITEM_TYPE.STYLE,
                            regionIdx=0)
            self.__ctx.mode.removeItem(slotId)
        elif self.__prevStyle != self.__ctx.mode.modifiedStyle:
            self.__installStyle(self.__prevStyle)
        self.__prevStyle = None
        return

    def onApply(self):
        self.__ctx.events.onHideStyleInfo(toBuyWindow=True)
        if self.__blurRectId:
            self.__blur.removeRect(self.__blurRectId)
            self.__blurRectId = None
        self.service.setDOFenabled(False)
        self.__visible = False
        return

    def hide(self):
        self.stopCallback(self.__enableBlur)
        self.stopCallback(self.service.setDOFenabled)
        self.disableBlur()
        self.as_hideS()
        self.__paramsDOF = None
        return

    def disableBlur(self):
        if self.__blurRectId:
            self.__blur.removeRect(self.__blurRectId)
            self.__blurRectId = None
        self.__blur.disable()
        self.__paramsDOF = None
        self.service.setDOFenabled(False)
        return

    def __makeVO(self, style):
        styleParams = self.__makeParamsVO(style)
        styleName = style.userName
        styleInfoText = style.longDescriptionSpecial
        styleInfo = text_styles.mainBig(
            styleInfoText % {
                'insertion_open': _INSERTION_OPEN_TAG,
                'insertion_close': _INSERTION_CLOSE_TAG
            })
        styleInfoBig = text_styles.mainBig(
            styleInfoText % {
                'insertion_open': _INSERTION_OPEN_TAG_BIG,
                'insertion_close': _INSERTION_CLOSE_TAG
            })
        suitableText = getSuitableText(style, g_currentVehicle.item)
        if suitableText:
            suitableBlock = text_styles.mainBig(
                backport.text(
                    R.strings.vehicle_customization.styleInfo.suitable()))
            suitableBlock += suitableText
        else:
            suitableBlock = text_styles.mainBig(
                backport.text(
                    R.strings.vehicle_customization.styleInfo.suitableAll()))
        return StyleInfoVO(styleName=styleName,
                           styleInfo=styleInfo,
                           styleInfoBig=styleInfoBig,
                           suitableBlock=suitableBlock,
                           styleParams=styleParams)._asdict()

    def __makeButtonVO(self, style):
        buttonVO = None
        if self.__ctx.isOutfitsModified():
            stylePrice = style.getBuyPrice().price
            moneyState = getPurchaseMoneyState(stylePrice)
            purchaseItem = first(self.__ctx.mode.getPurchaseItems())
            if purchaseItem is not None and purchaseItem.isFromInventory:
                label = backport.text(
                    R.strings.vehicle_customization.commit.apply())
                enabled = True
            else:
                label = backport.text(
                    R.strings.vehicle_customization.commit.buy())
                enabled = isTransactionValid(moneyState, stylePrice)
            buttonVO = ButtonVO(enabled=enabled,
                                label=label,
                                disabledTooltip=backport.text(
                                    R.strings.vehicle_customization.
                                    customization.buyDisabled.body()),
                                visible=True)._asdict()
        return buttonVO

    def __makeParamsVO(self, style):
        params = []
        vehicleCD = g_currentVehicle.item.descriptor.makeCompactDescr()
        for season in SeasonType.COMMON_SEASONS:
            outfit = style.getOutfit(season, vehicleCD=vehicleCD)
            if outfit:
                container = outfit.hull
                intCD = container.slotFor(GUI_ITEM_TYPE.CAMOUFLAGE).getItemCD()
                if not intCD:
                    continue
                camo = self.service.getItemByCD(intCD)
                if camo and camo.bonus:
                    bonus = camo.bonus.getFormattedValue(g_currentVehicle.item)
                    bonusIcon = backport.image(
                        R.images.gui.maps.icons.customization.style_info.bonus(
                        ))
                    formattedBonus = makeHtmlString(
                        'html_templates:lobby/customization',
                        'style_info_bonus',
                        ctx={'bonus': bonus})
                    bonusParam = ParamVO(bonusIcon, formattedBonus)
                    params.append(bonusParam._asdict())
                    break

        displayType = style.customizationDisplayType()
        if displayType == 0:
            historicIcon = backport.image(
                R.images.gui.maps.icons.customization.style_info.historical())
            historicString = backport.text(
                R.strings.vehicle_customization.styleInfo.historical())
        elif displayType == 1:
            historicIcon = backport.image(
                R.images.gui.maps.icons.customization.style_info.nonhistorical(
                ))
            historicString = backport.text(
                R.strings.vehicle_customization.styleInfo.nonhistorical())
        else:
            historicIcon = backport.image(
                R.images.gui.maps.icons.customization.style_info.fantastical())
            historicString = backport.text(
                R.strings.vehicle_customization.styleInfo.fantastical())
        historicParam = ParamVO(historicIcon, text_styles.main(historicString))
        params.append(historicParam._asdict())
        if style.isRentable:
            rentIcon = backport.image(
                R.images.gui.maps.icons.customization.style_info.rentable())
            rentString = backport.text(
                R.strings.vehicle_customization.styleInfo.rentable())
            rentParam = ParamVO(rentIcon, text_styles.main(rentString))
            params.append(rentParam._asdict())
        elif style.specialEventTag is not None:
            eventIcon = style.specialEventIcon
            eventName = style.specialEventName
            eventParam = ParamVO(eventIcon, text_styles.main(eventName))
            params.append(eventParam._asdict())
        return params

    def __enableBlur(self):
        self.__blur.enable()

    def __installStyle(self, style):
        slotId = C11nId(areaId=Area.MISC,
                        slotType=GUI_ITEM_TYPE.STYLE,
                        regionIdx=0)
        self.__ctx.mode.installItem(style.intCD, slotId)

    def __onUpdateStyleInfoDOF(self, paramsDOF):
        self.__paramsDOF = paramsDOF
        if self.__paramsDOF is not None and self.visible:
            self.service.setDOFparams(self.__paramsDOF)
            self.delayCallback(STYLE_INFO_BLUR_DELAY,
                               self.service.setDOFenabled,
                               enable=True)
        return

    def __onCustomizationHelperRecreated(self):
        if self.visible and self.__paramsDOF is not None:
            self.service.setDOFparams(self.__paramsDOF)
            self.service.setDOFenabled(True)
            self.service.suspendHighlighter()
        else:
            self.service.setDOFenabled(False)
        return

    def __onVehicleChangeStarted(self):
        self.__paramsDOF = None
        if self.visible:
            self.service.setDOFenabled(False)
        return

    def onWidthUpdated(self, x, width, height):
        if not self.visible:
            return
        blurRect = (round(x), 0, round(x + width), round(height))
        if self.__blurRectId:
            self.__blur.changeRect(self.__blurRectId, blurRect)
        else:
            self.__blurRectId = self.__blur.addRect(blurRect)

    def __setBackgroundAlpha(self):
        alpha = BACKGROUND_ALPHA_DEFERRED if isRendererPipelineDeferred(
        ) else BACKGROUND_ALPHA_FORWARD
        self.as_setBackgroundAlphaS(alpha)
Ejemplo n.º 17
0
class EventProgressionBuyConfirmView(EventProgressionBuyConfirmViewMeta):
    def __init__(self, ctx=None):
        super(EventProgressionBuyConfirmView, self).__init__(ctx)
        self.__vehicle = ctx.get('vehicle')
        self.__price = ctx.get('price')
        self.__blur = CachedBlur(enabled=True,
                                 ownLayer=APP_CONTAINERS_NAMES.DIALOGS,
                                 layers=(APP_CONTAINERS_NAMES.VIEWS,
                                         APP_CONTAINERS_NAMES.WINDOWS,
                                         APP_CONTAINERS_NAMES.SUBVIEW,
                                         APP_CONTAINERS_NAMES.BROWSER))

    def _populate(self):
        super(EventProgressionBuyConfirmView, self)._populate()
        self.setData()
        switchHangarOverlaySoundFilter(on=True)

    def destroy(self):
        self.__blur.fini()
        super(EventProgressionBuyConfirmView, self).destroy()

    def onClose(self):
        self.destroy()
        switchHangarOverlaySoundFilter(on=False)

    def onBack(self):
        self.onClose()

    @process
    def onBuy(self):
        result = yield EventProgressionBuyRewardVehicle(
            self.__vehicle).request()
        if result and result.success:
            ctx = {
                'congratulationsViewSettings': {
                    'backBtnLabel':
                    R.strings.store.congratulationAnim.showEpicBtnLabel(),
                    'backBtnEnabled':
                    True
                }
            }
            shared_event.showVehicleBuyDialog(
                vehicle=self.__vehicle,
                previousAlias=VIEW_ALIAS.EVENT_PROGRESSION_VEHICLE_PREVIEW,
                showOnlyCongrats=True,
                ctx=ctx)
        if result and result.userMsg:
            SystemMessages.pushI18nMessage(result.userMsg,
                                           type=result.sysMsgType)
        self.onClose()

    def setData(self):
        rTokensImage = R.images.gui.maps.icons.epicBattles.rewardPoints
        self.as_setDataS({
            'title':
            self.__formatTitle(text_styles.promoTitle,
                               rTokensImage.c_24x24(),
                               iconSize=24,
                               vSpace=-3),
            'titleBig':
            self.__formatTitle(text_styles.grandTitle,
                               rTokensImage.c_32x32(),
                               iconSize=32,
                               vSpace=-4),
            'content':
            '',
            'contentBig':
            '',
            'buyBtnLabel':
            backport.text(R.strings.event_progression.buyConfirm.buyLabel()),
            'backBtnLabel':
            backport.text(R.strings.event_progression.buyConfirm.backLabel()),
            'showIcon':
            False
        })

    def __formatTitle(self, style, iconResID, iconSize, vSpace):
        return style(
            backport.text(R.strings.event_progression.buyConfirm.title(),
                          price='{}{}'.format(
                              self.__price,
                              icons.makeImageTag(backport.image(iconResID),
                                                 width=iconSize,
                                                 height=iconSize,
                                                 vSpace=vSpace))))
Ejemplo n.º 18
0
class HangarVehicleInfo(BattleRoyaleVehicleInfoMeta, IGlobalListener):
    __itemsCache = dependency.descriptor(IItemsCache)
    __battleRoyaleController = dependency.descriptor(IBattleRoyaleController)
    _COMMON_SOUND_SPACE = BATTLE_ROYALE_VEHICLE_INFO_SOUND_SPACE

    def __init__(self, ctx=None):
        super(HangarVehicleInfo, self).__init__(ctx)
        self.__guiVehConfigurator = None
        self.__vehicle = self.__itemsCache.items.getItemByCD(
            g_currentVehicle.item.intCD)
        self.__isFirstEnter = ctx.get('isFirstEnter', False)
        self.__introPage = None
        self.__blur = CachedBlur(enabled=True)
        return

    def getSelectedVehicle(self):
        return self.__vehicle

    def onClose(self):
        self.fireEvent(events.LoadViewEvent(VIEW_ALIAS.LOBBY_HANGAR),
                       scope=EVENT_BUS_SCOPE.LOBBY)

    def onShowIntro(self):
        self.__showIntroPage()

    def onPrbEntitySwitched(self):
        if not self.__battleRoyaleController.isBattleRoyaleMode():
            self.onClose()

    def _populate(self):
        super(HangarVehicleInfo, self)._populate()
        if self.__isFirstEnter:
            self.__showIntroPage()
            self.__isFirstEnter = False
        self.__battleRoyaleController.onUpdated += self.__onBattleRoyaleEnabledChanged
        self.startGlobalListening()
        self.as_setTabsDataS(_getTabData())
        self.as_setDataS({
            'btnInfoLabel':
            backport.text(R.strings.battle_royale.hangarVehicleInfo.infoBtn()),
            'btnCloseLabel':
            backport.text(
                R.strings.battle_royale.hangarVehicleInfo.closeBtn()),
            'infoIconSource':
            backport.image(R.images.gui.maps.icons.library.info()),
            'engineLabel':
            backport.text(
                R.strings.battle_royale.hangarVehicleInfo.weakZones.engine()),
            'ammunitionLabel':
            backport.text(R.strings.battle_royale.hangarVehicleInfo.weakZones.
                          ammunition()),
            'vehTitle':
            text_styles.promoSubTitle(self.__vehicle.shortUserName),
            'nationIcon':
            getVehicleNationIcon(self.__vehicle),
            'weakZones':
            _getVehicleWeakZonesImage(self.__vehicle)
        })

    def _onRegisterFlashComponent(self, viewPy, alias):
        if isinstance(viewPy, HangarVehicleModulesConfigurator):
            viewPy.setVehicle(self.__vehicle)
            self.__guiVehConfigurator = viewPy
        super(HangarVehicleInfo, self)._onRegisterFlashComponent(viewPy, alias)

    def _dispose(self):
        if self.__introPage is not None:
            self.__introPage.destroy()
        self.__battleRoyaleController.onUpdated -= self.__onBattleRoyaleEnabledChanged
        self.stopGlobalListening()
        self.__blur.fini()
        self.__blur = None
        self.__vehicle = None
        self.__guiVehConfigurator = None
        super(HangarVehicleInfo, self)._dispose()
        return

    def __showIntroPage(self):
        self.__introPage = _HangarVehicleInfoIntroWindow(
            ctx={
                'vehicle': self.__vehicle,
                'firstView': self.__isFirstEnter
            })
        self.__introPage.load()

    def __onBattleRoyaleEnabledChanged(self):
        isEnabled = self.__battleRoyaleController.isEnabled()
        if not isEnabled:
            self.onClose()
class ColorSettingsView(LayerVisibilityMixin, ColorSettingsViewMeta):
    settingsCore = dependency.descriptor(ISettingsCore)

    def __init__(self, ctx=None):
        super(ColorSettingsView, self).__init__(ColorSettingsView)
        self.fireEvent(GameEvent(GameEvent.HIDE_EXTERNAL_COMPONENTS),
                       scope=EVENT_BUS_SCOPE.GLOBAL)
        self.__selectedTabIdx = AccountSettings.getSettings(
            COLOR_SETTINGS_TAB_IDX)
        self.__componentWidth = 0
        self.__isColorPreviewFilterActive = False
        self.__initSettings = self.__getSettings()
        self.__tabsPreviewSettings = self.__getLastAppliedTabsSettings()
        self.__wasGraphicsOptimizationEnabled = False
        if self.__selectedTabIdx == TABS.CUSTOM:
            self.__showColorPreviewFilter()
        self.__blur = None
        return

    def setViewWidth(self, width):
        self.__componentWidth = width
        if self.__isColorPreviewFilterActive:
            self.__showColorPreviewFilter()

    def moveSpace(self, dx, dy, dz):
        self.fireEvent(
            CameraRelatedEvents(CameraRelatedEvents.LOBBY_VIEW_MOUSE_MOVE,
                                ctx={
                                    'dx': dx,
                                    'dy': dy,
                                    'dz': dz
                                }))
        self.fireEvent(
            events.LobbySimpleEvent(events.LobbySimpleEvent.NOTIFY_SPACE_MOVED,
                                    ctx={
                                        'dx': dx,
                                        'dy': dy,
                                        'dz': dz
                                    }))

    def onSettingsChange(self, settingName, settingValue):
        settingValue = flashObject2Dict(settingValue)
        LOG_DEBUG('onSettingsChange', settingName, settingValue)
        self.settingsCore.previewSetting(settingName, settingValue)
        self.__tabsPreviewSettings[
            self.__selectedTabIdx][settingName] = settingValue

    def onApply(self, diff):
        diff = flashObject2Dict(diff)
        AccountSettings.setSettings(COLOR_SETTINGS_TAB_IDX,
                                    self.__selectedTabIdx)
        if self.__selectedTabIdx == TABS.CUSTOM:
            if self.__hasChangesInSettings(
                    settings_constants.GRAPHICS.getCustomColorSettings(),
                    diff):
                diff.update({
                    settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE:
                    COLOR_GRADING_TECHNIQUE_DEFAULT
                })
            diff[COLOR_SETTINGS.COLOR_GRADING_TECHNIQUE] = 0
            diff[COLOR_SETTINGS.COLOR_FILTER_INTENSITY] = 25
        self.settingsCore.applySettings(diff)
        lastAppliedSettings = AccountSettings.getSettings(
            APPLIED_COLOR_SETTINGS)
        lastAppliedSettings[self.__selectedTabIdx] = diff
        AccountSettings.setSettings(APPLIED_COLOR_SETTINGS,
                                    lastAppliedSettings)
        BigWorld.commitPendingGraphicsSettings()
        self.destroy()

    def onTabSelected(self, selectedTab):
        savedTab = AccountSettings.getSettings(COLOR_SETTINGS_TAB_IDX)
        if savedTab == self.__selectedTabIdx and self.__selectedTabIdx == TABS.FILTERS and selectedTab == TABS.CUSTOM:
            prevSettings = self.__getLastAppliedTabsSettings()[TABS.FILTERS]
            self.__selectedTabIdx = selectedTab
            settings = self.__getCurrentTabSettings()
            prevFilter = prevSettings[
                settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE]
            settings[settings_constants.GRAPHICS.
                     COLOR_GRADING_TECHNIQUE] = prevFilter
            settings[COLOR_SETTINGS.COLOR_FILTER_INTENSITY] = prevSettings[
                COLOR_SETTINGS.COLOR_FILTER_INTENSITY]
        else:
            self.__selectedTabIdx = selectedTab
            settings = self.__getCurrentTabSettings()
        self.__previewSettings(settings)
        self.as_updateDataS(self.__selectedTabIdx, settings)
        if self.__selectedTabIdx == TABS.CUSTOM:
            self.__showColorPreviewFilter()
        else:
            self.__hideColorPreviewFilter()

    def onReset(self):
        settings = self.__getCurrentTabSettings()
        for settingName in settings_constants.GRAPHICS.getCustomColorSettings(
        ):
            setting = self.settingsCore.options.getSetting(settingName)
            defaultValue = setting.getDefaultValue()
            self.settingsCore.previewSetting(settingName, defaultValue)
            self.__tabsPreviewSettings[
                self.__selectedTabIdx][settingName] = defaultValue
            settings[settingName] = defaultValue

        self.as_updateDataS(self.__selectedTabIdx, settings)

    def onClose(self):
        self.settingsCore.options.revert(
            settings_constants.GRAPHICS.getColorSettings())
        self.destroy()

    def _populate(self):
        super(ColorSettingsView, self)._populate()
        if self.app is not None:
            self._savedBackgroundAlpha = self.app.getBackgroundAlpha()
            self.app.setBackgroundAlpha(0)
            self.addListener(GameEvent.ON_BACKGROUND_ALPHA_CHANGE,
                             self.__onExternalBackgroundAlphaChange,
                             EVENT_BUS_SCOPE.GLOBAL)
            self.__wasGraphicsOptimizationEnabled = self.app.graphicsOptimizationManager.getEnable(
            )
            self.app.graphicsOptimizationManager.switchOptimizationEnabled(
                False)
        self.as_initDataS({
            'header':
            text_styles.superPromoTitle(SETTINGS.COLORSETTINGS_VIEW_HEADER),
            'typesHeader':
            text_styles.highTitle(SETTINGS.COLORSETTINGS_VIEW_SUBTITLE),
            'typesDesc':
            text_styles.main(SETTINGS.COLORSETTINGS_VIEW_DESCRIPTION),
            'applyLabel':
            i18n.makeString(SETTINGS.APPLY_BUTTON),
            'cancelLabel':
            i18n.makeString(SETTINGS.CANCEL_BUTTON),
            'settingsTypes':
            self.__getTypes(),
            'closeLabel':
            i18n.makeString(SETTINGS.COLORSETTINGS_VIEW_CLOSEBTN),
            'beforeStr':
            text_styles.promoSubTitle(SETTINGS.COLORSETTINGS_VIEW_BEFORE),
            'afterStr':
            text_styles.promoSubTitle(SETTINGS.COLORSETTINGS_VIEW_AFTER),
            'filtersHeader':
            text_styles.highTitle(SETTINGS.COLORSETTINGS_TAB_FILTERS),
            'filterPowerLabel':
            i18n.makeString(SETTINGS.COLORSETTINGS_TAB_FILTERS_INTENSITY),
            'filtersTypes':
            self.__getFiltersTypes(),
            'manualHeader':
            text_styles.highTitle(SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS),
            'brightnessLabel':
            i18n.makeString(
                SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS_BRIGHTNESS),
            'contrastLabel':
            i18n.makeString(
                SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS_CONTRAST),
            'saturationLabel':
            i18n.makeString(
                SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS_SATURATION),
            'resetLabel':
            i18n.makeString(SETTINGS.COLORSETTINGS_VIEW_RESETBTN)
        })
        self.as_updateDataS(self.__selectedTabIdx, self.__initSettings)
        self.__blur = CachedBlur(enabled=False)
        return

    def _dispose(self):
        self.__hideColorPreviewFilter()
        self.settingsCore.clearStorages()
        self.removeListener(GameEvent.ON_BACKGROUND_ALPHA_CHANGE,
                            self.__onExternalBackgroundAlphaChange,
                            EVENT_BUS_SCOPE.GLOBAL)
        if self.app is not None:
            self.app.setBackgroundAlpha(self._savedBackgroundAlpha)
            if hasattr(self.app, 'leaveGuiControlMode'):
                self.app.leaveGuiControlMode(VIEW_ALIAS.COLOR_SETTING)
            self.app.graphicsOptimizationManager.switchOptimizationEnabled(
                self.__wasGraphicsOptimizationEnabled)
        self.fireEvent(GameEvent(GameEvent.SHOW_EXTERNAL_COMPONENTS),
                       scope=EVENT_BUS_SCOPE.GLOBAL)
        if self.__initSettings is not None:
            self.__initSettings.clear()
            self.__initSettings = None
        if self.__blur is not None:
            self.__blur.fini()
        super(ColorSettingsView, self)._dispose()
        return

    def __getLastAppliedTabsSettings(self):
        lastAppliedSettings = AccountSettings.getSettings(
            APPLIED_COLOR_SETTINGS)
        filterTabsKeys = (GRAPHICS.COLOR_GRADING_TECHNIQUE,
                          GRAPHICS.COLOR_FILTER_INTENSITY)
        return {
            TABS.DEFAULT: {},
            TABS.FILTERS:
            self.__getTabSettings(lastAppliedSettings, TABS.FILTERS,
                                  filterTabsKeys),
            TABS.CUSTOM:
            self.__getTabSettings(lastAppliedSettings, TABS.CUSTOM,
                                  GRAPHICS.getCustomColorSettings())
        }

    def __getTabSettings(self, lastAppliedSettings, tabIdx, settingKeys):
        tabSettings = lastAppliedSettings.get(tabIdx, {})
        settings = {}
        for key in settingKeys:
            settings[key] = tabSettings.get(key, self.__initSettings[key])

        return settings

    def __getTypes(self):
        return [{
            'id':
            TABS.DEFAULT,
            'label':
            text_styles.highlightText(SETTINGS.COLORSETTINGS_TAB_DEFAULT),
            'icon':
            RES_ICONS.MAPS_ICONS_SETTINGS_COLORSETTINGS_DEFAULT
        }, {
            'id':
            TABS.FILTERS,
            'label':
            text_styles.highlightText(SETTINGS.COLORSETTINGS_TAB_FILTERS),
            'icon':
            RES_ICONS.MAPS_ICONS_SETTINGS_COLORSETTINGS_FILTERS
        }, {
            'id':
            TABS.CUSTOM,
            'label':
            text_styles.highlightText(
                SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS),
            'icon':
            RES_ICONS.MAPS_ICONS_SETTINGS_COLORSETTINGS_MANUAL
        }]

    def __getFiltersTypes(self):
        result = []
        setting = self.settingsCore.options.getSetting(
            GRAPHICS.COLOR_GRADING_TECHNIQUE)
        images = graphics.getGraphicSettingColorSettingsFiletersImages()
        if setting is not None:
            for option in setting.getOptions():
                result.append({
                    'id':
                    option.get('data', COLOR_GRADING_TECHNIQUE_DEFAULT),
                    'label':
                    text_styles.stats(option.get('label')),
                    'icon':
                    images.get(
                        option.get('data', COLOR_GRADING_TECHNIQUE_DEFAULT))
                })

            result = sorted(result, key=lambda k: k['id'])
        return result

    def __getSettings(self):
        settings = {}
        for setting in settings_constants.GRAPHICS.getColorSettings():
            settings[setting] = self.settingsCore.getSetting(setting)

        return settings

    def __showColorPreviewFilter(self):
        width, _ = GUI.screenResolution()[:2]
        witdthPrc = self.__componentWidth / width
        delimiterPrc = witdthPrc + (1 - witdthPrc) / 2
        BigWorld.setColorBCSSetup(1, delimiterPrc)
        self.__isColorPreviewFilterActive = True

    def __hideColorPreviewFilter(self):
        BigWorld.setColorBCSSetup(0, 0)
        self.__isColorPreviewFilterActive = False

    def __hasChangesInSettings(self, settingsNames, diff):
        for name in settingsNames:
            if self.__initSettings[name] != diff[name]:
                return True

        return False

    def __getCurrentTabSettings(self):
        settings = {}
        for settingName in settings_constants.GRAPHICS.getColorSettings():
            setting = self.settingsCore.options.getSetting(settingName)
            if settingName != settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE:
                defaultValue = setting.getDefaultValue()
            else:
                defaultValue = COLOR_GRADING_TECHNIQUE_DEFAULT
            settings[settingName] = defaultValue

        settings.update(self.__tabsPreviewSettings[self.__selectedTabIdx])
        return settings

    def __previewSettings(self, settings):
        for settingName, value in settings.iteritems():
            self.settingsCore.applySetting(settingName, value)

    def __onExternalBackgroundAlphaChange(self, event):
        self._savedBackgroundAlpha = event.ctx['alpha']
        self.app.setBackgroundAlpha(0, notSilentChange=False)
class BCMessageWindow(BCMessageWindowMeta):
    _hangarSpace = dependency.descriptor(IHangarSpace)
    BC_NEW_MODULE_UNLOCK_SOUND_ID = 'bc_new_module_unlock'
    BC_RESOURCE_FLY_SOUND_ID = 'bc_resources_fly'
    BC_RESOURCE_GLOW_SOUND_ID = 'bc_resources_glow'
    BC_INFO_LINE_DISAPPEAR_SOUND_ID = 'bc_info_line_disappear'
    FLY_ANIMATIONS = ['gold', 'prem', 'credits', 'experience']
    RTPC_EXT_BC_ELEMENT_POSITION = 'RTPC_ext_bc_element_position'

    def __init__(self, content):
        super(BCMessageWindow, self).__init__(content)
        self.__blur = None
        return

    def needRTPCCorection(self, animation):
        return self.isFlyAnimation(animation)

    def isFlyAnimation(self, animation):
        return animation in self.FLY_ANIMATIONS

    def setParentWindow(self, window):
        super(BCMessageWindow, self).setParentWindow(window)
        self.__blur = CachedBlur(enabled=True,
                                 ownLayer=window.layer,
                                 blurAnimRepeatCount=1)

    def onMessageButtonClicked(self):
        self.onCustomButton(needStopEffect=True, needCloseWindow=False)

    def onTryClosing(self):
        return False

    @subtitleDecorator
    def onMessageAppear(self, type):
        pass

    def onMessageDisappear(self, type, animation):
        if type != BOOTCAMP_MESSAGE_ALIASES.RENDERER_INTRO and not self.isFlyAnimation(
                animation):
            SoundGroups.g_instance.playSound2D(
                self.BC_INFO_LINE_DISAPPEAR_SOUND_ID)

    def onMessageRemoved(self):
        callback = self._content.get('callback')
        if callback is not None:
            callback(False)
        self.submit()
        return

    def onMessageExecuted(self, renderedType):
        callback = self._content.get('callback')
        if callback is not None:
            callback(True)
        return

    def hideBlur(self):
        self.__blur.disable()

    def onMessageAnimationStopped(self, animation):
        if self.needRTPCCorection(animation):
            self.soundManager.setRTPC(self.RTPC_EXT_BC_ELEMENT_POSITION,
                                      SOUNDS.MIN_MISSIONS_ZOOM)

    def onMessageAnimationStarted(self, animation):
        if self.needRTPCCorection(animation):
            self.soundManager.playSound(self.BC_RESOURCE_FLY_SOUND_ID)
            self.soundManager.playSound(self.BC_RESOURCE_GLOW_SOUND_ID)
            self.soundManager.setRTPC(self.RTPC_EXT_BC_ELEMENT_POSITION,
                                      SOUNDS.MAX_MISSIONS_ZOOM)
        else:
            self.soundManager.playSound(self.BC_NEW_MODULE_UNLOCK_SOUND_ID)

    def _populate(self):
        super(BCMessageWindow, self)._populate()
        self.as_setMessageDataS(self._content['messages'])
        self.as_blurOtherWindowsS(WindowLayer.TOP_WINDOW)
        g_bootcampEvents.onRequestBootcampMessageWindowClose += self.onMessageRemoved
        if self._hangarSpace.spaceInited:
            self.__setCameraDisabled(True)
        else:
            self._hangarSpace.onSpaceCreate += self.__onSpaceCreated

    def _dispose(self):
        super(BCMessageWindow, self)._dispose()
        if self.__blur is not None:
            self.__blur.fini()
        g_bootcampEvents.onRequestBootcampMessageWindowClose -= self.onMessageRemoved
        self._hangarSpace.onSpaceCreate -= self.__onSpaceCreated
        self.__setCameraDisabled(False)
        return

    def _stop(self, needCloseWindow=True):
        self._content.clear()
        for _, effect in self._gui.effects.iterEffects():
            if effect.isStillRunning(self.uniqueName):
                effect.stop()

        if needCloseWindow:
            self.destroy()

    def __onSpaceCreated(self):
        BigWorld.callback(0.1, partial(self.__setCameraDisabled, True))

    def __setCameraDisabled(self, disabled):
        self.fireEvent(
            CameraRelatedEvents(
                CameraRelatedEvents.FORCE_DISABLE_IDLE_PARALAX_MOVEMENT,
                ctx={
                    'isDisable': disabled,
                    'setIdle': True,
                    'setParallax': True
                }), EVENT_BUS_SCOPE.LOBBY)
        self.fireEvent(
            CameraRelatedEvents(
                CameraRelatedEvents.FORCE_DISABLE_CAMERA_MOVEMENT,
                ctx={'disable': disabled}), EVENT_BUS_SCOPE.LOBBY)
Ejemplo n.º 21
0
class ModeSelectorView(ViewImpl):
    __slots__ = ('__blur', '__dataProvider', '__prevAppBackgroundAlpha',
                 '__isEventEnabled', '__isClickProcessing',
                 '__prevOptimizationEnabled', '__isGraphicsRestored')
    uiLogger = BaseModeSelectorLogger(LOG_KEYS.MS_WINDOW)
    uiBootcampLogger = BootcampLogger(LOG_KEYS.MS_WINDOW)
    _COMMON_SOUND_SPACE = MODE_SELECTOR_SOUND_SPACE
    __appLoader = dependency.descriptor(IAppLoader)
    __bootcamp = dependency.descriptor(IBootcampController)
    __lobbyContext = dependency.descriptor(ILobbyContext)
    __gui = dependency.descriptor(IGuiLoader)
    __tooltipByContentID = {
        R.views.lobby.battle_pass.tooltips.BattlePassNotStartedTooltipView():
        BattlePassNotStartedTooltipView,
        R.views.lobby.battle_pass.tooltips.BattlePassCompletedTooltipView():
        BattlePassCompletedTooltipView,
        R.views.lobby.battle_pass.tooltips.BattlePassInProgressTooltipView():
        partial(BattlePassInProgressTooltipView,
                battleType=QUEUE_TYPE.RANDOMS),
        R.views.lobby.battle_pass.tooltips.BattlePass3dStyleNotChosenTooltip():
        BattlePass3dStyleNotChosenTooltip
    }
    layoutID = R.views.lobby.mode_selector.ModeSelectorView()
    _areWidgetsVisible = False

    def __init__(self, layoutId, isEventEnabled=False, provider=None):
        super(ModeSelectorView, self).__init__(
            ViewSettings(layoutId, ViewFlags.LOBBY_TOP_SUB_VIEW,
                         ModeSelectorModel()))
        self.__dataProvider = provider if provider else ModeSelectorDataProvider(
        )
        self.__blur = None
        self.__prevOptimizationEnabled = False
        self.__prevAppBackgroundAlpha = 0.0
        self.__isEventEnabled = isEventEnabled
        self.__isClickProcessing = False
        self.__isGraphicsRestored = False
        self.inputManager.addEscapeListener(self.__handleEscape)
        return

    @property
    def viewModel(self):
        return self.getViewModel()

    @property
    def inputManager(self):
        app = self.__appLoader.getApp()
        return app.gameInputManager

    def createToolTip(self, event):
        if event.contentID == _R_BACKPORT_TOOLTIP():
            tooltipId = event.getArgument('tooltipId')
            if tooltipId in [
                    ModeSelectorTooltipsConstants.DISABLED_TOOLTIP,
                    ModeSelectorTooltipsConstants.CALENDAR_TOOLTIP
            ]:
                index = int(event.getArgument('index'))
                modeSelectorItem = self.__dataProvider.getItemByIndex(index)
                if modeSelectorItem is None:
                    return
                body = modeSelectorItem.disabledTooltipText
                if tooltipId == ModeSelectorTooltipsConstants.CALENDAR_TOOLTIP:
                    body = modeSelectorItem.calendarTooltipText
                return self.__createSimpleTooltip(event, body=body)
            if tooltipId == ModeSelectorTooltipsConstants.RANDOM_BP_PAUSED_TOOLTIP:
                return self.__createSimpleTooltip(
                    event,
                    header=backport.text(R.strings.battle_pass.tooltips.
                                         entryPoint.disabled.header()),
                    body=backport.text(R.strings.battle_pass.tooltips.
                                       entryPoint.disabled.body()))
            if tooltipId in [
                    ModeSelectorTooltipsConstants.
                    RANKED_CALENDAR_DAY_INFO_TOOLTIP,
                    ModeSelectorTooltipsConstants.RANKED_STEP_TOOLTIP,
                    ModeSelectorTooltipsConstants.
                    RANKED_BATTLES_LEAGUE_TOOLTIP,
                    ModeSelectorTooltipsConstants.
                    RANKED_BATTLES_EFFICIENCY_TOOLTIP,
                    ModeSelectorTooltipsConstants.
                    RANKED_BATTLES_POSITION_TOOLTIP,
                    ModeSelectorTooltipsConstants.RANKED_BATTLES_BONUS_TOOLTIP,
                    ModeSelectorTooltipsConstants.MAPBOX_CALENDAR_TOOLTIP,
                    ModeSelectorTooltipsConstants.EPIC_BATTLE_CALENDAR_TOOLTIP
            ]:
                return createAndLoadBackportTooltipWindow(
                    self.getParentWindow(),
                    tooltipId=tooltipId,
                    isSpecial=True,
                    specialArgs=(None, ))
            if tooltipId == ModeSelectorTooltipsConstants.RANKED_BATTLES_RANK_TOOLTIP:
                rankID = int(event.getArgument('rankID'))
                return createAndLoadBackportTooltipWindow(
                    self.getParentWindow(),
                    tooltipId=tooltipId,
                    isSpecial=True,
                    specialArgs=(rankID, ))
        return super(ModeSelectorView, self).createToolTip(event)

    def createToolTipContent(self, event, contentID):
        if contentID == _R_SIMPLE_TOOLTIP():
            return SimpleTooltipContent(contentID,
                                        event.getArgument('header', ''),
                                        event.getArgument('body', ''),
                                        event.getArgument('note', ''),
                                        event.getArgument('alert', ''))
        elif contentID == R.views.lobby.mode_selector.tooltips.SimplyFormatTooltip(
        ):
            modeName = event.getArgument('modeName', '')
            if modeName is None:
                return
            tooltipLocal = R.strings.mode_selector.mode.dyn(modeName)
            if not tooltipLocal:
                return
            header = backport.text(tooltipLocal.battlePassTooltip.header())
            body = backport.text(tooltipLocal.battlePassTooltip.body())
            if not header:
                return
            return SimplyFormatTooltipView(header, body)
        else:
            tooltipClass = self.__tooltipByContentID.get(contentID)
            return tooltipClass() if tooltipClass else None

    def destroyWindow(self):
        self.uiLogger.log(LOG_ACTIONS.CLOSED, details=LOG_CLOSE_DETAILS.OTHER)
        super(ModeSelectorView, self).destroyWindow()

    def createPopOverContent(self, event):
        return RandomBattlePopover(
        ) if event.contentID == R.views.lobby.mode_selector.popovers.RandomBattlePopover(
        ) else super(ModeSelectorView, self).createPopOverContent(event)

    def close(self):
        g_eventBus.handleEvent(events.DestroyGuiImplViewEvent(self.layoutID))

    def _onLoading(self):
        self.__gui.windowsManager.onWindowStatusChanged += self.__windowStatusChanged
        self.__lobbyContext.addHeaderNavigationConfirmator(
            self.__handleHeaderNavigation)
        self.viewModel.onItemClicked += self.__itemClickHandler
        self.viewModel.onShowMapSelectionClicked += self.__showMapSelectionClickHandler
        self.viewModel.onShowWidgetsClicked += self.__showWidgetsClickHandler
        self.viewModel.onInfoClicked += self.__infoClickHandler
        self.__dataProvider.onListChanged += self.__dataProviderListChangeHandler
        self.__updateViewModel(self.viewModel)
        self.__blur = CachedBlur(enabled=True, ownLayer=WindowLayer.MARKER)
        g_eventBus.handleEvent(events.GameEvent(
            events.GameEvent.HIDE_LOBBY_SUB_CONTAINER_ITEMS),
                               scope=EVENT_BUS_SCOPE.GLOBAL)
        g_eventBus.handleEvent(events.LobbyHeaderMenuEvent(
            events.LobbyHeaderMenuEvent.TOGGLE_VISIBILITY,
            ctx={
                'state': HeaderMenuVisibilityState.NOTHING,
                'alias': self.layoutID
            }),
                               scope=EVENT_BUS_SCOPE.LOBBY)
        app = self.__appLoader.getApp()
        self.__prevAppBackgroundAlpha = app.getBackgroundAlpha()
        app.setBackgroundAlpha(_BACKGROUND_ALPHA)
        self.__prevOptimizationEnabled = app.graphicsOptimizationManager.getEnable(
        )
        if self.__prevOptimizationEnabled:
            app.graphicsOptimizationManager.switchOptimizationEnabled(False)

    def _initialize(self):
        g_eventBus.handleEvent(
            FullscreenModeSelectorEvent(FullscreenModeSelectorEvent.NAME,
                                        ctx={'showing': True}))

    def _onLoaded(self):
        self.uiBootcampLogger.logOnlyFromBootcamp(LOG_ACTIONS.OPENED)
        self.inputManager.removeEscapeListener(self.__handleEscape)
        self.uiLogger.log(LOG_ACTIONS.OPENED,
                          isNew=self.__dataProvider.hasNewIndicator,
                          isWidget=self._areWidgetsVisible,
                          isFeatured=self.__isEventEnabled)

    def _finalize(self):
        self.uiBootcampLogger.logOnlyFromBootcamp(LOG_ACTIONS.CLOSED)
        self.__gui.windowsManager.onWindowStatusChanged -= self.__windowStatusChanged
        self.inputManager.removeEscapeListener(self.__handleEscape)
        self.__lobbyContext.deleteHeaderNavigationConfirmator(
            self.__handleHeaderNavigation)
        self.viewModel.onItemClicked -= self.__itemClickHandler
        self.viewModel.onShowMapSelectionClicked -= self.__showMapSelectionClickHandler
        self.viewModel.onShowWidgetsClicked -= self.__showWidgetsClickHandler
        self.viewModel.onInfoClicked -= self.__infoClickHandler
        saveBattlePassStateForItems(self.__dataProvider.itemList)
        self.__dataProvider.onListChanged -= self.__dataProviderListChangeHandler
        self.__dataProvider.dispose()
        g_eventBus.handleEvent(events.LobbyHeaderMenuEvent(
            events.LobbyHeaderMenuEvent.TOGGLE_VISIBILITY,
            ctx={'state': HeaderMenuVisibilityState.ALL}),
                               scope=EVENT_BUS_SCOPE.LOBBY)
        g_eventBus.handleEvent(
            FullscreenModeSelectorEvent(FullscreenModeSelectorEvent.NAME,
                                        ctx={'showing': False}))
        g_eventBus.handleEvent(events.GameEvent(
            events.GameEvent.REVEAL_LOBBY_SUB_CONTAINER_ITEMS),
                               scope=EVENT_BUS_SCOPE.GLOBAL)
        self.__restoreGraphics()

    def __restoreGraphics(self):
        if self.__isGraphicsRestored:
            return
        else:
            self.__isGraphicsRestored = True
            if self.__blur:
                self.__blur.fini()
                self.__blur = None
            app = self.__appLoader.getApp()
            if self.__prevOptimizationEnabled:
                app.graphicsOptimizationManager.switchOptimizationEnabled(True)
            app.setBackgroundAlpha(self.__prevAppBackgroundAlpha)
            return

    def __createSimpleTooltip(self, event, header='', body=''):
        window = DecoratedTooltipWindow(content=SimpleTooltipContent(
            _R_SIMPLE_TOOLTIP(), body=body, header=header),
                                        parent=self.getParentWindow())
        window.load()
        window.move(event.mouse.positionX, event.mouse.positionY)
        return window

    def __dataProviderListChangeHandler(self):
        with self.viewModel.transaction() as tx:
            self.__updateViewModel(tx)

    def __updateViewModel(self, vm):
        vm.setIsMapSelectionVisible(self.__dataProvider.isDemonstrator)
        vm.setIsMapSelectionEnabled(self.__dataProvider.isDemoButtonEnabled)
        vm.setAreWidgetsVisible(ModeSelectorView._areWidgetsVisible)
        if self.__bootcamp.isInBootcamp():
            vm.setState(ModeSelectorWindowStates.BOOTCAMP)
        cards = vm.getCardList()
        cards.clear()
        for item in self.__dataProvider.itemList:
            cards.addViewModel(item.viewModel)

        cards.invalidate()

    @process
    def __itemClickHandler(self, event):
        self.__isClickProcessing = True
        navigationPossible = yield self.__lobbyContext.isHeaderNavigationPossible(
        )
        if not navigationPossible:
            self.__isClickProcessing = False
            return
        else:
            index = int(event.get('index'))
            modeSelectorItem = self.__dataProvider.getItemByIndex(index)
            if modeSelectorItem is None:
                self.__isClickProcessing = False
                return
            self.uiLogger.log(
                LOG_ACTIONS.CARD_CLICKED,
                size=event.get('size'),
                details=event.get('cardMediaSize'),
                isNew=modeSelectorItem.viewModel.getIsNew(),
                mode=modeSelectorItem.modeName,
                isSelected=modeSelectorItem.viewModel.getIsSelected())
            modeSelectorItem.handleClick()
            if modeSelectorItem.isSelectable:
                specView = self.__gui.windowsManager.getViewByLayoutID(
                    BattleSessionView.layoutID)
                if modeSelectorItem.modeName != PREBATTLE_ACTION_NAME.SPEC_BATTLES_LIST and specView is not None:
                    specView.destroyWindow()
                self.__dataProvider.select(modeSelectorItem.modeName)
            self.uiLogger.log(LOG_ACTIONS.CLOSED,
                              details=LOG_CLOSE_DETAILS.CARD_CLICKED)
            self.close()
            return

    def __showMapSelectionClickHandler(self):
        demonstratorWindow = self.__appLoader.getApp(
        ).containerManager.getView(WindowLayer.WINDOW,
                                   criteria={
                                       POP_UP_CRITERIA.VIEW_ALIAS:
                                       VIEW_ALIAS.DEMONSTRATOR_WINDOW
                                   })
        if demonstratorWindow is not None:
            demonstratorWindow.onWindowClose()
        else:
            g_eventBus.handleEvent(LoadViewEvent(
                SFViewLoadParams(VIEW_ALIAS.DEMONSTRATOR_WINDOW)),
                                   scope=EVENT_BUS_SCOPE.LOBBY)
        return

    def __showWidgetsClickHandler(self):
        ModeSelectorView._areWidgetsVisible = not ModeSelectorView._areWidgetsVisible
        self.viewModel.setAreWidgetsVisible(
            ModeSelectorView._areWidgetsVisible)

    def __infoClickHandler(self, event):
        self.uiBootcampLogger.logOnlyFromBootcamp(
            LOG_ACTIONS.INFO_PAGE_ICON_CLICKED)
        index = int(event.get('index'))
        modeSelectorItem = self.__dataProvider.getItemByIndex(index)
        if modeSelectorItem is None:
            return
        else:
            self.uiLogger.log(LOG_ACTIONS.INFO_PAGE_ICON_CLICKED,
                              isNew=modeSelectorItem.viewModel.getIsNew(),
                              mode=modeSelectorItem.modeName)
            modeSelectorItem.handleInfoPageClick()
            return

    def __windowStatusChanged(self, uniqueID, newStatus):
        if newStatus == WindowStatus.LOADED:
            window = self.__gui.windowsManager.getWindow(uniqueID)
            parent = None
            if window.parent is not None and window.parent.content is not None:
                parent = window.parent.content
            if window.content == self or parent is not None and parent == self:
                return
            if window.layer in _CLOSE_LAYERS:
                self.__restoreGraphics()
                if not self.__isClickProcessing:
                    self.uiLogger.log(LOG_ACTIONS.CLOSED,
                                      details=LOG_CLOSE_DETAILS.OTHER)
                    self.close()
        return

    @adisp. async
    def __handleHeaderNavigation(self, callback):
        if self.viewStatus not in (ViewStatus.DESTROYED, ViewStatus.DESTROYING
                                   ) and not self.__isClickProcessing:
            self.close()
        callback(True)

    def __handleEscape(self):
        self.close()
class BCMessageWindow(BCMessageWindowMeta):
    _hangarSpace = dependency.descriptor(IHangarSpace)

    def __init__(self, content):
        super(BCMessageWindow, self).__init__(content)
        self.__blur = None
        return

    def onMessageButtonClicked(self):
        self.onCustomButton(needStopEffect=True, needCloseWindow=False)

    def onTryClosing(self):
        return False

    @subtitleDecorator
    def onMessageAppear(self, type):
        pass

    def onMessageDisappear(self, type):
        if type != BOOTCAMP_MESSAGE_ALIASES.RENDERER_INTRO:
            SoundGroups.g_instance.playSound2D('bc_info_line_disappear')

    def onMessageRemoved(self):
        callback = self._content.get('callback')
        if callback is not None:
            callback(False)
        self.submit()
        return

    def onMessageExecuted(self, renderedType):
        callback = self._content.get('callback')
        if callback is not None:
            callback(True)
        return

    def _populate(self):
        super(BCMessageWindow, self)._populate()
        self.as_setMessageDataS(self._content['messages'])
        self.__blur = CachedBlur(enabled=True,
                                 ownLayer=APP_CONTAINERS_NAMES.VIEWS,
                                 layers=(APP_CONTAINERS_NAMES.TOP_SUB_VIEW,
                                         APP_CONTAINERS_NAMES.SUBVIEW,
                                         APP_CONTAINERS_NAMES.WINDOWS),
                                 blurAnimRepeatCount=1)
        self.as_blurOtherWindowsS(APP_CONTAINERS_NAMES.DIALOGS)
        g_bootcampEvents.onRequestBootcampMessageWindowClose += self.onMessageRemoved
        if self._hangarSpace.spaceInited:
            self.__setCameraDisabled(True)
        else:
            self._hangarSpace.onSpaceCreate += self.__onSpaceCreated

    def _dispose(self):
        super(BCMessageWindow, self)._dispose()
        self.__blur.fini()
        g_bootcampEvents.onRequestBootcampMessageWindowClose -= self.onMessageRemoved
        self._hangarSpace.onSpaceCreate -= self.__onSpaceCreated
        self.__setCameraDisabled(False)

    def _stop(self, needCloseWindow=True):
        self._content.clear()
        for _, effect in self._gui.effects.iterEffects():
            if effect.isStillRunning(self.uniqueName):
                effect.stop()

        if needCloseWindow:
            self.destroy()

    def __onSpaceCreated(self):
        BigWorld.callback(0.1, partial(self.__setCameraDisabled, True))

    def __setCameraDisabled(self, disabled):
        self.fireEvent(
            CameraRelatedEvents(
                CameraRelatedEvents.FORCE_DISABLE_IDLE_PARALAX_MOVEMENT,
                ctx={'isDisable': disabled}), EVENT_BUS_SCOPE.LOBBY)
        self.fireEvent(
            CameraRelatedEvents(
                CameraRelatedEvents.FORCE_DISABLE_CAMERA_MOVEMENT,
                ctx={'disable': disabled}), EVENT_BUS_SCOPE.LOBBY)