fixedcratewindow.py (5220B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\crate\fixedcratewindow.py 2 import uthread2 3 from carbon.common.script.util.format import FmtAmt 4 from carbonui import uiconst 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.frame import Frame 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.util.color import Color 9 from carbonui.window.header.small import SmallWindowHeader 10 from eve.client.script.ui import eveColor, eveThemeColor 11 from eve.client.script.ui.control.eveLabel import Label 12 from carbonui.control.window import Window 13 from eve.client.script.ui.crate.controller import FixedCrateStackController 14 from eve.client.script.ui.crate.view.fixed import FixedView 15 from eve.client.script.ui.crate.window import Splash, CrateWindowUnderlay 16 from carbonui.fontconst import STYLE_SMALLTEXT 17 18 class StackBadge(Container): 19 20 def ApplyAttributes(self, attributes): 21 super(StackBadge, self).ApplyAttributes(attributes) 22 self._value = attributes.value 23 self._Layout() 24 self._Update() 25 26 def SetValue(self, value): 27 self._value = value 28 self._Update() 29 30 def GetValue(self): 31 return self._value 32 33 def _Layout(self): 34 self.frame = Frame(bgParent=self, texturePath='res:/UI/Texture/Shared/counterFrame.png', cornerSize=8 if self._value >= 10 else 1, offset=-1, color=eveThemeColor.THEME_FOCUSDARK) 35 self.label = Label(parent=self, align=uiconst.CENTER, fontStyle=STYLE_SMALLTEXT, fontsize=10, bold=True, color=Color.WHITE, padLeft=-1, padRight=1) 36 37 def _Update(self): 38 self._UpdateLabel() 39 self._UpdateSize() 40 41 def _UpdateLabel(self): 42 self.label.SetText(FmtAmt(self._value, fmt='sn')) 43 44 def _UpdateSize(self): 45 self.width = max(16, self.label.textwidth + 5) 46 self.height = max(16, self.label.textheight) 47 48 49 class Stack(Container): 50 51 def ApplyAttributes(self, attributes): 52 super(Stack, self).ApplyAttributes(attributes) 53 Sprite(parent=self, width=32, height=32, align=uiconst.TORIGHT, texturePath='res:/UI/Texture/classes/ItemPacks/Stack_32.png') 54 self.circle = StackBadge(parent=self, value=attributes.size, width=32, height=32, align=uiconst.CENTERLEFT, idx=0) 55 padAmount = self.circle.width / 2 56 self.circle.padLeft = -padAmount 57 self.circle.padRight = padAmount 58 59 def SetValue(self, value): 60 self.circle.SetValue(value) 61 62 63 class FixedCrateWindow(Window): 64 __guid__ = 'form.CrateRedeemedWindow' 65 default_windowID = 'CrateRedeemedWindow' 66 default_fixedWidth = 800 67 default_fixedHeight = 420 68 default_width = 800 69 default_height = 420 70 default_clipChildren = False 71 default_isCollapseable = False 72 default_isLightBackgroundConfigurable = False 73 default_isStackable = False 74 default_isLockable = False 75 default_isOverlayable = False 76 default_isMinimizable = False 77 78 @classmethod 79 def Open(cls, *args, **kwargs): 80 cls.CloseIfOpen() 81 return super(FixedCrateWindow, cls).Open(**kwargs) 82 83 def ApplyAttributes(self, attributes): 84 super(FixedCrateWindow, self).ApplyAttributes(attributes) 85 crate_stack_list = attributes.crate_stack_list 86 self.controller = FixedCrateStackController(crate_stack_list) 87 self.view = None 88 self.splash = None 89 self.Layout() 90 self.controller.onOpen.connect(self.OnCrateOpenedOrSkipped) 91 self.controller.onSkip.connect(self.OnCrateOpenedOrSkipped) 92 self.controller.onFinish.connect(self.Close) 93 self.controller.onCrateMultiOpenEnded.connect(self.OnMultiOpenEnded) 94 uthread2.start_tasklet(self.AnimEntry) 95 96 def Layout(self, shouldAnimateView = False): 97 if self.view: 98 self.view.Close() 99 self.Flush() 100 self.SetCaption(self.controller.caption) 101 self._stack = Stack(parent=self.content, size=self.controller.stacksize, align=uiconst.TOPRIGHT, width=32, height=32, top=20, padRight=5, padLeft=-5) 102 if self.controller.stacksize <= 1: 103 self._stack.Hide() 104 if self.splash: 105 self.splash.Close() 106 self.splash = Splash(parent=self.GetMainArea(), align=uiconst.CENTERLEFT, pos=(120, 0, 1, 1), controller=self.controller) 107 self.view = FixedView(parent=self.GetMainArea(), align=uiconst.TOALL, controller=self.controller, shouldAnimateView=shouldAnimateView) 108 109 def Prepare_Header_(self): 110 self._SetHeader(SmallWindowHeader(show_caption=False)) 111 112 def OnCrateOpen(self): 113 if self.controller.stacksize < 1: 114 self.Close() 115 self.UpdateStackValue() 116 self.Layout(shouldAnimateView=True) 117 118 def OnCrateOpenedOrSkipped(self): 119 self.OnCrateOpen() 120 121 def OnMultiOpenEnded(self, *args): 122 self.UpdateStackValue() 123 124 def UpdateStackValue(self): 125 self._stack.SetValue(self.controller.stacksize) 126 127 def AnimEntry(self): 128 self.splash.AnimEntry() 129 130 def Prepare_Background_(self): 131 self.sr.underlay = CrateWindowUnderlay(parent=self) 132 133 def Close(self, *args, **kwargs): 134 self.controller.Close() 135 super(FixedCrateWindow, self).Close(*args, **kwargs)