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

structureState.py (7702B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\structureBrowser\structureState.py
      2 import gametime
      3 from carbon.common.script.util.format import FmtDate
      4 from carbonui.primitives.container import Container
      5 import carbonui.const as uiconst
      6 from carbonui.primitives.sprite import Sprite
      7 from localization import GetByLabel
      8 import structures
      9 SHIELD_TEXTURE_PATH = 'res:/UI/Texture/classes/StructureBrowser/shield.png'
     10 ARMOR_TEXTURE_PATH = 'res:/UI/Texture/classes/StructureBrowser/armor.png'
     11 HULL_TEXTURE_PATH = 'res:/UI/Texture/classes/StructureBrowser/hull.png'
     12 UNDER_ATTACK_TEXTURE_PATH = 'res:/UI/Texture/classes/StructureBrowser/attackState.png'
     13 NO_ATTACK_TEXTURE_PATH = 'res:/UI/Texture/classes/StructureBrowser/notAttackState.png'
     14 GREY = (125 / 255.0, 125 / 255.0, 125 / 255.0)
     15 YELLOW = (251 / 255.0, 176 / 255.0, 64 / 255.0)
     16 RED = (239 / 255.0, 65 / 255.0, 54 / 255.0)
     17 BLUE = (153 / 255.0, 211 / 255.0, 255 / 255.0)
     18 FULL_OPACITY = 1.0
     19 LOW_OPACITY = 0.25
     20 VERY_LOW_OPACITY = 0.07
     21 SECURE_STATES = [structures.STATE_ONLINE_DEPRECATED,
     22  structures.STATE_ARMOR_REINFORCE,
     23  structures.STATE_HULL_REINFORCE,
     24  structures.STATE_ANCHORING,
     25  structures.STATE_FOB_INVULNERABLE]
     26 VULNERABLE_STATES = [structures.STATE_SHIELD_VULNERABLE,
     27  structures.STATE_ARMOR_VULNERABLE,
     28  structures.STATE_HULL_VULNERABLE,
     29  structures.STATE_ANCHOR_VULNERABLE,
     30  structures.STATE_ONLINING_VULNERABLE,
     31  structures.STATE_UNANCHORED,
     32  structures.STATE_DEPLOY_VULNERABLE]
     33 hintDict = {(structures.STATE_ONLINE_DEPRECATED, 0): 'UI/StructureBrowser/StateOnline',
     34  (structures.STATE_FITTING_INVULNERABLE, 0): 'UI/StructureBrowser/StateFittingInvulnerable',
     35  (structures.STATE_ANCHORING, 0): 'UI/StructureBrowser/StateAnchoring',
     36  (structures.STATE_UNANCHORED, 0): 'UI/StructureBrowser/StateUnanchored',
     37  (structures.STATE_ONLINING_VULNERABLE, 0): 'UI/StructureBrowser/StateHullVulnerable',
     38  (structures.STATE_ONLINING_VULNERABLE, 1): 'UI/StructureBrowser/StateHullVulnerableAttack',
     39  (structures.STATE_ARMOR_REINFORCE, 0): 'UI/StructureBrowser/StateArmorReinforced',
     40  (structures.STATE_HULL_REINFORCE, 0): 'UI/StructureBrowser/StateHullReinforced',
     41  (structures.STATE_SHIELD_VULNERABLE, 0): 'UI/StructureBrowser/StateShieldVulnerable',
     42  (structures.STATE_ARMOR_VULNERABLE, 0): 'UI/StructureBrowser/StateArmorVulnerable',
     43  (structures.STATE_HULL_VULNERABLE, 0): 'UI/StructureBrowser/StateHullVulnerable',
     44  (structures.STATE_ANCHOR_VULNERABLE, 0): 'UI/StructureBrowser/StateAnchorVulnerable',
     45  (structures.STATE_SHIELD_VULNERABLE, 1): 'UI/StructureBrowser/StateShieldVulnerableAttack',
     46  (structures.STATE_ARMOR_VULNERABLE, 1): 'UI/StructureBrowser/StateArmorVulnerableAttack',
     47  (structures.STATE_HULL_VULNERABLE, 1): 'UI/StructureBrowser/StateHullVulnerableAttack',
     48  (structures.STATE_ANCHOR_VULNERABLE, 1): 'UI/StructureBrowser/StateAnchorVulnerableAttack',
     49  (structures.STATE_DEPLOY_VULNERABLE, 0): 'UI/StructureBrowser/StateDeployVulnerable',
     50  (structures.STATE_DEPLOY_VULNERABLE, 1): 'UI/StructureBrowser/StateDeployVulnerableAttack'}
     51 
     52 class StructureStateIcon(Container):
     53     default_width = 32
     54     default_height = 32
     55     default_align = uiconst.CENTER
     56     default_state = uiconst.UI_NORMAL
     57     default_name = 'StructureStateIcon'
     58 
     59     def ApplyAttributes(self, attributes):
     60         Container.ApplyAttributes(self, attributes)
     61         structureState = attributes.get('structureState', None)
     62         timerEnd = attributes.get('timerEnd', None)
     63         underAttack = attributes.get('underAttack', False)
     64         self.shield = Sprite(name='shield', parent=self, align=uiconst.TOALL, texturePath=SHIELD_TEXTURE_PATH, state=uiconst.UI_DISABLED, opacity=0)
     65         self.armor = Sprite(name='armor', parent=self, align=uiconst.TOALL, texturePath=ARMOR_TEXTURE_PATH, state=uiconst.UI_DISABLED, opacity=0)
     66         self.hull = Sprite(name='hull', parent=self, align=uiconst.TOALL, texturePath=HULL_TEXTURE_PATH, state=uiconst.UI_DISABLED, opacity=0)
     67         self.attackSprite = Sprite(parent=self, align=uiconst.TOALL, texturePath='', state=uiconst.UI_DISABLED)
     68         if structureState is not None:
     69             self.SetStructureState(structureState, underAttack=underAttack, timerEnd=timerEnd)
     70 
     71     def SetStructureState(self, structureState, underAttack = False, timerEnd = None):
     72         if structureState not in SECURE_STATES + VULNERABLE_STATES:
     73             self.display = False
     74             return
     75         self.display = True
     76         opacity, stateColor = self._GetStateColorAndOpacity(structureState, underAttack)
     77         self._SetAttackSprite(underAttack, stateColor, opacity)
     78         self.SetHintForIcon(structureState, underAttack, timerEnd)
     79         if structureState in (structures.STATE_ONLINE_DEPRECATED, structures.STATE_SHIELD_VULNERABLE):
     80             self._SetColorAndOpacity(self.shield, stateColor, opacity)
     81             self._SetColorAndOpacity(self.armor, stateColor, LOW_OPACITY)
     82             self._SetColorAndOpacity(self.hull, stateColor, LOW_OPACITY)
     83         elif structureState in (structures.STATE_ARMOR_REINFORCE, structures.STATE_ARMOR_VULNERABLE):
     84             self._SetColorAndOpacity(self.shield, GREY, LOW_OPACITY)
     85             self._SetColorAndOpacity(self.armor, stateColor, opacity)
     86             self._SetColorAndOpacity(self.hull, stateColor, LOW_OPACITY)
     87         elif structureState in (structures.STATE_HULL_REINFORCE,
     88          structures.STATE_ONLINING_VULNERABLE,
     89          structures.STATE_HULL_VULNERABLE,
     90          structures.STATE_ANCHOR_VULNERABLE,
     91          structures.STATE_DEPLOY_VULNERABLE,
     92          structures.STATE_FITTING_INVULNERABLE):
     93             self._SetColorAndOpacity(self.shield, GREY, LOW_OPACITY)
     94             self._SetColorAndOpacity(self.armor, GREY, LOW_OPACITY)
     95             self._SetColorAndOpacity(self.hull, stateColor, opacity)
     96         elif structureState in (structures.STATE_ANCHORING, structures.STATE_FOB_INVULNERABLE):
     97             self._SetColorAndOpacity(self.shield, stateColor, VERY_LOW_OPACITY)
     98             self._SetColorAndOpacity(self.armor, stateColor, VERY_LOW_OPACITY)
     99             self._SetColorAndOpacity(self.hull, stateColor, VERY_LOW_OPACITY)
    100             self.attackSprite.SetAlpha(VERY_LOW_OPACITY)
    101         self.opacity = 1.0
    102 
    103     def _GetStateColorAndOpacity(self, state, underAttack):
    104         accentOpacity = FULL_OPACITY
    105         if state == structures.STATE_SHIELD_VULNERABLE:
    106             stateColor = GREY
    107         elif state in SECURE_STATES:
    108             stateColor = BLUE
    109             accentOpacity = LOW_OPACITY
    110         elif underAttack:
    111             stateColor = RED
    112         else:
    113             stateColor = YELLOW
    114         return (accentOpacity, stateColor)
    115 
    116     def _SetColorAndOpacity(self, uiObject, color, opacity):
    117         newColor = color + (opacity,)
    118         uiObject.SetRGBA(*newColor)
    119 
    120     def _SetAttackSprite(self, isUnderAttack, stateColor, opacity):
    121         if isUnderAttack:
    122             texturePath = UNDER_ATTACK_TEXTURE_PATH
    123         else:
    124             texturePath = NO_ATTACK_TEXTURE_PATH
    125         self.attackSprite.SetTexturePath(texturePath)
    126         newColor = stateColor + (opacity,)
    127         self.attackSprite.SetRGBA(*newColor)
    128 
    129     def SetHintForIcon(self, structureState, isUnderAttack, timerEnd):
    130         hintPath = hintDict.get((structureState, isUnderAttack), None)
    131         hintTextList = []
    132         if hintPath:
    133             hintTextList.append(GetByLabel(hintPath))
    134         if timerEnd and timerEnd > gametime.GetWallclockTime() and structureState in (structures.STATE_ARMOR_REINFORCE, structures.STATE_HULL_REINFORCE):
    135             hintTextList.append(GetByLabel('UI/StructureBrowser/TimerEndTooltip', timerEnd=FmtDate(timerEnd)))
    136         self.hint = '<br><br>'.join(hintTextList)