shipTreeUnlockContainer.py (11003B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\shipTree\shipTreeUnlockContainer.py 2 import eveicon 3 import trinity 4 from carbon.client.script.environment.AudioUtil import PlaySound 5 from carbonui import uiconst, Align 6 from carbonui.text.styles import TextHeader 7 from carbonui.control.button import Button 8 from carbonui.control.scrollContainer import ScrollContainer 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.containerAutoSize import ContainerAutoSize 11 from carbonui.primitives.frame import Frame 12 from carbonui.primitives.line import Line 13 from carbonui.primitives.sprite import Sprite 14 from clientsettings.setting import CharSettingBool 15 from carbonui.uianimations import animations 16 from characterdata.factions import get_faction_name 17 from eve.client.script.ui import eveThemeColor, eveColor 18 from eve.client.script.ui.control.eveLabel import EveCaptionLarge 19 from eve.client.script.ui.shared.shipTree.shipTreeConst import ICON_BY_FACTIONID 20 from localization import GetByMessageID 21 from shipprogression import shipUnlockSignals 22 from shipprogression.shipUnlockSvc import GetShipUnlockService 23 from eve.common.script.sys.eveCfg import eveConfig 24 import localization 25 UNLOCK_HEADER_PADDING = 24 26 UNLOCK_HEADER_HEIGHT = 30 27 REWARD_ENTRY_PADDING = 8 28 SCROLL_CONTAINER_PADDING = 24 29 30 class ShipTreeUnlockContainer(Container): 31 default_state = uiconst.UI_NORMAL 32 default_name = 'ShipTreeUnlockContainer' 33 default_color = (0, 0, 0, 0.9) 34 35 def ApplyAttributes(self, attributes): 36 super(ShipTreeUnlockContainer, self).ApplyAttributes(attributes) 37 self._callback = attributes.get('callback', None) 38 self._shipUnlockSvc = GetShipUnlockService() 39 self._expanded = False 40 self._ignore_setting = CharSettingBool('ShipProgression_Ignore', False) 41 self._ConstructHeader() 42 self._ConstructMainContainer() 43 self._ConstructFrame() 44 self._ConstructInitialContent() 45 self.RegisterListeners() 46 47 def Close(self): 48 super(ShipTreeUnlockContainer, self).Close() 49 self.UnregisterListeners() 50 51 def RegisterListeners(self): 52 shipUnlockSignals.on_group_unlocked.connect(self._on_group_unlocked) 53 shipUnlockSignals.on_group_unlock_viewed.connect(self._on_group_viewed) 54 shipUnlockSignals.on_unlocks_dismissed.connect(self._on_unlocks_dismissed) 55 56 def UnregisterListeners(self): 57 shipUnlockSignals.on_group_unlocked.disconnect(self._on_group_unlocked) 58 shipUnlockSignals.on_group_unlock_viewed.disconnect(self._on_group_viewed) 59 shipUnlockSignals.on_unlocks_dismissed.disconnect(self._on_unlocks_dismissed) 60 61 def _ConstructLine(self): 62 Line(parent=self, align=uiconst.TOTOP, outputMode=trinity.Tr2SpriteTarget.COLOR_AND_GLOW, color=eveThemeColor.THEME_ACCENT) 63 64 def _ConstructHeader(self): 65 self._ConstructLine() 66 self.headerContainer = Container(name='headerContainer', parent=self, align=uiconst.TOTOP, padding=(UNLOCK_HEADER_PADDING, 67 UNLOCK_HEADER_PADDING, 68 UNLOCK_HEADER_PADDING, 69 UNLOCK_HEADER_PADDING), height=UNLOCK_HEADER_HEIGHT, contentSpacing=(8, 0)) 70 self.titleLabel = EveCaptionLarge(parent=ContainerAutoSize(parent=self.headerContainer, align=uiconst.TOLEFT), name='headerLabel', align=Align.TOLEFT, state=uiconst.UI_DISABLED, text=localization.GetByLabel('UI/ShipTree/NewUnlocks')) 71 self.claimAllBtn = Button(parent=self.headerContainer, label=localization.GetByLabel('UI/ShipTree/DismissAllUnlocks'), align=Align.TORIGHT, func=self._dismiss_all) 72 73 def _ConstructMainContainer(self): 74 self.mainCont = Container(name='mainContainer', parent=self, align=uiconst.TOALL, padding=(SCROLL_CONTAINER_PADDING, 75 0, 76 10, 77 SCROLL_CONTAINER_PADDING)) 78 self.rewardsScroll = ScrollContainer(name='unlockScroll', parent=self.mainCont, align=uiconst.TOALL, padding=(0, 0, 12, 0)) 79 80 def _ConstructInitialContent(self): 81 unlocks = self._shipUnlockSvc.GetUnseenEntries() 82 if len(unlocks) == 0: 83 self.display = False 84 return 85 for entry in unlocks: 86 self._add_unlock_entry(entry) 87 88 self.FadeIn() 89 90 def _add_unlock_entry(self, shipUnlockEntry): 91 ShipTreeUnlockEntry(name='unlock_entry', align=Align.TOTOP, parent=self.rewardsScroll, opacity=0.8, height=58, unlockEntry=shipUnlockEntry, callback=self._callback) 92 93 def _ConstructFrame(self): 94 Frame(bgParent=self, texturePath='res:/UI/Texture/Shared/DarkStyle/panel1Corner_Solid.png', cornerSize=9, color=eveColor.BLACK, opacity=0.9) 95 96 def _on_group_unlocked(self, shipUnlockEntry): 97 if self._ignore_setting.is_enabled(): 98 return 99 self.display = True 100 self._add_unlock_entry(shipUnlockEntry) 101 if self.opacity < 1: 102 animations.StopAllAnimations(self) 103 self.FadeIn() 104 105 def _on_group_viewed(self, shipUnlockEntry): 106 if len(self._shipUnlockSvc.GetUnseenEntries()) == 0: 107 self.FadeOut() 108 109 def _on_unlocks_dismissed(self): 110 self.FadeOut(callback=self._on_dismiss_fade_complete) 111 112 def _on_dismiss_fade_complete(self): 113 for child in self.rewardsScroll.mainCont.children: 114 child.display = False 115 116 self.display = False 117 118 def _dismiss_all(self, *args, **kwargs): 119 self._shipUnlockSvc.DismissAll() 120 121 def FadeOut(self, callback = None): 122 if callback is None: 123 callback = self._FadeOutComplete 124 animations.FadeOut(self, duration=0.4, callback=callback) 125 126 def _FadeOutComplete(self): 127 self.display = False 128 129 def FadeIn(self, callback = None): 130 animations.FadeIn(self, duration=0.4, callback=callback) 131 132 133 class ShipTreeUnlockEntry(Container): 134 default_state = uiconst.UI_NORMAL 135 FRAME_COLOR_DISABLED = tuple(eveColor.FOCUS_BLUE[:3]) + (0.2,) 136 FRAME_GLOW_DISABLED = tuple(eveColor.FOCUS_BLUE[:3]) + (0.0,) 137 FRAME_COLOR_ENABLED = tuple(eveColor.FOCUS_BLUE[:3]) + (0.5,) 138 PIP_COLOR_DISABLED = tuple(eveColor.FOCUS_BLUE[:3]) + (0.0,) 139 PIP_COLOR_ENABLED = eveColor.FOCUS_BLUE 140 141 def ApplyAttributes(self, attributes): 142 super(ShipTreeUnlockEntry, self).ApplyAttributes(attributes) 143 self.unlockEntry = attributes.unlockEntry 144 self.original_bgColor = attributes.bgColor 145 self.callback = attributes.callback 146 self.ConstructLayout() 147 shipUnlockSignals.on_group_unlock_viewed.connect(self._on_unlock_viewed) 148 149 def Close(self): 150 shipUnlockSignals.on_group_unlock_viewed.disconnect(self._on_unlock_viewed) 151 152 def _on_unlock_viewed(self, unlockEntry): 153 if self.unlockEntry.shipGroupID == unlockEntry.shipGroupID: 154 self._fade_out() 155 156 def ConstructLayout(self): 157 self.padCnt = Container(parent=self, align=Align.TOALL, padBottom=10) 158 Button(parent=self.padCnt, align=Align.CENTERRIGHT, label=localization.GetByLabel('UI/Common/View'), padRight=8, func=self.OnClick) 159 self.content = ContainerAutoSize(parent=self.padCnt, align=Align.CENTERLEFT, padLeft=15, height=20) 160 self.factionIconCnt = Container(parent=self.content, align=Align.TOLEFT, width=24) 161 self.factionIcon = Sprite(parent=self.factionIconCnt, align=Align.CENTERLEFT, height=24, width=24, texturePath=ICON_BY_FACTIONID.get(self.unlockEntry.FactionID), hint=get_faction_name(self.unlockEntry.FactionID)) 162 self.groupIconCnt = Container(parent=self.content, align=Align.TOLEFT, width=24, padLeft=8) 163 self.groupIcon = Sprite(parent=self.groupIconCnt, align=Align.CENTERLEFT, height=24, width=24, texturePath=eveConfig.infoBubbleGroups[self.unlockEntry.GroupID]['icon']) 164 self.groupName = TextHeader(parent=self.content, align=Align.TOLEFT, text=GetByMessageID(eveConfig.infoBubbleGroups[self.unlockEntry.GroupID]['nameID']), padLeft=5) 165 frame_texture = 'res:/UI/Texture/classes/ShipProgression/Border.png' 166 pip_texture = 'res:/UI/Texture/classes/ShipProgression/Detail.png' 167 fill_texture = 'res:/UI/Texture/classes/ShipProgression/Fill.png' 168 self._frame_glow = Frame(parent=self.padCnt, align=uiconst.TOALL, texturePath=frame_texture, cornerSize=9, color=self.FRAME_GLOW_DISABLED, outputMode=trinity.Tr2SpriteTarget.GLOW) 169 self._pip_glow = Frame(parent=self.padCnt, align=uiconst.TOALL, texturePath=pip_texture, cornerSize=9, color=self.PIP_COLOR_DISABLED, outputMode=trinity.Tr2SpriteTarget.GLOW) 170 self._frame = Frame(parent=self.padCnt, align=uiconst.TOALL, texturePath=frame_texture, cornerSize=9, color=self.FRAME_COLOR_DISABLED) 171 self._pip = Frame(parent=self.padCnt, align=uiconst.TOALL, texturePath=pip_texture, cornerSize=9, color=self.PIP_COLOR_DISABLED) 172 self._background = Frame(parent=self.padCnt, align=uiconst.TOALL, texturePath=fill_texture, cornerSize=9, color=(0.1, 0.1, 0.2, 0.6), outputMode=trinity.Tr2SpriteTarget.COLOR_AND_GLOW, glowBrightness=0.3) 173 174 def OnClick(self, *args, **kwds): 175 GetShipUnlockService().MarkAsSeen(self.unlockEntry) 176 sm.GetService('shipTreeUI').ShowUnlockFanfare(self.unlockEntry.FactionID, self.unlockEntry.GroupID) 177 PlaySound('ship_goals_reveal_button_ship_play') 178 179 def OnMouseEnter(self, *args): 180 super(ShipTreeUnlockEntry, self).OnMouseEnter(*args) 181 duration = 0.1 182 animations.StopAllAnimations(self._pip_glow) 183 animations.StopAllAnimations(self._frame_glow) 184 animations.StopAllAnimations(self._pip) 185 animations.StopAllAnimations(self._frame) 186 animations.SpColorMorphTo(self._pip_glow, endColor=self.PIP_COLOR_ENABLED, duration=duration) 187 animations.SpColorMorphTo(self._frame_glow, endColor=self.FRAME_COLOR_ENABLED, duration=duration) 188 animations.SpColorMorphTo(self._pip, endColor=self.PIP_COLOR_ENABLED, duration=duration) 189 animations.SpColorMorphTo(self._frame, endColor=self.FRAME_COLOR_ENABLED, duration=duration) 190 191 def OnMouseExit(self, *args): 192 super(ShipTreeUnlockEntry, self).OnMouseExit(*args) 193 duration = 0.1 194 animations.StopAllAnimations(self._pip_glow) 195 animations.StopAllAnimations(self._frame_glow) 196 animations.StopAllAnimations(self._pip) 197 animations.StopAllAnimations(self._frame) 198 animations.SpColorMorphTo(self._pip_glow, endColor=self.PIP_COLOR_DISABLED, duration=duration) 199 animations.SpColorMorphTo(self._frame_glow, endColor=self.FRAME_GLOW_DISABLED, duration=duration) 200 animations.SpColorMorphTo(self._pip, endColor=self.PIP_COLOR_DISABLED, duration=duration) 201 animations.SpColorMorphTo(self._frame, endColor=self.FRAME_COLOR_DISABLED, duration=duration) 202 203 def _fade_out(self): 204 animations.FadeOut(self, duration=0.3, callback=self._collapse) 205 206 def _collapse(self): 207 animations.MorphScalar(self, 'height', endVal=0, callback=self._disable, duration=1.5) 208 209 def _disable(self): 210 self.display = False