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

scannerToolsUIComponents.py (14010B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\scannerFiles\scannerToolsUIComponents.py
      2 import localization
      3 import probescanning
      4 import weakref
      5 from carbon.common.script.util.timerstuff import AutoTimer
      6 from carbonui import uiconst
      7 from carbonui.button.const import HEIGHT_COMPACT
      8 from carbonui.control.button import Button
      9 from carbonui.control.buttonIcon import ButtonIcon
     10 from carbonui.control.checkbox import Checkbox
     11 from carbonui.control.combo import ComboUnderlay
     12 from carbonui.primitives.container import Container
     13 from carbonui.primitives.layoutGrid import LayoutGridRow
     14 from carbonui.primitives.sprite import Sprite
     15 from carbonui.uicore import uicore
     16 from eve.client.script.ui.control import eveLabel
     17 from eve.client.script.ui.control.eveLabel import EveLabelSmall
     18 from eve.client.script.ui.control.themeColored import FillThemeColored
     19 from eve.client.script.ui.control.tooltips import ShortcutHint
     20 from eve.client.script.ui.tooltips.tooltipHandler import TOOLTIP_DELAY_GAMEPLAY
     21 from eve.client.script.ui.util.utilWindows import NamePopup
     22 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     23 
     24 class ProbeTooltipButtonBase(LayoutGridRow):
     25     default_state = uiconst.UI_NORMAL
     26 
     27     def ApplyAttributes(self, attributes):
     28         LayoutGridRow.ApplyAttributes(self, attributes)
     29         self.func = attributes.func
     30         self.funcArgs = attributes.funcArgs
     31         self.highlight = FillThemeColored(bgParent=self, padding=(1, 0, 1, 0), opacity=0.25, colorType=uiconst.COLORTYPE_UIHILIGHT)
     32         self.highlight.display = False
     33 
     34     def OnClick(self, *args):
     35         if self.func:
     36             if self.funcArgs:
     37                 self.func(*self.funcArgs)
     38             else:
     39                 self.func()
     40 
     41     def OnMouseEnter(self, *args):
     42         self.highlight.display = True
     43 
     44     def OnMouseExit(self, *args):
     45         self.highlight.display = False
     46 
     47     def Disable(self):
     48         self.state = uiconst.UI_DISABLED
     49         self.opacity = 0.3
     50 
     51     def Enable(self):
     52         self.state = uiconst.UI_NORMAL
     53         self.opacity = 1.0
     54 
     55 
     56 class FilterBox(Container):
     57     default_align = uiconst.TOPLEFT
     58 
     59     def ApplyAttributes(self, attributes):
     60         Container.ApplyAttributes(self, attributes)
     61         labelCont = Container(parent=self, padRight=16, clipChildren=True)
     62         self.label = eveLabel.EveLabelSmall(parent=labelCont, state=uiconst.UI_DISABLED, align=uiconst.CENTERLEFT, left=5)
     63         Sprite(parent=self, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', pos=(5, -1, 7, 7), align=uiconst.CENTERRIGHT, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.5, state=uiconst.UI_DISABLED)
     64         ComboUnderlay(parent=self, align=uiconst.TOALL)
     65         self.SetText(attributes.text)
     66 
     67     def SetText(self, text):
     68         self.label.text = text
     69         self.width = self.label.textwidth + self.label.left * 2 + 12
     70         if self.maxWidth:
     71             self.width = min(self.width, self.maxWidth)
     72         self.height = max(HEIGHT_COMPACT, self.label.textheight + 2)
     73 
     74     def OnMouseEnter(self, *args):
     75         uicore.animations.FadeTo(self, startVal=self.opacity, endVal=1.5, duration=0.1)
     76 
     77     def OnMouseExit(self, *args):
     78         uicore.animations.FadeTo(self, startVal=self.opacity, endVal=1.0, duration=0.3)
     79 
     80     def GetTooltipPointer(self):
     81         return uiconst.POINT_TOP_2
     82 
     83     def GetTooltipDelay(self):
     84         return TOOLTIP_DELAY_GAMEPLAY
     85 
     86 
     87 class IgnoredBox(Container):
     88     default_align = uiconst.TOPLEFT
     89     noIgnored = 0
     90 
     91     def ApplyAttributes(self, attributes):
     92         Container.ApplyAttributes(self, attributes)
     93         self.scanSvc = sm.GetService('scanSvc')
     94         self.label = eveLabel.EveLabelSmall(parent=self, state=uiconst.UI_DISABLED, align=uiconst.CENTERLEFT, left=5)
     95         self.clearIcon = Sprite(parent=self, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', pos=(5, -1, 7, 7), align=uiconst.CENTERRIGHT, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.5, state=uiconst.UI_DISABLED)
     96         ComboUnderlay(parent=self, align=uiconst.TOALL)
     97         self.SetText(attributes.text)
     98 
     99     def OnClick(self):
    100         pass
    101 
    102     def UpdateIgnoredAmount(self, noIgnored):
    103         self.noIgnored = noIgnored
    104         if noIgnored:
    105             self.hint = localization.GetByLabel('UI/Inflight/Scanner/ResetIgnoredResults')
    106             self.Show()
    107         else:
    108             self.Hide()
    109         self.SetText(localization.GetByLabel('UI/Inflight/Scanner/Ignored', noIgnored=noIgnored))
    110 
    111     def SetText(self, text):
    112         self.label.text = text
    113         self.width = self.label.textwidth + self.label.left * 2 + 12
    114         self.height = self.label.textheight + 2
    115 
    116     def OnMouseEnter(self, *args):
    117         if self.noIgnored:
    118             uicore.animations.FadeTo(self, startVal=self.opacity, endVal=1.5, duration=0.1)
    119 
    120     def OnMouseExit(self, *args):
    121         uicore.animations.FadeTo(self, startVal=self.opacity, endVal=1.0, duration=0.3)
    122 
    123     def GetTooltipPointer(self):
    124         return uiconst.POINT_TOP_2
    125 
    126 
    127 class ProbeTooltipButtonRow(ProbeTooltipButtonBase):
    128 
    129     def ApplyAttributes(self, attributes):
    130         ProbeTooltipButtonBase.ApplyAttributes(self, attributes)
    131         width = attributes.width or 128
    132         icon = Sprite(texturePath=attributes.texturePath, pos=(0, 0, 17, 17), align=uiconst.CENTER, state=uiconst.UI_DISABLED)
    133         self.AddCell(icon, cellPadding=(5, 3, 4, 3))
    134         self.label = eveLabel.EveLabelMedium(text=attributes.text, bold=True, align=uiconst.CENTERLEFT, autoFitToText=True, width=width)
    135         self.AddCell(self.label, colSpan=self.columns - 1, cellPadding=(0, 2, 10, 2))
    136 
    137 
    138 class ProbeTooltipCheckboxRow(ProbeTooltipButtonBase):
    139     deleteFunction = None
    140     editFunction = None
    141 
    142     def ApplyAttributes(self, attributes):
    143         ProbeTooltipButtonBase.ApplyAttributes(self, attributes)
    144         self.checkBox = Checkbox(groupname=attributes.groupName, align=uiconst.CENTER, checked=attributes.checked, wrapLabel=True, settingsPath=None, width=16, height=16, state=uiconst.UI_DISABLED)
    145         self.settingsKey = attributes.settingsKey
    146         self.AddCell(self.checkBox, cellPadding=(5, 1, 4, 1))
    147         self.deleteFunction = attributes.deleteFunc
    148         self.editFunction = attributes.editFunc
    149         self.label = EveLabelSmall(text=attributes.text, bold=True, align=uiconst.CENTERLEFT, autoFitToText=True, width=128)
    150         self.AddCell(self.label, colSpan=1 if attributes.filterIndex is not None else 2, cellPadding=(0, 2, 6, 2))
    151         if attributes.filterIndex is not None:
    152             shortcutObj = ShortcutHint(text=str(attributes.filterIndex))
    153             self.AddCell(shortcutObj, cellPadding=(2, 2, 2, 0))
    154             return shortcutObj
    155 
    156     def OnDelete(self, *args):
    157         if self.deleteFunction:
    158             self.state = uiconst.UI_DISABLED
    159             if callable(self.deleteFunction):
    160                 self.deleteFunction()
    161             elif isinstance(self.deleteFunction, tuple):
    162                 func, args = self.deleteFunction
    163                 func(*args)
    164             uicore.animations.FadeOut(self, duration=0.5, callback=self.Close)
    165 
    166     def OnEdit(self, *args):
    167         if callable(self.editFunction):
    168             self.editFunction()
    169         elif isinstance(self.editFunction, tuple):
    170             func, args = self.editFunction
    171             func(*args)
    172 
    173     def OnClick(self, *args):
    174         self.checkBox.ToggleState()
    175         if self.func:
    176             self.func(self.settingsKey, self.checkBox.GetValue())
    177 
    178     def GetMenu(self):
    179         m = []
    180         if self.editFunction:
    181             m.append((localization.GetByLabel('UI/Inventory/Filters/Edit'), self.OnEdit))
    182         if self.deleteFunction:
    183             m.append((localization.GetByLabel('UI/Common/Delete'), self.OnDelete))
    184         return m
    185 
    186 
    187 class ProbeTooltipButton_CustomFormation(ProbeTooltipButtonBase):
    188 
    189     def ApplyAttributes(self, attributes):
    190         ProbeTooltipButtonBase.ApplyAttributes(self, attributes)
    191         self.formation = attributes.formation
    192         self.OnChangeCallback = attributes.OnChangeCallback
    193         self.launchFunc = attributes.launchFunc
    194         self.AddCell()
    195         self.label = EveLabelSmall(parent=self, text=attributes.text, bold=True, align=uiconst.CENTERLEFT)
    196         deleteButton = Sprite(texturePath='res:/UI/Texture/Icons/38_16_111.png', pos=(0, 0, 16, 16), align=uiconst.CENTERRIGHT, hint=localization.GetByLabel('UI/Inflight/Scanner/DeleteFormation'))
    197         self.AddCell(deleteButton, cellPadding=(5, 3, 4, 3))
    198         deleteButton.OnClick = self.DeleteFormation
    199 
    200     def Close(self, *args):
    201         ProbeTooltipButtonBase.Close(self, *args)
    202         self.OnChangeCallback = None
    203 
    204     def OnClick(self, *args):
    205         probescanning.customFormations.SelectFormation(self.formation[0])
    206         self.launchFunc(self.formation[0])
    207         if self.OnChangeCallback:
    208             self.OnChangeCallback()
    209 
    210     def DeleteFormation(self, *args):
    211         response = prompt_player_fsd_dialog('DeleteFormation', {'formationName': '%s' % self.formation[1]}, uiconst.YESNO, suppress=uiconst.ID_YES)
    212         if response != uiconst.ID_YES:
    213             return
    214         formation = self.formation
    215         probescanning.customFormations.DeleteFormation(formation[0])
    216         self.state = uiconst.UI_DISABLED
    217         uicore.animations.FadeOut(self, duration=0.5, callback=self.Close)
    218         if self.OnChangeCallback:
    219             self.OnChangeCallback()
    220 
    221 
    222 class FormationButton(ButtonIcon):
    223     default_texturePath = 'res:/UI/Texture/classes/ProbeScanner/32/customFormation.png'
    224     default_soundClick = 'msg_newscan_probe_formation_play'
    225 
    226     def __init__(self, launchFunc, **kwargs):
    227         self.scanSvc = sm.GetService('scanSvc')
    228         self.launchFunc = launchFunc
    229         super(FormationButton, self).__init__(func=self._LaunchFormation, args=(), **kwargs)
    230         self.UpdateButton()
    231 
    232     @property
    233     def selectedFormationID(self):
    234         return probescanning.customFormations.GetSelectedFormationID()
    235 
    236     @property
    237     def selectedFormationName(self):
    238         return probescanning.customFormations.GetSelectedFormationName() or localization.GetByLabel('UI/Inflight/Scanner/ProbeFormation')
    239 
    240     def UpdateButton(self):
    241         selectedFormationID = probescanning.customFormations.GetSelectedFormationID()
    242         if selectedFormationID is not None:
    243             try:
    244                 canLaunch = self.scanSvc.CanLaunchFormation(selectedFormationID)
    245             except KeyError:
    246                 self.Disable()
    247                 return
    248 
    249             if canLaunch:
    250                 self.Enable()
    251             else:
    252                 self.Disable()
    253         elif self.scanSvc.HasAvailableProbes():
    254             self.Enable()
    255         else:
    256             self.Disable()
    257         self.hint = self.selectedFormationName
    258 
    259     def _LaunchFormation(self):
    260         selectedFormationID = probescanning.customFormations.GetSelectedFormationID()
    261         if selectedFormationID is not None:
    262             self.launchFunc(selectedFormationID)
    263 
    264     def LoadTooltipPanel(self, tooltipPanel, *args):
    265         tooltipPanel.Flush()
    266         tooltipPanel.LoadStandardSpacing()
    267         tooltipPanel.columns = 3
    268         tooltipPanel.state = uiconst.UI_NORMAL
    269         formationsInfo = probescanning.customFormations.GetCustomFormationsInfo()
    270         buttonRow = tooltipPanel.AddRow()
    271         saveBtn = Button(align=uiconst.CENTER, label=localization.GetByLabel('UI/Inflight/Scanner/SaveCurrentFormation'), func=self.OnClickSaveFormation)
    272         buttonRow.AddCell(cellObject=saveBtn, colSpan=tooltipPanel.columns)
    273         if not self.scanSvc.GetActiveProbes() or len(formationsInfo) >= 10:
    274             saveBtn.Disable()
    275         selectedFormationID = probescanning.customFormations.GetSelectedFormationID()
    276         self.formationButtonsByID = {}
    277         for formationInfo in formationsInfo:
    278             formationID = formationInfo[0]
    279             if formationID < 0:
    280                 continue
    281             isActiveFormation = formationID == selectedFormationID
    282             formationName = '%s (%i)' % (formationInfo[1], formationInfo[2])
    283             button = tooltipPanel.AddRow(rowClass=ProbeTooltipButton_CustomFormation, text=formationName, formation=formationInfo, OnChangeCallback=self.OnCustomFormationsChanged, launchFunc=self.launchFunc)
    284             if isActiveFormation:
    285                 FillThemeColored(bgParent=button, padding=(3, 2, 3, 2), opacity=0.5, colorType=uiconst.COLORTYPE_UIHILIGHT)
    286             self.formationButtonsByID[formationInfo[0]] = button
    287 
    288         self.customFormationTooltip = weakref.ref(tooltipPanel)
    289         self.UpdateTooltipPanel(tooltipPanel)
    290         self.tooltipUpdateTimer = AutoTimer(100, self.UpdateTooltipPanel, tooltipPanel)
    291 
    292     def OnClickSaveFormation(self, *args):
    293         formationName = NamePopup(caption=localization.GetByLabel('UI/Inflight/Scanner/SaveCurrentFormation'), label=localization.GetByLabel('UI/Inflight/Scanner/FormationName'), maxLength=16)
    294         if formationName:
    295             sm.GetService('scanSvc').PersistCurrentFormation(formationName)
    296 
    297     def ReloadCustomFormationTooltip(self):
    298         if not self.customFormationTooltip or self.destroyed:
    299             return
    300         customFormationTooltip = self.customFormationTooltip()
    301         if customFormationTooltip is not None:
    302             self.LoadTooltipPanel(customFormationTooltip)
    303 
    304     def OnCustomFormationsChanged(self, *args):
    305         self.ReloadCustomFormationTooltip()
    306         self.UpdateButton()
    307 
    308     def UpdateTooltipPanel(self, tooltipPanel):
    309         if tooltipPanel.destroyed:
    310             self.tooltipUpdateTimer = None
    311             return
    312         for formationID, button in self.formationButtonsByID.iteritems():
    313             if button.destroyed:
    314                 continue
    315             try:
    316                 canLaunch = self.scanSvc.CanLaunchFormation(formationID)
    317             except KeyError:
    318                 continue
    319 
    320             if canLaunch:
    321                 button.Enable()
    322             else:
    323                 button.Disable()