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

hackingTile.py (15813B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\hacking\hackingTile.py
      2 import random
      3 from math import pi
      4 import carbonui.const as uiconst
      5 import localization
      6 from carbon.common.script.sys.serviceConst import ROLE_QA
      7 from carbonui import fontconst
      8 from carbonui.primitives.container import Container
      9 from carbonui.primitives.sprite import Sprite
     10 from carbonui.primitives.transform import Transform
     11 from carbonui.util.color import Color
     12 from eve.client.script.ui.control import eveLabel
     13 from eve.client.script.ui.hacking.hackingStatContainer import StatContainer
     14 import hackingcommon.hackingConstants as hackingConst
     15 from eve.client.script.ui.hacking import hackingUIConst
     16 import uthread
     17 import blue
     18 import evetypes
     19 from carbonui.uicore import uicore
     20 
     21 class Tile(Container):
     22     __notifyevents__ = ['OnSelectedUtilityElementChanged',
     23      'OnHackingUEDurationReduced',
     24      'OnDefenseSoftwareUnveiled',
     25      'OnCoreUnveiled',
     26      'OnHoneyPotHealed',
     27      'OnCoreContentsRevealed']
     28     default_width = hackingUIConst.TILE_SIZE
     29     default_height = hackingUIConst.TILE_SIZE
     30     pickRadius = hackingUIConst.TILE_SIZE
     31     default_align = uiconst.TOPLEFT
     32     default_state = uiconst.UI_NORMAL
     33 
     34     def ApplyAttributes(self, attributes):
     35         Container.ApplyAttributes(self, attributes)
     36         sm.RegisterNotify(self)
     37         self.tileData = attributes.tileData
     38         showCoordLabel = attributes.showCoordLabel
     39         self.bgColor = Color.WHITE
     40         self.iconColor = Color.WHITE
     41         self.emptySegmentTexturePath = None
     42         self.bgScale = (1.0, 1.0)
     43         if showCoordLabel:
     44             self.AddCoordLabel()
     45         self.mouseHoverSprite = Sprite(name='mouseHoverSprite', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/hacking/tileHover.png', opacity=0.0)
     46         self.coherenceCont = None
     47         self.strengthCont = None
     48         self.distanceIndicatorCont = None
     49         self.iconSprite = Sprite(name='iconSprite', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=hackingUIConst.TILE_ICON_SIZE, height=hackingUIConst.TILE_ICON_SIZE)
     50         self.tileBgTransform = Transform(name='tileBgTransform', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=hackingUIConst.TILE_ICON_SIZE, height=hackingUIConst.TILE_ICON_SIZE, scalingCenter=(0.5, 0.5), scale=self.bgScale)
     51         self.tileBgSprite = Sprite(name='tileSprite', bgParent=self.tileBgTransform)
     52         self.utilElementMarkerSprite = None
     53         self.healingGivenSprite = None
     54         self.healingReceivedSprite = None
     55         self.UpdateTileState(hackingConst.EVENT_TILE_CREATED)
     56 
     57     def AddCoordLabel(self):
     58         if not session.role & ROLE_QA:
     59             return
     60         x, y = self.tileData.coord
     61         coordText = '(%s, %s)' % (x, y)
     62         eveLabel.Label(name='coordLabel', parent=self, align=uiconst.CENTERTOP, fontsize=fontconst.EVE_SMALL_FONTSIZE, text=coordText, idx=0)
     63 
     64     def UpdateTileState(self, eventID = None, tileData = None):
     65         tileType = self.tileData.type
     66         tileSubType = self.tileData.subtype
     67         self.tileBgSprite.SetTexturePath(self.GetTileBackgroundTexturePath())
     68         self.bgColor = self.GetTileBackgroundColor()
     69         uicore.animations.SpColorMorphTo(self.tileBgSprite, self.tileBgSprite.GetRGBA(), self.bgColor)
     70         self.iconSprite.SetTexturePath(self.GetIconTexturePath())
     71         self.iconColor = hackingUIConst.COLOR_TILE_ICON_BY_TYPE.get(tileType, Color.WHITE)
     72         uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), self.iconColor)
     73         if self.HasLargeIcon():
     74             uicore.animations.FadeOut(self.mouseHoverSprite, duration=0.1)
     75         if (self.HasLargeIcon() or tileType == hackingConst.TYPE_DATACACHE) and self.tileData.blocked:
     76             uicore.animations.FadeTo(self, self.opacity, 0.3, duration=0.3)
     77         else:
     78             uicore.animations.FadeIn(self, duration=0.3)
     79         if self.IsAttackable(tileType):
     80             self.ShowCoherence()
     81             self.ShowStrength()
     82         else:
     83             self.HideCoherence()
     84             self.HideStrength()
     85         if self.tileData.distanceIndicator > 0:
     86             uthread.new(self.ShowDistanceIndicator)
     87         if uicore.uilib.mouseOver == self:
     88             self.OnMouseEnter()
     89         if tileType == hackingConst.TYPE_SEGMENT:
     90             self.bgScale = (0.7, 0.7)
     91         else:
     92             self.bgScale = (1.0, 1.0)
     93         uicore.animations.Tr2DScaleTo(self.tileBgTransform, self.tileBgTransform.scale, self.bgScale, duration=0.6)
     94         if eventID == hackingConst.EVENT_TILE_FLIPPED and not self.IsAttackable(tileType):
     95             rotation = pi * (0.05 + 0.2 * random.random()) * random.choice((-1, 1))
     96             uicore.animations.Tr2DRotateTo(self.tileBgSprite, rotation, 0.0, duration=0.3)
     97             uicore.animations.FadeTo(self.tileBgSprite, 0.0, 1.0, duration=0.3)
     98         elif eventID == hackingConst.EVENT_ATTACK:
     99             if self.tileData.coherence > 0:
    100                 uicore.animations.BlinkIn(self.iconSprite, duration=0.1, loops=3)
    101                 uicore.animations.Tr2DScaleTo(self.tileBgTransform, self.bgScale, (0.9, 0.9), duration=0.15, curveType=uiconst.ANIM_WAVE)
    102             else:
    103                 uicore.animations.BlinkIn(self.iconSprite, duration=0.1, loops=3)
    104         elif eventID == hackingConst.EVENT_OBJECT_KILLED:
    105             uicore.animations.BlinkIn(self.iconSprite, duration=0.1, loops=3)
    106         elif eventID == hackingConst.EVENT_TILE_REACHABLE and not self.tileData.blocked and tileType == hackingConst.TYPE_NONE:
    107             uicore.animations.BlinkIn(self, duration=0.1, loops=3)
    108         elif eventID == hackingConst.EVENT_TILE_CREATED and self.tileData.type == hackingConst.TYPE_SEGMENT:
    109             uthread.new(self.AnimBlinkFirstSegment)
    110 
    111     def AnimBlinkFirstSegment(self):
    112         uicore.animations.BlinkIn(self.mouseHoverSprite, timeOffset=0.6, loops=2, duration=0.15)
    113         blue.synchro.SleepSim(1200)
    114         uicore.animations.FadeOut(self.mouseHoverSprite, duration=0.6)
    115 
    116     def GetTileBackgroundTexturePath(self):
    117         tileType = self.tileData.type
    118         if tileType == hackingConst.TYPE_NONE:
    119             if not self.tileData.IsFlippable() or self.tileData.blocked:
    120                 return 'res:/UI/Texture/classes/hacking/tileBlocked.png'
    121             else:
    122                 return 'res:/UI/Texture/classes/hacking/tileUnflipped.png'
    123         else:
    124             if tileType in (hackingConst.TYPE_DATACACHE, hackingConst.TYPE_SEGMENT, hackingConst.TYPE_UTILITYELEMENTTILE):
    125                 return self.GetEmptySegmentTexturePath()
    126             return 'res:/UI/Texture/classes/hacking/tileIconFrame.png'
    127 
    128     def GetTileBackgroundColor(self):
    129         tileType = self.tileData.type
    130         if tileType == hackingConst.TYPE_CORE:
    131             return hackingUIConst.COLOR_BY_SUBTYPE[self.tileData.subtype]
    132         elif self.tileData.blocked and tileType == hackingConst.TYPE_NONE:
    133             return hackingUIConst.COLOR_DEFENSE
    134         elif not self.tileData.IsFlippable():
    135             return hackingUIConst.COlOR_UNREACHABLE
    136         else:
    137             return hackingUIConst.COLOR_TILE_BG_BY_TYPE.get(tileType, hackingUIConst.COLOR_UNFLIPPED)
    138 
    139     def GetIconTexturePath(self):
    140         tileType = self.tileData.type
    141         if tileType == hackingConst.TYPE_DATACACHE:
    142             return 'res:/UI/Texture/classes/hacking/tileDataCache.png'
    143         elif tileType in (hackingConst.TYPE_DEFENSESOFTWARE, hackingConst.TYPE_CORE, hackingConst.TYPE_UTILITYELEMENTTILE):
    144             return hackingUIConst.ICONPATH_BY_SUBTYPE[self.tileData.subtype]
    145         else:
    146             return None
    147 
    148     def GetEmptySegmentTexturePath(self):
    149         if not self.emptySegmentTexturePath:
    150             self.emptySegmentTexturePath = random.choice(hackingUIConst.ICONPATHS_INFECTED)
    151         return self.emptySegmentTexturePath
    152 
    153     def ConstructMarkerSprite(self):
    154         if self.utilElementMarkerSprite is None:
    155             self.utilElementMarkerSprite = Sprite(name='utilElementMarkerSprite', bgParent=self, texturePath='res:/UI/Texture/classes/hacking/utilTileMouseDown.png', opacity=0.0, padding=-20)
    156 
    157     def ShowCoherence(self):
    158         self.ConstructCoherenceCont()
    159         self.coherenceCont.Show()
    160         self.coherenceCont.SetValue(self.tileData.coherence)
    161 
    162     def ConstructCoherenceCont(self):
    163         if self.coherenceCont is None:
    164             self.coherenceCont = StatContainer(name='coherenceCont', statType=hackingUIConst.STAT_COHERENCE, parent=self, align=uiconst.CENTERTOP, top=-3)
    165 
    166     def HideCoherence(self):
    167         if self.coherenceCont:
    168             self.coherenceCont.Hide()
    169 
    170     def ShowStrength(self):
    171         self.ConstructStrengthCont()
    172         self.strengthCont.Show()
    173         self.strengthCont.SetValue(self.tileData.strength)
    174 
    175     def ConstructStrengthCont(self):
    176         if self.strengthCont is None:
    177             self.strengthCont = StatContainer(name='strengthCont', statType=hackingUIConst.STAT_STRENGTH, parent=self, align=uiconst.CENTERBOTTOM, top=-3)
    178 
    179     def HideStrength(self):
    180         if self.strengthCont:
    181             self.strengthCont.Hide()
    182 
    183     def ShowDistanceIndicator(self):
    184         if self.distanceIndicatorCont is None:
    185             self.distanceIndicatorCont = eveLabel.Label(name='distanceIndicatorCont', parent=self, align=uiconst.CENTER, fontsize=fontconst.EVE_SMALL_FONTSIZE, text=self.tileData.distanceIndicator, idx=0)
    186         uicore.animations.BlinkIn(self.distanceIndicatorCont, duration=0.1, loops=3)
    187         blue.synchro.SleepSim(1200)
    188         uicore.animations.FadeOut(self.distanceIndicatorCont, duration=0.6)
    189         self.tileData.distanceIndicator = 0
    190 
    191     def OnSelectedUtilityElementChanged(self, selected):
    192         if self.IsAttackable(self.tileData.type) and selected is not None:
    193             self.ConstructMarkerSprite()
    194             uicore.animations.FadeTo(self.utilElementMarkerSprite, 0.2, 1.0, duration=1.2, curveType=uiconst.ANIM_WAVE, loops=uiconst.ANIM_REPEAT)
    195         elif self.utilElementMarkerSprite:
    196             uicore.animations.FadeOut(self.utilElementMarkerSprite, duration=0.2, callback=self.utilElementMarkerSprite.Close)
    197             self.utilElementMarkerSprite = None
    198 
    199     def OnHackingUEDurationReduced(self, index, coord):
    200         if coord == self.tileData.coord:
    201             self.ConstructMarkerSprite()
    202             uicore.animations.FadeTo(self.utilElementMarkerSprite, 0.8, 0.0, duration=0.6)
    203 
    204     def GetTileHint(self):
    205         if self.tileData.blocked:
    206             ret = localization.GetByLabel('UI/Hacking/BlockedNode')
    207         elif self.tileData.subtype in hackingUIConst.DS_HINTS_BY_SUBTYPE:
    208             ret = localization.GetByLabel(hackingUIConst.DS_HINTS_BY_SUBTYPE[self.tileData.subtype])
    209         else:
    210             ret = localization.GetByLabel(hackingUIConst.HINTS_BY_TILE_TYPE[self.tileData.type])
    211         return ret
    212 
    213     def OnMouseEnter(self, *args):
    214         if self.tileData.blocked or not self.tileData.IsFlippable():
    215             return
    216         sm.GetService('audio').SendUIEvent('minigame_node' + str(len(self.tileData.neighbourTiles)))
    217         sm.GetService('hackingUI').SetTileHint(self.GetTileHint())
    218         color = Color(*self.bgColor).SetBrightness(1.0).GetRGBA()
    219         uicore.animations.SpColorMorphTo(self.tileBgSprite, self.tileBgSprite.GetRGBA(), color, duration=0.3)
    220         if self.HasLargeIcon():
    221             uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), Color.WHITE, duration=0.3)
    222         else:
    223             uicore.animations.FadeIn(self.mouseHoverSprite, duration=0.3)
    224         if self.IsAttackable(self.tileData.type):
    225             uicore.animations.Tr2DScaleTo(self.tileBgTransform, (1.0, 1.0), (1.05, 1.05), duration=0.8, curveType=uiconst.ANIM_WAVE)
    226 
    227     def OnMouseExit(self, *args):
    228         sm.GetService('hackingUI').SetTileHint(None)
    229         uicore.animations.SpColorMorphTo(self.tileBgSprite, self.tileBgSprite.GetRGBA(), self.bgColor, duration=0.3)
    230         uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), Color.WHITE, duration=0.3)
    231         if self.HasLargeIcon():
    232             uicore.animations.SpColorMorphTo(self.iconSprite, self.iconSprite.GetRGBA(), self.iconColor, duration=0.3)
    233         else:
    234             uicore.animations.FadeOut(self.mouseHoverSprite, duration=0.3)
    235 
    236     def OnMouseMove(self, *args):
    237         l, t = self.GetAbsolutePosition()
    238         x = 2.0 * (uicore.uilib.x - l) / float(hackingUIConst.TILE_SIZE) - 1.0
    239         y = 2.0 * (uicore.uilib.y - t) / float(hackingUIConst.TILE_SIZE) - 1.0
    240         z = (x ** 2 + y ** 2) ** 0.5
    241         val = 99 * (1.0 - min(1.0, z))
    242         sm.GetService('audio').SetGlobalRTPC('minigame_mouseover', val)
    243 
    244     def OnMouseDown(self, *args):
    245         uthread.new(sm.GetService('hackingUI').OnTileClicked, self.tileData.coord)
    246 
    247     def IsAttackable(self, type):
    248         return type in (hackingConst.TYPE_CORE, hackingConst.TYPE_DEFENSESOFTWARE)
    249 
    250     def HasLargeIcon(self):
    251         return self.tileData.type in (hackingConst.TYPE_CORE, hackingConst.TYPE_DEFENSESOFTWARE, hackingConst.TYPE_UTILITYELEMENTTILE)
    252 
    253     def OnCoreUnveiled(self, coord):
    254         if coord == self.tileData.coord:
    255             uicore.animations.BlinkIn(self.iconSprite, loops=3, duration=0.2)
    256 
    257     def OnDefenseSoftwareUnveiled(self, coord):
    258         if coord == self.tileData.coord:
    259             uicore.animations.FadeTo(self.iconSprite, 0.0, 1.0, duration=0.3, timeOffset=0.2)
    260 
    261     def OnHoneyPotHealed(self, sourceCoord, healedCoord, amount):
    262         if sourceCoord == self.tileData.coord:
    263             self.ConstructHealingGivenSprite()
    264             duration = 0.5
    265             curve = ((0.0, 0),
    266              (0.2, 100),
    267              (0.8, 100),
    268              (1.0, 0))
    269             uicore.animations.MorphScalar(self.healingGivenSprite, 'width', duration=duration, curveType=curve)
    270             uicore.animations.MorphScalar(self.healingGivenSprite, 'height', duration=duration, curveType=curve)
    271             curve = ((0.0, 0.0),
    272              (0.2, 1.0),
    273              (0.8, 1.0),
    274              (1.0, 0.0))
    275             uicore.animations.FadeTo(self.healingGivenSprite, 0.0, 1.0, duration=duration, curveType=curve)
    276         elif healedCoord == self.tileData.coord:
    277             self.ConstructHealingReceivedSprite()
    278             duration = 0.2
    279             timeOffset = 0.1
    280             loops = 2
    281             uicore.animations.MorphScalar(self.healingReceivedSprite, 'width', 128, 0, duration=duration, timeOffset=timeOffset, loops=loops)
    282             uicore.animations.MorphScalar(self.healingReceivedSprite, 'height', 128, 0, duration=duration, timeOffset=timeOffset, loops=loops)
    283             uicore.animations.FadeTo(self.healingReceivedSprite, 0.0, 1.0, duration=duration, curveType=uiconst.ANIM_WAVE, timeOffset=timeOffset, loops=loops)
    284 
    285     def OnCoreContentsRevealed(self, coord, contentsList):
    286         if coord == self.tileData.coord:
    287             text = 'Contents:'
    288             for entry in contentsList:
    289                 text = text + '<br>' + str(entry[1]) + 'x ' + evetypes.GetName(entry[0])
    290 
    291             self.hint = text
    292 
    293     def ConstructHealingGivenSprite(self):
    294         if self.healingGivenSprite is None:
    295             self.healingGivenSprite = Sprite(name='healingGivenSprite', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=hackingUIConst.COLOR_UNEXPLORED, texturePath='res:/UI/Texture/classes/hacking/healRing1.png', opacity=0.0)
    296 
    297     def ConstructHealingReceivedSprite(self):
    298         if self.healingReceivedSprite is None:
    299             self.healingReceivedSprite = Sprite(name='healingReceivedSprite', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=hackingUIConst.COLOR_UNEXPLORED, texturePath='res:/UI/Texture/classes/hacking/healRing2.png', opacity=0.0)