Esempio n. 1
0
 def __handleIdleCameraActivation(self, event):
     if self.__currentLocation is not None:
         return
     else:
         positionControlValue = _RTPC_MUSIC_POSITION_CONTROL_MAX_VALUE if event.ctx['started'] else _RTPC_MUSIC_POSITION_CONTROL_MIN_VALUE
         NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_MUSIC_POSITION_CONTROL, positionControlValue)
         return
Esempio n. 2
0
 def __setVehicleSlot(self, invID):
     self.onWindowClose()
     result = yield SetVehicleBranchProcessor(invID, self.__slot.getSlotID()).request()
     if result.userMsg:
         SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType)
     if result.success:
         NewYearSoundsManager.playEvent(NewYearSoundEvents.TANKS_SET)
Esempio n. 3
0
 def __onStopPrintSound(self):
     self.__stopCounter = self.__stopCounter + 1
     eventCounter = self.__getEventCounter()
     if not self.__stopped and self.__stopCounter >= eventCounter:
         self.__stopped = True
         NewYearSoundsManager.playEvent(
             NewYearSoundEvents.CRAFT_MONITOR_PRINTING_STOP)
Esempio n. 4
0
 def __setSoundStyles(self):
     toySettingIdx = self._viewModel.getCurrentSettingIndex()
     _, toySettingIdx, _ = mapToyParamsFromCraftUiToSrv(0, toySettingIdx, 0)
     toySetting = getSafeFromCollection(ToySettings.NEW,
                                        toySettingIdx,
                                        default=RANDOM_STYLE_BOX)
     NewYearSoundsManager.setStylesSwitchBox(toySetting)
Esempio n. 5
0
 def __init__(self, viewModel, parentView, soundConfig=None):
     super(SubModelPresenter, self).__init__()
     self.__parentView = parentView
     self.__viewModel = viewModel
     self.__isLoaded = False
     self.__soundsManager = NewYearSoundsManager(
         {} if soundConfig is None else soundConfig)
     return
Esempio n. 6
0
 def _finalize(self):
     NewYearSoundsManager.playEvent(
         NewYearSoundEvents.AWARD_STYLE_SCREEN_EXIT)
     setOverlayHangarGeneral(False)
     super(NewYearStyleRewardView, self)._finalize()
     self.__rewards = None
     self.viewModel.onClose -= self.__onClose
     self._nyController.onStateChanged -= self.__onEventStateChanged
     return
Esempio n. 7
0
 def __onSettingChanged(self, settingData):
     if not self.__isBlockActive():
         return
     settingData = int(settingData.get('setting', RANDOM_TYPE))
     self._viewModel.setCurrentSettingIndex(settingData)
     NewYearSoundsManager.playEvent(
         NewYearSoundEvents.CRAFT_CHANGE_TOYS_SETTING)
     self.__setSoundStyles()
     self._raiseOnDataChanged()
Esempio n. 8
0
 def __playTransitionSound(cls, objectName):
     if cls.getCurrentViewName() not in (ViewAliases.GLADE_VIEW,
                                         ViewAliases.CELEBRITY_VIEW):
         return
     if objectName == AdditionalCameraObject.CELEBRITY and not cls._celebrityController.isChallengeVisited:
         eventName = NewYearSoundEvents.CELEBRITY_INTRO
     else:
         eventName = _SWITCH_OBJECT_SOUND_EVENTS.get(objectName)
     if eventName:
         NewYearSoundsManager.playEvent(eventName)
Esempio n. 9
0
 def __onAddCraftDecoration(self, *_):
     toyDescriptor = self._itemsCache.items.festivity.getToys().get(self.__currentCraftToyID)
     NewYearSoundsManager.setStylesSwitchBox(toyDescriptor.getSetting())
     with self.viewModel.transaction() as model:
         items = model.craftCarousel.getItems()
         item = CraftToyPresenter(toyDescriptor).asSlotViewModel()
         if CurrentNYCollectionPresenter.getCount() > self.__lastCollectionSize and not self.__nyController.isMaxAtmosphereLevel():
             atmospherePoints = NewYearAtmospherePresenter.getAtmPointsForNewToy(self.__currentCraftToyID)
             item.setAtmosphereBonus(atmospherePoints)
         items.addViewModel(item)
         items.invalidate()
Esempio n. 10
0
 def initialize(self, *args, **kwargs):
     super(NYMainMenu, self).initialize(*args, **kwargs)
     self.catchGiftEventHub()
     soundConfig = {
         NewYearSoundConfigKeys.ENTRANCE_EVENT:
         self.__getEntranceSoundEvent,
         NewYearSoundConfigKeys.EXIT_EVENT: self.__getExitSoundEvent,
         NewYearSoundConfigKeys.STATE_VALUE: self.__getSoundStateValue
     }
     self.__soundsManager = NewYearSoundsManager(soundConfig)
     self.viewModel.setIsExtendedAnim(not isMemoryRiskySystem())
    def onMouseClick(self):
        anchorName = self.anchorName
        if self.enabled and anchorName and anchorName != self.__customizableObjectsMgr.getCurrentCameraAnchor():
            self.logClick(anchorName)
            NewYearSoundsManager.playEvent(NewYearSoundEvents.ENTER_CUSTOME)
            NewYearNavigation.switchByAnchorName(anchorName)
            for cameraObject in ClientSelectableCameraObject.allCameraObjects:
                if cameraObject.state != CameraMovementStates.FROM_OBJECT:
                    cameraObject.onDeselect(None)

        return
