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

leftSideButton.py (16179B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\shipHud\leftSideButton.py
      2 from carbon.client.script.environment.AudioUtil import PlaySound
      3 from carbonui import uiconst
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.sprite import Sprite
      6 from carbonui.primitives.transform import Transform
      7 from eve.client.script.environment.invControllers import ShipCargo
      8 from eve.client.script.ui import eveThemeColor
      9 from eve.client.script.ui.camera.cameraUtil import IsAutoTrackingEnabled
     10 from eve.client.script.ui.control import eveIcon
     11 from eve.client.script.ui.inflight.radialMenuScanner import RadialMenuScanner
     12 from eve.client.script.ui.view.viewStateConst import ViewState
     13 import evecamera
     14 from eveuniverse.solar_systems import is_tactical_camera_suppressed
     15 from localization import GetByLabel
     16 import uthread
     17 from eve.client.script.ui.shared.inventory.invWindow import Inventory
     18 import localization
     19 import trinity
     20 from carbonui.uicore import uicore
     21 from carbonui.loggers.buttonLogger import log_button_clicked
     22 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst
     23 BTN_SIZE = 36
     24 ICON_SIZE = 32
     25 
     26 class LeftSideButton(Container):
     27     default_texturePath = None
     28     default_state = uiconst.UI_NORMAL
     29     default_align = uiconst.TOPRIGHT
     30     default_width = BTN_SIZE
     31     default_height = BTN_SIZE
     32     cmdName = None
     33 
     34     def __init__(self, **kwargs):
     35         self.busy = None
     36         super(LeftSideButton, self).__init__(**kwargs)
     37 
     38     def ApplyAttributes(self, attributes):
     39         super(LeftSideButton, self).ApplyAttributes(attributes)
     40         texturePath = attributes.get('texturePath', self.default_texturePath)
     41         self.orgTop = None
     42         self.pickRadius = self.width / 2
     43         self.icon = eveIcon.Icon(parent=self, name='icon', pos=(0,
     44          0,
     45          ICON_SIZE,
     46          ICON_SIZE), align=uiconst.CENTER, state=uiconst.UI_DISABLED, icon=texturePath)
     47         self.transform = Transform(parent=self, name='icon', pos=(0,
     48          0,
     49          ICON_SIZE,
     50          ICON_SIZE), align=uiconst.CENTER, state=uiconst.UI_DISABLED)
     51         self.hilite = Sprite(parent=self, name='hilite', align=uiconst.TOALL, state=uiconst.UI_HIDDEN, texturePath='res:/UI/Texture/classes/ShipUI/utilBtnBaseAndShadow.png', color=(0.63, 0.63, 0.63, 1.0), blendMode=trinity.TR2_SBM_ADD)
     52         Sprite(parent=self, name='slot', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/utilBtnBaseAndShadow.png')
     53         self.busyContainer = Container(parent=self, name='busyContainer', align=uiconst.TOALL, clipChildren=True)
     54         self.busy = Sprite(parent=self.busyContainer, name='busy', align=uiconst.TOPLEFT, width=self.width, height=self.height, state=uiconst.UI_HIDDEN, texturePath='res:/UI/Texture/classes/ShipUI/utilBtnGlow.png', color=self._get_busy_color())
     55         self.blinkBG = Sprite(parent=self, name='blinkBG', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/utilBtnGlow.png', opacity=0.0, blendMode=trinity.TR2_SBM_ADD)
     56 
     57     def LoadTooltipPanel(self, tooltipPanel, *args):
     58         if self.cmdName:
     59             tooltipPanel.LoadGeneric2ColumnTemplate()
     60             cmd = uicore.cmd.commandMap.GetCommandByName(self.cmdName)
     61             commandTooltipResult = tooltipPanel.AddCommandTooltip(cmd)
     62             self.AddMoreToTooltipPanel(tooltipPanel)
     63             return commandTooltipResult
     64         return (None, None)
     65 
     66     def AddMoreToTooltipPanel(self, panel):
     67         pass
     68 
     69     def LoadIcon(self, iconPath):
     70         self.icon.LoadIcon(iconPath)
     71 
     72     def OnClick(self, *args):
     73         ui_name = getattr(self, 'uniqueUiName', None)
     74         if ui_name in (pConst.UNIQUE_NAME_CAMERA_ORBIT,
     75          pConst.UNIQUE_NAME_CAMERA_TACTICAL,
     76          pConst.UNIQUE_NAME_CAMERA_POV,
     77          pConst.UNIQUE_NAME_HUD_CARGO_BTN,
     78          pConst.UNIQUE_NAME_AUTOPILOT_BTN):
     79             self.analyticID = ui_name
     80             log_button_clicked(self)
     81         PlaySound(uiconst.SOUND_BUTTON_CLICK)
     82         sm.GetService('ui').StopBlink(self.icon)
     83 
     84     def OnMouseDown(self, btn, *args):
     85         if getattr(self, 'orgTop', None) is None:
     86             self.orgTop = self.top
     87         self.top = self.orgTop + 2
     88 
     89     def OnMouseUp(self, *args):
     90         if getattr(self, 'orgTop', None) is not None:
     91             self.top = self.orgTop
     92 
     93     def OnMouseEnter(self, *args):
     94         PlaySound(uiconst.SOUND_BUTTON_HOVER)
     95         self.hilite.state = uiconst.UI_DISABLED
     96 
     97     def OnMouseExit(self, *args):
     98         self.hilite.state = uiconst.UI_HIDDEN
     99         if getattr(self, 'orgTop', None) is not None:
    100             self.top = self.orgTop
    101 
    102     def Blink(self, loops = 3):
    103         uicore.animations.FadeTo(self.blinkBG, 0.0, 0.9, duration=0.15, loops=loops, callback=self._BlinkFadeOut)
    104 
    105     def _BlinkFadeOut(self):
    106         uicore.animations.FadeOut(self.blinkBG, duration=0.6)
    107 
    108     def Enable(self, *args):
    109         Container.Enable(self, *args)
    110         self.opacity = 1.0
    111 
    112     def Disable(self, *args):
    113         Container.Disable(self, *args)
    114         self.opacity = 0.3
    115 
    116     def SetInactive(self):
    117         self.busy.state = uiconst.UI_HIDDEN
    118 
    119     def SetActive(self):
    120         self.busy.state = uiconst.UI_DISABLED
    121 
    122     def OnColorThemeChanged(self):
    123         if self.busy is not None:
    124             self.busy.color = self._get_busy_color()
    125 
    126     @staticmethod
    127     def _get_busy_color():
    128         return tuple(eveThemeColor.THEME_FOCUS[:3]) + (0.6,)
    129 
    130 
    131 def ExpandRadialMenu(button, radialClass):
    132     if button.destroyed:
    133         return
    134     uicore.layer.menu.Flush()
    135     if not uicore.uilib.leftbtn:
    136         return
    137     radialMenu = radialClass(name='radialMenu', parent=uicore.layer.menu, state=uiconst.UI_HIDDEN, align=uiconst.TOPLEFT, anchorObject=button)
    138     uicore.layer.menu.radialMenu = radialMenu
    139     uicore.uilib.SetMouseCapture(radialMenu)
    140     radialMenu.state = uiconst.UI_NORMAL
    141 
    142 
    143 class LeftSideButtonStructureAmmoHold(LeftSideButton):
    144     default_name = 'inFlightStructureAmmoBtn'
    145     default_texturePath = 'res:/UI/Texture/icons/44_32_10.png'
    146     cmdName = 'OpenCargoHoldOfActiveShip'
    147     cmdDescription_override = 'Tooltips/Hud/CargoHoldStructure_description'
    148 
    149     def OnClick(self, *args):
    150         LeftSideButton.OnClick(self)
    151         Inventory.OpenOrShow(toggle=True)
    152 
    153     def OnDropData(self, dragObj, nodes):
    154         ShipCargo().OnDropData(nodes)
    155 
    156     def LoadTooltipPanel(self, tooltipPanel, *args):
    157         l, d = LeftSideButton.LoadTooltipPanel(self, tooltipPanel)
    158         if d:
    159             detailedDescription = GetByLabel(self.cmdDescription_override)
    160             d.text = detailedDescription
    161 
    162 
    163 class LeftSideButtonScanner(LeftSideButton):
    164     default_name = 'inFlightScannerBtn'
    165     uniqueUiName = pConst.UNIQUE_NAME_SCANNER_BTN
    166     default_texturePath = 'res:/UI/Texture/classes/SensorSuite/radar.png'
    167     label = 'UI/Generic/Scanner'
    168     cmdName = 'ToggleProbeScanner'
    169 
    170     def ApplyAttributes(self, attributes):
    171         LeftSideButton.ApplyAttributes(self, attributes)
    172         self.sweep = Sprite(parent=self.transform, align=uiconst.TOALL, texturePath='res:/UI/Texture/classes/SensorSuite/radar_sweep.png')
    173 
    174     def OnMouseDown(self, *args):
    175         uthread.new(ExpandRadialMenu, self, RadialMenuScanner)
    176 
    177     def OnClick(self, *args):
    178         LeftSideButton.OnClick(self)
    179 
    180     def LoadTooltipPanel(self, tooltipPanel, *args):
    181         tooltipPanel.LoadGeneric2ColumnTemplate()
    182         tooltipPanel.AddLabelShortcut(localization.GetByLabel('Tooltips/Hud/Scanners'), '')
    183         tooltipPanel.AddLabelMedium(text=localization.GetByLabel('Tooltips/Hud/Scanners_description'), wrapWidth=200, colSpan=tooltipPanel.columns, color=(0.6, 0.6, 0.6, 1))
    184 
    185 
    186 class LeftSideButtonTactical(LeftSideButton):
    187     default_name = 'inFlightTacticalBtn'
    188     uniqueUiName = pConst.UNIQUE_NAME_TACTICAL_BTN
    189     default_texturePath = 'res:/UI/Texture/Icons/44_32_42.png'
    190     label = 'UI/Generic/Tactical'
    191     cmdName = 'CmdToggleTacticalOverlay'
    192     __notifyevents__ = ['OnTacticalOverlayChange', 'OnActiveCameraChanged']
    193 
    194     def ApplyAttributes(self, attributes):
    195         LeftSideButton.ApplyAttributes(self, attributes)
    196         sm.RegisterNotify(self)
    197         self.UpdateButtonState()
    198 
    199     def OnClick(self, *args):
    200         LeftSideButton.OnClick(self)
    201         sm.GetService('tactical').ToggleOnOff()
    202 
    203     def OnActiveCameraChanged(self, cameraID):
    204         self.UpdateButtonState()
    205 
    206     def OnTacticalOverlayChange(self):
    207         self.UpdateButtonState()
    208 
    209     def UpdateButtonState(self):
    210         if sm.GetService('tactical').IsTacticalOverlayAllowed():
    211             self.Enable()
    212         else:
    213             self.Disable()
    214         isActive = sm.GetService('tactical').IsTacticalOverlayActive()
    215         if isActive:
    216             self.busy.state = uiconst.UI_DISABLED
    217             self.hint = localization.GetByLabel('UI/Inflight/HideTacticalOverview')
    218         else:
    219             self.busy.state = uiconst.UI_HIDDEN
    220             self.hint = localization.GetByLabel('UI/Inflight/ShowTacticalOverlay')
    221 
    222 
    223 class LeftSideButtonAutopilot(LeftSideButton):
    224     default_name = 'inFlightAutopilotBtn'
    225     uniqueUiName = pConst.UNIQUE_NAME_AUTOPILOT_BTN
    226     default_texturePath = 'res:/UI/Texture/Icons/44_32_12.png'
    227     label = 'UI/Generic/Autopilot'
    228     cmdName = 'CmdToggleAutopilot'
    229     __notifyevents__ = ['OnAutoPilotOn', 'OnAutoPilotOff']
    230 
    231     def ApplyAttributes(self, attributes):
    232         LeftSideButton.ApplyAttributes(self, attributes)
    233         sm.RegisterNotify(self)
    234         apActive = sm.GetService('autoPilot').GetState()
    235         if apActive:
    236             self.OnAutoPilotOn()
    237         else:
    238             self.OnAutoPilotOff()
    239 
    240     def OnClick(self, *args):
    241         LeftSideButton.OnClick(self)
    242         self.AutoPilotOnOff(not sm.GetService('autoPilot').GetState())
    243 
    244     def AutoPilotOnOff(self, onoff, *args):
    245         if onoff:
    246             sm.GetService('autoPilot').SetOn()
    247         else:
    248             sm.GetService('autoPilot').SetOff('toggled by shipUI')
    249 
    250     def OnAutoPilotOn(self):
    251         self.busy.state = uiconst.UI_DISABLED
    252         self.hint = localization.GetByLabel('UI/Inflight/DeactivateAutopilot')
    253         self.hint += self._GetShortcutForCommand(self.cmdName)
    254 
    255     def OnAutoPilotOff(self):
    256         self.busy.state = uiconst.UI_HIDDEN
    257         self.hint = localization.GetByLabel('UI/Inflight/ActivateAutopilot')
    258         self.hint += self._GetShortcutForCommand(self.cmdName)
    259 
    260     def _GetShortcutForCommand(self, cmdName):
    261         if cmdName:
    262             shortcut = uicore.cmd.GetShortcutStringByFuncName(cmdName)
    263             if shortcut:
    264                 return localization.GetByLabel('UI/Inflight/ShortcutFormatter', shortcut=shortcut)
    265         return ''
    266 
    267 
    268 class LeftSideButtonZoomIn(LeftSideButton):
    269     default_name = 'inFlightZoomInBtn'
    270     default_texturePath = 'res:/UI/Texture/Icons/44_32_43.png'
    271     label = 'UI/Inflight/ZoomIn'
    272     cmdName = 'CmdZoomIn'
    273 
    274     def OnClick(self, *args):
    275         LeftSideButton.OnClick(self)
    276         uicore.cmd.GetCommandAndExecute('CmdZoomIn')
    277 
    278 
    279 class LeftSideButtonZoomOut(LeftSideButton):
    280     default_name = 'inFlightZoomOutBtn'
    281     default_texturePath = 'res:/UI/Texture/Icons/44_32_44.png'
    282     label = 'UI/Inflight/ZoomOut'
    283     cmdName = 'CmdZoomOut'
    284 
    285     def OnClick(self, *args):
    286         LeftSideButton.OnClick(self)
    287         uicore.cmd.GetCommandAndExecute('CmdZoomOut')
    288 
    289 
    290 class LeftSideButtonCameraBase(LeftSideButton):
    291     __notifyevents__ = ['OnActiveCameraChanged']
    292 
    293     def ApplyAttributes(self, attributes):
    294         LeftSideButton.ApplyAttributes(self, attributes)
    295         sm.RegisterNotify(self)
    296         self.UpdateButtonState()
    297 
    298     def OnActiveCameraChanged(self, cameraID):
    299         self.UpdateButtonState()
    300 
    301     def UpdateButtonState(self):
    302         activeCamera = sm.GetService('sceneManager').GetActivePrimaryCamera()
    303         if activeCamera.IsLocked():
    304             self.Disable()
    305         else:
    306             self.Enable()
    307         if self.IsActive():
    308             self.SetActive()
    309         else:
    310             self.SetInactive()
    311 
    312     def IsActive(self):
    313         cameraID = sm.GetService('viewState').GetView(ViewState.Space).GetRegisteredCameraID()
    314         return cameraID == self.cameraID
    315 
    316 
    317 class LeftSideButtonCameraPOV(LeftSideButtonCameraBase):
    318     default_name = 'cameraButtonPOV'
    319     uniqueUiName = pConst.UNIQUE_NAME_CAMERA_POV
    320     default_texturePath = 'res:/UI/Texture/classes/ShipUI/iconCameraFirstPerson.png'
    321     cmdName = 'CmdSetCameraPOV'
    322     cameraID = evecamera.CAM_SHIPPOV
    323 
    324     def OnClick(self, *args):
    325         LeftSideButton.OnClick(self)
    326         uicore.cmd.GetCommandAndExecute('CmdSetCameraPOV')
    327 
    328     def LoadTooltipPanel(self, tooltipPanel, *args):
    329         LeftSideButtonCameraBase.LoadTooltipPanel(self, tooltipPanel, *args)
    330         tooltipPanel.AddSpacer(width=0, height=5)
    331         for cmdName in ('CmdFlightControlsUp', 'CmdFlightControlsDown', 'CmdFlightControlsLeft', 'CmdFlightControlsRight'):
    332             cmd = uicore.cmd.commandMap.GetCommandByName(cmdName)
    333             tooltipPanel.AddCommandTooltip(cmd)
    334             tooltipPanel.AddSpacer(width=0, height=1)
    335 
    336 
    337 class LeftSideButtonCameraOrbit(LeftSideButtonCameraBase):
    338     default_name = 'cameraButtonOrbit'
    339     uniqueUiName = pConst.UNIQUE_NAME_CAMERA_ORBIT
    340     default_texturePath = 'res:/UI/Texture/classes/ShipUI/iconCameraOrbit.png'
    341     cmdName = 'CmdSetCameraOrbit'
    342     cameraID = evecamera.CAM_SHIPORBIT
    343 
    344     def ApplyAttributes(self, attributes):
    345         LeftSideButtonCameraBase.ApplyAttributes(self, attributes)
    346         self.UpdateIcon()
    347         settings.char.Subscribe('ui', 'orbitCameraAutoTracking', self.OnAutoTrackingChanged)
    348 
    349     def Close(self):
    350         super(LeftSideButtonCameraOrbit, self).Close()
    351         settings.char.Unsubscribe('ui', 'orbitCameraAutoTracking', self.OnAutoTrackingChanged)
    352 
    353     def UpdateIcon(self):
    354         if IsAutoTrackingEnabled():
    355             self.LoadIcon('res:/UI/Texture/classes/ShipUI/iconCameraTracking.png')
    356         else:
    357             self.LoadIcon('res:/UI/Texture/classes/ShipUI/iconCameraOrbit.png')
    358 
    359     def OnClick(self, *args):
    360         LeftSideButton.OnClick(self)
    361         uicore.cmd.GetCommandAndExecute('CmdSetCameraOrbit')
    362 
    363     def LoadTooltipPanel(self, tooltipPanel, *args):
    364         LeftSideButtonCameraBase.LoadTooltipPanel(self, tooltipPanel, *args)
    365         tooltipPanel.AddSpacer(width=0, height=5)
    366         tooltipPanel.AddLabelShortcut(GetByLabel('Tooltips/Hud/FOVZoom'), GetByLabel('Tooltips/Hud/AltPlusZoom'))
    367         cmd = uicore.cmd.commandMap.GetCommandByName('CmdToggleAutoTracking')
    368         tooltipPanel.AddSpacer(width=0, height=1)
    369         tooltipPanel.AddCommandTooltip(cmd)
    370 
    371     def OnAutoTrackingChanged(self):
    372         self.UpdateIcon()
    373         self.Blink(3)
    374 
    375     def GetMenu(self):
    376         return [(GetByLabel('UI/Commands/CmdToggleAutoTracking'), uicore.cmd.GetCommandToExecute('CmdToggleAutoTracking'))]
    377 
    378     def IsActive(self):
    379         cameraID = sm.GetService('viewState').GetView(ViewState.Space).GetRegisteredCameraID()
    380         return cameraID in (evecamera.CAM_SHIPORBIT,
    381          evecamera.CAM_SHIPORBIT_ABYSSAL_SPACE,
    382          evecamera.CAM_SHIPORBIT_HAZARD,
    383          evecamera.CAM_SHIPORBIT_RESTRICTED)
    384 
    385 
    386 class LeftSideButtonCameraTactical(LeftSideButtonCameraBase):
    387     default_name = 'cameraButtonTactical'
    388     uniqueUiName = pConst.UNIQUE_NAME_CAMERA_TACTICAL
    389     default_texturePath = 'res:/UI/Texture/classes/ShipUI/iconCameraGrid.png'
    390     cmdName = 'CmdSetCameraTactical'
    391     cameraID = evecamera.CAM_TACTICAL
    392 
    393     def ApplyAttributes(self, attributes):
    394         LeftSideButton.ApplyAttributes(self, attributes)
    395         if is_tactical_camera_suppressed(session.solarsystemid2):
    396             self.Disable()
    397         sm.RegisterNotify(self)
    398         self.UpdateButtonState()
    399 
    400     def OnClick(self, *args):
    401         LeftSideButton.OnClick(self)
    402         uicore.cmd.GetCommandAndExecute('CmdSetCameraTactical')
    403 
    404     def LoadTooltipPanel(self, tooltipPanel, *args):
    405         LeftSideButtonCameraBase.LoadTooltipPanel(self, tooltipPanel, *args)
    406         tooltipPanel.AddSpacer(width=0, height=5)
    407         tooltipPanel.AddLabelShortcut(GetByLabel('Tooltips/Hud/Pan'), GetByLabel('Tooltips/Hud/RightMouse'))