breach_point_asteroid_bracket.py (7262B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\bracketsAndTargets\breach_point_asteroid_bracket.py 2 import appConst 3 import carbonui 4 import carbonui.text.styles 5 import evetypes 6 import logging 7 import uthread2 8 from carbonui import Align, PickState 9 from carbonui.primitives.warningContainer import DangerContainer 10 from eve.client.script.remote.michelle import GetMichelle 11 from eve.client.script.ui import eveColor 12 from eve.client.script.ui.inflight.bracketsAndTargets.asteroid_bracket import AsteroidBracket, ExpandedBracket, ExpandedBracketAsteroid 13 from eve.client.script.ui.inflight.bracketsAndTargets.expanded_bracket import get_label_and_value_formatted 14 from localization import GetByLabel 15 from spacecomponents.client.components import breachPointAsteroid 16 from spacecomponents.common import componentConst 17 log = logging.getLogger(__name__) 18 19 class BreachPointAsteroidBracket(AsteroidBracket): 20 21 def has_expanded_bracket(self): 22 return True 23 24 def show_expanded_bracket(self): 25 if not self.expanded_bracket: 26 self.expanded_bracket = ExpandedBracketBreachPointAsteroid(parent=self.parent, item_id=self.itemID, bracket=self, idx=0, slimItem=self.slimItem) 27 28 29 class ExpandedBracketBreachPointAsteroid(ExpandedBracketAsteroid): 30 31 def __init__(self, **kwargs): 32 super(ExpandedBracketBreachPointAsteroid, self).__init__(**kwargs) 33 uthread2.start_tasklet(self.update_countdown_thread) 34 35 def update_countdown_thread(self): 36 while not self.destroyed: 37 self.update() 38 uthread2.sleep(0.5) 39 40 def construct_layout(self): 41 super(ExpandedBracketBreachPointAsteroid, self).construct_layout() 42 self.not_phased_in_warning = DangerContainer(name='not_phased_in_warning', parent=self.layout_grid, align=Align.TOPLEFT, text=GetByLabel('UI/PhasedAsteroid/MiningEfficiencyWarning'), hint=GetByLabel('UI/PhasedAsteroid/HintBreachedNotPhasedIn', item_name=evetypes.GetName(appConst.typeMobilePhaseAnchor)), pickState=PickState.ON, display=False, padTop=4) 43 44 def construct_labels(self): 45 super(ExpandedBracketBreachPointAsteroid, self).construct_labels() 46 self.state_label = carbonui.text.styles.TextDetail(name='collapse_timer_label', parent=self.layout_grid, display=False) 47 self.countdown_label = carbonui.text.styles.TextDetail(name='countdown_label', parent=self.layout_grid, display=False, pickState=PickState.OFF) 48 49 def update(self, is_bracket_floating = True): 50 super(ExpandedBracketBreachPointAsteroid, self).update(is_bracket_floating) 51 self.update_countdown_text() 52 state_label_text = self.get_state_text() 53 self.state_label.text = state_label_text 54 self.state_label.hint = self.get_state_hint() 55 self.state_label.display = bool(state_label_text) 56 self.check_show_not_phased_in_warning() 57 58 def check_show_not_phased_in_warning(self): 59 component = self.get_breach_point_asteroid_component() 60 if not component or component.state != breachPointAsteroid.BREACH_POINT_ASTEROID_ACTIVE: 61 display = False 62 else: 63 phaseable_component = self.get_phaseable_component() 64 display = False 65 if phaseable_component: 66 display = not phaseable_component.isPhasedIn 67 self.not_phased_in_warning.display = display 68 69 def update_countdown_text(self): 70 countdown_text = self.get_countdown_label_text() 71 self.countdown_label.text = countdown_text 72 self.countdown_label.display = bool(countdown_text) 73 74 def get_countdown_label_text(self): 75 component = self.get_breach_point_asteroid_component() 76 phaseable_component = self.get_phaseable_component() 77 if not component: 78 return None 79 if phaseable_component and phaseable_component.isPhasingIn: 80 countdown = phaseable_component.get_phasing_in_timer_formatted() 81 return get_label_and_value_formatted(GetByLabel('UI/PhasedAsteroid/UntilPhasedIn'), countdown) 82 if component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_INACTIVE: 83 countdown = component.get_entry_time_formatted() 84 return get_label_and_value_formatted(GetByLabel('UI/PhasedAsteroid/UntilBreach'), countdown) 85 if component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_ACTIVE: 86 countdown = component.get_exit_time_formatted() 87 return get_label_and_value_formatted(GetByLabel('UI/PhasedAsteroid/UntilCollapse'), countdown) 88 89 def get_state_text(self): 90 component = self.get_breach_point_asteroid_component() 91 phaseable_component = self.get_phaseable_component() 92 if not component or not phaseable_component: 93 return None 94 color = eveColor.DANGER_RED_HEX 95 if component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_INACTIVE: 96 state = GetByLabel('UI/PhasedAsteroid/LatentHeader') 97 elif component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_ACTIVE: 98 if phaseable_component.isPhasingIn: 99 state = GetByLabel('UI/PhasedAsteroid/BreachedPhasingIn') 100 color = eveColor.WARNING_ORANGE_HEX 101 elif phaseable_component.isPhasedIn: 102 state = GetByLabel('UI/PhasedAsteroid/BreachedPhasedIn') 103 color = eveColor.SUCCESS_GREEN_HEX 104 else: 105 state = GetByLabel('UI/PhasedAsteroid/BreachedNotPhasedIn') 106 else: 107 state = GetByLabel('UI/PhasedAsteroid/CollapsedHeader') 108 state = u'<color={}>{}</color>'.format(color, state) 109 return get_label_and_value_formatted(GetByLabel('UI/PhasedAsteroid/State'), state) 110 111 def get_state_hint(self): 112 component = self.get_breach_point_asteroid_component() 113 phaseable_component = self.get_phaseable_component() 114 if not component or not phaseable_component: 115 return None 116 if component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_INACTIVE: 117 return GetByLabel('UI/PhasedAsteroid/HintLatent') 118 if component.state == breachPointAsteroid.BREACH_POINT_ASTEROID_ACTIVE: 119 if phaseable_component.isPhasingIn: 120 return GetByLabel('UI/PhasedAsteroid/HintBreachedPhasingIn', item_name=evetypes.GetName(appConst.typeMobilePhaseAnchor)) 121 elif phaseable_component.isPhasedIn: 122 return GetByLabel('UI/PhasedAsteroid/HintBreachedPhasedIn') 123 else: 124 return GetByLabel('UI/PhasedAsteroid/HintBreachedNotPhasedIn', item_name=evetypes.GetName(appConst.typeMobilePhaseAnchor)) 125 else: 126 return GetByLabel('UI/PhasedAsteroid/HintCollapsed') 127 128 def get_breach_point_asteroid_component(self): 129 return self.get_component(componentConst.BREACH_POINT_ASTEROID) 130 131 def get_phaseable_component(self): 132 return self.get_component(componentConst.PHASEABLE) 133 134 def get_component(self, component_id): 135 bp = GetMichelle().GetBallpark() 136 if not bp: 137 return None 138 try: 139 return bp.componentRegistry.GetComponentForItem(self.slim_item.itemID, component_id) 140 except Exception as e: 141 log.exception(e)