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

mapViewLayoutWidget.py (34591B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\controls\mapViewLayoutWidget.py
      2 import carbonui
      3 import eveicon
      4 import localization
      5 import signals
      6 import uthread2
      7 from carbonui import uiconst, TextColor
      8 from carbonui.text.styles import TextHeader, TextDetail
      9 from carbonui.control.buttonIcon import ButtonIcon
     10 from carbonui.loggers.buttonLogger import log_button_clicked
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.fill import Fill
     13 from carbonui.primitives.frame import Frame
     14 from carbonui.primitives.sprite import Sprite
     15 from carbonui.uianimations import animations
     16 from carbonui.uicore import uicore
     17 from eve.client.script.ui import eveThemeColor
     18 from eve.client.script.ui.shared.mapView.controls.proximitySensor import ProximitySensor
     19 from eve.client.script.ui.shared.mapView.mapSignals import on_map_layout_mode_selected, on_layout_widget_expanded
     20 from eve.client.script.ui.shared.mapView.mapViewConst import VIEWMODE_LINES_SETTINGS, VIEWMODE_LAYOUT_SETTINGS, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_SETTINGS, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_ALL, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_MY, VIEWMODE_LINES_ALL, VIEWMODE_LINES_SELECTION, VIEWMODE_LINES_SELECTION_REGION, VIEWMODE_LAYOUT_SOLARSYSTEM, VIEWMODE_LAYOUT_CONSTELLATIONS, VIEWMODE_LAYOUT_REGIONS, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_NONE, VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS
     21 from eve.client.script.ui.shared.mapView.mapViewSettings import GetMapViewSetting, SetMapViewSetting
     22 BUTTON_COLOR_HOVER = (0.1,
     23  0.1,
     24  0.1,
     25  0.9)
     26 BUTTON_COLOR = (0.1,
     27  0.1,
     28  0.1,
     29  0.1)
     30 FADE_OUT_DURATION = 0.15
     31 FADE_DURATION = 0.2
     32 GLOW_BRIGHTNESS_NORMAL = 0.0
     33 GLOW_BRIGHTNESS_HOVER = 0.4
     34 GLOW_BRIGHTNESS_CLICK = 0.1
     35 setting_updated = signals.Signal('setting_updated')
     36 WIDGET_STYLE_NORMAL = {'initial_width': 120,
     37  'initial_height': 120,
     38  'expanded_width': 340,
     39  'button_spacing': 30,
     40  'button_offset_x': 40,
     41  'button_offset_y': 48,
     42  'button_width': 40,
     43  'button_height': 40,
     44  'button_height_expanded': 60,
     45  'extended_offset_x': 30,
     46  'extended_offset_y': 30,
     47  'extended_width': 320,
     48  'extended_height': 464,
     49  'compact_cont_width': 196,
     50  'compact_cont_height': 276,
     51  'extended_cont_width': 250,
     52  'extended_cont_height': 394,
     53  'extended_cont_padding': 20,
     54  'setting_group_button_spacing': 30,
     55  'setting_group_button_width': 40,
     56  'setting_group_button_height': 40,
     57  'setting_group_outer_padding': 16,
     58  'setting_group_padding_x': 20,
     59  'setting_group_padding_y': 10,
     60  'setting_group_label_height': 20,
     61  'setting_group_label_padding': (0,
     62                                  0,
     63                                  0,
     64                                  0),
     65  'setting_group_button_label_height': 24,
     66  'setting_group_label_class': TextHeader,
     67  'setting_group_label_color': TextColor.NORMAL,
     68  'setting_indicator_offset_y': 2,
     69  'icon_cont_size': 40,
     70  'icon_size': 32,
     71  'compact': False}
     72 WIDGET_STYLE_COMPACT = {'initial_width': 90,
     73  'initial_height': 90,
     74  'expanded_width': 200,
     75  'button_spacing': 10,
     76  'button_offset_x': 12,
     77  'button_offset_y': 18,
     78  'button_width': 32,
     79  'button_height': 32,
     80  'button_height_expanded': 60,
     81  'extended_offset_x': 20,
     82  'extended_offset_y': 20,
     83  'extended_width': 250,
     84  'extended_height': 300,
     85  'compact_cont_width': 196,
     86  'compact_cont_height': 276,
     87  'extended_cont_width': 196,
     88  'extended_cont_height': 276,
     89  'extended_cont_padding': 8,
     90  'setting_group_button_spacing': 30,
     91  'setting_group_button_width': 32,
     92  'setting_group_button_height': 32,
     93  'setting_group_outer_padding': 8,
     94  'setting_group_padding_x': 8,
     95  'setting_group_padding_y': 4,
     96  'setting_group_label_height': 12,
     97  'setting_group_label_padding': (2,
     98                                  4,
     99                                  0,
    100                                  0),
    101  'setting_group_button_label_height': 16,
    102  'setting_group_label_class': TextDetail,
    103  'setting_group_label_color': TextColor.SECONDARY,
    104  'setting_indicator_offset_y': 4,
    105  'icon_cont_size': 32,
    106  'icon_size': 16,
    107  'compact': True}
    108 
    109 class MapLayoutWidgetButton(Container):
    110     default_state = uiconst.UI_NORMAL
    111 
    112     def __init__(self, style, **kwargs):
    113         self._style = style
    114         super(MapLayoutWidgetButton, self).__init__(**kwargs)
    115 
    116     def ApplyAttributes(self, attributes):
    117         self._layout_mode = attributes.layout_mode
    118         self._text = attributes.text
    119         self._texture_path = attributes.texture_path
    120         self._func = attributes.func
    121         self._permanently_expanded = attributes.get('permanently_expanded', False)
    122         self._expanded = False
    123         self._idle_color = TextColor.NORMAL
    124         super(MapLayoutWidgetButton, self).ApplyAttributes(attributes)
    125         self.construct_layout()
    126         if self._permanently_expanded:
    127             self.expand(animate=False)
    128 
    129     def construct_layout(self):
    130         self._content = Container(parent=self, align=uiconst.VERTICALLY_CENTERED, width=self._style['button_width'], height=self._style['button_height'])
    131         self._icon_cont = Container(parent=self._content, align=uiconst.TOTOP, height=self._style['icon_cont_size'], state=uiconst.UI_DISABLED)
    132         self.construct_icon()
    133         self._label_cont = Container(parent=self._content, align=uiconst.TOTOP, height=self._style['setting_group_label_height'], opacity=0, state=uiconst.UI_DISABLED)
    134         self._label = TextDetail(parent=self._label_cont, align=uiconst.CENTER, text=self._text, state=uiconst.UI_DISABLED)
    135 
    136     def construct_icon(self):
    137         self._icon = Sprite(parent=self._icon_cont, align=uiconst.CENTER, height=self._style['icon_size'], width=self._style['icon_size'], texturePath=self._texture_path, color=TextColor.NORMAL, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=GLOW_BRIGHTNESS_NORMAL, state=uiconst.UI_DISABLED)
    138         self._fill = Fill(parent=self._icon_cont, align=uiconst.TOALL, color=BUTTON_COLOR, opacity=0.0, state=uiconst.UI_DISABLED)
    139 
    140     def expand(self, animate = True):
    141         compact = self._style['compact']
    142         self._expanded = True
    143         if animate:
    144             if not compact:
    145                 animations.StopAllAnimations(self._content)
    146                 animations.MorphScalar(self._content, 'height', self._style['button_height'], self._style['button_height_expanded'], duration=0.2)
    147                 animations.FadeIn(self._label_cont, duration=0.2)
    148             color = self._fill.color
    149             current_color = (color.r,
    150              color.g,
    151              color.b,
    152              color.a)
    153             animations.SpColorMorphTo(self._fill, current_color, BUTTON_COLOR_HOVER, duration=0.2)
    154         else:
    155             if not compact:
    156                 self._content.height = self._style['button_height_expanded']
    157                 self._label_cont.opacity = 1
    158             self._fill.color = BUTTON_COLOR_HOVER
    159 
    160     def contract(self, animate = True):
    161         compact = self._style['compact']
    162         if self._permanently_expanded:
    163             return
    164         self._expanded = False
    165         if animate:
    166             if not compact:
    167                 animations.StopAllAnimations(self._content)
    168                 animations.MorphScalar(self._content, 'height', self._style['button_height_expanded'], self._style['button_height'], duration=0.2)
    169                 animations.FadeOut(self._label_cont, duration=0.2)
    170             color = self._fill.color
    171             current_color = (color.r,
    172              color.g,
    173              color.b,
    174              color.a)
    175             animations.SpColorMorphTo(self._fill, current_color, BUTTON_COLOR, duration=0.2)
    176         else:
    177             if not compact:
    178                 self._content.height = self._style['button_height']
    179                 self._label_cont.opacity = 0
    180             self._fill.color = BUTTON_COLOR
    181 
    182     def OnMouseEnter(self, *args):
    183         animations.StopAllAnimations(self._icon)
    184         current_glow = self._icon.glowBrightness
    185         animations.MorphScalar(self._icon, 'glowBrightness', current_glow, GLOW_BRIGHTNESS_HOVER, duration=0.1)
    186         color = self._icon.color
    187         current_color = (color.r,
    188          color.g,
    189          color.b,
    190          color.a)
    191         animations.SpColorMorphTo(self._icon, current_color, TextColor.HIGHLIGHT, duration=0.1)
    192 
    193     def OnMouseExit(self, *args):
    194         animations.StopAllAnimations(self._icon)
    195         current_glow = self._icon.glowBrightness
    196         animations.MorphScalar(self._icon, 'glowBrightness', current_glow, GLOW_BRIGHTNESS_NORMAL, duration=0.1)
    197         color = self._icon.color
    198         current_color = (color.r,
    199          color.g,
    200          color.b,
    201          color.a)
    202         animations.SpColorMorphTo(self._icon, current_color, self._idle_color, duration=0.1)
    203 
    204     def OnMouseDown(self, *args):
    205         animations.StopAllAnimations(self._icon)
    206         self._icon.glowBrightness = GLOW_BRIGHTNESS_CLICK
    207 
    208     def OnMouseUp(self, *args):
    209         animations.StopAllAnimations(self._icon)
    210         self._icon.glowBrightness = GLOW_BRIGHTNESS_HOVER
    211 
    212     def OnClick(self, *args):
    213         uthread2.start_tasklet(self._func)
    214 
    215     def GetHint(self):
    216         if self._style['compact']:
    217             return self._text
    218 
    219 
    220 class MapLayoutWidgetLayoutModeButton(MapLayoutWidgetButton):
    221 
    222     def ApplyAttributes(self, attributes):
    223         super(MapLayoutWidgetLayoutModeButton, self).ApplyAttributes(attributes)
    224         self._layout_mode = attributes.layout_mode
    225         self.analyticID = 'layout_mode_button_%s' % self._layout_mode
    226         self._is_selected_func = attributes.is_selected_func
    227         self.set_selected(attributes.selected)
    228         self._register()
    229 
    230     def Close(self):
    231         super(MapLayoutWidgetLayoutModeButton, self).Close()
    232         self._unregister()
    233 
    234     def _register(self):
    235         setting_updated.connect(self._on_setting_updated)
    236 
    237     def _unregister(self):
    238         setting_updated.disconnect(self._on_setting_updated)
    239 
    240     def _on_setting_updated(self):
    241         selected = self._is_selected_func(self._layout_mode)
    242         self.set_selected(selected)
    243 
    244     def construct_icon(self):
    245         self._selected_frame = Frame(parent=self._icon_cont, align=uiconst.CENTER, width=self._style['icon_cont_size'] + 2, height=self._style['icon_cont_size'] + 2, color=(0.2, 0.2, 0.2, 1))
    246         super(MapLayoutWidgetLayoutModeButton, self).construct_icon()
    247 
    248     def OnClick(self, *args):
    249         uthread2.start_tasklet(self._func, self._layout_mode)
    250         log_button_clicked(self)
    251 
    252     def set_selected(self, selected):
    253         self._selected_frame.opacity = 1 if selected else 0
    254         self._icon.color = TextColor.HIGHLIGHT if selected else TextColor.NORMAL
    255         self._idle_color = TextColor.HIGHLIGHT if selected else TextColor.NORMAL
    256 
    257 
    258 class MapLayoutExtendedSettingButton(Container):
    259     default_state = uiconst.UI_NORMAL
    260 
    261     def __init__(self, style, analyticID, **kwargs):
    262         self._style = style
    263         self.analyticID = analyticID
    264         super(MapLayoutExtendedSettingButton, self).__init__(**kwargs)
    265 
    266     def ApplyAttributes(self, attributes):
    267         super(MapLayoutExtendedSettingButton, self).ApplyAttributes(attributes)
    268         self._value = attributes.value
    269         self._texture_path = attributes.texture_path
    270         self._text = attributes.text
    271         self._func = attributes.func
    272         self._content = Container(parent=self, align=uiconst.TOTOP, padTop=self._style['setting_group_padding_y'], width=self._style['button_width'], height=self._style['button_height'], state=uiconst.UI_DISABLED)
    273         self._icon_cont = Container(parent=self._content, align=uiconst.TOTOP, height=self._style['icon_cont_size'], state=uiconst.UI_DISABLED)
    274         self._icon = Sprite(parent=self._icon_cont, align=uiconst.CENTER, height=self._style['icon_size'], width=self._style['icon_size'], texturePath=self._texture_path, color=(1, 1, 1, 1), outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=GLOW_BRIGHTNESS_NORMAL, state=uiconst.UI_DISABLED)
    275         self._label_cont = Container(parent=self._content, align=uiconst.TOTOP, height=self._style['setting_group_button_label_height'], state=uiconst.UI_DISABLED)
    276         self._label = TextDetail(parent=self._label_cont, align=uiconst.CENTER, text=self._text, state=uiconst.UI_DISABLED)
    277 
    278     def OnMouseEnter(self, *args):
    279         animations.StopAllAnimations(self._icon)
    280         current_glow = self._icon.glowBrightness
    281         animations.MorphScalar(self._icon, 'glowBrightness', current_glow, GLOW_BRIGHTNESS_HOVER, duration=0.1)
    282 
    283     def OnMouseExit(self, *args):
    284         animations.StopAllAnimations(self._icon)
    285         current_glow = self._icon.glowBrightness
    286         animations.MorphScalar(self._icon, 'glowBrightness', current_glow, GLOW_BRIGHTNESS_NORMAL, duration=0.1)
    287 
    288     def OnMouseDown(self, *args):
    289         animations.StopAllAnimations(self._icon)
    290         self._icon.glowBrightness = GLOW_BRIGHTNESS_CLICK
    291 
    292     def OnMouseUp(self, *args):
    293         animations.StopAllAnimations(self._icon)
    294         self._icon.glowBrightness = GLOW_BRIGHTNESS_HOVER
    295 
    296     def OnClick(self, *args):
    297         self._func(self._value)
    298         log_button_clicked(self)
    299 
    300     def set_selected_value(self, value):
    301         if self._value == value:
    302             self._icon.color = TextColor.HIGHLIGHT
    303             self._label.color = TextColor.HIGHLIGHT
    304         else:
    305             self._icon.color = TextColor.SECONDARY
    306             self._label.color = TextColor.NORMAL
    307 
    308 
    309 class MapLayoutExtendedSettingGroup(Container):
    310 
    311     def __init__(self, style, **kwargs):
    312         self._style = style
    313         super(MapLayoutExtendedSettingGroup, self).__init__(**kwargs)
    314 
    315     def ApplyAttributes(self, attributes):
    316         super(MapLayoutExtendedSettingGroup, self).ApplyAttributes(attributes)
    317         self._setting_group = attributes.setting_group
    318         self._map_view_id = attributes.map_view_id
    319         self._setting_key = self._setting_group['setting_key']
    320         self._settings = self._setting_group['settings']
    321         self._text = localization.GetByLabel(self._setting_group['text'])
    322         self._func = attributes.func
    323         self._buttons = []
    324         self._selection_indicator = Fill(parent=self, align=uiconst.BOTTOMLEFT, height=2, top=self._style['setting_indicator_offset_y'], width=self._style['setting_group_button_width'] + self._style['setting_group_button_spacing'] / 2, color=eveThemeColor.THEME_FOCUS)
    325         self._label_container = Container(parent=self, align=uiconst.TOTOP, height=self._style['setting_group_label_height'], clipChildren=False, padding=self._style['setting_group_label_padding'])
    326         label_cls = self._style['setting_group_label_class']
    327         self._label = label_cls(parent=self._label_container, align=uiconst.TOPLEFT, text=self._text, color=self._style['setting_group_label_color'])
    328         self._content_container = Container(parent=self, align=uiconst.TOALL, padding=(self._style['setting_group_padding_x'],
    329          self._style['setting_group_padding_y'],
    330          self._style['setting_group_padding_x'],
    331          self._style['setting_group_padding_y']))
    332         for idx, setting in enumerate(self._settings):
    333             self._buttons.append(self._construct_setting_button(setting, idx))
    334 
    335         Fill(parent=self, align=uiconst.TOBOTTOM_NOPUSH, height=2, top=self._style['setting_indicator_offset_y'], color=(1, 1, 1, 0.2))
    336         current_value = GetMapViewSetting(self._setting_key, self._map_view_id)
    337         self._set_selected_value(current_value, animate=False)
    338         self._register()
    339 
    340     def Close(self):
    341         super(MapLayoutExtendedSettingGroup, self).Close()
    342         self._unregister()
    343 
    344     def _register(self):
    345         setting_updated.connect(self._on_setting_updated)
    346 
    347     def _unregister(self):
    348         setting_updated.disconnect(self._on_setting_updated)
    349 
    350     def _construct_setting_button(self, setting, idx):
    351         button_width = self._style['setting_group_button_width']
    352         button_spacing = self._style['setting_group_button_spacing']
    353         pos_x = idx * (button_width + button_spacing) - button_spacing / 4
    354         pos_y = 0
    355         width = button_width + button_spacing / 2
    356         height = self._style['button_height_expanded'] + 10
    357         return MapLayoutExtendedSettingButton(parent=self._content_container, align=uiconst.TOPLEFT, pos=(pos_x,
    358          pos_y,
    359          width,
    360          height), texture_path=setting['texture_path'], text=localization.GetByLabel(setting['text']), value=setting['value'], func=self._on_setting_button_pressed, pickState=uiconst.PickState.ON, style=self._style, analyticID='extended_setting_button_' + self._setting_key + '_' + str(setting['value']))
    361 
    362     def _on_setting_button_pressed(self, value):
    363         self._func(self._setting_key, value)
    364         self._set_selected_value(value)
    365 
    366     def _set_selected_value(self, value, animate = True):
    367         for button in self._buttons:
    368             button.set_selected_value(value)
    369 
    370         for idx, setting in enumerate(self._settings):
    371             if setting['value'] == value:
    372                 button_width = self._style['setting_group_button_width']
    373                 button_spacing = self._style['setting_group_button_spacing']
    374                 indent = idx * (button_width + button_spacing) + self._style['setting_group_padding_x'] - button_spacing / 4
    375                 if animate:
    376                     animations.MoveTo(self._selection_indicator, startPos=self._selection_indicator.GetPosition(), endPos=(indent, self._style['setting_indicator_offset_y']), duration=0.1)
    377                 else:
    378                     self._selection_indicator.SetPosition(indent, self._style['setting_indicator_offset_y'])
    379 
    380     def _on_setting_updated(self):
    381         current_value = GetMapViewSetting(self._setting_key, self._map_view_id)
    382         self._set_selected_value(current_value, animate=False)
    383 
    384 
    385 MODE_INITIAL = 'initial'
    386 MODE_EXPANDED = 'expanded'
    387 MODE_EXTENDED = 'extended'
    388 _LAYOUT_MODES = [{'layout_mode': VIEWMODE_LAYOUT_SOLARSYSTEM,
    389   'text': 'UI/Map/Layout/layoutUniverse',
    390   'icon': eveicon.universe_layout}, {'layout_mode': VIEWMODE_LAYOUT_CONSTELLATIONS,
    391   'text': 'UI/Map/Layout/layoutConstellation',
    392   'icon': eveicon.constellation_layout}, {'layout_mode': VIEWMODE_LAYOUT_REGIONS,
    393   'text': 'UI/Map/Layout/layoutRegion',
    394   'icon': eveicon.region_layout}]
    395 layoutSettings = {'setting_key': VIEWMODE_LAYOUT_SETTINGS,
    396  'text': 'UI/Map/Layout/settingGroupGeography',
    397  'settings': [{'texture_path': eveicon.universe_layout,
    398                'text': 'UI/Map/Layout/layoutUniverse',
    399                'value': VIEWMODE_LAYOUT_SOLARSYSTEM}, {'texture_path': eveicon.constellation_layout,
    400                'text': 'UI/Map/Layout/layoutConstellation',
    401                'value': VIEWMODE_LAYOUT_CONSTELLATIONS}, {'texture_path': eveicon.region_layout,
    402                'text': 'UI/Map/Layout/layoutRegion',
    403                'value': VIEWMODE_LAYOUT_REGIONS}]}
    404 linesSettings = {'setting_key': VIEWMODE_LINES_SETTINGS,
    405  'text': 'UI/Map/Layout/settingGroupNavigationLinks',
    406  'settings': [{'texture_path': eveicon.all_lines_layout,
    407                'text': 'UI/Map/Layout/linesAll',
    408                'value': VIEWMODE_LINES_ALL}, {'texture_path': eveicon.region_lines_layout,
    409                'text': 'UI/Map/Layout/linesRegion',
    410                'value': VIEWMODE_LINES_SELECTION_REGION}, {'texture_path': eveicon.selection_only_layout,
    411                'text': 'UI/Map/Layout/linesSelection',
    412                'value': VIEWMODE_LINES_SELECTION}]}
    413 jumpLineSettings = {'setting_key': VIEWMODE_LINES_SHOW_JUMP_BRIDGES_SETTINGS,
    414  'text': 'UI/Map/Layout/settingGroupJumpBridgeLinks',
    415  'settings': [{'texture_path': eveicon.jump_gate_layout,
    416                'text': 'UI/Map/Layout/jumpBridgeLinksAll',
    417                'value': VIEWMODE_LINES_SHOW_JUMP_BRIDGES_ALL}, {'texture_path': eveicon.jump_gate_access_layout,
    418                'text': 'UI/Map/Layout/jumpBridgeLinksWithAccess',
    419                'value': VIEWMODE_LINES_SHOW_JUMP_BRIDGES_MY}, {'texture_path': eveicon.jumpgate_none,
    420                'text': 'UI/Map/Layout/jumpBridgeLinksNone',
    421                'value': VIEWMODE_LINES_SHOW_JUMP_BRIDGES_NONE}]}
    422 
    423 def get_extended_settings(isAbstract):
    424     if isAbstract:
    425         return [layoutSettings, jumpLineSettings]
    426     else:
    427         return [layoutSettings, linesSettings, jumpLineSettings]
    428 
    429 
    430 class MapLayoutWidget(Container):
    431     default_align = uiconst.BOTTOMLEFT
    432     default_style = WIDGET_STYLE_NORMAL
    433     _extended_settings_container = None
    434 
    435     def __init__(self, style = None, *args, **kwargs):
    436         self._style = style if style else self.default_style
    437         super(MapLayoutWidget, self).__init__(*args, **kwargs)
    438 
    439     def ApplyAttributes(self, attributes):
    440         super(MapLayoutWidget, self).ApplyAttributes(attributes)
    441         self._layout_buttons = {}
    442         self._on_settings_changed_callback = attributes.on_settings_changed_callback
    443         self._map_view_id = attributes.map_view_id
    444         self._mode_definitions = None
    445         self._current_mode = MODE_INITIAL
    446         self._proximity_entered = False
    447         self._mouse_entered = False
    448         self._highlighted = False
    449         self._extended = False
    450         self._expanded = False
    451         self._initialize_mode_definitions()
    452         self._initialize_proximity_sensor()
    453         self._construct_layout()
    454         self._update_layout_button_icon()
    455         self._register()
    456 
    457     def Close(self):
    458         self._unregister()
    459         super(MapLayoutWidget, self).Close()
    460 
    461     def _register(self):
    462         self._global_click = uicore.event.RegisterForTriuiEvents(uiconst.UI_MOUSEDOWN, self.on_global_mouse_down)
    463         self._proximity_sensor.on_mouse_enter.connect(self._on_mouse_enter)
    464         self._proximity_sensor.on_mouse_exit.connect(self._on_mouse_exit)
    465 
    466     def _unregister(self):
    467         uicore.event.UnregisterForTriuiEvents(self._global_click)
    468         self._proximity_sensor.on_mouse_enter.disconnect(self._on_mouse_enter)
    469         self._proximity_sensor.on_mouse_exit.disconnect(self._on_mouse_exit)
    470 
    471     def _initialize_proximity_sensor(self):
    472         self._proximity_sensor = ProximitySensor(parent=self, align=uiconst.TOALL)
    473 
    474     def _construct_layout(self):
    475         self._layout_button = MapLayoutWidgetButton(name='layout_button', parent=self, align=uiconst.BOTTOMLEFT, layout_mode='layout', text=localization.GetByLabel('UI/Map/Layout/layoutButton'), texture_path=eveicon.universe_layout, pos=(self._style['button_offset_x'],
    476          self._style['button_offset_y'],
    477          self._style['button_width'],
    478          self._style['button_height']), func=self._on_layout_button_pressed, pickState=carbonui.PickState.ON, style=self._style)
    479         self._construct_layout_mode_section()
    480 
    481     def _construct_layout_mode_section(self):
    482         self._layout_setting_container = Container(name='layout_setting_container', parent=self, align=uiconst.BOTTOMLEFT, pos=(0,
    483          0,
    484          self._style['expanded_width'],
    485          self._style['initial_height']), opacity=0)
    486         current_layout = GetMapViewSetting(VIEWMODE_LAYOUT_SETTINGS, self._map_view_id)
    487         for idx, definition in enumerate(_LAYOUT_MODES):
    488             layout_mode = definition['layout_mode']
    489             selected = layout_mode == current_layout
    490             self._layout_buttons[layout_mode] = self._construct_layout_mode_button(definition, idx, selected)
    491 
    492         self._extended_settings_button = MapLayoutWidgetButton(name='layout_button', parent=self._layout_setting_container, align=uiconst.BOTTOMLEFT, layout_mode='layout', text=localization.GetByLabel('UI/Map/Layout/buttonMore'), texture_path=eveicon.more_vertical, permanently_expanded=True, pos=(self._get_layout_button_offset_x(len(_LAYOUT_MODES)),
    493          self._style['button_offset_y'],
    494          self._style['button_width'],
    495          self._style['button_height']), func=self._on_extended_settings_button_pressed, style=self._style)
    496         self._layout_setting_container.Hide()
    497 
    498     def _get_layout_button_offset_x(self, idx):
    499         return self._style['button_offset_x'] + idx * (self._style['button_width'] + self._style['button_spacing'])
    500 
    501     def _construct_layout_mode_button(self, layout_mode, idx, selected):
    502         return MapLayoutWidgetLayoutModeButton(name='layout_mode_button_{}'.format(layout_mode['layout_mode']), parent=self._layout_setting_container, align=uiconst.BOTTOMLEFT, layout_mode=layout_mode['layout_mode'], text=localization.GetByLabel(layout_mode['text']), texture_path=layout_mode['icon'], permanently_expanded=True, selected=selected, pos=(self._get_layout_button_offset_x(idx),
    503          self._style['button_offset_y'],
    504          self._style['button_width'],
    505          self._style['button_height']), func=self._on_layout_mode_button_pressed, is_selected_func=self._is_layout_mode_selected, style=self._style)
    506 
    507     def _is_layout_mode_selected(self, layout_mode):
    508         current_layout = GetMapViewSetting(VIEWMODE_LAYOUT_SETTINGS, self._map_view_id)
    509         return layout_mode == current_layout
    510 
    511     def _extended_settings_container_needs_constructing(self, currentAbstractSetting):
    512         if not self._extended_settings_container:
    513             return True
    514         if self._extended_settings_container.destroyed:
    515             return True
    516         if currentAbstractSetting != getattr(self._extended_settings_container, 'is_abstract', None):
    517             return True
    518         return False
    519 
    520     def _construct_extended_settings_section(self):
    521         is_abstract = GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, self._map_view_id)
    522         if not self._extended_settings_container_needs_constructing(is_abstract):
    523             return
    524         extended_settings = get_extended_settings(is_abstract)
    525         extended_cont_height = self._get_extended_setting_height(len(extended_settings))
    526         self._extended_settings_container = Container(name='extended_settings_container', parent=self, state=uiconst.UI_NORMAL, align=uiconst.BOTTOMLEFT, pos=(self._style['extended_offset_x'],
    527          self._style['extended_offset_y'],
    528          self._style['extended_cont_width'],
    529          extended_cont_height), bgColor=eveThemeColor.THEME_TINT, opacity=0)
    530         self._extended_settings_container.is_abstract = is_abstract
    531         for idx, setting_group in enumerate(extended_settings):
    532             self._construct_extended_setting_group(setting_group, idx)
    533 
    534         ButtonIcon(parent=self._extended_settings_container, align=uiconst.TOPRIGHT, size=20, texturePath=eveicon.close, func=self._on_close_extended_settings_button_pressed)
    535 
    536     def _get_extended_setting_height(self, num_groups):
    537         extended_cont_height = self._style['extended_cont_height']
    538         if num_groups == 3:
    539             return extended_cont_height
    540         diff = 3 - num_groups
    541         group_height = self._get_group_height()
    542         extended_cont_height -= diff * group_height
    543         return extended_cont_height
    544 
    545     def _get_group_height(self):
    546         return (self._style['extended_cont_height'] - self._style['extended_cont_padding'] * 2) / 3
    547 
    548     def _construct_extended_setting_group(self, setting_group, idx):
    549         height = self._get_group_height()
    550         offset_x = self._style['setting_group_outer_padding']
    551         offset_y = idx * (height + self._style['setting_group_padding_y']) + self._style['setting_group_padding_y']
    552         width = self._style['extended_cont_width'] - self._style['setting_group_outer_padding'] * 2
    553         return MapLayoutExtendedSettingGroup(name='extended_setting_group', parent=self._extended_settings_container, align=uiconst.TOPLEFT, setting_group=setting_group, map_view_id=self._map_view_id, pos=(offset_x,
    554          offset_y,
    555          width,
    556          height), func=self._on_extended_setting_group_pressed, style=self._style)
    557 
    558     def _enable_highlight(self):
    559         if self._highlighted:
    560             return
    561         self._highlighted = True
    562         self._layout_button.expand()
    563 
    564     def _disable_highlight(self):
    565         if not self._highlighted:
    566             return
    567         self._highlighted = False
    568         self._layout_button.contract()
    569 
    570     def _on_mouse_enter(self):
    571         self._proximity_entered = True
    572         self._update_expanded_state()
    573 
    574     def _on_mouse_exit(self):
    575         self._proximity_entered = False
    576         self._check_close_expanded_view()
    577         self._update_expanded_state()
    578 
    579     def OnMouseEnter(self, *args):
    580         self._mouse_entered = True
    581         self._update_expanded_state()
    582 
    583     def OnMouseExit(self, *args):
    584         self._mouse_entered = False
    585         self._check_close_expanded_view()
    586         self._update_expanded_state()
    587 
    588     def on_global_mouse_down(self, *args, **kwargs):
    589         if not self._proximity_sensor.mouse_inside():
    590             self.set_initial_mode()
    591         return True
    592 
    593     def _check_close_expanded_view(self):
    594         if self._mouse_entered or self._proximity_entered or self._extended:
    595             return
    596         self.set_initial_mode()
    597 
    598     def _update_expanded_state(self):
    599         if self._mouse_entered or self._proximity_entered:
    600             self._enable_highlight()
    601         else:
    602             self._disable_highlight()
    603 
    604     def _on_layout_button_pressed(self, *args):
    605         self.set_expanded_mode()
    606 
    607     def _on_layout_mode_button_pressed(self, layout_mode):
    608         SetMapViewSetting(VIEWMODE_LAYOUT_SETTINGS, layout_mode, self._map_view_id)
    609         self._update_layout_button_icon()
    610         uthread2.start_tasklet(self._on_settings_changed_callback, VIEWMODE_LAYOUT_SETTINGS, layout_mode)
    611         setting_updated()
    612         on_map_layout_mode_selected(layout_mode)
    613         sm.ScatterEvent('OnMapLayoutModeSelected', layout_mode)
    614 
    615     def Show(self, *args):
    616         self._update_layout_button_icon()
    617         super(MapLayoutWidget, self).Show(*args)
    618 
    619     def _update_layout_button_icon(self):
    620         current_layout = GetMapViewSetting(VIEWMODE_LAYOUT_SETTINGS, self._map_view_id)
    621         for layout_mode in _LAYOUT_MODES:
    622             if layout_mode['layout_mode'] == current_layout:
    623                 self._layout_buttons[layout_mode['layout_mode']].set_selected(True)
    624                 self._layout_button._icon.texturePath = layout_mode['icon']
    625             else:
    626                 self._layout_buttons[layout_mode['layout_mode']].set_selected(False)
    627 
    628     def _on_extended_settings_button_pressed(self):
    629         self._construct_extended_settings_section()
    630         self.set_extended_mode()
    631 
    632     def _on_close_extended_settings_button_pressed(self):
    633         self.set_initial_mode()
    634 
    635     def _on_extended_setting_group_pressed(self, setting_key, value):
    636         SetMapViewSetting(setting_key, value, self._map_view_id)
    637         self._on_settings_changed_callback(setting_key, value)
    638         self._update_layout_button_icon()
    639         setting_updated()
    640         if setting_key == VIEWMODE_LAYOUT_SETTINGS:
    641             on_map_layout_mode_selected(value)
    642             sm.ScatterEvent('OnMapLayoutModeSelected', value)
    643 
    644     def _initialize_mode_definitions(self):
    645         self._mode_definitions = {MODE_INITIAL: {'enable': self._enable_initial_mode,
    646                         'disable': self._disable_initial_mode},
    647          MODE_EXPANDED: {'enable': self._enable_expanded_mode,
    648                          'disable': self._disable_expanded_mode},
    649          MODE_EXTENDED: {'enable': self._enable_extended_mode,
    650                          'disable': self._disable_extended_mode}}
    651 
    652     def _switch_mode(self, new_mode):
    653         if self._current_mode == new_mode:
    654             return
    655         delay = 0.0
    656         if self._current_mode:
    657             disable_func = self._mode_definitions[self._current_mode]['disable']
    658             delay = disable_func()
    659         self._current_mode = new_mode
    660         enable_func = self._mode_definitions[new_mode]['enable']
    661         enable_func(delay=delay)
    662 
    663     def set_initial_mode(self):
    664         self._switch_mode(MODE_INITIAL)
    665 
    666     def set_expanded_mode(self):
    667         self._switch_mode(MODE_EXPANDED)
    668 
    669     def set_extended_mode(self):
    670         self._switch_mode(MODE_EXTENDED)
    671 
    672     def _enable_initial_mode(self, animate = True, delay = 0.01):
    673         if animate:
    674             animations.StopAllAnimations(self._layout_button)
    675             animations.FadeIn(self._layout_button, duration=FADE_DURATION, timeOffset=delay)
    676         else:
    677             self._layout_button.opacity = 1
    678         self._layout_button.display = True
    679         self.SetSize(self._style['initial_width'], self._style['initial_height'])
    680 
    681     def _disable_initial_mode(self, animate = True, delay = 0.0):
    682         if animate:
    683             animations.StopAllAnimations(self._layout_button)
    684             animations.FadeOut(self._layout_button, duration=FADE_OUT_DURATION, timeOffset=delay)
    685         else:
    686             self._layout_button.opacity = 0
    687         self._layout_button.display = False
    688         return 0
    689 
    690     def _enable_expanded_mode(self, animate = True, delay = 0.0):
    691         self._expanded = True
    692         if animate:
    693             animations.StopAllAnimations(self._layout_setting_container)
    694             animations.FadeIn(self._layout_setting_container, duration=FADE_DURATION, timeOffset=delay)
    695         else:
    696             self._layout_setting_container.opacity = 1
    697         self._layout_setting_container.display = True
    698         self.SetSize(self._style['expanded_width'], self._style['initial_height'])
    699         on_layout_widget_expanded()
    700         sm.ScatterEvent('OnLayoutWidgetExpanded')
    701 
    702     def _disable_expanded_mode(self, animate = True, delay = 0.0):
    703         self._expanded = False
    704         if animate:
    705             animations.StopAllAnimations(self._layout_setting_container)
    706             animations.FadeOut(self._layout_setting_container, duration=FADE_OUT_DURATION, timeOffset=delay)
    707         else:
    708             self._layout_setting_container.opacity = 0
    709         self._layout_setting_container.display = False
    710         return 0
    711 
    712     def _enable_extended_mode(self, animate = True, delay = 0.0):
    713         self._extended = True
    714         if animate:
    715             animations.StopAllAnimations(self._extended_settings_container)
    716             animations.FadeIn(self._extended_settings_container, duration=FADE_DURATION, timeOffset=delay)
    717         else:
    718             self._extended_settings_container.opacity = 1
    719         self._extended_settings_container.display = True
    720         self.SetSize(self._style['extended_width'], self._style['extended_height'])
    721 
    722     def _disable_extended_mode(self, animate = True, delay = 0.0):
    723         self._extended = False
    724         if animate:
    725             animations.StopAllAnimations(self._extended_settings_container)
    726             animations.FadeOut(self._extended_settings_container, duration=FADE_OUT_DURATION, timeOffset=delay)
    727         else:
    728             self._extended_settings_container.opacity = 0
    729         self._extended_settings_container.display = False
    730         return 0
    731 
    732 
    733 class MapLayoutWidgetCompact(MapLayoutWidget):
    734     default_style = WIDGET_STYLE_COMPACT