loginRewardsWnd.py (12370B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\loginRewards\loginRewardsWnd.py 2 import blue 3 import uthread2 4 from carbon.client.script.environment.AudioUtil import PlaySound 5 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER 6 from carbonui import uiconst 7 from carbonui.control.checkbox import Checkbox 8 from carbonui.control.window import Window 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.sprite import Sprite 11 from carbonui.util.color import Color 12 from carbonui.control.button import Button 13 from eve.client.script.ui.control.toggleButtonGroup import ToggleButtonGroup 14 from eve.client.script.ui.shared.loginRewards.evergreenRewardPanel import EvergreenRewardPanel 15 from eve.client.script.ui.shared.loginRewards.rewardToggleButtonGroupButton import RewardToggleButtonGroupButtonHeader 16 from eve.client.script.ui.shared.loginRewards.rewardUiConst import BACKGROUND_HEIGHT, BACKGROUND_WIDTH, BLUE_TEXT_COLOR, BOTTOM_BORDER_HEIGHT, DEFAULT_BANNER, LOGIN_REWARDS_WINDOW_ID, REWARD_EVERGREEN_BTN, REWARD_ROOKIE_BTN, REWARD_SEASONAL_BTN, REWARD_WND_HEIGHT, REWARD_WND_OPEN_ON_LOGIN_SETTING, REWARD_WND_WIDTH, SEASON_BACKGROUND_HEIGHT, SEASON_BACKGROUND_WIDTH, TOP_HEIGHT 17 from eve.client.script.ui.shared.loginRewards.rookieRewardPanel import RookieRewardPanel 18 from eve.client.script.ui.shared.loginRewards.seasonRewardPanel import SeasonRewardPanel 19 from localization import GetByLabel, GetByMessageID 20 from loginrewards.common.fsdloaders import SeasonalCampaignsStaticData 21 from utillib import KeyVal 22 TAB_SELECTED = 'rewardWndTabSelected' 23 24 class DailyLoginRewardsWnd(Window): 25 __notifyevents__ = ['OnUIScalingChange', 'OnSubscriptionChanged_Local'] 26 __guid__ = 'DailyLoginRewardsWnd' 27 default_height = REWARD_WND_HEIGHT 28 default_width = REWARD_WND_WIDTH 29 default_minSize = (default_width, default_height) 30 default_isStackable = False 31 default_isOverlayable = False 32 default_windowID = LOGIN_REWARDS_WINDOW_ID 33 default_captionLabelPath = 'UI/LoginRewards/WindowCaption' 34 default_descriptionLabelPath = 'UI/LoginRewards/WindowDescription' 35 36 def DebugReload(self, *args): 37 self.Close() 38 DailyLoginRewardsWnd.Open() 39 40 def ApplyAttributes(self, attributes): 41 self.triggersModalAdjustment = False 42 super(DailyLoginRewardsWnd, self).ApplyAttributes(attributes) 43 self.MakeUnResizeable() 44 self.LoadWnd() 45 PlaySound('daily_login_atmo_play') 46 47 def LoadWnd(self): 48 if session.role & ROLE_PROGRAMMER: 49 reloadBtn = Button(parent=self.sr.main, label='Reload', align=uiconst.TOPRIGHT, func=self.DebugReload, top=14, idx=0) 50 RewardsContainer(parent=self.sr.main, align=uiconst.CENTER, width=1075, height=656) 51 self.width, self.height = self.GetWindowSizeForContentSize(1075, 656) 52 53 def OnUIScalingChange(self, *args): 54 self.sr.main.Flush() 55 self.LoadWnd() 56 57 def OnSubscriptionChanged_Local(self): 58 self.sr.main.Flush() 59 self.LoadWnd() 60 61 def Close(self, setClosed = False, *args, **kwds): 62 super(DailyLoginRewardsWnd, self).Close(setClosed=setClosed, *args, **kwds) 63 PlaySound('daily_login_atmo_stop') 64 65 66 class RewardsContainer(Container): 67 default_name = 'rewardsContainer' 68 default_clipChildren = True 69 70 def ApplyAttributes(self, attributes): 71 self._adjustingThread = None 72 self.isScrolling = False 73 self.currentFirstVisibleDay = 0 74 Container.ApplyAttributes(self, attributes) 75 self.BuildBottomBorder() 76 innerCont = Container(name='innerCont', parent=self) 77 bgCont = Container(name='bgCont', parent=self, padding=(12, 2, 12, 3), clipChildren=True) 78 topCont = Container(name='topCont', parent=innerCont, align=uiconst.TOTOP, height=TOP_HEIGHT) 79 self.campaignCont = Container(name='campaignCont', parent=innerCont, align=uiconst.TOALL, padTop=10) 80 self.btnGroup = ToggleButtonGroup(parent=topCont, align=uiconst.TOALL, padding=(12, 2, 12, 3), height=0, callback=self.OnMainTabGroup) 81 self.backgroundImage = Sprite(name='backgroundImage', parent=bgCont, align=uiconst.CENTERTOP, pos=(0, 82 0, 83 BACKGROUND_WIDTH, 84 BACKGROUND_HEIGHT), opacity=1.0) 85 loginCampaignService = sm.GetService('loginCampaignService') 86 seasonalLoginCampaignService = sm.GetService('seasonalLoginCampaignService') 87 seasonalCampaignID = seasonalLoginCampaignService.get_active_login_campaign() 88 dailyCampaign = loginCampaignService.get_active_campaign() 89 totalBtnNum = 1 if bool(seasonalCampaignID) else 0 90 if dailyCampaign: 91 totalBtnNum += 1 92 if not totalBtnNum: 93 return 94 groupWidth = REWARD_WND_WIDTH - self.btnGroup.padLeft - self.btnGroup.padRight 95 btnWidth = groupWidth / totalBtnNum 96 midIdx = (totalBtnNum - 1) / 2.0 97 activeBtnID = None 98 currentBtns = [] 99 tabsWithAvailableRewards = [] 100 if dailyCampaign: 101 static_data = dailyCampaign.static_data 102 titleMessageID = static_data.titleMessageID 103 subtitleMessageID = static_data.subtitleMessageID 104 bgNarrow = static_data.windowHeaderBackgroundNarrow 105 bgWide = static_data.windowHeaderBackgroundWide 106 texturePath = None 107 if totalBtnNum == 1: 108 if bgWide: 109 texturePath = bgWide 110 elif bgNarrow: 111 texturePath = bgNarrow 112 texturePath = texturePath or DEFAULT_BANNER 113 textureInfo = KeyVal(texturePath=texturePath, textureWidth=BACKGROUND_WIDTH, textureHeight=BACKGROUND_HEIGHT, textureOpacity=self.backgroundImage.opacity, textureOffset=0, textureAlign=uiconst.TOPLEFT) 114 btn = None 115 tabName = None 116 if static_data.is_rookie_campaign: 117 panel = RookieRewardPanel(parent=self.campaignCont) 118 panel.Hide() 119 btn = self.btnGroup.AddButton(btnID=REWARD_ROOKIE_BTN, label=GetByMessageID(titleMessageID) if titleMessageID else GetByLabel('UI/LoginRewards/RewardHeaderDefault'), subLabel=GetByMessageID(subtitleMessageID) if subtitleMessageID else GetByLabel('UI/LoginRewards/CollectText'), btnClass=RewardToggleButtonGroupButtonHeader, panel=panel, btnIdx=len(currentBtns), totalBtnNum=totalBtnNum, textureInfo=textureInfo, btnWidth=btnWidth) 120 if loginCampaignService.can_claim_now(): 121 tabsWithAvailableRewards.append(REWARD_ROOKIE_BTN) 122 else: 123 panel = EvergreenRewardPanel(parent=self.campaignCont) 124 panel.Hide() 125 btn = self.btnGroup.AddButton(btnID=REWARD_EVERGREEN_BTN, label=GetByMessageID(titleMessageID) if titleMessageID else GetByLabel('UI/LoginRewards/RewardHeaderDefault'), subLabel=GetByMessageID(subtitleMessageID) if subtitleMessageID else GetByLabel('UI/LoginRewards/CollectText'), btnClass=RewardToggleButtonGroupButtonHeader, panel=panel, btnIdx=len(currentBtns), totalBtnNum=totalBtnNum, textureInfo=textureInfo, btnWidth=btnWidth) 126 if loginCampaignService.can_claim_now(): 127 tabsWithAvailableRewards.append(REWARD_EVERGREEN_BTN) 128 if btn: 129 currentBtns.append(btn) 130 if seasonalCampaignID: 131 seasonCampaignData = SeasonalCampaignsStaticData().get_campaign(seasonalCampaignID) 132 titleMessageID = seasonCampaignData.campaignName 133 bgWide = seasonCampaignData.windowHeaderBackground or DEFAULT_BANNER 134 days_remaining = seasonalLoginCampaignService.get_days_remaining() 135 formattingStart = '<color=%s>' % Color.RGBtoHex(*BLUE_TEXT_COLOR) 136 formattingEnd = '</color>' 137 if days_remaining > 1: 138 time_remaining_text = GetByLabel('UI/LoginRewards/DaysRemainingWithFormatting', numDays=days_remaining, formattingStart=formattingStart, formattingEnd=formattingEnd) 139 else: 140 hours = seasonalLoginCampaignService.get_hours_until_next_reward_date() 141 time_remaining_text = GetByLabel('UI/LoginRewards/HoursRemainingWithFormatting', numHours=hours, formattingStart=formattingStart, formattingEnd=formattingEnd) 142 btnIdx = len(currentBtns) 143 textureInfo = KeyVal(texturePath=bgWide, textureWidth=SEASON_BACKGROUND_WIDTH, textureHeight=SEASON_BACKGROUND_HEIGHT, textureOpacity=self.backgroundImage.opacity, textureOffset=int((btnIdx - midIdx) * btnWidth)) 144 panel = SeasonRewardPanel(parent=self.campaignCont) 145 panel.Hide() 146 btn = self.btnGroup.AddButton(btnID=REWARD_SEASONAL_BTN, label=GetByMessageID(titleMessageID) if titleMessageID else GetByLabel('UI/LoginRewards/RewardHeaderDefault'), subLabel=GetByLabel('UI/LoginRewards/CollectText'), topText=time_remaining_text, btnClass=RewardToggleButtonGroupButtonHeader, texturePath=bgWide, panel=panel, btnIdx=btnIdx, totalBtnNum=totalBtnNum, textureInfo=textureInfo, btnWidth=btnWidth) 147 currentBtns.append(btn) 148 if seasonalLoginCampaignService.can_claim_now(): 149 tabsWithAvailableRewards.append(REWARD_SEASONAL_BTN) 150 activeBtnID = REWARD_SEASONAL_BTN 151 defaultBtnID = currentBtns[0].btnID 152 activeBtnID = activeBtnID or settings.user.ui.Get(TAB_SELECTED, defaultBtnID) 153 if tabsWithAvailableRewards and activeBtnID not in tabsWithAvailableRewards: 154 activeBtnID = tabsWithAvailableRewards[0] 155 if activeBtnID not in self.btnGroup.buttonsByID: 156 activeBtnID = defaultBtnID 157 self.btnGroup.SelectByID(activeBtnID) 158 159 def OnMainTabGroup(self, btnID, oldBtnID, *args): 160 settings.user.ui.Set(TAB_SELECTED, btnID) 161 self.btnGroup.SetSelected(btnID) 162 newBtn = self.btnGroup.GetButton(btnID) 163 if not newBtn: 164 return 165 textureInfo = newBtn.textureInfo 166 newBtnIdx = newBtn.btnIdx 167 loginCampaignService = sm.GetService('loginCampaignService') 168 btnsWithAvailableRewards = loginCampaignService.get_rewards_available() 169 for eacButton in self.btnGroup.buttons: 170 eacButton.ChangePositionBasedTextures(newBtnIdx) 171 showAsUnseen = eacButton.btnID in btnsWithAvailableRewards and eacButton.btnID != btnID 172 eacButton.UpdateUnseenCont(showAsUnseen) 173 174 self.AdjustBackgroundImage(newBtn, textureInfo) 175 loginCampaignService.AddSeenSettingValue(btnID) 176 sm.ScatterEvent('OnLoginRewardWindowOpened') 177 178 def AdjustBackgroundImage(self, newBtn, textureInfo): 179 self.backgroundImage.width = textureInfo.textureWidth 180 self.backgroundImage.height = textureInfo.textureHeight 181 self.backgroundImage.texturePath = textureInfo.texturePath 182 self.backgroundImage.SetAlign(getattr(textureInfo, 'textureAlign', uiconst.CENTERTOP)) 183 self.backgroundImage.left = textureInfo.textureOffset 184 if self._adjustingThread: 185 self._adjustingThread.kill() 186 self._adjustingThread = None 187 self._adjustingThread = uthread2.start_tasklet(self._AdjustBgResolution, textureInfo.texturePath, textureInfo.textureWidth, textureInfo.textureHeight) 188 189 def _AdjustBgResolution(self, texturePath, w, h): 190 try: 191 for x in xrange(3): 192 if self.backgroundImage.texturePath != texturePath: 193 return 194 textureWidth = self.backgroundImage.renderObject.texturePrimary.atlasTexture.width 195 textureHeight = self.backgroundImage.renderObject.texturePrimary.atlasTexture.height 196 if textureWidth and textureHeight: 197 if w != textureWidth: 198 self.backgroundImage.width = textureWidth 199 if h != textureHeight: 200 self.backgroundImage.height = textureHeight 201 break 202 blue.synchro.Sleep(100) 203 204 except Exception as e: 205 pass 206 207 def BuildBottomBorder(self): 208 bottomCont = Container(name='bottomCont', parent=self, align=uiconst.TOBOTTOM, height=BOTTOM_BORDER_HEIGHT) 209 Checkbox(parent=bottomCont, align=uiconst.CENTERLEFT, left=20, setting=REWARD_WND_OPEN_ON_LOGIN_SETTING, text=GetByLabel('UI/LoginRewards/ShowOnLogIn'))