eveImage.py (10084B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\eveImage.py 2 import types 3 import carbonui.const as uiconst 4 import dogma.data as dogma_data 5 import localization 6 import log 7 import uthread 8 from carbon.common.script.util import htmlwriter 9 from carbonui.control.image import ImageCore 10 from carbonui.control.link import Link 11 from carbonui.primitives.container import Container 12 from carbonui.primitives.fill import Fill 13 from carbonui.primitives.line import Line 14 from carbonui.primitives.sprite import Sprite 15 from carbonui.util import stringManip, various_unsorted 16 from eve.client.script.ui.control import eveIcon 17 from eve.client.script.ui.control.eveIcon import DraggableIcon 18 from eve.client.script.ui.shared.maps.map2D import Map2D 19 from eve.client.script.ui.util import uix 20 from eve.common.script.sys import dbrow, idCheckers 21 from menu import MenuLabel 22 23 class Image(ImageCore): 24 __guid__ = 'uicls.Image' 25 __notifyevents__ = ['OnPortraitCreated'] 26 DRAW_LEVELS = {'universe': 0, 27 'region': 1, 28 'constellation': 2, 29 'solarsystem': 3, 30 'celestials': 4} 31 IMAGE_TYPES = {'portrait', 32 'corplogo', 33 'factionlogo', 34 'starmap', 35 'typeicon', 36 'icon', 37 'res', 38 'netres', 39 'alliancelogo', 40 'racelogo'} 41 LOGO_IMAGE_TYPES = {'corplogo', 42 'factionlogo', 43 'alliancelogo', 44 'racelogo'} 45 46 def ApplyAttributes(self, attributes): 47 ImageCore.ApplyAttributes(self, attributes) 48 self.SetAlign(uiconst.TOPLEFT) 49 50 def LoadAttrs(self, attrs): 51 src = attrs.src 52 if attrs.texture: 53 sprite = Sprite(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED) 54 sprite.texture = attrs.texture 55 elif src.startswith('icon:'): 56 uthread.new(self.LoadIcon) 57 parts = src.split(':', 1) 58 if len(parts) == 2: 59 imageType, imageData = parts 60 if imageType == 'portrait': 61 uthread.new(self.LoadPortrait) 62 elif imageType in self.LOGO_IMAGE_TYPES: 63 eveIcon.GetLogoIcon(itemID=int(imageData), align=uiconst.TOALL, parent=self, state=uiconst.UI_DISABLED) 64 elif src.startswith('starmap:'): 65 uthread.new(self.GetMap, src) 66 elif src.startswith('typeicon:'): 67 uthread.new(self.LoadTypeIcon) 68 69 def GetMap(self, src): 70 if self.destroyed: 71 return 72 data = stringManip.PrepareArgs(src[8:]) 73 if 'ids' not in data: 74 log.LogError('Invalid starmap data:', data, ' (missing ids)') 75 return 76 if 'level' in data: 77 drawLevel = self.DRAW_LEVELS[data['level'].lower()] 78 else: 79 drawLevel = 3 80 ids = [] 81 if type(data['ids']) == types.IntType: 82 ids = [data['ids']] 83 else: 84 for each in data['ids'].replace(' ', '').split(','): 85 try: 86 ids.append(int(each)) 87 except Exception as e: 88 log.LogWarn(e) 89 90 if not ids: 91 idLevel = 0 92 if idCheckers.IsRegion(ids[0]): 93 idLevel = 1 94 if idCheckers.IsConstellation(ids[0]): 95 idLevel = 2 96 if idCheckers.IsSolarSystem(ids[0]): 97 idLevel = 3 98 pilmap = Map2D(parent=self, align=uiconst.TOALL) 99 pilmap.Draw(ids, idLevel, drawLevel, int(self.attrs.size)) 100 if self.destroyed: 101 return 102 for each in pilmap.children[:]: 103 if each.name == 'frame': 104 each.Close() 105 106 if 'marks' in data: 107 marks = [] 108 for each in data['marks'].split(','): 109 mark = each.split('::') 110 if len(mark) == 4: 111 try: 112 id = int(mark[0]) 113 hint = unicode(mark[1]) 114 color = unicode(mark[2]) 115 sumin = mark[3] 116 marks += [id, 117 hint, 118 color, 119 sumin] 120 except Exception as e: 121 log.LogWarn('Failed mark parsing', mark, e) 122 123 if marks: 124 pilmap.SetMarks(marks) 125 pilmap.UpdateMyLocation() 126 127 def GetMenu(self): 128 m = [] 129 if getattr(self, 'attrs', None) and getattr(self.attrs, 'src', None) and self.attrs.src: 130 src = self.attrs.src 131 parts = self.attrs.src.split(':', 1) 132 if len(parts) == 2: 133 if parts[0] not in self.IMAGE_TYPES: 134 m += [(MenuLabel('UI/Common/ReloadImage'), self.Reload)] 135 if getattr(self.attrs, 'a', None): 136 m += Link().GetLinkMenu(self, self.attrs.a.href) 137 return m 138 139 def LoadPortrait(self, orderIfMissing = True): 140 attrs = self.attrs 141 self.Flush() 142 sprite = eveIcon.Icon(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, pos=(0, 0, 0, 0)) 143 self.sr.sprite = sprite 144 size = int(max(attrs.size, 64)) 145 charID = int(attrs.src[9:]) 146 if sm.GetService('photo').GetPortrait(charID, size, sprite, orderIfMissing, callback=True): 147 self.picloaded = 1 148 else: 149 sm.RegisterNotify(self) 150 sm.GetService('photo').on_scene_portrait_rendered.connect(self._OnScenePortraitRendered) 151 152 def _OnScenePortraitRendered(self, charID, size, path): 153 if self.destroyed: 154 return 155 if self.attrs.src.startswith('portrait:'): 156 mycharID = int(self.attrs.src[9:]) 157 if mycharID == charID and self.sr.sprite and not self.sr.sprite.destroyed: 158 self.sr.sprite.LoadTexture(path) 159 self.picloaded = 1 160 161 def Close(self, *args, **kwargs): 162 try: 163 sm.GetService('photo').on_scene_portrait_rendered.disconnect(self._OnScenePortraitRendered) 164 except Exception: 165 pass 166 167 ImageCore.Close(self, *args, **kwargs) 168 169 def OnPortraitCreated(self, charID, _size): 170 if hasattr(self, 'attrs') and self.attrs.src.startswith('portrait:'): 171 mycharID = int(self.attrs.src[9:]) 172 if mycharID == charID: 173 self.LoadPortrait(False) 174 175 def LoadTypeIcon(self, *args): 176 attrs = self.attrs 177 src = attrs.src 178 typeID = None 179 try: 180 typeID = int(src[9:]) 181 except: 182 log.LogInfo("couldn't convert string to typeID, looking up constvalue, Img::Load", src) 183 typeID = dbrow.LookupConstValue('type%s' % attrs.src[9:].strip().capitalize(), None) 184 185 bumped = getattr(attrs, 'bumped', 0) 186 showFitting = getattr(attrs, 'showfitting', 0) 187 showTechLevel = getattr(attrs, 'showtechlevel', 0) 188 isCopy = getattr(attrs, 'iscopy', 0) 189 if not typeID: 190 kw = htmlwriter.PythonizeArgs(src[9:]) 191 typeID = kw.get('typeID', None) 192 bumped = kw.get('bumped', 0) 193 isCopy = kw.get('isCopy', 0) 194 showFitting = kw.get('showFitting', 0) 195 showTechLevel = kw.get('showTechLevel', 0) 196 if typeID: 197 if bumped: 198 if hasattr(self, 'icon') and self.icon: 199 self.icon.Close() 200 self.icon = DraggableIcon(parent=self, typeID=typeID, isCopy=True if isCopy == 1 else False, state=uiconst.UI_DISABLED) 201 if showFitting: 202 powerEffect = None 203 powerIcon = None 204 powerEffects = [const.effectHiPower, const.effectMedPower, const.effectLoPower] 205 for effect in dogma_data.get_type_effects(typeID): 206 if effect.effectID in powerEffects: 207 powerEffect = dogma_data.get_effect_with_default(effect.effectID, None) 208 powerIcon = {const.effectHiPower: 11, 209 const.effectMedPower: 10, 210 const.effectLoPower: 9}.get(powerEffect.effectID, None) 211 break 212 213 if powerIcon: 214 c = Container(name='powericon', align=uiconst.BOTTOMRIGHT, parent=self.icon, width=attrs.width / 4, height=attrs.width / 4, idx=0) 215 Line(parent=c, align=uiconst.TOLEFT, color=(1.0, 1.0, 1.0, 0.5)) 216 Line(parent=c, align=uiconst.TOTOP, color=(1.0, 1.0, 1.0, 0.5)) 217 Fill(parent=c, padRight=2, padBottom=2, color=(0.0, 0.0, 0.0, 1.0)) 218 eveIcon.Icon(icon='ui_8_64_%s' % powerIcon, parent=c, align=uiconst.TOALL, idx=0, hint=localization.GetByLabel('UI/Common/FitsToSlot', slotType=dogma_data.get_effect_display_name(powerEffect.effectID)), ignoreSize=True) 219 if showTechLevel: 220 techSprite = uix.GetTechLevelIcon(None, 0, typeID) 221 if techSprite: 222 c = Container(name='techIcon', align=uiconst.TOPLEFT, parent=self.icon, width=16, height=16, idx=0) 223 c.children.append(techSprite) 224 else: 225 eveIcon.Icon(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, pos=(0, 0, 0, 0), typeID=typeID, size=attrs.width, isCopy=isCopy) 226 else: 227 log.LogInfo('Couldnt convert', attrs.src[9:], 'to typeID') 228 229 def LoadIcon(self, *args): 230 sprite = Sprite(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, idx=0, pos=(0, 0, 0, 0)) 231 if not hasattr(self, 'attrs'): 232 return 233 icon = self.attrs.src[5:] 234 if isinstance(icon, unicode): 235 icon = icon.encode('ascii', 'xmlcharrefreplace') 236 spl = icon.split('_') 237 if len(spl) == 2: 238 texpix, num = spl 239 iconSize = eveIcon.GetIconSize(texpix) 240 icon = 'ui_%s_%s_%s' % (texpix, iconSize, num) 241 various_unsorted.MapIcon(sprite, icon, ignoreSize=True) 242 243 244 from carbonui.control.image import ImageCoreOverride 245 ImageCoreOverride.__bases__ = (Image,)