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

windowsvc.py (9833B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\windowsvc.py
      2 import weakref
      3 from carbonui.primitives.fill import Fill
      4 from carbonui.window.layout import apply_desktop_window_layout, capture_desktop_window_layout
      5 from eve.client.script.ui import eveColor
      6 from carbon.common.script.sys.service import Service
      7 from carbonui.control.window import Window
      8 from carbonui.window.settings import ResetAllWindowSettings
      9 from carbonui.window.stack import WindowStack
     10 from carbonui.primitives.base import ScaleDpi
     11 from carbonui.util.various_unsorted import Transplant
     12 import carbonui.const as uiconst
     13 import evegraphics.settings as gfxsettings
     14 from carbonui.uicore import uicore
     15 from eve.client.script.ui.inflight.drones.dronesWindow import DronesWindow
     16 from eve.client.script.ui.inflight.overview.overviewWindow import OverviewWindow
     17 from eve.client.script.ui.inflight.selectedItemWnd import SelectedItemWnd
     18 from eve.client.script.ui.services import sessionChangeWindowOpener
     19 from eve.client.script.ui.shared.fleet.fleetWatchList import WatchListPanel
     20 from chat.client.window import ChatWindow
     21 from xmppchatclient.xmppchatwindow import XmppChatWindow
     22 
     23 class WindowMgr(Service):
     24     __guid__ = 'svc.window'
     25     __servicename__ = 'window'
     26     __displayname__ = 'Window Service'
     27     __dependencies__ = ['form']
     28     __notifyevents__ = ['DoSessionChanging',
     29      'OnSessionChanged',
     30      'OnEndChangeDevice',
     31      'ProcessDeviceChange',
     32      'OnBlurredBufferCreated',
     33      'OnHideUI',
     34      'OnShowUI',
     35      'OnBeforeViewStateChanged',
     36      'OnViewStateChanged',
     37      'OnWindowMaximized']
     38     __startupdependencies__ = ['settings']
     39 
     40     def Run(self, memStream = None):
     41         self.LogInfo('Starting Window Service')
     42         self.wndIntersectionsByRects = {}
     43         self.windowsMinimizedByFullscreenView = weakref.WeakSet()
     44 
     45     def Stop(self, memStream = None):
     46         self.LogInfo('Stopping Window Service')
     47         Service.Stop(self)
     48 
     49     def ProcessDeviceChange(self, *args):
     50         self.PreDeviceChange_DesktopLayout = capture_desktop_window_layout()
     51 
     52     def OnEndChangeDevice(self, *args):
     53         self.RealignWindows()
     54         sm.GetService('device').SetupUIScaling()
     55 
     56     def OnBeforeViewStateChanged(self, oldViewName, newViewName):
     57         if not oldViewName:
     58             return
     59         viewStateSvc = sm.GetService('viewState')
     60         newViewInfo = viewStateSvc.GetViewInfo(newViewName)
     61         if newViewInfo.IsSecondary():
     62             self._OnEnteringSecondaryView()
     63 
     64     def OnViewStateChanged(self, oldViewName, newViewName):
     65         if not oldViewName:
     66             return
     67         viewStateSvc = sm.GetService('viewState')
     68         oldViewInfo = viewStateSvc.GetViewInfo(oldViewName)
     69         newViewInfo = viewStateSvc.GetViewInfo(newViewName)
     70         if newViewInfo.IsPrimary() and oldViewInfo.IsSecondary():
     71             self._OnExitingSecondaryView()
     72 
     73     def _OnEnteringSecondaryView(self):
     74         for wnd in uicore.registry.GetValidWindows(floatingOnly=True, getHidden=True):
     75             if not wnd.IsOverlayed() and not wnd.minimized:
     76                 wnd.Minimize(animate=False)
     77                 self.RegisterAsMinimizedByFullscreenView(wnd)
     78 
     79     def RegisterAsMinimizedByFullscreenView(self, wnd):
     80         self.windowsMinimizedByFullscreenView.add(wnd)
     81 
     82     def _OnExitingSecondaryView(self):
     83         shouldMaximze = []
     84         for wnd in self.windowsMinimizedByFullscreenView:
     85             if not wnd.destroyed:
     86                 shouldMaximze.append(wnd)
     87 
     88         for wnd in shouldMaximze:
     89             wnd.Maximize(retainOrder=True)
     90 
     91     def OnWindowMaximized(self, wnd, wasMinimized):
     92         if wnd in self.windowsMinimizedByFullscreenView:
     93             self.windowsMinimizedByFullscreenView.remove(wnd)
     94 
     95     def ValidateWindows(self):
     96         d = uicore.desktop
     97         all = uicore.registry.GetValidWindows(1, floatingOnly=True)
     98         for wnd in all:
     99             if wnd.align != uiconst.RELATIVE:
    100                 continue
    101             wnd.left = max(-wnd.width + 64, min(d.width - 64, wnd.left))
    102             wnd.top = max(0, min(d.height - wnd.GetCollapsedHeight(), wnd.top))
    103 
    104     def DoSessionChanging(self, isRemote, session, change):
    105         if not session.charid:
    106             for layer in (uicore.layer.starmap,):
    107                 for each in layer.children:
    108                     each.Close()
    109 
    110     def OnSessionChanged(self, isRemote, session, change):
    111         if sm.GetService('connection').IsConnected() and self.IsLocationChange(change):
    112             sessionChangeWindowOpener.OnSessionChanged()
    113 
    114     def IsLocationChange(self, change):
    115         if 'locationid' in change:
    116             return True
    117         if 'structureid' in change:
    118             return True
    119         if 'shipid' in change and session.structureid in change['shipid']:
    120             return True
    121         return False
    122 
    123     def OnHideUI(self, *args):
    124         self.UpdateIntersectionBackground()
    125 
    126     def OnShowUI(self, *args):
    127         self.UpdateIntersectionBackground()
    128 
    129     def ResetWindowSettings(self):
    130         openWindowStacks = []
    131         openWindows = []
    132         for wnd in uicore.registry.GetWindows():
    133             if not isinstance(wnd, Window):
    134                 continue
    135             if wnd.isDialog:
    136                 continue
    137             if wnd.parent != uicore.layer.main:
    138                 Transplant(wnd, uicore.layer.main)
    139             if isinstance(wnd, WindowStack):
    140                 openWindowStacks.append(wnd)
    141             else:
    142                 openWindows.append(wnd)
    143 
    144         for wnd in openWindowStacks:
    145             wnd.Close()
    146 
    147         sm.GetService('device').SetupUIScaling()
    148         ResetAllWindowSettings()
    149         favorClasses = [XmppChatWindow,
    150          ChatWindow,
    151          SelectedItemWnd,
    152          OverviewWindow,
    153          DronesWindow,
    154          WatchListPanel]
    155         openWindows = sorted(openWindows, key=lambda wnd: wnd.__class__ in favorClasses, reverse=True)
    156         for wnd in openWindows:
    157             wnd.OnResetWindowSettings()
    158 
    159         settings.user.ui.Delete('targetOrigin')
    160         sm.GetService('target').ArrangeTargets()
    161 
    162     def RealignWindows(self):
    163         desktopLayout = getattr(self, 'PreDeviceChange_DesktopLayout', None)
    164         if desktopLayout:
    165             apply_desktop_window_layout(desktopLayout)
    166         self.PreDeviceChange_DesktopLayout = None
    167         if session.charid:
    168             sm.GetService('target').ArrangeTargets()
    169 
    170     def OnBlurredBufferCreated(self):
    171         self.UpdateIntersectionBackground()
    172 
    173     def GetWindowIntersectionRects(self):
    174         ret = set()
    175         wndRects = self.GetWindowRects()
    176         numWnds = len(wndRects)
    177         for i in xrange(numWnds):
    178             for j in xrange(i + 1, numWnds):
    179                 wnd1 = wndRects[i]
    180                 wnd2 = wndRects[j]
    181                 if self.IsIntersecting(wnd1, wnd2):
    182                     ret.add(self.GetIntersection(wnd1, wnd2))
    183 
    184         return ret
    185 
    186     def UpdateIntersectionBackground(self):
    187         desktop = uicore.uilib.desktopBlurredBg
    188         if not desktop:
    189             return
    190         currRects = self.GetWindowIntersectionRects()
    191         toRemove = [ rect for rect in self.wndIntersectionsByRects.keys() if rect not in currRects ]
    192         for rect in toRemove:
    193             intersection = self.wndIntersectionsByRects.pop(rect)
    194             intersection.Close()
    195 
    196         toCreate = [ rect for rect in currRects if rect not in self.wndIntersectionsByRects ]
    197         for x1, y1, x2, y2 in toCreate:
    198             intersection = Fill(parent=desktop, pos=(x1,
    199              y1,
    200              x2 - x1,
    201              y2 - y1), align=uiconst.TOPLEFT, padding=1, color=eveColor.BLACK, opacity=0.5)
    202             self.wndIntersectionsByRects[x1, y1, x2, y2] = intersection
    203 
    204         desktop.UpdateAlignmentAsRoot()
    205 
    206     def IsIntersecting(self, wnd1, wnd2):
    207         l1, t1, r1, b1 = wnd1
    208         l2, t2, r2, b2 = wnd2
    209         hoverlaps = True
    210         voverlaps = True
    211         if l1 >= r2 or r1 <= l2:
    212             hoverlaps = False
    213         if t1 >= b2 or b1 <= t2:
    214             voverlaps = False
    215         return hoverlaps and voverlaps
    216 
    217     def GetIntersection(self, wnd1, wnd2):
    218         l1, t1, r1, b1 = wnd1
    219         l2, t2, r2, b2 = wnd2
    220         left = max(l1, l2)
    221         top = max(t1, t2)
    222         right = min(r1, r2)
    223         bottom = min(b1, b2)
    224         return (left,
    225          top,
    226          right,
    227          bottom)
    228 
    229     def GetWindowRects(self):
    230         windows = uicore.registry.GetValidWindows()
    231         ret = [ (wnd.displayX,
    232          wnd.displayY,
    233          wnd.displayX + wnd.displayWidth,
    234          wnd.displayY + wnd.displayHeight) for wnd in windows ]
    235         neocom = sm.GetService('neocom').GetNeocomContainer()
    236         if neocom:
    237             l, t, w, h = neocom.GetAbsolute()
    238             ret.append((ScaleDpi(l),
    239              ScaleDpi(t),
    240              ScaleDpi(l + w),
    241              ScaleDpi(t + h)))
    242         return ret
    243 
    244     def GetCameraLeftOffset(self, width, align = None, left = 0, *args):
    245         offset = self.GetCameraOffsetSettingValue()
    246         if not offset:
    247             return 0
    248         if align in [uiconst.CENTER, uiconst.CENTERTOP, uiconst.CENTERBOTTOM]:
    249             camerapush = int(offset / 100.0 * uicore.desktop.width / 3.0)
    250             allowedOffset = int((uicore.desktop.width - width) / 2) - 10
    251             if camerapush < 0:
    252                 return max(camerapush, -allowedOffset - left)
    253             if camerapush > 0:
    254                 return min(camerapush, allowedOffset + left)
    255         return 0
    256 
    257     def GetCameraOffsetSettingValue(self):
    258         try:
    259             offsetUI = gfxsettings.Get(gfxsettings.UI_OFFSET_UI_WITH_CAMERA)
    260         except gfxsettings.UninitializedSettingsGroupError:
    261             offsetUI = False
    262 
    263         if not offsetUI:
    264             return 0
    265         else:
    266             return int(gfxsettings.Get(gfxsettings.UI_CAMERA_OFFSET))