class InfoPanelHeaderBackground(Container): BGCOLOR = (1, 1, 1, 0.15) def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) self.colorFill = Fill(bgParent=self, color=attributes.color or self.BGCOLOR) self.shadow = Frame(bgParent=self, frameConst=FRAME_SOFTSHADE, color=(0, 0, 0, 0.25), padding=(-10, -10, -10, -10)) def SetBackgroundColor(self, *color): self.colorFill.SetRGBA(*color)
class BroadcastSettingsEntry(listentry.Checkbox): colorList = [(1.0, 0.7, 0.0), (1.0, 0.35, 0.0), (0.75, 0.0, 0.0), (0.1, 0.6, 0.1), (0.0, 0.63, 0.57), (0.2, 0.5, 1.0), (0.0, 0.15, 0.6), (0.0, 0.0, 0.0), (0.7, 0.7, 0.7)] def Startup(self, *args): listentry.Checkbox.Startup(self, *args) colorPicker = Container(parent=self, pos=(0, 0, 27, 20), name='colorPicker', state=uiconst.UI_NORMAL, align=uiconst.CENTERRIGHT, idx=0) Sprite(parent=colorPicker, pos=(0, 0, 16, 16), name='arrow', align=uiconst.CENTERRIGHT, texturePath='res:/ui/texture/icons/38_16_229.png', color=(1, 1, 1, 0.5), state=uiconst.UI_DISABLED) self.colorCont = Container(parent=colorPicker, name='colorCont', pos=(2, 0, 10, 10), align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED) Frame(parent=self.colorCont, name='colorFrame', color=(1, 1, 1, 0.2)) self.colorFill = Fill(parent=self.colorCont, color=(0, 0, 0, 0)) colorPicker.LoadTooltipPanel = self.LoadColorTooltipPanel colorPicker.GetTooltipPointer = self.GetColorTooltipPointer colorPicker.GetTooltipDelay = self.GetTooltipDelay def Load(self, node): listentry.Checkbox.Load(self, node) if node.colorcoded: fillColor = node.colorcoded + (1, ) self.colorFill.SetRGBA(*fillColor) def GetColorTooltipPointer(self): return uiconst.POINT_LEFT_2 def GetTooltipDelay(self): return 50 def LoadColorTooltipPanel(self, tooltipPanel, *args): currentColor = self.sr.node.colorcoded tooltipPanel.state = uiconst.UI_NORMAL tooltipPanel.margin = (2, 2, 2, 2) def SetBroadcastTypeColorFromPanel(color): self.SetBroadcastTypeColor(color, tooltipPanel) colorPanel = ColorPanel(callback=SetBroadcastTypeColorFromPanel, currentColor=currentColor, colorList=self.colorList) tooltipPanel.AddLabelSmall( text=localization.GetByLabel('UI/Mail/Select Color')) tooltipPanel.AddCell(cellObject=colorPanel) def SetBroadcastTypeColor(self, color, tooltipPanel): settings.user.ui.Set('fleet_broadcastcolor_%s' % self.sr.node.cfgname, color) if color: self.colorFill.SetRGB(*color) self.colorFill.display = True else: self.colorFill.display = False self.sr.node.colorcoded = color sm.ScatterEvent('OnFleetBroadcastFilterChange') tooltipPanel.Close() def _OnResize(self): w, h = self.GetAbsoluteSize() availableWidth = w - self.sr.label.left - self.colorCont.width - 10 textwidth = self.sr.label.textwidth if textwidth > availableWidth: fadeEnd = availableWidth self.sr.label.SetRightAlphaFade(fadeEnd, maxFadeWidth=20) else: self.sr.label.SetRightAlphaFade(0, maxFadeWidth=0)
class SkillEntry(LayoutGridRow): default_name = 'SkillEntry' default_state = uiconst.UI_NORMAL default_showLevel = True isDragObject = True def ApplyAttributes(self, attributes): LayoutGridRow.ApplyAttributes(self, attributes) self.typeID = attributes.typeID self.level = attributes.level self.showLevel = attributes.Get('showLevel', self.default_showLevel) self.bgPattern = Sprite( bgParent=self, align=uiconst.TOALL, padBottom=1, texturePath= 'res:/UI/Texture/Classes/Industry/Output/hatchPattern.png', tileX=True, tileY=True, color=SkillTreeEntry.COLOR_RESTRICTED, opacity=0.0) self.bgFill = Fill(bgParent=self, padBottom=1) leftCont = ContainerAutoSize(padding=(0, 3, 0, 3), align=uiconst.CENTERLEFT) self.icon = Sprite(name='icon', parent=leftCont, align=uiconst.CENTERLEFT, pos=(2, 0, 16, 16), state=uiconst.UI_NORMAL) if self.showLevel: text = GetByLabel('UI/InfoWindow/SkillAndLevelInRoman', skill=self.typeID, levelInRoman=util.IntToRoman(self.level)) else: text = cfg.invtypes.Get(self.typeID).name self.label = Label(name='label', parent=leftCont, align=uiconst.CENTERLEFT, left=self.icon.width + 4, text=text) self.AddCell(leftCont) self.skillBar = SkillLevels(align=uiconst.CENTERRIGHT, typeID=self.typeID) self.AddCell(self.skillBar, cellPadding=(8, 8, 8, 8)) self.UpdateState() def UpdateState(self): mySkill = sm.GetService('skills').MySkills(byTypeID=True).get( self.typeID, None) if mySkill: self.skillBar.SetLevel(mySkill) myLevel = mySkill.skillLevel else: myLevel = None isTrialRestricted = sm.GetService('skills').IsTrialRestricted( self.typeID) if isTrialRestricted: self.icon.SetTexturePath( 'res:/UI/Texture/classes/Skills/trial-restricted-16.png') self.icon.color = SkillTreeEntry.COLOR_RESTRICTED self.icon.state = uiconst.UI_NORMAL self.icon.OnClick = self.OpenSubscriptionPage self.icon.hint = GetByLabel( 'UI/InfoWindow/SkillRestrictedForTrial') self.bgFill.SetRGBA(0.2, 0.1, 0.05, 1.0) self.bgPattern.opacity = 0.15 elif myLevel is None: self.icon.SetTexturePath('res:/UI/Texture/icons/38_16_194.png') self.icon.hint = GetByLabel('UI/InfoWindow/NotTrained') self.bgFill.SetRGBA(*SkillTreeEntry.COLOR_NOTTRAINED) self.skillBar.opacity = 0.4 self.bgPattern.opacity = 0.0 elif myLevel < self.level: self.icon.SetTexturePath('res:/UI/Texture/icons/38_16_195.png') self.icon.hint = GetByLabel( 'UI/InfoWindow/TrainedButNotOfRequiredLevel') self.bgFill.SetRGBA(*SkillTreeEntry.COLOR_PARTIAL) self.skillBar.opacity = 1.0 self.bgPattern.opacity = 0.0 else: self.icon.SetTexturePath('res:/UI/Texture/icons/38_16_193.png') self.icon.hint = GetByLabel( 'UI/InfoWindow/TrainedAndOfRequiredLevel') self.bgFill.SetRGBA(*SkillTreeEntry.COLOR_TRAINED) self.skillBar.opacity = 1.0 self.bgPattern.opacity = 0.0 def GetMenu(self): return sm.GetService('menu').GetMenuForSkill(self.typeID) def OnClick(self): sm.GetService('info').ShowInfo(self.typeID) def GetDragData(self): ret = KeyVal(__guid__='uicls.GenericDraggableForTypeID', typeID=self.typeID, label=cfg.invtypes.Get(self.typeID).name) return (ret, ) def OpenSubscriptionPage(self, *args): sm.GetService('shipTree').OpenSubscriptionPage(['skill', self.typeID])
class ShipGroupIcon(Container): default_name = 'ShipGroupIcon' default_align = uiconst.TOPLEFT default_state = uiconst.UI_DISABLED default_width = 42 default_height = 42 __notifyevents__ = ('OnShipTreeZoomChanged', 'OnShipTreeShipGroupFocused') def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) sm.RegisterNotify(self) self.node = attributes.node if self.node.IsRestricted(): self.bgPattern = Sprite(bgParent=self, aling=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipTree/groups/hatchPattern.png', textureSecondaryPath='res:/UI/Texture/classes/ShipTree/groups/bgVignette.png', spriteEffect=trinity.TR2_SFX_MODULATE, tileX=True, tileY=True, color=(0.965, 0.467, 0.157, 0.4)) self.bgFrame = Frame(name='bgFrame', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/Groups/groupIconFrame.png') self.bgFill = Fill(name='bgFill', bgParent=self, color=shipTreeConst.COLOR_BG) self.bgBlinkFill = None self.icon = Sprite(parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, texturePath=cfg.fsdInfoBubbleGroups[self.node.shipGroupID].icon, color=shipTreeConst.COLOR_HILIGHT, width=32, height=32) def OnShipTreeZoomChanged(self, zoom): self.UpdateState(0, True) def OnShipTreeShipGroupFocused(self, factionID, shipGroupID): if (factionID, shipGroupID) == (self.node.factionID, self.node.shipGroupID): self.Blink() elif self.bgBlinkFill and not self.node.IsBeingTrained(): uicore.animations.FadeOut(self.bgBlinkFill) def Blink(self): self.ConstructBgBlinkFill() uicore.animations.FadeTo(self.bgBlinkFill, 0.0, 0.5, loops=ANIM_REPEAT, duration=1.2, curveType=ANIM_WAVE) def ConstructBgBlinkFill(self): if self.node.IsLocked(): color = COLOR_HOVER_LOCKED else: color = COLOR_HOVER_UNLOCKED if not self.bgBlinkFill: self.bgBlinkFill = Sprite(name='bgFillBlink', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgVignette.png', idx=0, color=color, opacity=0.0) else: self.bgBlinkFill.SetRGBA(color[0], color[1], color[2], self.bgBlinkFill.opacity) def OnMouseEnter(self, *args): self.ConstructBgBlinkFill() uicore.animations.FadeTo(self.bgBlinkFill, self.bgBlinkFill.opacity, 0.4, duration=0.3) def OnMouseExit(self, *args): if self.bgBlinkFill: uicore.animations.FadeTo(self.bgBlinkFill, self.bgBlinkFill.opacity, 0.0, duration=0.3) def UpdateState(self, i, animate = True): zoomLevel = sm.GetService('shipTreeUI').GetZoomLevel() isLocked = self.node.IsLocked() opacity = OPACITY_LOCKED if isLocked else 1.0 if animate: uicore.animations.FadeTo(self.icon, self.icon.opacity, opacity, timeOffset=0.05 * i, duration=0.3) else: self.icon.opacity = opacity if zoomLevel == ZOOMED_OUT: opacity = 0.0 elif isLocked: opacity = OPACITY_LOCKED else: opacity = 1.0 if animate: uicore.animations.FadeTo(self.bgFrame, self.bgFrame.opacity, opacity, timeOffset=0.05 * i, duration=0.3) else: self.bgFrame.opacity = opacity color = COLOR_BG if isLocked else COLOR_SHIPGROUP_UNLOCKED if animate: uicore.animations.SpColorMorphTo(self.bgFill, self.bgFill.GetRGBA(), color) else: self.bgFill.SetRGBA(*color) if self.node.IsBeingTrained(): self.Blink() elif self.bgBlinkFill: uicore.animations.FadeOut(self.bgBlinkFill)
class GaugeCircular(Container): __notifyevents__ = ['OnUIScalingChange'] default_name = 'GaugeCircular' default_radius = 20 default_lineWidth = 3.0 default_align = uiconst.TOPLEFT default_state = uiconst.UI_NORMAL default_colorStart = (1.0, 1.0, 1.0, 1.0) default_colorEnd = (0.8, 0.8, 0.8, 1.0) default_colorBg = None default_colorMarker = None default_startAngle = -pi / 2 default_value = 0.0 default_callback = None default_hoverMarkerEnabled = False default_clockwise = True default_bgPortion = 1.0 default_showMarker = True default_autoUpdate = True default_moveMarker = False default_animateInRealTime = True def ApplyAttributes(self, attributes): Container.ApplyAttributes(self, attributes) sm.RegisterNotify(self) self.radius = attributes.Get('radius', self.default_radius) self.lineWidth = attributes.Get('lineWidth', self.default_lineWidth) self.startAngle = attributes.Get('startAngle', self.default_startAngle) self.value = attributes.Get('value', self.default_value) self.colorStart = attributes.Get('colorStart', self.default_colorStart) self.colorEnd = attributes.Get('colorEnd', self.default_colorEnd) self.colorBg = attributes.Get('colorBg', self.default_colorBg) colorMarker = attributes.Get('colorMarker', self.default_colorMarker) self.callback = attributes.Get('callback', self.default_callback) self.isHoverMarkerEnabled = attributes.Get( 'hoverMarkerEnabled', self.default_hoverMarkerEnabled) self.isClockwise = attributes.Get('clockwise', self.default_clockwise) self.bgPortion = attributes.Get('bgPortion', self.default_bgPortion) self.showMarker = attributes.get('showMarker', self.default_showMarker) self.autoUpdate = attributes.get('autoUpdate', self.default_autoUpdate) self.moveMarker = attributes.get('moveMarker', self.default_moveMarker) self.useRealTime = attributes.get('useRealTime', self.default_animateInRealTime) if colorMarker is None: colorMarker = self.colorStart self.width = self.height = self.radius * 2 self.pickRadius = self.radius + self.lineWidth self._angle = 0.0 hoverMarkerSize = self.lineWidth * 1.7 self.hoverMarker = Sprite( name='hoverMarker', parent=self, color=colorMarker, width=hoverMarkerSize, height=hoverMarkerSize, state=uiconst.UI_DISABLED, opacity=0.0, texturePath='res:/UI/Texture/Classes/Gauge/circle.png') if self.isClockwise: rotation = -self.startAngle - pi / 2 else: rotation = self.startAngle + pi / 2 state = uiconst.UI_DISABLED if self.showMarker else uiconst.UI_HIDDEN self.markerTransform = Transform(name='markerTransform', parent=self, align=uiconst.TOALL, rotationCenter=(0.5, 0.5), rotation=rotation, state=state) height = self.lineWidth + 5 self.marker = Fill(name='marker', parent=self.markerTransform, color=colorMarker, align=uiconst.CENTERTOP, pos=(0, -(height - self.lineWidth), 2, height)) self.gauge = None self.bgGauge = None self.Reconstruct() if self.autoUpdate: uthread.new(self.UpdateThread) def UpdateThread(self): while not self.destroyed: diff = self.gauge.end - self.value diff = 3.0 * diff / blue.os.fps self.gauge.end -= diff blue.synchro.Yield() def Reconstruct(self): if self.gauge: self.gauge.Close() self.gauge = self.ConstructLine(self.colorStart, self.colorEnd) self.gauge.end = self.value self.gauge.name = 'gaugeLine' if self.colorBg is None: self.colorBg = Color(*self.colorStart).SetBrightness(0.2).GetRGBA() if self.bgGauge: self.bgGauge.Close() self.bgGauge = self.ConstructLine(self.colorBg, self.colorBg) self.bgGauge.end = self.bgPortion self.bgGauge.name = 'backgroundLine' def GetLinePoint(self, t, w): if not self.isClockwise: t = -t r = self.radius - w if not self.isClockwise: t = t - pi xPoint = w + r * (1.0 + cos(t)) yPoint = w + r * (1.0 + sin(t)) return (xPoint, yPoint) def ConstructLine(self, colorStart, colorEnd): numPoints = max(30, self.radius) line = VectorLineTrace(parent=self, lineWidth=self.lineWidth, width=1, height=1, end=0.0) w = self.lineWidth / 2.0 stepSize = 2 * pi / numPoints for i in xrange(numPoints + 1): if i == 0: t = self.startAngle - 0.1 * stepSize point = self.GetLinePoint(t, w) line.AddPoint(point, color=(1, 1, 1, 0)) t = self.startAngle + float(i) * stepSize point = self.GetLinePoint(t, w) color = geo2.Vec4Lerp(colorStart, colorEnd, i / float(numPoints)) line.AddPoint(point, color) return line def SetValue(self, value, animate=True): if value == self.value: return if not animate: self.gauge.end = value self.value = value def SetMarkerValue(self, value): self.markerTransform.rotation = self.GetOffsetMarkerValue(value) def SetValueAndMarker(self, value, animated=True): self.SetValue(value, animated) self.SetMarkerValue(value) def SetValueAndMarkerTimed(self, value, duration): self.SetMarkerValueTimed(value, duration) self.SetValueTimed(value, duration) def SetValueTimed(self, value, duration): uicore.animations.MorphScalar(self.gauge, 'end', self.gauge.end, value, duration=duration, curveType=uiconst.ANIM_LINEAR, curveSet=self._GetCorrectCurveSet()) self.value = value def _GetCorrectCurveSet(self): simTimeCurveSet = uicore.animations.CreateCurveSet( useRealTime=self.useRealTime) simTimeCurveSet.name = 'gaugeCircularCurveSet' return simTimeCurveSet def SetMarkerValueTimed(self, value, duration): newRotation = self.GetOffsetMarkerValue(value) uicore.animations.MorphScalar(self.markerTransform, 'rotation', self.markerTransform.rotation, newRotation, duration=duration, curveType=uiconst.ANIM_LINEAR, curveSet=self._GetCorrectCurveSet()) def StopGaugeAnimations(self): self.gauge.StopAnimations() self.markerTransform.StopAnimations() def GetOffsetMarkerValue(self, value): offSet = math.pi * 2 * (1.0 - value) newRotation = math.pi * 1.5 - self.startAngle + offSet return newRotation def SetColor(self, colorStart, colorEnd=None): self.gauge.Close() self.gauge = self.ConstructLine(colorStart, colorEnd) self.gauge.end = self.value def SetColorMarker(self, colorMarker): self.marker.SetRGBA(*colorMarker) def SetColorBg(self, colorBg): self.bgGauge.Close() self.bgGauge = self.ConstructLine(colorBg, colorBg) self.bgGauge.name = 'backgroundLine' def GetMousePositionAngle(self): x, y = self.GetAbsolutePosition() x = uicore.uilib.x - x - self.radius y = uicore.uilib.y - y - self.radius v1 = (x, y) if geo2.Vec2Length(v1) < 5: return self._angle v2 = (0.0, 1.0) dot = geo2.Vec2Dot(v1, v2) cross = v1[0] * v2[1] - v1[1] * v2[0] angle = atan2(dot, cross) angle -= self.startAngle if angle < 0: angle += 2 * pi self._angle = angle return angle def TriggerCallback(self): if not self.callback: return angle = self.GetMousePositionAngle() value = angle / (2.0 * pi) self.callback(value) def OnMouseDown(self, *args): if not uicore.uilib.leftbtn: return self.TriggerCallback() def OnMouseEnter(self, *args): if not self.callback: return for obj in (self.gauge, self.bgGauge, self.marker): uicore.animations.FadeTo(obj, obj.opacity, 1.5, duration=0.3) if self.isHoverMarkerEnabled: uicore.animations.FadeIn(self.hoverMarker, 1.0, duration=0.3) def OnMouseExit(self, *args): if not self.callback: return for obj in (self.gauge, self.bgGauge, self.marker): uicore.animations.FadeTo(obj, obj.opacity, 1.0, duration=0.6) if self.isHoverMarkerEnabled: uicore.animations.FadeOut(self.hoverMarker, duration=0.3) currAngle = self.hoverMarkerAngle endAngle = 2 * pi if currAngle > pi else 0.0 uicore.animations.MorphScalar(self, 'hoverMarkerAngle', currAngle, endAngle, duration=0.3) def OnMouseMove(self, *args): if uicore.uilib.leftbtn: self.TriggerCallback() if not self.isHoverMarkerEnabled: return self.hoverMarkerAngle = self.GetMousePositionAngle() def GetHoverMarkerAngle(self): if not self.isHoverMarkerEnabled: return 0.0 return self.GetMousePositionAngle() def SetHoverMarkerAngle(self, angle): angle += self.startAngle w = self.hoverMarker.height / 2.0 r = self.radius + self.lineWidth x = (r + w) * cos(angle) y = (r + w) * sin(angle) offset = r - w - self.lineWidth / 2.0 self.hoverMarker.left = x + offset self.hoverMarker.top = y + offset hoverMarkerAngle = property(GetHoverMarkerAngle, SetHoverMarkerAngle) def EnableHoverMarker(self): self.isHoverMarkerEnabled = True def DisableHoverMarker(self): self.isHoverMarkerEnabled = False def OnUIScalingChange(self, *args): self.Reconstruct()