charCreationOvalSlider.py (19624B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation_new\charCreationOvalSlider.py 2 import math 3 import carbonui.const as uiconst 4 from carbon.common.script.util import timerstuff 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.sprite import Sprite 7 from carbonui.uicore import uicore 8 from eve.client.script.ui.control import eveIcon 9 from eve.client.script.ui.login.charcreation_new.charCreationUtils import CCLabel 10 SMALLSLIDER = 1 11 TEXTURESIZE = 164 12 SETTINGS = {SMALLSLIDER: {'name': 'small', 13 'radius': 65, 14 'textureWidth': 56, 15 'textureHeight': 136, 16 'rotationRangeLeft': (5.0471258177, (math.pi * 2 - 5.0471258177) * 2), 17 'rotationRangeRight': (5.0471258177 - math.pi, (math.pi * 2 - 5.0471258177) * 2), 18 'centerOffsetLeft': (71, 136 / 2), 19 'centerOffsetRight': (-15, 136 / 2), 20 'comboSize': (142, 136)}} 21 22 class CharCreationSingleSlider(Container): 23 __guid__ = 'uicls.CharCreationSingleSlider' 24 default_name = 'CharCreationSingleSlider' 25 default_align = uiconst.CENTER 26 default_state = uiconst.UI_PICKCHILDREN 27 default_pickRadius = 75 28 29 def ApplyAttributes(self, attributes): 30 for each in uicore.layer.main.children: 31 if each.name == self.default_name: 32 each.Close() 33 34 Container.ApplyAttributes(self, attributes) 35 if attributes.parent is None: 36 uicore.layer.main.children.append(self) 37 self.SetSize(TEXTURESIZE, TEXTURESIZE) 38 settings = {'radius': 72, 39 'textureWidth': 164, 40 'textureHeight': 164, 41 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_1.dds', 42 'rotationRange': (4.97, math.pi * 2 - 0.53), 43 'centerOffset': (82, 82)} 44 self.slider = CharCreationOvalSlider(parent=self, align=uiconst.CENTERLEFT, sliderSetting=settings, OnSetValue=attributes.get('OnSetValue', None), setValue=attributes.get('setValue', 0.0), invertSlider=attributes.get('invertSlider', False), modifierName=attributes.modifierName, increments=attributes.get('incrementsSlider', None)) 45 if attributes.label: 46 CCLabel(parent=self.slider, fontsize=13, align=uiconst.BOTTOMRIGHT, text=attributes.label, letterspace=2, top=-20, uppercase=True) 47 48 49 class CharCreationDoubleSlider(Container): 50 __guid__ = 'uicls.CharCreationDoubleSlider' 51 default_name = 'CharCreationDoubleSlider' 52 default_align = uiconst.CENTER 53 default_state = uiconst.UI_PICKCHILDREN 54 default_pickRadius = 75 55 56 def ApplyAttributes(self, attributes): 57 for each in uicore.layer.main.children: 58 if each.name == self.default_name: 59 each.Close() 60 61 Container.ApplyAttributes(self, attributes) 62 if attributes.parent is None: 63 uicore.layer.main.children.append(self) 64 self.SetSize(TEXTURESIZE, TEXTURESIZE) 65 settings1 = {'radius': 72, 66 'textureWidth': 82, 67 'textureHeight': 164, 68 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_2_1.dds', 69 'rotationRange': (4.97, math.pi - 0.53), 70 'centerOffset': (82, 82)} 71 self.slider1 = CharCreationOvalSlider(parent=self, align=uiconst.CENTERLEFT, sliderSetting=settings1, OnSetValue=attributes.get('OnSetValue1', None), setValue=attributes.get('setValue1', 0.0), invertSlider=attributes.get('invertSlider1', False), modifierName=attributes.modifierName1, increments=attributes.get('incrementsSlider1', None)) 72 if attributes.label1: 73 CCLabel(parent=self.slider1, fontsize=12, align=uiconst.BOTTOMRIGHT, text=attributes.label1, letterspace=2, top=-20, uppercase=True, left=13) 74 settings2 = {'radius': 72, 75 'textureWidth': 82, 76 'textureHeight': 164, 77 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_2_2.dds', 78 'rotationRange': (math.pi * 0.5 + 0.27, math.pi - 0.53), 79 'centerOffset': (0, 82)} 80 self.slider2 = CharCreationOvalSlider(parent=self, align=uiconst.CENTERRIGHT, sliderSetting=settings2, OnSetValue=attributes.get('OnSetValue2', None), setValue=attributes.get('setValue2', 0.0), invertSlider=attributes.get('invertSlider2', True), modifierName=attributes.modifierName2, increments=attributes.get('incrementsSlider2', None)) 81 if attributes.label2: 82 CCLabel(parent=self.slider2, fontsize=12, align=uiconst.BOTTOMLEFT, text=attributes.label2, letterspace=2, top=-20, uppercase=True, left=13) 83 84 85 class CharCreationTripleSlider(Container): 86 __guid__ = 'uicls.CharCreationTripleSlider' 87 default_name = 'CharCreationTripleSlider' 88 default_align = uiconst.CENTER 89 default_state = uiconst.UI_PICKCHILDREN 90 default_pickRadius = 75 91 92 def ApplyAttributes(self, attributes): 93 for each in uicore.layer.main.children: 94 if each.name == self.default_name: 95 each.Close() 96 97 Container.ApplyAttributes(self, attributes) 98 if attributes.parent is None: 99 uicore.layer.main.children.append(self) 100 self.SetSize(TEXTURESIZE, TEXTURESIZE) 101 settings1 = {'radius': 72, 102 'textureWidth': 82, 103 'textureHeight': 117, 104 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_3_1.dds', 105 'rotationRange': (4.975, math.pi * 0.502), 106 'centerOffset': (82, 35)} 107 self.slider1 = CharCreationOvalSlider(parent=self, align=uiconst.BOTTOMLEFT, sliderSetting=settings1, OnSetValue=attributes.get('OnSetValue1', None), setValue=attributes.get('setValue1', 0.0), invertSlider=attributes.get('invertSlider1', False), modifierName=attributes.modifierName1, increments=attributes.get('incrementsSlider1', None)) 108 if attributes.label1: 109 CCLabel(parent=self.slider1, fontsize=12, align=uiconst.BOTTOMRIGHT, text=attributes.label1, letterspace=2, top=-10, uppercase=True, left=12) 110 settings2 = {'radius': 72, 111 'textureWidth': 82, 112 'textureHeight': 118, 113 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_3_2.dds', 114 'rotationRange': (2.88, math.pi * 0.502), 115 'centerOffset': (0, 36)} 116 self.slider2 = CharCreationOvalSlider(parent=self, align=uiconst.BOTTOMRIGHT, sliderSetting=settings2, OnSetValue=attributes.get('OnSetValue2', None), setValue=attributes.get('setValue2', 0.0), invertSlider=attributes.get('invertSlider2', True), modifierName=attributes.modifierName2, increments=attributes.get('incrementsSlider2', None)) 117 if attributes.label2: 118 CCLabel(parent=self.slider2, fontsize=12, align=uiconst.BOTTOMLEFT, text=attributes.label2, letterspace=2, top=-10, uppercase=True, left=12) 119 settings3 = {'radius': 72, 120 'textureWidth': 164, 121 'textureHeight': 48, 122 'texturePath': 'res:/UI/Texture/CharacterCreation/ovalSlider_3_3.dds', 123 'rotationRange': (0.78, math.pi * 0.502), 124 'centerOffset': (82, 82)} 125 self.slider3 = CharCreationOvalSlider(parent=self, align=uiconst.TOPLEFT, sliderSetting=settings3, OnSetValue=attributes.get('OnSetValue3', None), setValue=attributes.get('setValue3', 0.0), invertSlider=attributes.get('invertSlider3', False), modifierName=attributes.modifierName3, increments=attributes.get('incrementsSlider3', None)) 126 if attributes.label3: 127 CCLabel(parent=self.slider3, fontsize=12, align=uiconst.CENTERTOP, text=attributes.label3, letterspace=2, top=-20, uppercase=True) 128 129 130 class CharCreationOvalSlider(Container): 131 __guid__ = 'uicls.CharCreationOvalSlider' 132 default_name = 'CharCreationOvalSlider' 133 default_align = uiconst.CENTER 134 default_state = uiconst.UI_NORMAL 135 136 def ApplyAttributes(self, attributes): 137 Container.ApplyAttributes(self, attributes) 138 self._invertedValue = False 139 self._lastCallbackValue = None 140 self.incrementStopToValue = {} 141 settings = attributes.sliderSetting 142 textureRadius = settings['radius'] 143 textureWidth = settings['textureWidth'] 144 textureHeight = settings['textureHeight'] 145 texturePath = settings['texturePath'] 146 centerOffset = settings['centerOffset'] 147 rotationRange = settings['rotationRange'] 148 texturePath = settings['texturePath'] 149 self.increments = attributes.increments 150 if self.increments is None: 151 self.increments = None 152 else: 153 self.increments.sort() 154 self.textureRadius = textureRadius 155 self.modifierName = attributes.modifierName 156 self.SetSize(textureWidth, textureHeight) 157 self.SetRotationCenterOffset(*centerOffset) 158 self.SetRotationRange(*rotationRange) 159 if attributes.get('invertSlider', False): 160 self.InvertSlider() 161 self.marker = Sprite(parent=self, align=uiconst.TOPLEFT, pos=(0, 0, 16, 16), texturePath='res:/UI/Texture/CharacterCreation/OvalSliderHandle.dds', ignoreSize=True) 162 self.marker.OnMouseDown = self.OnMarkerMouseDown 163 self.marker.OnMouseEnter = self.OnMarkerMouseEnter 164 self.marker.OnMouseExit = self.OnMarkerMouseExit 165 self.ghostMarker = Sprite(parent=self, align=uiconst.TOPLEFT, pos=(0, 0, 16, 16), texturePath='res:/UI/Texture/CharacterCreation/OvalSliderHandle.dds', ignoreSize=True, state=uiconst.UI_DISABLED, color=(1.0, 1.0, 1.0, 0.5)) 166 bg = Sprite(parent=self, align=uiconst.TOPLEFT, texturePath=texturePath, ignoreSize=True, state=uiconst.UI_DISABLED, color=(1.0, 1.0, 1.0, 1.0), pos=(0, 167 0, 168 textureWidth, 169 textureHeight)) 170 self.DrawIncrements() 171 self.DrawFill() 172 self.fill = Container(parent=self, align=uiconst.BOTTOMLEFT, clipChildren=True, pos=(0, 173 0, 174 textureWidth, 175 textureHeight)) 176 self.SetValue(attributes.get('setValue', 0.0)) 177 setvalueCallback = attributes.get('OnSetValue', None) 178 if setvalueCallback: 179 self.OnSetValue = setvalueCallback 180 181 def OnMarkerMouseDown(self, *args): 182 self.OnMouseDown() 183 184 def OnMarkerMouseEnter(self, *args): 185 self.marker.texture.resPath = 'res:/UI/Texture/CharacterCreation/OvalSliderHandle_MO.dds' 186 187 def OnMarkerMouseExit(self, *args): 188 self.marker.texture.resPath = 'res:/UI/Texture/CharacterCreation/OvalSliderHandle.dds' 189 190 def OnMouseDown(self, *args): 191 if uicore.uilib.leftbtn: 192 sm.StartService('audio').SendUIEvent(unicode('ui_icc_button_mouse_down_play')) 193 self.UpdateMarkerPosition(jump=True) 194 self.updateTimer = timerstuff.AutoTimer(10, self.UpdateSlider) 195 196 def OnMouseWheel(self, *args): 197 delta = uicore.uilib.dz 198 if self.increments: 199 current = self.GetValue() 200 currentIndex = self.increments.index(current) 201 newIndex = max(0, min(len(self.increments) - 1, currentIndex + [-1, 1][delta > 0])) 202 newVal = self.increments[newIndex] 203 self.SetValue(newVal) 204 self._OnSetValue(self, self._value) 205 else: 206 self.SetValue(self.GetValue() + [-0.01, 0.01][delta > 0]) 207 self._OnSetValue(self, self._value) 208 209 def UpdateSlider(self, *args): 210 if not uicore.uilib.leftbtn: 211 self.updateTimer = None 212 self.ghostMarker.state = uiconst.UI_HIDDEN 213 self.marker.texture.resPath = 'res:/UI/Texture/CharacterCreation/OvalSliderHandle.dds' 214 sm.StartService('audio').SendUIEvent(unicode('ui_icc_button_mouse_down_play')) 215 self._OnSetValue(self, self._value) 216 return 217 self.marker.texture.resPath = 'res:/UI/Texture/CharacterCreation/OvalSliderHandle_MD.dds' 218 self.UpdateMarkerPosition() 219 220 def SetIncrements(self, increments): 221 self.increments = increments 222 self.DrawIncrements() 223 224 def DrawIncrements(self): 225 for each in self.children[:]: 226 if each.name == 'incrementMarker': 227 each.Close() 228 229 if not self.increments or len(self.increments) < 2: 230 return 231 fromAngle, toAngle, rotationRange = self.rotationRange 232 numberic = True 233 try: 234 for each in self.increments: 235 float(each) 236 237 except: 238 numberic = False 239 240 self.incrementStopToValue = {} 241 if numberic: 242 useIncrements = self.increments 243 else: 244 step = 1.0 / len(self.increments) - 1 245 useIncrements = [ i * step for i, each in enumerate(self.increments) ] 246 for i, step in enumerate(useIncrements): 247 radianAngle = fromAngle + rotationRange * step 248 l, t, w, h = self.GetAbsolute() 249 ox, oy = self.centerOffset 250 radius = self.textureRadius + 1 251 cos = math.cos(radianAngle + math.pi) 252 sin = math.sin(radianAngle + math.pi) 253 left = int(radius * cos) + ox - 4 254 top = int(radius * sin) + oy - 4 255 self.incrementStopToValue[step] = self.increments[i] 256 icon = eveIcon.Icon(parent=self, pos=(left, 257 top, 258 8, 259 8), icon='ui_3_8_1', color=(1.0, 260 1.0, 261 1.0, 262 step * 0.5), state=uiconst.UI_DISABLED, name='incrementMarker') 263 264 def DrawFill(self): 265 step = math.pi / 90.0 266 fromAngle, toAngle, rotationRange = self.rotationRange 267 l, t, w, h = self.GetAbsolute() 268 ox, oy = self.centerOffset 269 radius = self.textureRadius 270 startAngle = fromAngle + math.pi 271 while startAngle < fromAngle + rotationRange + math.pi: 272 cos = math.cos(startAngle) 273 sin = math.sin(startAngle) 274 left = int(radius * cos) + ox - 8 275 top = int(radius * sin) + oy - 8 276 fillDot = Sprite(parent=self, align=uiconst.TOPLEFT, pos=(left, 277 top, 278 16, 279 16), texturePath='res:/UI/Texture/CharacterCreation/ovalSlider_Filler.dds', ignoreSize=True, state=uiconst.UI_DISABLED, name='fillDot', color=(0.3, 0.3, 0.3, 1.0)) 280 startAngle += step 281 282 def UpdateFillByValue(self, value): 283 dots = [ each for each in self.children if each.name == 'fillDot' ] 284 if self._invertedValue: 285 totalVisible = len(dots) * (1.0 - value) 286 for i, dot in enumerate(dots): 287 if i > totalVisible: 288 dot.state = uiconst.UI_DISABLED 289 else: 290 dot.state = uiconst.UI_HIDDEN 291 292 else: 293 totalVisible = len(dots) * value 294 for i, dot in enumerate(dots): 295 if i < totalVisible: 296 dot.state = uiconst.UI_DISABLED 297 else: 298 dot.state = uiconst.UI_HIDDEN 299 300 def InvertSlider(self): 301 self._invertedValue = True 302 303 def SetRotationCenterOffset(self, x = 0, y = 0): 304 self.centerOffset = (x, y) 305 306 def SetRotationRange(self, fromAngle, rotationRange): 307 toAngle = self.ClampAngle(fromAngle + rotationRange) 308 self.rotationRange = (fromAngle, toAngle, rotationRange) 309 310 def GetRotationAngleFromCenterToMouse(self): 311 x, y = uicore.uilib.x, uicore.uilib.y 312 l, t, w, h = self.GetAbsolute() 313 ox, oy = self.centerOffset 314 px, py = l + ox, t + oy 315 tn = (abs(x - px) or 1e-07) / float(abs(y - py) or 1e-07) 316 if y < py: 317 if x > px: 318 rot = math.pi * 0.5 + math.atan(tn) 319 else: 320 rot = math.pi * 0.5 - math.atan(tn) 321 elif x > px: 322 rot = math.pi * 1.5 - math.atan(tn) 323 else: 324 rot = math.pi * 1.5 + math.atan(tn) 325 return rot 326 327 def UpdateMarkerPosition(self, jump = False): 328 angle = self.GetRotationAngleFromCenterToMouse() 329 fromAngle, toAngle, rotationRange = self.rotationRange 330 if angle < fromAngle and toAngle < angle: 331 fromDiff = abs(angle - fromAngle) 332 toDiff = abs(angle - toAngle) 333 if fromDiff < toDiff: 334 angle = fromAngle 335 else: 336 angle = toAngle 337 if fromAngle + rotationRange > math.pi * 2 and 0.0 < angle <= toAngle: 338 angle += math.pi * 2 339 portion = (angle - fromAngle) / rotationRange 340 if self._invertedValue: 341 portion = 1.0 - portion 342 nonIncrementedValue = None 343 if self.increments: 344 nonIncrementedValue = portion 345 portion = self.FindIncrementValue(portion) 346 self.SetValue(portion, jump, nonIncrementedValue) 347 348 def FindIncrementValue(self, fromValue): 349 if fromValue < 0: 350 return self.increments[0] 351 if fromValue > 1.0: 352 return self.increments[-1] 353 nextStep = 0.0 354 for i, step in enumerate(self.increments): 355 if i != len(self.increments) - 1: 356 nextStep = self.increments[i + 1] 357 if step <= fromValue <= nextStep: 358 if abs(step - fromValue) < abs(nextStep - fromValue): 359 return step 360 else: 361 return nextStep 362 363 return nextStep 364 365 def ClampAngle(self, angle): 366 if angle > math.pi * 2: 367 angle -= math.pi * 2 368 elif angle < 0: 369 angle += math.pi * 2 370 return angle 371 372 def GetValue(self): 373 return self._value 374 375 def SetValue(self, value, jump = False, nonIncrementedValue = None): 376 value = min(1.0, max(0.0, value)) 377 if nonIncrementedValue is not None: 378 nonIncrementedValue = min(1.0, max(0.0, nonIncrementedValue)) 379 self._value = value 380 niSetAngle = None 381 fromAngle, toAngle, rotationRange = self.rotationRange 382 if self._invertedValue: 383 setAngle = self.ClampAngle(fromAngle + rotationRange - rotationRange * value) 384 if nonIncrementedValue: 385 niSetAngle = self.ClampAngle(fromAngle + rotationRange - rotationRange * nonIncrementedValue) 386 else: 387 setAngle = self.ClampAngle(fromAngle + rotationRange * value) 388 if nonIncrementedValue: 389 niSetAngle = self.ClampAngle(fromAngle + rotationRange * nonIncrementedValue) 390 self.MoveMarkerByAngle(setAngle, niSetAngle) 391 if self._lastCallbackValue != value: 392 self._lastCallbackValue = value 393 self.UpdateFillByValue(value) 394 395 def _OnSetValue(self, ctrl, stopvalue): 396 if stopvalue in self.incrementStopToValue: 397 self.OnSetValue(self, self.incrementStopToValue[stopvalue]) 398 else: 399 self.OnSetValue(self, stopvalue) 400 401 def OnSetValue(self, ctrl, value): 402 pass 403 404 def MoveMarkerByAngle(self, radianAngle, nonIncrementAngle = None): 405 l, t, w, h = self.GetAbsolute() 406 ox, oy = self.centerOffset 407 radius = self.textureRadius 408 cos = math.cos(radianAngle + math.pi) 409 sin = math.sin(radianAngle + math.pi) 410 left = int(radius * cos) + ox - self.marker.width / 2 411 top = int(radius * sin) + oy - self.marker.height / 2 412 self.marker.SetPosition(left, top) 413 if nonIncrementAngle is not None: 414 cos = math.cos(nonIncrementAngle + math.pi) 415 sin = math.sin(nonIncrementAngle + math.pi) 416 left = int(radius * cos) + ox - self.ghostMarker.width / 2 417 top = int(radius * sin) + oy - self.ghostMarker.height / 2 418 self.ghostMarker.SetPosition(left, top) 419 self.ghostMarker.state = uiconst.UI_DISABLED 420 else: 421 self.ghostMarker.state = uiconst.UI_HIDDEN