factionSelector.py (2835B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\studio\factionSelector.py 2 from carbonui import Align 3 from carbonui.control.buttonIcon import ButtonIcon 4 from carbonui.primitives.cardsContainer import CardsContainer 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.frame import Frame 7 from carbonui.primitives.sprite import Sprite 8 from characterdata.factions import get_faction_name 9 from eve.client.script.ui import eveColor 10 from eve.client.script.ui.cosmetics.ship.pages.studio.studioUtil import get_ship_factions 11 from eve.client.script.ui.shared.shipTree import shipTreeConst 12 ICON_SIZE = 48 13 14 class FactionSelector(CardsContainer): 15 default_contentSpacing = (4, 4) 16 default_cardHeight = ICON_SIZE 17 default_cardMaxWidth = ICON_SIZE + 16 18 19 def __init__(self, faction_id_setting, **kwargs): 20 super(FactionSelector, self).__init__(**kwargs) 21 self.buttons = [] 22 self.faction_id_setting = faction_id_setting 23 for faction_id in get_ship_factions(): 24 button = SelectableButtonIcon(parent=Container(parent=self), align=Align.CENTER, pos=(0, 25 0, 26 ICON_SIZE, 27 ICON_SIZE), texturePath=shipTreeConst.ICON_BY_FACTIONID[faction_id], hint=get_faction_name(faction_id), iconSize=ICON_SIZE, func=self.on_faction_button, args=faction_id) 28 self.buttons.append(button) 29 30 self.update_button_selected_state(self.faction_id_setting.get()) 31 32 def on_faction_button(self, faction_id): 33 if faction_id == self.faction_id_setting.get(): 34 faction_id = None 35 self.set_faction(faction_id) 36 37 def set_faction(self, faction_id): 38 self.update_button_selected_state(faction_id) 39 if faction_id is None: 40 faction_id = shipTreeConst.ANY_FACTION 41 self.faction_id_setting.set(faction_id) 42 43 def update_button_selected_state(self, faction_id): 44 for button in self.buttons: 45 if button.args == faction_id: 46 button.ToggleSelected() 47 else: 48 button.SetDeselected() 49 50 51 class SelectableButtonIcon(ButtonIcon): 52 default_iconColor = eveColor.WHITE 53 default_useThemeColor = False 54 55 def _GetIconColor(self): 56 return eveColor.WHITE 57 58 def ConstructBackground(self): 59 self.mouseEnterBG = Frame(name='mouseEnterBG', bgParent=self.bgContainer, texturePath='res:/UI/Texture/classes/ShipTree/InfoPanel/hover.png', opacity=0.0) 60 self.mouseDownBG = Sprite(name='mouseDownBG', bgParent=self.bgContainer, texturePath='res:/UI/Texture/classes/ButtonIcon/mouseDown.png', opacity=0.0) 61 self.selectedBG = Frame(name='selectedBG', bgParent=self.bgContainer, texturePath='res:/UI/Texture/classes/ShipTree/InfoPanel/selected.png', opacity=0.0)