section_controller.py (11810B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\ships\skins\live_data\section_controller.py 2 from cosmetics.client.shipSkinComponentSvc import get_ship_skin_component_svc 3 from cosmetics.client.shipSkinComponentTradingSvc import get_ship_skin_component_trading_svc 4 from cosmetics.client.shipSkinDesignSvc import get_ship_skin_design_svc 5 from cosmetics.client.shipSkinLicensesSvc import get_ship_skin_license_svc 6 from cosmetics.client.shipSkinSequencingSvc import get_ship_skin_sequencing_svc 7 from cosmetics.client.ships.skins.live_data.paginationController import PaginationController 8 from cosmetics.client.ships.skins.static_data.collection_section import CollectionSection 9 from cosmetics.common.ships.skins.static_data.component_category import ComponentCategory 10 from cosmetics.common.ships.skins.util import ComponentListingOrder, SkinListingOrder 11 from player_messaging.client.ui_message import message_player 12 from eve.client.script.ui.cosmetics.ship.const import SkinrPage 13 from eve.client.script.ui.cosmetics.ship.pages.cards.baseSkinCard import BlankSkinCard 14 from eve.client.script.ui.cosmetics.ship.pages.cards.componentLicenseCard import BlankMaterialComponentCard, BlankPatternComponentCard 15 from eve.client.script.ui.cosmetics.ship.pages.collection import collectionSettings 16 from eve.client.script.ui.cosmetics.ship.pages.homepage.savedDesignsSettings import designs_sort_by_setting 17 from eve.client.script.ui.cosmetics.ship.pages.store import storeSettings 18 from eve.client.script.ui.cosmetics.ship.pages.store.storeSettings import components_sort_by_setting 19 from localization import GetByLabel 20 from publicGateway.grpc.exceptions import GenericException 21 from stackless_response_router.exceptions import TimeoutException 22 23 class BaseSection(object): 24 name = None 25 category = None 26 page_id = None 27 pagination_controller = None 28 29 def __init__(self, num_per_page = None, apply_sorting = True, apply_filtering = True): 30 self.num_per_page = num_per_page 31 self.pagination_controller = self._get_pagination_controller() 32 self.apply_sorting = apply_sorting 33 self.apply_filtering = apply_filtering 34 35 def _get_pagination_controller(self): 36 return PaginationController() 37 38 def get_card_controllers(self, page_num = None): 39 if page_num is None or not self.pagination_controller.initialized: 40 controllers = self._get_card_controllers_filtered_and_sorted() 41 self.reset_pagination_controller(controllers) 42 return self.pagination_controller.get_page(page_num or 0) 43 44 def reset_pagination_controller(self, controllers): 45 self.pagination_controller.reset(controllers, self.num_per_page) 46 47 def _get_all_card_controllers(self): 48 return [] 49 50 def _get_card_controllers_filtered_and_sorted(self): 51 controllers = self._get_all_card_controllers() 52 if self.apply_filtering: 53 controllers = self._filter_controllers(controllers) 54 if self.apply_sorting: 55 controllers = self._sort_controllers(controllers) 56 return controllers 57 58 def _sort_controllers(self, controllers): 59 return controllers 60 61 def _filter_controllers(self, controllers): 62 return controllers 63 64 def get_num_entries(self): 65 return len(self._get_all_card_controllers()) 66 67 def get_page_id_and_args(self): 68 return (self.page_id, self.category) 69 70 def get_name(self): 71 return GetByLabel(self.name) 72 73 def is_paginated(self): 74 return self.pagination_controller.has_more_than_one_page() 75 76 @property 77 def blank_card_class(self): 78 return None 79 80 81 def _get_listing_sort_key(component_listing, sort_by): 82 if sort_by == ComponentListingOrder.EXPIRES_AT: 83 return component_listing.valid_until 84 if sort_by == ComponentListingOrder.NAME: 85 return component_listing.name.lower() 86 if sort_by == ComponentListingOrder.PRICE: 87 return component_listing.price 88 if sort_by == ComponentListingOrder.COLOR_SHADE: 89 return component_listing.get_component_data().color_shade_sort_index 90 91 92 class BaseStoreComponentsSectionController(BaseSection): 93 page_id = SkinrPage.STORE_COMPONENTS 94 95 def _sort_controllers(self, controllers): 96 limited_offer_controllers = [] 97 discount_offer_controllers = [] 98 other_controllers = [] 99 for controller in controllers: 100 if controller.has_discount(): 101 discount_offer_controllers.append(controller) 102 elif controller.is_limited_offer(): 103 limited_offer_controllers.append(controller) 104 else: 105 other_controllers.append(controller) 106 107 sort_by, ascending = components_sort_by_setting.get() 108 sorted_controllers = sorted(limited_offer_controllers, key=lambda l: _get_listing_sort_key(l, sort_by), reverse=ascending) 109 sorted_controllers.extend(sorted(discount_offer_controllers, key=lambda l: _get_listing_sort_key(l, sort_by), reverse=ascending)) 110 sorted_controllers.extend(sorted(other_controllers, key=lambda l: _get_listing_sort_key(l, sort_by), reverse=ascending)) 111 return sorted_controllers 112 113 def _get_all_card_controllers(self): 114 try: 115 return get_ship_skin_component_trading_svc().get_category_listings(self.category) 116 except (GenericException, TimeoutException): 117 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 118 return [] 119 120 121 class StoreNanocoatingComponentsSection(BaseStoreComponentsSectionController): 122 category = ComponentCategory.MATERIAL 123 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Nanocoatings' 124 125 @property 126 def blank_card_class(self): 127 return BlankMaterialComponentCard 128 129 def get_num_entries(self): 130 all_controllers = self._get_all_card_controllers() 131 return len(self._filter_controllers(all_controllers)) 132 133 def _filter_controllers(self, controllers): 134 finish = storeSettings.nanocoating_finish_filter_setting.get() 135 if not finish: 136 return controllers 137 return [ c for c in controllers if c.get_component_data().finish == finish ] 138 139 140 class StoreMetallicComponentsSection(BaseStoreComponentsSectionController): 141 category = ComponentCategory.METALLIC 142 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Metallics' 143 144 @property 145 def blank_card_class(self): 146 return BlankMaterialComponentCard 147 148 149 class StorePatternComponentsSection(BaseStoreComponentsSectionController): 150 category = ComponentCategory.PATTERN 151 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Patterns' 152 153 @property 154 def blank_card_class(self): 155 return BlankPatternComponentCard 156 157 158 def _get_skin_license_sort_key(component_listing, sort_by): 159 if sort_by == ComponentListingOrder.NAME: 160 return component_listing.name.lower() 161 162 163 class CollectionBaseSkinsSection(BaseSection): 164 page_id = SkinrPage.COLLECTION_SKINS 165 166 def _filter_controllers(self, controllers): 167 type_id = collectionSettings.skins_hull_type_filter_setting.get() 168 if not type_id: 169 return controllers 170 return [ l for l in controllers if l.skin_design.ship_type_id in [type_id] ] 171 172 def _sort_controllers(self, controllers): 173 sort_by, reverse = collectionSettings.skins_sort_by_setting.get() 174 return sorted(controllers, key=lambda l: _get_skin_license_sort_key(l, sort_by), reverse=reverse) 175 176 @property 177 def blank_card_class(self): 178 return BlankSkinCard 179 180 181 class CollectionAllActivatedSkinsSection(CollectionBaseSkinsSection): 182 category = CollectionSection.SKINS_3RD_PARTY_ACTIVATED 183 name = 'UI/Personalization/ShipSkins/SKINR/Collection/ActivatedSkins' 184 185 def _get_all_card_controllers(self): 186 try: 187 return get_ship_skin_license_svc().get_my_activated_licenses() 188 except (GenericException, TimeoutException): 189 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 190 return [] 191 192 193 class CollectionAllUnactivatedSkinsSection(CollectionBaseSkinsSection): 194 category = CollectionSection.SKINS_3RD_PARTY_UNACTIVATED 195 name = 'UI/Personalization/ShipSkins/SKINR/Collection/UnactivatedSkins' 196 197 def _get_all_card_controllers(self): 198 try: 199 return get_ship_skin_license_svc().get_my_unactivated_licenses() 200 except (GenericException, TimeoutException): 201 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 202 return [] 203 204 205 def _get_component_license_sort_key(component_listing, sort_by): 206 if sort_by == ComponentListingOrder.NAME: 207 return component_listing.name.lower() 208 if sort_by == ComponentListingOrder.COLOR_SHADE: 209 return component_listing.get_component_data().color_shade_sort_index 210 211 212 class BaseCollectionComponentsSection(BaseSection): 213 page_id = SkinrPage.COLLECTION_COMPONENTS 214 215 def _get_all_card_controllers(self): 216 try: 217 return get_ship_skin_component_svc().get_all_owned_licenses_in_category(category=self.category) 218 except (GenericException, TimeoutException): 219 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 220 return [] 221 222 def _sort_controllers(self, controllers): 223 sort_by, reverse = collectionSettings.components_sort_by_setting.get() 224 return sorted(controllers, key=lambda l: _get_component_license_sort_key(l, sort_by), reverse=reverse) 225 226 227 class CollectionNanocoatingComponentsSection(BaseCollectionComponentsSection): 228 category = ComponentCategory.MATERIAL 229 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Nanocoatings' 230 231 @property 232 def blank_card_class(self): 233 return BlankMaterialComponentCard 234 235 236 class CollectionMetallicComponentsSection(BaseCollectionComponentsSection): 237 category = ComponentCategory.METALLIC 238 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Metallics' 239 240 @property 241 def blank_card_class(self): 242 return BlankMaterialComponentCard 243 244 245 class CollectionPatternComponentsSection(BaseCollectionComponentsSection): 246 category = ComponentCategory.PATTERN 247 name = 'UI/Personalization/ShipSkins/SKINR/Studio/Patterns' 248 249 @property 250 def blank_card_class(self): 251 return BlankPatternComponentCard 252 253 254 class SequencingInProgressSection(BaseSection): 255 page_id = SkinrPage.STUDIO 256 name = 'UI/Personalization/ShipSkins/SKINR/Studio/SequencingInProgress' 257 258 @property 259 def blank_card_class(self): 260 return BlankPatternComponentCard 261 262 def _get_all_card_controllers(self): 263 try: 264 svc = get_ship_skin_sequencing_svc() 265 return svc.get_all_my_active_sequencing_jobs().values() 266 except (GenericException, TimeoutException): 267 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 268 return [] 269 270 271 class SavedDesignsSection(BaseSection): 272 page_id = SkinrPage.STUDIO 273 category = SkinrPage.STUDIO_SAVED_DESIGNS 274 name = 'UI/Personalization/ShipSkins/SKINR/Studio/SavedDesigns' 275 276 @property 277 def blank_card_class(self): 278 return BlankSkinCard 279 280 def _get_all_card_controllers(self): 281 try: 282 return get_ship_skin_design_svc().get_all_owned_designs().items() 283 except (GenericException, TimeoutException): 284 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 285 return [] 286 287 def _sort_controllers(self, controllers): 288 sort_by, ascending = designs_sort_by_setting.get() 289 return sorted(controllers, key=lambda l: _get_saved_design_sort_key(l, sort_by), reverse=ascending) 290 291 292 def _get_saved_design_sort_key(design_data, sort_by): 293 skin_design_id, skin_design = design_data 294 if sort_by == SkinListingOrder.NAME: 295 return skin_design.name.lower() 296 return skin_design