browserwindow.py (9824B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\maps\browserwindow.py 2 import blue 3 import uthread 4 import trinity 5 import carbonui.const as uiconst 6 import localization 7 from carbonui.primitives.base import Base 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.frame import Frame 11 from carbonui.uicore import uicore 12 from carbonui.util.various_unsorted import FlushList 13 from eve.client.script.ui.control import eveIcon, eveLabel 14 from carbonui.control.window import Window 15 from eveuniverse.solar_systems import is_map_browser_suppressed 16 from menu import MenuLabel 17 VIEWWIDTH = 48 18 MAXMAPSIZE = 8000 19 MINMAPSIZE = 256 20 IDLVLUNI = 0 21 IDLVLREG = 1 22 IDLVLCON = 2 23 IDLVLSOL = 3 24 IDLVLSYS = 4 25 DRAWLVLREG = 1 26 DRAWLVLCON = 2 27 DRAWLVLSOL = 3 28 DRAWLVLSYS = 4 29 30 class MapBrowserWnd(Window): 31 __guid__ = 'form.MapBrowserWnd' 32 __notifyevents__ = ['OnSetDevice', 33 'OnUIScalingChange', 34 'OnDirectionalScannerAngleChanged', 35 'OnDirectionalScannerClosed', 36 'ProcessSessionChange'] 37 default_windowID = 'mapbrowser' 38 default_captionLabelPath = 'UI/Map/MapBrowser/MapBrowser' 39 40 def ApplyAttributes(self, attributes): 41 attributes.parent = uicore.layer.sidePanels 42 Window.ApplyAttributes(self, attributes) 43 locationID = attributes.locationID 44 self.Reset_() 45 self.scope = uiconst.SCOPE_INGAME 46 self.MakeUnMinimizable() 47 self.HideHeader() 48 self.MakeUnResizeable() 49 closeX = eveIcon.Icon(parent=self.sr.main, icon='ui_38_16_220', align=uiconst.TOPRIGHT, top=-1, idx=0) 50 closeX.OnClick = self.CloseByUser 51 closeX.hint = localization.GetByLabel('UI/Map/MapBrowser/CloseMapBrowser') 52 self.isDockWnd = 0 53 from eve.client.script.ui.shared.maps.browser import MapBrowser 54 self.sr.browser = MapBrowser(name='browserX', parent=self.sr.main, pos=(3, 0, 3, 0)) 55 self.sr.browser.GetMenu = self.GetMenu 56 self.initLocationID = locationID 57 58 def ProcessSessionChange(self, isRemote, session, change): 59 if is_map_browser_suppressed(session.locationid): 60 if self.state != uiconst.UI_HIDDEN: 61 self.Close() 62 63 def Close(self, *args, **kwds): 64 self.Hide() 65 Window.Close(self, *args, **kwds) 66 67 def GetAbsolutePosition(self): 68 stack = self.GetStack() 69 if stack: 70 return stack.contentCont.GetAbsolutePosition() 71 return Base.GetAbsolutePosition(self) 72 73 def Hide(self, *args, **kwargs): 74 self.state = uiconst.UI_HIDDEN 75 76 def Show(self, *args, **kwargs): 77 self.state = uiconst.UI_NORMAL 78 79 def OnUIScalingChange(self, change, *args): 80 self.OnSetDevice() 81 82 def OnSetDevice(self): 83 wasOpen = self.state != uiconst.UI_HIDDEN 84 self.Close() 85 if wasOpen: 86 MapBrowserWnd.Open() 87 88 def Reset_(self): 89 self.id = None 90 self.ids = None 91 self.inited = 0 92 self.loading = 0 93 self.history = [] 94 self.sr.mainmap = None 95 self.mapscale = settings.user.ui.Get('mapscale', 1.0) or 1.0 96 97 def InitializeStatesAndPosition(self, *args, **kw): 98 Window.InitializeStatesAndPosition(self, *args, **kw) 99 self.SetAlign([uiconst.TOLEFT, uiconst.TORIGHT][settings.user.ui.Get('mapbrowseralign', 'right') == 'right']) 100 self.height = uicore.desktop.height 101 self.width = self.height / 4 + 5 102 self.left = 0 103 self.top = 0 104 self.state = uiconst.UI_PICKCHILDREN 105 neocom = sm.GetService('neocom').GetNeocomContainer() 106 if neocom: 107 neocom.SetOrder(0) 108 self.DoLoad(self.initLocationID) 109 110 def DoLoad(self, locationID = None): 111 if locationID: 112 self.ShowLocation(locationID) 113 else: 114 uthread.new(self.LoadCurrentDelayed) 115 116 def LoadCurrentDelayed(self): 117 blue.pyos.synchro.SleepWallclock(200) 118 if not self.destroyed: 119 self.LoadCurrent() 120 121 def LoadCurrent(self): 122 self.sr.browser.LoadCurrent() 123 124 def Maximize(self, *args): 125 pass 126 127 def Minimize(self, *args): 128 pass 129 130 def GetMenu(self): 131 m = [] 132 if self.GetAlign() == uiconst.TOLEFT: 133 m.append((MenuLabel('UI/Map/MapBrowser/AlignRight'), self.ChangeAlign, ('right',))) 134 else: 135 m.append((MenuLabel('UI/Map/MapBrowser/AlignLeft'), self.ChangeAlign, ('left',))) 136 return m 137 138 def ChangeAlign(self, align): 139 settings.user.ui.Set('mapbrowseralign', align) 140 self.SetAlign([uiconst.TOLEFT, uiconst.TORIGHT][align == 'right']) 141 142 def OnDirectionalScannerAngleChanged(self, angle): 143 self.SetTempAngle(angle) 144 145 def OnDirectionalScannerClosed(self): 146 self.SetTempAngle(0) 147 148 def SetTempAngle(self, angle): 149 if self is None or self.destroyed: 150 return 151 if self.sr.browser and not self.sr.browser.destroyed: 152 self.sr.browser.SetTempAngle(angle) 153 154 def ShowLocation(self, locationID): 155 universeID, regionID, constellationID, solarsystemID, _itemID = sm.GetService('map').GetParentLocationID(locationID) 156 ids = [(universeID, 157 IDLVLUNI, 158 DRAWLVLREG, 159 regionID)] 160 if regionID is not None: 161 ids.append((regionID, 162 IDLVLREG, 163 DRAWLVLCON, 164 constellationID)) 165 if constellationID is not None: 166 ids.append((constellationID, 167 IDLVLCON, 168 DRAWLVLSOL, 169 solarsystemID)) 170 if solarsystemID is not None: 171 ids.append((solarsystemID, 172 IDLVLSOL, 173 DRAWLVLSYS, 174 None)) 175 self.sr.browser.LoadIDs(ids) 176 177 def MapScaler(self, where): 178 parent = Container(parent=where, align=uiconst.TOBOTTOM, height=14) 179 eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/Map/MapBrowser/ZoomLevel'), parent=parent, left=0, top=-12, width=100, color=(1.0, 1.0, 1.0, 0.5), state=uiconst.UI_NORMAL) 180 for level in (1, 2, 4): 181 sub = Container(parent=parent, align=uiconst.TOLEFT, width=24, state=uiconst.UI_NORMAL) 182 sub.OnClick = (self.ChangeZoomLevel, sub, level) 183 parent.width += sub.width 184 Frame(parent=sub, color=(1.0, 1.0, 1.0, 0.5)) 185 txt = eveLabel.EveLabelSmall(text='%sx' % level, parent=sub, align=uiconst.TOALL, left=6, top=2, state=uiconst.UI_DISABLED) 186 if settings.user.ui.Get('mapbrowserzoomlevel', 1) == level: 187 Fill(parent=sub, padding=(1, 1, 1, 1)) 188 189 def ChangeZoomLevel(self, btn, level, *args): 190 for each in btn.parent.children: 191 FlushList(each.children[5:]) 192 193 Fill(parent=btn, padding=(1, 1, 1, 1)) 194 settings.user.ui.Set('mapbrowserzoomlevel', level) 195 self.ResetMapContainerSize() 196 if self.sr.mainmap: 197 self.sr.mainmap.RefreshOverlays(1) 198 199 def _OnClose(self, *args): 200 settings.user.ui.Set('mapscale', self.mapscale) 201 if self.sr.mainmap: 202 self.sr.mainmap.Close() 203 self.sr.mainmap = None 204 self.Reset_() 205 206 def SetViewport(self, update = 0): 207 viewwidth = self.sr.mainmapparent.absoluteRight - self.sr.mainmapparent.absoluteLeft 208 viewheight = self.sr.mainmapparent.absoluteBottom - self.sr.mainmapparent.absoluteTop 209 self.sr.viewport.width = int(viewwidth * (float(VIEWWIDTH) / self.sr.mapcontainer.width)) 210 self.sr.viewport.height = int(self.sr.viewport.width * (float(viewheight) / viewwidth)) 211 self.sr.viewport.left = -int(self.sr.mapcontainer.left * (float(VIEWWIDTH) / self.sr.mapcontainer.width)) 212 self.sr.viewport.top = -int(self.sr.mapcontainer.top * (float(VIEWWIDTH) / self.sr.mapcontainer.width)) 213 214 def ResetMapContainerSize(self, keeplocation = 0): 215 mainwidth = self.sr.mainmapparent.absoluteRight - self.sr.mainmapparent.absoluteLeft 216 mainheight = self.sr.mainmapparent.absoluteBottom - self.sr.mainmapparent.absoluteTop 217 size = max(mainwidth, mainheight) 218 scale = settings.user.ui.Get('mapbrowserzoomlevel', 1) 219 self.sr.mapcontainer.width = size * scale 220 self.sr.mapcontainer.height = size * scale 221 if not keeplocation: 222 self.sr.mapcontainer.left = (mainwidth - self.sr.mapcontainer.width) / 2 223 self.sr.mapcontainer.top = (mainheight - self.sr.mapcontainer.height) / 2 224 self.SetViewport() 225 226 def SetMyViewportLocation(self, maxdist): 227 bp = sm.GetService('michelle').GetBallpark() 228 if not bp: 229 return 230 myball = bp.GetBall(session.shipid) 231 pos = trinity.TriVector(myball.x, myball.y, myball.z) 232 sizefactor = VIEWWIDTH / (maxdist * 2.0) * 0.75 233 pos.Scale(sizefactor) 234 me = self.sr.viewport.sr.me 235 me.left = VIEWWIDTH / 2 + int(pos.x) - me.width / 2 236 me.top = VIEWWIDTH / 2 + int(pos.z) - me.height / 2 237 238 def MoveMapWithViewport(self): 239 self.sr.mapcontainer.left = -int(self.sr.viewport.left / (float(VIEWWIDTH) / self.sr.mapcontainer.width)) 240 self.sr.mapcontainer.top = -int(self.sr.viewport.top / (float(VIEWWIDTH) / self.sr.mapcontainer.width)) 241 242 def OnFrameMouseDown(self, par, frame, *args): 243 self.dragframe = 1 244 uicore.uilib.ClipCursor(par.absoluteLeft, par.absoluteTop, par.absoluteRight, par.absoluteBottom) 245 frame.sr.grableft = uicore.uilib.x - frame.absoluteLeft 246 frame.sr.grabtop = uicore.uilib.y - frame.absoluteTop 247 248 def OnFrameMouseUp(self, par, frame, *args): 249 self.dragframe = 0 250 uicore.uilib.UnclipCursor() 251 252 def OnFrameMouseMove(self, par, frame, *args): 253 if getattr(self, 'dragframe', 0) == 1: 254 self.MoveMapWithViewport()