npccharacterview.py (11300B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\agentinteraction\npccharacterview.py 2 import blue 3 import trinity 4 import eveformat 5 import eveformat.client 6 from agentinteraction.constUI import PADDING_SMALL, HEADER_SIZE_XLARGE 7 from agentinteraction.npccharacterconst import BACKGROUND_BY_DIVISION, BACKGROUND_FALLBACK, BACKGROUND_BY_FACTION_ID, BACKGROUND_BY_AGENT_ID 8 from carbonui import TextColor, uiconst 9 from carbonui.fontconst import STYLE_SMALLTEXT 10 from carbonui.primitives.container import Container 11 from carbonui.primitives.containerAutoSize import ContainerAutoSize 12 from carbonui.primitives.sprite import Sprite, StreamingVideoSprite 13 from carbonui.util.color import Color 14 from carbonui.util.dpi import reverse_scale_dpi 15 from eve.client.script.ui import eveColor 16 from eve.client.script.ui.control.eveLabel import Label, EveLabelMedium 17 import evegraphics.settings as gfxsettings 18 from evelink.client.handlers.show_info.link import location_link 19 from localization import GetByLabel, GetByMessageID 20 from npcs.divisions import get_division_name 21 from npcs.npccorporations import get_corporation_faction_id 22 from uthread2 import StartTasklet 23 import evelink.client 24 PORTRAIT_WIDTH = 800 25 PORTRAIT_HEIGHT = 1080 26 PORTRAIT_WIDTH_EXTRA = 2.0 27 PORTRAIT_PROPS = float(PORTRAIT_WIDTH) / PORTRAIT_HEIGHT 28 BACKGROUND_WIDTH = 800 29 BACKGROUND_HEIGHT = 1400 30 BACKGROUND_PROPS = float(BACKGROUND_WIDTH) / BACKGROUND_HEIGHT 31 32 class NpcCharacterView(Container): 33 default_name = 'NpcCharacterView' 34 show_background_for_character = True 35 PORTRAITS_FOLDER_2D = None 36 PORTRAIT_FALLBACK_2D = 'res:/UI/Texture/classes/Agents/3019471.png' 37 PORTRAITS_FOLDER_VIDEO = None 38 PORTRAIT_FALLBACK_VIDEO = None 39 H_PADDING_CONTENT = PADDING_SMALL 40 V_PADDING_BETWEEN_AGENT_INFO_AND_STANDINGS = 64 41 V_PADDING_TEXT_TO_BOTTOM = 12 42 V_PADDING_LINES_LEVEL_TO_NAME = 11 43 V_PADDING_LINES_NAME_TO_LOCATION = 2 44 H_PADDING_LINE_LEVEL_BITS = 6 45 HEIGHT_LINE_LEVEL = 16 46 HEIGHT_LINE_NAME = 58 47 HEIGHT_LINE_LOCATION = 17 48 49 def __init__(self, npc_character, inner_padding = (0, 0, 0, 0), **kwargs): 50 self._inner_padding = inner_padding 51 self.background_sprite = None 52 self.container_npc_character_text = None 53 self.gradient_text = None 54 self.inner_cont = None 55 self.npc_character = npc_character 56 self.portrait = None 57 super(NpcCharacterView, self).__init__(**kwargs) 58 self.inner_cont = Container(name='inner_cont', parent=self, align=uiconst.TOALL, padding=self._inner_padding) 59 StartTasklet(self._build_content) 60 61 @property 62 def inner_padding(self): 63 return self._inner_padding 64 65 @inner_padding.setter 66 def inner_padding(self, value): 67 if isinstance(value, (int, float)): 68 value = (value, 69 value, 70 value, 71 value) 72 if self._inner_padding != value: 73 self._inner_padding = value 74 if self.inner_cont: 75 self.inner_cont.padding = self._inner_padding 76 77 def _build_content(self): 78 self._build_npc_character_text() 79 self._build_gradient() 80 self._build_portrait() 81 self._build_background() 82 self._update_sizes() 83 self._load_npc_character_location() 84 85 def _build_npc_character_text(self): 86 self.container_npc_character_text = ContainerAutoSize(name='container_npc_character_text', parent=self.inner_cont, align=uiconst.TOBOTTOM_NOPUSH, padRight=self.H_PADDING_CONTENT, padLeft=self.H_PADDING_CONTENT) 87 self._build_npc_character_level() 88 self._build_npc_character_name() 89 self._build_npc_character_location() 90 91 def _build_npc_character_level(self): 92 level = self.npc_character.get_level() 93 division_id = self.npc_character.get_division_id() 94 division_name = get_division_name(division_id) 95 container_level_line = Container(name='container_level_line', parent=self.container_npc_character_text, align=uiconst.TOTOP, height=self.HEIGHT_LINE_LEVEL) 96 container_level = ContainerAutoSize(name='container_level', parent=container_level_line, align=uiconst.TOLEFT) 97 EveLabelMedium(name='label_level', parent=container_level, align=uiconst.CENTERLEFT, text=GetByLabel('UI/Agents/AgentLevel').upper(), color=Color.WHITE) 98 container_level_number = ContainerAutoSize(name='container_level_number', parent=container_level_line, align=uiconst.TOLEFT, padLeft=self.H_PADDING_LINE_LEVEL_BITS, bgColor=Color.WHITE) 99 EveLabelMedium(name='number_level', parent=container_level_number, align=uiconst.CENTER, text=int(level), padLeft=self.H_PADDING_LINE_LEVEL_BITS, padRight=self.H_PADDING_LINE_LEVEL_BITS, color=Color.BLACK) 100 container_division = ContainerAutoSize(name='container_division', parent=container_level_line, align=uiconst.TOLEFT, padLeft=self.H_PADDING_LINE_LEVEL_BITS) 101 EveLabelMedium(name='division', parent=container_division, align=uiconst.CENTERLEFT, text=division_name, color=Color.WHITE) 102 103 def _build_npc_character_name(self): 104 name = GetByMessageID(self.npc_character.get_name()) 105 name_link = evelink.character_link(self.npc_character.get_id(), name) 106 container_name_line = ContainerAutoSize(name='container_name_line', parent=self.container_npc_character_text, align=uiconst.TOTOP, height=self.HEIGHT_LINE_NAME, padTop=self.V_PADDING_LINES_LEVEL_TO_NAME) 107 Label(name='label_name', parent=container_name_line, align=uiconst.TOTOP, text=name_link, fontsize=HEADER_SIZE_XLARGE, fontStyle=STYLE_SMALLTEXT, color=TextColor.HIGHLIGHT, bold=True, letterspace=1, state=uiconst.UI_NORMAL) 108 109 def _build_npc_character_location(self): 110 self.npc_character_location_label = EveLabelMedium(name='label_location', parent=self.container_npc_character_text, align=uiconst.TOTOP, state=uiconst.UI_ACTIVE, padTop=self.V_PADDING_LINES_NAME_TO_LOCATION) 111 112 def _load_npc_character_location(self): 113 text = self._get_location_text() 114 self.npc_character_location_label.text = text 115 116 def _build_gradient(self): 117 self.gradient_text = Sprite(name='gradient_text', parent=self, align=uiconst.TOBOTTOM_NOPUSH, texturePath='res:/UI/Texture/classes/AgentInteraction/Gradient_CareerAgent.png', state=uiconst.UI_DISABLED, height=600, color=eveColor.BLACK) 118 119 def _build_portrait(self): 120 portait_cont = Container(name='portrait_cont', parent=self, clipChildren=True) 121 if self._should_show_video(): 122 portrait_video_path = self._get_video_portrait_path() 123 if portrait_video_path: 124 self.portrait = StreamingVideoSprite(parent=portait_cont, name='sprite_video_portrait', videoPath=portrait_video_path, videoLoop=True, disableAudio=True, blendMode=trinity.TR2_SBM_NONE, spriteEffect=trinity.TR2_SFX_COPY, align=uiconst.CENTERBOTTOM, state=uiconst.UI_DISABLED) 125 self.portrait.Play() 126 return 127 portrait_2d_path = self._get_2d_portrait_path() 128 self.portrait = Sprite(name='sprite_2d_portrait', parent=portait_cont, align=uiconst.CENTERBOTTOM, texturePath=portrait_2d_path, state=uiconst.UI_DISABLED) 129 130 def _build_background(self): 131 if not self.show_background_for_character: 132 return 133 background_path = self._get_background_path() 134 if not background_path: 135 return 136 background_container = Container(name='background_container', parent=self, state=uiconst.UI_DISABLED, align=uiconst.TOALL, clipChildren=True) 137 self.background_sprite = Sprite(name='background_npc_character', parent=background_container, align=uiconst.TOLEFT, texturePath=background_path) 138 139 def _get_background_path(self): 140 texture_path = BACKGROUND_BY_AGENT_ID.get(self.npc_character.get_id()) 141 if texture_path: 142 return texture_path 143 division_id = self.npc_character.get_division_id() 144 texture_path = BACKGROUND_BY_DIVISION.get(division_id, BACKGROUND_FALLBACK) 145 if texture_path: 146 return texture_path 147 corporation_id = self.npc_character.get_corporation_id() 148 faction_id = get_corporation_faction_id(corporation_id) 149 texture_path = BACKGROUND_BY_FACTION_ID.get(faction_id, BACKGROUND_FALLBACK) 150 return texture_path 151 152 def _get_2d_portrait_path(self): 153 if self.PORTRAITS_FOLDER_2D: 154 npc_character_id = self.npc_character.get_id() 155 path = '{path}/{character_id}.png'.format(path=self.PORTRAITS_FOLDER_2D, character_id=npc_character_id) 156 if blue.paths.FileExistsLocally(path): 157 return path 158 return self.PORTRAIT_FALLBACK_2D 159 160 def _get_video_portrait_path(self): 161 if self.PORTRAITS_FOLDER_VIDEO: 162 npc_character_id = self.npc_character.get_id() 163 path = '{path}/{character_id}.webm'.format(path=self.PORTRAITS_FOLDER_VIDEO, character_id=npc_character_id) 164 if blue.paths.FileExistsLocally(path): 165 return path 166 return self.PORTRAIT_FALLBACK_VIDEO 167 168 def _should_show_video(self): 169 return gfxsettings.Get(gfxsettings.GFX_SHADER_QUALITY) >= gfxsettings.SHADER_MODEL_MEDIUM 170 171 def _get_location_text(self): 172 station_id = self.npc_character.get_station_id() 173 solar_system_id = sm.GetService('ui').GetStationSolarSystem(station_id) 174 return u'{security} {location}'.format(security=eveformat.client.solar_system_security_status(solar_system_id), location=location_link(station_id)) 175 176 def _update_sizes(self): 177 available_width = reverse_scale_dpi(self.displayWidth) 178 available_height = reverse_scale_dpi(self.displayHeight) 179 if not available_width or not available_height: 180 return 181 self._update_portrait_size(available_width, available_height) 182 self._update_portrait_background_size(available_width, available_height) 183 184 def _update_portrait_size(self, available_width, available_height): 185 needed_width = PORTRAIT_PROPS * available_height 186 needed_vs_actual = float(needed_width) / available_width 187 if needed_vs_actual > PORTRAIT_WIDTH_EXTRA: 188 width = available_width * PORTRAIT_WIDTH_EXTRA 189 else: 190 width = needed_width 191 height = width / PORTRAIT_PROPS 192 if self.portrait and not self.portrait.destroyed: 193 self.portrait.SetSize(width, height) 194 if self.gradient_text and not self.gradient_text.destroyed: 195 self.gradient_text.height = height * 0.7 196 197 def _update_portrait_background_size(self, available_width, available_height): 198 width = BACKGROUND_PROPS * available_height 199 height = width / BACKGROUND_PROPS 200 if self.background_sprite and not self.background_sprite.destroyed: 201 if available_width > width: 202 self.background_sprite.align = uiconst.CENTER 203 self.background_sprite.width = available_width 204 self.background_sprite.height = float(available_width * height) / width 205 else: 206 self.background_sprite.align = uiconst.TOLEFT 207 self.background_sprite.left = -(width - available_width) / 2 208 self.background_sprite.width = width 209 210 def _OnResize(self, *args): 211 self._update_sizes()