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

menuAction.py (7402B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\menuAction.py
      2 import sys
      3 import types
      4 import uthread
      5 import localization
      6 import log
      7 from carbon.client.script.environment.AudioUtil import PlaySound
      8 from carbon.common.script.util.format import FmtDist
      9 from carbonui import uiconst
     10 from carbonui.control.contextMenu.menuUtil import ClearMenuLayer
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.fill import Fill
     13 from carbonui.uicore import uicore
     14 from eve.client.script.ui.control.glowSprite import GlowSprite
     15 from player_messaging.client.ui_message import message_player
     16 from eve.client.script.ui.crimewatch import crimewatchConst
     17 from eve.client.script.ui.inflight.selectedItemConst import CLOSE_MENU_ACTIONS
     18 from eve.client.script.ui.services.menuSvcExtras.movementFunctions import SetDefaultDist, GetGlobalActiveItemKeyName
     19 from eveservices.menu import GetMenuService
     20 from menu import MenuLabel, CaptionIsInMultiFunctions
     21 
     22 class Action(Container):
     23     default_state = uiconst.UI_NORMAL
     24 
     25     def ApplyAttributes(self, attributes):
     26         Container.ApplyAttributes(self, attributes)
     27         self.actionID = None
     28         self.disabled = attributes.get('disabled', False)
     29         self.Prepare_(icon=attributes.icon)
     30 
     31     def Prepare_(self, icon = None):
     32         opacity = 0.2 if self.disabled else 1.0
     33         self.icon = GlowSprite(parent=self, align=uiconst.TOALL, texturePath=icon, state=uiconst.UI_DISABLED, opacity=opacity, iconOpacity=1.0)
     34         self.sr.fill = Fill(parent=self, state=uiconst.UI_HIDDEN)
     35 
     36     def LoadTooltipPanel(self, tooltipPanel, *args):
     37         tooltipPanel.LoadGeneric2ColumnTemplate()
     38         shortcutString = None
     39         reasonString = None
     40         distString = None
     41         keywords = {}
     42         if isinstance(self.action[1], basestring):
     43             reasonString = self.action[1]
     44             if self.actionID in ('UI/Inflight/WarpToWithinDistance', 'UI/Inflight/WarpToMoonMiningPoint'):
     45                 defaultWarpDist = GetMenuService().GetDefaultActionDistance('WarpTo')
     46                 keywords['distance'] = FmtDist(float(defaultWarpDist))
     47         else:
     48             if isinstance(self.action[0], MenuLabel):
     49                 actionNamePath, keywords = self.action[0]
     50             if self.actionID in ('UI/Inflight/OrbitObject', 'UI/Inflight/Submenus/KeepAtRange'):
     51                 key = GetGlobalActiveItemKeyName(actionNamePath)
     52                 current = GetMenuService().GetDefaultActionDistance(key)
     53                 if current is not None:
     54                     distString = FmtDist(current)
     55                 else:
     56                     distString = localization.GetByLabel('UI/Menusvc/MenuHints/NoDistanceSet')
     57         if hasattr(self, 'cmdName'):
     58             shortcutString = uicore.cmd.GetShortcutStringByFuncName(self.cmdName)
     59         actionName = localization.GetByLabel(self.actionID, **keywords)
     60         if distString:
     61             hint = localization.GetByLabel('UI/Menusvc/MenuHints/SelectedItemActionWithDist', actionName=actionName, distanceString=distString)
     62         else:
     63             hint = actionName
     64         tooltipPanel.AddLabelShortcut(hint, shortcutString)
     65         if reasonString:
     66             tooltipPanel.AddLabelMedium(text=reasonString, colSpan=tooltipPanel.columns)
     67 
     68     def GetTooltipPointer(self):
     69         return uiconst.POINT_TOP_2
     70 
     71     def GetMenu(self):
     72         m = []
     73         label = ''
     74         key = GetGlobalActiveItemKeyName(self.actionID)
     75         if key == 'Orbit':
     76             label = MenuLabel('UI/Inflight/SetDefaultOrbitDistance', {'typeName': self.actionID})
     77         elif key == 'KeepAtRange':
     78             label = MenuLabel('UI/Inflight/SetDefaultKeepAtRangeDistance', {'typeName': self.actionID})
     79         elif key == 'WarpTo':
     80             label = MenuLabel('UI/Inflight/SetDefaultWarpWithinDistance', {'typeName': self.actionID})
     81         if len(label) > 0:
     82             m.append((label, SetDefaultDist, (key,)))
     83         return m
     84 
     85     def OnMouseEnter(self, *args):
     86         if self.disabled:
     87             return
     88         PlaySound(uiconst.SOUND_BUTTON_HOVER)
     89         if self.sr.Get('fill', None):
     90             if hasattr(self, 'action'):
     91                 if 'EngageTarget' in self.action[0][0]:
     92                     crimewatchSvc = sm.GetService('crimewatchSvc')
     93                     droneInfo = self.action[2]
     94                     if len(self.itemIDs) > 1 and len(droneInfo) > 1 and isinstance(droneInfo[0], (types.MethodType, types.LambdaType, types.FunctionType)):
     95                         droneIDs = droneInfo[1]
     96                     else:
     97                         droneIDs = droneInfo
     98                     targetID = sm.GetService('target').GetActiveTargetID()
     99                     requiredSafetyLevel = crimewatchSvc.GetRequiredSafetyLevelForEngagingDrones(droneIDs, targetID)
    100                     if crimewatchSvc.CheckUnsafe(requiredSafetyLevel):
    101                         if requiredSafetyLevel == const.shipSafetyLevelNone:
    102                             color = crimewatchConst.Colors.Criminal.GetRGBA()
    103                         else:
    104                             color = crimewatchConst.Colors.Suspect.GetRGBA()
    105                         self.sr.fill.SetRGBA(*color[:3])
    106             self.sr.fill.state = uiconst.UI_DISABLED
    107             self.sr.fill.opacity = 0.25
    108             uicore.animations.MorphScalar(self.icon, 'glowAmount', self.icon.glowAmount, 1.0, duration=uiconst.TIME_ENTRY)
    109 
    110     def OnMouseExit(self, *args):
    111         if self.sr.Get('fill', None):
    112             self.sr.fill.SetRGBA(1, 1, 1, 1)
    113             self.sr.fill.state = uiconst.UI_HIDDEN
    114             uicore.animations.MorphScalar(self.icon, 'glowAmount', self.icon.glowAmount, 0.0, duration=uiconst.TIME_ENTRY)
    115 
    116     def OnMouseDown(self, *args):
    117         if self.sr.Get('fill', None):
    118             self.sr.fill.opacity = 0.5
    119             uicore.animations.MorphScalar(self.icon, 'glowAmount', self.icon.glowAmount, 1.3, duration=uiconst.TIME_ENTRY)
    120 
    121     def OnMouseUp(self, *args):
    122         if self.sr.Get('fill', None):
    123             self.sr.fill.opacity = 0.25
    124             uicore.animations.MorphScalar(self.icon, 'glowAmount', self.icon.glowAmount, 1.0, duration=uiconst.TIME_ENTRY)
    125 
    126     def OnClick(self, *args):
    127         sm.StartService('ui').StopBlink(self)
    128         if self.destroyed:
    129             ClearMenuLayer()
    130             return
    131         PlaySound(uiconst.SOUND_BUTTON_CLICK)
    132         if self.actionID in CLOSE_MENU_ACTIONS and isinstance(self.action[1], list):
    133             uthread.new(self.action[1][0][1], self.action[1][0][2][0])
    134             ClearMenuLayer()
    135             return
    136         if isinstance(self.action[1], basestring):
    137             message_player(self.action[1])
    138         else:
    139             try:
    140                 actionMenuLabel = self.action[0]
    141                 labelPath = actionMenuLabel[0]
    142                 if len(self.action) > 2 and self.action[2]:
    143                     funcArgs = self.action[2]
    144                     if CaptionIsInMultiFunctions(labelPath) and not isinstance(funcArgs[0], (types.MethodType, types.FunctionType)):
    145                         funcArgs = (funcArgs,)
    146                 else:
    147                     funcArgs = ()
    148                 self.action[1](*funcArgs)
    149             except Exception as e:
    150                 log.LogError(e, 'Failed executing action:', self.action)
    151                 log.LogException()
    152                 sys.exc_clear()
    153 
    154         ClearMenuLayer()