eveHint.py (11292B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\eveHint.py 2 import log 3 import types 4 import uthread 5 from carbon.client.script.util.misc import GetAttrs 6 from carbonui import uiconst 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.fill import Fill 9 from carbonui.primitives.frame import Frame 10 from carbonui.primitives.line import Line 11 from carbonui.primitives.sprite import Sprite 12 from carbonui.uicore import uicore 13 from carbonui.util.various_unsorted import ParanoidDecoMethod 14 from eve.client.script.ui.control.eveIcon import Icon 15 from eve.client.script.ui.control.eveLabel import EveLabelSmall 16 17 class BubbleHint(Container): 18 __guid__ = 'xtriui.BubbleHint' 19 default_name = 'bubblehint' 20 default_left = 200 21 default_top = 100 22 default_width = 100 23 default_height = 100 24 default_align = uiconst.TOPLEFT 25 default_state = uiconst.UI_NORMAL 26 27 def ApplyAttributes(self, attributes): 28 Container.ApplyAttributes(self, attributes) 29 self.sr.showExtended = None 30 self.extendedHint = '' 31 self.collapsedHint = '' 32 self.expanded = 0 33 self.sr.p5 = p5 = Sprite(parent=self, name='p5', pos=(0, -14, 18, 18), align=uiconst.TOPRIGHT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToTopRight.png') 34 self.sr.p4 = p4 = Sprite(parent=self, name='p4', pos=(0, -14, 18, 18), align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToTopCenter.png') 35 self.sr.p3 = p3 = Sprite(parent=self, name='p3', pos=(0, -14, 18, 18), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToTopLeft.png') 36 self.sr.p2 = p2 = Sprite(parent=self, name='p2', pos=(0, -14, 18, 18), align=uiconst.BOTTOMRIGHT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToBottomRight.png') 37 self.sr.p1 = p1 = Sprite(parent=self, name='p1', pos=(0, -14, 18, 18), align=uiconst.CENTERBOTTOM, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToBottomCenter.png') 38 self.sr.p0 = p0 = Sprite(parent=self, name='p0', pos=(0, -14, 18, 18), align=uiconst.BOTTOMLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Hint/pointerToBottomLeft.png') 39 self.sr.frame = Frame(parent=self, texturePath='res:/UI/Texture/classes/Hint/background.png', rectWidth=18, rectHeight=18, color=(1.0, 1.0, 1.0, 0.5)) 40 self.content = Container(name='content', parent=self, idx=0, padding=(2, 4, 2, 4)) 41 Fill(parent=self, color=(0.0, 0.0, 0.0, 0.8), padding=(2, 2, 2, 2)) 42 43 def ShowHint(self, hint, pointer = 0, textMaxWidth = 200): 44 self.content.Flush() 45 if type(hint) != types.ListType: 46 hint = [hint] 47 maxWidth = 0 48 for entryData in hint: 49 if entryData in ('<line>', '<dotline>'): 50 Line(parent=self.content, align=uiconst.TOTOP, height=1) 51 continue 52 entry = HintEntry(name='entryparent', parent=self.content, align=uiconst.TOTOP) 53 entry.Startup(entryData, textMaxWidth) 54 entry.OnMouseEnter = self.DecoEntryMouseEnter(entry, getattr(entry, 'OnMouseEnter', None)) 55 entry.OnMouseExit = self.DecoEntryMouseExit(entry, getattr(entry, 'OnMouseExit', None)) 56 57 self.width = max([ each.width for each in self.content.children ]) + 12 58 self.height = sum([ each.height for each in self.content.children ]) + 8 59 self.SetPointer(pointer) 60 self.data = (hint, pointer) 61 62 def DecoEntryMouseExit(self, entry, f): 63 64 def OnMouseExit(entry, *args): 65 sub = getattr(entry.sr, 'sub', None) 66 if sub: 67 if uicore.uilib.mouseOver != sub: 68 self.ClearSub(entry) 69 elif type(f) in (list, tuple): 70 callback, passedArgs = f 71 callback(passedArgs, entry, *args) 72 if f is not None: 73 f(entry, *args) 74 75 return (OnMouseExit, entry) 76 77 def DecoEntryMouseEnter(self, entry, f): 78 79 def OnMouseEnter(entry, *args): 80 self.Expand() 81 if f is None: 82 pass 83 elif type(f) in (list, tuple): 84 callback, passedArgs = f 85 callback(passedArgs, entry, *args) 86 else: 87 f(entry, *args) 88 89 return (OnMouseEnter, entry) 90 91 def OnEntryMouseExit(self, entry, *args): 92 if getattr(entry, 'OnMouseExit', None) not in (None, self.OnEntryMouseExit): 93 entry.OnMouseExit(entry, *args) 94 95 def OnEntryMouseEnter(self, entry, *args): 96 self.Expand() 97 if getattr(entry, 'OnMouseEnter', None) not in (None, self.OnEntryMouseEnter): 98 entry.OnMouseEnter(entry, *args) 99 100 def OnMouseEnter(self, *args): 101 self.Expand() 102 103 def Expand(self): 104 func = self.sr.Get('ExpandHint', None) 105 if func: 106 func(self, 1) 107 108 def _ShowSubhint(self, passedArgs, entry): 109 if not getattr(entry.sr, 'hilite', None): 110 entry.sr.hilite = Fill(parent=entry) 111 self.ClearSubs() 112 self.parent.SetOrder(0) 113 for each in self.content.children: 114 if each != entry and getattr(each, 'sr', None) and getattr(each.sr, 'hilite', None): 115 each.sr.hilite.state = uiconst.UI_HIDDEN 116 117 entry.sr.hilite.state = uiconst.UI_DISABLED 118 if len(passedArgs) == 2: 119 funcName, args = passedArgs 120 func = getattr(self, funcName, None) 121 if not func: 122 log.LogError('Unsupported dynamic function in bubblehint', funcName) 123 return 124 hint = func(*args) 125 else: 126 hint, = passedArgs 127 bubble = BubbleHint(parent=self.parent, align=uiconst.TOPLEFT, width=0, height=0, idx=0, state=uiconst.UI_NORMAL) 128 bubble.ShowHint(hint, None, 100) 129 if not self or self.destroyed: 130 return 131 self.sr.sub = bubble 132 if self.parent: 133 pl, pt, pw, ph = self.parent.GetAbsolute() 134 ll, lt, lw, lh = entry.GetAbsolute() 135 bubble.left = ll - pl + lw - 6 136 bubble.top = lt - pt - 2 137 138 def SetPointer(self, pointer, reposition = 1): 139 self.sr.p0.state = uiconst.UI_HIDDEN 140 self.sr.p1.state = uiconst.UI_HIDDEN 141 self.sr.p2.state = uiconst.UI_HIDDEN 142 self.sr.p3.state = uiconst.UI_HIDDEN 143 self.sr.p4.state = uiconst.UI_HIDDEN 144 self.sr.p5.state = uiconst.UI_HIDDEN 145 if pointer is not None: 146 p = self.sr.Get('p%s' % pointer, None) 147 p.state = uiconst.UI_DISABLED 148 if pointer in (0, 3): 149 left = self.parent.width / 2 + 2 150 elif pointer in (2, 5): 151 left = self.parent.width / 2 - self.width - 2 152 elif pointer in (1, 4): 153 left = (self.parent.width - self.width) / 2 + 1 154 sidePointerIdx = pointer 155 if pointer in (0, 1, 2): 156 top = self.parent.height / 2 - self.height - 18 157 elif pointer in (3, 4, 5): 158 top = self.parent.height / 2 + 20 159 if reposition: 160 self.left = left 161 self.top = top 162 elif GetAttrs(self, 'parent') is not None: 163 self.left = self.parent.width / 2 + 12 164 self.top = self.parent.height / 2 - 8 165 166 def GetEntry(self, id_): 167 for each in self.content.children: 168 if GetAttrs(each, 'data', 'id') == id_: 169 return each 170 171 def Offset(self, x, y, pointer): 172 self.SetPointer(pointer, 0) 173 self.sr.left = self.left 174 self.sr.top = self.top 175 self.left += x 176 self.top += y 177 178 def ResetOffset(self): 179 if self.sr.Get('left', None): 180 self.left = self.sr.left 181 self.top = self.sr.top 182 if getattr(self, 'data', None): 183 self.SetPointer(self.data[1]) 184 185 def GetBubbleHint(self, *args): 186 return sm.GetService('systemmap').GetBubbleHint(*args) 187 188 def ClearSubs(self): 189 if self.sr.Get('sub', None): 190 self.sr.sub.Close() 191 self.sr.sub = None 192 193 def _OnClose(self): 194 self.ClearSubs() 195 196 197 class HintEntry(Container): 198 199 def Startup(self, data, textMaxWidth): 200 self.data = data 201 self.textMaxWidth = textMaxWidth 202 self.Refresh() 203 204 def Refresh(self): 205 data = self.data 206 self.Flush() 207 textMaxWidth = self.textMaxWidth 208 if isinstance(data, basestring): 209 data = HintEntryData(data) 210 elif isinstance(data, tuple): 211 text, (event, func, args) = data 212 data = HintEntryData(text, event=event, func=func, args=args) 213 if data.menuGetter: 214 self.state = uiconst.UI_NORMAL 215 self.GetMenu = data.menuGetter 216 label = EveLabelSmall(text=data.text, parent=self, left=5, top=1, state=uiconst.UI_DISABLED, idx=0) 217 self.sr.label = label 218 self.width = label.textwidth 219 self.height = label.textheight + 1 220 self.name = data.text 221 222 def AddIcon(iconNum, left = -1): 223 Icon(icon=iconNum, parent=self, pos=(left, 224 -2, 225 16, 226 16), align=uiconst.TOPRIGHT, idx=0, state=uiconst.UI_DISABLED) 227 self.width += 14 228 229 if data.func: 230 setattr(self, data.event, (getattr(self, data.func, None), data.args)) 231 self.state = uiconst.UI_NORMAL 232 if data.func == 'ShowSubhint': 233 AddIcon(iconNum='ui_38_16_127') 234 elif data.func == 'ShowInfo': 235 AddIcon(iconNum='ui_38_16_126') 236 elif data.func == 'OpenAssets': 237 AddIcon(iconNum='ui_38_16_125') 238 if data.talking: 239 AddIcon(iconNum='ui_38_16_91', left=0) 240 241 def GetBubble(self): 242 return self.FindParentByName('bubblehint') 243 244 def OnMouseEnter(self, *etc): 245 self.sr.label.bold = True 246 247 OnMouseEnter = ParanoidDecoMethod(OnMouseEnter, ('sr', 'label')) 248 249 def OnMouseExit(self, *etc): 250 self.sr.label.bold = False 251 252 OnMouseExit = ParanoidDecoMethod(OnMouseExit, ('sr',)) 253 254 def ShowInfo(self, passedArgs, *args): 255 typeID, itemID = passedArgs 256 sm.GetService('info').ShowInfo(typeID, itemID) 257 258 def ShowSubhint(self, passedArgs, entry): 259 bubble = self.GetBubble() 260 if bubble is None: 261 return 262 if len(passedArgs) == 2: 263 uthread.new(bubble._ShowSubhint, passedArgs, entry) 264 else: 265 bubble._ShowSubhint(passedArgs, entry) 266 267 def OpenAssets(self, passedArgs, *args): 268 stationID, = passedArgs 269 sm.GetService('assets').Show(stationID) 270 271 def OpenAddressbook(self, contactType, *args): 272 ab = sm.GetService('addressbook') 273 ab.Show() 274 ab.ShowContacts(contactType) 275 276 277 class HintEntryData(): 278 279 def __init__(self, text, id = None, event = None, func = None, args = None, menuGetter = None, talking = False): 280 self.text = text 281 self.event = event 282 self.func = func 283 self.args = args 284 self.menuGetter = menuGetter 285 self.talking = talking 286 self.id = id