expandedSovHubEntry.py (12150B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\Alliances\sovHubs\expandedSovHubEntry.py 2 import math 3 import carbonui.text.styles 4 from collections import defaultdict, OrderedDict 5 import carbonui 6 import eveicon 7 import evetypes 8 import uthread 9 from carbonui.control.button import Button 10 from carbonui.control.scrollentries import SE_BaseClassCore 11 from carbonui.primitives.container import Container 12 from carbonui.primitives.sprite import Sprite 13 from carbonui.primitives.vectorlinetrace import VectorLineTrace 14 from eve.client.script.ui import eveColor 15 from eve.client.script.ui.shared.mapView.markers.mapMarkerScanResult import Circle 16 from eve.client.script.ui.shared.sov.sovHub.editSections import TransitCont 17 from eve.client.script.ui.shared.sov.sovHub.fuelConts import FuelMagmaCont, FuelIceCont 18 from eve.client.script.ui.shared.sov.sovHub.resourceConts import PowerCont, WorkforceCont 19 import carbonui.const as uiconst 20 from eve.client.script.ui.shared.sov.threadedLoader import ThreadedLoader 21 from eveexceptions import ExceptionEater 22 from inventorycommon.const import typeSkyhook 23 from localization import GetByLabel 24 from sovereignty.client.quasarCallWrapper import DATA_NOT_AVAILABLE 25 from sovereignty.client.sovHub.hubUtil import GetTexturePathForUpgradeTypeList, GetAllUpgradeTypeLists 26 27 class ExpandedSovHubEntry(SE_BaseClassCore): 28 ENTRYHEIGHT = 300 29 30 def ApplyAttributes(self, attributes): 31 super(ExpandedSovHubEntry, self).ApplyAttributes(attributes) 32 self.threadedLoader = ThreadedLoader('ExpandedSovHubEntry') 33 self.node = attributes.node 34 self.entryController = self.node.entryController 35 contentCont = Container(name='contentCont', parent=self) 36 topCont = Container(name='topCont', parent=contentCont, align=carbonui.Align.TOTOP, height=40, top=20, padBottom=20, padLeft=24) 37 editCont = Container(name='editCont', parent=topCont, align=carbonui.Align.TORIGHT, left=10, width=30) 38 self.nameLabel = carbonui.text.styles.TextHeader(parent=topCont, text='', align=carbonui.Align.TOTOP, maxLines=1, autoFadeSides=30) 39 self.locationLabel = carbonui.text.styles.TextDetail(parent=topCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP, top=2, maxLines=1, autoFadeSides=30) 40 editButton = Button(parent=editCont, label=GetByLabel('UI/Sovereignty/HubPage/EditStructure'), align=carbonui.Align.TOPRIGHT, texturePath=eveicon.open_window, func=lambda *args: self.entryController.OpenSovHubWindow()) 41 editCont.width = editButton.width 42 lowerContentCont = Container(name='lowerContentCont', parent=contentCont, padLeft=8) 43 topPad = 30 44 labelTop = 170 45 upgradeCont = Container(name='upgradeCont', parent=lowerContentCont, align=carbonui.Align.TOLEFT, width=145) 46 carbonui.text.styles.TextDetail(parent=upgradeCont, text=GetByLabel('UI/Sovereignty/HubPage/Upgrades'), color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP, padLeft=16) 47 self.upgradeGraph = UpgradeGraph(parent=upgradeCont, align=carbonui.Align.TOPLEFT, top=10, radius=55) 48 self.upgradeLabel = carbonui.text.styles.TextDetail(parent=upgradeCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERTOP, top=labelTop) 49 lavaCont = Container(name='lavaCont', parent=lowerContentCont, align=carbonui.Align.TOLEFT, width=120) 50 carbonui.text.styles.TextDetail(parent=lavaCont, text=GetByLabel('UI/Sovereignty/HubPage/Fuel'), color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP) 51 self.fuelMagmaCont = FuelMagmaCont(parent=lavaCont, align=carbonui.Align.TOPLEFT, top=topPad, hubController=self.entryController) 52 self.lavaLabel = carbonui.text.styles.TextDetail(parent=lavaCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERTOP, top=labelTop) 53 iceCont = Container(name='iceCont', parent=lowerContentCont, align=carbonui.Align.TOLEFT, width=120) 54 self.fuelIceCont = FuelIceCont(parent=iceCont, align=carbonui.Align.TOPLEFT, top=topPad, hubController=self.entryController) 55 self.iceLabel = carbonui.text.styles.TextDetail(parent=iceCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERTOP, top=labelTop) 56 resourceCont = Container(name='resourceCont', parent=lowerContentCont, align=carbonui.Align.TOLEFT, width=300) 57 self.powerCont = PowerCont(parent=resourceCont, align=carbonui.Align.TOTOP, gaugeHeight=4, controller=self.entryController, useLegend=False, isCompact=True, padBottom=10) 58 self.workforceCont = WorkforceCont(parent=resourceCont, align=carbonui.Align.TOTOP, gaugeHeight=4, controller=self.entryController, useLegend=False, isCompact=True, padBottom=10) 59 self.transitCont = TransitCont(parent=resourceCont, align=carbonui.Align.TOTOP, workforceController=self.entryController.workforceController, canEdit=False) 60 self.transitCont.section_loaded.connect(self.TransitContLoaded) 61 skyhookCont = Container(parent=lowerContentCont, align=carbonui.Align.TOLEFT, width=100, padLeft=30) 62 skyhookColor = eveColor.SMOKE_BLUE[:3] + (0.6,) 63 Sprite(parent=skyhookCont, align=carbonui.Align.CENTERLEFT, pos=(0, 0, 125, 200), texturePath='res:/UI/Texture/classes/Sov/skyhook.png', color=skyhookColor, pickState=carbonui.PickState.OFF) 64 self.numSkyhooks = carbonui.text.styles.TextHeadline(parent=skyhookCont, text='', align=carbonui.Align.TOPLEFT, pos=(60, 60, 0, 0)) 65 carbonui.text.styles.TextBody(parent=skyhookCont, text=evetypes.GetName(typeSkyhook), color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOPLEFT, pos=(60, 85, 0, 0)) 66 67 def Load(self, node): 68 if self.destroyed: 69 return 70 self.nameLabel.text = self.entryController.GetHubName() 71 self.locationLabel.text = self.entryController.GetLocation() 72 self.threadedLoader.StartLoading(self.LoadPowerWorkforceAsync, self) 73 self.threadedLoader.StartLoading(self.LoadTextAcync, self) 74 self.threadedLoader.StartLoading(self.transitCont.LoadSection, self) 75 self.threadedLoader.StartLoading(self.fuelMagmaCont.LoadUI, self.fuelMagmaCont) 76 self.threadedLoader.StartLoading(self.fuelIceCont.LoadUI, self.fuelIceCont) 77 self.threadedLoader.StartLoading(self.LoadSkyhookLabel, self) 78 79 def LoadPowerWorkforceAsync(self): 80 uthread.parallel([(self.powerCont.LoadCont, ()), (self.workforceCont.LoadCont, ())]) 81 82 def LoadTextAcync(self): 83 results = uthread.parallel([(self.entryController.GetUpgradesTextLong, ()), 84 (self.entryController.GetLavaText, ()), 85 (self.entryController.GetIceText, ()), 86 (self.entryController.GetInstalledUpgrades, ())]) 87 upgradeText, lavaText, iceText, installedUpgrades = results 88 if self.destroyed: 89 return 90 self.upgradeLabel.text = upgradeText 91 self.lavaLabel.text = lavaText 92 self.iceLabel.text = iceText 93 self.upgradeGraph.UpdatePoints(installedUpgrades) 94 95 def LoadSkyhookLabel(self): 96 numSkyhooks = self.entryController.GetNumSkyhooks() 97 self.numSkyhooks.text = numSkyhooks 98 99 @classmethod 100 def GetDynamicHeight(cls, node, width = None): 101 return node.height or cls.ENTRYHEIGHT 102 103 def TransitContLoaded(self): 104 if self.destroyed: 105 return 106 tw, th = self.transitCont.GetAbsoluteSize() 107 newHeight = 210 + th 108 if newHeight <= self.ENTRYHEIGHT: 109 return 110 self.node.height = newHeight 111 self.node.scroll.RefreshNodes() 112 113 def Close(self): 114 with ExceptionEater('Closing ExpandedSovHubEntry'): 115 self.entryController = None 116 super(ExpandedSovHubEntry, self).Close() 117 118 119 class UpgradeGraph(Container): 120 default_align = carbonui.Align.TOPLEFT 121 default_width = 160 122 default_height = 160 123 124 def ApplyAttributes(self, attributes): 125 super(UpgradeGraph, self).ApplyAttributes(attributes) 126 self.radius = attributes.radius 127 numCircles = 5 128 radiusSteps = self.radius / numCircles 129 self.iconCont = Container(parent=self, align=carbonui.Align.CENTER, pos=(0, 130 0, 131 self.width, 132 self.height)) 133 lineCont = Container(parent=self, align=carbonui.Align.CENTER, pos=(0, 134 0, 135 self.width, 136 self.height)) 137 self.onlineVectorLine = VectorLineTrace(name='onlineVectorLine', parent=lineCont, lineWidth=1.3, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, align=carbonui.Align.CENTER, opacity=1.3, isLoop=True) 138 self.totalVectorLine = VectorLineTrace(name='totalVectorLine', parent=lineCont, lineWidth=1.0, outputMode=uiconst.OUTPUT_COLOR, align=carbonui.Align.CENTER, isLoop=True) 139 for i in xrange(1, numCircles + 1): 140 r = i * radiusSteps 141 c = Container(parent=self, align=carbonui.Align.CENTER, pos=(0, 142 0, 143 2 * r, 144 2 * r)) 145 circle = Circle(parent=c, radius=r, color=eveColor.TUNGSTEN_GREY, opacity=0.5, lineWidth=0.5) 146 147 def UpdatePoints(self, upgradeDataList): 148 self.iconCont.Flush() 149 self.onlineVectorLine.Flush() 150 self.totalVectorLine.Flush() 151 if upgradeDataList == DATA_NOT_AVAILABLE: 152 return 153 typeIDsByListID = OrderedDict() 154 numUpgradesByTypeList = OrderedDict() 155 upgradeTypeLists = GetAllUpgradeTypeLists() 156 for typeListID in upgradeTypeLists: 157 typeIDsByListID[typeListID] = evetypes.GetTypeIDsByListID(typeListID) 158 numUpgradesByTypeList[typeListID] = 0 159 160 onlineNumPerTypeList = numUpgradesByTypeList.copy() 161 for upgrade in upgradeDataList: 162 currentListID = None 163 for listID, typeIDs in typeIDsByListID.iteritems(): 164 if upgrade.typeID in typeIDs: 165 currentListID = listID 166 break 167 168 if currentListID is None: 169 continue 170 numUpgradesByTypeList[currentListID] += 1 171 if upgrade.isPowerStateFunctional: 172 onlineNumPerTypeList[currentListID] += 1 173 174 maxNum = max(numUpgradesByTypeList.values()) 175 degreeStep = 360 / len(numUpgradesByTypeList) 176 maxValue = self.radius - 3 177 iconOffset = self.radius + 12 178 totalVectorPoints = [] 179 onlineVectorPoints = [] 180 textureAndPos = [] 181 angle = 180 182 for typeListID, numUpgrades in numUpgradesByTypeList.iteritems(): 183 angle += degreeStep 184 angle_rad = math.radians(angle) 185 if maxNum: 186 totalProp = float(numUpgrades) / maxNum 187 totalProp = max(0.1, totalProp) 188 totalR = totalProp * maxValue 189 tX = totalR * math.sin(angle_rad) 190 tY = totalR * math.cos(angle_rad) 191 totalVectorPoints.append((tX, tY)) 192 numOnline = onlineNumPerTypeList[typeListID] 193 onlineProp = float(numOnline) / maxNum 194 onlineProp = max(0.1, onlineProp) 195 onlineR = onlineProp * maxValue 196 oX = onlineR * math.sin(angle_rad) 197 oY = onlineR * math.cos(angle_rad) 198 onlineVectorPoints.append((oX, oY)) 199 texturePath = GetTexturePathForUpgradeTypeList(typeListID) 200 iX = iconOffset * math.sin(angle_rad) 201 iY = iconOffset * math.cos(angle_rad) 202 textureAndPos.append((iX, 203 iY, 204 texturePath, 205 typeListID)) 206 207 for pointList, vectorLine, color in ((onlineVectorPoints, self.onlineVectorLine, eveColor.CRYO_BLUE), (totalVectorPoints, self.totalVectorLine, eveColor.GUNMETAL_GREY)): 208 if pointList: 209 vectorLine.AddPoints(pointList, color) 210 211 for x, y, texturePath, typeListID in textureAndPos: 212 s = Sprite(parent=self.iconCont, pos=(x, 213 y, 214 16, 215 16), align=carbonui.Align.CENTER, texturePath=texturePath, opacity=0.3) 216 s.hint = evetypes.GetTypeListDisplayName(typeListID)