NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

squadronCont.py (10278B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\squadrons\squadronCont.py
      2 from math import pi
      3 from carbon.common.script.util.timerstuff import AutoTimer
      4 from carbonui.primitives.container import Container
      5 import carbonui.const as uiconst
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.util.color import Color
      8 from eve.client.script.ui.control.eveLabel import EveLabelSmall
      9 from eve.client.script.ui.control.gaugeCircular import GaugeCircular
     10 from eve.client.script.ui.inflight.overview.overviewConst import KILOMETERS10, KILOMETERS10000000
     11 from eve.client.script.ui.inflight.squadrons.fightersHealthGaugeCont import FightersHealthGauge
     12 from eve.client.script.ui.inflight.squadrons.squadronController import SquadronController
     13 from eve.client.script.ui.inflight.squadrons.squadronManagementCont import SquadronNumber
     14 from eve.client.script.ui.shared.fittingScreen.fighterTooltip import TooltipFighterWrapper
     15 from eve.common.lib import appConst as const
     16 from eve.common.script.mgt.fighterConst import COLOR_OPEN, LABEL_BY_STATE, TUBE_STATE_EMPTY
     17 from localization import GetByLabel
     18 import localization
     19 import uthread2
     20 from carbonui.uicore import uicore
     21 
     22 class SquadronCont(Container):
     23     default_width = 86
     24     default_height = 116
     25     default_align = uiconst.TOPLEFT
     26     default_doDamageUpdates = True
     27 
     28     def ApplyAttributes(self, attributes):
     29         Container.ApplyAttributes(self, attributes)
     30         self.tooltipPanelClassInfo = TooltipFighterWrapper()
     31         self.controller = attributes.controller
     32         self.tubeFlagID = attributes.tubeFlagID
     33         self.doDamageUpdates = attributes.get('doDamageUpdates', self.default_doDamageUpdates)
     34         textCont = Container(name='textCont', parent=self, align=uiconst.TOBOTTOM, top=10, height=30)
     35         self.squadronNumber = SquadronNumber(parent=self, top=1, left=1)
     36         self.squadronNumber.SetColor(False)
     37         self.squadronNumber.SetText(self.tubeFlagID)
     38         self.fighterHealthCont = FightersHealthGauge(parent=self, align=uiconst.TOTOP, height=86, tubeFlagID=self.tubeFlagID)
     39         self.OnMouseEnter = self.fighterHealthCont.OnMouseEnter
     40         self.OnMouseExit = self.fighterHealthCont.OnMouseExit
     41         self.selectHilight = Container(name='navSelectHilight', parent=self.fighterHealthCont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=86, height=86)
     42         self.ringSprite = Sprite(bgParent=self.selectHilight, texturePath='res:/UI/Texture/classes/ShipUI/Fighters/selectionRing.png')
     43         self.bracketSprite = Sprite(bgParent=self.selectHilight, texturePath='res:/UI/Texture/classes/ShipUI/Fighters/selectionBracket.png')
     44         self.selectHilight.display = False
     45         self.loadingGauge = GaugeCircular(parent=self, radius=26, align=uiconst.CENTER, colorStart=Color.GRAY3, colorEnd=Color.GRAY3, colorBg=Color.BLACK, lineWidth=2.5, state=uiconst.UI_DISABLED, showMarker=True, top=-15, idx=0, startAngle=pi / 2)
     46         self.loadingGauge.display = False
     47         self.actionLabel = SquadronActionLabel(parent=textCont, align=uiconst.CENTERTOP, top=2, controller=self.controller)
     48         self.speedLabel = SquadronInfoLabel(parent=textCont, align=uiconst.CENTERBOTTOM, top=2)
     49         if self.controller.GetIsInSpace(self.tubeFlagID):
     50             self.SetSquadronInfo(self.tubeFlagID)
     51         self.SetSquadronAction(self.tubeFlagID)
     52         if self.doDamageUpdates:
     53             self.damageTimer = AutoTimer(1000, self.UpdateDamage)
     54         else:
     55             self.damageTimer = None
     56 
     57     def SetSquadronInfo(self, tubeFlagID):
     58         self.speedLabel.SetSquadronInfo(tubeFlagID)
     59 
     60     def StopSquadronTimer(self):
     61         self.speedLabel.text = ''
     62         self.speedLabel.StopLooping()
     63 
     64     def SetSquadronAction(self, tubeFlagID):
     65         self.actionLabel.SetSquadronAction(tubeFlagID)
     66 
     67     def SetNewSquadron(self, fighterItemID, typeID, squadronSize):
     68         self.fighterItemID = fighterItemID
     69         self.fighterHealthCont.LoadFighterToSquadron(typeID)
     70         self.fighterHealthCont.SetSquadronSize(squadronSize)
     71         self.hint = self.fighterHealthCont.hint
     72 
     73     def ClearFighters(self):
     74         self.fighterHealthCont.ClearFighters()
     75 
     76     def GetFighterItemID(self):
     77         return self.fighterItemID
     78 
     79     def UpdateDamage(self):
     80         bp = sm.GetService('michelle').GetBallpark()
     81         if bp is None:
     82             return
     83         damageState = bp.GetDamageState(self.fighterItemID)
     84         if damageState is not None:
     85             shieldDamage = damageState[0]
     86             self.fighterHealthCont.UpdateFighters(damage=shieldDamage)
     87             self.hint = self.fighterHealthCont.hint
     88 
     89     def ShowSelectionHilite(self):
     90         if self.selectHilight.display:
     91             return
     92         self.selectHilight.display = True
     93         self.ringSprite.opacity = 0.2
     94         self.bracketSprite.opacity = 3.0
     95         uicore.animations.FadeTo(self.ringSprite, self.ringSprite.opacity, 1.0, duration=0.2)
     96         uicore.animations.FadeTo(self.bracketSprite, self.bracketSprite.opacity, 1.0, duration=0.2)
     97 
     98     def HideSelectionHilite(self):
     99         self.selectHilight.display = False
    100 
    101     def _OnClose(self, *args):
    102         self.damageTimer = None
    103         Container._OnClose(self, args)
    104 
    105 
    106 class SquadronContEmpty(Container):
    107     default_width = 86
    108     default_height = 116
    109     default_align = uiconst.TOPLEFT
    110     default_state = uiconst.UI_NORMAL
    111 
    112     def ApplyAttributes(self, attributes):
    113         Container.ApplyAttributes(self, attributes)
    114         self.controller = attributes.controller
    115         tubeFlagID = attributes.tubeFlagID
    116         textCont = Container(parent=self, align=uiconst.TOBOTTOM, height=30, top=10)
    117         self.squadronNumber = SquadronNumber(parent=self, top=1, left=1)
    118         self.squadronNumber.SetColor(True)
    119         self.squadronNumber.SetText(tubeFlagID)
    120         self.actionLabel = SquadronActionLabel(parent=textCont, align=uiconst.CENTERTOP, top=2, controller=self.controller)
    121         self.fighterCont = Container(name='fighterCont', parent=self, align=uiconst.TOTOP, height=86, state=uiconst.UI_NORMAL, pickRadius=32)
    122         self.fighterCont.OnMouseEnter = self.OnFighterContMouseEnter
    123         self.fighterCont.OnMouseExit = self.OnFighterContMouseExit
    124         self.fighterCont.hint = GetByLabel('UI/Inventory/Fighters/EmptyLaunchTube')
    125         self.fighterCont.GetTooltipPosition = self.GetTooltipPosition
    126         Sprite(parent=self.fighterCont, texturePath='res:/UI/Texture/classes/ShipUI/Fighters/fighterItemEmpty_Up.png', align=uiconst.CENTER, height=86, width=86, state=uiconst.UI_DISABLED)
    127         self.hilite = Sprite(parent=self.fighterCont, name='hilite', texturePath='res:/UI/Texture/classes/ShipUI/Fighters/fighterItemEmpty_Over.png', align=uiconst.CENTER, height=86, width=86, state=uiconst.UI_DISABLED)
    128         self.hilite.display = False
    129         self.actionLabel.text = GetByLabel(LABEL_BY_STATE[TUBE_STATE_EMPTY])
    130         self.actionLabel.SetTextColor(COLOR_OPEN)
    131 
    132     def OnFighterContMouseEnter(self, *args):
    133         self.hilite.display = True
    134 
    135     def OnFighterContMouseExit(self, *args):
    136         self.hilite.display = False
    137 
    138     def GetTooltipPosition(self):
    139         retLeft, retTop, retWidth, retHeight = self.fighterCont.GetAbsolute()
    140         return (retLeft,
    141          retTop + 15,
    142          retWidth,
    143          retHeight)
    144 
    145 
    146 class SquadronActionLabel(EveLabelSmall):
    147 
    148     def ApplyAttributes(self, attributes):
    149         EveLabelSmall.ApplyAttributes(self, attributes)
    150         self.controller = attributes.controller
    151 
    152     def SetSquadronAction(self, tubeFlagID):
    153         action, color = self.controller.GetSquadronAction(tubeFlagID)
    154         self.text = GetByLabel(action)
    155         self.SetTextColor(color.GetRGBA())
    156 
    157 
    158 class SquadronInfoLabel(EveLabelSmall):
    159 
    160     def ApplyAttributes(self, attributes):
    161         EveLabelSmall.ApplyAttributes(self, attributes)
    162         self._keepLooping = False
    163         self.controller = SquadronController()
    164 
    165     def SetSquadronInfo(self, tubeFlagID):
    166         if self._keepLooping:
    167             return
    168         self._keepLooping = True
    169         uthread2.StartTasklet(self.LoopText, tubeFlagID)
    170 
    171     def LoopText(self, tubeFlagID):
    172         isVelocity = False
    173         while self._keepLooping:
    174             if isVelocity:
    175                 self.text = self.GetDistanceText(tubeFlagID)
    176             else:
    177                 self.text = self.GetVelocityText(tubeFlagID)
    178             isVelocity = not isVelocity
    179             uthread2.Sleep(3)
    180 
    181     def StopLooping(self):
    182         self._keepLooping = False
    183 
    184     def GetDistanceText(self, tubeFlagID):
    185         distance = self.controller.GetSquadronDistance(tubeFlagID)
    186         if distance is None:
    187             return GetByLabel('UI/Generic/Unknown')
    188         return self.FormatDistance(distance)
    189 
    190     def GetVelocityText(self, tubeFlagID):
    191         velocity = self.controller.GetSquadronVelocity(tubeFlagID)
    192         if velocity is None:
    193             return GetByLabel('UI/Generic/Unknown')
    194         return GetByLabel('UI/Inflight/MetersPerSecond', speed=int(velocity))
    195 
    196     def FormatVelocity(self, velocity):
    197         if velocity is None or velocity == '':
    198             return u''
    199         velocity = localization.formatters.FormatNumeric(int(velocity), useGrouping=True)
    200         return velocity
    201 
    202     def FormatDistance(self, distance):
    203         if distance is None or distance == '':
    204             return u''
    205         formatFunc = localization.formatters.FormatNumeric
    206         distance = max(0, distance)
    207         if distance < KILOMETERS10:
    208             currentDist = int(distance)
    209             distance = GetByLabel('/Carbon/UI/Common/FormatDistance/fmtDistInMeters', distance=formatFunc(currentDist, useGrouping=True))
    210         elif distance < KILOMETERS10000000:
    211             currentDist = long(distance / 1000)
    212             distance = GetByLabel('/Carbon/UI/Common/FormatDistance/fmtDistInKiloMeters', distance=formatFunc(currentDist, useGrouping=True))
    213         else:
    214             currentDist = round(distance / const.AU, 1)
    215             distance = GetByLabel('/Carbon/UI/Common/FormatDistance/fmtDistInAU', distance=formatFunc(currentDist, useGrouping=True, decimalPlaces=1))
    216         return distance or u''
    217 
    218     def _OnClose(self, *args, **kw):
    219         self.StopLooping()
    220         EveLabelSmall._OnClose(self, args, kw)