charCreationUtils.py (9036B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation_new\charCreationUtils.py 2 import carbonui.const as uiconst 3 import charactercreator.const as ccConst 4 from carbon.common.script.util import timerstuff 5 from carbonui.primitives.container import Container 6 from carbonui.uicore import uicore 7 from carbonui.primitives.gradientSprite import GradientConst, GradientSprite 8 from eve.client.script.ui.control import eveLabel 9 10 class CCLabel(eveLabel.Label): 11 default_bold = 1 12 default_color = ccConst.COLOR 13 default_letterspace = 1 14 default_state = uiconst.UI_DISABLED 15 16 17 class BitSlider(Container): 18 default_name = 'BitSlider' 19 default_align = uiconst.RELATIVE 20 default_bitWidth = 3 21 default_bitHeight = 8 22 default_bitGap = 1 23 default_state = uiconst.UI_NORMAL 24 default_left = 0 25 default_top = 0 26 default_width = 128 27 default_height = 12 28 cursor = uiconst.UICURSOR_SELECT 29 30 def ApplyAttributes(self, attributes): 31 Container.ApplyAttributes(self, attributes) 32 self.onSetValueCallback = None 33 targetWidth = attributes.get('sliderWidth', 100) 34 bitGap = attributes.get('bitGap', self.default_bitGap) 35 bitAmount = attributes.bitAmount 36 self.bitHeight = attributes.bitHeight or self.default_bitHeight 37 self.height = self.bitHeight + 4 38 if bitAmount: 39 self.bitWidth = int(targetWidth / float(bitAmount)) 40 else: 41 self.bitWidth = attributes.bitWidth or self.default_bitWidth 42 self._value = 0.0 43 self.bitParent = Container(parent=self, pos=(0, 44 0, 45 targetWidth, 46 self.height), align=uiconst.TOPLEFT) 47 self.handle = Container(parent=self.bitParent, align=uiconst.RELATIVE, state=uiconst.UI_DISABLED, pos=(0, 48 0, 49 3, 50 self.height), bgColor=ccConst.COLOR + (1.0,)) 51 i = 0 52 while True: 53 if bitAmount is None and i >= 3 and i * (self.bitWidth + bitGap) + self.bitWidth > targetWidth: 54 break 55 bit = Container(parent=self.bitParent, pos=(i * (self.bitWidth + bitGap), 56 2, 57 self.bitWidth, 58 self.bitHeight), align=uiconst.RELATIVE, state=uiconst.UI_DISABLED, bgColor=ccConst.COLOR + (1.0,)) 59 bit.isBit = True 60 i += 1 61 if bitAmount is not None and i == bitAmount: 62 break 63 64 self._numBits = i 65 if targetWidth != bit.left + bit.width: 66 diff = targetWidth - (bit.left + bit.width) 67 bit.width += diff 68 self.bitParent.width = targetWidth 69 self.width = targetWidth 70 if attributes.setvalue is not None: 71 self.SetValue(attributes.setvalue) 72 self.onSetValueCallback = attributes.OnSetValue 73 74 def OnMouseDown(self, mouseBtn, *args): 75 if mouseBtn != uiconst.MOUSELEFT: 76 return 77 self.softSlideTimer = None 78 self.slideTimer = timerstuff.AutoTimer(33, self.UpdateSliderPortion) 79 80 def OnMouseEnter(self, *args): 81 self.softSlideTimer = timerstuff.AutoTimer(33, self.UpdateSoftSliderPortion) 82 83 def OnMouseExit(self, *args): 84 pass 85 86 def OnMouseWheel(self, *args): 87 if uicore.uilib.dz > 0: 88 self.SetValue(self.GetValue() + 1.0 / self._numBits) 89 else: 90 self.SetValue(self.GetValue() - 1.0 / self._numBits) 91 92 def UpdateSoftSliderPortion(self, *args): 93 if uicore.uilib.mouseOver is self or uicore.uilib.mouseOver.IsUnder(self): 94 l, t, w, h = self.bitParent.GetAbsolute() 95 portion = max(0.0, min(1.0, (uicore.uilib.x - l) / float(w))) 96 self.ShowSoftLit(portion) 97 else: 98 self.softSlideTimer = None 99 self.ShowSoftLit(0.0) 100 101 def UpdateSliderPortion(self, *args): 102 l, t, w, h = self.bitParent.GetAbsolute() 103 portion = max(0.0, min(1.0, (uicore.uilib.x - l) / float(w))) 104 self.handle.left = int((w - self.bitWidth) * portion) 105 self.ShowLit(portion) 106 107 def OnMouseUp(self, mouseBtn, *args): 108 if mouseBtn != uiconst.MOUSELEFT: 109 return 110 self.slideTimer = None 111 l, t, w, h = self.bitParent.GetAbsolute() 112 portion = max(0.0, min(1.0, (uicore.uilib.x - l) / float(w))) 113 self.handle.left = int((w - self.handle.width) * portion) 114 self.SetValue(portion) 115 116 def ShowLit(self, portion): 117 l, t, w, h = self.bitParent.GetAbsolute() 118 if not w: 119 return 120 self.handle.left = int((w - self.handle.width) * portion) 121 for each in self.bitParent.children: 122 if not hasattr(each, 'isBit'): 123 continue 124 mportion = max(0.0, min(1.0, (each.left + each.width / 2) / float(w))) 125 if portion > mportion: 126 each.SetOpacity(1.0) 127 else: 128 each.SetOpacity(0.333) 129 130 def ShowSoftLit(self, portion): 131 l, t, w, h = self.bitParent.GetAbsolute() 132 for each in self.bitParent.children: 133 if not hasattr(each, 'isBit'): 134 continue 135 if each.opacity == 1.0: 136 continue 137 mportion = max(0.0, min(1.0, (each.left + each.width / 2) / float(w))) 138 if portion > mportion: 139 each.SetOpacity(0.5) 140 else: 141 each.SetOpacity(0.333) 142 143 def SetValue(self, value, doCallback = True): 144 callback = value != self._value 145 self._value = max(0.0, min(1.0, value)) 146 self.ShowLit(self._value) 147 if callback and doCallback and self.onSetValueCallback: 148 self.onSetValueCallback(self) 149 150 def GetValue(self): 151 return self._value 152 153 154 class GradientSlider(Container): 155 default_name = 'GradientSlider' 156 default_align = uiconst.RELATIVE 157 default_bitWidth = 3 158 default_bitHeight = 8 159 default_bitGap = 1 160 default_state = uiconst.UI_NORMAL 161 default_left = 0 162 default_top = 0 163 default_width = 128 164 default_height = 12 165 cursor = uiconst.UICURSOR_SELECT 166 167 def ApplyAttributes(self, attributes): 168 Container.ApplyAttributes(self, attributes) 169 self.onSetValueCallback = None 170 targetWidth = attributes.get('sliderWidth', 100) 171 bitHeight = attributes.bitHeight or self.default_bitHeight 172 self.height = bitHeight + 4 173 self._value = 0.0 174 self.handle = Container(parent=self, align=uiconst.RELATIVE, state=uiconst.UI_DISABLED, pos=(0, 175 -2, 176 3, 177 self.height + 4), bgColor=ccConst.COLOR + (1.0,)) 178 if attributes.get('alphaValues'): 179 alphaValues = attributes.get('alphaValues') 180 rgbValues = [(0, (0, 0, 0))] 181 else: 182 alphaValues = (1, 1) 183 rgbValues = [(0, (0, 0, 0)), (1.0, (1, 1, 1))] 184 self.gradientSprite = GradientSprite(parent=self, pos=(0, 185 0, 186 targetWidth, 187 self.height), rgbData=rgbValues, alphaData=[alphaValues, (1.0, 1.0)], alphaInterp=GradientConst.INTERP_LINEAR, colorInterp=GradientConst.INTERP_LINEAR, state=uiconst.UI_DISABLED) 188 self.gradientSprite.width = targetWidth 189 if attributes.setvalue is not None: 190 self.SetValue(attributes.setvalue) 191 self.onSetValueCallback = attributes.OnSetValue 192 self.ChangeGradientColor(secondColor=(1.0, (1, 1, 0))) 193 194 def OnMouseDown(self, mouseBtn, *args): 195 if mouseBtn != uiconst.MOUSELEFT: 196 return 197 self.slideTimer = timerstuff.AutoTimer(33, self.UpdateSliderPortion) 198 199 def UpdateSliderPortion(self, *args): 200 l, t, w, h = self.gradientSprite.GetAbsolute() 201 portion = max(0.0, min(1.0, (uicore.uilib.x - l) / float(w))) 202 self.handle.left = int(w * portion) 203 204 def OnMouseUp(self, mouseBtn, *args): 205 if mouseBtn != uiconst.MOUSELEFT: 206 return 207 self.slideTimer = None 208 l, t, w, h = self.gradientSprite.GetAbsolute() 209 portion = max(0.0, min(1.0, (uicore.uilib.x - l) / float(w))) 210 self.handle.left = int(w * portion) 211 self.SetValue(portion) 212 213 def SetValue(self, value, doCallback = True): 214 callback = value != self._value 215 self._value = max(0.0, min(1.0, value)) 216 self.SetHandle(self._value) 217 if callback and doCallback and self.onSetValueCallback: 218 self.onSetValueCallback(self) 219 220 def SetHandle(self, portion): 221 l, t, w, h = self.gradientSprite.GetAbsolute() 222 if not w: 223 return 224 self.handle.left = int((w - self.handle.width) * portion) 225 226 def GetValue(self): 227 return self._value 228 229 def ChangeGradientColor(self, firstColor = None, secondColor = None): 230 colorData = self.gradientSprite.colorData 231 if len(colorData) < 2: 232 firstColor = secondColor 233 if firstColor is not None: 234 colorData[0] = firstColor 235 if secondColor is not None and len(colorData) > 1: 236 colorData[1] = secondColor 237 self.gradientSprite.SetGradient()