skinLicenseInfo.py (14626B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\collection\skinLicenseInfo.py 2 import carbonui 3 import carbonui.text.styles 4 import uthread2 5 from carbonui import Align, AxisAlignment, Density, uiconst, PickState 6 from carbonui import TextAlign, TextColor 7 from carbonui.text.styles import TextHeadline, TextBody 8 from carbonui.button.group import ButtonGroup, ButtonSizeMode, OverflowAlign 9 from carbonui.control.button import Button 10 from carbonui.primitives.container import Container 11 from carbonui.primitives.sprite import Sprite 12 from carbonui.uianimations import animations 13 from cosmetics.client.shipSkinApplicationSvc import get_ship_skin_application_svc 14 from cosmetics.client.shipSkinLicensesSvc import get_ship_skin_license_svc 15 from cosmetics.client.shipSkinTradingSvc import get_ship_skin_trading_svc 16 from cosmetics.common.ships.skins import trading_util 17 from cosmetics.common.ships.skins.static_data import trading_const 18 from cosmetics.common.ships.skins.static_data.skin_type import ShipSkinType 19 from eve.client.script.ui import eveColor 20 from eve.client.script.ui.cosmetics.ship import shipUtil 21 from eve.client.script.ui.cosmetics.ship.const import SkinrPage 22 from eve.client.script.ui.cosmetics.ship.controls.characterInfo import MadeByCharacterInfo 23 from eve.client.script.ui.cosmetics.ship.controls.shipName import ShipName 24 from eve.client.script.ui.cosmetics.ship.pages.collection.baseLicenseInfo import LicenseInfo 25 from eve.client.script.ui.cosmetics.ship.pages.collection.sellSkinDialogue import SellSkinDialogue 26 from eve.client.script.ui.cosmetics.ship.pages.studio import studioSignals 27 from eve.client.script.ui.shared.shipTree.infoBubble import SkillEntry 28 from localization import GetByLabel 29 from player_messaging.client.ui_message import message_player, prompt_player_fsd_dialog 30 from publicGateway.grpc.exceptions import GenericException 31 from skills.client.util import get_skill_service 32 from stackless_response_router.exceptions import TimeoutException 33 34 class SkinLicenseInfo(LicenseInfo): 35 __notifyevents__ = ['OnSessionChanged'] 36 37 def __init__(self, *args, **kwargs): 38 sm.RegisterNotify(self) 39 self.license_id = None 40 self.skin_license = None 41 self.is_activated_license = False 42 self.update_thread = None 43 super(SkinLicenseInfo, self).__init__(*args, **kwargs) 44 45 def Close(self): 46 try: 47 self.disconnect_signals() 48 finally: 49 super(SkinLicenseInfo, self).Close() 50 51 def connect_signals(self): 52 super(SkinLicenseInfo, self).connect_signals() 53 studioSignals.on_page_opened.connect(self.on_page_opened) 54 55 def disconnect_signals(self): 56 super(SkinLicenseInfo, self).disconnect_signals() 57 studioSignals.on_page_opened.disconnect(self.on_page_opened) 58 59 def OnSessionChanged(self, isRemote, sess, change): 60 if 'shipid' in change: 61 self.update() 62 63 def construct_layout(self): 64 self.construct_bottom_container() 65 self.construct_tier_indicator() 66 self.construct_name_and_line() 67 self.construct_ship_name() 68 69 def construct_name_and_line(self): 70 self.skin_line_label = TextBody(name='skin_line_label', parent=self, align=Align.TOBOTTOM, textAlign=TextAlign.CENTER) 71 self.skin_name_label = TextHeadline(name='skin_name_label', parent=self, align=Align.TOBOTTOM, textAlign=TextAlign.CENTER, color=TextColor.HIGHLIGHT) 72 73 def construct_tier_indicator(self): 74 self.tier_container = Container(name='tier_container', parent=self, align=Align.TOBOTTOM, width=336, height=58, padTop=8) 75 self.tier_label = TextHeadline(name='tier_label', parent=self.tier_container, align=Align.TOTOP_NOPUSH, textAlign=TextAlign.CENTER, color=eveColor.BLACK, shadowOffset=(0, 0), bold=True, padTop=14) 76 self.tier_background = Sprite(name='tier_background', parent=self.tier_container, align=Align.CENTERTOP, state=uiconst.UI_DISABLED, width=336, height=58) 77 78 def get_skin_tier_level(self): 79 if self.skin_license: 80 return self.skin_license.skin_design.tier_level 81 return 1 82 83 def get_skin_tier_texture(self): 84 tier_level = self.get_skin_tier_level() 85 return 'res:/UI/Texture/classes/Cosmetics/Ship/cards/tier/tier_{level}.png'.format(level=tier_level) 86 87 def construct_bottom_container(self): 88 self.bottom_cont = Container(name='bottom_cont', height=64, parent=self, padTop=32, align=Align.TOBOTTOM) 89 self.character_info = MadeByCharacterInfo(name='character_info', parent=self.bottom_cont, align=Align.TOLEFT) 90 self.construct_button_container() 91 92 def construct_button_container(self): 93 self.button_container = Container(name='button_container', parent=self.bottom_cont, padLeft=8) 94 self.button_group = ButtonGroup(name='button_group', parent=self.button_container, align=Align.TOBOTTOM, button_alignment=AxisAlignment.END, density=Density.EXPANDED, button_size_mode=ButtonSizeMode.DYNAMIC, overflow_align=OverflowAlign.LEFT) 95 self.reconstruct_buttons() 96 97 def construct_ship_name(self): 98 self.ship_name = ShipName(name='ship_name', parent=self, align=Align.CENTERTOP) 99 100 def reconstruct_buttons(self): 101 self.button_group.FlushButtons() 102 if not self.skin_license: 103 return 104 self.add_apply_button() 105 self.add_unapply_button() 106 self.add_activate_apply_button() 107 self.add_activate_button() 108 self.add_sell_button() 109 110 def add_apply_button(self): 111 if not self.skin_license.activated or not self.is_activated_license: 112 return 113 if shipUtil.is_currently_applied_skin(self.skin_license.skin_hex): 114 return 115 if self.is_license_for_active_ship(): 116 enabled = True 117 hint = None 118 else: 119 enabled = False 120 hint = GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/SkinApplyDisabledHint') 121 self.apply_button = Button(name='apply_button', label=GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/Apply'), func=self.on_apply_button, enabled=enabled, hint=hint) 122 self.button_group.add_button(self.apply_button) 123 124 def add_unapply_button(self): 125 if not self.skin_license.activated or not self.is_activated_license: 126 return 127 applied_skin = shipUtil.get_active_ship_skin_state() 128 if applied_skin.skin_type == ShipSkinType.THIRD_PARTY_SKIN and applied_skin.skin_data.skin_id == self.skin_license.skin_hex: 129 self.unapply_button = Button(name='unapply_button', label=GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/UnApply'), func=self.on_unapply_button) 130 self.button_group.add_button(self.unapply_button) 131 132 def add_activate_apply_button(self): 133 if self.skin_license.activated or self.is_activated_license: 134 return 135 if not self.is_license_for_active_ship(): 136 return 137 self.apply_activate_button = Button(name='apply_activate_button', label=GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/ActivateAndApply'), func=self.on_apply_activate_button) 138 self.button_group.add_button(self.apply_activate_button) 139 140 def add_activate_button(self): 141 if self.skin_license.activated or self.is_activated_license: 142 return 143 self.activate_button = Button(name='activate_button', label=GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/Activate'), func=self.on_activate_button) 144 self.button_group.add_button(self.activate_button) 145 146 def add_sell_button(self): 147 if self.is_activated_license: 148 return 149 if not self.skin_license.activated or self.skin_license.nb_unactivated > 0: 150 self.sell_button = SellButton(name='sell_button', label=GetByLabel('UI/Personalization/ShipSkins/SKINR/Collection/Sell'), func=self.on_sell_button) 151 self.button_group.add_button(self.sell_button) 152 153 def on_apply_activate_button(self, *args): 154 if prompt_player_fsd_dialog('ActivateAndApply', {}, uiconst.YESNO) != uiconst.ID_YES: 155 return 156 try: 157 get_ship_skin_application_svc().apply_third_party_skin(shipUtil.get_active_ship_item_id(), self.license_id, apply_license=True, activate_license=True) 158 except Exception as e: 159 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 160 161 def on_activate_button(self, *args): 162 if prompt_player_fsd_dialog('ActivateSkin', {}, uiconst.YESNO) != uiconst.ID_YES: 163 return 164 try: 165 get_ship_skin_license_svc().activate_license(self.license_id) 166 except Exception as e: 167 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 168 169 def on_sell_button(self, *args): 170 dialogue = SellSkinDialogue(self.skin_license) 171 dialogue.ShowModal() 172 self.sell_button.update_enabled_state() 173 174 def on_apply_button(self, *args): 175 try: 176 self.apply_button.busy = True 177 get_ship_skin_application_svc().apply_third_party_skin(shipUtil.get_active_ship_item_id(), self.license_id, apply_license=True, activate_license=False) 178 except Exception as e: 179 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 180 self.apply_button.busy = False 181 182 def on_unapply_button(self, *args): 183 try: 184 self.unapply_button.busy = True 185 get_ship_skin_application_svc().apply_third_party_skin(shipUtil.get_active_ship_item_id(), self.license_id, apply_license=False, activate_license=False) 186 except Exception as e: 187 self.unapply_button.busy = False 188 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 189 190 def on_page_opened(self, page_id, page_args, last_page_id, animate = True): 191 any_collection_page = [SkinrPage.COLLECTION, SkinrPage.COLLECTION_COMPONENTS, SkinrPage.COLLECTION_SKINS] 192 if page_id in any_collection_page and last_page_id in any_collection_page: 193 self.fade_out() 194 195 def update(self): 196 if self.update_thread: 197 self.update_thread.kill() 198 self.update_thread = uthread2.start_tasklet(self._update) 199 200 def _update(self): 201 self.skin_name_label.text = self.get_skin_name() 202 self.update_skin_line_label() 203 self.update_ship_name() 204 uthread2.start_tasklet(self.update_character_info) 205 self.reconstruct_buttons() 206 self.update_tier() 207 self.update_thread = None 208 209 def get_skin_name(self): 210 if self.skin_license: 211 return self.skin_license.skin_design.name 212 return '' 213 214 def update_skin_line_label(self): 215 if not self.skin_license: 216 self.skin_line_label.display = False 217 return 218 if self.skin_license.skin_design.line_name: 219 self.skin_line_label.display = True 220 self.skin_line_label.text = self.skin_license.skin_design.line_name 221 else: 222 self.skin_line_label.display = False 223 self.skin_line_label.text = '' 224 225 def update_tier(self): 226 self.tier_label.text = '{tier}'.format(tier=self.get_skin_tier_level()) 227 self.tier_background.texturePath = self.get_skin_tier_texture() 228 229 def update_character_info(self): 230 if self.skin_license: 231 self.character_info.character_id = self.skin_license.skin_design.creator_character_id 232 233 def update_ship_name(self): 234 self.ship_name.ship_type_id = self.skin_license.skin_design.ship_type_id if self.skin_license else None 235 236 def is_license_for_active_ship(self): 237 return shipUtil.get_active_ship_type_id() == self.skin_license.skin_design.ship_type_id 238 239 def on_unactivated_skin_license_selected(self, skin_license): 240 self.license_id = skin_license.skin_hex 241 self.is_activated_license = False 242 self.skin_license = skin_license 243 self.fade_out(callback=self.on_fade_out_complete) 244 245 def on_activated_skin_license_selected(self, skin_license): 246 self.license_id = skin_license.skin_hex 247 self.is_activated_license = True 248 self.skin_license = skin_license 249 self.fade_out(callback=self.on_fade_out_complete) 250 251 def on_component_license_selected(self, *args): 252 self.fade_out() 253 254 def on_skin_state_set(self, _ship_instance_id, skin_state): 255 if skin_state.character_id == session.charid: 256 uthread2.start_tasklet(self.update) 257 258 def fade_out(self, callback = None): 259 if callback is None: 260 self.license_id = None 261 self.skin_license = None 262 self.state = uiconst.UI_DISABLED 263 animations.FadeTo(self, self.opacity, 0.0, uiconst.TIME_EXIT, callback=callback) 264 265 def on_fade_out_complete(self): 266 self.update() 267 self.fade_in() 268 269 def fade_in(self): 270 self.state = uiconst.UI_PICKCHILDREN 271 animations.FadeTo(self, self.opacity, 1.0, uiconst.TIME_ENTRY) 272 273 274 class SellButton(Button): 275 default_enabled = False 276 277 def __init__(self, get_menu_entry_data_func = None, **kwargs): 278 super(SellButton, self).__init__(get_menu_entry_data_func, **kwargs) 279 uthread2.start_tasklet(self.update_enabled_state) 280 281 def update_enabled_state(self): 282 self.max_listings = trading_util.get_maximum_concurrent_skin_listings(get_skill_service().GetMyLevel) 283 try: 284 self.num_listings = len(get_ship_skin_trading_svc().get_owned_listings()) 285 except (TimeoutException, GenericException): 286 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 287 self.num_listings = 0 288 289 if self.num_listings >= self.max_listings: 290 self.disable() 291 else: 292 self.enable() 293 294 def LoadTooltipPanel(self, tooltipPanel, *args): 295 tooltipPanel.LoadStandardSpacing() 296 tooltipPanel.columns = 2 297 tooltipPanel.pickState = PickState.ON 298 if self.num_listings >= self.max_listings: 299 tooltipPanel.AddCell(carbonui.text.styles.TextBody(text=GetByLabel('UI/Personalization/ShipSkins/SKINR/Store/UnableToListMoreSKINs', num_listings=self.num_listings), width=300, color=eveColor.WARNING_ORANGE), colSpan=2) 300 tooltipPanel.AddCell(carbonui.text.styles.TextBody(text=GetByLabel('UI/Personalization/ShipSkins/SKINR/Store/MaxListingsTooltip'), width=300, color=TextColor.SECONDARY), colSpan=2) 301 for type_id in trading_const.max_concurrent_listings_skills: 302 level = get_skill_service().GetMyLevel(type_id) 303 tooltipPanel.AddRow(rowClass=SkillEntry, typeID=type_id, level=level, showLevel=False)