NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

browser.py (11437B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\maps\browser.py
      2 import localization
      3 import uthread
      4 from carbonui import uiconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.uicore import uicore
      8 from carbonui.util.various_unsorted import FlushList
      9 from eve.client.script.ui.control import eveLabel
     10 from eve.client.script.ui.control.themeColored import LineThemeColored
     11 from eve.client.script.ui.shared.infoPanels.listSurroundingsBtn import ListSurroundingsBtn
     12 from eve.client.script.ui.shared.mapView.mapViewUtil import OpenMap
     13 from eve.client.script.ui.shared.maps.map2D import Map2D
     14 from eve.common.lib import appConst as const
     15 from eveexceptions import UserError
     16 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     17 DRAWLVLREG = 1
     18 DRAWLVLCON = 2
     19 DRAWLVLSOL = 3
     20 DRAWLVLSYS = 4
     21 
     22 class MapBrowser(Container):
     23     __guid__ = 'xtriui.MapBrowser'
     24     __nonpersistvars__ = []
     25     __notifyevents__ = ['ProcessSessionChange', 'DoBallsAdded']
     26 
     27     def ApplyAttributes(self, attributes):
     28         Container.ApplyAttributes(self, attributes)
     29         sm.RegisterNotify(self)
     30         self.ids = [[],
     31          [],
     32          [],
     33          []]
     34         self.loadingMap = 0
     35 
     36     def ProcessSessionChange(self, isRemote, session, change):
     37         if 'regionid' in change and change['regionid'][0] == self.ids[1][0]:
     38             self.LoadIDs([(const.locationUniverse,
     39               0,
     40               DRAWLVLREG,
     41               session.regionid),
     42              (session.regionid,
     43               1,
     44               DRAWLVLCON,
     45               session.constellationid),
     46              (session.constellationid,
     47               2,
     48               DRAWLVLSOL,
     49               session.solarsystemid2),
     50              (session.solarsystemid2,
     51               3,
     52               DRAWLVLSYS,
     53               None)])
     54         elif 'constellationid' in change and change['constellationid'][0] == self.ids[2][0]:
     55             self.LoadIDs([(session.regionid,
     56               1,
     57               DRAWLVLCON,
     58               session.constellationid), (session.constellationid,
     59               2,
     60               DRAWLVLSOL,
     61               session.solarsystemid2), (session.solarsystemid2,
     62               3,
     63               DRAWLVLSYS,
     64               None)])
     65         elif 'solarsystemid' in change and change['solarsystemid'][0] == self.ids[3][0]:
     66             self.LoadIDs([(session.constellationid,
     67               2,
     68               DRAWLVLSOL,
     69               session.solarsystemid2), (session.solarsystemid2,
     70               3,
     71               DRAWLVLSYS,
     72               None)])
     73 
     74     def Startup(self):
     75         pass
     76 
     77     def LoadCurrent(self):
     78         self.LoadIDs([(const.locationUniverse,
     79           0,
     80           DRAWLVLREG,
     81           session.regionid),
     82          (session.regionid,
     83           1,
     84           DRAWLVLCON,
     85           session.constellationid),
     86          (session.constellationid,
     87           2,
     88           DRAWLVLSOL,
     89           session.solarsystemid2),
     90          (session.solarsystemid2,
     91           3,
     92           DRAWLVLSYS,
     93           None)])
     94 
     95     def LoadIDs(self, ids):
     96         for id, idlevel, drawlevel, selected in ids:
     97             if self.destroyed:
     98                 return
     99             if self.ids[idlevel] == [id]:
    100                 if selected and len(self.children) > idlevel:
    101                     self.children[idlevel].SetSelected([selected])
    102                 continue
    103             self.GetMap([id], idlevel, drawlevel, selected)
    104 
    105     def Prepare():
    106         pass
    107 
    108     def GetMap(self, ids, idlevel, drawlevel, selected = None):
    109         if getattr(self, 'loadingMap', 0):
    110             return
    111         self.loadingMap = 1
    112         FlushList(self.children[idlevel:])
    113         self.ids[idlevel] = ids
    114         cfg.evelocations.Prime(ids)
    115         l, t, absWidth, absHeight = self.GetAbsolute()
    116         pilmap = Map2D(name='map', align=uiconst.TOTOP, state=uiconst.UI_NORMAL, height=absWidth)
    117         pilmap.OnSelectItem = self.OnMapSelection
    118         pilmap.GetParentMenu = self.GetMenu
    119         pilmapList = []
    120         basesize = self.absoluteRight - self.absoluteLeft
    121         if drawlevel == DRAWLVLSYS:
    122             pilmap.width = pilmap.height = basesize
    123             pilmap.left = pilmap.top = (pilmap.width - basesize) / 2
    124             pilmap.align = uiconst.RELATIVE
    125             pilmap.dragAllowed = 1
    126             mapparent = Container(name='mapparent', align=uiconst.TOTOP, lockAspect=1, parent=self, clipChildren=1, height=absWidth)
    127             LineThemeColored(parent=mapparent, align=uiconst.TOBOTTOM)
    128             pilmapList = mapparent.children
    129             self.SetLoadExternalPointer(mapparent, self.ids[idlevel][0])
    130             addstuff = mapparent
    131         else:
    132             LineThemeColored(parent=pilmap.overlays, align=uiconst.TOBOTTOM)
    133             pilmapList = self.children
    134             self.SetLoadExternalPointer(pilmap, self.ids[idlevel][0])
    135             addstuff = pilmap.overlays
    136         pilmap.Draw(ids, idlevel, drawlevel, basesize)
    137         uicore.animations.FadeIn(pilmap, duration=0.3)
    138         pilmapList.append(pilmap)
    139         listicon = ListSurroundingsBtn(parent=addstuff, align=uiconst.TOPLEFT, state=uiconst.UI_NORMAL, pos=(0, 3, 16, 16), idx=0, showIcon=True)
    140         locConsts = {0: {const.typeUniverse: ''},
    141          1: {const.typeRegion: localization.GetByLabel('UI/Common/LocationTypes/Region')},
    142          2: {const.typeConstellation: localization.GetByLabel('UI/Common/LocationTypes/Constellation')},
    143          3: {const.typeSolarSystem: localization.GetByLabel('UI/Common/LocationTypes/SolarSystem')}}
    144         levelName = locConsts.get(idlevel, '').values()[0]
    145         levelID = locConsts.get(idlevel, '').keys()[0]
    146         for id in ids:
    147             if levelID != const.typeUniverse:
    148                 locName = cfg.evelocations.Get(id).name
    149 
    150         hintStr = ''
    151         buttonStr = ''
    152         if levelID == const.typeUniverse:
    153             buttonStr = localization.GetByLabel('UI/Common/LocationTypes/Universe')
    154             hintStr = localization.GetByLabel('UI/Map/MapBrowser/ListRegions')
    155         elif levelID == const.typeRegion:
    156             buttonStr = localization.GetByLabel('UI/Map/MapBrowser/NameRegion', name=locName)
    157             hintStr = localization.GetByLabel('UI/Map/MapBrowser/ListConstellations', name=locName)
    158         elif levelID == const.typeConstellation:
    159             buttonStr = localization.GetByLabel('UI/Map/MapBrowser/NameConstellation', name=locName)
    160             hintStr = localization.GetByLabel('UI/Map/MapBrowser/ListSolarSystems', name=locName)
    161         elif levelID == const.typeSolarSystem:
    162             buttonStr = localization.GetByLabel('UI/Map/MapBrowser/NameSolarSystem', name=locName)
    163             hintStr = localization.GetByLabel('UI/Map/MapBrowser/ListCelestials', name=locName)
    164         listbtn = eveLabel.EveLabelMedium(text=buttonStr, parent=addstuff, left=listicon.left + listicon.width + 4, top=5, color=(1.0, 1.0, 1.0, 0.75), idx=0, state=uiconst.UI_NORMAL)
    165         listbtn.expandOnLeft = True
    166         listbtn.GetMenu = listicon.GetMenu
    167         for id in ids:
    168             if id != const.typeUniverse:
    169                 listicon.sr.typeID = listbtn.sr.typeID = levelID
    170                 listicon.sr.itemID = listbtn.sr.itemID = id
    171 
    172         listbtn.sr.hint = hintStr
    173         if self.destroyed:
    174             return
    175         if drawlevel == DRAWLVLSYS:
    176             listbtn.sr.groupByType = listicon.sr.groupByType = 1
    177             listbtn.sr.mapitems = listicon.sr.mapitems = pilmap.mapitems
    178         elif drawlevel in (DRAWLVLCON, DRAWLVLSOL):
    179             listbtn.sr.mapitems = listicon.sr.mapitems = pilmap.mapitems[1:]
    180         else:
    181             listbtn.sr.mapitems = listicon.sr.mapitems = pilmap.mapitems
    182         listbtn.solarsystemid = listicon.solarsystemid = ids[0]
    183         if selected:
    184             pilmap.SetSelected([selected])
    185         self.Refresh()
    186         self.loadingMap = 0
    187 
    188     def GetMenu(self):
    189         return []
    190 
    191     def ShowOnMap(self, itemID, *args):
    192         if itemID >= const.mapWormholeRegionMin and itemID <= const.mapWormholeRegionMax or itemID >= const.mapWormholeConstellationMin and itemID <= const.mapWormholeConstellationMax or itemID >= const.mapWormholeSystemMin and itemID <= const.mapWormholeSystemMax:
    193             raise UserError('MapShowWormholeSpaceInfo', {'char': session.charid})
    194         if session.stationid:
    195             sm.GetService('station').CleanUp()
    196         OpenMap(interestID=itemID)
    197 
    198     def SetLoadExternalPointer(self, where, id, func = None, args = None, hint = None):
    199         pointer = Sprite(parent=where, name='pointer', align=uiconst.BOTTOMLEFT, pos=(2, 2, 16, 16), texturePath='res:/UI/Texture/Shared/arrowLeft.png', color=(1.0, 1.0, 1.0, 0.5))
    200         pointer.hint = hint if hint is not None else localization.GetByLabel('UI/Map/MapBrowser/ShowInWorldMap')
    201         pointer.OnClick = (self.ShowOnMap, id)
    202 
    203     def OnMapSelection(self, themap, itemID):
    204         if themap.drawlevel == DRAWLVLSYS:
    205             return
    206         sm.GetService('loading').Cycle('Loading map')
    207         mapidx = self.children.index(themap)
    208         ids = [itemID]
    209         idlevel = mapidx + 1
    210         drawlevel = mapidx + 2
    211         shift = uicore.uilib.Key(uiconst.VK_SHIFT)
    212         if drawlevel > DRAWLVLSYS:
    213             sm.GetService('loading').StopCycle()
    214             return
    215         if drawlevel == DRAWLVLSYS:
    216             if shift:
    217                 uthread.new(prompt_player_fsd_dialog, 'CustomInfo', {'info': localization.GetByLabel('UI/Map/MapBrowser/CannotShiftSelect')})
    218         elif shift and len(self.children) > idlevel:
    219             currentids = self.children[idlevel].ids
    220             ids += currentids
    221             if itemID in currentids:
    222                 while itemID in ids:
    223                     ids.remove(itemID)
    224 
    225         if not len(ids):
    226             return
    227         themap.SetSelected(ids)
    228         if mapidx < 3:
    229             uthread.new(self.GetMap, ids, idlevel, drawlevel)
    230         sm.GetService('loading').StopCycle()
    231 
    232     def Refresh(self, update = 0):
    233         for each in self.children:
    234             if hasattr(each, 'RefreshSize'):
    235                 each.RefreshSize()
    236             if hasattr(each, 'RefreshOverlays'):
    237                 each.RefreshOverlays()
    238 
    239     def SetTempAngle(self, angle):
    240         if len(self.children) == 4 and len(self.children[-1].children):
    241             if hasattr(self.children[-1].children[-1], 'SetTempAngle'):
    242                 self.children[-1].children[-1].SetTempAngle(angle)
    243 
    244     def DoBallsAdded(self, *args, **kw):
    245         import stackless
    246         import blue
    247         t = stackless.getcurrent()
    248         timer = t.PushTimer(blue.pyos.taskletTimer.GetCurrent() + '::mapBrowser')
    249         try:
    250             return self.DoBallsAdded_(*args, **kw)
    251         finally:
    252             t.PopTimer(timer)
    253 
    254     def DoBallsAdded_(self, lst):
    255 
    256         def PassEventToChild(childItem):
    257             if hasattr(childItem, 'CheckMyLocation'):
    258                 childItem.CheckMyLocation()
    259             if hasattr(childItem, 'CheckDestination'):
    260                 childItem.CheckDestination()
    261 
    262         for ball, slimItem in lst:
    263             if slimItem.itemID == session.shipid:
    264                 for childMap in self.children:
    265                     PassEventToChild(childMap)
    266                     if hasattr(childMap, 'children'):
    267                         for grandchildItem in childMap.children:
    268                             PassEventToChild(grandchildItem)
    269 
    270                 break