vgsUiController.py (6779B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\view\aurumstore\vgsUiController.py 2 import logging 3 import blue 4 import carbonui.const as uiconst 5 from carbon.client.script.environment.AudioUtil import PlaySound 6 from carbonui.uicore import uicore 7 from eve.client.script.ui.util.uiComponents import RunThreadOnce 8 from eve.client.script.ui.view.aurumstore.nesFastCheckoutContainer import NesFastCheckoutContainer 9 from eve.client.script.ui.view.aurumstore.vgsDetailContainer import VgsDetailContainer 10 from eve.client.script.ui.view.viewStateConst import ViewState 11 from fastcheckout.const import FROM_NES_HEADER 12 from plex.client.api.repository import get_repository 13 logger = logging.getLogger(__name__) 14 OPEN_OFFER_THREAD_KEY = 'OPEN_OFFER' 15 CLOSE_OFFER_THREAD_KEY = 'CLOSE_OFFER' 16 OPEN_AURUM_STORE_THREAD_KEY = 'OPEN_AURUM_STORE' 17 MINIMUM_PROGRESS_DISPLAY_TIME = 1.2 * const.SEC 18 OFFER_ADDED_TO_REDEEMING_QUEUE_TIME = 0.75 19 REDEEMING_BUTTON_SHOW_TIME = 2 20 21 class VgsUiController(object): 22 23 def __init__(self, vgsService, viewStateService): 24 self.viewState = viewStateService 25 self.vgsService = vgsService 26 self.fastCheckoutClientService = sm.GetService('fastCheckoutClientService') 27 self.view = self.viewState.GetView(ViewState.VirtualGoodsStore) 28 self.detailContainer = None 29 self.buyIsInProgress = False 30 self.nesFastCheckoutStoreView = None 31 self.isInFastCheckoutWindow = False 32 self.featuredOffers = [] 33 34 @RunThreadOnce(OPEN_OFFER_THREAD_KEY) 35 def ShowOffer(self, offerId, categoryId = None): 36 if self.buyIsInProgress: 37 return 38 self._ShowOffer(offerId, uicore.layer.vgsabovesuppress) 39 if self.viewState.IsViewActive(ViewState.VirtualGoodsStore): 40 self.view.ShowCategory(categoryId) 41 else: 42 self.viewState.ActivateView(ViewState.VirtualGoodsStore, categoryId=categoryId) 43 44 def ShowOfferInWindow(self, offerId): 45 self._ShowOffer(offerId, uicore.layer.abovemain) 46 self.view.ActivateSuppressLayer(duration=0.3, clickCallback=self.CloseOffer) 47 48 def _ShowOffer(self, offerId, parent): 49 self.CheckCloseOffer() 50 offer = self.vgsService.GetStore().GetOffer(offerId) 51 PlaySound('store_click') 52 self.detailContainer = VgsDetailContainer(parent=parent, align=uiconst.TOALL, opacity=0.0, vgsUiController=self, offer=offer, plexBalance=get_repository().get_balance()) 53 self.view._LogOpenOffer(offerId) 54 uicore.animations.FadeTo(self.detailContainer, 0.0, 1.0, duration=0.3, sleep=True) 55 return offer 56 57 @RunThreadOnce(OPEN_AURUM_STORE_THREAD_KEY) 58 def OpenFastCheckoutWindow(self): 59 self.Close() 60 self.nesFastCheckoutStoreView = NesFastCheckoutContainer(parent=uicore.layer.vgsabovesuppress, logContext=FROM_NES_HEADER) 61 self.view.ActivateSuppressLayer(duration=0.5, clickCallback=self.fastCheckoutClientService.close_fast_checkout_nes, callback=self.SetFastCheckoutWindowActive()) 62 63 def CloseFastCheckoutWindow(self): 64 self.SetFastCheckoutWindowInactive() 65 if self.nesFastCheckoutStoreView is not None: 66 self.nesFastCheckoutStoreView.Close() 67 self.nesFastCheckoutStoreView = None 68 self.view.DeactivateSuppressLayer(duration=0.25) 69 self.fastCheckoutClientService.close_fast_checkout_popup() 70 71 def Close(self): 72 self.CheckCloseOffer() 73 self.CloseFastCheckoutWindow() 74 75 def CanClose(self): 76 return self.detailContainer is not None and not self.detailContainer.destroyed and not self.buyIsInProgress 77 78 def CheckCloseOffer(self): 79 if not self.CanClose(): 80 return 81 logger.debug('Force closing offer') 82 self.view.storeContainer.redeemingPanel.SetListenToRedeemQueueUpdatedEvents(True) 83 self.view.storeContainer.redeemingPanel.UpdateDisplay(animate=False) 84 self.detailContainer.fakeRedeemingPanel.CollapsePanel(animate=False) 85 self.detailContainer.Close() 86 self.view.DeactivateSuppressLayer(duration=0.0) 87 88 @RunThreadOnce(CLOSE_OFFER_THREAD_KEY) 89 def CloseOffer(self): 90 if not self.CanClose(): 91 return 92 closeDuration = 0.25 93 self.view.storeContainer.redeemingPanel.SetListenToRedeemQueueUpdatedEvents(True) 94 self.view.storeContainer.redeemingPanel.UpdateDisplay(animate=False) 95 self.detailContainer.fakeRedeemingPanel.CollapsePanel(duration=closeDuration) 96 self.detailContainer.PrepareClose() 97 uicore.animations.FadeOut(self.detailContainer.offerContainer, duration=closeDuration) 98 self.view.DeactivateSuppressLayer(duration=closeDuration, callback=self.detailContainer.Close) 99 100 def SetFastCheckoutWindowActive(self): 101 self.isInFastCheckoutWindow = True 102 103 def SetFastCheckoutWindowInactive(self): 104 self.isInFastCheckoutWindow = False 105 106 def IsFastCheckoutWindowActive(self): 107 return self.isInFastCheckoutWindow 108 109 def _LogPurchase(self, offer, quantity, success, toCharacterID): 110 isGametime = self.vgsService.store.IsGametimeOffer(offer) 111 if toCharacterID: 112 self.view._LogPurchaseGift(offer.id, quantity, success, toCharacterID, isGametime=isGametime) 113 else: 114 self.view._LogPurchase(offer.id, quantity, success) 115 116 def BuyOffer(self, offer, currency, quantity = 1, toCharacterID = None, message = None): 117 self.vgsService.LogInfo('VgsUiController.BuyOffer', offer, quantity) 118 self.buyIsInProgress = True 119 try: 120 self.detailContainer.SwitchToProgressPanel() 121 startTime = blue.os.GetWallclockTime() 122 result = None 123 try: 124 result = self.vgsService.GetStore().BuyOffer(offer, currency=currency, qty=quantity, toCharacterID=toCharacterID, message=message) 125 blue.pyos.synchro.SleepUntilWallclock(startTime + MINIMUM_PROGRESS_DISPLAY_TIME) 126 finally: 127 success = bool(result) 128 self._LogPurchase(offer, quantity, success, toCharacterID) 129 if success: 130 self.detailContainer.SwitchToSuccessPanel(quantity, toCharacterID) 131 else: 132 self.detailContainer.SwitchToFailurePanel() 133 134 finally: 135 self.buyIsInProgress = False 136 self.view.storeContainer.OnOfferPurchase(offer.id) 137 138 def SetFeaturedOffers(self, offerIDs = None): 139 if self.featuredOffers == offerIDs: 140 return 141 self.featuredOffers = offerIDs or [] 142 try: 143 self.view.storeContainer.SetFeaturedOffers(offerIDs) 144 except AttributeError: 145 pass 146 147 def GetFeaturedOffers(self): 148 return self.featuredOffers