backButton.py (7462B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\empireui\backButton.py 2 from carbonui import uiconst 3 from carbonui.control.buttonIcon import ButtonIcon 4 from carbonui.primitives.frame import Frame 5 from carbonui.uicore import uicore 6 from carbonui.primitives.container import Container 7 import charactercreator.client.scalingUtils as ccScalingUtils 8 from eve.client.script.ui.control.glowSprite import GlowSprite 9 from eve.client.script.ui.control.themeColored import FrameThemeColored 10 from eve.client.script.ui.login.charcreation.label import CCLabel 11 from eve.client.script.ui.login.charcreation.technologyViewUtils import TECH_NAV_ARROW_SIZE 12 from eve.client.script.ui.util.uix import GetTextWidth 13 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar 14 from localization import GetByLabel 15 from math import pi 16 ARROW_TEXTURE = 'res:/UI/Texture/Classes/EmpireSelection/navArrow_Up.png' 17 ARROW_TEXTURE_OVER = 'res:/UI/Texture/Classes/EmpireSelection/navArrow_Over.png' 18 ARROW_TEXTURE_DOWN = 'res:/UI/Texture/Classes/EmpireSelection/navArrow_Down.png' 19 BACK_BUTTON_UP_TEXTURE = 'res:/UI/Texture/Classes/EmpireSelection/largeButton_Up.png' 20 BACK_BUTTON_DOWN_TEXTURE = 'res:/UI/Texture/Classes/EmpireSelection/largeButton_Over.png' 21 BACK_BUTTON_OVER_TEXTURE = 'res:/UI/Texture/Classes/EmpireSelection/largeButton_Down.png' 22 ARROW_ICON_SIZE = 24.5 23 BACK_BUTTON_FONTSIZE = 12 24 BACK_BUTTON_ARROW_TEXT_PADDING = 4 25 BACK_BUTTON_ARROW_LEFT_PADDING_RATIO = 0.35 26 BACK_BUTTON_OPACITY = 1.0 27 BACK_BUTTON_TINT_BY_RACE = {raceAmarr: (0.51, 0.44, 0.32), 28 raceCaldari: (0.29, 0.43, 0.5), 29 raceGallente: (0.21, 0.4, 0.4), 30 raceMinmatar: (0.4, 0.22, 0.2)} 31 BACK_BUTTON_LABEL = 'UI/Commands/Back' 32 BUTTON_HOVER_SOUND = 'ui_icc_button_mouse_over_play' 33 BUTTON_SELECT_SOUND = 'ui_icc_button_select_play' 34 35 class BackButton(ButtonIcon): 36 default_iconColor = (1.0, 1.0, 1.0, 1.0) 37 default_iconSize = TECH_NAV_ARROW_SIZE 38 default_rotation = pi 39 default_isBGFrameUsed = True 40 default_isHoverBGUsed = True 41 default_showGlow = False 42 default_texturePath = ARROW_TEXTURE 43 default_hoverTexture = ARROW_TEXTURE_OVER 44 default_downTexture = ARROW_TEXTURE_DOWN 45 default_mouseUpBGTexture = BACK_BUTTON_UP_TEXTURE 46 default_mouseEnterBGTexture = BACK_BUTTON_OVER_TEXTURE 47 default_mouseDownBGTexture = BACK_BUTTON_DOWN_TEXTURE 48 default_frameCornerSize = 7 49 default_frameOffset = 0 50 51 def ApplyAttributes(self, attributes): 52 self.mouseUpBGTexture = attributes.Get('mouseUpBGTexture', self.default_mouseUpBGTexture) 53 self.mouseEnterBGTexture = attributes.Get('mouseEnterBGTexture', self.default_mouseEnterBGTexture) 54 self.mouseDownBGTexture = attributes.Get('mouseDownBGTexture', self.default_mouseDownBGTexture) 55 self.isBGFrameUsed = attributes.Get('isBGFrameUsed', self.default_isBGFrameUsed) 56 self.frameOffset = attributes.Get('frameOffset', self.default_frameOffset) 57 self.frameCornerSize = attributes.Get('frameCornerSize', self.default_frameCornerSize) 58 self.bgRotation = attributes.Get('bgRotation', self.default_bgRotation) 59 self.mouseUpBG = None 60 self.mouseEnterBG = None 61 self.mouseDownBG = None 62 super(BackButton, self).ApplyAttributes(attributes) 63 raceID = attributes.Get('raceID', None) 64 r, g, b = BACK_BUTTON_TINT_BY_RACE[raceID] 65 color = (r, 66 g, 67 b, 68 BACK_BUTTON_OPACITY) 69 self.SetColor(color) 70 backText = GetByLabel(BACK_BUTTON_LABEL) 71 backTextFontsize = BACK_BUTTON_FONTSIZE * ccScalingUtils.GetScaleFactor() 72 backStringWidth = GetTextWidth(backText, fontsize=backTextFontsize, uppercase=1, hspace=1) 73 labelContainer = Container(name='labelContainer', parent=self, align=uiconst.TOTOP_NOPUSH, width=self.width, height=self.height) 74 backLabel = CCLabel(text=backText, name='backLabel', parent=labelContainer, align=uiconst.CENTERLEFT, uppercase=1, bold=False, fontsize=backTextFontsize) 75 margin = BACK_BUTTON_ARROW_TEXT_PADDING * ccScalingUtils.GetScaleFactor() 76 self.icon.align = uiconst.CENTERLEFT 77 contentsWidth = self.iconSize + backStringWidth + margin 78 freeSpace = max(0, self.width - contentsWidth) 79 iconLeft = freeSpace * BACK_BUTTON_ARROW_LEFT_PADDING_RATIO 80 self.icon.left = iconLeft 81 backLabel.left = iconLeft + self.iconSize + margin 82 83 def ConstructIcon(self): 84 iconContainer = Container(name='iconContainer', parent=self, width=self.width, height=self.height, align=uiconst.TOTOP_NOPUSH) 85 self.icon = GlowSprite(name='icon', parent=iconContainer, align=uiconst.CENTER, width=self.iconSize, height=self.iconSize, texturePath=self.texturePath, state=uiconst.UI_DISABLED, color=self.iconColor, iconOpacity=self.iconDisabledOpacity, gradientStrength=self.iconDisabledOpacity, rotation=self.rotation) 86 if self.isBGFrameUsed and self.mouseUpBGTexture: 87 self.mouseUpBG = Frame(name='bg_frame', texturePath=self.mouseUpBGTexture, offset=self.frameOffset, cornerSize=self.frameCornerSize, parent=self, align=uiconst.TOTOP_NOPUSH, width=self.width, height=self.height, rotation=self.bgRotation, color=(1.0, 1.0, 1.0, 0.5)) 88 89 def ConstructBackground(self): 90 if self.mouseEnterBGTexture and self.mouseDownBGTexture: 91 self.mouseEnterBG = FrameThemeColored(name='mouseEnterBG', bgParent=self.bgContainer, texturePath=self.mouseEnterBGTexture, width=self.width, height=self.height, opacity=0.0, colorType=uiconst.COLORTYPE_UIHILIGHT, rotation=self.bgRotation, cornerSize=self.frameCornerSize) 92 self.mouseDownBG = FrameThemeColored(name='mouseDownBG', bgParent=self.bgContainer, texturePath=self.mouseDownBGTexture, width=self.width, height=self.height, opacity=0.0, colorType=uiconst.COLORTYPE_UIHILIGHT, rotation=self.bgRotation, cornerSize=self.frameCornerSize) 93 return 94 super(BackButton, self).ConstructBackground() 95 96 def OnMouseDown(self, *args): 97 if not self.enabled: 98 return 99 if self.isHoverBGUsed: 100 uicore.animations.FadeTo(self.mouseDownBG, self.mouseDownBG.opacity, 1.0, duration=0.1, callback=self.ShowMouseDownBG) 101 uicore.animations.FadeOut(self.mouseEnterBG, duration=0.1) 102 self.UpdateIconState() 103 104 def OnMouseUp(self, *args): 105 if self.isHoverBGUsed: 106 uicore.animations.FadeOut(self.mouseDownBG, duration=0.1) 107 if not self.enabled: 108 return 109 self.UpdateIconState() 110 if uicore.uilib.mouseOver == self: 111 if self.isHoverBGUsed: 112 uicore.animations.FadeIn(self.mouseEnterBG, 0.5, duration=0.1, callback=self.ShowMouseEnterBG) 113 114 def ShowMouseEnterBG(self): 115 self.mouseEnterBG.opacity = 1.0 116 117 def ShowMouseDownBG(self): 118 self.mouseDownBG.opacity = 1.0 119 120 def SetColor(self, color): 121 if self.mouseUpBG: 122 self.mouseUpBG.color = color 123 if self.mouseEnterBG: 124 self.mouseEnterBG.SetFixedColor(color) 125 if self.mouseDownBG: 126 self.mouseDownBG.SetFixedColor(color) 127 128 def OnMouseEnter(self, *args): 129 super(BackButton, self).OnMouseEnter() 130 sm.GetService('audio').SendUIEvent(BUTTON_HOVER_SOUND) 131 132 def OnClick(self, *args): 133 sm.GetService('audio').SendUIEvent(BUTTON_SELECT_SOUND) 134 uicore.layer.charactercreation.controller.Back()