fixed.py (9338B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\crate\view\fixed.py 2 from carbonui import const as uiconst, ButtonVariant 3 from carbonui.button.group import ButtonGroup 4 from carbonui.control.button import Button 5 from carbonui.control.scrollContainer import ScrollContainer 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.primitives.layoutGrid import LayoutGrid 9 from carbonui.primitives.sprite import Sprite 10 from carbonui.uianimations import animations 11 from crates.const import MAX_MULTI_OPEN 12 from eve.client.script.ui.control.eveIcon import Icon 13 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveCaptionLarge 14 from eve.client.script.ui.crate.button import CrateButton 15 import localization 16 import uthread 17 18 def center(text): 19 return u'<center>{}</center>'.format(text) 20 21 22 class FixedView(Container): 23 24 def ApplyAttributes(self, attributes): 25 super(FixedView, self).ApplyAttributes(attributes) 26 self.controller = attributes.controller 27 self.shouldAnimateView = attributes.shouldAnimateView 28 self.openCrateButton = None 29 uthread.new(self.Layout) 30 31 def Layout(self): 32 self.Flush() 33 self.mainCont = Container(parent=self, align=uiconst.TOALL, padding=(380, 38, 24, 24), padLeft=380, padTop=38) 34 cont = ContainerAutoSize(parent=self.mainCont, align=uiconst.TOBOTTOM) 35 buttonGroupCont = ContainerAutoSize(parent=cont, align=uiconst.BOTTOMRIGHT, minWidth=400, idx=0, top=8) 36 self.buttonGroup = ButtonGroup(parent=buttonGroupCont, align=uiconst.CENTER) 37 self.contentCont = Container(name='contentCont', parent=self.mainCont, align=uiconst.TOALL, padBottom=8) 38 self.descriptionLabel = EveCaptionLarge(name='descriptionLabel', parent=self.contentCont, align=uiconst.TOTOP, text=self.controller.caption, opacity=0.0) 39 self.LayoutScroll() 40 self.LayoutButtons() 41 self.ShowContent() 42 43 def LayoutScroll(self): 44 self.scroll = LootScroll(parent=self.contentCont, name='lootScroll', align=uiconst.TOALL, controller=self.controller, opacity=0.0) 45 if self.controller.stacksize <= 0: 46 self.scroll.Hide() 47 self.descriptionLabel.Hide() 48 49 def RevealButtons(self): 50 self.LayoutButtons() 51 for button in self.buttonGroup.buttons: 52 animations.FadeTo(button) 53 54 def LayoutButtons(self): 55 self.buttonGroup.FlushButtons() 56 self.openCrateButton = None 57 if self.controller.stacksize > 0: 58 if self.controller.stacksize > 1: 59 if self.controller.stacksize > MAX_MULTI_OPEN: 60 text = localization.GetByLabel('UI/Crate/OpenMultiple', quantity=MAX_MULTI_OPEN) 61 else: 62 text = localization.GetByLabel('UI/Crate/OpenAll', quantity=self.controller.stacksize) 63 Button(parent=self.buttonGroup, label=text, func=self.OpenMultiple, variant=ButtonVariant.GHOST) 64 text = localization.GetByLabel('UI/Crate/OpenCrate', quantity=self.controller.stacksize) 65 self.openCrateButton = CrateButton(parent=self.buttonGroup, align=uiconst.NOALIGN, label=text, func=self.OpenCrate, name='CrateButton_OpenButton') 66 else: 67 Button(parent=self.buttonGroup, label=localization.GetByLabel('UI/Crate/Finish'), func=self.controller.Finish, args=()) 68 69 def ShowContent(self): 70 if self.shouldAnimateView: 71 self.AnimEntry() 72 else: 73 self.descriptionLabel.opacity = 1.0 74 self.scroll.opacity = 1.0 75 76 def AnimEntry(self): 77 animations.FadeTo(self.descriptionLabel) 78 uthread.new(self.scroll.AnimEntry, offset=0.0, child_offset=0.0) 79 if self.openCrateButton: 80 animations.FadeTo(self.openCrateButton, timeOffset=0.0, callback=self.openCrateButton.Enable) 81 82 def OpenCrate(self, button): 83 self.DisableButtons() 84 try: 85 animations.FadeTo(self.contentCont, startVal=self.contentCont.opacity, endVal=0.2) 86 self.controller.OpenCrate() 87 finally: 88 self.RevealButtons() 89 animations.FadeIn(self.contentCont) 90 91 def OpenMultiple(self, btn): 92 self.DisableButtons() 93 try: 94 animations.FadeTo(self.contentCont, startVal=self.contentCont.opacity, endVal=0.2, duration=0.1) 95 self.controller.OpenMultipleCrates() 96 finally: 97 self.RevealButtons() 98 animations.FadeIn(self.contentCont) 99 self.descriptionLabel.opacity = 0.0 100 self.scroll.opacity = 0.0 101 uthread.new(self.AnimEntry) 102 103 def DisableButtons(self, *args): 104 for button in self.buttonGroup.buttons: 105 button.Disable() 106 107 108 class LootItemEntry(Container): 109 default_height = 40 110 default_align = uiconst.TOTOP 111 112 def ApplyAttributes(self, attributes): 113 super(LootItemEntry, self).ApplyAttributes(attributes) 114 self.item = attributes.item 115 self.AddGrid() 116 self.AddIcon() 117 self.AddLabel() 118 119 def AddGrid(self): 120 self.grid = LayoutGrid(parent=self, align=uiconst.TOPLEFT, columns=2) 121 122 def AddIcon(self): 123 self.icon = None 124 125 def AddLabel(self): 126 self.label = EveLabelMedium(parent=self.grid, align=uiconst.CENTERLEFT, text=self.item.get_name()) 127 128 def AnimEntry(self, offset = 0.0): 129 if self.label: 130 animations.FadeTo(self.label, timeOffset=offset) 131 if self.icon: 132 animations.FadeTo(self.icon, duration=0.15, timeOffset=offset) 133 animations.MorphVector2(self.icon, 'scale', startVal=(4.0, 4.0), endVal=(0.9, 0.9), duration=0.15, timeOffset=offset, sleep=True) 134 animations.MorphVector2(self.icon, 'scale', startVal=(0.9, 0.9), endVal=(1.0, 1.0), duration=0.15) 135 animations.SpGlowFadeOut(self.icon, duration=0.3) 136 animations.MorphScalar(self.icon, 'glowExpand', startVal=0.5, endVal=10.0, duration=0.3) 137 138 139 class LootItemFromTypeEntry(LootItemEntry): 140 141 def AddIcon(self): 142 icon = Icon(align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=32, height=32, typeID=self.item.typeID, isCopy=self.item.is_copy()) 143 techIcon = self.item.get_tech_icon() 144 if techIcon: 145 iconCont = Container(align=uiconst.CENTER, width=32, height=32) 146 techIcon.SetParent(iconCont) 147 icon.SetParent(iconCont) 148 self.icon = iconCont 149 else: 150 self.icon = icon 151 self.grid.AddCell(self.icon, cellPadding=(8, 8)) 152 153 154 class SpecialLootItemEntry(LootItemEntry): 155 156 def AddIcon(self): 157 self.icon = Sprite(align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=32, height=32, texturePath=self.item.get_icon()) 158 self.grid.AddCell(self.icon, cellPadding=(8, 8)) 159 160 161 class LootScroll(ScrollContainer): 162 163 def ApplyAttributes(self, attributes): 164 super(LootScroll, self).ApplyAttributes(attributes) 165 self.controller = attributes.controller 166 for item in self.controller.GetSortedLoot(): 167 LootItemFromTypeEntry(parent=self, item=item) 168 169 for item in self.controller.GetSpecialLoot(): 170 (SpecialLootItemEntry(parent=self, item=item),) 171 172 @property 173 def verticalScrollPosition(self): 174 return self.GetPositionVertical() 175 176 @verticalScrollPosition.setter 177 def verticalScrollPosition(self, fraction): 178 self.ScrollToVertical(fraction) 179 180 def AnimEntry(self, offset = 0.0, child_offset = 0.1): 181 animations.FadeTo(self, duration=0.5, timeOffset=offset) 182 for i, entry in enumerate(self.mainCont.children): 183 uthread.new(entry.AnimEntry, offset=child_offset * i + offset) 184 185 animations.MorphScalar(self, 'verticalScrollPosition', duration=2.0, timeOffset=offset + 0.6, sleep=True) 186 animations.MorphScalar(self, 'verticalScrollPosition', startVal=1.0, endVal=0.0, duration=1.0, timeOffset=0.4) 187 188 189 class FixedViewForRandomizedLoot(FixedView): 190 191 def LayoutScroll(self): 192 self.scroll = LootScroll(parent=self.contentCont, name='lootScroll', align=uiconst.TOALL, controller=self.controller) 193 self.descriptionLabel.Hide() 194 self.controller.ClaimAllLoot() 195 196 def LayoutButtons(self): 197 self.buttonGroup.FlushButtons() 198 self.openCrateButton = None 199 if self.controller.stacksize > 0: 200 if self.controller.stacksize > 1: 201 if self.controller.stacksize > MAX_MULTI_OPEN: 202 text = localization.GetByLabel('UI/Crate/HackMultiple', quantity=MAX_MULTI_OPEN) 203 else: 204 text = localization.GetByLabel('UI/Crate/HackAll', quantity=self.controller.stacksize) 205 Button(parent=self.buttonGroup, label=text, func=self.OpenMultiple, variant=ButtonVariant.GHOST) 206 text = localization.GetByLabel('UI/Crate/HackCrate', quantity=self.controller.stacksize) 207 self.openCrateButton = CrateButton(parent=self.buttonGroup, align=uiconst.NOALIGN, label=text, func=self.OpenCrate) 208 self.openCrateButton.Enable() 209 else: 210 Button(parent=self.buttonGroup, label=localization.GetByLabel('UI/Crate/Finish'), func=self.controller.Finish, args=()) 211 212 def ShowContent(self): 213 pass