def __onViewShowed(self): if self._isMemoryRiskySystem: g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY) self._isCanClose = True return g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.NEED_STOP_ENTRY_VIDEO), EVENT_BUS_SCOPE.LOBBY)
def __openBox(self): result = yield LootBoxOpenProcessor(self.__boxItem).request() if not result: _logger.error('Failed to open lootbox. Missing result.') self.viewModel.setHardReset(True) return else: if result.userMsg: SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType) if not result.success: _logger.error('Failed to open lootbox. Failed result.') self.viewModel.setHardReset(True) return rewards = first(result.auxData['bonus']) if rewards is None: _logger.error('Failed to open lootbox. Missing rewards.') self.viewModel.setHardReset(True) return self.__rewards = rewards self.__isGuaranteedReward = 'usedLimits' in result.auxData['extData'] self.__giftsInfo = result.auxData['giftsInfo'] self.__updateBoxInfo() self.__updateRewards() g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_OPEN_LOOTBOX, ctx={'boxItem': self.__boxItem, 'specialRewardType': self.viewModel.getSpecialRewardType(), 'withReload': True, 'isForcedToEnd': False}), EVENT_BUS_SCOPE.LOBBY) return
def _initialize(self, *args, **kwargs): super(LootBoxRewardView, self)._initialize() self.catchGiftEventHub() self.viewModel.onCloseBtnClick += self.__onWindowClose self.viewModel.onNextBtnClick += self.__onOpenNextBox self.viewModel.onVideoChangeClick += self.__onVideoSettingsChanged self.viewModel.onDestroyEvent += self.__onDestroy self.viewModel.showSpecialReward += self.__showSpecialReward self.viewModel.onBuyBoxBtnClick += self.__onBuyBoxBtnClick self.viewModel.onSpecialActionBtnClick += self.__onSpecialActionButtonClick self.viewModel.guaranteedReward.onInfoClick += self.__onGuaranteedRewardsInfo self.festivityController.onStateChanged += self.__onStateChange self.itemsCache.onSyncCompleted += self.__onCacheResync self.settingsCore.onSettingsChanged += self.__onSettingsChanged self.lobbyContext.getServerSettings().onServerSettingsChange += self.__onServerSettingChanged if not self._isMemoryRiskySystem: g_eventBus.addListener(LootboxesEvent.ON_SHOW_SPECIAL_REWARDS_CLOSED, self.__onSpecialRewardsClosed, scope=EVENT_BUS_SCOPE.LOBBY) if self._isMemoryRiskySystem: g_eventBus.addListener(LootboxesEvent.ON_VIDEO_OFF_MOVIE_LOADED, self.__onVideoOffMovieLoaded, scope=EVENT_BUS_SCOPE.LOBBY) g_eventBus.addListener(LootboxesEvent.ON_OPENING_START, self.__onOpeningStart, scope=EVENT_BUS_SCOPE.LOBBY) g_eventBus.addListener(LootboxesEvent.NEED_SHOW_REWARDS, self.__needShowRewards, scope=EVENT_BUS_SCOPE.LOBBY) g_eventBus.addListener(events.LootboxesEvent.ON_STATISTICS_RESET, self.__onStatisticsReset, scope=EVENT_BUS_SCOPE.LOBBY) self.__updateAvailability() self.__updateBoxInfo() self.__updateRewards() g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_OPEN_LOOTBOX, ctx={'boxItem': self.__boxItem, 'specialRewardType': self.viewModel.getSpecialRewardType(), 'withReload': False, 'isForcedToEnd': self.__isBackward}), EVENT_BUS_SCOPE.LOBBY) with self.viewModel.transaction() as model: model.setIsForcedRendering(self.__isBackward) model.setIsVideoOff(self.isVideoOff) model.setIsMemoryRiskySystem(self._isMemoryRiskySystem) model.setRealm(CURRENT_REALM)
def _initialize(self, *args, **kwargs): super(LootBoxSpecialRewardView, self)._initialize() if args: specialRewardData = args[0] self.__congratsSourceId = specialRewardData.congratsSourceId self.__backToSingleOpening = specialRewardData.backToSingleOpening Windowing.addWindowAccessibilitynHandler( self.__onWindowAccessibilityChanged) self.viewModel.onContinueBtnClick += self.__onContinue self.viewModel.onGoToRewardBtnClick += self.__onGoToReward self.viewModel.onCloseBtnClick += self.__onContinue self.viewModel.onVideoStarted += self.__onVideoStarted self.viewModel.onVideoStopped += self.__onVideoStopped self.viewModel.onVideoInterrupted += self.__onVideoInterrupted with self.viewModel.transaction() as model: model.setVideoSource(specialRewardData.sourceName) model.setCongratsType(specialRewardData.congratsType) model.setVehicleLvl(specialRewardData.vehicleLvl) model.setVehicleName(specialRewardData.vehicleName) model.setVehicleType(specialRewardData.vehicleType) model.setVehicleIsElite(specialRewardData.vehicleIsElite) model.setStreamBufferLength(_VIDEO_BUFFER_TIME) model.setIsViewAccessible(Windowing.isWindowAccessible()) model.setIsGuaranteedReward( specialRewardData.isGuaranteedReward) model.setRealm(CURRENT_REALM) else: _logger.error('__specialRewardData is not specified!') self.__onContinue() if self._isMemoryRiskySystem and self.__backToSingleOpening: g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY) self._isCanClose = True self.setHoldSwfs(True)
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
def __stopVideo(self): if self.__isDeliveryVideoPlaying: g_eventBus.handleEvent(events.LootboxesEvent( events.LootboxesEvent.NEED_DELIVERY_VIDEO_STOP), scope=EVENT_BUS_SCOPE.LOBBY) self.__isDeliveryVideoPlaying = False return True return False
def __onVideoOffViewReady(self): if not self._isMemoryRiskySystem: return self.viewModel.onVideoOffViewReady -= self.__onVideoOffViewReady g_eventBus.handleEvent( events.LootboxesEvent( events.LootboxesEvent.ON_VIDEO_OFF_MOVIE_LOADED), EVENT_BUS_SCOPE.LOBBY)
def _initialize(self, *args, **kwargs): super(NyLootBoxMainView, self)._initialize() g_messengerEvents.onLockPopUpMessages(key=self.__class__.__name__, lockHigh=True, clear=True) if self._isMemoryRiskySystem: g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY)
def __onWindowClose(self): if self.__isWaitingToHide: return if not self.__stopVideo(): g_eventBus.handleEvent(events.LootboxesEvent( events.LootboxesEvent.ON_MAIN_VIEW_CLOSED), scope=EVENT_BUS_SCOPE.LOBBY) self.__flowlogger.logCloseClick( currentObject=NewYearNavigation.getCurrentObject(), currentView=NewYearNavigation.getCurrentViewName()) self.destroyWindow()
def _onHideCompleteCallback(self, _=None): g_eventBus.removeListener(events.LootboxesEvent.HIDE_COMPLETE, self._onHideCompleteCallback, scope=EVENT_BUS_SCOPE.LOBBY) if self._hideCompleteCallback is not None: try: self._hideCompleteCallback() except Exception: g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY) raise self._hideCompleteCallback = None return
def __onOpeningStart(self): if self.__boxItem is None: _logger.error( 'Failed to handle lootbox opening video start. Missing lootbox item.' ) return else: self.__playOpeningSound() g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.ON_OPENING_START), EVENT_BUS_SCOPE.LOBBY) return
def __updateLootBoxesDeliveryVideo(self, isAfterRewardView=False): if self.__isDeliveryVideoPlaying: return else: boxCategory = self.__tabsController.getSelectedBoxCategory() if boxCategory is not None and LootBoxNotification.hasDeliveredBox( boxCategory): if not isAfterRewardView: self.__isDeliveryVideoPlaying = True g_eventBus.handleEvent(events.LootboxesEvent( events.LootboxesEvent.NEED_DELIVERY_VIDEO_START), scope=EVENT_BUS_SCOPE.LOBBY) self.__updateLootBoxesDeliveryVideoViewed() with self.viewModel.transaction() as model: model.setIsViewHidden(True) return
def _initialize(self): super(LootBoxMultiOpenView, self)._initialize() self.viewModel.onCloseBtnClick += self.__onWindowClose self.viewModel.onOpenBox += self.__onOpenBox self.itemsCache.onSyncCompleted += self.__onCacheResync self._festivityController.onStateChanged += self.__onStateChange self.lobbyContext.getServerSettings( ).onServerSettingsChange += self.__onServerSettingChanged self.viewModel.setLimitToOpen(self.__countToOpen) self.__updateBoxesAvailability() self.__update() self.__setRewards() self.__validateOpening() if self._isMemoryRiskySystem: g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY) self._isCanClose = True
def _onLoaded(self, *_, **__): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_ENTRY_VIEW_LOADED), EVENT_BUS_SCOPE.LOBBY)
def __onOpeningEnd(self): self.viewModel.setIsOpening(False) self.__videoStartStopHandler.onVideoDone() g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.ON_OPENING_END), EVENT_BUS_SCOPE.LOBBY)
def __onBoxTransitionEnd(self): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_BOX_TRANSITION_END), EVENT_BUS_SCOPE.LOBBY)
def __onDeliveryShowControls(self): self.viewModel.setIsDeliveryVideoPlaying(False) g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_DELIVERY_VIDEO_END), EVENT_BUS_SCOPE.LOBBY)
def __sendSwitchBoxHoveredEvent(self, isBoxHovered): g_eventBus.handleEvent(events.LootboxesEvent( eventType=events.LootboxesEvent.SWITCH_BOX_HOVER, ctx={'isBoxHovered': isBoxHovered}), scope=EVENT_BUS_SCOPE.LOBBY)
def __onVideoLoadError(self): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_VIDEO_LOAD_ERROR), EVENT_BUS_SCOPE.LOBBY)
def __onResetClick(self): result = yield ResetLootboxStatisticsProcessor(self.__lootboxID).request() if result.userMsg: SystemMessages.pushI18nMessage(result.userMsg, type=result.sysMsgType, priority=NotificationPriorityLevel.MEDIUM) g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_STATISTICS_RESET, {'serverError': not result.success and bool(result.userMsg)}), EVENT_BUS_SCOPE.LOBBY)
def __onAnimationSwitch(self, _=None): g_eventBus.handleEvent(events.LootboxesEvent( events.LootboxesEvent.NEED_DELIVERY_VIDEO_STOP), scope=EVENT_BUS_SCOPE.LOBBY) self.settingsCore.applySetting(NewYearStorageKeys.LOOT_BOX_VIDEO_OFF, not self.__isVideoOff)
def fireHideRewardView(): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_REWARD_VIEW_CLOSED), EVENT_BUS_SCOPE.LOBBY)
def fireHideMultiOpenView(): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_MULTI_OPEN_VIEW_CLOSED), EVENT_BUS_SCOPE.LOBBY)
def fireSpecialRewardsClosed(): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.ON_SHOW_SPECIAL_REWARDS_CLOSED), EVENT_BUS_SCOPE.LOBBY)
def __sendRemoveHideView(self): g_eventBus.handleEvent(events.LootboxesEvent(events.LootboxesEvent.REMOVE_HIDE_VIEW), EVENT_BUS_SCOPE.LOBBY) self._setIsCanClose(True)
def __onNeedShowRewards(self): self.__videoStartStopHandler.onVideoDone() g_eventBus.handleEvent( events.LootboxesEvent(events.LootboxesEvent.NEED_SHOW_REWARDS), EVENT_BUS_SCOPE.LOBBY)