cosmeticsSlot.py (6748B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\cosmetics\cosmeticsSlot.py 2 from carbon.client.script.environment.AudioUtil import PlaySound 3 from carbonui import uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 from carbonui.primitives.transform import Transform 7 from cosmetics.common.ships.skins.static_data.skin_type import ShipSkinType 8 from cosmetics.client.shipSkinLicensesSvc import get_ship_skin_license_svc 9 from player_messaging.client.ui_message import message_player 10 from eveui import Sprite 11 from localization import GetByLabel 12 from publicGateway.grpc.exceptions import GenericException 13 from stackless_response_router.exceptions import TimeoutException 14 15 class CosmeticsSlot(Transform): 16 default_align = uiconst.TOPLEFT 17 default_state = uiconst.UI_NORMAL 18 default_width = 44 19 default_height = 54 20 21 def ApplyAttributes(self, attributes): 22 super(CosmeticsSlot, self).ApplyAttributes(attributes) 23 self.slotController = attributes.get('controller', None) 24 self.radCosSin = attributes.radCosSin 25 self.texturePath = None 26 self.ConstructLayout() 27 self.SetupSlot() 28 29 def ConstructLayout(self): 30 self.content = Container(name='content', parent=self, align=uiconst.TOALL) 31 self.logoContainer = ContainerAutoSize(name='logoContainer', parent=self.content, align=uiconst.CENTER, state=uiconst.UI_DISABLED) 32 self.UpdateLogo() 33 self.frame = Sprite(bgParent=self.content, name='frame', state=uiconst.UI_DISABLED, padding=(-8, -4, -8, -4), texturePath='res:/UI/Texture/classes/Fitting/moduleFrame.png', opacity=0.3) 34 self.fill = Sprite(bgParent=self.content, name='fill', state=uiconst.UI_DISABLED, padding=(-8, -4, -8, -4), texturePath='res:/UI/Texture/classes/Fitting/moduleSlotFill.png', color=(0.0, 0.0, 0.0, 0.2)) 35 self.fill.Hide() 36 37 def UpdateLogo(self, size = 32): 38 self.logoContainer.Flush() 39 if self.texturePath: 40 self.backgroundIcon = Sprite(name='backgroundIcon', parent=self.logoContainer, texturePath=self.texturePath) 41 else: 42 self.CreateEmptySlotIcon() 43 self.backgroundIcon.SetSize(size, size) 44 45 def CreateEmptySlotIcon(self): 46 if self.slotController: 47 self.texturePath = self.slotController.backgroundIconPath 48 self.backgroundIcon = Sprite(name='backgroundIcon', parent=self.logoContainer, texturePath=self.texturePath) 49 50 def SetupSlot(self, texturePath = None, size = 32): 51 self.texturePath = texturePath 52 if not self.slotController: 53 self.fill.Show() 54 return 55 self.UpdateLogo(size) 56 57 def GetHint(self): 58 if not self.slotController: 59 return GetByLabel('UI/Fitting/FittingWindow/Cosmetic/ReservedSlot') 60 return self.slotController.hint 61 62 def OnMouseEnter(self, *args): 63 self.frame.SetAlpha(0.5) 64 PlaySound(uiconst.SOUND_BUTTON_HOVER) 65 66 def OnMouseExit(self, *args): 67 self.frame.SetAlpha(0.3) 68 69 def GetTooltipPosition(self): 70 rect, point = self.PositionHint() 71 return rect 72 73 def GetTooltipPointer(self): 74 rect, point = self.PositionHint() 75 return point 76 77 def PositionHint(self, *_args): 78 sl, st, sw, sh = self.parent.GetAbsolute() 79 cX = sl + sw / 2.0 80 cY = st + sh / 2.0 81 rad, cos, sin, oldcX, oldcY = self.radCosSin 82 hintLeft = int(round(rad * cos)) 83 hintTop = int(round(rad * sin)) 84 cap = rad * 0.7 85 if hintLeft < -cap: 86 point = uiconst.POINT_RIGHT_2 87 elif hintLeft > cap: 88 point = uiconst.POINT_LEFT_2 89 elif hintTop < -cap: 90 if hintLeft < 0: 91 point = uiconst.POINT_BOTTOM_3 92 else: 93 point = uiconst.POINT_BOTTOM_1 94 elif hintLeft < 0: 95 point = uiconst.POINT_TOP_3 96 else: 97 point = uiconst.POINT_TOP_1 98 return ((hintLeft + cX - 15, 99 hintTop + cY - 15, 100 30, 101 30), point) 102 103 104 class CosmeticAllianceLogoSlot(CosmeticsSlot): 105 106 def UpdateLogo(self, size = 32): 107 self.logoContainer.Flush() 108 if session.allianceid and self.texturePath: 109 self.backgroundIcon = Sprite(name='backgroundIcon', parent=self.logoContainer, texturePath=self.texturePath) 110 else: 111 self.CreateEmptySlotIcon() 112 self.backgroundIcon.SetSize(size, size) 113 self.backgroundIcon.rotation = -self.rotation 114 115 116 class CosmeticCorporationLogoSlot(CosmeticsSlot): 117 118 def UpdateLogo(self, size = 32): 119 self.logoContainer.Flush() 120 if self.texturePath: 121 self.backgroundIcon = Sprite(name='backgroundIcon', parent=self.logoContainer, texturePath=self.texturePath) 122 else: 123 self.CreateEmptySlotIcon() 124 self.backgroundIcon.SetSize(size, size) 125 self.backgroundIcon.rotation = -self.rotation 126 127 128 class CosmeticSkinSlot(CosmeticsSlot): 129 130 def UpdateLogo(self, size = 32): 131 super(CosmeticSkinSlot, self).UpdateLogo(size) 132 self.backgroundIcon.rotation = -self.rotation 133 134 def GetHint(self): 135 if not self.slotController: 136 return GetByLabel('UI/Fitting/FittingWindow/Cosmetic/ReservedSlot') 137 itemID = session.shipid 138 skin = sm.GetService('cosmeticsSvc').GetAppliedSkinStateForCurrentSession(itemID) 139 if skin: 140 if skin.skin_type == ShipSkinType.FIRST_PARTY_SKIN: 141 skin_name = sm.GetService('cosmeticsSvc').GetFirstPartySkinMaterialDisplayName(skin.skin_data.skin_id) 142 return GetByLabel('UI/ShipCosmetics/ActiveSkin', skinName=skin_name) 143 if skin.skin_type == ShipSkinType.THIRD_PARTY_SKIN: 144 try: 145 skin_license = get_ship_skin_license_svc().get_license(skin.skin_data.skin_id, skin.character_id) 146 except (GenericException, TimeoutException): 147 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 148 skin_license = None 149 150 if skin_license: 151 return GetByLabel('UI/ShipCosmetics/ActiveSkin', skinName=skin_license.skin_design.full_name) 152 else: 153 return '' 154 return GetByLabel('UI/ShipCosmetics/NoSkinActive') 155 156 157 class CosmeticBlankSlot(CosmeticsSlot): 158 159 def ApplyAttributes(self, attributes): 160 super(CosmeticBlankSlot, self).ApplyAttributes(attributes) 161 self.content.opacity = 0.05 162 163 def OnMouseEnter(self, *args): 164 pass 165 166 def OnMouseExit(self, *args): 167 pass 168 169 def GetHint(self): 170 return None