charCreationButtons.py (17482B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\charCreationButtons.py 2 import trinity 3 import carbonui.const as uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.frame import Frame 6 from carbonui.primitives.gradientSprite import GradientSprite 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.uianimations import animations 9 from carbonui.uicore import uicore 10 from carbonui.util.color import Color 11 from charactercreator.client.empireSelectionData import GetEmpireColor, GetEmpireLogo, GetEmpireButtonLogo 12 import charactercreator.client.scalingUtils as ccScalingUtils 13 import charactercreator.const as ccConst 14 from eve.client.script.ui import eveColor 15 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar 16 from localization import GetByLabel 17 EXIT_BUTTON_SIZE = 16 18 TEMP_RACE_BUTTON_NORMAL = 'res:/UI/Texture/CharacterCreation/raceButtons/RaceButtonNormal_%s.dds' 19 TEMP_RACE_BUTTON_DOWN = 'res:/UI/Texture/CharacterCreation/raceButtons/RaceButtonDown_%s.dds' 20 BLOODLINE_HEADERS = {raceAmarr: GetByLabel('UI/Login/CharacterCreation/BloodlineSelection/AmarrBloodlines'), 21 raceCaldari: GetByLabel('UI/Login/CharacterCreation/BloodlineSelection/CaldariBloodlines'), 22 raceGallente: GetByLabel('UI/Login/CharacterCreation/BloodlineSelection/GallenteBloodlines'), 23 raceMinmatar: GetByLabel('UI/Login/CharacterCreation/BloodlineSelection/MinmatarBloodlines')} 24 EMPIRE_TAB_BUTTON_OPACITY = 0.3 25 EMPIRE_TAB_BUTTON_TEXTURE_ACTIVE = 'res:/UI/Texture/classes/EmpireSelection/empireTabActive.png' 26 EMPIRE_TAB_BUTTON_TEXTURE_ACTIVE_GLOW = 'res:/UI/Texture/classes/EmpireSelection/empireTabActiveGlow.png' 27 EMPIRE_TAB_BUTTON_TEXTURE_INACTIVE = 'res:/UI/Texture/classes/EmpireSelection/empireTabInactive.png' 28 HEADER_SPOTLIGHT_HEIGHT_FACTOR = 1.6 29 EMPIRE_TAB_ICON_SIZE = 160 30 EMPIRE_ICON_SIZE_ACTIVE = 84 31 EMPIRE_ICON_PAD = 3 32 EMPIRE_ICON_GLOW_WIDTH = 64 33 EMPIRE_ICON_GLOW_HEIGHT = 17 34 EMPIRE_ICON_GRADIENT_HEIGHT = 1 35 EMPIRE_ICON_FRAME_ACTIVE_OPACITY = 1.0 36 EMPIRE_ICON_FRAME_INACTIVE_OPACITY = 0.6 37 EMPIRE_ICON_FRAME_HOVER_OPACITY = 1.5 38 EMPIRE_ICON_FRAME_DOWN_OPACITY = 3.0 39 EMPIRE_ICON_FRAME_GLOW_OPACITY = 1.0 40 EMPIRE_ICON_FRAME_GRADIENT_OPACITY = 1.0 41 42 def GetEmpireTabSizeLarge(): 43 return EMPIRE_ICON_SIZE_ACTIVE * ccScalingUtils.GetScaleFactor() 44 45 46 class BaseCCButton(Container): 47 __guid__ = 'uicls.BaseCCButton' 48 default_state = uiconst.UI_NORMAL 49 default_left = 0 50 default_top = 0 51 default_width = 128 52 default_height = 128 53 default_align = uiconst.CENTER 54 mouseoverSound = 'ui_icc_button_mouse_over_play' 55 selectSound = 'ui_icc_button_select_play' 56 57 def ApplyAttributes(self, attributes): 58 Container.ApplyAttributes(self, attributes) 59 spriteWidth = attributes.Get('spriteWidth', self.default_width) 60 spriteHeight = attributes.Get('spriteHeight', self.default_height) 61 self.normalSprite = Sprite(name='normalSprite', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, texturePath='', width=spriteWidth, height=spriteHeight) 62 self.hiliteSprite = Sprite(name='hiliteSprite', parent=self, align=uiconst.CENTER, state=uiconst.UI_HIDDEN, texturePath='', width=spriteWidth, height=spriteHeight) 63 self.normalSprite.SetAlpha(0.3) 64 65 def OnMouseEnter(self, *args): 66 if self.mouseoverSound: 67 sm.StartService('audio').SendUIEvent(unicode(self.mouseoverSound)) 68 self.normalSprite.SetAlpha(0.6) 69 70 def OnMouseExit(self, *args): 71 self.normalSprite.SetAlpha(0.3) 72 73 def Deselect(self): 74 self.hiliteSprite.state = uiconst.UI_HIDDEN 75 self.normalSprite.state = uiconst.UI_DISABLED 76 self.normalSprite.SetAlpha(0.3) 77 78 def Select(self): 79 if self.selectSound: 80 sm.StartService('audio').SendUIEvent(unicode(self.selectSound)) 81 self.hiliteSprite.state = uiconst.UI_DISABLED 82 self.normalSprite.state = uiconst.UI_HIDDEN 83 84 def OnClick(self, *args): 85 pass 86 87 88 class RaceButton(BaseCCButton): 89 __guid__ = 'uicls.RaceButton' 90 default_left = 0 91 default_top = 0 92 default_width = 256 93 default_height = 256 94 95 def ApplyAttributes(self, attributes): 96 BaseCCButton.ApplyAttributes(self, attributes) 97 self.raceID = attributes.raceID 98 self.mouseExitCallback = attributes.mouseExitCallback 99 self.normalSprite.texture.resPath = 'res:/UI/Texture/CharacterCreation/raceButtons/RaceButtonNormal_%s.dds' % self.raceID 100 self.hiliteSprite.texture.resPath = 'res:/UI/Texture/CharacterCreation/raceButtons/RaceButtonDown_%s.dds' % self.raceID 101 102 def OnMouseEnter(self, *args): 103 BaseCCButton.OnMouseEnter(self, *args) 104 info = uicore.layer.charactercreation.controller.GetInfo() 105 if not info.raceID: 106 uicore.layer.charactercreation.controller.UpdateBackdropLite(raceID=self.raceID, mouseEnter=True) 107 108 def OnMouseExit(self, *args): 109 BaseCCButton.OnMouseExit(self, *args) 110 info = uicore.layer.charactercreation.controller.GetInfo() 111 if not info.raceID: 112 uicore.layer.charactercreation.controller.UpdateBackdropLite(raceID=None, mouseEnter=True) 113 if self.mouseExitCallback is not None: 114 self.mouseExitCallback() 115 116 def OnClick(self, *args): 117 if uicore.layer.charactercreation.controller.raceID != self.raceID: 118 uicore.layer.charactercreation.controller.SelectRace(self.raceID) 119 120 def OnDblClick(self, *args): 121 uicore.layer.charactercreation.controller.Approve() 122 123 124 class GenderButton(BaseCCButton): 125 __guid__ = 'uicls.GenderButton' 126 default_left = 0 127 default_top = 0 128 default_width = 64 129 default_height = 64 130 selectSound = None 131 mouseoverSound = None 132 133 def ApplyAttributes(self, attributes): 134 BaseCCButton.ApplyAttributes(self, attributes) 135 self.raceID = attributes.raceID 136 self.genderID = attributes.genderID 137 if self.genderID == ccConst.GENDERID_FEMALE: 138 gender = 'Female' 139 else: 140 gender = 'Male' 141 self.normalSprite.texture.resPath = 'res:/UI/Texture/classes/EmpireSelection/gender%s.png' % gender 142 self.hiliteSprite.texture.resPath = 'res:/UI/Texture/classes/EmpireSelection/gender%sSelected.png' % gender 143 144 def OnClick(self, *args): 145 if uicore.layer.charactercreation.controller.genderID != self.genderID: 146 uicore.layer.charactercreation.controller.SelectGender(self.genderID) 147 148 def HoverInHighlighted(self): 149 self.Deselect() 150 self.normalSprite.SetAlpha(1.0) 151 self.Show() 152 153 def HoverIn(self): 154 self.Deselect() 155 self.normalSprite.SetAlpha(0.25) 156 self.Show() 157 158 def HoverOut(self): 159 self.Deselect() 160 self.normalSprite.Hide() 161 162 def OnDblClick(self, *args): 163 uicore.layer.charactercreation.controller.Approve() 164 165 def Resize(self, width, height): 166 self.width = width 167 self.height = height 168 self.normalSprite.width = width 169 self.normalSprite.height = height 170 self.hiliteSprite.width = width 171 self.hiliteSprite.height = height 172 173 174 class EmpireTabAnimationType: 175 ACTIVATE = 1 176 DEACTIVATE = 2 177 HOVER = 3 178 DEHOVER = 4 179 180 181 class EmpireTabButton(BaseCCButton): 182 selectSound = None 183 mouseoverSound = None 184 185 def ApplyAttributes(self, attributes): 186 self.isActive = attributes.isActive 187 self.isHovered = False 188 tabSize = GetEmpireTabSizeLarge() 189 attributes.spriteWidth = tabSize 190 attributes.spriteHeight = tabSize 191 super(EmpireTabButton, self).ApplyAttributes(attributes) 192 self.raceSetter = attributes.raceSetter 193 self.raceHoverer = attributes.raceHoverer 194 self.raceID = attributes.raceID 195 self.isDisabled = attributes.get('isDisabled', False) 196 r, g, b, _ = GetEmpireColor(self.raceID) 197 self.buttonLogo = Sprite(name='buttonLogo', texturePath=GetEmpireButtonLogo(self.raceID), parent=self, width=tabSize, height=tabSize, state=uiconst.UI_DISABLED, align=uiconst.CENTER, opacity=float(not self.isActive)) 198 self.empireLogo = Sprite(name='empireLogo', texturePath=GetEmpireLogo(self.raceID), parent=self, width=tabSize, height=tabSize, state=uiconst.UI_DISABLED, align=uiconst.CENTER, opacity=float(self.isActive)) 199 self.BuildFrames() 200 201 def BuildFrames(self): 202 scaleFactor = ccScalingUtils.GetScaleFactor() 203 r, g, b, _ = GetEmpireColor(self.raceID) 204 tabSize = GetEmpireTabSizeLarge() 205 self.frameGradientContainer = Container(parent=self, name='frameGradientContainer', align=uiconst.TOTOP_NOPUSH, width=tabSize, height=tabSize) 206 self.frameGradient = GradientSprite(parent=self.frameGradientContainer, name='frameGradient', align=uiconst.CENTERBOTTOM, width=tabSize, height=EMPIRE_ICON_GRADIENT_HEIGHT, rgbData=[(0, (1.0, 1.0, 1.0))], alphaData=[(0, 0.0), 207 (0.4, 0.5), 208 (0.6, 0.5), 209 (1.0, 0.0)], opacity=EMPIRE_ICON_FRAME_GRADIENT_OPACITY * self.isActive) 210 self.frameGlowContainer = Container(parent=self, name='frameGlowContainer', align=uiconst.TOTOP_NOPUSH, width=tabSize, height=tabSize) 211 self.frameGlow = Frame(parent=self.frameGlowContainer, name='frameGlow', align=uiconst.CENTERBOTTOM, width=EMPIRE_ICON_GLOW_WIDTH * scaleFactor, height=EMPIRE_ICON_GLOW_HEIGHT * scaleFactor, texturePath=EMPIRE_TAB_BUTTON_TEXTURE_ACTIVE_GLOW, color=(r, 212 g, 213 b, 214 EMPIRE_ICON_FRAME_GLOW_OPACITY * self.isActive)) 215 self.frameActiveContainer = Container(parent=self, name='frameActiveContainer', align=uiconst.TOTOP_NOPUSH, width=tabSize, height=tabSize) 216 self.frameActive = Frame(parent=self.frameActiveContainer, name='frameActive', align=uiconst.TOALL, texturePath=EMPIRE_TAB_BUTTON_TEXTURE_ACTIVE, color=(r, 217 g, 218 b, 219 EMPIRE_ICON_FRAME_ACTIVE_OPACITY * self.isActive)) 220 self.frameInactiveContainer = Container(parent=self, name='frameInactiveContainer', align=uiconst.TOTOP_NOPUSH, width=tabSize, height=tabSize) 221 self.frameInactive = Frame(parent=self.frameInactiveContainer, name='frameInactive', align=uiconst.TOALL, texturePath=EMPIRE_TAB_BUTTON_TEXTURE_INACTIVE, color=(r, 222 g, 223 b, 224 EMPIRE_ICON_FRAME_INACTIVE_OPACITY)) 225 226 def DesaturateRaceIcon(self): 227 self.buttonLogo.spriteEffect = trinity.TR2_SFX_SOFTLIGHT 228 self.buttonLogo.saturation = 0 229 230 def GetMaximumAllowedLogoOpacity(self): 231 if self.isDisabled: 232 return 0.5 233 return 1.0 234 235 def Activate(self): 236 self.isActive = True 237 self.ActivateFrame() 238 self.buttonLogo.opacity = 0.0 239 self.empireLogo.opacity = 1.0 240 241 def ActivateFrame(self): 242 self.frameActive.opacity = EMPIRE_ICON_FRAME_ACTIVE_OPACITY 243 self.frameGlow.opacity = EMPIRE_ICON_FRAME_GLOW_OPACITY 244 self.frameGradient.opacity = EMPIRE_ICON_FRAME_GRADIENT_OPACITY 245 246 def Deactivate(self): 247 self.isActive = False 248 self.DeactivateFrame() 249 self.buttonLogo.opacity = self.GetMaximumAllowedLogoOpacity() 250 self.empireLogo.opacity = 0.0 251 252 def DeactivateFrame(self): 253 self.frameActive.opacity = 0.0 254 self.frameGlow.opacity = 0.0 255 self.frameGradient.opacity = 0.0 256 257 def Hover(self): 258 self.isHovered = True 259 self.HoverFrame() 260 self.buttonLogo.opacity = self.GetMaximumAllowedLogoOpacity() 261 self.empireLogo.opacity = 0.0 262 263 def HoverFrame(self): 264 self.frameActive.opacity = EMPIRE_ICON_FRAME_HOVER_OPACITY 265 self.frameGlow.opacity = 0.0 266 self.frameGradient.opacity = 0.0 267 268 def Dehover(self): 269 self.isHovered = False 270 self.DeactivateFrame() 271 self.buttonLogo.opacity = self.GetMaximumAllowedLogoOpacity() 272 self.empireLogo.opacity = 0.0 273 274 def OnClick(self): 275 self.raceSetter(self.raceID) 276 277 def OnMouseDown(self, *args): 278 animations.MorphScalar(self.frameActive, 'opacity', self.frameActive.opacity, EMPIRE_ICON_FRAME_DOWN_OPACITY, 0.05) 279 super(EmpireTabButton, self).OnMouseDown(self, *args) 280 281 def OnMouseUp(self, *args): 282 animations.MorphScalar(self.frameActive, 'opacity', self.frameActive.opacity, EMPIRE_ICON_FRAME_ACTIVE_OPACITY, 0.25) 283 super(EmpireTabButton, self).OnMouseUp(self, *args) 284 285 def OnMouseEnter(self): 286 if not self.isActive and not self.isHovered: 287 self.raceHoverer(self.raceID) 288 super(EmpireTabButton, self).OnMouseEnter() 289 290 def OnMouseExit(self): 291 if not self.isActive and self.isHovered: 292 self.raceHoverer(None) 293 super(EmpireTabButton, self).OnMouseExit() 294 295 296 class EmpireTab(Container): 297 default_mouseUpBGTexture = None 298 default_mouseEnterBGTexture = None 299 default_mouseDownBGTexture = None 300 default_isBGFrameUsed = None 301 default_frameOffset = 0 302 default_frameCornerSize = 0 303 304 def ApplyAttributes(self, attributes): 305 self.isActive = attributes.Get('isActive', False) 306 self.isHovered = attributes.Get('isActive', False) 307 self.raceID = attributes.Get('raceID', None) 308 self.raceSetter = attributes.Get('raceSetter', None) 309 self.raceHoverer = attributes.Get('raceHoverer', None) 310 self.empireLogoPath = attributes.Get('empireLogoPath', None) 311 self.isDisabled = attributes.Get('isDisabled', False) 312 super(EmpireTab, self).ApplyAttributes(attributes) 313 self.iconSize = self.width / 2.0 314 tabSize = GetEmpireTabSizeLarge() 315 self.buttonContainer = Container(parent=self, align=uiconst.BOTTOMLEFT, width=self.width, height=self.height) 316 self.button = EmpireTabButton(parent=self.buttonContainer, width=tabSize, height=tabSize, raceID=self.raceID, align=uiconst.BOTTOMLEFT, raceSetter=self.raceSetter, raceHoverer=self.raceHoverer, isActive=self.isActive, isDisabled=self.isDisabled) 317 self.gradientFill = None 318 self.gradientBgFill = None 319 self.width = tabSize 320 self.height = tabSize 321 if self.isDisabled: 322 Sprite(name='warningIcon', parent=self.buttonContainer, align=uiconst.BOTTOMLEFT, width=26, height=26, left=5, texturePath='res:/UI/Texture/classes/agency/iconExclamation.png', color=eveColor.WARNING_ORANGE, state=uiconst.UI_NORMAL, hint=GetByLabel('UI/CharacterCreation/FactionDisabled')) 323 self.button.Disable() 324 self.button.DesaturateRaceIcon() 325 326 def Activate(self): 327 self.isActive = True 328 self.button.Activate() 329 330 def Deactivate(self): 331 self.isActive = False 332 self.button.Deactivate() 333 334 def Hover(self): 335 self.isHovered = True 336 self.button.Hover() 337 338 def Dehover(self): 339 self.isHovered = False 340 self.button.Dehover() 341 342 343 class BloodlineButton(BaseCCButton): 344 __guid__ = 'uicls.BloodlineButton' 345 default_width = 185 346 default_height = 140 347 348 def ApplyAttributes(self, attributes): 349 BaseCCButton.ApplyAttributes(self, attributes) 350 self.bloodlineID = attributes.bloodlineID 351 self.mouseEnterCallback = attributes.mouseEnterCallback 352 self.mouseExitCallback = attributes.mouseExitCallback 353 self.normalSprite.texture.resPath = 'res:/UI/Texture/CharacterCreation/bloodlineButtons/Bloodline_Normal_%d.png' % self.bloodlineID 354 self.normalSprite.top = 6 355 self.hiliteSprite.texture.resPath = 'res:/UI/Texture/CharacterCreation/bloodlineButtons/Bloodline_Down_%d.png' % self.bloodlineID 356 self.hiliteSprite.top = 6 357 358 def OnClick(self, *args): 359 if uicore.layer.charactercreation.controller.bloodlineID != self.bloodlineID: 360 uicore.layer.charactercreation.controller.SelectBloodline(self.bloodlineID) 361 362 def OnMouseEnter(self, *args): 363 if self.mouseEnterCallback is not None: 364 self.mouseEnterCallback(self.bloodlineID) 365 366 def OnMouseEnterAppearanceChange(self, *args): 367 BaseCCButton.OnMouseEnter(self, *args) 368 369 def OnMouseExit(self, *args): 370 BaseCCButton.OnMouseExit(self, *args) 371 if self.mouseExitCallback is not None: 372 self.mouseExitCallback() 373 374 375 class StaticBloodlineButton(Container): 376 __guid__ = 'uicls.SmallerBloodlineButton' 377 default_width = 125 378 default_height = 100 379 380 def ApplyAttributes(self, attributes): 381 iconTexturePath = attributes.iconTexturePath 382 super(StaticBloodlineButton, self).ApplyAttributes(attributes) 383 self.bloodlineID = attributes.bloodlineID 384 self.sprite = Sprite(parent=self, align=uiconst.CENTER, texturePath=iconTexturePath, width=self.width, height=self.height) 385 386 def Resize(self, width, height): 387 self.width = width 388 self.height = height 389 self.sprite.width = width 390 self.sprite.height = height 391 392 393 class ExitButton(Container): 394 default_name = 'exitButton' 395 default_width = EXIT_BUTTON_SIZE 396 default_height = EXIT_BUTTON_SIZE 397 default_state = uiconst.UI_NORMAL 398 399 def ApplyAttributes(self, attributes): 400 Container.ApplyAttributes(self, attributes) 401 self.onClick = attributes.onClick 402 width = attributes.Get('width', self.default_width) 403 height = attributes.Get('height', self.default_height) 404 Sprite(parent=self, texturePath='res:/UI/Texture/Icons/73_16_45.png', width=width, height=height, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=Color.GRAY7) 405 406 def OnClick(self): 407 self.onClick()