structureSelectionPage.py (8230B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\pages\structureSelectionPage.py 2 import evetypes 3 import math 4 from carbonui import uiconst, ButtonVariant, TextColor, TextAlign 5 from carbonui.control.button import Button 6 from carbonui.primitives.flowcontainer import FlowContainer 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.sprite import Sprite 10 from carbonui.uianimations import animations 11 from carbonui.util.dpi import ReverseScaleDpi 12 from carbon.client.script.environment.AudioUtil import PlaySound 13 from cosmetics.common.structures.const import PAINT_ELIGIBLE_STRUCTURE_TYPE_IDS 14 from eve.client.script.ui import eveColor 15 from eve.client.script.ui.control.eveLabel import EveCaptionLarge, EveLabelMedium, EveLabelLarge 16 from eve.client.script.ui.cosmetics.structure import const as paintToolConst 17 from eve.client.script.ui.cosmetics.structure import paintToolSelections 18 from eve.client.script.ui.cosmetics.structure.pages.basePage import BasePage 19 from localization import GetByLabel 20 21 class StructureCard(ContainerAutoSize): 22 default_state = uiconst.UI_NORMAL 23 default_width = 115 24 25 def __init__(self, type_id, icon_texture_path, glow_texture_path, callback = None, **kwargs): 26 super(StructureCard, self).__init__(**kwargs) 27 self._type_id = type_id 28 self._icon_texture_path = icon_texture_path 29 self._glow_texture_path = glow_texture_path 30 self._callback = callback 31 self._sprite_container = None 32 self._selection_sprite = None 33 self._name_label = None 34 self._construct_layout() 35 36 def _construct_layout(self): 37 sprite_size = self.width 38 self._sprite_container = Container(name='sprite_container', parent=self, align=uiconst.TOTOP, width=sprite_size, height=sprite_size) 39 Sprite(name='icon_sprite', parent=self._sprite_container, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath=self._icon_texture_path) 40 self._selection_sprite = Sprite(name='selection_sprite', parent=self._sprite_container, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath=self._glow_texture_path, opacity=0.0, color=eveColor.CRYO_BLUE) 41 self._name_label = EveLabelLarge(name='name_label', parent=self, text=evetypes.GetName(self._type_id), textAlign=TextAlign.CENTER, align=uiconst.TOTOP) 42 43 def _OnResize(self, *args): 44 super(StructureCard, self)._OnResize(*args) 45 sprite_size = ReverseScaleDpi(self.displayWidth) 46 self._sprite_container.width = sprite_size 47 self._sprite_container.height = sprite_size 48 49 def OnClick(self, *args): 50 super(StructureCard, self).OnClick(*args) 51 self.select() 52 PlaySound('nanocoating_hover_structure_play') 53 if self._callback: 54 self._callback(self, self._type_id) 55 56 @property 57 def type_id(self): 58 return self._type_id 59 60 def select(self): 61 animations.FadeTo(self._selection_sprite, self._selection_sprite.opacity, 1.0, duration=0.2) 62 animations.SpColorMorphTo(self._name_label, self._name_label.GetRGBA(), eveColor.CRYO_BLUE, 0.2) 63 64 def deselect(self): 65 animations.FadeTo(self._selection_sprite, self._selection_sprite.opacity, 0.0, duration=0.2) 66 animations.SpColorMorphTo(self._name_label, self._name_label.GetRGBA(), TextColor.NORMAL, 0.2) 67 68 69 class StructureSelectionPage(BasePage): 70 71 def __init__(self, **kwargs): 72 self._structure_cards = [] 73 self._card_columns = 4 74 self._card_spacing_x = 20 75 self._card_spacing_y = 20 76 self._label_area_prop_height = 0.12 77 self._button_area_prop_height = self._label_area_prop_height 78 self._label_container = None 79 self._structure_grid = None 80 self._select_button = None 81 super(StructureSelectionPage, self).__init__(**kwargs) 82 paintToolSelections.SELECTED_STRUCTURE_TYPE.on_change.connect(self._on_structure_selection_changed) 83 84 def Close(self): 85 super(StructureSelectionPage, self).Close() 86 paintToolSelections.SELECTED_STRUCTURE_TYPE.on_change.disconnect(self._on_structure_selection_changed) 87 88 def _construct_layout(self): 89 self._construct_description_labels() 90 self._construct_button_area() 91 self._construct_structure_grid() 92 93 def _construct_description_labels(self): 94 label_area_container = Container(name='label_area_container', parent=self, align=uiconst.TOTOP_PROP, height=self._label_area_prop_height) 95 self._label_container = ContainerAutoSize(name='label_container', parent=label_area_container, align=uiconst.CENTER) 96 EveCaptionLarge(name='description_main_label', parent=self._label_container, align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/SelectStructureCaption'), textAlign=TextAlign.CENTER) 97 EveLabelMedium(name='description_sub_label', parent=self._label_container, align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/SelectStructureInfo'), textAlign=TextAlign.CENTER) 98 self._update_label_sizes() 99 100 def _construct_button_area(self): 101 button_area_container = Container(name='button_area_container', parent=self, align=uiconst.TOBOTTOM_PROP, height=self._button_area_prop_height) 102 self._select_button = Button(name='select_button', parent=button_area_container, align=uiconst.CENTERBOTTOM, label=GetByLabel('UI/Personalization/PaintTool/StartDesigning'), variant=ButtonVariant.PRIMARY, func=self._on_select_button_clicked, enabled=False, padBottom=30) 103 104 def _construct_structure_grid(self): 105 grid_container = Container(name='grid_container', parent=self, align=uiconst.TOALL) 106 self._structure_grid = FlowContainer(name='structure_grid', parent=grid_container, align=uiconst.CENTER, centerContent=True) 107 for type_id in PAINT_ELIGIBLE_STRUCTURE_TYPE_IDS: 108 card = StructureCard(name='structure_card', parent=self._structure_grid, align=uiconst.NOALIGN, type_id=type_id, icon_texture_path=paintToolConst.get_structure_icon(type_id), glow_texture_path=paintToolConst.get_structure_glow_texture(type_id), callback=self._on_structure_card_select) 109 self._structure_cards.append(card) 110 111 self._update_grid_size() 112 113 def _on_structure_card_select(self, _card, type_id): 114 paintToolSelections.SELECTED_STRUCTURE_TYPE.set(type_id) 115 self._select_button.enabled = True 116 117 @staticmethod 118 def _on_next_button_clicked(_button): 119 paintToolSelections.SELECTED_PAGE.set(paintToolConst.DESIGN_CREATION_PAGE_ID) 120 121 @staticmethod 122 def _on_select_button_clicked(_button): 123 paintToolSelections.SELECTED_PAGE.set(paintToolConst.DESIGN_CREATION_PAGE_ID) 124 PlaySound('nanocoating_button_start_designing_play') 125 126 def _on_structure_selection_changed(self, type_id): 127 for card in self._structure_cards: 128 if card.type_id == type_id: 129 card.select() 130 else: 131 card.deselect() 132 133 def _OnResize(self, *args): 134 super(StructureSelectionPage, self)._OnResize(*args) 135 self._update_label_sizes() 136 self._update_grid_size() 137 138 def _update_label_sizes(self): 139 self._label_container.width = self.displayWidth 140 141 def _update_grid_size(self): 142 if self._structure_grid is None: 143 return 144 window_min_width, window_min_height = paintToolConst.WINDOW_MIN_SIZE 145 if self.displayWidth > self.displayHeight: 146 ratio = float(self.displayHeight) / float(window_min_height) 147 else: 148 ratio = float(self.displayWidth) / float(window_min_height) 149 card_size = math.floor(ReverseScaleDpi(StructureCard.default_width) * ratio) 150 card_spacing_x = math.floor(ReverseScaleDpi(self._card_spacing_x) * ratio) 151 card_spacing_y = math.floor(ReverseScaleDpi(self._card_spacing_y) * ratio) 152 for card in self._structure_cards: 153 card.width = card_size 154 155 self._structure_grid.contentSpacing = (card_spacing_x, card_spacing_y) 156 self._structure_grid.width = card_size * self._card_columns + card_spacing_x * self._card_columns