paymentselector.py (4458B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\view\aurumstore\shared\paymentselector.py 2 import logging 3 from carbonui import uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.sprite import Sprite 6 logger = logging.getLogger(__name__) 7 RADIO_FILL = 'res:/UI/Texture/classes/RadioButton/fill.png' 8 RADIO_FRAME = 'res:/UI/Texture/classes/RadioButton/frame.png' 9 RADIO_GLOW = 'res:/UI/Texture/classes/RadioButton/innerGlow.png' 10 RADIO_SELECTED = 'res:/UI/Texture/classes/RadioButton/selected.png' 11 BACKGROUND_COLOR_INACTIVE = (0.1, 0.1, 0.1, 1.0) 12 BACKGROUND_COLOR_ACTIVE = (0.2, 0.2, 0.2, 1.0) 13 14 class RadioButtonComponent(Container): 15 default_name = 'RadioButtonComponent' 16 default_fillColor = (1.0, 1.0, 1.0, 0.9) 17 18 def ApplyAttributes(self, attributes): 19 super(RadioButtonComponent, self).ApplyAttributes(attributes) 20 fillColor = attributes.get('fillColor', self.default_fillColor) 21 self.radioFill = Sprite(parent=self, texturePath=RADIO_FILL, width=8, height=8, align=uiconst.CENTER, state=uiconst.UI_HIDDEN, color=fillColor) 22 Sprite(parent=self, texturePath=RADIO_FRAME, width=12, height=12, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=(0.3, 0.3, 0.3, 0.8)) 23 24 def OnSelect(self): 25 self.radioFill.Show() 26 27 def OnDeselect(self): 28 self.radioFill.Hide() 29 30 31 class PaymentSelectionBox(Container): 32 33 def ApplyAttributes(self, attributes): 34 super(PaymentSelectionBox, self).ApplyAttributes(attributes) 35 self.selectionValue = attributes.selectionValue 36 self.contents = attributes.contents 37 self.contents.SetParent(self) 38 radioBoxContainer = Container(name='radioBoxContainer', parent=self, align=uiconst.TOLEFT_NOPUSH, width=24, padLeft=12) 39 self.radioBox = RadioButtonComponent(parent=radioBoxContainer, align=uiconst.CENTER, width=24, height=12) 40 self.selectedBackground = Sprite(name='selectedBackground', parent=self, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/currencySelectorActive.png', opacity=0.0, state=uiconst.UI_DISABLED) 41 self.deselectedBackground = Sprite(name='deselectedBackground', parent=self, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/currencySelectorInactive.png', opacity=1.0, state=uiconst.UI_DISABLED) 42 43 def OnClick(self, *args): 44 super(PaymentSelectionBox, self).OnClick(*args) 45 self.parent.Select(self) 46 47 def OnSelect(self): 48 self.deselectedBackground.opacity = 0.0 49 self.selectedBackground.opacity = 1.0 50 self.radioBox.OnSelect() 51 52 def OnDeSelect(self): 53 self.deselectedBackground.opacity = 1.0 54 self.selectedBackground.opacity = 0.0 55 self.radioBox.OnDeselect() 56 57 58 class PaymentSelector(Container): 59 60 def ApplyAttributes(self, attributes): 61 super(PaymentSelector, self).ApplyAttributes(attributes) 62 defaultValue = attributes.defaultValue 63 self.onSelect = attributes.onSelect 64 self.selected = defaultValue 65 self.selectedBox = None 66 self.selectionBoxes = {} 67 numButtons = len(attributes.optionsDict) 68 for k, v in attributes.optionsDict.iteritems(): 69 box = PaymentSelectionBox(parent=self, align=uiconst.TOLEFT_PROP, selectionValue=k, contents=v, padLeft=10, state=uiconst.UI_NORMAL) 70 box.width = 1.0 / numButtons 71 self.selectionBoxes[k] = box 72 73 if self.selectionBoxes: 74 self._SetDefaultSelected(defaultValue) 75 76 def _SetDefaultSelected(self, defaultValue): 77 if defaultValue: 78 for box in self.selectionBoxes.values(): 79 if box.selectionValue == defaultValue: 80 self.Select(box) 81 82 else: 83 self.Select(self.selectionBoxes.values()[0]) 84 85 def Select(self, selectionBox): 86 if selectionBox == self.selectedBox: 87 return 88 if self.selectedBox is not None: 89 self.selectedBox.OnDeSelect() 90 self.selectedBox = selectionBox 91 self.selected = selectionBox.selectionValue 92 selectionBox.OnSelect() 93 if self.onSelect: 94 self.onSelect(selectionBox.selectionValue) 95 96 def SelectValue(self, value): 97 try: 98 self.Select(self.selectionBoxes[value]) 99 except KeyError: 100 logger.warn('Value %s does not exist' % str(value)) 101 102 def GetSelectedValue(self): 103 return self.selected