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

warzoneInfoSideCont.py (19707B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\fwwarzone\client\dashboard\warzoneInfoSideCont.py
      2 import logging
      3 from collections import deque
      4 from eve.client.script.ui.structure.accessGroups.searchCont import hintText
      5 from evePathfinder.core import IsUnreachableJumpCount
      6 import eveformat
      7 import evelink.client
      8 from carbonui import TextAlign, uiconst, TextColor, Density
      9 from carbonui.text.styles import TextDetail
     10 from carbonui.primitives.container import Container
     11 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.primitives.transform import Transform
     14 from carbonui.uianimations import animations
     15 from eve.client.script.ui import eveColor
     16 from eve.client.script.ui.control.eveLabel import EveCaptionLarge, EveLabelLarge, EveLabelMedium
     17 from eve.client.script.ui.control.toggleButtonGroup import ToggleButtonGroup
     18 from eve.client.script.ui.skillPlan.skillPlanInfoIcon import SkillPlanInfoIcon
     19 from eve.common.script.util.facwarCommon import GetOccupationEnemyFaction
     20 from factionwarfare.client.text import GetSystemCaptureStatusText
     21 from fwwarzone.client.dashboard.collapsingSection import CollapsingSection
     22 from fwwarzone.client.dashboard.const import ADJACENCY_TO_LABEL_TEXT, ADVANTAGE_CONTENT_DATA, FACTION_ID_TO_COLOR, ADJACENCY_TO_HINT_PATHS
     23 from fwwarzone.client.dashboard.gauges.advantageWidget import AdvantageWidget
     24 from fwwarzone.client.dashboard.gauges.contestedGauge import ContestedFWSystemGauge
     25 from fwwarzone.client.dashboard.shipCasterVisualization import _ShipCasterVisualization
     26 from localization import GetByLabel
     27 logger = logging.getLogger(__name__)
     28 RESIZE_DURATION = 0.5
     29 FADE_OUT_DURATION = 0.25
     30 FADE_OFFSET = 0.25
     31 NOT_FW_SOLARSYSTEM = -1
     32 TEMP_BULWARK_SYSTEM_DES = 'bulwark'
     33 
     34 class WarzoneInfoSideCont(Container):
     35     default_name = 'WarzoneInfoSideCont'
     36     default_align = uiconst.TORIGHT
     37     default_width = 350
     38 
     39     def ApplyAttributes(self, attributes):
     40         super(WarzoneInfoSideCont, self).ApplyAttributes(attributes)
     41         self.fullWidth = self.width
     42         self.currentSolarsystemID = None
     43         self.attackerGauge = None
     44         self.defenderGauge = None
     45         self.fwWarzoneSvc = sm.GetService('fwWarzoneSvc')
     46         self.fwAdvantageSvc = sm.GetService('fwAdvantageSvc')
     47         self.isShowing = False
     48         self.viewingFactionId = attributes.get('viewingFactionId')
     49         self.contentCont = Container(name='contentCont', parent=self)
     50         self.hasLoaded = False
     51         self.interstellarShipCasterFactionFocusSignal = attributes.get('interstellarShipCasterFactionFocusSignal')
     52         self.sections = {}
     53         self.lastOpenedSectionNames = deque([])
     54 
     55     def EnsureEnoughSpaceForSectionToExpand(self, section):
     56         if not section.collapsed:
     57             return
     58         totalHeightOfOpenedSections = 0
     59         for name, eachSection in self.sections.iteritems():
     60             if not eachSection.collapsed:
     61                 totalHeightOfOpenedSections += eachSection.expandedSectionHeightWithHeader
     62 
     63         heightDifference = self.displayHeight - totalHeightOfOpenedSections - section.expandedSectionHeightWithHeader
     64         while heightDifference < 0 and len(self.lastOpenedSectionNames) > 0:
     65             poppedSectionName = self.lastOpenedSectionNames.pop()
     66             poppedSection = self.sections[poppedSectionName]
     67             if not poppedSection.collapsed:
     68                 poppedSection.Toggle(callCallback=False)
     69                 heightDifference += poppedSection.expandedSectionHeight
     70 
     71         self.lastOpenedSectionNames.appendleft(section.name)
     72 
     73     def ConstructNotPartOfWarzoneSystem(self, systemId):
     74         hqSystems = sm.GetService('fwWarzoneSvc').GetAllHQSystems()
     75         cont = Container(parent=self.selectedSystemCont, align=uiconst.TOALL, padding=(41, 10, 41, 0), opacity=0)
     76         systemHeaderLineCont = Container(parent=cont, align=uiconst.TOTOP, height=42, padBottom=16)
     77         solarSystem = cfg.mapSystemCache.get(systemId, None)
     78         if not solarSystem:
     79             return
     80         factionId = getattr(solarSystem, 'factionID', None)
     81         isHqSystem = systemId in hqSystems.values()
     82         try:
     83             isBulwarkSystem = sm.GetService('fwWarzoneSvc').GetMapTagProvider().is_bulwark_system(systemId)
     84         except Exception:
     85             logger.exception('Failed to check if bulwark system')
     86             isBulwarkSystem = False
     87 
     88         if isHqSystem:
     89             spriteTransform = Transform(parent=systemHeaderLineCont, width=32, height=32, align=uiconst.TOLEFT, padRight=8)
     90             Sprite(parent=spriteTransform, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/frontlines/shipcaster/shipcaster_icon_32.png', useSizeFromTexture=True)
     91             factionText = GetByLabel('UI/FactionWarfare/frontlinesDashboard/FactionHQSystem', factionID=factionId)
     92             hint = ''
     93             if isBulwarkSystem:
     94                 hint = self._GetSystemDesignationHint(TEMP_BULWARK_SYSTEM_DES)
     95                 factionText = '%s - <b>%s</b>' % (factionText, GetByLabel('UI/Common/Bulwark'))
     96             l = EveLabelLarge(parent=cont, text=factionText, align=uiconst.TOTOP, state=uiconst.UI_NORMAL)
     97             l.hint = hint
     98         elif cfg.eveowners.GetIfExists(factionId):
     99             factionText = cfg.eveowners.Get(factionId).name
    100             hint = ''
    101             if isBulwarkSystem:
    102                 hint = self._GetSystemDesignationHint(TEMP_BULWARK_SYSTEM_DES)
    103                 factionText = '%s - <b>%s</b>' % (factionText, GetByLabel('UI/Common/Bulwark'))
    104             l = EveLabelLarge(parent=cont, align=uiconst.TOTOP, text=factionText, state=uiconst.UI_NORMAL)
    105             l.hint = hint
    106         secStatusText = eveformat.client.hint(hint=GetByLabel('UI/Map/StarMap/SecurityStatus'), text=eveformat.client.solar_system_security_status(systemId))
    107         EveCaptionLarge(parent=systemHeaderLineCont, align=uiconst.TOLEFT, text=u'{} {}'.format(cfg.evelocations.Get(systemId).name, secStatusText))
    108         if isHqSystem:
    109             SkillPlanInfoIcon(parent=systemHeaderLineCont, align=uiconst.TOLEFT, top=-4, padLeft=8, hint=GetByLabel('UI/FactionWarfare/frontlinesDashboard/factionShipcasterHereTooltip', factionID=factionId))
    110         EveLabelLarge(parent=cont, align=uiconst.TOTOP, padTop=8, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/jumps', numJumps=self._GetNumJumpsString(systemId)))
    111         EveLabelLarge(parent=cont, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/systemNotPartOfWarzone'), align=uiconst.TOTOP, color=TextColor.SECONDARY, padTop=8)
    112         animations.FadeIn(cont, duration=0.25)
    113 
    114     def _GetSystemDesignationHint(self, systemDesignation):
    115         if systemDesignation == TEMP_BULWARK_SYSTEM_DES:
    116             return GetByLabel('UI/FactionWarfare/frontlines/BulwarkHint')
    117         path = ADJACENCY_TO_HINT_PATHS.get(systemDesignation, None)
    118         if not path:
    119             return ''
    120         return GetByLabel(path)
    121 
    122     def SelectSystem(self, systemId, gateLinks, forceExpanded = False):
    123         if systemId == self.currentSolarsystemID and not forceExpanded:
    124             self.FadeOut()
    125             return False
    126         if self.selecetedSystemSection.collapsed:
    127             self.selecetedSystemSection.Toggle()
    128         self.selectedSystemCont.Flush()
    129         self.currentSolarsystemID = systemId or NOT_FW_SOLARSYSTEM
    130         occupationState = sm.GetService('fwWarzoneSvc').GetOccupationState(systemId)
    131         if occupationState is None:
    132             self.ConstructNotPartOfWarzoneSystem(systemId)
    133             return True
    134         padLeft = 41
    135         padTop = 0
    136         headlineCont = Container(parent=self.selectedSystemCont, align=uiconst.TOTOP, height=62, padTop=padTop, padLeft=padLeft)
    137         adjacencyState = occupationState.adjacencyState
    138         occupierID = occupationState.occupierID
    139         attackerID = occupationState.attackerID
    140         ContestedFWSystemGauge(parent=headlineCont, align=uiconst.TOLEFT, systemId=systemId, radius=25, attackerColor=FACTION_ID_TO_COLOR[attackerID], defenderColor=FACTION_ID_TO_COLOR[occupierID], adjacencyState=adjacencyState)
    141         secStatusText = eveformat.client.hint(hint=GetByLabel('UI/Map/StarMap/SecurityStatus'), text=eveformat.client.solar_system_security_status(systemId))
    142         systemNameLabel = EveCaptionLarge(parent=Container(parent=headlineCont, align=uiconst.TOLEFT, width=1, padLeft=10), align=uiconst.CENTERLEFT, text=u'{} {}'.format(cfg.evelocations.Get(systemId).name, secStatusText), opacity=0.0, state=uiconst.UI_NORMAL)
    143         victoryPointsState = sm.GetService('fwVictoryPointSvc').GetVictoryPointState(systemId)
    144         stateText = GetSystemCaptureStatusText(victoryPointsState)
    145         EveLabelLarge(padTop=14, padLeft=padLeft, parent=self.selectedSystemCont, align=uiconst.TOTOP, text=cfg.eveowners.Get(occupierID).name + u': {}'.format(stateText))
    146         EveLabelLarge(parent=self.selectedSystemCont, align=uiconst.TOTOP, padLeft=padLeft, padTop=5, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/jumps', numJumps=self._GetNumJumpsString(systemId)))
    147         frontlineText = GetByLabel('UI/FactionWarfare/frontlinesDashboard/thisSystemIsAdjacencyLabel', adjacencyState=ADJACENCY_TO_LABEL_TEXT[adjacencyState])
    148         l = EveLabelMedium(parent=self.selectedSystemCont, align=uiconst.TOTOP, padTop=10, padLeft=padLeft, text=frontlineText, state=uiconst.UI_NORMAL)
    149         l.hint = self._GetSystemDesignationHint(adjacencyState)
    150         if gateLinks:
    151             for gate in gateLinks:
    152                 empireSolarSystemId = gate.empireSolarSystemId
    153                 nonFWSolarSystem = cfg.mapSystemCache.get(empireSolarSystemId, None)
    154                 empireFaction = getattr(nonFWSolarSystem, 'factionID', None)
    155                 if occupierID != empireFaction:
    156                     continue
    157                 solarSystemName = evelink.location_link(empireSolarSystemId)
    158                 text = GetByLabel('UI/FactionWarfare/frontlinesDashboard/GateLeadsToSystem', solarSystemLink=solarSystemName)
    159                 EveLabelMedium(name='gateLinkLabel', parent=self.selectedSystemCont, align=uiconst.TOTOP, padTop=10, padLeft=padLeft, text=text, state=uiconst.UI_NORMAL)
    160 
    161         advantageTitleCont = Container(parent=self.selectedSystemCont, height=19, align=uiconst.TOTOP, padTop=20, padLeft=padLeft)
    162         EveLabelLarge(parent=advantageTitleCont, align=uiconst.TOLEFT, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/advantageTitleLabel'), bold=True)
    163         SkillPlanInfoIcon(parent=advantageTitleCont, align=uiconst.TOLEFT, padLeft=5, hint=GetByLabel('UI/FactionWarfare/frontlinesDashboard/objectives/advantageTrackerDescription'))
    164         systemAdvantageWidget = AdvantageWidget(systemId=systemId, name='AdvantageWidget', parent=self.selectedSystemCont, align=uiconst.TOTOP, padLeft=padLeft, padRight=40)
    165         animations.FadeIn(systemNameLabel, duration=0.25)
    166         animations.FadeIn(systemAdvantageWidget, duration=0.25)
    167         return True
    168 
    169     def LoadPanel(self, fadeIn = True):
    170         self.contentCont.Flush()
    171         self.sections = {}
    172         self.selectedSystemCont = Container(height=295, clipChildren=True)
    173         self.selecetedSystemSection = CollapsingSection(name='selecetedSystemSection', sectionId=1, parent=self.contentCont, section=self.selectedSystemCont, align=uiconst.TOTOP, headerText=GetByLabel('UI/FactionWarfare/frontlinesDashboard/selectedSystemSectionHeader'), collapsed=False, showDividerLine=False, preToggleCallback=self.EnsureEnoughSpaceForSectionToExpand)
    174         self.sections[self.selecetedSystemSection.name] = self.selecetedSystemSection
    175         self.lastOpenedSectionNames.appendleft(self.selecetedSystemSection.name)
    176         advantageMechanicsCont = Container(height=300, clipChildren=True)
    177         objectivesSection = CollapsingSection(name='objectivesSection', parent=self.contentCont, section=advantageMechanicsCont, align=uiconst.TOTOP, headerText=GetByLabel('UI/FactionWarfare/frontlinesDashboard/AdvantageObjectivesSectionHeader'), collapsed=True, preToggleCallback=self.EnsureEnoughSpaceForSectionToExpand)
    178         self.sections[objectivesSection.name] = objectivesSection
    179         infoTextCont = ContainerAutoSize(parent=self.selectedSystemCont, name='systemInfo', align=uiconst.TOTOP, padLeft=25, padRight=25)
    180         EveCaptionLarge(parent=infoTextCont, padTop=28, name='systemStateLabel', align=uiconst.TOTOP, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/systemState'), textAlign=TextAlign.CENTER)
    181         TextDetail(padTop=15, parent=infoTextCont, name='systemStateInstructionLabel', align=uiconst.TOTOP, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/systemStateInstructionLabel'), textAlign=TextAlign.CENTER, color=TextColor.SECONDARY)
    182         padLeft = 41
    183         EveLabelLarge(parent=advantageMechanicsCont, align=uiconst.TOTOP, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/advantageObjectivesTitle'), padLeft=padLeft, padRight=padLeft, padTop=10)
    184         objectivesDetailsCont = ContainerAutoSize(parent=advantageMechanicsCont, align=uiconst.TOTOP, padding=(padLeft,
    185          10,
    186          0,
    187          0))
    188         for obj in ADVANTAGE_CONTENT_DATA:
    189             _ObjectiveRow(parent=objectivesDetailsCont, align=uiconst.TOTOP, iconTexturePath=obj.iconTexturePath, text=obj.text, tooltipText=obj.tooltipText)
    190 
    191         link = evelink.local_service_link(method='OpenFWInfoTab', text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/objectives/moreInfo'))
    192         EveLabelLarge(parent=objectivesDetailsCont, align=uiconst.TOTOP, text=link, padTop=10, state=uiconst.UI_NORMAL)
    193         self.shipCasterInfoCont = Container(height=160, clipChildren=True)
    194         shipCasterSection = CollapsingSection(name='shipCasterSection', parent=self.contentCont, section=self.shipCasterInfoCont, align=uiconst.TOTOP, headerText=GetByLabel('UI/FactionWarfare/frontlinesDashboard/shipcasterSectionHeader'), collapsed=False, preToggleCallback=self.EnsureEnoughSpaceForSectionToExpand)
    195         self.sections[shipCasterSection.name] = shipCasterSection
    196         self.lastOpenedSectionNames.appendleft(shipCasterSection.name)
    197         myToggleBtnGroup = ToggleButtonGroup(name='myToggleBtnGroup', parent=self.shipCasterInfoCont, align=uiconst.TOTOP, padding=(30, 10, 30, 0), callback=self.ConstructShipCasterFactionView, density=Density.COMPACT)
    198         myToggleBtnGroup.height = 24
    199         myToggleBtnGroup.AddButton(self.viewingFactionId, cfg.eveowners.Get(self.viewingFactionId).name)
    200         enemyID = GetOccupationEnemyFaction(self.viewingFactionId)
    201         myToggleBtnGroup.AddButton(enemyID, cfg.eveowners.Get(enemyID).name)
    202         self.shipCasterCont = ContainerAutoSize(parent=self.shipCasterInfoCont, align=uiconst.TOTOP, padLeft=padLeft)
    203         myToggleBtnGroup.SelectByID(self.viewingFactionId)
    204         if fadeIn:
    205             self.FadeIn()
    206         return True
    207 
    208     def ConstructShipCasterFactionView(self, factionID, *args):
    209         self.interstellarShipCasterFactionFocusSignal(factionID)
    210         self.shipCasterCont.Flush()
    211         _ShipCasterVisualization(factionID=factionID, parent=self.shipCasterCont, align=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN)
    212         landingPads = sm.GetService('shipcaster').GetFactionLandingPads(factionID)
    213         unlinkedLandingPadsCont = Container(parent=self.shipCasterCont, align=uiconst.TOTOP, height=32)
    214         disrupted = []
    215         building = []
    216         idle = []
    217         for pad in landingPads:
    218             if pad.isDisrupted:
    219                 disrupted.append(pad.solarSystemID)
    220             elif not pad.isBuilt:
    221                 building.append(pad.solarSystemID)
    222             elif not pad.isLinked and pad.canBeLinked:
    223                 idle.append(pad.solarSystemID)
    224 
    225         if idle or building or disrupted:
    226             EveLabelLarge(parent=unlinkedLandingPadsCont, align=uiconst.TOLEFT, text=GetByLabel('UI/FactionWarfare/frontlinesDashboard/otherLandingPadsText'))
    227         if len(idle) > 0:
    228             idleSprite = Sprite(parent=unlinkedLandingPadsCont, align=uiconst.TOLEFT, texturePath='res:/UI/Texture/classes/frontlines/shipcaster/landingpad_32.png', width=32, height=32, top=-5, color=TextColor.NORMAL)
    229             idleSprite.LoadTooltipPanel = self.GetLoadTooltipFunctionForLandingPadSprite(idle, GetByLabel('UI/FactionWarfare/frontlinesDashboard/idleLandingPadsTooltipHeading'))
    230         if len(building) > 0:
    231             buildingLandingPads = Sprite(parent=unlinkedLandingPadsCont, align=uiconst.TOLEFT, texturePath='res:/UI/Texture/classes/frontlines/shipcaster/landingpad_32.png', width=32, height=32, top=-5, color=TextColor.SECONDARY)
    232             buildingLandingPads.LoadTooltipPanel = self.GetLoadTooltipFunctionForLandingPadSprite(building, GetByLabel('UI/FactionWarfare/frontlinesDashboard/underConstructionLandingPadsTooltipHeading'))
    233         if len(disrupted):
    234             disruptedSprite = Sprite(parent=unlinkedLandingPadsCont, align=uiconst.TOLEFT, texturePath='res:/UI/Texture/classes/frontlines/shipcaster/landingpad_32.png', width=32, height=32, top=-5, color=eveColor.WARNING_ORANGE)
    235             disruptedSprite.LoadTooltipPanel = self.GetLoadTooltipFunctionForLandingPadSprite(disrupted, GetByLabel('UI/FactionWarfare/frontlinesDashboard/disruptedLandingPadsTooltipHeading'))
    236 
    237     def GetLoadTooltipFunctionForLandingPadSprite(self, systemIds, title):
    238 
    239         def fun(tooltipPanel, owner):
    240             tooltipPanel.LoadGeneric1ColumnTemplate()
    241             tooltipPanel.cellSpacing = 3
    242             tooltipPanel.AddLabelLarge(text=title)
    243             textList = []
    244             for id in systemIds:
    245                 nameText = cfg.evelocations.Get(id).name
    246                 secStatusText = eveformat.client.hint(hint=GetByLabel('UI/Map/StarMap/SecurityStatus'), text=eveformat.client.solar_system_security_status(id))
    247                 textList.append(u'{} {}'.format(nameText, secStatusText))
    248 
    249             textList.sort()
    250             for text in textList:
    251                 tooltipPanel.AddLabelMedium(text=text, padding=0)
    252 
    253         return fun
    254 
    255     def _GetNumJumpsString(self, systemID):
    256         numJumps = sm.GetService('clientPathfinderService').GetJumpCountFromCurrent(systemID)
    257         if IsUnreachableJumpCount(numJumps):
    258             return '-'
    259         else:
    260             return numJumps
    261 
    262     def FadeIn(self, animate = True):
    263         self.Show()
    264         animations.FadeIn(self, duration=RESIZE_DURATION, timeOffset=FADE_OFFSET)
    265         self.isShowing = True
    266         if animate:
    267             animations.MorphScalar(self, 'width', startVal=self.width, endVal=self.fullWidth, duration=RESIZE_DURATION)
    268         else:
    269             self.width = self.fullWidth
    270 
    271     def FadeOut(self, animate = True):
    272         self.currentSolarsystemID = None
    273         animations.FadeOut(self, duration=FADE_OUT_DURATION)
    274         self.isShowing = False
    275         if animate:
    276             animations.MorphScalar(self, 'width', startVal=self.width, endVal=0, duration=RESIZE_DURATION, callback=self.Hide)
    277         else:
    278             self.width = 0
    279 
    280 
    281 class _ObjectiveRow(Container):
    282     default_height = 25
    283 
    284     def ApplyAttributes(self, attributes):
    285         super(_ObjectiveRow, self).ApplyAttributes(attributes)
    286         self.iconTexturePath = attributes.get('iconTexturePath')
    287         self.text = attributes.get('text')
    288         self.tooltipText = attributes.get('tooltipText')
    289         self.ConstructLayout()
    290 
    291     def ConstructLayout(self):
    292         Sprite(parent=self, align=uiconst.CENTERLEFT, top=-5, width=16, height=16, texturePath=self.iconTexturePath)
    293         EveLabelLarge(parent=self, align=uiconst.TOLEFT, padLeft=20, text=self.text)
    294         SkillPlanInfoIcon(parent=self, align=uiconst.TOLEFT, top=-2, padLeft=5, hint=self.tooltipText)