areaToggleButtonMenuIcon.py (7942B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\studio\areaToggleButtonMenuIcon.py 2 from carbonui.control.contextMenu.menuUtil import ClearMenuLayer 3 from carbonui.text.color import TextColor 4 from carbonui import uiconst 5 from carbonui.uianimations import animations 6 from carbonui.text.styles import TextBody 7 from carbonui.uiconst import Align 8 import eveicon 9 from carbonui.control.contextMenu.contextMenuMixin import ContextMenuMixin 10 from carbonui.primitives.container import Container 11 from carbonui.uicore import uicore 12 from cosmetics.client.ships.skins.live_data import current_skin_design, current_skin_design_signals 13 from eve.client.script.ui import eveColor 14 from eve.client.script.ui.cosmetics.ship.pages.studio.circularButtonIcon import CircularMenuButtonIcon 15 from localization import GetByLabel 16 17 class AreaToggleButtonMenuIcon(CircularMenuButtonIcon): 18 default_texturePath = eveicon.ship_areas 19 default_hint = GetByLabel('UI/Personalization/ShipSkins/SKINR/Studio/PatternAreaApplication') 20 21 def __init__(self, slot_id, *args, **kwargs): 22 super(AreaToggleButtonMenuIcon, self).__init__(*args, **kwargs) 23 self.slot_id = slot_id 24 self.menu = None 25 self.update_selected() 26 self.connect_signals() 27 28 def Close(self): 29 try: 30 self.disconnect_signals() 31 finally: 32 super(AreaToggleButtonMenuIcon, self).Close() 33 34 def disconnect_signals(self): 35 current_skin_design_signals.on_component_attribute_changed.disconnect(self.on_current_design_component_attribute_changed) 36 37 def connect_signals(self): 38 current_skin_design_signals.on_component_attribute_changed.connect(self.on_current_design_component_attribute_changed) 39 40 def on_current_design_component_attribute_changed(self, *args): 41 self.update_selected() 42 43 def OnMouseUp(self, *args): 44 if self.has_open_menu(): 45 return 46 ClearMenuLayer() 47 left, top, width, height = self.GetAbsolute() 48 self.menu = AreaToggleButtonMenu(parent=uicore.layer.menu, left=left - AreaToggleButtonMenu.default_width - 16, top=top - (AreaToggleButtonMenu.default_height - height) / 2.0, slot_id=self.slot_id) 49 50 def GetHint(self): 51 if self.has_open_menu(): 52 return None 53 return super(AreaToggleButtonMenuIcon, self).GetHint() 54 55 def has_open_menu(self): 56 return self.menu and not self.menu.destroyed 57 58 def get_component_instance(self): 59 component_instance = current_skin_design.get().get_fitted_component_instance(self.slot_id) 60 return component_instance 61 62 def is_all_areas_enabled(self): 63 component_instance = self.get_component_instance() 64 if not component_instance: 65 return True 66 return component_instance.projection_area1 and component_instance.projection_area2 and component_instance.projection_area3 and component_instance.projection_area4 67 68 def update_selected(self): 69 if self.enabled and not self.is_all_areas_enabled(): 70 self.SetSelected() 71 else: 72 self.SetDeselected() 73 74 def Enable(self): 75 super(AreaToggleButtonMenuIcon, self).Enable() 76 self.update_selected() 77 78 def Disable(self): 79 super(AreaToggleButtonMenuIcon, self).Disable() 80 self.update_selected() 81 82 83 class BaseAreaToggleButtonIcon(CircularMenuButtonIcon): 84 area_name = None 85 86 def __init__(self, slot_id, *args, **kwargs): 87 super(BaseAreaToggleButtonIcon, self).__init__(*args, **kwargs) 88 self.slot_id = slot_id 89 self.update_selected() 90 self.text = TextBody(parent=self, text=self.area_name, align=Align.CENTERRIGHT, opacity=0.0) 91 92 def update_selected(self): 93 if self.get_value(): 94 self.SetSelected() 95 else: 96 self.SetDeselected() 97 98 def get_component_instance(self): 99 component_instance = current_skin_design.get().get_fitted_component_instance(self.slot_id) 100 return component_instance 101 102 def get_value(self): 103 raise NotImplemented 104 105 def set_value(self, value): 106 raise NotImplemented 107 108 def toggle_value(self): 109 self.set_value(not self.get_value()) 110 111 def OnClick(self, *args): 112 self.toggle_value() 113 self.update_selected() 114 current_skin_design.add_to_undo_history() 115 116 def OnMouseEnter(self, *args): 117 animations.FadeIn(self.text, endVal=TextColor.NORMAL[-1], duration=uiconst.TIME_ENTRY) 118 self.text.left = self.default_width + 8 119 animations.MorphScalar(self.text, 'top', -8, 0, duration=uiconst.TIME_ENTRY) 120 121 def OnMouseExit(self, *args): 122 animations.FadeOut(self.text, duration=0.1) 123 animations.MorphScalar(self.text, 'left', self.text.left, self.default_width, duration=0.1) 124 125 126 class PrimaryAreaToggleButtonIcon(BaseAreaToggleButtonIcon): 127 default_texturePath = eveicon.primary_area 128 area_name = GetByLabel('UI/Personalization/ShipSkins/SKINR/Studio/PrimaryArea') 129 130 def get_value(self): 131 return self.get_component_instance().projection_area1 132 133 def set_value(self, value): 134 self.get_component_instance().projection_area1 = value 135 136 137 class SecondaryAreaToggleButtonIcon(BaseAreaToggleButtonIcon): 138 default_texturePath = eveicon.secondary_area 139 area_name = GetByLabel('UI/Personalization/ShipSkins/SKINR/Studio/SecondaryArea') 140 141 def get_value(self): 142 return self.get_component_instance().projection_area2 143 144 def set_value(self, value): 145 self.get_component_instance().projection_area2 = value 146 147 148 class DetailingAreaToggleButtonIcon(BaseAreaToggleButtonIcon): 149 default_texturePath = eveicon.details 150 area_name = GetByLabel('UI/Personalization/ShipSkins/SKINR/Studio/DetailingArea') 151 152 def get_value(self): 153 return self.get_component_instance().projection_area3 154 155 def set_value(self, value): 156 self.get_component_instance().projection_area3 = value 157 158 159 class TechAreaToggleButtonIcon(BaseAreaToggleButtonIcon): 160 default_texturePath = eveicon.tech_area 161 area_name = GetByLabel('UI/Personalization/ShipSkins/SKINR/Studio/TechArea') 162 163 def get_value(self): 164 return self.get_component_instance().projection_area4 165 166 def set_value(self, value): 167 self.get_component_instance().projection_area4 = value 168 169 170 class AreaToggleButtonMenu(Container, ContextMenuMixin): 171 default_width = 32 172 default_height = 176 173 default_align = Align.ABSOLUTE 174 175 def __init__(self, slot_id, **kw): 176 super(AreaToggleButtonMenu, self).__init__(**kw) 177 self.primary_btn = PrimaryAreaToggleButtonIcon(parent=self, align=Align.CENTERTOP, slot_id=slot_id) 178 self.secondary_btn = SecondaryAreaToggleButtonIcon(parent=self, align=Align.CENTERTOP, slot_id=slot_id) 179 self.detail_btn = DetailingAreaToggleButtonIcon(parent=self, align=Align.CENTERTOP, slot_id=slot_id) 180 self.tech_btn = TechAreaToggleButtonIcon(parent=self, align=Align.CENTERTOP, slot_id=slot_id) 181 self.appear() 182 183 def appear(self): 184 animations.FadeTo(self, 0.0, 1.0, duration=uiconst.TIME_ENTRY) 185 center_top = self.default_height / 2 186 left_offset = 32 187 duration = 0.08 188 animations.MorphScalar(self.primary_btn, 'left', left_offset, 0, duration=duration) 189 animations.MorphScalar(self.primary_btn, 'top', center_top, 0, duration=duration) 190 animations.MorphScalar(self.secondary_btn, 'left', left_offset, 0, duration=duration) 191 animations.MorphScalar(self.secondary_btn, 'top', center_top, 48, duration=duration) 192 animations.MorphScalar(self.detail_btn, 'left', left_offset, 0, duration=duration) 193 animations.MorphScalar(self.detail_btn, 'top', center_top, 96, duration=duration) 194 animations.MorphScalar(self.tech_btn, 'left', left_offset, 0, duration=duration) 195 animations.MorphScalar(self.tech_btn, 'top', center_top, 144, duration=duration)