hackingWindow.py (9796B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\hacking\hackingWindow.py 2 import random 3 import evetypes 4 import hackingcommon.hackingConstants as hackingConst 5 import localization 6 import trinity 7 import uthread 8 from carbon.common.script.sys.serviceConst import ROLE_QA 9 from carbonui import fontconst, uiconst 10 from carbonui.control.contextMenu.menuDataFactory import CreateMenuDataFromRawTuples 11 from carbonui.control.window import Window 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.containerAutoSize import ContainerAutoSize 14 from carbonui.primitives.sprite import StreamingVideoSprite 15 from carbonui.primitives.transform import Transform 16 from clientsettings.setting import UserSettingBool 17 from carbonui.uicore import uicore 18 from carbonui.util.color import Color 19 from eve.client.script.ui.control import eveLabel 20 from eve.client.script.ui.hacking import hackingLine, hackingTile, hackingUIConst, hackingUtilityElement, hackingVirusInfo 21 QA_SHOW_TILES_SETTING = UserSettingBool('Hacking_QA_showTiles', False) 22 23 class HackingWindow(Window): 24 __guid__ = 'form.HackingWindow' 25 __notifyevents__ = ['OnHackingNewTurn', 26 'OnHackingWon', 27 'OnHackingLost', 28 'OnDefenseSoftwareUnveiled', 29 'OnCoreUnveiled', 30 'OnHackingTileCreated', 31 'OnHackingTileChanged', 32 'OnHackingStart', 33 'OnHackingUEInventoryConstructed'] 34 default_windowID = 'HackingWindow' 35 default_caption = 'Hacking' 36 default_width = 898 37 default_height = 647 38 default_fixedWidth = default_width 39 default_fixedHeight = default_height 40 default_isCollapseable = False 41 default_isStackable = False 42 default_extend_content_into_header = True 43 default_apply_content_padding = False 44 45 def ApplyAttributes(self, attributes): 46 Window.ApplyAttributes(self, attributes) 47 sm.RegisterNotify(self) 48 self.tilesByTileCoord = {} 49 self.linesByTileCoords = {} 50 self.utilityElements = [] 51 self.accessibleTiles = [] 52 self.hasGameEnded = False 53 self.header.show_caption = False 54 self.hasWindowIcon = False 55 self.bottomCont = Container(name='bottomCont', parent=self.content, align=uiconst.TOBOTTOM, height=110) 56 self.tileHintLabel = eveLabel.Label(name='tileHintLabel', parent=self.bottomCont, align=uiconst.BOTTOMRIGHT, pos=(15, 15, 220, 0), fontsize=fontconst.EVE_SMALL_FONTSIZE) 57 self.utilityElementContainer = ContainerAutoSize(name='utilityElementContainer', parent=self.bottomCont, align=uiconst.CENTERBOTTOM, state=uiconst.UI_PICKCHILDREN, opacity=1.0, height=50, top=10) 58 self.virusInfo = hackingVirusInfo.VirusInfo(parent=self.bottomCont, left=15, top=10, opacity=0.0) 59 self.boardTransform = Transform(name='boardTransform', parent=self.content, align=uiconst.TOALL, padTop=32, state=uiconst.UI_NORMAL, scalingCenter=(0.5, 0.5)) 60 self.boardContainer = Container(name='boardContainer', parent=self.boardTransform, align=uiconst.TOPLEFT, opacity=0.0) 61 self.backgroundVideo = StreamingVideoSprite(bgParent=self.sr.maincontainer, padTop=16, videoPath='res:/video/hacking/bgLoop_alpha.webm', videoLoop=True, spriteEffect=trinity.TR2_SFX_COPY, color=hackingUIConst.COLOR_WINDOW_BG, opacity=0.0) 62 sm.GetService('audio').SendUIEvent('minigame_start') 63 64 def Close(self, *args, **kw): 65 Window.Close(self, *args, **kw) 66 sm.GetService('audio').SendUIEvent('minigame_stop') 67 68 def CloseByUser(self, *args): 69 uthread.new(sm.GetService('hackingUI').QuitHackingAttempt) 70 71 def EntryAnimation(self): 72 uicore.animations.Tr2DScaleTo(self.boardTransform, startScale=(0.99, 0.99), endScale=(1.0, 1.0), duration=0.8) 73 uicore.animations.FadeTo(self.backgroundVideo, 0.0, hackingUIConst.COLOR_WINDOW_BG[3], duration=1.6) 74 uicore.animations.FadeIn(self.boardContainer, duration=0.8) 75 uicore.animations.FadeIn(self.virusInfo, duration=0.8, timeOffset=0.3) 76 uicore.animations.FadeIn(self.utilityElementContainer, duration=0.8, timeOffset=0.6) 77 78 def OnHackingWon(self): 79 self.EndGame(True) 80 81 def OnHackingLost(self): 82 self.EndGame(False) 83 84 def OnHackingTileChanged(self, eventID, tileData): 85 self.tilesByTileCoord[tileData.coord].UpdateTileState(eventID, tileData) 86 self.UpdateLineColors() 87 for neighbour in tileData.GetNeighbours(): 88 if neighbour.coord in self.tilesByTileCoord: 89 self.tilesByTileCoord[neighbour.coord].UpdateTileState(hackingConst.EVENT_TILE_REACHABLE, tileData) 90 91 def OnHackingTileCreated(self, tileData, objectData): 92 if tileData.coord in self.tilesByTileCoord: 93 self.OnHackingTileChanged(hackingConst.EVENT_TILE_CREATED, tileData) 94 else: 95 left, top = tileData.GetXY() 96 tile = hackingTile.Tile(parent=self.boardContainer, left=left, top=top, tileData=tileData, showCoordLabel=QA_SHOW_TILES_SETTING.is_enabled()) 97 self.tilesByTileCoord[tileData.coord] = tile 98 99 def OnHackingUEInventoryConstructed(self, inventoryContents): 100 for i, elementData in enumerate(inventoryContents): 101 elementUI = hackingUtilityElement.UtilityElement(parent=self.utilityElementContainer, utilityElementData=elementData, index=i) 102 self.utilityElements.append(elementUI) 103 104 def OnHackingStart(self, eventData): 105 self.SetBoardSize() 106 if eventData['moduleTypeID']: 107 self.SetCaption(evetypes.GetName(eventData['moduleTypeID'])) 108 for tile in self.tilesByTileCoord.values(): 109 self.ConstructLinesForTile(tile.tileData) 110 111 self.EntryAnimation() 112 113 def SetBoardSize(self): 114 x = y = 0 115 for tile in self.tilesByTileCoord.values(): 116 hexX, hexY = tile.tileData.GetHexXY() 117 if hexX > x: 118 x = hexX 119 if hexY > y: 120 y = hexY 121 122 self.boardContainer.width = x * hackingUIConst.GRID_X + hackingUIConst.TILE_SIZE 123 self.boardContainer.height = y * hackingUIConst.GRID_Y + hackingUIConst.TILE_SIZE 124 offsetY = int(hackingUIConst.GRID_MAX_ROWS - y - 1) / 2 125 self.boardContainer.top = 16 + offsetY * hackingUIConst.GRID_Y 126 offsetX = int(hackingUIConst.GRID_MAX_COLUMNS - x + 0.5) / 2 127 if offsetY % 2 == 1: 128 offsetX -= 0.5 129 self.boardContainer.left = 15 + offsetX * hackingUIConst.GRID_X 130 131 def OnDefenseSoftwareUnveiled(self, coord): 132 uicore.animations.SpColorMorphTo(self.backgroundVideo, hackingUIConst.COLOR_WINDOW_BG_BLINK, hackingUIConst.COLOR_WINDOW_BG, duration=0.6) 133 134 def OnCoreUnveiled(self, coord): 135 uicore.animations.SpColorMorphTo(self.backgroundVideo, hackingUIConst.COLOR_WINDOW_BG_BLINK, hackingUIConst.COLOR_WINDOW_BG, duration=0.15, loops=3) 136 137 def EndGame(self, won): 138 self.boardContainer.Disable() 139 text = localization.GetByLabel('UI/Hacking/HackSuccess') if won else localization.GetByLabel('UI/Hacking/HackFailed') 140 label = eveLabel.Label(parent=self.content, align=uiconst.CENTER, text=text, bold=True, fontsize=30, idx=0, color=Color.WHITE) 141 uicore.animations.FadeTo(self.boardContainer, 1.0, 0.5, duration=1.0) 142 uicore.animations.FadeOut(self.utilityElementContainer, duration=0.6) 143 uicore.animations.FadeOut(self.virusInfo, duration=0.6, timeOffset=0.3) 144 uicore.animations.FadeTo(label, 0.0, 1.0, duration=0.6, timeOffset=0.2) 145 color = hackingUIConst.COLOR_EXPLORED if won else hackingUIConst.COLOR_UNEXPLORED 146 lines = self.linesByTileCoords.values() 147 random.shuffle(lines) 148 for i, line in enumerate(lines): 149 line.AnimExit(i) 150 151 tiles = self.tilesByTileCoord.values() 152 random.shuffle(tiles) 153 for i, tile in enumerate(tiles): 154 uicore.animations.FadeTo(tile, tile.opacity, 0.0, timeOffset=0.2 + i * 0.01, duration=0.2) 155 156 uicore.animations.Tr2DScaleOut(self.boardTransform, endScale=(0.99, 0.99), duration=10.0) 157 uicore.animations.FadeOut(self, duration=1.6, callback=self.Close) 158 159 def UpdateLineColors(self): 160 for line in self.linesByTileCoords.values(): 161 line.UpdateState() 162 163 def ConstructLinesForTile(self, tileData): 164 for neighbour in tileData.GetNeighbours(): 165 lineID = [tileData.coord, neighbour.coord] 166 lineID.sort() 167 lineID = tuple(lineID) 168 tile1 = self.tilesByTileCoord[lineID[0]] 169 tile2 = self.tilesByTileCoord[lineID[1]] 170 if lineID in self.linesByTileCoords: 171 continue 172 line = hackingLine.Line(tileFrom=tile1, tileTo=tile2, parent=self.boardContainer) 173 self.linesByTileCoords[lineID] = line 174 175 def OnKeyDown(self, key, *args): 176 if key == uiconst.VK_1: 177 self.utilityElements[0].OnClick() 178 elif key == uiconst.VK_2: 179 self.utilityElements[1].OnClick() 180 elif key == uiconst.VK_3: 181 self.utilityElements[2].OnClick() 182 183 def SetTileHint(self, hint): 184 if hint: 185 self.tileHintLabel.text = '<right>' + hint + '</right>' 186 if self.tileHintLabel.opacity < 0.01: 187 uicore.animations.FadeTo(self.tileHintLabel, self.tileHintLabel.opacity, 1.0, duration=0.3, timeOffset=0.6) 188 else: 189 uicore.animations.FadeTo(self.tileHintLabel, self.tileHintLabel.opacity, 1.0, duration=0.3) 190 else: 191 uicore.animations.FadeOut(self.tileHintLabel, duration=0.1) 192 193 def GetMenu(self, *args): 194 menuData = CreateMenuDataFromRawTuples(Window.GetMenu(self, *args)) 195 if session.role & ROLE_QA: 196 menuData.AddCheckbox('QA - Show tiles', setting=QA_SHOW_TILES_SETTING) 197 return menuData