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

controlButton.py (3677B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\dockedUI\controlButton.py
      2 import weakref
      3 import localization
      4 from carbon.common.script.sys.serviceManager import ServiceManager
      5 from carbonui.control.button import Button
      6 from eve.client.script.ui import eveColor
      7 from eve.client.script.ui.control import primaryButton
      8 from eve.client.script.ui.shared.dockedUI.inControlCont import ConfirmTakeControl
      9 
     10 class ControlButton(Button):
     11 
     12     def __init__(self, docked_ui_controller, **kwargs):
     13         self._controller = ControlButtonController(docked_ui_controller)
     14         self._docked_ui_controller = docked_ui_controller
     15         super(ControlButton, self).__init__(name='takeControlBtn', label=localization.GetByLabel('UI/Commands/TakeStructureControl'), func=self._execute, args=(), **kwargs)
     16         self._controller.connect(self)
     17 
     18     def Close(self):
     19         self._controller.close()
     20         super(ControlButton, self).Close()
     21 
     22     def LoadTooltipPanel(self, panel, owner):
     23         self._controller.load_tooltip_panel(panel, owner)
     24 
     25     def _execute(self):
     26         with self.busy_context:
     27             self._controller.execute()
     28 
     29 
     30 class ControlButtonController(object):
     31     _button_ref = None
     32 
     33     def __init__(self, docked_ui_controller):
     34         self._docked_ui_controller = docked_ui_controller
     35 
     36     def connect(self, button):
     37         self._button_ref = weakref.ref(button)
     38         self._update_enabled(button)
     39         ServiceManager.Instance().RegisterForNotifyEvent(self, 'OnDockingProgressChanged')
     40 
     41     def close(self):
     42         ServiceManager.Instance().UnregisterForNotifyEvent(self, 'OnDockingProgressChanged')
     43 
     44     def execute(self):
     45         pilot_id = self._docked_ui_controller.GetStructurePilot(self._get_structure_id())
     46         if pilot_id is not None:
     47             if pilot_id != session.charid:
     48                 confirm_override_control(self._docked_ui_controller)
     49         else:
     50             self._docked_ui_controller.TakeControl()
     51 
     52     def load_tooltip_panel(self, panel, owner):
     53         panel.LoadGeneric1ColumnTemplate()
     54         panel.AddLabelMedium(text=localization.GetByLabel('UI/Station/TakeControlHint'), wrapWidth=220)
     55         error_hint = None
     56         if not self._may_take_control():
     57             error_hint = localization.GetByLabel('UI/Station/MayNotTakeControlHint')
     58         elif self._is_undocking():
     59             error_hint = localization.GetByLabel('UI/Station/UndockingInProgressHint')
     60         if error_hint:
     61             panel.AddSpacer(height=8)
     62             panel.AddLabelMedium(text=error_hint, wrapWidth=220, color=eveColor.DANGER_RED)
     63 
     64     def _get_button(self):
     65         if self._button_ref is not None:
     66             return self._button_ref()
     67 
     68     def _get_structure_id(self):
     69         return self._docked_ui_controller.GetItemID()
     70 
     71     def _is_undocking(self):
     72         return self._docked_ui_controller.IsExiting() or self._docked_ui_controller.InProcessOfUndocking()
     73 
     74     def _may_take_control(self):
     75         return self._docked_ui_controller.MayTakeControl(self._get_structure_id())
     76 
     77     def _get_enabled(self):
     78         return self._may_take_control() and not self._is_undocking()
     79 
     80     def _update_enabled(self, button):
     81         button.enabled = self._get_enabled()
     82 
     83     def OnDockingProgressChanged(self, progress):
     84         button = self._get_button()
     85         if button:
     86             self._update_enabled(button)
     87 
     88 
     89 def confirm_override_control(docked_ui_controller):
     90     structure_id = docked_ui_controller.GetItemID()
     91     current_pilot_id = docked_ui_controller.GetStructurePilot(structure_id)
     92     ConfirmTakeControl.Open(controller=docked_ui_controller, charInControl=current_pilot_id)