cosmeticFittingCenter.py (7183B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\cosmetics\cosmeticFittingCenter.py 2 from collections import defaultdict 3 from carbonui.uianimations import animations 4 import uthread2 5 from cosmetics.common.ships.skins.static_data.skin_type import ShipSkinType 6 from shipcosmetics.common.const import CosmeticsType 7 from eve.client.script.ui.shared.fitting.slotAdder import SlotAdder 8 from shipcosmetics.client.fittingsgateway.fittingsSignals import on_ship_cosmetics_changed 9 from carbonui.primitives.container import Container 10 from eve.client.script.ui.shared.fitting.cosmeticFittingController import CosmeticFittingController 11 from eve.client.script.ui.shared.fitting.fittingUtil import GetScaleFactor 12 from eve.client.script.ui.shared.fittingScreen.cosmetics.cosmeticFittingLayout import CosmeticFittingLayout 13 from eve.client.script.ui.shared.fittingScreen.cosmetics.cosmeticsSlot import CosmeticAllianceLogoSlot, CosmeticCorporationLogoSlot, CosmeticSkinSlot, CosmeticBlankSlot 14 from eve.client.script.ui.shared.fittingScreen.fittingCenter import ShipSceneParent 15 from carbonui import uiconst 16 from eve.client.script.ui.shared.skins.skinUISignals import on_skin_selected 17 LOGO_SIZE = 64 18 19 class CosmeticFittingCenter(CosmeticFittingLayout): 20 __notifyevents__ = ['OnDogmaItemChange', 21 'ProcessActiveShipChanged', 22 'OnSessionChanged', 23 'OnCorporationChanged', 24 'OnCorpLogoReady', 25 'OnAllianceLogoReady'] 26 default_name = 'CosmeticFittingCenter' 27 default_align = uiconst.CENTER 28 default_state = uiconst.UI_NORMAL 29 default_top = -20 30 cosmeticsFittingController = None 31 32 def ApplyAttributes(self, attributes): 33 super(CosmeticFittingCenter, self).ApplyAttributes(attributes) 34 self.cosmeticsFittingController = attributes.controller 35 self.slots = defaultdict(list) 36 self.ConstructSlots() 37 sm.RegisterNotify(self) 38 on_skin_selected.connect(self.OnSkinEntrySelected) 39 on_ship_cosmetics_changed.connect(self.OnShipCosmeticsChanged) 40 self.ConstructSceneContainer() 41 self._entryAnimThread = uthread2.start_tasklet(self.EntryAnimation) 42 self._setupSkinSlotThread = uthread2.start_tasklet(self.SetupSkinSlot) 43 44 def Close(self): 45 sm.UnregisterNotify(self) 46 on_skin_selected.disconnect(self.OnSkinEntrySelected) 47 on_ship_cosmetics_changed.disconnect(self.OnShipCosmeticsChanged) 48 if hasattr(self, '_entryAnimThread') and self._entryAnimThread: 49 self._entryAnimThread.Kill() 50 if hasattr(self, '_setupSkinSlotThread') and self._setupSkinSlotThread: 51 self._setupSkinSlotThread.Kill() 52 super(CosmeticFittingCenter, self).Close() 53 54 def ConstructSlots(self): 55 slotCont = Container(parent=self, name='slotCont', align=uiconst.TOALL, state=uiconst.UI_PICKCHILDREN, idx=0) 56 slotAdder = SlotAdder(self.cosmeticsFittingController, CosmeticBlankSlot) 57 slotAdder.rad = int(245 * GetScaleFactor()) 58 slotAdder.center = self.width / 2 59 for groupID, cosmeticTypes in self.cosmeticsFittingController.SLOT_GROUPS.iteritems(): 60 arcStart, arcLength = self.cosmeticsFittingController.SLOT_GROUP_LAYOUT_ARCS[groupID] 61 slotAdder.StartGroup(arcStart, arcLength, len(cosmeticTypes)) 62 slotClass = CosmeticBlankSlot 63 for cosmeticType in cosmeticTypes: 64 if cosmeticType == CosmeticsType.ALLIANCE_LOGO: 65 slotClass = CosmeticAllianceLogoSlot 66 elif cosmeticType == CosmeticsType.CORPORATION_LOGO: 67 slotClass = CosmeticCorporationLogoSlot 68 elif cosmeticType == CosmeticsType.SKIN: 69 slotClass = CosmeticSkinSlot 70 slot = slotAdder.AddSlot(slotCont, cosmeticType, slotClass) 71 self.slots[cosmeticType].append(slot) 72 73 self.UpdateLogoSlots() 74 75 def ConstructSceneContainer(self): 76 size = self.width * GetScaleFactor() 77 self.shipSceneContainer = ShipSceneParent(parent=self, align=uiconst.CENTER, width=size, height=size, controller=self.cosmeticsFittingController, stencilMask='res:/UI/Texture/classes/Fitting/fittingCircleStencil.png') 78 79 def EntryAnimation(self): 80 for i, slots in self.slots.iteritems(): 81 for slot in slots: 82 if slot.state == uiconst.UI_DISABLED: 83 endOpacity = 0.05 84 else: 85 endOpacity = 1.0 86 animations.FadeTo(slot, 0.0, endOpacity, duration=0.3, timeOffset=0.2 * i / 1.7) 87 88 def OnSkinEntrySelected(self, skin): 89 texturePath = skin.iconTexturePath if skin else None 90 self.slots[CosmeticsType.SKIN][0].SetupSlot(texturePath) 91 92 def SetupSkinSlot(self): 93 self.slots[CosmeticsType.SKIN][0].SetupSlot(self.cosmeticsFittingController.texturePath) 94 95 def OnShipCosmeticsChanged(self, _ship_id, _cosmetics_types): 96 self.UpdateLogoSlots() 97 98 def ProcessActiveShipChanged(self, _shipID, _oldShipID): 99 self.UpdateAllSlots() 100 101 def OnSessionChanged(self, _isremote, _session, change): 102 if 'corpid' or 'allianceid' in change: 103 self.UpdateAllSlots() 104 105 def OnCorporationChanged(self, _corpID, _change): 106 self.UpdateAllSlots() 107 108 def OnCorpLogoReady(self, corpID, size): 109 if corpID == session.corpid and size == LOGO_SIZE: 110 selectedCosmetics = sm.GetService('cosmeticsSvc').get_enabled_ship_cosmetics(session.shipid) 111 if CosmeticsType.CORPORATION_LOGO in selectedCosmetics: 112 texturePath = sm.GetService('photo').GetCorporationLogo(session.corpid, size=LOGO_SIZE) 113 self.slots[CosmeticsType.CORPORATION_LOGO][0].SetupSlot(texturePath) 114 115 def OnAllianceLogoReady(self, allianceID, size): 116 if allianceID == session.allianceid and size == LOGO_SIZE: 117 selectedCosmetics = sm.GetService('cosmeticsSvc').get_enabled_ship_cosmetics(session.shipid) 118 if CosmeticsType.ALLIANCE_LOGO in selectedCosmetics: 119 texturePath = sm.GetService('photo').GetAllianceLogo(session.allianceid, size=LOGO_SIZE) 120 self.slots[CosmeticsType.ALLIANCE_LOGO][0].SetupSlot(texturePath) 121 122 def UpdateAllSlots(self): 123 self.UpdateLogoSlots() 124 self.SetupSkinSlot() 125 126 def UpdateLogoSlots(self): 127 selectedCosmetics = sm.GetService('cosmeticsSvc').get_enabled_ship_cosmetics(session.shipid) 128 if CosmeticsType.ALLIANCE_LOGO in selectedCosmetics: 129 texturePath = sm.GetService('photo').GetAllianceLogo(session.allianceid, size=LOGO_SIZE, callback=True) 130 self.slots[CosmeticsType.ALLIANCE_LOGO][0].SetupSlot(texturePath) 131 else: 132 self.slots[CosmeticsType.ALLIANCE_LOGO][0].SetupSlot(None) 133 if CosmeticsType.CORPORATION_LOGO in selectedCosmetics: 134 texturePath = sm.GetService('photo').GetCorporationLogo(session.corpid, size=LOGO_SIZE, callback=True) 135 self.slots[CosmeticsType.CORPORATION_LOGO][0].SetupSlot(texturePath) 136 else: 137 self.slots[CosmeticsType.CORPORATION_LOGO][0].SetupSlot(None)