rewardEntry.py (14858B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\careerPortal\rewards\rewardEntry.py 2 import eveicon 3 import evetypes 4 import math 5 from carbonui import Align, ButtonStyle, PickState, TextAlign, TextColor, uiconst 6 from carbonui.control.button import Button 7 from carbonui.control.scrollContainer import ScrollContainer 8 from carbonui.control.section import SubSection 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.containerAutoSize import ContainerAutoSize 11 from carbonui.primitives.fill import Fill 12 from carbonui.primitives.frame import Frame 13 from carbonui.primitives.gradientSprite import GradientSprite 14 from carbonui.primitives.sprite import Sprite 15 from carbonui.uianimations import animations 16 from carbonui.util.color import Color 17 from carbonui.util.various_unsorted import GetWindowAbove 18 from careergoals.client.career_goal_svc import get_career_goals_svc 19 from careergoals.client.const import RewardLabel, RewardType 20 from careergoals.client.goal import Goal 21 from careergoals.client.signal import on_reward_claimed, on_reward_claimed_failed, on_definitions_loaded 22 from characterdata import careerpath 23 from eve.client.script.ui import eveColor 24 from eve.client.script.ui.control.eveLabel import EveLabelMedium 25 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 26 from eve.client.script.ui.control.themeColored import LabelThemeColored 27 from eve.client.script.ui.shared.careerPortal import careerConst 28 from eve.client.script.ui.shared.careerPortal.rewards.rewardsTooltip import RewardBundleTooltip 29 from eve.client.script.ui.shared.careerPortal.util import get_texture_path_for_reward, get_text_for_reward 30 from eve.client.script.ui.shared.cloneGrade import open_omega_upgrade_window 31 from eve.common.lib import appConst 32 from eve.common.lib.vgsConst import CATEGORYTAG_GAMETIME 33 from eveexceptions import ExceptionEater 34 from localization import GetByLabel, GetByMessageID 35 from omega.client.clone_grade_svc import get_clone_grade_svc 36 REWARD_ENTRY_HEIGHT = 105 37 BOTTOM_CONT_HEIGHT = 25 38 BOTTOM_FRAME_CORNER_SIZE = 9 39 GRADUATION_REWARD_CORNER_SIZE = 14 40 41 class RewardEntry(SubSection): 42 default_name = 'RewardEntry' 43 default_height = REWARD_ENTRY_HEIGHT 44 default_state = uiconst.UI_NORMAL 45 default_align = uiconst.TOTOP 46 default_stroked = False 47 default_inside_padding = 0 48 default_opacity = 0 49 50 def UpdateAlignment(self, budgetLeft = 0, budgetTop = 0, budgetWidth = 0, budgetHeight = 0, updateChildrenOnly = False): 51 budgetLeft, budgetTop, budgetWidth, budgetHeight, sizeChange = super(RewardEntry, self).UpdateAlignment(budgetLeft, budgetTop, budgetWidth, budgetHeight, updateChildrenOnly) 52 self._UpdateTextContainerOpacity() 53 return (budgetLeft, 54 budgetTop, 55 budgetWidth, 56 budgetHeight, 57 sizeChange) 58 59 def _UpdateTextContainerOpacity(self): 60 if self.textContainer.displayWidth < 40: 61 self.textContainer.opacity = 0 62 else: 63 self.textContainer.opacity = 1 64 65 def ApplyAttributes(self, attributes): 66 self.goal = attributes.goal 67 self.reward_label = attributes.reward_label 68 super(RewardEntry, self).ApplyAttributes(attributes) 69 self.ConstructLayout() 70 self.LoadGoal() 71 on_reward_claimed.connect(self.OnRewardClaimed) 72 on_reward_claimed_failed.connect(self.OnRewardClaimedFailed) 73 on_definitions_loaded.connect(self.LoadGoal) 74 wnd = GetWindowAbove(self) 75 if wnd: 76 wnd.on_end_scale.connect(self.OnWindowEndScale) 77 self.AnimEntry() 78 79 def OnWindowEndScale(self, wnd): 80 self._UpdateTextContainerOpacity() 81 82 def AnimEntry(self): 83 order = self.GetOrder() 84 timeOffset = order * 0.2 if order else 0 85 animations.FadeIn(self, duration=0.25, timeOffset=timeOffset / 2) 86 if self.reward_label not in self.goal.get_unclaimed_reward_labels(): 87 self.SetClaimedState() 88 89 def Close(self): 90 with ExceptionEater('disconnectSignals'): 91 on_reward_claimed.disconnect(self.OnRewardClaimed) 92 on_reward_claimed_failed.disconnect(self.OnRewardClaimedFailed) 93 on_definitions_loaded.disconnect(self.LoadGoal) 94 super(RewardEntry, self).Close() 95 96 def _ConstructConts(self): 97 self.topCont = Container(name='topCont', parent=self, align=uiconst.TOTOP, height=self.height - BOTTOM_CONT_HEIGHT) 98 self.topUiCont = Container(name='topUiCont', parent=self.topCont, align=uiconst.TOALL, left=8) 99 self.bottomCont = Container(name='bottomCont', parent=self) 100 101 def _ConstructFrame(self): 102 self._ConstructConts() 103 self.construct_bottom_frame() 104 self.topFillContainer = Container(name='topFillContainer', parent=self.topCont) 105 self.construct_top_fill() 106 107 def construct_bottom_frame(self): 108 self.bottomCont.Flush() 109 self.bottomFrame = Frame(bgParent=self.bottomCont, name='bottomFrame', texturePath='res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png', cornerSize=BOTTOM_FRAME_CORNER_SIZE, color=self.bottom_frame_color, opacity=self.bottom_frame_opacity) 110 EveLabelMedium(parent=self.bottomCont, name='goalName', align=uiconst.CENTERLEFT, text=self.goal.definition.name, color=TextColor.SECONDARY, left=8) 111 112 def construct_top_fill(self): 113 self.topFill = Fill(bgParent=self.topFillContainer, name='topFill', color=self.top_fill_color, opacity=self.top_fill_opacity) 114 115 def ConstructLayout(self): 116 self.loadingWheel = LoadingWheel(parent=self, name='loadingWheel', align=uiconst.CENTER) 117 self.loadingFill = Fill(parent=self, name='loadingFill', color=Color.GRAY1, opacity=0.75) 118 self.rewardIconCont = Container(parent=self.topUiCont, name='iconCont', align=uiconst.TOLEFT, width=64) 119 self.rewardIcon = Sprite(parent=self.rewardIconCont, name='rewardIcon', align=uiconst.CENTER, state=uiconst.UI_NORMAL, pos=(0, 0, 48, 48)) 120 button_container = ContainerAutoSize(name='button_container', parent=self.topUiCont, align=Align.TORIGHT, left=16) 121 self.claimBtn = Button(parent=button_container, name='claimBtn', label=GetByLabel('UI/CareerPortal/ClaimReward'), align=Align.TOPRIGHT, func=self.ClickClaim, style=self.claim_button_style, top=16) 122 self.textContainer = ScrollContainer(parent=self.topUiCont, name='textCont', align=uiconst.TOALL, padding=(8, 16, 0, 8)) 123 self.nameLabel = EveLabelMedium(parent=self.textContainer, name='nameLabel', align=uiconst.TOTOP, textAlign=TextAlign.LEFT, color=self.name_label_color, autoFadeSides=True, bold=True) 124 self.amountInBundleLabel = LabelThemeColored(parent=self.textContainer, name='amountInBundleLabel', align=uiconst.TOTOP, textAlign=TextAlign.LEFT, top=4) 125 126 def update(self): 127 pass 128 129 def LoadGoal(self): 130 if not self.goal or not self.reward_label: 131 return 132 rewards = [ x for x in self.goal.get_unclaimed_rewards() if x.reward_label == self.reward_label ] 133 if len(rewards) == 1: 134 reward = rewards[0] 135 self.rewardIcon.texturePath = get_texture_path_for_reward(reward) 136 self.rewardIcon.OnClick = self.on_reward_icon_click 137 self.nameLabel.text = get_text_for_reward(reward) 138 else: 139 self.rewardIcon.tooltipPanelClassInfo = RewardBundleTooltip(goal=self.goal) 140 self.rewardIcon.texturePath = careerConst.CRATE_64_SIZES.get(self.goal.definition.career, '') 141 self.rewardIcon.OnClick = None 142 self.nameLabel.text = self.GetBundleRewardName() 143 self.amountInBundleLabel.text = GetByLabel('UI/CareerPortal/ItemsInRewardBundle', quantity=len(rewards)) 144 self.update() 145 self.loadingFill.Hide() 146 self.loadingWheel.Hide() 147 148 def GetName(self, typeID): 149 if typeID == appConst.typeKredits: 150 return GetByLabel('UI/Common/ISK') 151 else: 152 return evetypes.GetName(typeID) 153 154 def GetBundleRewardName(self): 155 return GetByLabel('UI/CareerPortal/RewardBundle') 156 157 def GetPathLabelText(self): 158 return self.goal.definition.career_points_text 159 160 def SetLoadingState(self): 161 self.claimBtn.Disable() 162 self.loadingFill.Show() 163 self.loadingWheel.Show() 164 165 def SetNormalState(self): 166 self.claimBtn.Enable() 167 self.loadingFill.Hide() 168 self.loadingWheel.Hide() 169 170 def SetClaimedState(self): 171 self.loadingFill.Show() 172 self.loadingWheel.Hide() 173 self.claimBtn.SetLabel(GetByLabel('UI/CareerPortal/RewardClaimed')) 174 self.claimBtn.Disable() 175 self.SetHint(GetByLabel('UI/CareerPortal/CheckRedeemingQueue')) 176 177 def ClickClaim(self, *args): 178 if self.reward_label not in self.goal.get_unclaimed_reward_labels() or not self.claimBtn.IsEnabled(): 179 return 180 self.SetLoadingState() 181 get_career_goals_svc().claim_reward(self.goal.goal_id, self.reward_label) 182 183 def OnRewardClaimed(self, goal_id, reward_label): 184 if goal_id != self.goal.goal_id or self.reward_label != reward_label: 185 return 186 self.SetClaimedState() 187 188 def OnRewardClaimedFailed(self, goal_id, reward_label): 189 if goal_id != self.goal.goal_id or self.reward_label != reward_label: 190 return 191 self.SetNormalState() 192 193 def OnTimeout(self): 194 self.SetNormalState() 195 196 def on_reward_icon_click(self, *args): 197 if len(self.rewards) == 1: 198 if self.rewards[0].reward_type == RewardType.TYPE_ID: 199 sm.GetService('info').ShowInfo(self.rewards[0].type_id) 200 201 @property 202 def top_fill_color(self): 203 return eveColor.WHITE 204 205 @property 206 def top_fill_opacity(self): 207 return 0.05 208 209 @property 210 def bottom_frame_color(self): 211 return eveColor.WHITE 212 213 @property 214 def bottom_frame_opacity(self): 215 return 0.1 216 217 @property 218 def name_label_color(self): 219 return TextColor.NORMAL 220 221 @property 222 def claim_button_style(self): 223 return ButtonStyle.NORMAL 224 225 @property 226 def rewards(self): 227 return [ x for x in self.goal.get_unclaimed_rewards() if x.reward_label == self.reward_label ] 228 229 230 class GraduationRewardEntry(RewardEntry): 231 default_name = 'GraduationRewardEntry' 232 233 def __init__(self, *args, **kwargs): 234 self.career_color = careerConst.COLOR_BY_CAREER_ID.get(kwargs.get('goal').definition.career) 235 super(GraduationRewardEntry, self).__init__(*args, **kwargs) 236 237 def GetBundleRewardName(self): 238 return GetByLabel('UI/CareerPortal/GraduationReward') 239 240 def GetPathLabelText(self): 241 careerInfo = careerpath.get_career_path(self.goal.definition.career) 242 return GetByMessageID(careerInfo.nameID) 243 244 @property 245 def top_fill_color(self): 246 return self.career_color 247 248 @property 249 def top_fill_opacity(self): 250 return 0.1 251 252 @property 253 def bottom_frame_color(self): 254 return self.career_color 255 256 @property 257 def bottom_frame_opacity(self): 258 return 0.15 259 260 261 class OmegaRewardEntry(RewardEntry): 262 __notifyevents__ = ['OnSubscriptionChanged'] 263 264 def __init__(self, *args, **kwargs): 265 super(OmegaRewardEntry, self).__init__(*args, **kwargs) 266 sm.RegisterNotify(self) 267 268 def Close(self): 269 try: 270 sm.UnregisterNotify(self) 271 finally: 272 super(OmegaRewardEntry, self).Close() 273 274 def ConstructLayout(self): 275 super(OmegaRewardEntry, self).ConstructLayout() 276 self.construct_omega_icon() 277 278 def construct_omega_icon(self): 279 Sprite(name='omega_icon', parent=self.rewardIconCont, align=Align.CENTER, pickState=PickState.OFF, texturePath=eveicon.omega, pos=(16, 16, 16, 16), idx=0) 280 281 def construct_top_fill(self): 282 self.topFillContainer.Flush() 283 GradientSprite(name='topFill', bgParent=self.topCont, rgbData=((0.0, eveColor.BLACK[:3]), (1.0, self.top_fill_color[:3])), alphaData=((0.0, 0.0), (self.top_fill_opacity, self.top_fill_opacity)), rotation=math.pi * 0.5) 284 285 def construct_bottom_frame(self): 286 super(OmegaRewardEntry, self).construct_bottom_frame() 287 if self.has_omega: 288 return 289 text = GetByLabel('UI/CareerPortal/Locked') 290 text_width, _ = EveLabelMedium.MeasureTextSize(text) 291 label_container = Container(parent=self.bottomCont, align=Align.TORIGHT, width=text_width, height=BOTTOM_CONT_HEIGHT, left=16) 292 EveLabelMedium(name='locked_label', parent=label_container, align=Align.CENTER, text=text, color=eveColor.OMEGA_YELLOW) 293 icon_container = Container(parent=self.bottomCont, align=Align.TORIGHT, height=BOTTOM_CONT_HEIGHT, width=16, padRight=8) 294 Sprite(name='locked_icon', parent=icon_container, align=Align.CENTER, texturePath=eveicon.locked, color=eveColor.OMEGA_YELLOW, pos=(0, 0, 16, 16)) 295 296 def update(self): 297 self.construct_top_fill() 298 self.construct_bottom_frame() 299 if self.has_omega: 300 self.textContainer.mainCont.opacity = 1.0 301 self.rewardIconCont.opacity = 1.0 302 self.claimBtn.label = GetByLabel('UI/CareerPortal/ClaimReward') 303 self.claimBtn.texturePath = None 304 self.claimBtn.func = self.ClickClaim 305 else: 306 self.textContainer.mainCont.opacity = 0.5 307 self.rewardIconCont.opacity = 0.5 308 self.claimBtn.label = GetByLabel('UI/CareerPortal/UpgradeToClaim') 309 self.claimBtn.texturePath = eveicon.omega 310 self.claimBtn.func = self._click_upgrade_to_omega 311 312 def ClickClaim(self, *args): 313 if self.has_omega: 314 super(OmegaRewardEntry, self).ClickClaim(*args) 315 316 def _click_upgrade_to_omega(self, *args): 317 open_omega_upgrade_window() 318 319 def OnSubscriptionChanged(self): 320 self.update() 321 322 @property 323 def top_fill_color(self): 324 return eveColor.OMEGA_YELLOW 325 326 @property 327 def top_fill_opacity(self): 328 return 0.025 329 330 @property 331 def bottom_frame_color(self): 332 return eveColor.OMEGA_YELLOW 333 334 @property 335 def name_label_color(self): 336 return eveColor.OMEGA_YELLOW 337 338 @property 339 def claim_button_style(self): 340 return ButtonStyle.MONETIZATION 341 342 @property 343 def has_omega(self): 344 return get_clone_grade_svc().is_omega_with_grace_period() 345 346 347 class OmegaGraduationRewardEntry(OmegaRewardEntry): 348 default_name = 'OmegaGraduationRewardEntry' 349 350 def GetBundleRewardName(self): 351 return GetByLabel('UI/CareerPortal/GraduationReward') 352 353 def GetPathLabelText(self): 354 careerInfo = careerpath.get_career_path(self.goal.definition.career) 355 return GetByMessageID(careerInfo.nameID) 356 357 @property 358 def top_fill_opacity(self): 359 return 0.1 360 361 @property 362 def bottom_frame_opacity(self): 363 return 0.15