Esempio n. 12
0
 def __onTypeChanged(self, typeData):
     if not self.__isBlockActive():
         return
     else:
         selectedType = typeData.get('type', RANDOM_TYPE)
         groupName = typeData.get('groupName', None)
         self._viewModel.setSelectedType(selectedType)
         self._viewModel.setCurrentCategory(groupName)
         NewYearSoundsManager.playEvent(
             NewYearSoundEvents.CRAFT_CHANGE_TOY_TYPE)
         self._raiseOnDataChanged()
         return
Esempio n. 13
0
 def __init__(self):
     settings = ViewSettings(R.views.lobby.new_year.components.
                             ny_main_widget.NewYearMainWidget())
     settings.flags = ViewFlags.COMPONENT
     settings.model = NewYearMainWidgetModel()
     super(NyMainWidget, self).__init__(settings)
     self._lobbyMode = True
     self.__level = NewYearAtmospherePresenter.getLevel()
     self.__maxLevel = self._itemsCache.items.festivity.getMaxLevel()
     self.__soundManager = NewYearSoundsManager({})
     self.__soundRTPCController = None
     return
Esempio n. 14
0
 def __update(self):
     jukeboxEntity = self.__getJukeboxEntity()
     if jukeboxEntity is None:
         return
     else:
         camera = BigWorld.camera()
         cameraPos = camera.position
         distance = jukeboxEntity.position.distTo(cameraPos)
         diff = math.fabs(self.__lastDistance - distance)
         if diff > _MIN_DIST:
             NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_JUKEBOX_DISTANCE, distance)
             self.__lastDistance = distance
         return
Esempio n. 15
0
 def initialize(self, *args, **kwargs):
     super(NyVehiclesViewPresenter, self).initialize(*args, **kwargs)
     NewYearSoundsManager.setHangarFilteredState(True)
     self.__subscribe()
     self.__startNotifier()
     levelStr = backport.text(
         R.strings.ny.vehiclesView.levelsStr(),
         minLevel=formatRomanNumber(NY_BRANCH_MIN_LEVEL),
         maxLevel=formatRomanNumber(NY_BRANCH_MAX_LEVEL))
     with self.viewModel.transaction() as tx:
         tx.setIsRomanNumbersAllowed(IS_ROMAN_NUMBERS_ALLOWED)
         tx.setIsPostEvent(self.__nyController.isPostEvent())
         tx.setLevelStr(levelStr)
         tx.setCurrentAtmosphereLvl(
             self.__itemsCache.items.festivity.getMaxLevel())
         self.__createVehiclesList(tx)
         self.__updateIntroStatus(tx)
Esempio n. 16
0
 def initialize(self, ctx=None, *args, **kwargs):
     super(NYSidebar, self).initialize(*args, **kwargs)
     self.viewModel.onSideBarBtnClick += self.__onSideBarBtnClick
     self._nyController.onDataUpdated += self.__onDataUpdated
     self.__celebrityController.onQuestsUpdated += self.__onQuestUpdated
     AccountSettings.onSettingsChanging += self.__onAccountDataUpdated
     self.__settingsCore.onSettingsChanged += self.__onSettingsChanged
     soundConfig = {NewYearSoundConfigKeys.ENTRANCE_EVENT: self.__getEntranceSoundEvent,
      NewYearSoundConfigKeys.EXIT_EVENT: self.__getExitSoundEvent,
      NewYearSoundConfigKeys.STATE_VALUE: self.__getSoundStateValue}
     self.__soundsManager = NewYearSoundsManager(soundConfig)
     self.__controllers = {NyWidgetTopMenu.GLADE: GladeTabsController(),
      NyWidgetTopMenu.COLLECTIONS: AlbumsTabsController(),
      NyWidgetTopMenu.REWARDS: RewardsTabsController()}
     g_eventBus.addListener(events.NewYearEvent.ON_SWITCH_VIEW, self.__onSwitchViewEvent, scope=EVENT_BUS_SCOPE.LOBBY)
     g_eventBus.addListener(events.NewYearEvent.SELECT_SIDEBAR_TAB_OUTSIDE, self.__onSelectTabOutside, scope=EVENT_BUS_SCOPE.LOBBY)
     if ctx is not None:
         self.__onSwitchView(ctx)
     return
Esempio n. 17
0
 def __onSelectedDecoration(self):
     if not self.viewModel.getHasDecoration():
         self.__craftCtrl.setSettings(isMegaOn=True)
         self.__flowLogger.logBigDecorationSlotClick(
             NewYearNavigation.getCurrentObject())
         NewYearNavigation.switchToView(ViewAliases.CRAFT_VIEW)
         self.destroyWindow()
         return
     else:
         toyID = INVALID_TOY_ID if self.viewModel.getSelected(
         ) else self.viewModel.slot.getToyID()
         toy = self.__itemsCache.items.festivity.getToys().get(toyID)
         if toy is not None:
             isPureToy = toy.getPureCount() > 0
             points = toy.getAtmosphere(isPureToy, self.__isPureSlot)
             toyUsage = TOY_SLOT_USAGE.PURE if isPureToy else TOY_SLOT_USAGE.USED
         else:
             points = 0
             toyUsage = TOY_SLOT_USAGE.USED
         result = yield self._nyController.hangToy(toyID, self.__slotID,
                                                   toyUsage)
         if result.success and self.viewStatus == ViewStatus.LOADED:
             g_eventBus.handleEvent(events.NewYearEvent(
                 events.NewYearEvent.ON_TOY_INSTALLED,
                 ctx={
                     'toyID': toyID,
                     'slotID': self.__slotID,
                     'atmoshereBonus': points
                 }),
                                    scope=EVENT_BUS_SCOPE.LOBBY)
             self.__isSelected = toyID != INVALID_TOY_ID
             with self.viewModel.transaction() as tx:
                 tx.setSelected(self.__isSelected)
                 self.__updateTitle(tx)
                 if self.__isSelected:
                     if self.__slotType in ToyTypes.MEGA:
                         NewYearSoundsManager.playEvent(
                             NewYearSoundEvents.ADD_TOY_MEGA)
                 else:
                     tx.slot.setIsNew(True)
         self.destroyWindow()
         return
