widget.py (8533B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\sidePanel\widgets\system_security\widget.py 2 import localization 3 from carbonui import Align, TextColor, uiconst 4 from carbonui.control.button import Button 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.containerAutoSize import ContainerAutoSize 7 from carbonui.primitives.frame import Frame 8 from carbonui.primitives.sprite import Sprite 9 from carbonui.text.styles import TextHeader, TextBody 10 from carbonui.util.color import Color 11 from eve.client.script.ui import eveThemeColor 12 from eve.client.script.ui.shared.mapView.sidePanel.sidePanelWidgetBase import SidePanelWidgetBase 13 from eve.client.script.ui.shared.mapView.sidePanel.widgets.system_security.const import get_range_definition, RANGE_TITLES 14 from eve.client.script.ui.shared.mapView.sidePanel.widgets.system_security.controller import get_system_security_filter_controller 15 from security.client.const import SECURITY_LEVELS, SECURITY_RANGES, SAFE_SEC 16 from security.client.securityColor import COLORCURVE_SECURITY 17 from eve.common.lib import appConst 18 import eveicon 19 RANGE_FORMAT_UNCLASSIFIED = 'UI/Map/Filters/Security/secRangeUnclassified' 20 RANGE_FORMAT_MAX_TO_MIN = 'UI/Map/Filters/Security/secRangeMaxToMin' 21 22 class SystemSecurityFilterWidget(SidePanelWidgetBase): 23 MIN_HEIGHT = 360 24 25 def __init__(self, *args, **kwargs): 26 self._security_buttons = {} 27 self._range_container = None 28 self._controller = get_system_security_filter_controller() 29 super(SystemSecurityFilterWidget, self).__init__(*args, **kwargs) 30 self._set_selected(self._controller.get_security_level()) 31 32 @property 33 def selected_security_level(self): 34 return self._controller.get_security_level() 35 36 def _set_selected(self, security_level): 37 for level, button in self._security_buttons.items(): 38 button.set_selected(level == security_level) 39 40 self._construct_selected_range() 41 42 def _construct_header(self): 43 header_cont = ContainerAutoSize(parent=self, name='header_cont', align=Align.TOTOP) 44 TextHeader(parent=header_cont, name='header_text', align=Align.TOTOP, text=localization.GetByLabel('UI/Map/Filters/Security/panelHeaderTitle')) 45 desc_cont = ContainerAutoSize(parent=header_cont, name='desc_cont', align=Align.TOTOP, padTop=4) 46 TextBody(parent=desc_cont, name='desc_text', align=Align.TOTOP, text=localization.GetByLabel('UI/Map/Filters/Security/panelHeaderDescription'), color=TextColor.SECONDARY) 47 48 def _construct_content(self): 49 Container(parent=self.content_cont, name='pad_cont', align=Align.TOTOP, height=24) 50 for security_level in SECURITY_LEVELS: 51 entry = SecurityStatusEntry(security_level=security_level, callback=self._on_security_level_selected, parent=self.content_cont, align=Align.TOTOP, height=26, padTop=6) 52 self._security_buttons[security_level] = entry 53 54 def _construct_selected_range(self): 55 selected_range = self._controller.get_security_level() 56 range_definition = get_range_definition(selected_range) 57 if range_definition.description is None: 58 if self._range_container: 59 self._range_container.Flush() 60 return 61 if self._range_container: 62 self._range_container.Flush() 63 else: 64 self._range_container = ContainerAutoSize(parent=self, name='range_cont', align=Align.TOTOP, padTop=12) 65 TextHeader(parent=self._range_container, name='range_header', align=Align.TOTOP, text=localization.GetByLabel(range_definition.title)) 66 range_value_cont = Container(parent=self._range_container, name='range_header_cont', align=Align.TOTOP, height=20, padTop=4) 67 Sprite(parent=Container(parent=range_value_cont, name='range_icon_cont', align=Align.TOLEFT, width=16), name='range_icon', align=Align.CENTER, texturePath=range_definition.icon, color=TextColor.SECONDARY, width=16, height=16) 68 TextBody(parent=Container(parent=range_value_cont, name='range_value_cont', align=Align.TOALL, padLeft=6), name='range_value', align=Align.CENTERLEFT, text=self._get_range_string(SECURITY_RANGES[selected_range])) 69 TextBody(parent=self._range_container, name='range_desc', align=Align.TOTOP, text=localization.GetByLabel(range_definition.description), padTop=8) 70 if selected_range == SAFE_SEC: 71 Button(parent=self._range_container, name='safe_sec_set_destination_button', align=Align.TOTOP, label=localization.GetByLabel('UI/Map/Filters/Security/SetDestinationToStarterHub'), func=self._set_destination_to_starter_hub, texturePath=eveicon.set_destination, padTop=12) 72 73 def _set_destination_to_starter_hub(self, *args): 74 sm.GetService('starmap').SetWaypoint(appConst.solarSystemManifest, clearOtherWaypoints=True, origin='map_set_destination_to_starter_hub') 75 76 def _get_range_string(self, rng): 77 min = rng.min_value 78 max = rng.max_value 79 if rng.unclassified: 80 return localization.GetByLabel(RANGE_FORMAT_UNCLASSIFIED, color=TextColor.SECONDARY) 81 elif min == max: 82 return self._get_colored_value_string(min) 83 elif min < 0 and max == 0: 84 return localization.GetByLabel(RANGE_FORMAT_MAX_TO_MIN, max=self._get_colored_value_string(max), min=self._get_colored_value_string(min)) 85 else: 86 ret = '' 87 for i in range(int(min * 10) + 1, int(max * 10) + 1)[::-1]: 88 ret += self._get_colored_value_string(i / 10.0) + ' ' 89 90 return ret 91 92 def _get_colored_value_string(self, value): 93 idx = max(0, int(value * 10)) 94 color = COLORCURVE_SECURITY[idx] 95 hex_color = Color.RGBtoHex(*color) 96 return u'<color={}>{}</color>'.format(hex_color, value) 97 98 def _on_security_level_selected(self, security_level): 99 self._controller.set_security_level(security_level) 100 for level, button in self._security_buttons.items(): 101 button.set_selected(level == security_level) 102 103 104 class SecurityStatusEntry(Container): 105 default_state = uiconst.UI_NORMAL 106 107 def __init__(self, security_level, callback, *args, **kwargs): 108 super(SecurityStatusEntry, self).__init__(*args, **kwargs) 109 self._selected = False 110 self.security_level = security_level 111 self._callback = callback 112 super(SecurityStatusEntry, self).__init__(*args, **kwargs) 113 self._construct() 114 115 def _construct(self): 116 self._content_cont = Container(name='content_cont', parent=self, align=Align.TOALL, padLeft=20) 117 self._bg_cont = Container(name='bg_cont', parent=self, align=Align.TOALL) 118 definition = get_range_definition(self.security_level) 119 if definition.icon: 120 Sprite(parent=Container(parent=self._content_cont, name='icon_cont', align=Align.TOLEFT, width=16), name='icon', align=Align.CENTER, texturePath=definition.icon, color=TextColor.SECONDARY, state=uiconst.UI_DISABLED, width=16, height=16) 121 self.title = TextBody(text=localization.GetByLabel(RANGE_TITLES.get(self.security_level, '')), parent=Container(parent=self._content_cont, name='title_cont', align=Align.TOALL), align=Align.CENTERLEFT, padLeft=6 if definition.icon else 0) 122 self.bg = Frame(name='bg', parent=self._bg_cont, align=Align.TOALL, color=(1, 1, 1, 0.1), texturePath='res:/UI/Texture/classes/Button/background_cut_bottom_left_right.png', cornerSize=8) 123 124 def OnClick(self, *args, **kwargs): 125 if self._callback: 126 self._callback(self.security_level) 127 128 def OnMouseDown(self, *args): 129 self.bg.color = (1, 1, 1, 0.4) 130 super(SecurityStatusEntry, self).OnMouseDown(*args) 131 132 def OnMouseUp(self, *args): 133 self.bg.color = self.get_bg_color() 134 super(SecurityStatusEntry, self).OnMouseUp(*args) 135 136 def OnMouseEnter(self, *args): 137 self._mouse_over = True 138 self.bg.color = eveThemeColor.THEME_FOCUS[:3] + (0.3,) 139 super(SecurityStatusEntry, self).OnMouseEnter(*args) 140 141 def OnMouseExit(self, *args): 142 self._mouse_over = False 143 self.bg.color = self.get_bg_color() 144 super(SecurityStatusEntry, self).OnMouseExit(*args) 145 146 def set_selected(self, is_selected): 147 self._selected = is_selected 148 self.bg.color = self.get_bg_color() 149 150 def get_bg_color(self): 151 if self._selected: 152 return eveThemeColor.THEME_FOCUSDARK[:3] + (0.6,) 153 else: 154 return (1, 1, 1, 0.1)