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

mapViewNavButtons.py (9739B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\controls\mapViewNavButtons.py
      2 import eveicon
      3 import localization
      4 from carbonui import uiconst, TextColor
      5 from carbonui.control.buttonIcon import ButtonIcon
      6 from carbonui.control.contextMenu.menuData import MenuData
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      9 from carbonui.primitives.sprite import Sprite
     10 from eve.client.script.ui import eveColor
     11 from eve.client.script.ui.shared.mapView.mapSignals import on_2d_map_toggled, on_focus_current_position_pressed
     12 from eve.client.script.ui.shared.mapView.mapViewConst import VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS
     13 from eve.client.script.ui.shared.mapView.mapViewSettings import GetMapViewSetting, SetMapViewSetting, mapPreviewModeActive, jumpRangeExcludeIneligibleSystem
     14 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst
     15 EXPANDED_TOP = 48
     16 COLLAPSED_TOP = 24
     17 ICON_SIZE = 32
     18 ICON_SIZE_COMPACT = 16
     19 EXTRA_WIDTH = 8
     20 ICON_COLOR = TextColor.SECONDARY
     21 ICON_COLOR_SELECTED = TextColor.HIGHLIGHT
     22 
     23 class MapViewNavButtons(ContainerAutoSize):
     24     default_align = uiconst.BOTTOMRIGHT
     25     default_height = ICON_SIZE
     26     default_top = EXPANDED_TOP
     27 
     28     def ApplyAttributes(self, attributes):
     29         super(MapViewNavButtons, self).ApplyAttributes(attributes)
     30         self._map_view_id = attributes.map_view_id
     31         self._transitioning = False
     32         self._on_abstract_mode_toggled_callback = attributes.on_abstract_mode_toggled
     33         self._on_focus_home_callback = attributes.on_focus_home_callback
     34         self._on_focus_current_position_callback = attributes.on_focus_current_position_callback
     35         self._on_jump_range_callback = attributes.on_jump_range_callback
     36         self._jump_range_func = attributes.jump_range_func
     37         self._construct_layout()
     38         self._update_abstract_state()
     39 
     40     def _construct_layout(self):
     41         self._abstract_cont = AbstractButtonCont(parent=self, align=uiconst.TORIGHT, width=ICON_SIZE + EXTRA_WIDTH, on_abstract_button_pressed=self._on_abstract_button_pressed)
     42         self._home_cont = Container(parent=self, align=uiconst.TORIGHT, width=ICON_SIZE + EXTRA_WIDTH)
     43         self._home_button = ButtonIcon(parent=self._home_cont, name='focus_home_button', align=uiconst.CENTERBOTTOM, iconSize=ICON_SIZE, texturePath=eveicon.find_home_station, iconColor=ICON_COLOR, hint=localization.GetByLabel('UI/Map/MapPallet/buttonTooltipFocusHome'), func=self._on_home_button_pressed, analyticID='map_view_home_button', soundClick='map_home_station_play', uniqueUiName=pConst.UNIQUE_NAME_MAP_FOCUS_HOME)
     44         self._current_cont = Container(parent=self, align=uiconst.TORIGHT, width=ICON_SIZE)
     45         self._current_position_button = ButtonIcon(parent=self._current_cont, name='focus_self_button', align=uiconst.CENTERBOTTOM, iconSize=ICON_SIZE, texturePath=eveicon.focus_viewfinder, iconColor=ICON_COLOR, hint=localization.GetByLabel('UI/Map/MapPallet/buttonTooltipFocusCurrentPosition'), func=self._on_current_position_button_pressed, analyticID='map_view_current_position_button', soundClick='map_current_location_play', uniqueUiName=pConst.UNIQUE_NAME_MAP_FOCUS_CURRENT)
     46         self._jump_range_cont = Container(parent=self, align=uiconst.TORIGHT, width=ICON_SIZE + EXTRA_WIDTH)
     47         self._jump_range_button = ButtonIcon(name='_jump_range_button', parent=self._jump_range_cont, align=uiconst.CENTERBOTTOM, iconSize=ICON_SIZE, texturePath=eveicon.jump_range_map, iconColor=ICON_COLOR, colorSelected=ICON_COLOR_SELECTED, hint=localization.GetByLabel('UI/Map/MapPallet/buttonTooltipShowJumpRange'), func=self._on_jump_range_button_pressed, analyticID='map_view_jump_range_button', uniqueUiName=pConst.UNIQUE_NAME_MAP_JUMP_RANGE)
     48         self._jump_range_button.GetMenu = self.get_jump_range_options
     49         self.update_jump_range_state()
     50 
     51     def _on_abstract_button_pressed(self, *args):
     52         if self._transitioning:
     53             return
     54         self._abstract_cont.DisableAbstractButton()
     55         is_abstract = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, self._map_view_id)
     56         SetMapViewSetting(VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, not is_abstract, self._map_view_id)
     57         self._on_abstract_mode_toggled_callback()
     58         self._update_abstract_state()
     59         on_2d_map_toggled(is_abstract)
     60         sm.ScatterEvent('On2DMapToggled', is_abstract)
     61 
     62     def _update_abstract_state(self):
     63         is_abstract = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, self._map_view_id)
     64         self._abstract_cont.UpdateAbstractState(is_abstract)
     65 
     66     def _on_home_button_pressed(self, *args):
     67         self._on_focus_home_callback()
     68 
     69     def _on_current_position_button_pressed(self, *args):
     70         self._on_focus_current_position_callback()
     71         on_focus_current_position_pressed()
     72         sm.ScatterEvent('OnFocusCurrentPositionPressed')
     73 
     74     def _on_jump_range_button_pressed(self, *args):
     75         should_show = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS, self._map_view_id)
     76         SetMapViewSetting(VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS, not should_show, self._map_view_id)
     77         self._on_jump_range_callback()
     78         self.update_jump_range_state()
     79 
     80     def update_jump_range_state(self):
     81         if self._jump_range_func and self._jump_range_func() <= 0:
     82             self._jump_range_cont.Hide()
     83             return
     84         self._jump_range_cont.Show()
     85         should_show = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS, self._map_view_id)
     86         if should_show:
     87             self._jump_range_button.SetSelected()
     88         else:
     89             self._jump_range_button.SetDeselected()
     90 
     91     def update_compact_mode(self, is_compact):
     92         if is_compact:
     93             self._set_icon_size(ICON_SIZE_COMPACT)
     94             self.top = COLLAPSED_TOP
     95             self.height = 2 * ICON_SIZE_COMPACT
     96         else:
     97             self.top = EXPANDED_TOP
     98             self._set_icon_size(ICON_SIZE)
     99             self.height = 2 * ICON_SIZE
    100 
    101     def _set_icon_size(self, size):
    102         for cont, btn in ((self._home_cont, self._home_button), (self._current_cont, self._current_position_button), (self._jump_range_cont, self._jump_range_button)):
    103             cont.width = size + EXTRA_WIDTH
    104             btn.SetIconSize(size)
    105             btn.SetSize(size + EXTRA_WIDTH, size)
    106 
    107         self._abstract_cont.SetContSize(size)
    108 
    109     def on_layout_transition_started(self):
    110         self._transitioning = True
    111         self._abstract_cont.DisableAbstractButton()
    112 
    113     def on_layout_transition_completed(self):
    114         self._transitioning = False
    115         self._abstract_cont.EnableAbstractButton()
    116         is_abstract = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, self._map_view_id)
    117         self._abstract_cont.UpdateAbstractState(is_abstract)
    118 
    119     def get_jump_range_options(self):
    120         m = MenuData()
    121         m.AddCheckbox(text=localization.GetByLabel('UI/Map/MapPallet/ExcludeIneligibleSystems'), setting=jumpRangeExcludeIneligibleSystem)
    122         return m
    123 
    124 
    125 class AbstractButtonCont(Container):
    126 
    127     def SetContSize(self, size):
    128         self.width = size + EXTRA_WIDTH
    129         self._abstract_button.SetIconSize(size)
    130         self._abstract_button.SetSize(size, size)
    131         self.toggleBackground.width = size
    132         self.toggleBackground.height = 2 * size
    133         self.eyeSprite.width = 0.75 * size
    134         self.eyeSprite.height = 0.75 * size
    135         self.eyeSprite.top = int(round(size / 6)) + 1
    136 
    137     def ApplyAttributes(self, attributes):
    138         super(AbstractButtonCont, self).ApplyAttributes(attributes)
    139         on_abstract_button_pressed = attributes.on_abstract_button_pressed
    140         self._abstract_button = ButtonIcon(parent=self, align=uiconst.CENTERBOTTOM, iconSize=ICON_SIZE, texturePath=eveicon.abstract_layout, iconColor=ICON_COLOR, colorSelected=ICON_COLOR_SELECTED, func=on_abstract_button_pressed, analyticID='map_view_abstract_button', soundClick='map_2d3d_play', hint=localization.GetByLabel('UI/Map/MapPallet/buttonTooltipToggleAbstractLayout'), uniqueUiName=pConst.UNIQUE_NAME_MAP_TOGGLE_2D)
    141         top = int(round(ICON_SIZE / 6)) + 1
    142         self.eyeSprite = Sprite(name='eyeSprite', parent=self, align=uiconst.CENTERTOP, pos=(0,
    143          top,
    144          12,
    145          12), texturePath=eveicon.visibility, color=eveColor.BLACK, uniqueUiName=pConst.UNIQUE_NAME_MAP_DATA_VIEW_TOGGLE)
    146         self.eyeSprite.OnClick = self.OnPreviewBtnClicked
    147         self.eyeSprite.hint = localization.GetByLabel('UI/Map/MapPallet/PersistentDataView')
    148         self.toggleBackground = Sprite(name='toggleBackground', parent=self, align=uiconst.CENTERTOP, pos=(0, 0, 32, 64), texturePath='res:/UI/Texture/classes/MapView/abstractToggle.png', opacity=1.0)
    149 
    150     def OnPreviewBtnClicked(self, *args):
    151         mapPreviewModeActive.toggle()
    152         self.UpdateEyeIcon()
    153 
    154     def UpdateEyeIcon(self):
    155         isActive = mapPreviewModeActive.get()
    156         if isActive:
    157             self.eyeSprite.SetTexturePath(eveicon.visibility)
    158         else:
    159             self.eyeSprite.SetTexturePath(eveicon.hidden)
    160 
    161     def UpdateAbstractState(self, is_abstract):
    162         if is_abstract:
    163             self._abstract_button.SetSelected(force=True)
    164             self.eyeSprite.Show()
    165             self.toggleBackground.Show()
    166         else:
    167             self._abstract_button.SetDeselected(force=True)
    168             self.eyeSprite.Hide()
    169             self.toggleBackground.Hide()
    170         self.UpdateEyeIcon()
    171 
    172     def DisableAbstractButton(self):
    173         self._abstract_button.enabled = False
    174 
    175     def EnableAbstractButton(self):
    176         self._abstract_button.enabled = True