expiry.py (3720B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\achievement_system\client\ui\window\card\components\expiry.py 2 import appConst 3 import eveicon 4 import uthread2 5 from carbonui import Align, TextColor, uiconst 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.primitives.sprite import Sprite 9 from carbonui.text.styles import TextBody 10 from localization import GetByLabel 11 from localization.formatters import timeIntervalFormatters 12 ICON_SIZE = 16 13 COUNTDOWN_COLOR = TextColor.WARNING 14 EXPIRED_COLOR = TextColor.DANGER 15 16 class AchievementExpiryTimer(ContainerAutoSize): 17 default_height = 16 18 19 def __init__(self, controller, display_icon = True, use_verbose_text = True, *args, **kwargs): 20 super(AchievementExpiryTimer, self).__init__(*args, **kwargs) 21 self.controller = controller 22 self.display_icon = display_icon 23 self.use_verbose_text = use_verbose_text 24 self.construct_layout() 25 self.update_thread = uthread2.start_tasklet(self.update_async) 26 27 def construct_layout(self): 28 self.construct_icon() 29 self.construct_label() 30 31 def construct_icon(self): 32 if not self.display_icon: 33 return 34 self.icon_container = Container(name='icon_container', parent=self, align=Align.TOLEFT, width=ICON_SIZE) 35 self.icon = Sprite(name='icon', parent=self.icon_container, align=Align.CENTER, state=uiconst.UI_DISABLED, texturePath=eveicon.hourglass, pos=(0, 36 0, 37 ICON_SIZE, 38 ICON_SIZE)) 39 40 def construct_label(self): 41 self.label = TextBody(name='label', parent=self, align=Align.TOLEFT, padding=(4, -1, 0, 0)) 42 43 def update_async(self): 44 while not self.destroyed: 45 self.update_content() 46 if self.controller.is_expired: 47 self.update_thread.kill() 48 uthread2.Sleep(0.5) 49 50 def update_content(self): 51 self.label.text = self.time_remaining_text 52 self.label.color = self.timer_color 53 if self.display_icon: 54 self.icon.color = self.timer_color 55 56 @property 57 def time_remaining_text(self): 58 if self.controller.is_expired: 59 return GetByLabel('UI/Achievements/Window/Card/Expired') 60 seconds = int(self.controller.time_remaining.total_seconds() * appConst.SEC) 61 time_remaining = timeIntervalFormatters.FormatTimeIntervalShortWritten(seconds) 62 if self.use_verbose_text: 63 return GetByLabel(labelNameAndPath='UI/Achievements/Window/Card/TimeRemaining', time_remaining=time_remaining) 64 else: 65 return time_remaining 66 67 @property 68 def timer_color(self): 69 if self.controller.is_expired: 70 return EXPIRED_COLOR 71 return COUNTDOWN_COLOR 72 73 74 class AchievementExpiryTimerIcon(AchievementExpiryTimer): 75 default_state = uiconst.UI_NORMAL 76 77 def construct_layout(self): 78 self.construct_icon() 79 80 def update_content(self): 81 self.icon.color = self.timer_color 82 self.hint = self.time_remaining_text 83 84 def LoadTooltipPanel(self, tooltipPanel, *args): 85 AchievementExpiryTooltip(tooltipPanel=tooltipPanel, controller=self.controller, display_icon=False) 86 87 88 class AchievementExpiryTooltip(object): 89 90 def __init__(self, tooltipPanel, controller, display_icon): 91 self.panel = tooltipPanel 92 self.controller = controller 93 self.Layout(display_icon) 94 95 def Layout(self, display_icon = True): 96 self.panel.Flush() 97 self.panel.LoadGeneric2ColumnTemplate() 98 self.panel.AddCell(AchievementExpiryTimer(controller=self.controller, display_icon=display_icon), colSpan=1)