Esempio n. 18
0
 def __updateMainContent(self,
                         isClickTab=False,
                         prevBoxType=None,
                         prevHasBoxes=False):
     with self.viewModel.transaction() as model:
         hasBoxes = False
         boxType = self.__tabsController.getSelectedBoxType()
         boxCategory = self.__tabsController.getSelectedBoxCategory()
         if boxType in self.__availableBoxes:
             available = self.__availableBoxes[boxType]
             if boxType == NewYearLootBoxes.PREMIUM:
                 categories = available['categories']
                 boxNumber = categories[
                     boxCategory] if boxCategory in categories else available[
                         'total']
             else:
                 boxNumber = available['total']
             hasBoxes = boxNumber > 0
             if hasBoxes:
                 self.__updateBoxesButtons(
                     boxNumber, boxType == NewYearLootBoxes.PREMIUM)
         setting = self.__LOOT_BOX_CATEGORY_MAPPING.get(
             boxCategory) if boxCategory is not None else None
         NewYearSoundsManager.setStylesSwitchBox(
             setting if setting else RANDOM_STYLE_BOX)
         NewYearSoundsManager.setRTPCBoxEntryView(boxType)
         NewYearSoundsManager.setRTPCBoxAvailability(hasBoxes)
         if model.getCurrentName() and model.getCurrentName(
         ) != self.__tabsController.getSelectedBoxName():
             playSound(LootBoxViewEvents.LOGISTIC_CENTER_SWITCH)
         model.setSelectedBoxType(boxType)
         model.setCurrentName(self.__tabsController.getSelectedBoxName())
         model.setIsPremiumType(boxType == NewYearLootBoxes.PREMIUM)
         model.setRealm(CURRENT_REALM)
         lootboxItem = getLootBoxByTypeAndCategory(boxType,
                                                   boxCategory,
                                                   isInInventory=False)
         isBoxEnabled = lootboxItem is not None and self.lobbyContext.getServerSettings(
         ).isLootBoxEnabled(lootboxItem.getID())
         model.setIsOpenBoxBtnVisible(hasBoxes and isBoxEnabled)
         model.setIsBoxesAvailable(isBoxEnabled)
         model.setCurrentCountButton(self.__getSelectedCountIndx())
         nyStorage = self.settingsCore.serverSettings.getNewYearStorage()
         model.setIsStatisticsHintActive(
             not nyStorage.get(NewYearStorageKeys.NY_STATISTICS_HINT_SHOWN,
                               False)
             and bool(self.itemsCache.items.tokens.getLootBoxesStats()))
         if isClickTab and (prevBoxType != boxType or hasBoxes
                            or prevHasBoxes and not hasBoxes):
             model.setIsBoxChangeAnimation(True)
         setGaranteedRewardData(model.guaranteedReward, lootboxItem,
                                not self.__isViewHidden, True)
     g_eventBus.handleEvent(events.LootboxesEvent(
         events.LootboxesEvent.ON_TAB_SELECTED,
         ctx={
             'tabName': self.__tabsController.getSelectedBoxName(),
             'hasBoxes': hasBoxes
         }),
                            scope=EVENT_BUS_SCOPE.LOBBY)
     return
Esempio n. 19
0
 def setCurrentLocation(self, location, force=False):
     if force or self.__currentLocation != location:
         self.__currentLocation = location
         if self.__currentLocation == CustomizationObjects.FAIR:
             self.__startTicker()
         else:
             self.__stopTicker()
             NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_JUKEBOX_DISTANCE, 0)
         if self.__currentLocation is not None:
             positionControlValue = _RTPC_MUSIC_POSITION_CONTROL_MAX_VALUE
         else:
             positionControlValue = _RTPC_MUSIC_POSITION_CONTROL_MIN_VALUE
         NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_MUSIC_POSITION_CONTROL, positionControlValue)
     NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_GIFT_AVAILABILITY, _RTPC_GIFT_AVAILABILITY_MIN_VALUE)
     return
Esempio n. 20
0
 def updateData(self):
     isMegaDeviceTurnedOn = self._nodesHolder.megaDevice.getState() in MegaDeviceState.ACTIVATED
     toyTypeIdx, toySettingIdx, toyRankIdx, _ = self._nodesHolder.regularToysBlock.getToyConfig()
     fillerState = self._nodesHolder.antiduplicator.getState()
     craftCost = self._craftCtrl.calculateToyCraftCost(isMegaToy=isMegaDeviceTurnedOn, toyTypeIdx=toyTypeIdx, toySettingIdx=toySettingIdx, toyRankIdx=toyRankIdx, fillerState=fillerState)
     self.__toyTypeID, self.__toySettingID, self.__toyRankID = mapToyParamsFromCraftUiToSrv(toyTypeIdx, toySettingIdx, toyRankIdx)
     if isMegaDeviceTurnedOn:
         self.__toySettingID = YEARS_INFO.CURRENT_SETTING_IDS_BY_NAME[ToySettings.MEGA_TOYS]
     shardsCount = self._itemsCache.items.festivity.getShardsCount()
     if shardsCount < craftCost:
         NewYearSoundsManager.playEvent(NewYearSoundEvents.COST_TOYS_NOT_CHANGE)
     elif self.__craftCost > craftCost:
         NewYearSoundsManager.playEvent(NewYearSoundEvents.COST_TOYS_DOWN)
     elif self.__craftCost < craftCost:
         NewYearSoundsManager.playEvent(NewYearSoundEvents.COST_TOYS_UP)
     self.__craftCost = craftCost
     with self._viewModel.transaction() as tx:
         tx.setCraftPrice(self.__craftCost)
