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

baseSlot.py (14268B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fitting\baseSlot.py
      2 import eveui
      3 from carbon.client.script.environment.AudioUtil import PlaySound
      4 from carbon.common.script.sys.serviceConst import ROLE_GML, ROLE_WORLDMOD
      5 from carbon.common.script.util.timerstuff import AutoTimer
      6 from carbonui import const as uiconst
      7 from menu import MenuLabel
      8 from carbonui.primitives.transform import Transform
      9 from carbonui.util.various_unsorted import GetAttrs, IsUnder
     10 from eve.client.script.ui.shared.fitting.fittingUtil import EatSignalChangingErrors, CanFitFromSourceLocation
     11 from eve.client.script.ui.shared.fitting.utilBtns import UtilBtnData
     12 import inventorycommon.const as invConst
     13 import eve.client.script.ui.shared.fittingScreen as fittingScreenConst
     14 from inventorycommon.util import IsSubsystemFlagVisible
     15 from signals.signalUtil import ChangeSignalConnect
     16 from localization import GetByLabel
     17 import localization
     18 import blue
     19 from carbonui.uicore import uicore
     20 import trinity
     21 
     22 class FittingSlotBase(Transform):
     23     slotActiveTexturePath = 'res:/UI/Texture/classes/Fitting/slotActive.png'
     24     slotPassiveTexturePath = 'res:/UI/Texture/classes/Fitting/slotPassive.png'
     25     slotOverheatedTexturePath = 'res:/UI/Texture/classes/Fitting/slotOverheated.png'
     26     slotsToHintDict = {}
     27 
     28     def ApplyAttributes(self, attributes):
     29         Transform.ApplyAttributes(self, attributes)
     30         self.controller = attributes.controller
     31         self.utilButtons = []
     32         self._emptyHint, self._emptyTooltip = self.PrimeToEmptySlotHint()
     33         self.ChangeSignalConnection()
     34         self.hilitedFromMathing = False
     35         self.ConstructFlagAndUnderlay()
     36         self.moduleSlotFill = None
     37         self.warningFill = None
     38         self.skillSprite = None
     39         self.fittingWarning = None
     40 
     41     def ConstructFlagAndUnderlay(self):
     42         pass
     43 
     44     def ConstructModuleSlotFill(self):
     45         pass
     46 
     47     def ConstructWarningFill(self):
     48         pass
     49 
     50     def ConstructSkillSprite(self):
     51         pass
     52 
     53     def ConstructFittingWarning(self):
     54         pass
     55 
     56     def ChangeSignalConnection(self, connect = True):
     57         signalAndCallback = [(self.controller.on_online_state_change, self.UpdateOnlineDisplay), (self.controller.on_item_fitted, self.UpdateFitting)]
     58         ChangeSignalConnect(signalAndCallback, connect)
     59 
     60     def UpdateFitting(self):
     61         pass
     62 
     63     def DisableSlot(self):
     64         self.opacity = 0.1
     65         self.state = uiconst.UI_DISABLED
     66         self.flagIcon.state = uiconst.UI_HIDDEN
     67         self.UpdateGhostFittingIcons(None)
     68         self.Hilite(0)
     69 
     70     def EnableSlot(self):
     71         self.opacity = 1.0
     72         self.state = uiconst.UI_NORMAL
     73         self.flagIcon.state = uiconst.UI_DISABLED
     74         self.sr.underlay.display = True
     75 
     76     def HideSlot(self):
     77         self.state = uiconst.UI_HIDDEN
     78 
     79     def HideModuleSlotFill(self):
     80         self.HideElement(self.moduleSlotFill)
     81 
     82     def ColorUnderlay(self, color = None):
     83         a = self.sr.underlay.opacity
     84         r, g, b = color or (1.0, 1.0, 1.0)
     85         self.sr.underlay.SetRGBA(r, g, b, a)
     86         self.UpdateOnlineDisplay()
     87 
     88     def GetMenu(self):
     89         m = self.controller.GetMenu(self)
     90         if self.controller.GetModuleTypeID() and self.controller.GetModuleID():
     91             if session.role & (ROLE_GML | ROLE_WORLDMOD):
     92                 m += [(str(self.controller.GetModuleID()), self.CopyItemIDToClipboard, (self.controller.GetModuleID(),)), None]
     93             m += [(MenuLabel('UI/Commands/ShowInfo'), self.ShowInfo)]
     94             if self.controller.IsRigSlot():
     95                 if self.controller.CanUnfitRigsWithoutDestroying():
     96                     m += self.controller.TryGetUnfitOption()
     97                 else:
     98                     m += [(MenuLabel('UI/Fitting/Destroy'), self.controller.Unfit)]
     99             else:
    100                 m += self.controller.TryGetUnfitOption()
    101                 if self.controller.IsOnlineable():
    102                     if self.controller.IsOnline():
    103                         m.append((MenuLabel('UI/Fitting/PutOffline'), self.ToggleOnline))
    104                     else:
    105                         m.append((MenuLabel('UI/Fitting/PutOnline'), self.ToggleOnline))
    106         return m
    107 
    108     def OnClick(self, *args):
    109         if self.controller.GetModule():
    110             PlaySound(uiconst.SOUND_BUTTON_CLICK)
    111         return self.controller.OnClick(self)
    112 
    113     def ToggleOnline(self):
    114         self.controller.ToggleOnlineModule()
    115         self.UpdateOnlineDisplay()
    116 
    117     def CopyItemIDToClipboard(self, itemID):
    118         blue.pyos.SetClipboardData(str(itemID))
    119 
    120     def ShowInfo(self, *args):
    121         sm.GetService('info').ShowInfo(self.controller.GetModuleTypeID(), self.controller.GetModuleID())
    122 
    123     def OnMouseEnter(self, *args):
    124         PlaySound(uiconst.SOUND_BUTTON_HOVER)
    125         self.Hilite(1)
    126         if self.controller.GetModule() is not None:
    127             self.ShowUtilButtons()
    128             if self.controller.IsOnlineable() and self.controller.IsOnline():
    129                 self.ShowCpuAndPowergrid()
    130         else:
    131             self.hint = self._emptyHint
    132 
    133     def OnMouseExit(self, *args):
    134         self.Hilite(0)
    135         self.HideCpuAndPowergrid()
    136 
    137     def Hilite(self, state):
    138         if state:
    139             self.sr.underlay.opacity = 0.5
    140         else:
    141             self.sr.underlay.opacity = 0.3
    142 
    143     def GetDragData(self, *args):
    144         return self.controller.GetDragData()
    145 
    146     def HiliteIfMatching(self, flagID, powerType, itemTypeID):
    147         if flagID is None and powerType is None:
    148             if self.state != uiconst.UI_DISABLED and self.controller.DoesFitAsCharge(itemTypeID):
    149                 self.SetHiliteFromMatching(1)
    150                 return
    151         elif self.state != uiconst.UI_DISABLED and self.controller.GetModule() is None:
    152             if powerType is not None and self.controller.GetPowerType() == powerType:
    153                 self.SetHiliteFromMatching(1)
    154                 return
    155             if flagID is not None and self.controller.GetFlagID() == flagID:
    156                 self.SetHiliteFromMatching(1)
    157                 return
    158         self.SetHiliteFromMatching(0)
    159 
    160     def SetHiliteFromMatching(self, value):
    161         self.Hilite(value)
    162         self.hilitedFromMathing = value
    163 
    164     def SetFittingWarningColor(self, color):
    165         if color is None:
    166             if self.fittingWarning:
    167                 self.fittingWarning.display = False
    168         else:
    169             self.ConstructFittingWarning()
    170             self.fittingWarning.display = True
    171             self.fittingWarning.SetRGBA(*color)
    172 
    173     def OnDropData(self, dragObj, nodes):
    174         if not CanFitFromSourceLocation(nodes):
    175             return
    176         self.controller.OnDropData(dragObj, nodes)
    177 
    178     def GetDroppedItems(self, nodes):
    179         items = []
    180         for node in nodes:
    181             if node.__guid__ in ('listentry.InvItem', 'xtriui.InvItem'):
    182                 invType = node.rec
    183                 if self.controller.IsFittableType(invType.typeID):
    184                     items.append(invType)
    185 
    186         return items
    187 
    188     def SetDragState(self):
    189         if not self.controller.GetModule() and not self.controller.GetCharge():
    190             self.DisableDrag()
    191         elif self.controller.SlotExists():
    192             self.EnableDrag()
    193 
    194     def PrimeToEmptySlotHint(self):
    195         flagID = self.controller.GetFlagID()
    196         slotKey = self.GetSlotKey(flagID)
    197         if slotKey is None or slotKey not in self.slotsToHintDict:
    198             return (GetByLabel('UI/Fitting/EmptySlot'), '')
    199         labelPath, tooltipName = self.slotsToHintDict[slotKey]
    200         return (GetByLabel(labelPath), tooltipName)
    201 
    202     def GetSlotKey(self, flagID):
    203         if flagID in invConst.hiSlotFlags:
    204             return 'hiSlot'
    205         if flagID in invConst.medSlotFlags:
    206             return 'medSlot'
    207         if flagID in invConst.loSlotFlags:
    208             return 'loSlot'
    209         if IsSubsystemFlagVisible(flagID):
    210             return 'subSystemSlot'
    211         if flagID in invConst.rigSlotFlags:
    212             return 'rigSlot'
    213 
    214     @eveui.skip_if_destroyed
    215     def UpdateOnlineDisplay(self):
    216         if self.controller.parentController.GetItemID() == self.controller.dogmaLocation.shipIDBeingDisembarked:
    217             return
    218         if self.controller.GetModule() is not None and self.controller.IsOnlineable():
    219             if self.controller.IsOnline():
    220                 self.flagIcon.SetRGBA(1.0, 1.0, 1.0, 1.0)
    221                 if GetAttrs(self, 'sr', 'onlineButton') and self.sr.onlineButton.hint == localization.GetByLabel('UI/Fitting/PutOnline'):
    222                     self.sr.onlineButton.hint = localization.GetByLabel('UI/Fitting/PutOffline')
    223             else:
    224                 self.flagIcon.SetRGBA(1.0, 1.0, 1.0, 0.25)
    225                 if GetAttrs(self, 'sr', 'onlineButton') and self.sr.onlineButton.hint == localization.GetByLabel('UI/Fitting/PutOffline'):
    226                     self.sr.onlineButton.hint = localization.GetByLabel('UI/Fitting/PutOnline')
    227         elif self.flagIcon:
    228             if self.controller.GetModule() is None or self.controller.SlotExists():
    229                 self.flagIcon.SetRGBA(1.0, 1.0, 1.0, 1.0)
    230             else:
    231                 self.flagIcon.SetRGBA(0.7, 0.0, 0.0, 0.5)
    232 
    233     def GetRigsBtns(self):
    234         if self.controller.CanUnfitRigsWithoutDestroying():
    235             removeLabel = localization.GetByLabel('UI/Fitting/Unfit')
    236         else:
    237             removeLabel = localization.GetByLabel('UI/Fitting/Destroy')
    238         btns = [UtilBtnData(removeLabel, 'ui_38_16_200', self.controller.Unfit, 1, 0), UtilBtnData(localization.GetByLabel('UI/Commands/ShowInfo'), 'ui_38_16_208', self.ShowInfo, 1, 0)]
    239         return btns
    240 
    241     def GetModuleBtns(self, isOnlinable):
    242         if bool(self.controller.IsOnline):
    243             toggleLabel = localization.GetByLabel('UI/Fitting/PutOffline')
    244         else:
    245             toggleLabel = localization.GetByLabel('UI/Fitting/PutOnline')
    246         btns = [UtilBtnData(localization.GetByLabel('UI/Fitting/UnfitModule'), 'ui_38_16_200', self.controller.UnfitModule, 1, 0), UtilBtnData(localization.GetByLabel('UI/Commands/ShowInfo'), 'ui_38_16_208', self.ShowInfo, 1, 0), UtilBtnData(toggleLabel, 'ui_38_16_207', self.ToggleOnline, isOnlinable, 1)]
    247         return btns
    248 
    249     @eveui.skip_if_destroyed
    250     def ShowUtilButtons(self, *args):
    251         flagID = self.controller.GetFlagID()
    252         self.controller.parentController.SetSlotWithMenu(flagID)
    253         for button in self.utilButtons:
    254             button.SetBtnColorBasedOnIsActive()
    255 
    256         self.utilButtonsTimer = AutoTimer(500, self.HideUtilButtons)
    257 
    258     @eveui.skip_if_destroyed
    259     def HideUtilButtons(self, force = 0):
    260         mo = uicore.uilib.mouseOver
    261         if not force and (mo in self.utilButtons or mo == self or IsUnder(mo, self)):
    262             return
    263         for button in self.utilButtons:
    264             button.Hide()
    265 
    266         self.utilButtonsTimer = None
    267         self.HideCpuAndPowergrid()
    268 
    269     def ShowCpuAndPowergrid(self):
    270         if self.controller:
    271             self.controller.GetCpuAndPowergridUsage()
    272 
    273     def HideCpuAndPowergrid(self):
    274         if self.controller:
    275             self.controller.HideCpuAndPowergridUsage()
    276 
    277     def SetTexurePathForActivatable(self):
    278         self.SetModuleSlotPathAndState(self.slotActiveTexturePath)
    279 
    280     def SetTexturePathForPassive(self):
    281         self.SetModuleSlotPathAndState(self.slotPassiveTexturePath)
    282 
    283     def SetTexturePathForOverheated(self):
    284         self.SetModuleSlotPathAndState(self.slotOverheatedTexturePath)
    285 
    286     def HideElement(self, element):
    287         if element:
    288             element.display = False
    289 
    290     def UpdateGhostFittingIcons(self, invItem):
    291         self.controller.UpdateGhostFittingIcons(self, invItem)
    292 
    293     def UpdateStatusDisplay(self):
    294         self.controller.UpdateStatusDisplay(self)
    295 
    296     def SetModuleSlotPathAndState(self, texturePath):
    297         self.ConstructModuleSlotFill()
    298         self.moduleSlotFill.SetTexturePath(texturePath)
    299         self.moduleSlotFill.display = True
    300 
    301     def SetStatusDisplayOffline(self):
    302         self.flagIcon.SetAlpha(0.25)
    303         self.moduleSlotFill.SetRGBA(*fittingScreenConst.OFFLINE_COLOR)
    304         self.sr.underlay.display = False
    305 
    306     def SetStatusDisplayOnline(self):
    307         newAlpha = getattr(self.flagIcon, 'fullAlphaValue', None) or 1.0
    308         self.flagIcon.SetAlpha(newAlpha)
    309         self.moduleSlotFill.SetRGBA(*fittingScreenConst.ONLINE_COLOR)
    310         self.sr.underlay.display = False
    311 
    312     def SetStatusDisplayActive(self):
    313         newAlpha = getattr(self.flagIcon, 'fullAlphaValue', None) or 1.0
    314         self.flagIcon.SetAlpha(newAlpha)
    315         self.ConstructModuleSlotFill()
    316         self.moduleSlotFill.SetRGBA(*fittingScreenConst.ACTIVE_COLOR)
    317         self.sr.underlay.display = False
    318 
    319     def SetStatusDisplayOverheated(self):
    320         newAlpha = getattr(self.flagIcon, 'fullAlphaValue', None) or 1.0
    321         self.flagIcon.SetAlpha(newAlpha)
    322         self.ConstructModuleSlotFill()
    323         self.moduleSlotFill.SetRGBA(*fittingScreenConst.OVERHEATED_COLOR)
    324         self.sr.underlay.display = False
    325 
    326     def ChangeWarningDisplay(self, isOn = False):
    327         if isOn:
    328             self.ConstructWarningFill()
    329             self.warningFill.display = True
    330         elif self.warningFill:
    331             self.HideElement(self.warningFill)
    332 
    333     def SetIconAsPreview(self):
    334         flagIcon = self.flagIcon
    335         flagIcon.spriteEffect = trinity.TR2_SFX_SOFTLIGHT
    336         flagIcon.saturation = 0.1
    337         flagIcon.SetRGBA(80 / 255.0, 150 / 255.0, 255 / 255.0, flagIcon.GetAlpha())
    338 
    339     def SetIconNotAsPreview(self):
    340         flagIcon = self.flagIcon
    341         flagIcon.spriteEffect = trinity.TR2_SFX_COPY
    342         flagIcon.saturation = 1.0
    343         if self.controller.GetModule() is None or self.controller.SlotExists():
    344             flagIcon.SetRGBA(1, 1, 1, flagIcon.GetAlpha())
    345             flagIcon.fullAlphaValue = 1.0
    346         else:
    347             flagIcon.SetRGBA(0.7, 0.0, 0.0, 0.75)
    348             flagIcon.fullAlphaValue = 0.75
    349 
    350     def HideGhostFittingElement(self):
    351         self.HideElement(self.moduleSlotFill)
    352         self.sr.underlay.display = True
    353 
    354     def Close(self):
    355         with EatSignalChangingErrors(errorMsg='FittingSlotBase'):
    356             self.ChangeSignalConnection(connect=False)
    357         Transform.Close(self)
    358         self.controller = None