jumpBridgeCont.py (11275B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\spacecomponents\client\ui\jumpbridge\jumpBridgeCont.py 2 import math 3 import eveicon 4 import uthread2 5 from carbon.common.script.util.timerstuff import AutoTimer 6 from carbonui import TextColor, Align, TextAlign, PickState 7 from carbonui.control.button import Button 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.containerAutoSize import ContainerAutoSize 10 from carbonui.primitives.fill import Fill 11 from carbonui.primitives.frame import Frame 12 from carbonui.primitives.layoutGrid import LayoutGrid 13 from carbonui.primitives.sprite import Sprite 14 from carbonui.text.styles import TextBody, TextHeadline 15 from carbonui.uiconst import UI_DISABLED 16 from eve.client.script.ui import eveColor, eveThemeColor 17 from eve.client.script.ui.control.gaugeCircular import GaugeCircular 18 from eve.client.script.ui.eveColor import TUNGSTEN_GREY 19 from eveexceptions import ExceptionEater 20 from localization import GetByLabel 21 from spacecomponents.client.ui.jumpbridge.jumpBridgeContController import JumpBridgeContController, JumpBridgeValuesNoAccess 22 23 class JumpBridgeCont(Container): 24 default_name = 'jumpBridgeCont' 25 CONTENT_HEIGHT = 170 26 __notifyevents__ = ['OnCapitalSystemChanged', 27 'OnSessionChanged', 28 'OnJumpBridgeChargeChanged', 29 'OnJumpBridgeActivationChanged'] 30 31 def ApplyAttributes(self, attributes): 32 super(JumpBridgeCont, self).ApplyAttributes(attributes) 33 self.item_id = attributes.itemID 34 self.type_id = attributes.typeID 35 self.panel = attributes.panel 36 self.jump_bridge_cont_controller = JumpBridgeContController(self.item_id, self.type_id) 37 self.construct_ui() 38 sm.RegisterNotify(self) 39 self._connect_signals() 40 41 def _connect_signals(self): 42 with ExceptionEater('JumpBridgeCont: Failing to connect signals'): 43 self.panel.on_collapse_changed.connect(self._on_collapse_changed) 44 45 def _disconnect_signals(self): 46 with ExceptionEater('JumpBridgeCont: Failing to disconnect signals'): 47 self.panel.on_collapse_changed.disconnect(self._on_collapse_changed) 48 49 def construct_ui(self): 50 self._construct_button() 51 self._construct_center_sprite_cont() 52 self._construct_top_cont() 53 self._update_item_id_and_ui() 54 55 def _construct_button(self): 56 cont = ContainerAutoSize(parent=self, align=Align.TOBOTTOM) 57 button_grid = LayoutGrid(parent=cont, columns=3, align=Align.CENTER) 58 button_grid.AddCell(Fill(align=Align.TOPLEFT)) 59 button_grid.AddCell(Fill(align=Align.TOPLEFT), minWidth=168) 60 button_grid.AddCell(Fill(align=Align.TOPLEFT)) 61 button_grid.FillRow() 62 self._left_btn_sprite = Sprite(parent=button_grid, pos=(0, 4, 147, 24), align=Align.CENTERRIGHT, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterLeftSide.png', color=TUNGSTEN_GREY, state=UI_DISABLED) 63 self._button = Button(parent=button_grid, align=Align.CENTER, label=GetByLabel('UI/Inflight/InitiateJump'), func=self.jump) 64 self._right_btn_sprite = Sprite(parent=button_grid, pos=(0, 4, 147, 24), align=Align.CENTERLEFT, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterRightSide.png', color=TUNGSTEN_GREY, state=UI_DISABLED) 65 66 def _construct_center_sprite_cont(self): 67 self.center_sprite_cont = Container(name='center_sprite_cont', parent=self, height=40, align=Align.TOBOTTOM) 68 self.center_icon_cont = Container(parent=self.center_sprite_cont, align=Align.TOBOTTOM, height=40) 69 Sprite(parent=self.center_icon_cont, pos=(0, 0, 204, 66), align=Align.CENTERTOP, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterCenter.png', color=TUNGSTEN_GREY, state=UI_DISABLED) 70 Sprite(parent=self.center_icon_cont, pos=(0, 0, 26, 26), align=Align.CENTERTOP, texturePath='res:/UI/Texture/classes/ShipCaster/shipcasterCenterIcon.png', state=UI_DISABLED) 71 sweep_angle = 2 * math.pi * 0.21 72 start_angle = -math.pi / 2 - sweep_angle / 2 73 self.gauge = GaugeWithRed(parent=self.center_sprite_cont, showMarker=False, radius=118, lineWidth=4.0, startAngle=start_angle, angle=sweep_angle, align=Align.CENTERTOP, pickState=PickState.OFF) 74 75 def _construct_top_cont(self): 76 top_cont = Container(name='top_cont', parent=self, align=Align.TOBOTTOM, height=70, top=32) 77 self.cost_label_cont = ContainerAutoSize(parent=top_cont, align=Align.TOBOTTOM) 78 cost_grid = LayoutGrid(parent=self.cost_label_cont, align=Align.CENTER, margin=8, cellSpacing=(8, 0)) 79 self.warning_sprite = Sprite(parent=cost_grid, align=Align.CENTER, pos=(0, 0, 16, 16), texturePath=eveicon.difficulty, opacity=TextColor.SECONDARY.opacity) 80 self.warning_sprite.Hide() 81 self.cost_label = TextBody(parent=cost_grid, align=Align.CENTERLEFT, color=TextColor.SECONDARY) 82 Frame(bgParent=cost_grid, opacity=0.1) 83 Fill(bgParent=cost_grid, color=eveColor.BLACK, opacity=0.2) 84 spacer = Container(parent=top_cont, align=Align.TOBOTTOM, height=8) 85 self.zone_label = TextBody(name='zone_label', parent=top_cont, align=Align.TOBOTTOM, textAlign=TextAlign.CENTER, color=eveThemeColor.THEME_FOCUS) 86 self.system_name_label = TextHeadline(parent=top_cont, align=Align.TOBOTTOM, text='', color=TextColor.HIGHLIGHT, textAlign=TextAlign.CENTER) 87 c = ContainerAutoSize(parent=top_cont, align=Align.TOBOTTOM, top=4) 88 grid = LayoutGrid(parent=c, align=Align.CENTERTOP, columns=3, cellSpacing=(8, 0)) 89 self.capacitory_label = TextBody(parent=grid) 90 self.capacitory_div = Fill(parent=grid, pos=(0, 0, 1, 4), align=Align.CENTER, opacity=0.5) 91 self.capacitor_perc_label = TextBody(parent=grid) 92 93 def jump(self, *args): 94 sm.GetService('menu').JumpThroughStructureJumpBridge(self.item_id) 95 96 def _update_item_id_and_ui(self): 97 self.update_ui(force=True) 98 self.updateTimer = AutoTimer(2000, self.update_ui) 99 100 def _should_update_ui(self, force): 101 if force: 102 return True 103 if not self.panel: 104 return False 105 if self.panel.is_collapsed: 106 return False 107 return True 108 109 def update_ui(self, force = False): 110 if self.destroyed: 111 self.updateTimer = None 112 return 113 if not self._should_update_ui(force): 114 return 115 with ExceptionEater('JumpBridgeCont:Failed to update ui'): 116 self._update_target_name() 117 jump_bridge_values = self.jump_bridge_cont_controller.get_jump_bridge_values() 118 if not jump_bridge_values: 119 return 120 self._update_button(jump_bridge_values) 121 self._update_top_cont(jump_bridge_values) 122 123 def _update_button(self, jump_bridge_values): 124 from menucheckers import CelestialChecker 125 from menucheckers import SessionChecker 126 self._button.Disable() 127 self._button.hint = '' 128 self._left_btn_sprite.opacity = 0.5 129 self._right_btn_sprite.opacity = 0.5 130 if isinstance(jump_bridge_values, JumpBridgeValuesNoAccess): 131 self._button.hint = GetByLabel('UI/Inflight/SpaceComponents/JumpBridge/NoAccess') 132 return 133 slim_item = self.jump_bridge_cont_controller.get_slim_item() 134 if not slim_item: 135 return 136 celestialChecker = CelestialChecker(slim_item, cfg, SessionChecker(session, sm)) 137 if celestialChecker.OfferActivateJumpBridge(): 138 self._left_btn_sprite.opacity = 1.0 139 self._right_btn_sprite.opacity = 1.0 140 self._button.Enable() 141 self._button.hint = None 142 143 def _update_top_cont(self, jump_bridge_values): 144 if self.destroyed: 145 return 146 if isinstance(jump_bridge_values, JumpBridgeValuesNoAccess): 147 self._update_top_cont_without_access() 148 else: 149 self._update_top_cont_with_access(jump_bridge_values) 150 151 def _update_target_name(self): 152 system_name = self.jump_bridge_cont_controller.get_target_system_name() 153 self.system_name_label.text = system_name 154 155 def _update_top_cont_with_access(self, jump_bridge_values): 156 self.capacitory_label.text = jump_bridge_values.capacitory_text 157 self.capacitor_perc_label.text = jump_bridge_values.capacitor_perc_text 158 self.capacitor_perc_label.Show() 159 self.capacitory_div.Show() 160 self.zone_label.text = jump_bridge_values.zone_text 161 self.zone_label.Show() 162 self.cost_label.text = jump_bridge_values.cost_text 163 cost_prop = jump_bridge_values.cost_proportion 164 if jump_bridge_values.has_sufficient_charge: 165 capacity_prop = jump_bridge_values.capacity_proportion 166 white_prop = capacity_prop - cost_prop 167 self.gauge.SetValue(white_prop) 168 self.gauge.UpdateRedGauge(white_prop, capacity_prop) 169 self.warning_sprite.Hide() 170 else: 171 self.gauge.SetValue(0) 172 self.gauge.UpdateRedGauge(0, cost_prop) 173 self.warning_sprite.Show() 174 self.gauge.Show() 175 self.center_icon_cont.Hide() 176 177 def _update_top_cont_without_access(self): 178 self.capacitory_label.text = GetByLabel('UI/Inflight/SpaceComponents/JumpBridge/Redacted') 179 self.capacitor_perc_label.Hide() 180 self.capacitory_div.Hide() 181 self.zone_label.Hide() 182 self.cost_label.text = GetByLabel('UI/Inflight/SpaceComponents/JumpBridge/NoAccess') 183 self.warning_sprite.Show() 184 self.gauge.Hide() 185 self.center_icon_cont.Show() 186 187 def OnCapitalSystemChanged(self, change): 188 self.jump_bridge_cont_controller.clear_capital_memoize() 189 self.jump_bridge_cont_controller.reset_jump_bridge_values() 190 191 def OnSessionChanged(self, isremote, sess, change): 192 if 'allianceid' in change: 193 self.jump_bridge_cont_controller.clear_capital_memoize() 194 self.jump_bridge_cont_controller.reset_jump_bridge_values() 195 if 'shipid' in change: 196 self.jump_bridge_cont_controller.reset_jump_bridge_values() 197 self.update_ui() 198 199 def _on_collapse_changed(self, collapsing = False): 200 if not collapsing: 201 uthread2.StartTasklet(self.update_ui, True) 202 203 def OnJumpBridgeChargeChanged(self): 204 self.jump_bridge_cont_controller.reset_jump_bridge_values() 205 206 def OnJumpBridgeActivationChanged(self): 207 self.jump_bridge_cont_controller.reset_jump_bridge_values() 208 209 def Close(self): 210 self._disconnect_signals() 211 super(JumpBridgeCont, self).Close() 212 213 214 class GaugeWithRed(GaugeCircular): 215 216 def ApplyAttributes(self, attributes): 217 self.redGauge = None 218 super(GaugeWithRed, self).ApplyAttributes(attributes) 219 220 def Reconstruct(self): 221 self._ConstructGauge() 222 self._ConstructRedGauge() 223 self._ConstructBGGauge() 224 225 def _ConstructRedGauge(self): 226 if self.redGauge: 227 self.redGauge.Close() 228 self.redGauge = self.ConstructLine(eveColor.HOT_RED, eveColor.HOT_RED) 229 self.redGauge.end = 0 230 self.redGauge.name = 'redGaugeLine' 231 232 def UpdateRedGauge(self, start, end): 233 self.redGauge.start = start 234 self.redGauge.end = end