Esempio n. 21
0
 def fini(self):
     NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_MUSIC_POSITION_CONTROL, _RTPC_MUSIC_POSITION_CONTROL_MIN_VALUE)
     g_eventBus.removeListener(CameraRelatedEvents.IDLE_CAMERA, self.__handleIdleCameraActivation)
     self.__stopTicker()
     self.__entityID = None
     return
Esempio n. 22
0
 def setLevelAtmosphere(level):
     NewYearSoundsManager.setRTPC(NewYearSoundVars.RTPC_LEVEL_ATMOSPHERE, level)
Esempio n. 23
0
class SubModelPresenter(object):
    __slots__ = ('__viewModel', '__isLoaded', '__parentView',
                 '__soundsManager')

    def __init__(self, viewModel, parentView, soundConfig=None):
        super(SubModelPresenter, self).__init__()
        self.__parentView = parentView
        self.__viewModel = viewModel
        self.__isLoaded = False
        self.__soundsManager = NewYearSoundsManager(
            {} if soundConfig is None else soundConfig)
        return

    @property
    def isLoaded(self):
        return self.__isLoaded

    @property
    def parentView(self):
        return self.__parentView

    def getViewModel(self):
        return self.__viewModel

    def getParentWindow(self):
        return self.parentView.getParentWindow()

    def initialize(self, *args, **kwargs):
        self.__soundsManager.onEnterView()
        self.__subscribe()
        self.__isLoaded = True

    def finalize(self):
        self.__isLoaded = False
        self.__unsubscribe()
        self.__soundsManager.onExitView()

    def clear(self):
        self.__viewModel = None
        self.__parentView = None
        self.__soundsManager.clear()
        return

    def createToolTip(self, event):
        return None

    def createToolTipContent(self, event, ctID):
        return None

    def createPopOverContent(self, event):
        return None

    def _getCallbacks(self):
        pass

    def _getListeners(self):
        pass

    def _getEvents(self):
        pass

    def __subscribe(self):
        g_clientUpdateManager.addCallbacks(dict(self._getCallbacks()))
        for eventBusArgs in self._getListeners():
            g_eventBus.addListener(*eventBusArgs)

        for event, handler in self._getEvents():
            event += handler

    def __unsubscribe(self):
        for event, handler in reversed(self._getEvents()):
            event -= handler

        for eventBusArgs in reversed(self._getListeners()):
            g_eventBus.removeListener(*eventBusArgs[:3])

        g_clientUpdateManager.removeObjectCallbacks(self)
 def onMouseClick(self):
     super(NewYearCelebrityEntryObject, self).onMouseClick()
     NewYearSoundsManager.playEvent(NewYearSoundEvents.ENTER_CUSTOME)
     self.logClick(AnchorNames.CELEBRITY)
     NewYearNavigation.switchByAnchorName(AnchorNames.CELEBRITY)
Esempio n. 25
0
 def finalize(self):
     self.__stopNotifier()
     self.__unsubscribe()
     NewYearSoundsManager.setHangarFilteredState(False)
     super(NyVehiclesViewPresenter, self).finalize()
