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

hackingUtilityElement.py (5576B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\hacking\hackingUtilityElement.py
      2 import localization
      3 import hackingcommon.hackingConstants as hackingConst
      4 import uthread
      5 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER
      6 from carbonui import uiconst
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.sprite import Sprite
      9 from carbonui.uicore import uicore
     10 from carbonui.util.color import Color
     11 from eve.client.script.ui.control import eveLabel
     12 from eve.client.script.ui.hacking import hackingUIConst
     13 
     14 class UtilityElement(Container):
     15     __notifyevents__ = ['OnSelectedUtilityElementChanged', 'OnHackingUEInventoryChanged', 'OnHackingUEDurationReduced']
     16     SIZE = 50
     17     default_width = SIZE
     18     pickRadius = SIZE
     19     default_align = uiconst.TOLEFT
     20     default_state = uiconst.UI_NORMAL
     21     default_padLeft = 5
     22     default_opacity = 0.0
     23 
     24     def ApplyAttributes(self, attributes):
     25         Container.ApplyAttributes(self, attributes)
     26         sm.RegisterNotify(self)
     27         self.data = attributes.utilityElementData
     28         self.index = attributes.index
     29         self.color = None
     30         self.inUseThread = None
     31         self.mouseDownSprite = Sprite(name='mouseDownSprite', bgParent=self, texturePath='res:/UI/Texture/classes/hacking/utilTileMouseDown.png', opacity=0.0, padding=-15)
     32         self.mouseHoverSprite = Sprite(name='mouseHoverSprite', bgParent=self, texturePath='res:/UI/Texture/classes/hacking/utilTileMouseHover.png', opacity=0.0, padding=-15)
     33         Sprite(name='baseSprite', bgParent=self, texturePath='res:/UI/Texture/classes/hacking/utilTileBase.png', padding=-15)
     34         self.iconSprite = Sprite(parent=self, align=uiconst.CENTER, pos=(0, 0, 64, 64), state=uiconst.UI_DISABLED)
     35         self.durationLabel = eveLabel.Label(name='durationLabel', parent=self, align=uiconst.CENTERTOP, top=-10, bold=True)
     36         uicore.animations.FadeTo(self, self.opacity, 0.5, duration=0.6)
     37         self.UpdateUtilityElementState()
     38 
     39     def UpdateUtilityElementState(self):
     40         oldSubtype = self.data.subtype if self.data else None
     41         texturePath = hackingUIConst.ICONPATH_BY_SUBTYPE.get(self.data.subtype, None)
     42         self.iconSprite.SetTexturePath(texturePath)
     43         if self.data.subtype != hackingConst.SUBTYPE_NONE:
     44             uicore.animations.FadeTo(self, self.opacity, 1.0, duration=0.6)
     45             if self.data.isInUse:
     46                 self.color = hackingUIConst.COLOR_UTILITYELEMENTICON
     47                 if not self.inUseThread:
     48                     self.inUseThread = uthread.new(self.AnimInUseThread)
     49             elif self.data.isSelected:
     50                 self.color = hackingUIConst.COLOR_UTILITYELEMENTICON
     51             else:
     52                 self.color = Color.WHITE
     53         else:
     54             self.color = hackingUIConst.COLOR_UEEMPTY_SLOT
     55             if oldSubtype != hackingConst.SUBTYPE_NONE:
     56                 uicore.animations.FadeTo(self, 1.0, 0.5, duration=0.15, loops=2)
     57                 uicore.animations.FadeTo(self.mouseDownSprite, 0.5, 0.0, duration=0.15, loops=2)
     58         if self.data.durationRemaining:
     59             self.durationLabel.text = str(self.data.durationRemaining)
     60         else:
     61             self.durationLabel.text = ''
     62         uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGB(), self.color, duration=0.1)
     63 
     64     def AnimInUseThread(self):
     65         while not self.destroyed and self.data.isInUse:
     66             uicore.animations.FadeTo(self.iconSprite, 1.0, 0.1, duration=1.0, curveType=uiconst.ANIM_WAVE, sleep=True)
     67 
     68         self.inUseThread = None
     69         self.opacity = 1.0
     70 
     71     def OnMouseEnter(self, *args):
     72         if self.data.subtype == hackingConst.SUBTYPE_NONE or self.data.isInUse:
     73             return
     74         color = Color(*self.color).SetBrightness(1.0).GetRGBA()
     75         uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), color, duration=0.3)
     76         uicore.animations.FadeIn(self.mouseHoverSprite, duration=0.3)
     77 
     78     def OnMouseExit(self, *args):
     79         uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), self.color, duration=0.3)
     80         uicore.animations.FadeOut(self.mouseHoverSprite, duration=0.3)
     81 
     82     def OnMouseDown(self, *args):
     83         if self.data.subtype == hackingConst.SUBTYPE_NONE or self.data.isInUse:
     84             return
     85         uicore.animations.FadeIn(self.mouseDownSprite, duration=0.1)
     86 
     87     def OnMouseUp(self, *args):
     88         uicore.animations.FadeOut(self.mouseDownSprite, duration=0.2)
     89 
     90     def OnClick(self, *args):
     91         if self.data.subtype == hackingConst.SUBTYPE_NONE or self.data.isInUse:
     92             return
     93         sm.GetService('hackingUI').OnUtilityElementClicked(self.index, self.data)
     94 
     95     def OnSelectedUtilityElementChanged(self, eventData):
     96         self.UpdateUtilityElementState()
     97 
     98     def OnHackingUEInventoryChanged(self):
     99         self.UpdateUtilityElementState()
    100 
    101     def OnHackingUEDurationReduced(self, index, coord = None):
    102         if index == self.data.index:
    103             uicore.animations.FadeTo(self.mouseDownSprite, 0.8, 0.0, duration=0.6)
    104 
    105     def GetHint(self):
    106         if self.data.subtype != hackingConst.SUBTYPE_NONE:
    107             ret = localization.GetByLabel(hackingUIConst.UE_HINTS_BY_SUBTYPE[self.data.subtype], amount=self.data.info, turns=self.data.totalDuration)
    108         else:
    109             ret = localization.GetByLabel('UI/Hacking/EmptyUtilitySlot')
    110         if bool(session.role & ROLE_PROGRAMMER):
    111             ret += repr(self.data).replace('<', '').replace('>', '')
    112         return ret