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

launcherCont.py (13584B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\spacecomponents\client\ui\shipcaster\launcherCont.py
      2 from carbonui import TextAlign, TextColor
      3 from carbonui.control.button import Button
      4 from carbonui.primitives.container import Container
      5 import carbonui.const as uiconst
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.layoutGrid import LayoutGrid
      8 from carbonui.primitives.sprite import Sprite
      9 from dynamicresources.client.ess.bracket.label import Header, MediumInSpaceLabel
     10 from eve.client.script.ui import eveColor
     11 from eve.client.script.ui.shared.theatersOfWar.util import open_fw_window
     12 from factionwarfare.client.text import GetSystemCaptureStatusText
     13 from fwwarzone.client.dashboard.const import ADJACENCY_STATE_TO_ICON_PATH_SMALL
     14 from localization import GetByLabel
     15 from menucheckers import CelestialChecker, SessionChecker
     16 from shipcaster.client.shipcasterUtil import GetFailureTextAndDisabledOption
     17 from spacecomponents.client.ui.shipcaster.launcherContController import LauncherContController
     18 from carbon.common.script.util.format import FmtAmt
     19 from carbon.common.script.util.timerstuff import AutoTimer
     20 from eve.client.script.ui.control.eveLabel import Label, EveLabelMedium
     21 from eve.client.script.ui.control.gaugeCircular import GaugeCircular
     22 from eve.client.script.ui.control.infoIcon import MoreInfoIcon
     23 from eve.client.script.ui.eveColor import TUNGSTEN_GREY
     24 from eve.client.script.ui.skillPlan.skillPlanConst import ICON_BY_FACTION_ID
     25 
     26 class LauncerCont(Container):
     27     default_name = 'launcerCont'
     28     CONTENT_HEIGHT = 170
     29     __notifyevents__ = ['OnShipcasterTargetStateChanged']
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(LauncerCont, self).ApplyAttributes(attributes)
     33         self.itemID = attributes.itemID
     34         self.typeID = attributes.typeID
     35         self.launcherContController = LauncherContController(self.itemID, self.typeID)
     36         self.ConstructUI()
     37         sm.RegisterNotify(self)
     38 
     39     def ConstructUI(self):
     40         self._button = Button(parent=self, align=uiconst.CENTERBOTTOM, label=GetByLabel('UI/FactionWarfare/ShipcasterInitiateLaunch'), func=self.Jump)
     41         sideOffset = max(self._button.width * 1.3, 180)
     42         self._ConstructLeftCont(sideOffset)
     43         self._ConstructRightCont(sideOffset)
     44         self._ConstructCenterSpriteCont()
     45         self._ConstructTopCont()
     46         self._UpdateItemIDAndUI()
     47         self.infoCont.UpdateInfoCont()
     48         maxTargets = self.launcherContController.GetMaxTargets()
     49         if maxTargets < 3:
     50             self.leftCont.Hide()
     51         if maxTargets < 2:
     52             self.rightCont.Hide()
     53 
     54     def _ConstructLeftCont(self, sideOffset):
     55         self.leftCont = SideCont(name='leftCont', parent=self, pos=(-sideOffset,
     56          0,
     57          200,
     58          50), align=uiconst.CENTERBOTTOM, isRightSide=False)
     59 
     60     def _ConstructRightCont(self, sideOffset):
     61         self.rightCont = SideCont(name='rightCont', parent=self, pos=(sideOffset,
     62          0,
     63          200,
     64          50), align=uiconst.CENTERBOTTOM, isRightCont=True)
     65 
     66     def _ConstructCenterSpriteCont(self):
     67         self.centerSpriteCont = Container(name='centerSpriteCont', parent=self, pos=(0, 13, 204, 66), align=uiconst.CENTERBOTTOM)
     68         Sprite(parent=self.centerSpriteCont, pos=(0, 0, 204, 66), align=uiconst.BOTTOMLEFT, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterCenter.png', color=TUNGSTEN_GREY, state=uiconst.UI_DISABLED)
     69         Sprite(parent=self.centerSpriteCont, pos=(0, 0, 26, 26), align=uiconst.CENTERTOP, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterCenterIcon.png', state=uiconst.UI_DISABLED)
     70 
     71     def _ConstructTopCont(self):
     72         self.topCont = Container(name='topCont', parent=self, align=uiconst.TOBOTTOM, top=90, height=70)
     73         self.infoCont = TargetInfoCont(parent=self.topCont, align=uiconst.TOBOTTOM, launcherContController=self.launcherContController)
     74         self.fwCont, fwInnerCont = self.GetLabelConts(self.topCont, 'topHeaderCont', top=10)
     75         fwInnerCont.state = uiconst.UI_NORMAL
     76         MoreInfoIcon(name='moreInfoIcon', parent=fwInnerCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED)
     77         MediumInSpaceLabel(parent=fwInnerCont, text=GetByLabel('UI/FactionWarfare/OpenSystemInFwWindow'), align=uiconst.CENTERLEFT, left=20)
     78         fwInnerCont.OnClick = self.OpenFwWndForSystem
     79         _, topHeaderInnerCont = self.GetLabelConts(self.topCont, 'topHeaderCont')
     80         self.topHeaderAdjacencySprite = Sprite(parent=topHeaderInnerCont, pos=(0, 0, 20, 20), align=uiconst.CENTERLEFT)
     81         self.topHeader = Header(parent=topHeaderInnerCont, text='', align=uiconst.CENTERLEFT, left=26)
     82         _, topLabelInnerCont = self.GetLabelConts(self.topCont, 'topLabelStatusCont')
     83         self.topLabelStatus = MediumInSpaceLabel(parent=topLabelInnerCont, align=uiconst.CENTERLEFT)
     84 
     85     def GetLabelConts(self, parent, prefsName, top = 0):
     86         topLabelStatusCont = ContainerAutoSize(name=prefsName, parent=parent, align=uiconst.TOBOTTOM, top=top)
     87         topLabelInnerCont = ContainerAutoSize(name='%sInner' % prefsName, parent=topLabelStatusCont, align=uiconst.CENTER)
     88         return (topLabelStatusCont, topLabelInnerCont)
     89 
     90     def Jump(self, *args):
     91         sm.GetService('menu').JumpThroughShipcaster(self.itemID)
     92 
     93     def OpenFwWndForSystem(self, *args):
     94         targetSystem, factionID = self.launcherContController.GetTargetAndFactionForDashboard()
     95         open_fw_window(factionID, targetSystem)
     96 
     97     def OnShipcasterTargetStateChanged(self, itemID):
     98         if itemID != self.itemID:
     99             return
    100         self._UpdateItemIDAndUI()
    101 
    102     def _UpdateItemIDAndUI(self):
    103         self.infoCont.UpdateInfoCont()
    104         self.UpdateUI()
    105         self.updateTimer = AutoTimer(500, self.UpdateUI)
    106 
    107     def UpdateUI(self):
    108         if self.destroyed:
    109             self.updateTimer = None
    110             return
    111         self._UpdateButton()
    112         self._UpdateLeftCont()
    113         self._UpdateRightCont()
    114         self._UpdateTopCont()
    115 
    116     def _UpdateButton(self):
    117         celestialChecker = CelestialChecker((self.itemID, self.typeID), cfg, SessionChecker(session, sm))
    118         self._button.Disable()
    119         if celestialChecker.OfferShipcasterJump():
    120             self._button.Enable()
    121             self._button.hint = None
    122         elif celestialChecker.failure_label:
    123             failureText, _ = GetFailureTextAndDisabledOption(self.itemID, celestialChecker)
    124             self._button.hint = failureText
    125 
    126     def _UpdateLeftCont(self):
    127         headerText, timeText, adjacencyState, headerColor, _, _ = self.launcherContController._GetHeaderStatusAndAdjacenyState(2)
    128         self.leftCont.UpdateSideCont(headerText, timeText, adjacencyState, headerColor)
    129 
    130     def _UpdateRightCont(self):
    131         headerText, timeText, adjacencyState, headerColor, _, _ = self.launcherContController._GetHeaderStatusAndAdjacenyState(1)
    132         self.rightCont.UpdateSideCont(headerText, timeText, adjacencyState, headerColor)
    133 
    134     def _UpdateTopCont(self):
    135         headerText, timeText, adjacencyState, headerColor, timeColor, timeGlow = self.launcherContController._GetHeaderStatusAndAdjacenyState(0)
    136         self.topHeader.text = headerText
    137         topLabelStatusLabel = self.topLabelStatus.mainLabel
    138         topLabelStatusLabel.SetText(timeText)
    139         topLabelStatusLabel.SetTextColor(timeColor)
    140         if timeGlow:
    141             topLabelStatusLabel.outputMode = uiconst.OUTPUT_COLOR_AND_GLOW
    142         else:
    143             topLabelStatusLabel.outputMode = uiconst.OUTPUT_COLOR
    144         nextTarget = self.launcherContController.GetNextTargetSystemID()
    145         if nextTarget:
    146             self.fwCont.Show()
    147         else:
    148             self.fwCont.Hide()
    149         if adjacencyState:
    150             self.topHeaderAdjacencySprite.Show()
    151             texturePath = ADJACENCY_STATE_TO_ICON_PATH_SMALL.get(adjacencyState, None)
    152             self.topHeaderAdjacencySprite.SetTexturePath(texturePath)
    153             self.topHeader.left = 26
    154         else:
    155             self.topHeaderAdjacencySprite.Hide()
    156             self.topHeader.left = 0
    157 
    158 
    159 class SideCont(Container):
    160 
    161     def ApplyAttributes(self, attributes):
    162         super(SideCont, self).ApplyAttributes(attributes)
    163         self.isRightCont = attributes.isRightCont
    164         self.innerCont = Container(name='innerCont', parent=self, align=uiconst.TOLEFT if self.isRightCont else uiconst.TORIGHT, width=100, left=65, top=6)
    165         topCont = Container(parent=self.innerCont, align=uiconst.TOTOP_PROP, height=0.5)
    166         bottomCont = Container(parent=self.innerCont, align=uiconst.TOBOTTOM_PROP, height=0.5)
    167         topTextCont = ContainerAutoSize(parent=topCont, align=uiconst.BOTTOMLEFT if self.isRightCont else uiconst.BOTTOMRIGHT, alignMode=uiconst.CENTERLEFT, top=2)
    168         self.adjacencySprite = Sprite(parent=topTextCont, pos=(0, 0, 16, 16), align=uiconst.CENTERLEFT)
    169         self.labelHeader = Label(parent=topTextCont, text='', align=uiconst.CENTERLEFT, left=16)
    170         self.labelStatus = Label(parent=bottomCont, text='', align=uiconst.TOPLEFT if self.isRightCont else uiconst.TOPRIGHT, top=4)
    171         spriteAlign = uiconst.CENTERLEFT if self.isRightCont else uiconst.CENTERRIGHT
    172         texturePath = 'res:/UI/Texture/classes/ShipCaster/shipcasterRightSide.png' if self.isRightCont else 'res:/UI/Texture/classes/ShipCaster/shipcasterLeftSide.png'
    173         Sprite(parent=self, pos=(0, 4, 147, 24), align=spriteAlign, texturePath=texturePath, color=TUNGSTEN_GREY, state=uiconst.UI_DISABLED)
    174 
    175     def UpdateSideCont(self, headerText, statusText, adjacencyState, headerColor):
    176         self.labelHeader.SetText(headerText)
    177         self.labelHeader.SetTextColor(headerColor)
    178         self.labelStatus.SetText(statusText)
    179         if adjacencyState:
    180             self.adjacencySprite.Show()
    181             texturePath = ADJACENCY_STATE_TO_ICON_PATH_SMALL.get(adjacencyState, None)
    182             self.adjacencySprite.SetTexturePath(texturePath)
    183             self.labelHeader.left = 20
    184         else:
    185             self.adjacencySprite.Hide()
    186             self.labelHeader.left = 0
    187         self.innerCont.width = self.labelHeader.textwidth + self.labelHeader.left
    188 
    189 
    190 class TargetInfoCont(ContainerAutoSize):
    191     default_name = 'targetInfoCont'
    192 
    193     def ApplyAttributes(self, attributes):
    194         super(TargetInfoCont, self).ApplyAttributes(attributes)
    195         self.launcherContController = attributes.launcherContController
    196         self.layoutGrid = LayoutGrid(parent=self, columns=5, margin=6, cellSpacing=(4, 0), align=uiconst.CENTER, bgColor=(0, 0, 0, 0.5))
    197         self.occupierSprite = Sprite(parent=self.layoutGrid, pos=(0, 0, 16, 16), align=uiconst.CENTER, color=eveColor.SILVER_GREY, state=uiconst.UI_DISABLED)
    198         self.occupierLabel = EveLabelMedium(text='', parent=self.layoutGrid, color=TextColor.SECONDARY)
    199         spacer = Container(name='spacer', parent=self.layoutGrid, pos=(0, 0, 12, 12), align=uiconst.TOPLEFT)
    200         self.advantageSprite = Sprite(parent=self.layoutGrid, pos=(0, 0, 16, 16), align=uiconst.CENTER, color=eveColor.SILVER_GREY, state=uiconst.UI_DISABLED)
    201         self.advantageLabel = EveLabelMedium(text='', parent=self.layoutGrid, color=TextColor.SECONDARY)
    202         self.layoutGrid.FillRow()
    203         self.constestedGauge = GaugeCircular(parent=self.layoutGrid, clockwise=False, showMarker=False, radius=6, lineWidth=2.0, align=uiconst.CENTER, value=0.75, colorStart=eveColor.SILVER_GREY, colorEnd=eveColor.SILVER_GREY, state=uiconst.UI_DISABLED)
    204         self.contestedLabel = EveLabelMedium(text='', parent=self.layoutGrid, color=TextColor.SECONDARY)
    205         spacer = Container(name='spacer', parent=self.layoutGrid, pos=(0, 0, 12, 12), align=uiconst.TOPLEFT)
    206         self.deathSprite = Sprite(parent=self.layoutGrid, pos=(0, 0, 16, 16), align=uiconst.CENTER, color=eveColor.SILVER_GREY, texturePath='res:/UI/Texture/classes/ShipCaster/deathsOnGrid.png', state=uiconst.UI_DISABLED)
    207         self.deathLabel = EveLabelMedium(text='', parent=self.layoutGrid, color=TextColor.SECONDARY)
    208 
    209     def UpdateInfoCont(self):
    210         nextTarget = self.launcherContController.GetNextTargetSystemID()
    211         if not nextTarget:
    212             self.Hide()
    213             return
    214         self.Show()
    215         occupierID, attackerID, advantageScore, advantageWinner = self.launcherContController.GetTargetOccuppierAndNetScore()
    216         if occupierID is None or attackerID is None:
    217             self.layoutGrid.Hide()
    218             return
    219         self.layoutGrid.Show()
    220         self.occupierSprite.SetTexturePath(ICON_BY_FACTION_ID.get(occupierID, None))
    221         occupierText = cfg.eveowners.Get(occupierID).name if occupierID else ''
    222         self.occupierLabel.SetText(occupierText)
    223         self.advantageSprite.SetTexturePath(ICON_BY_FACTION_ID.get(advantageWinner, None))
    224         percentageText = GetByLabel('UI/FactionWarfare/ShipcasterFwAdvantage', percentage=FmtAmt(abs(advantageScore) * 100, showFraction=True))
    225         self.advantageLabel.SetText(percentageText)
    226         victoryPointState = self.launcherContController.GetContestedInfo()
    227         systemStatusText = GetSystemCaptureStatusText(victoryPointState)
    228         self.contestedLabel.SetText(systemStatusText)
    229         if victoryPointState is None:
    230             self.constestedGauge.SetValue(0)
    231         else:
    232             self.constestedGauge.SetValue(1 - victoryPointState.contestedFraction, animate=False)
    233         numKills = self.launcherContController.GetKillsInTheLastHour(nextTarget)
    234         text = GetByLabel('UI/FactionWarfare/KillsInHour', numKills=numKills)
    235         self.deathLabel.SetText(text)