Esempio n. 26
0
class NYMainMenu(HistorySubModelPresenter, GiftEventHubWatcher):
    _GIFT_EVENT_ID = GiftEventID.NY_HOLIDAYS
    __celebrityController = dependency.descriptor(ICelebritySceneController)
    __settingsCore = dependency.descriptor(ISettingsCore)
    __topMenuLogger = NyWidgetTopMenuLogger()
    __flowLogger = NyTopMenuFlowLogger()

    def __init__(self, viewModel, parentView, *args, **kwargs):
        super(NYMainMenu, self).__init__(viewModel, parentView, *args,
                                         **kwargs)
        self.__tabsController = NewYearMainTabsController()
        self.__soundsManager = None
        self.__currentView = None
        return

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

    def createToolTipContent(self, event, contentID):
        tooltips = R.views.lobby.new_year.tooltips
        if event.contentID == tooltips.NyMenuGiftTooltip():
            return NyMenuGiftTooltip()
        if contentID == tooltips.NyMenuShardsTooltip():
            return NyMenuShardsTooltip()
        return NyMenuCollectionsTooltip(
        ) if contentID == tooltips.NyMenuCollectionsTooltip() else super(
            NYMainMenu, self).createToolTipContent(event, contentID)

    def initialize(self, *args, **kwargs):
        super(NYMainMenu, self).initialize(*args, **kwargs)
        self.catchGiftEventHub()
        soundConfig = {
            NewYearSoundConfigKeys.ENTRANCE_EVENT:
            self.__getEntranceSoundEvent,
            NewYearSoundConfigKeys.EXIT_EVENT: self.__getExitSoundEvent,
            NewYearSoundConfigKeys.STATE_VALUE: self.__getSoundStateValue
        }
        self.__soundsManager = NewYearSoundsManager(soundConfig)
        self.viewModel.setIsExtendedAnim(not isMemoryRiskySystem())

    def finalize(self):
        self.__soundsManager.onExitView()
        self.__soundsManager.clear()
        self.__soundsManager = None
        self.__currentView = None
        self.releaseGiftEventHub()
        super(NYMainMenu, self).finalize()
        return

    def _getEvents(self):
        return ((self.viewModel.onInfoBtnClick, self.__onInfoBtnClick),
                (self.viewModel.onSwitchContent, self.__onMenuItemSelected),
                (self._nyController.onDataUpdated, self.__onDataUpdated),
                (self.__celebrityController.onQuestsUpdated,
                 self.__onDataUpdated), (AccountSettings.onSettingsChanging,
                                         self.__onAccountDataUpdated),
                (self.__settingsCore.onSettingsChanged,
                 self.__onSettingsChanged))

    def _getListeners(self):
        return ((events.NewYearEvent.ON_SWITCH_VIEW, self.__onSwitchViewEvent,
                 EVENT_BUS_SCOPE.LOBBY), )

    def _getCallbacks(self):
        return (('tokens', self.__onTokensChanged), )

    def _onGiftHubUpdate(self, reason, _=None):
        if reason == HubUpdateReason.SETTINGS:
            self.__recreateMenu()
        elif reason == HubUpdateReason.STAMPER_UPDATE:
            self.__updateMenu()

    def __onInfoBtnClick(self):
        self.__flowLogger.logInfoClick(
            source=self.__currentView,
            albumTab=self._tabCache.getCurrentYear(),
            rewardTab=self._tabCache.getRewardsTab(),
            selectedObject=NewYearNavigation.getCurrentObject())
        NewYearNavigation.showInfoView(showDefaultTabForced=True)

    def __onMenuItemSelected(self, args):
        menuName = args['view']
        viewAlias = _NAVIGATION_ALIAS_VIEWS[menuName]
        self._navigationHistory.clear()
        self.__topMenuLogger.logClick(menuName)
        self.__flowLogger.logTabSelect(
            source=self.__currentView,
            view=menuName,
            albumTab=self._tabCache.getCurrentYear(),
            rewardTab=self._tabCache.getRewardsTab(),
            selectedObject=NewYearNavigation.getCurrentObject(),
            previousObject=NewYearNavigation.getPreviousObject())
        with self.viewModel.transaction() as tx:
            tx.setStartIndexMenu(self.__tabsController.tabOrderKey(menuName))
        self.__soundsManager.playEvent(NewYearSoundEvents.TAB_BAR_CLICK)
        self._goToByViewAlias(viewAlias, saveHistory=False)

    def __onSwitchViewEvent(self, event):
        self.__onSwitchView(event.ctx)

    def __onSwitchView(self, ctx):
        menuName = ctx.menuName
        if menuName != self.__currentView:
            self.__soundsManager.onExitView()
            self.__currentView = menuName
            self.__soundsManager.onEnterView()
        if menuName != NyWidgetTopMenu.INFO and self.__tabsController.getCurrentTabName(
        ) != menuName:
            self.__tabsController.selectTab(menuName)
        self.__updateMenu()

    def __onDataUpdated(self, *_):
        self.__updateMenu()

    def __onAccountDataUpdated(self, key, _):
        if key in (NY_CELEBRITY_QUESTS_VISITED_MASK,
                   NY_OLD_COLLECTIONS_BY_YEAR_VISITED,
                   NY_OLD_REWARDS_BY_YEAR_VISITED):
            self.__updateMenu()

    def __onSettingsChanged(self, diff):
        if NewYearStorageKeys.CELEBRITY_CHALLENGE_VISITED in diff:
            self.__updateMenu()

    def __onTokensChanged(self, tokens):
        if any((token.startswith(CelebrityQuestTokenParts.PREFIX)
                for token in tokens)):
            self.__updateMenu()

    def __recreateMenu(self):
        with self.viewModel.transaction() as model:
            tabIdx = self.__getTabIdx()
            model.setStartIndexMenu(tabIdx)
            self.__tabsController.setSelectedTabIdx(tabIdx)
            self.__tabsController.createTabModels(model.getItemsMenu())

    def __updateMenu(self):
        with self.viewModel.transaction() as model:
            self.__tabsController.updateTabModels(model.getItemsMenu())
            model.setStartIndexMenu(self.__getTabIdx())

    def __getEntranceSoundEvent(self):
        return _SOUNDS_MAP.get(NewYearSoundConfigKeys.ENTRANCE_EVENT,
                               {}).get(self.__currentView)

    def __getExitSoundEvent(self):
        return _SOUNDS_MAP.get(NewYearSoundConfigKeys.EXIT_EVENT,
                               {}).get(self.__currentView)

    def __getSoundStateValue(self):
        return _SOUNDS_MAP.get(NewYearSoundConfigKeys.STATE_VALUE,
                               {}).get(self.__currentView)

    def __getTabIdx(self):
        currentView = self.__currentView
        if currentView == NyWidgetTopMenu.INFO:
            return -1
        return 0 if currentView not in self.__tabsController.getEnabledTabsArray(
        ) else self.__tabsController.tabOrderKey(currentView)
