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

selectedInfoCont.py (11442B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\selectedInfoCont.py
      2 import eveformat.client
      3 import eveicon
      4 import localization
      5 from carbonui import uiconst, TextColor, ButtonFrameType, ButtonVariant, ButtonStyle
      6 from carbonui.text.styles import TextHeader, TextBody, TextDetail
      7 from carbonui.control.button import Button
      8 from carbonui.primitives.container import Container
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.uianimations import animations
     11 from eve.client.script.ui import eveThemeColor
     12 from eve.client.script.ui.control.eveIcon import OwnerIcon
     13 from localization import GetByLabel
     14 from pirateinsurgency.client.dashboard.const import CORRUPTION_STAGES
     15 from stackless_response_router.exceptions import TimeoutException
     16 LABEL_OFFSET = 72
     17 LABEL_PAD_LEFT = 20
     18 
     19 class SelectedInfoCont(ContainerAutoSize):
     20     default_name = 'SelectedInfoCont'
     21     default_minHeight = 60
     22     __notifyevents__ = ['OnDestinationSet', 'OnDestinationCleared']
     23 
     24     def ApplyAttributes(self, attributes):
     25         self._system_id = None
     26         self._constellation_id = None
     27         self._region_id = None
     28         super(SelectedInfoCont, self).ApplyAttributes(attributes)
     29         self.shouldShow = True
     30         setActiveCallback = attributes.setActiveCallback
     31         self.ownerIcon = OwnerIcon(parent=self, align=uiconst.CENTERLEFT, pos=(0, 0, 60, 60))
     32         self.labelCont = ContainerAutoSize(parent=self, pos=(LABEL_OFFSET,
     33          0,
     34          0,
     35          30), align=uiconst.CENTERLEFT)
     36         self.regionLabel = LocationLabel(parent=self.labelCont, align=uiconst.TOLEFT, caption=GetByLabel('UI/Common/LocationTypes/Region'), setActiveCallback=setActiveCallback)
     37         self.constLabel = LocationLabel(parent=self.labelCont, align=uiconst.TOLEFT, caption=GetByLabel('UI/Common/LocationTypes/Constellation'), padLeft=LABEL_PAD_LEFT, setActiveCallback=setActiveCallback)
     38         self.systemLabel = SystemLabel(parent=self.labelCont, align=uiconst.TOLEFT, caption=GetByLabel('UI/Common/LocationTypes/System'), padLeft=LABEL_PAD_LEFT, setActiveCallback=setActiveCallback)
     39         self.button_cont = ContainerAutoSize(parent=self.labelCont, align=uiconst.TOLEFT, padLeft=LABEL_PAD_LEFT)
     40         self.button_set_destination = IconButtonWithCommand(parent=self.button_cont, align=uiconst.TOLEFT, width=32, height=32, frame_type=ButtonFrameType.RECTANGLE, variant=ButtonVariant.GHOST, texturePath=eveicon.set_destination, func=self._OnSetDestination, command_label=GetByLabel('UI/Inflight/SetDestination'), command='Ctrl-Click')
     41         self.button_set_destination.GetTooltipPointer = self.button_tooltip_pointer
     42         self.button_add_waypoint = IconButtonWithCommand(parent=self.button_cont, align=uiconst.TOLEFT, width=32, height=32, left=8, frame_type=ButtonFrameType.RECTANGLE, variant=ButtonVariant.GHOST, texturePath=eveicon.set_waypoint_map, func=self._OnAddWaypoint, command_label=GetByLabel('UI/Inflight/AddWaypoint'), command='Ctrl-Shift-Click')
     43         self.button_add_waypoint.GetTooltipPointer = self.button_tooltip_pointer
     44         self.button_remove_waypoint = IconButton(parent=self.button_cont, align=uiconst.TOLEFT, width=32, height=32, left=8, frame_type=ButtonFrameType.RECTANGLE, variant=ButtonVariant.GHOST, style=ButtonStyle.WARNING, texturePath=eveicon.remove_waypoint_map, func=self._OnRemoveWaypoint, hint=GetByLabel('UI/Inflight/RemoveWaypoint'))
     45         self.button_remove_waypoint.GetTooltipPointer = self.button_tooltip_pointer
     46         self.button_remove_waypoint.Hide()
     47         self.Update()
     48         sm.RegisterNotify(self)
     49 
     50     def Close(self):
     51         super(SelectedInfoCont, self).Close()
     52         sm.UnregisterNotify(self)
     53 
     54     def button_tooltip_pointer(self):
     55         return uiconst.POINT_TOP_2
     56 
     57     def Update(self, solarSystemID = None, constID = None, regionID = None):
     58         self._system_id = solarSystemID
     59         self._constellation_id = constID
     60         self._region_id = regionID
     61         self.UpdateFactionLogoIcon(constID, regionID, solarSystemID)
     62         self.systemLabel.Update(solarSystemID)
     63         self.constLabel.Update(constID)
     64         self.regionLabel.Update(regionID)
     65         self.UpdateDisplayState()
     66         if solarSystemID:
     67             self.button_cont.Show()
     68             self._update_waypoint_state()
     69         else:
     70             self.button_cont.Hide()
     71 
     72     def UpdateDisplayState(self):
     73         if not self.shouldShow:
     74             self.Hide()
     75             return
     76         if self.systemLabel.GetLocationID() or self.constLabel.GetLocationID() or self.regionLabel.GetLocationID():
     77             self.Show()
     78         else:
     79             self.Hide()
     80 
     81     def SetShouldShow(self, value):
     82         self.shouldShow = value
     83 
     84     def UpdateFactionLogoIcon(self, constID, regionID, solarSystemID):
     85         factionSvc = sm.GetService('faction')
     86         if solarSystemID:
     87             factionID = factionSvc.GetFactionOfSolarSystem(solarSystemID)
     88             factionIDs = [factionID]
     89         elif constID:
     90             factionIDs = factionSvc.GetFactionsOfConstellation(constID)
     91         elif regionID:
     92             factionIDs = factionSvc.GetFactionsOfRegion(regionID)
     93         else:
     94             factionIDs = []
     95         factionID = factionIDs[0] if factionIDs else None
     96         if factionID:
     97             self.ownerIcon.SetOwnerID(factionID)
     98             self.ownerIcon.Show()
     99             self.labelCont.SetPosition(LABEL_OFFSET, 0)
    100         else:
    101             self.ownerIcon.Hide()
    102             self.labelCont.SetPosition(0, 0)
    103 
    104     def _OnSetDestination(self, *args):
    105         if self._system_id:
    106             sm.GetService('starmap').SetWaypoint(self._system_id, clearOtherWaypoints=True, origin='map_set_destination_button')
    107 
    108     def _OnAddWaypoint(self, *args):
    109         if self._system_id:
    110             sm.GetService('starmap').SetWaypoint(self._system_id, origin='map_add_waypoint_button')
    111 
    112     def _OnRemoveWaypoint(self, *args):
    113         if self._system_id:
    114             sm.GetService('starmap').ClearWaypoints(self._system_id)
    115 
    116     def _update_waypoint_state(self):
    117         if not self._system_id:
    118             return
    119         waypoints = sm.StartService('starmap').GetWaypoints()
    120         if len(waypoints) and self._system_id == waypoints[-1]:
    121             self.button_set_destination.enabled = False
    122         else:
    123             self.button_set_destination.enabled = True
    124         if self._system_id in waypoints:
    125             self.button_add_waypoint.Hide()
    126             self.button_remove_waypoint.Show()
    127         else:
    128             self.button_add_waypoint.Show()
    129             self.button_remove_waypoint.Hide()
    130 
    131     def OnDestinationSet(self, *args):
    132         self._update_waypoint_state()
    133 
    134     def OnDestinationCleared(self, *args):
    135         self._update_waypoint_state()
    136 
    137 
    138 class LocationLabel(Container):
    139     default_name = 'LocationLabel'
    140     default_state = uiconst.UI_NORMAL
    141     defautl_height = 30
    142 
    143     def ApplyAttributes(self, attributes):
    144         super(LocationLabel, self).ApplyAttributes(attributes)
    145         caption = attributes.caption
    146         self.setActiveCallback = attributes.setActiveCallback
    147         self.locationID = None
    148         self._content_cont = ContainerAutoSize(parent=self, align=uiconst.VERTICALLY_CENTERED)
    149         self._ConstructHeading(caption)
    150         self._ConstructLabel()
    151         self._UpdateSize()
    152 
    153     def _ConstructLabel(self):
    154         self.label = TextBody(parent=self._content_cont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, bold=True, top=14)
    155 
    156     def _ConstructHeading(self, caption):
    157         self._heading = TextDetail(parent=self._content_cont, align=uiconst.TOPLEFT, text=caption, state=uiconst.UI_DISABLED, color=TextColor.SECONDARY)
    158 
    159     def Update(self, locationID):
    160         self.locationID = locationID
    161         if locationID:
    162             text = self.GetLocationName()
    163             self.Enable()
    164         else:
    165             text = "<color='0x33ffffff'>-</color>"
    166             self.Disable()
    167         self.label.SetText(text)
    168         self._UpdateSize()
    169 
    170     def _UpdateSize(self):
    171         heading_width = self._heading.textwidth
    172         label_width = self.label.textwidth
    173         self.width = max(heading_width, label_width)
    174         heading_height = self._heading.textheight
    175         label_height = self.label.textheight
    176         self.height = max(heading_height, label_height)
    177 
    178     def GetLocationID(self):
    179         return self.locationID
    180 
    181     def GetLocationName(self):
    182         if self.locationID:
    183             return cfg.evelocations.Get(self.locationID).locationName
    184         return ''
    185 
    186     def OnClick(self, *args):
    187         self.setActiveCallback(self.locationID)
    188 
    189     def OnMouseEnter(self, *args):
    190         animations.FadeTo(self, self.opacity, 1.5, duration=0.3)
    191 
    192     def OnMouseExit(self, *args):
    193         animations.FadeTo(self, self.opacity, 1.0, duration=0.3)
    194 
    195 
    196 class SystemLabel(LocationLabel):
    197 
    198     def ApplyAttributes(self, attributes):
    199         super(SystemLabel, self).ApplyAttributes(attributes)
    200 
    201     def _ConstructLabel(self):
    202         self._label_cont = ContainerAutoSize(parent=self._content_cont, align=uiconst.TOPLEFT, top=14)
    203         self._inner_label_cont = ContainerAutoSize(parent=self._label_cont, align=uiconst.TOPLEFT)
    204         self._security_status_cont = ContainerAutoSize(parent=self._label_cont, align=uiconst.TOPLEFT)
    205         self.label = TextHeader(parent=self._inner_label_cont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, bold=True)
    206         self.security_status_label = TextHeader(parent=self._security_status_cont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, text='0.1')
    207 
    208     def Update(self, locationID):
    209         if locationID:
    210             try:
    211                 corruptionStage = sm.GetService('corruptionSuppressionSvc').GetCurrentSystemCorruption_Cached()
    212                 lawless = corruptionStage == CORRUPTION_STAGES
    213             except TimeoutException:
    214                 lawless = False
    215 
    216             secStatusHintText = localization.GetByLabel('UI/Map/StarMap/SecurityStatus')
    217             if lawless:
    218                 secStatusHintText = localization.GetByLabel('UI/PirateInsurgencies/lawlessSecurityWarning')
    219             secStatusText = eveformat.hint(hint=secStatusHintText, text=eveformat.solar_system_security_status(locationID, lawless=lawless))
    220         else:
    221             secStatusText = ''
    222             secStatusHintText = ''
    223         self.security_status_label.SetText(secStatusText)
    224         self.security_status_label.SetHint(secStatusHintText)
    225         super(SystemLabel, self).Update(locationID)
    226 
    227     def _UpdateSize(self):
    228         self._security_status_cont.SetPosition(self.label.textwidth + 12, 0)
    229         heading_width = self._heading.textwidth
    230         label_width = self.label.textwidth + 12 + self.security_status_label.textwidth
    231         self.width = max(heading_width, label_width)
    232         heading_height = self._heading.textheight
    233         label_height = self.label.textheight
    234         self.height = max(heading_height, label_height)
    235 
    236 
    237 class IconButton(Button):
    238     ICON_SIZE = 24
    239     ICON_MARGIN = 0
    240 
    241 
    242 class IconButtonWithCommand(IconButton):
    243 
    244     def __init__(self, command_label, command, **kwargs):
    245         super(IconButtonWithCommand, self).__init__(**kwargs)
    246         self.command_label = command_label
    247         self.command = command
    248 
    249     def LoadTooltipPanel(self, tooltipPanel, *args):
    250         tooltipPanel.LoadGeneric3ColumnTemplate()
    251         tooltipPanel.AddLabelShortcut(self.command_label, self.command, bold=False)