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
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)
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())
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)