Esempio n. 27
0
 def __onPlayPrintSound(self):
     if self.__printingSoundEnabled:
         self.__stopped = False
         NewYearSoundsManager.playEvent(
             NewYearSoundEvents.CRAFT_MONITOR_PRINING_START)
Esempio n. 28
0
class NYSidebar(HistorySubModelPresenter):
    __slots__ = ('__tabsController', '__controllers', '__currentTab', '__currentViewName', '__soundsManager')
    __celebrityController = dependency.descriptor(ICelebritySceneController)
    __newYearController = dependency.descriptor(INewYearController)
    __settingsCore = dependency.descriptor(ISettingsCore)
    __flowUILogger = NySideBarFlowLogger()

    def __init__(self, viewModel, parentView, *args, **kwargs):
        super(NYSidebar, self).__init__(viewModel, parentView)
        self.__tabsController = None
        self.__controllers = {}
        self.__currentTab = None
        self.__currentViewName = None
        self.__soundsManager = None
        return

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

    def initialize(self, ctx=None, *args, **kwargs):
        super(NYSidebar, self).initialize(*args, **kwargs)
        self.viewModel.onSideBarBtnClick += self.__onSideBarBtnClick
        self._nyController.onDataUpdated += self.__onDataUpdated
        self.__celebrityController.onQuestsUpdated += self.__onQuestUpdated
        AccountSettings.onSettingsChanging += self.__onAccountDataUpdated
        self.__settingsCore.onSettingsChanged += self.__onSettingsChanged
        soundConfig = {NewYearSoundConfigKeys.ENTRANCE_EVENT: self.__getEntranceSoundEvent,
         NewYearSoundConfigKeys.EXIT_EVENT: self.__getExitSoundEvent,
         NewYearSoundConfigKeys.STATE_VALUE: self.__getSoundStateValue}
        self.__soundsManager = NewYearSoundsManager(soundConfig)
        self.__controllers = {NyWidgetTopMenu.GLADE: GladeTabsController(),
         NyWidgetTopMenu.COLLECTIONS: AlbumsTabsController(),
         NyWidgetTopMenu.REWARDS: RewardsTabsController()}
        g_eventBus.addListener(events.NewYearEvent.ON_SWITCH_VIEW, self.__onSwitchViewEvent, scope=EVENT_BUS_SCOPE.LOBBY)
        g_eventBus.addListener(events.NewYearEvent.SELECT_SIDEBAR_TAB_OUTSIDE, self.__onSelectTabOutside, scope=EVENT_BUS_SCOPE.LOBBY)
        if ctx is not None:
            self.__onSwitchView(ctx)
        return

    def finalize(self):
        self._nyController.onDataUpdated -= self.__onDataUpdated
        self.__celebrityController.onQuestsUpdated -= self.__onQuestUpdated
        self.viewModel.onSideBarBtnClick -= self.__onSideBarBtnClick
        AccountSettings.onSettingsChanging -= self.__onAccountDataUpdated
        self.__settingsCore.onSettingsChanged -= self.__onSettingsChanged
        g_eventBus.removeListener(events.NewYearEvent.ON_SWITCH_VIEW, self.__onSwitchViewEvent, scope=EVENT_BUS_SCOPE.LOBBY)
        g_eventBus.removeListener(events.NewYearEvent.SELECT_SIDEBAR_TAB_OUTSIDE, self.__onSelectTabOutside, scope=EVENT_BUS_SCOPE.LOBBY)
        self.__tabsController = None
        self.__controllers.clear()
        self.__soundsManager.onExitView()
        self.__soundsManager.clear()
        self.__soundsManager = None
        self.__currentViewName = None
        super(NYSidebar, self).finalize()
        return

    def __onSwitchViewEvent(self, event):
        ctx = event.ctx
        self.__onSwitchView(ctx)

    def __onSwitchView(self, ctx):
        menuName = ctx.menuName
        selectedTab = None
        self.viewModel.setViewName(menuName)
        self.__tabsController = self.__controllers.get(menuName)
        if self.__tabsController is not None:
            self.__updateTabs(ctx.tabName, menuName)
            selectedTab = self.__tabsController.getSelectedName(self.viewModel.getItemsTabBar())
        else:
            self.__clearTabs()
        if self.__currentViewName != menuName or self.__currentTab != selectedTab:
            self.__soundsManager.onExitView()
            self.__currentViewName = menuName
            self.__currentTab = selectedTab
            self.__soundsManager.onEnterView()
        return

    def __onSelectTabOutside(self, event):
        menuName = event.ctx['menuName']
        tabName = event.ctx['tabName']
        if self.__currentViewName != menuName or self.__tabsController is None or self.__currentTab == tabName:
            return
        else:
            needToInvokeSound = self.__currentViewName != NyWidgetTopMenu.COLLECTIONS or self.__newYearController.isMaxAtmosphereLevel()
            if needToInvokeSound:
                self.__soundsManager.onExitView()
            self.__currentTab = tabName
            self.__tabsController.selectTab(tabName)
            self.viewModel.setStartIndex(self.__tabsController.getSelectedTabIdx())
            if needToInvokeSound:
                self.__soundsManager.onEnterView()
            return

    def __updateTabs(self, tabName, menuName):
        if tabName is not None:
            if self.__tabsController.getCurrentTabName() != tabName:
                self.__tabsController.selectTab(tabName)
        if self._tabCache.getIntroScreenState(menuName) == NewYearTabCache.OPENED_INTRO_STATE:
            self.__clearTabs()
        else:
            self.__fillTabs()
        return

    def __fillTabs(self):
        with self.viewModel.transaction() as model:
            tabsArray = model.getItemsTabBar()
            self.__tabsController.createTabModels(tabsArray)
            tabIdx = self.__tabsController.getSelectedTabIdx()
            model.setStartIndex(tabIdx)

    def __validateTabs(self):
        if self._tabCache.getIntroScreenState(self.__currentViewName) == NewYearTabCache.OPENED_INTRO_STATE:
            return
        self.__tabsController.updateTabModels(self.viewModel.getItemsTabBar())

    def __clearTabs(self):
        with self.viewModel.transaction() as model:
            tabsArray = model.getItemsTabBar()
            tabsArray.clear()
            tabsArray.invalidate()
            model.setStartIndex(0)

    def __onDataUpdated(self, keys):
        if self.__tabsController is None:
            return
        else:
            checkKeys = {SyncDataKeys.INVENTORY_TOYS,
             SyncDataKeys.SLOTS,
             SyncDataKeys.TOY_COLLECTION,
             SyncDataKeys.TOY_FRAGMENTS}
            if set(keys) & checkKeys:
                self.__validateTabs()
            return

    def __onQuestUpdated(self):
        if self.__tabsController is None:
            return
        else:
            self.__validateTabs()
            return

    def __onAccountDataUpdated(self, key, value):
        if self.__tabsController is None:
            return
        else:
            if key in (NY_OLD_COLLECTIONS_BY_YEAR_VISITED, NY_OLD_REWARDS_BY_YEAR_VISITED):
                self.__validateTabs()
            return

    def __onSettingsChanged(self, diff):
        if self.__tabsController is None:
            return
        else:
            if NewYearStorageKeys.GLADE_INTRO_VISITED in diff:
                self.__updateTabs(self.__currentTab, self.__currentViewName)
            return

    def __onSideBarBtnClick(self, args):
        tabName = args['tabName']
        self.__soundsManager.playEvent(NewYearSoundEvents.SIDE_BAR_CLICK)
        self.__flowUILogger.logTabSelect(view=self.__currentViewName, currentTab=self.__tabsController.getCurrentTabName(), targetTab=tabName)
        self.__selectTab(tabName)

    def __selectTab(self, tabName):
        needToInvokeSound = self.__currentViewName != NyWidgetTopMenu.COLLECTIONS or self.__newYearController.isMaxAtmosphereLevel()
        if needToInvokeSound:
            self.__soundsManager.onExitView()
        self.__currentTab = tabName
        self.__tabsController.selectTab(tabName)
        with self.viewModel.transaction() as model:
            model.setStartIndex(self.__tabsController.getSelectedTabIdx())
        g_eventBus.handleEvent(events.NewYearEvent(events.NewYearEvent.ON_SIDEBAR_SELECTED, ctx=NYTabCtx(tabName=tabName, menuName=self.viewModel.getViewName())), scope=EVENT_BUS_SCOPE.LOBBY)
        if needToInvokeSound:
            self.__soundsManager.onEnterView()

    def __getEntranceSoundEvent(self):
        return self.__getSoundEvent(NewYearSoundConfigKeys.ENTRANCE_EVENT)

    def __getExitSoundEvent(self):
        return self.__getSoundEvent(NewYearSoundConfigKeys.EXIT_EVENT)

    def __getSoundEvent(self, eventType):
        if self.__currentViewName == NyWidgetTopMenu.GLADE:
            return _GLADE_SOUNDS_MAP.get(eventType, {}).get(self.__currentTab)
        else:
            if self.__currentViewName == NyWidgetTopMenu.COLLECTIONS and (self.__currentTab == Collections.NewYear22 or self.__newYearController.isMaxAtmosphereLevel()):
                return _COLLECTIONS_SOUNDS_MAP.get(eventType, {}).get(self.__currentTab)
            return None

    def __getSoundStateValue(self):
        if self.__currentViewName == NyWidgetTopMenu.GLADE:
            selectedTabName = self.__tabsController.getCurrentTabName()
            return _GLADE_SOUNDS_MAP.get(NewYearSoundConfigKeys.STATE_VALUE, {}).get(selectedTabName)
        else:
            return None
