class TabUnderlay(Container): """ Underlay used for tab group buttons. Color is affected by "Background color" setting """ default_fixedColor = None default_isSelected = False default_clipChildren = True OPACITY_IDLE = 0.0 OPACITY_HOVER = 2.0 OPACITY_MOUSEDOWN = 3.0 OPACITY_BLINK = 6.0 OPACITY_SELECTED = 2.0 def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.fixedColor = attributes.Get('color', self.default_fixedColor) self.isSelected = attributes.get('isSelected', self.default_isSelected) self.bgCont = Container(name='bgCont', bgParent=self, opacity=self.OPACITY_IDLE, state=uiconst.UI_DISABLED, idx=0) StretchSpriteVerticalThemeColored( name='edgeGlow', bgParent=self.bgCont, texturePath='res:/UI/Texture/shared/buttonEdgeGlowFrameBottom.png', colorType=uiconst.COLORTYPE_UIHILIGHT, blendMode=trinity.TR2_SBM_ADD, opacity=0.5, color=self.fixedColor, topEdgeSize=1, bottomEdgeSize=1) SpriteThemeColored(name='buttonGlow', bgParent=self.bgCont, texturePath='res:/UI/Texture/shared/buttonGlow.png', colorType=uiconst.COLORTYPE_UIHILIGHT, padding=-14, opacity=0.15, color=self.fixedColor) colorType = uiconst.COLORTYPE_UIBASECONTRAST if self.isSelected else uiconst.COLORTYPE_UIBASE self.underlay = FillThemeColored(bgParent=self, name='tabBackground', colorType=colorType, opacity=0.7) def SetFixedColor(self, fixedColor): self.fixedColor = fixedColor self.frame.SetFixedColor(fixedColor) def GetHoverColor(self): if self.fixedColor: return self.fixedColor return sm.GetService('uiColor').GetUIColor( uiconst.COLORTYPE_UIBASECONTRAST) def OnMouseEnter(self, *args): if self.isSelected: return color = self.GetHoverColor() self.underlay.colorType = uiconst.COLORTYPE_UIBASECONTRAST uicore.animations.SpColorMorphTo(self.underlay, endColor=color, duration=0.15, includeAlpha=False) uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_HOVER, duration=0.15) def OnMouseExit(self, *args): if self.isSelected: uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_SELECTED, duration=0.5) else: uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_IDLE, duration=0.5) color = sm.GetService('uiColor').GetUIColor( uiconst.COLORTYPE_UIBASE) self.underlay.colorType = uiconst.COLORTYPE_UIBASE self.underlay.fixedColor = None uicore.animations.SpColorMorphTo(self.underlay, endColor=color, duration=0.5, includeAlpha=False) def OnMouseDown(self, *args): if not self.isSelected: uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_MOUSEDOWN, duration=0.1) else: uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_SELECTED, duration=0.1) def OnMouseUp(self, *args): uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_HOVER, duration=0.3) def Blink(self, loops=1): uicore.animations.FadeTo(self.bgCont, self.OPACITY_BLINK, self.OPACITY_IDLE, curveType=uiconst.ANIM_WAVE, duration=0.8, loops=loops) def StopBlink(self): uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_IDLE, duration=0.3) def Select(self): if self.isSelected: return self.underlay.StopAnimations() if self.fixedColor: self.underlay.SetFixedColor(self.fixedColor) else: self.underlay.SetColorType(uiconst.COLORTYPE_UIBASECONTRAST) uicore.animations.FadeTo(self.bgCont, self.bgCont.opacity, self.OPACITY_SELECTED, duration=0.15) self.underlay.opacity = 0.7 self.isSelected = True def Deselect(self): if not self.isSelected: return self.underlay.opacity = 0.4 self.isSelected = False self.OnMouseExit()
class Switch(Container): default_state = uiconst.UI_NORMAL default_align = uiconst.TOPLEFT default_width = 30 default_height = 10 def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.isEnabled = attributes.get('isEnabled', True) self.disabled = False FrameThemeColored(parent=self) btnCont = Container(parent=self) self.onBtn = Container(parent=self, align=uiconst.TOLEFT_PROP, width=0.5, bgColor=COLOR_GREEN, state=uiconst.UI_DISABLED) self.offBtn = Container(parent=self, align=uiconst.TORIGHT_PROP, width=0.5, bgColor=COLOR_RED, state=uiconst.UI_DISABLED) self.knob = FillThemeColored(parent=btnCont, align=uiconst.TOLEFT_PROP, width=0.5, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHEADER, opacity=1.0) self.SetStateNotAnimated() def SetStateNotAnimated(self): if self.isEnabled: self.knob.left = self.width / 2 else: self.knob.left = 0 def OnClick(self, *args): if self.disabled: return self.isEnabled = not self.isEnabled self.UpdateKnob() def UpdateKnob(self): if self.isEnabled: self.knob.StopAnimations() animations.MorphScalar(self.knob, 'left', startVal=self.knob.left, endVal=self.width / 2, duration=0.1) else: animations.MorphScalar(self.knob, 'left', startVal=self.knob.left, endVal=0, duration=0.1) def SetOnline(self): self.isEnabled = True self.UpdateKnob() def SetOffline(self): self.isEnabled = False self.UpdateKnob() def Close(self): super(Switch, self).Close() def Disable(self): self.disabled = True self.opacity = 0.5 if self.isEnabled: self.offBtn.opacity = 0.0 else: self.onBtn.opacity = 0.0 def Enable(self): self.disabled = False self.opacity = 1.0