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

lobbyWnd.py (18087B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\dockedUI\lobbyWnd.py
      2 import math
      3 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst
      4 import eve.client.script.ui.shared.systemMenu.settingCheckers as settingCheckers
      5 import uthread
      6 from carbonui import ButtonFrameType, uiconst
      7 from carbonui.control.window import Window
      8 from clientsettings.setting import CharSettingBool
      9 from carbonui.util.dpi import reverse_scale_dpi
     10 from carbonui.window.settings import RegisterState
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     13 from carbonui.primitives.flowcontainer import FlowContainer
     14 from carbonui.uicore import uicore
     15 from carbonui.control.tabGroup import TabGroup
     16 from eve.client.script.ui.menuUtil import SHOWINFOGROUP
     17 from eve.client.script.ui.shared.dockedUI.inventory import InventoryPanel
     18 from eve.common.lib import appConst as const
     19 from eve.client.script.ui.control.eveIcon import CheckCorpID, GetLogoIcon
     20 from eve.client.script.ui.control.eveLabel import Label
     21 from eve.client.script.ui.shared.dockedUI import ReloadLobbyWnd, controlButton, corvetteButton, modeButton, undockButton
     22 from eve.client.script.ui.shared.dockedUI.agents import AgentsPanel
     23 from eve.client.script.ui.shared.dockedUI.guests import GuestsPanel, GuestsPanelController
     24 from eve.client.script.ui.shared.dockedUI.inControlCont import ConfirmTakeControl
     25 from eve.client.script.ui.shared.dockedUI.offices import OfficesPanel
     26 from eve.client.script.ui.shared.dockedUI.serviceBtn import StationServiceBtn
     27 from eve.client.script.ui.station import stationServiceConst
     28 from localization import GetByLabel
     29 from uihider import UiHiderMixin
     30 BIGBUTTONSIZE = 48
     31 SMALLBUTTONSIZE = 32
     32 BUTTONGAP = 4
     33 DOCKING_BUTTONS_HEIGHT = 40
     34 DOCKING_BUTTONS_WIDTH = 160
     35 AGENTSPANEL = 'agentsPanel'
     36 GUESTSPANEL = 'guestsPanel'
     37 OFFICESPANEL = 'officesPanel'
     38 INVENTORYPANEL = 'inventoryPanel'
     39 show_hangars_tab_setting = CharSettingBool(settings_key='lobby_window_show_items_tab', default_value=lambda : bool(settings.char.windows.Get('dockshipsanditems', True)))
     40 
     41 class LobbyWnd(UiHiderMixin, Window):
     42     __guid__ = 'form.LobbyWnd'
     43     __notifyevents__ = ['OnSetDevice', 'OnStructureServiceUpdated']
     44     default_windowID = 'lobbyWnd'
     45     uniqueUiName = pConst.UNIQUE_NAME_LOBBY_WND
     46     default_top = 16
     47     default_width = 280
     48     default_minSize = (270, 495)
     49     default_captionLabelPath = 'UI/Station/StationServices'
     50     default_isLightBackground = True
     51     default_scope = uiconst.SCOPE_DOCKED
     52     hasWindowIcon = False
     53     selectedGroupButtonID = None
     54     _agents_panel = None
     55     _guests_panel = None
     56     _guests_panel_controller = None
     57     _inventory_panel = None
     58     _offices_panel = None
     59     _tabs = None
     60 
     61     @staticmethod
     62     def default_height(*args):
     63         return uicore.desktop.height - 160
     64 
     65     @staticmethod
     66     def default_left(*args):
     67         return uicore.desktop.width - LobbyWnd.default_width - 16
     68 
     69     def __init__(self, **kwargs):
     70         RegisterState(self.default_windowID, 'compact', False)
     71         super(LobbyWnd, self).__init__(**kwargs)
     72         show_hangars_tab_setting.on_change.connect(self._on_show_hangars_tab_setting_changed)
     73 
     74     def OnSetDevice(self):
     75         bottom = self.top + self.height
     76         if bottom > uicore.desktop.height:
     77             self.height = max(self.default_minSize[1], uicore.desktop.height - self.top)
     78         right = self.left + self.width
     79         if right > uicore.desktop.width:
     80             self.width = max(self.default_minSize[0], uicore.desktop.width - self.left)
     81 
     82     def ApplyAttributes(self, attributes):
     83         self.viewState = sm.GetService('viewState')
     84         super(LobbyWnd, self).ApplyAttributes(attributes)
     85         self.controller = attributes.controller
     86         self.MakeUnKillable()
     87         self.MakeUnstackable()
     88         self.BuildTopSection()
     89         self._AddStationServices()
     90         self._AddPanelToggleBtnCont()
     91         self._AddGuestPanel()
     92         self._AddAgentPanel()
     93         self._AddOfficePanel()
     94         activePanel = settings.user.ui.Get('stationsLobbyTabs', AGENTSPANEL)
     95         if show_hangars_tab_setting.is_enabled():
     96             self._AddInventoryPanel()
     97         elif activePanel == INVENTORYPANEL:
     98             activePanel = AGENTSPANEL
     99         self._tabs.SelectByID(activePanel)
    100         self.LoadOwnerInfo()
    101         self.LoadServiceButtons()
    102         if self.destroyed:
    103             return
    104         sm.RegisterNotify(self)
    105 
    106     def Prepare_Header_(self):
    107         super(LobbyWnd, self).Prepare_Header_()
    108         self.header.show_caption = False
    109 
    110     def BuildTopSection(self):
    111         self.corpLogoParent = Container(name='corpLogoParent', parent=self.content, align=uiconst.TOTOP, height=160)
    112         self.corpName = Label(name='corpName', parent=self.content, align=uiconst.TOTOP, top=8, fontsize=18)
    113         StationButtonGrid(parent=self.content, align=uiconst.TOTOP, padTop=16, station_controller=self.controller, view_state_service=self.viewState)
    114 
    115     def _AddStationServices(self):
    116         padTop = 8
    117         self.corvetteButtonParent = ContainerAutoSize(parent=self.content, align=uiconst.TOTOP, padTop=16)
    118         self.serviceButtons = FlowContainer(name='serviceButtons', parent=self.content, align=uiconst.TOTOP, centerContent=True, contentSpacing=(BUTTONGAP, BUTTONGAP), padding=(24, 16, 24, 0), idx=2)
    119 
    120     def _on_guests_panel_guest_count_changed(self, controller):
    121         if self.destroyed:
    122             self._guests_panel_controller.on_guest_count_changed.disconnect(self._on_guests_panel_guest_count_changed)
    123         else:
    124             self.UpdateGuestTabText()
    125 
    126     def _AddGuestPanel(self):
    127         self._guests_panel_controller = GuestsPanelController()
    128         self._guests_panel = GuestsPanel(parent=self.panelsCont, align=uiconst.TOALL, padding=(0, 8, 0, 0), controller=self._guests_panel_controller)
    129         self._guests_panel.display = False
    130         self._tabs.AddTab(tabID=GUESTSPANEL, panel=self._guests_panel, label=GetByLabel('UI/Station/Lobby/Guests'), hint=GetByLabel('Tooltips/StationServices/GuestsTab_description'), uniqueName=pConst.UNIQUE_NAME_GUESTS_TAB)
    131         self._guests_panel_controller.on_guest_count_changed.connect(self._on_guests_panel_guest_count_changed)
    132         uthread.new(self._guests_panel_controller.load)
    133 
    134     def _AddAgentPanel(self):
    135         self._agents_panel = AgentsPanel(name=AGENTSPANEL, parent=self.panelsCont, align=uiconst.TOALL, padding=(0, 8, 0, 0))
    136         self._agents_panel.display = False
    137         tab = self._tabs.AddTab(tabID=AGENTSPANEL, panel=self._agents_panel, label=GetByLabel('UI/Station/Lobby/Agents'), hint=GetByLabel('Tooltips/StationServices/AgentsTab_descrtiption'))
    138         tab.name = 'stationInformationTabAgents'
    139         tab.uniqueUiName = pConst.UNIQUE_NAME_AGENTS_TAB
    140 
    141     def _AddPanelToggleBtnCont(self):
    142         self._tabs = TabGroup(parent=self.content, align=uiconst.TOTOP, padding=(0, 16, 0, 0), callback=self._on_tab_selected)
    143         self.panelsCont = Container(name='panelsCont', parent=self.content)
    144 
    145     def _on_tab_selected(self, tab_id, old_tab_id):
    146         if tab_id is not None:
    147             settings.user.ui.Set('stationsLobbyTabs', tab_id)
    148 
    149     def _AddOfficePanel(self):
    150         self._offices_panel = OfficesPanel(parent=self.panelsCont, align=uiconst.TOALL, padding=(0, 8, 0, 0), station_controller=self.controller)
    151         tab = self._tabs.AddTab(tabID=OFFICESPANEL, panel=self._offices_panel, label=GetByLabel('UI/Station/Lobby/Offices'), hint=GetByLabel('Tooltips/StationServices/OfficesTab_description'))
    152         tab.uniqueUiName = pConst.UNIQUE_NAME_OFFICES_TAB
    153 
    154     def _AddInventoryPanel(self):
    155         self._inventory_panel = InventoryPanel(parent=self.panelsCont, station_controller=self.controller)
    156         tab = self._tabs.AddTab(tabID=INVENTORYPANEL, panel=self._inventory_panel, label=GetByLabel('UI/Station/Lobby/Hangars'), hint='<b>%s</b><br>%s' % (GetByLabel('Tooltips/StationServices/Hangars'), GetByLabel('Tooltips/StationServices/Hangars_description')))
    157         tab.name = 'Button_InventoryPanel'
    158         tab.uniqueUiName = pConst.UNIQUE_NAME_HANGARS_TAB
    159 
    160     def LoadOwnerInfo(self):
    161         parent = self.corpLogoParent
    162         parent.Flush()
    163         corpID = self.controller.GetOwnerID()
    164         size = 128 if CheckCorpID(corpID) else 64
    165         logo = GetLogoIcon(parent=parent, align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, itemID=corpID, acceptNone=False, pos=(0,
    166          0,
    167          size,
    168          size))
    169         parent.height = logo.top + logo.height
    170         if CheckCorpID(corpID):
    171             self.corpName.display = False
    172         else:
    173             self.corpName.text = '<center>' + cfg.eveowners.Get(corpID).name
    174             self.corpName.display = True
    175 
    176     def GetServiceBtnSize(self):
    177         return SMALLBUTTONSIZE
    178 
    179     def LoadServiceButtons(self):
    180         parent = self.serviceButtons
    181         parent.Flush()
    182         corvetteButton.CorvetteButton(parent=self.corvetteButtonParent, align=uiconst.CENTER)
    183         haveServices = self.GetCurrentStationServices()
    184         btnsize = self.GetServiceBtnSize()
    185         for serviceInfo in reversed(haveServices):
    186             button = StationServiceBtn(name=serviceInfo.name, uniqueUiName=pConst.GetUniqueStationServiceName(serviceInfo.name), parent=parent, align=uiconst.NOALIGN, serviceInfo=serviceInfo, iconSize=btnsize, func=lambda name = serviceInfo.name: self.OnSvcBtnClick(name), args=())
    187             self.SetServiceButtonState(button, serviceInfo.serviceID)
    188 
    189     def ReloadServiceButtons(self):
    190         self.controller.GetServices()
    191         for button in self.serviceButtons.children:
    192             try:
    193                 serviceID = button.serviceID
    194             except AttributeError:
    195                 continue
    196 
    197             self.SetServiceButtonState(button, serviceID)
    198 
    199     def SetServiceButtonState(self, button, serviceID):
    200         currentstate = self.controller.GetCurrentStateForService(serviceID)
    201         if currentstate is None:
    202             return
    203         self.controller.RemoveServiceFromCache(serviceID)
    204         button.UpdateState(currentstate.isEnabled)
    205 
    206     def OnSvcBtnClick(self, serviceName):
    207         self.CheckCanAccessService(serviceName)
    208         sm.GetService('station').LoadSvc(serviceName)
    209 
    210     def CheckCanAccessService(self, serviceName):
    211         return CheckCanAccessService(self.controller, serviceName)
    212 
    213     def GetCurrentStationServices(self):
    214         return self.controller.GetServices()
    215 
    216     def OnButtonGroupSelection(self, buttonID, *args):
    217         settings.user.ui.Set('stationsLobbyTabs', buttonID)
    218         self.selectedGroupButtonID = buttonID
    219         functionByButton = {AGENTSPANEL: self.ShowAgents,
    220          GUESTSPANEL: self.ShowGuests,
    221          OFFICESPANEL: self.ShowOffices,
    222          INVENTORYPANEL: self.ShowHangars}
    223         if buttonID in functionByButton:
    224             functionByButton[buttonID]()
    225 
    226     def AddControlButton(self):
    227         if not self.controller.IsControlable():
    228             return
    229         control_button_controller = controlButton.Controller(docked_ui_controller=self.controller, confirm_override_control=confirm_override_control)
    230         controlButton.ControlButton(parent=self.undockparent, align=uiconst.NOALIGN, controller=control_button_controller, fixedheight=DOCKING_BUTTONS_HEIGHT, fixedwidth=DOCKING_BUTTONS_WIDTH, frame_type=ButtonFrameType.RECTANGLE)
    231 
    232     def AddDockedModeButton(self):
    233         if not self.controller.HasDockModes():
    234             return
    235         mode_button_controller = modeButton.Controller(docked_ui_controller=self.controller, view_state_service=self.viewState)
    236         modeButton.ModeButton(parent=self.undockparent, align=uiconst.NOALIGN, controller=mode_button_controller, fixedheight=DOCKING_BUTTONS_HEIGHT, fixedwidth=DOCKING_BUTTONS_WIDTH, frame_type=ButtonFrameType.RECTANGLE)
    237 
    238     def AddUndockButton(self):
    239         undock_button_controller = undockButton.Controller(docked_ui_controller=self.controller)
    240         undockButton.UndockButton(parent=self.undockparent, align=uiconst.NOALIGN, uniqueUiName=pConst.UNIQUE_NAME_UNDOCK_BTN, controller=undock_button_controller, fixedheight=DOCKING_BUTTONS_HEIGHT, fixedwidth=DOCKING_BUTTONS_WIDTH, frame_type=ButtonFrameType.CUT_BOTTOM_LEFT_RIGHT)
    241 
    242     def UpdateGuestTabText(self):
    243         self._tabs.GetTabByID(GUESTSPANEL).SetLabel(u'{tab_name} [{count}]'.format(tab_name=GetByLabel('UI/Station/Lobby/Guests'), count=self._guests_panel_controller.guest_count))
    244 
    245     def ShowOffices(self):
    246         self._offices_panel.LoadPanel()
    247 
    248     def ShowHangars(self):
    249         self._inventory_panel.LoadPanel()
    250 
    251     def ShowAgents(self):
    252         self._agents_panel.LoadPanel()
    253 
    254     def ShowGuests(self, *args):
    255         self._guests_panel.LoadPanel()
    256 
    257     def OnStructureServiceUpdated(self):
    258         self.ReloadServiceButtons()
    259 
    260     def StopAllBlinkButtons(self):
    261         for each in self.serviceButtons.children:
    262             if hasattr(each, 'Blink'):
    263                 each.Blink(0)
    264 
    265     def BlinkButton(self, whatBtn):
    266         for each in self.serviceButtons.children:
    267             if each.name.lower() == whatBtn.lower():
    268                 each.Blink(blinks=40)
    269 
    270     def GetMenuMoreOptions(self):
    271         menu = super(LobbyWnd, self).GetMenuMoreOptions()
    272         menu.AddEntry(text=GetByLabel('UI/Station/Lobby/CorpShowInfoButton'), func=self._show_owner_info, menuGroupID=SHOWINFOGROUP)
    273         menu.AddSeparator()
    274         menu.AddCheckbox(text=GetByLabel('UI/Station/Lobby/ShowHangarsTab'), setting=show_hangars_tab_setting)
    275         return menu
    276 
    277     def _show_owner_info(self):
    278         sm.GetService('info').ShowInfo(typeID=const.typeCorporation, itemID=self.controller.GetOwnerID())
    279 
    280     @staticmethod
    281     def _on_show_hangars_tab_setting_changed(value):
    282         ReloadLobbyWnd()
    283 
    284 
    285 def is_small_buttons_enabled():
    286     return settingCheckers.get_small_station_buttons_setting()
    287 
    288 
    289 def CheckCanAccessService(stationController, serviceName):
    290     serviceData = stationServiceConst.serviceDataByNameID.get(serviceName)
    291     if serviceData is None:
    292         return
    293     for stationServiceID in serviceData.stationServiceIDs:
    294         result = stationController.PerformAndGetErrorForStandingCheck(stationServiceID)
    295         if result is not None:
    296             raise result
    297 
    298 
    299 def confirm_override_control(docked_ui_controller):
    300     structure_id = docked_ui_controller.GetItemID()
    301     current_pilot_id = docked_ui_controller.GetStructurePilot(structure_id)
    302     ConfirmTakeControl.Open(controller=docked_ui_controller, charInControl=current_pilot_id)
    303 
    304 
    305 class StationButtonGrid(ContainerAutoSize):
    306     GAP_SIZE = 8
    307     _undock_button = None
    308     _mode_button = None
    309     _control_button = None
    310 
    311     def __init__(self, station_controller, view_state_service, **kwargs):
    312         self._controller = station_controller
    313         self._view_state_service = view_state_service
    314         super(StationButtonGrid, self).__init__(alignMode=uiconst.TOPLEFT, **kwargs)
    315         self._load()
    316 
    317     def _load(self):
    318         if self._controller.IsControlable():
    319             self._create_control_button()
    320         if self._controller.HasDockModes():
    321             self._create_mode_button()
    322         self._create_undock_button()
    323 
    324     def _create_control_button(self):
    325         self._control_button = controlButton.ControlButton(parent=self, align=uiconst.TOPLEFT, docked_ui_controller=self._controller, frame_type=ButtonFrameType.RECTANGLE)
    326 
    327     def _create_mode_button(self):
    328         self._mode_button = modeButton.ModeButton(parent=self, align=uiconst.TOPLEFT, docked_ui_controller=self._controller, view_state_service=self._view_state_service, frame_type=ButtonFrameType.RECTANGLE)
    329 
    330     def _create_undock_button(self):
    331         self._undock_button = undockButton.UndockButton(parent=self, align=uiconst.TOPLEFT, docked_ui_controller=self._controller, frame_type=ButtonFrameType.CUT_BOTTOM_LEFT_RIGHT)
    332 
    333     def _update_button_alignment(self, budget_width):
    334         undock_button_top = 0
    335         if self._control_button and self._mode_button:
    336             control_button_width = self._control_button.get_intrinsic_width()
    337             mode_button_width = self._mode_button.get_intrinsic_width()
    338             total_width = control_button_width + self.GAP_SIZE + mode_button_width
    339             if total_width > budget_width:
    340                 self._control_button.left = 0
    341                 self._control_button.top = 0
    342                 self._control_button.width = budget_width
    343                 self._mode_button.left = 0
    344                 self._mode_button.top = self._control_button.height + self.GAP_SIZE
    345                 self._mode_button.width = budget_width
    346             else:
    347                 self._control_button.left = 0
    348                 self._control_button.top = 0
    349                 self._control_button.width = int(math.ceil((budget_width - self.GAP_SIZE) / 2.0))
    350                 self._mode_button.left = self._control_button.width + self.GAP_SIZE
    351                 self._mode_button.top = 0
    352                 self._mode_button.width = budget_width - self._control_button.width - self.GAP_SIZE
    353             undock_button_top = self._mode_button.top + self._mode_button.height + self.GAP_SIZE
    354         elif self._control_button:
    355             self._control_button.left = 0
    356             self._control_button.top = 0
    357             self._control_button.width = budget_width
    358             undock_button_top = self._control_button.height + self.GAP_SIZE
    359         elif self._mode_button:
    360             self._mode_button.left = 0
    361             self._mode_button.top = 0
    362             self._mode_button.width = budget_width
    363             undock_button_top = self._mode_button.height + self.GAP_SIZE
    364         self._undock_button.top = undock_button_top
    365         self._undock_button.width = budget_width
    366 
    367     def UpdateAlignment(self, budgetLeft = 0, budgetTop = 0, budgetWidth = 0, budgetHeight = 0, updateChildrenOnly = False):
    368         budget_width = reverse_scale_dpi(budgetWidth)
    369         self._update_button_alignment(budget_width)
    370         return super(StationButtonGrid, self).UpdateAlignment(budgetLeft, budgetTop, budgetWidth, budgetHeight, updateChildrenOnly)