Esempio n. 29
0
 def __playToggleSound(isOn):
     soundEvent = NewYearSoundEvents.CRAFT_MEGA_MODULE_ON if isOn else NewYearSoundEvents.CRAFT_MEGA_MODULE_OFF
     NewYearSoundsManager.playEvent(soundEvent)
Esempio n. 30
0
class NyMainWidget(ViewImpl):
    _nyController = dependency.descriptor(INewYearController)
    _COManager = dependency.descriptor(ICustomizableObjectsManager)
    _itemsCache = dependency.descriptor(IItemsCache)
    settingsCore = dependency.descriptor(ISettingsCore)
    __gui = dependency.descriptor(IGuiLoader)
    __uiLogger = NyMainWidgetLogger()

    def __init__(self):
        settings = ViewSettings(R.views.lobby.new_year.components.
                                ny_main_widget.NewYearMainWidget())
        settings.flags = ViewFlags.COMPONENT
        settings.model = NewYearMainWidgetModel()
        super(NyMainWidget, self).__init__(settings)
        self._lobbyMode = True
        self.__level = NewYearAtmospherePresenter.getLevel()
        self.__maxLevel = self._itemsCache.items.festivity.getMaxLevel()
        self.__soundManager = NewYearSoundsManager({})
        self.__soundRTPCController = None
        return

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

    def createToolTipContent(self, event, contentID):
        if event.contentID == R.views.lobby.new_year.tooltips.NyMainWidgetTooltip(
        ):
            return NyMainWidgetTooltip()
        else:
            return NyTotalBonusTooltip(
            ) if event.contentID == R.views.lobby.new_year.tooltips.NyTotalBonusTooltip(
            ) else None

    def _initialize(self):
        super(NyMainWidget, self)._initialize()
        self.viewModel.onClick += self.__onWidgetClick
        self._nyController.onDataUpdated += self.__onDataUpdated
        g_eventBus.addListener(NewYearEvent.ON_SWITCH_VIEW,
                               self.__onSwitchView, EVENT_BUS_SCOPE.LOBBY)
        NewYearNavigation.onObjectStateChanged += self.__onObjectStateChanged
        currentObject = NewYearNavigation.getCurrentObject()
        self._lobbyMode = currentObject is None
        self.__soundRTPCController = SoundRTPCController()
        self.__soundRTPCController.init(currentObject)
        self.__soundRTPCController.setLevelAtmosphere(
            self._itemsCache.items.festivity.getMaxLevel())
        with self.viewModel.transaction() as model:
            self.__updateData(model)
            self.__updateLevel(model)
            self.__updateActiveState(model)
            model.setIsExtendedAnim(not isMemoryRiskySystem())
        ClientSelectableCameraObject.switchCamera()
        self.viewModel.setIsInited(True)
        return

    def _finalize(self):
        if self.__soundRTPCController is not None:
            self.__soundRTPCController.fini()
            self.__soundRTPCController = None
        self.__soundManager.clear()
        self.viewModel.onClick -= self.__onWidgetClick
        self._nyController.onDataUpdated -= self.__onDataUpdated
        g_eventBus.removeListener(NewYearEvent.ON_SWITCH_VIEW,
                                  self.__onSwitchView,
                                  scope=EVENT_BUS_SCOPE.LOBBY)
        NewYearNavigation.onObjectStateChanged -= self.__onObjectStateChanged
        super(NyMainWidget, self)._finalize()
        return

    def getLobbyMode(self, *_):
        return self._lobbyMode

    def __onWidgetClick(self, *_):
        self.__uiLogger.logClick(self._lobbyMode)
        NewYearNavigation.switchTo(CustomizationObjects.FIR,
                                   True,
                                   withFade=True)
        if self._lobbyMode:
            self.__soundManager.playEvent(NewYearSoundEvents.ENTER_CUSTOME)
            self.__soundManager.playEvent(NewYearSoundEvents.TRANSITION_TREE)

    def __onDataUpdated(self, keys):
        if SyncDataKeys.POINTS in keys:
            with self.viewModel.transaction() as model:
                self.__updateData(model)
                self.__updateLevel(model)

    def __updateLevel(self, model):
        animationType = NewYearMainWidgetAnimTypes.ANIM_TYPE_NONE
        level = NewYearAtmospherePresenter.getLevel()
        if level != self.__level:
            self.__level = level
            self.__onLevelChanged()
        maxLevel = self._itemsCache.items.festivity.getMaxLevel()
        if maxLevel != self.__maxLevel:
            self.__maxLevel = maxLevel
            animationType = NewYearMainWidgetAnimTypes.ANIM_TYPE_UP_LONG
        model.setAnimationType(animationType)
        model.setLevel(self.__level)
        model.setLevelRoman(int2roman(self.__maxLevel))
        currentPoints, nextPoints = NewYearAtmospherePresenter.getLevelProgress(
        )
        model.setCurrentPoints(currentPoints)
        model.setNextPoints(nextPoints)

    def __updateData(self, model):
        model.setLobbyMode(self._lobbyMode)
        model.setUserLanguage(str(getLanguageCode()).upper())
        model.setBonusValue(CreditsBonusHelper.getBonusInPercents())
        model.setIsRomanNumbersAllowed(IS_ROMAN_NUMBERS_ALLOWED)
        model.setIsEnabled(
            NewYearNavigation.getCurrentObject() != CustomizationObjects.FIR)

    @staticmethod
    def __updateActiveState(model):
        currentView = NewYearNavigation.getCurrentViewName()
        model.setIsVisible(currentView != ViewAliases.INFO_VIEW)
        model.setIsEnabled(
            currentView != ViewAliases.GLADE_VIEW or
            NewYearNavigation.getCurrentObject() != CustomizationObjects.FIR)

    def __onObjectStateChanged(self):
        currentObject = NewYearNavigation.getCurrentObject()
        self._lobbyMode = currentObject is None
        with self.viewModel.transaction() as model:
            self.__updateData(model)
            self.__updateLevel(model)
            self.__updateActiveState(model)
        self.__soundRTPCController.setCurrentLocation(currentObject)
        return

    def __onSwitchView(self, _):
        with self.viewModel.transaction() as tx:
            self.__updateActiveState(tx)
        if not self.viewModel.getIsVisible():
            self.__tryToDestroyWidgetTooltip()

    def __tryToDestroyWidgetTooltip(self):
        tooltipIDs = (R.views.lobby.new_year.tooltips.NyMainWidgetTooltip(),
                      R.views.lobby.new_year.tooltips.NyTotalBonusTooltip())
        for tooltipID in tooltipIDs:
            tooltipView = self.__gui.windowsManager.getViewByLayoutID(
                tooltipID)
            if tooltipView:
                tooltipView.destroyWindow()

    def __onLevelChanged(self):
        self.__soundRTPCController.setLevelAtmosphere(
            self._itemsCache.items.festivity.getMaxLevel())