sovHubEntry.py (13501B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\Alliances\sovHubs\sovHubEntry.py 2 import carbonui.text.styles 3 from collections import OrderedDict 4 import carbonui 5 import eveicon 6 import uthread 7 import uthread2 8 from carbon.client.script.environment.AudioUtil import PlaySound 9 from carbon.common.script.util.timerstuff import AutoTimer 10 from carbonui import const as uiconst, TextColor 11 from carbonui.control.contextMenu.menuEntryData import MenuEntryData 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.sprite import Sprite 14 from carbonui.uicore import uicore 15 from eve.client.script.ui import eveColor 16 from eve.client.script.ui.control.baseListEntry import BaseListEntryCustomColumns 17 from eve.client.script.ui.control.eveLabel import Label 18 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 19 from eve.client.script.ui.control.glowSprite import GlowSprite 20 from eve.client.script.ui.shared.neocom.Alliances.sovHubs.sovHubEntryController import UNDEFINED 21 from eve.client.script.ui.shared.sov.threadedLoader import ThreadedLoader 22 from eveexceptions import ExceptionEater 23 from eveservices.menu import GetMenuService 24 from eveui import animation 25 from localization import GetByLabel 26 from menu import MenuLabel 27 from sovereignty.client.quasarCallWrapper import DATA_NOT_AVAILABLE 28 29 class ColumnInfo(object): 30 31 def __init__(self, labelPath, hintPath = None, defaultWidth = None, valueStorageAttribute = None): 32 self._labelPath = labelPath 33 self._hintPath = hintPath 34 self._defaultWidth = defaultWidth 35 self._valueStorageAttribute = valueStorageAttribute 36 37 @property 38 def columnText(self): 39 if self._labelPath: 40 return GetByLabel(self._labelPath) 41 return '' 42 43 @property 44 def defaultWidth(self): 45 if self._defaultWidth: 46 return self._defaultWidth 47 48 @property 49 def hintText(self): 50 if self._hintPath: 51 return GetByLabel(self._hintPath) 52 53 @property 54 def valueStorageAttribute(self): 55 return self._valueStorageAttribute 56 57 58 class SovHubEntry(BaseListEntryCustomColumns): 59 default_name = 'SovHubEntry' 60 isDragObject = True 61 dblclick = 0 62 default_height = 30 63 default_bgColor = eveColor.WHITE[:3] + (0.1,) 64 headerInfo = d = OrderedDict() 65 d['sovHubName'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnSovHub', None, 100) 66 d['jumps'] = ColumnInfo('UI/Common/Jumps', None, 40) 67 d['region'] = ColumnInfo('UI/Common/LocationTypes/Region', None, 80) 68 d['upgrade'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnUpgrades', None, 60, 'upgradeSortValue') 69 d['power'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnPower', None, 100, 'powerSortValue') 70 d['workforce'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnWorkforce', None, 120, 'workforceSortValue') 71 d['transit'] = ColumnInfo('UI/Sovereignty/SovHub/HubWnd/WorceforceMode', None, 70, 'worceforceMode') 72 d['lavaFuel'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnLavaFuel', None, 80, 'lavaText') 73 d['iceFuel'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnIceFuel', None, 80, 'iceText') 74 d['vulnStatus'] = ColumnInfo('UI/Generic/Status', None, 100) 75 d['vulnHour'] = ColumnInfo('UI/Sovereignty/HubPage/ColumnVulnerabilityHour', None, 200) 76 77 def ApplyAttributes(self, attributes): 78 BaseListEntryCustomColumns.ApplyAttributes(self, attributes) 79 self.entryController = self.node.entryController 80 self.threadedLoader = ThreadedLoader('SovHubEntry') 81 self.expander = GlowSprite(parent=self, pos=(4, 0, 16, 16), name='expander', state=uiconst.UI_DISABLED, texturePath=eveicon.caret_right, align=uiconst.CENTERLEFT) 82 self.expander.OnClick = self.Toggle 83 self.AddStructureName() 84 self.AddJumps() 85 self.AddRegion() 86 self.AddUpgrades() 87 self.AddPower() 88 self.AddWorkforce() 89 self.AddWorkforceTransit() 90 self.AddLavaFuel() 91 self.AddIceFuel() 92 self.AddStatus() 93 self.AddVulnerabilityHour() 94 95 def AddStructureName(self): 96 cont = self.AddColumnContainer() 97 Sprite(parent=cont, align=carbonui.Align.CENTERLEFT, pos=(24, 0, 16, 16), texturePath=self.entryController.GetTexturePath(), color=eveColor.TUNGSTEN_GREY) 98 text = self.entryController.GetSolarSystemName() 99 Label(parent=cont, text=text, align=uiconst.CENTERLEFT, left=45) 100 101 def AddJumps(self): 102 jumps = self.entryController.GetJumpText() 103 col = self.AddLoadingLabelCont(jumps) 104 col.label.left = 0 105 col.label.SetAlign(carbonui.Align.CENTERRIGHT) 106 107 def AddRegion(self): 108 regionName = self.entryController.GetRegionName() 109 self.AddLoadingLabelCont(regionName) 110 111 def AddUpgrades(self): 112 self.upgradesLabelCont = self.AddLoadingLabelCont('') 113 114 def AddPower(self): 115 self.powerLabelCont = self.AddLoadingLabelCont('') 116 117 def AddWorkforce(self): 118 self.workforceLabelCont = self.AddLoadingLabelCont('') 119 120 def AddWorkforceTransit(self): 121 self.workforceTransit = self.AddLoadingLabelCont('') 122 self.workforceTransitSprite = Sprite(parent=self.workforceTransit, pos=(0, 0, 16, 16), align=carbonui.Align.CENTER, color=eveColor.TUNGSTEN_GREY) 123 124 def AddIceFuel(self): 125 self.iceFuelLabelCont = self.AddLoadingLabelCont('') 126 127 def AddLavaFuel(self): 128 self.lavaFuelLabelCont = self.AddLoadingLabelCont('') 129 130 def AddStatus(self): 131 text = self.entryController.GetVulnerabilityStateText() 132 self.AddLoadingLabelCont(text) 133 134 def AddVulnerabilityHour(self): 135 text = self.entryController.GetVulnerabilityTime() 136 col = self.AddLoadingLabelCont(text) 137 self.vulnerabilityHourLabel = col.label 138 self.vulnerability_thread = AutoTimer(500, self.UpdateVulnerabilityTimer) 139 140 def Load(self, node): 141 super(SovHubEntry, self).Load(node) 142 self.sr.id = node.id 143 isOpen = uicore.registry.GetListGroupOpenState(self.sr.id, False) 144 self.ShowOpenState(isOpen) 145 self.threadedLoader.StartLoading(self.LoadInfo, self) 146 147 def LoadInfo(self): 148 uthread2.StartTasklet(self.ShowDelayedLoading_thread, 0.5, [self.upgradesLabelCont, 149 self.powerLabelCont, 150 self.workforceLabelCont, 151 self.iceFuelLabelCont, 152 self.lavaFuelLabelCont]) 153 results = uthread.parallel([(self.entryController.GetUpgradesTextShort, ()), 154 (self.entryController.GetPowerColumnText, ()), 155 (self.entryController.GetWorkforceColumnText, ()), 156 (self.entryController.GetIceText, ()), 157 (self.entryController.GetLavaText, ()), 158 (self.entryController.GetTransitMode, ())]) 159 upgradeText, powerText, workforceText, iceFuelText, lavelFuelText, transit = results 160 if self.destroyed: 161 return 162 self.upgradesLabelCont.text = upgradeText 163 self.powerLabelCont.text = powerText 164 self.workforceLabelCont.text = workforceText 165 self.iceFuelLabelCont.text = iceFuelText 166 self.lavaFuelLabelCont.text = lavelFuelText 167 if transit == DATA_NOT_AVAILABLE: 168 self.workforceTransit.text = self.entryController.GetNotAvailableText() 169 else: 170 texturePath, hintText, info = transit 171 self.workforceTransitSprite.SetTexturePath(texturePath) 172 self.workforceTransitSprite.hint = hintText 173 174 def ShowDelayedLoading_thread(self, delaySec, labelConts): 175 for eachLabelCont in labelConts: 176 eachLabelCont.SetPendingLoadingAnimation() 177 178 uthread2.Sleep(delaySec) 179 if self.destroyed: 180 return 181 for eachLabelCont in labelConts: 182 if eachLabelCont.loadingAnimationPending: 183 eachLabelCont.SetLoadingState(True) 184 185 @classmethod 186 def GetHeaders(cls): 187 return [ x.columnText for x in cls.headerInfo.itervalues() ] 188 189 @staticmethod 190 def GetDefaultColumnWidth(*args): 191 return {x.columnText:x.defaultWidth for x in SovHubEntry.headerInfo.itervalues() if x.defaultWidth} 192 193 @staticmethod 194 def GetSortValue(node, by, direction, idx): 195 entryController = node.entryController 196 structureName = entryController.GetSolarSystemName() 197 if idx is None: 198 return structureName 199 headerKey = SovHubEntry.headerInfo.keys()[idx] 200 headerValue = SovHubEntry.headerInfo[headerKey] 201 valueStorageAttribute = headerValue.valueStorageAttribute 202 if valueStorageAttribute: 203 storage = entryController.valueStorage 204 val = getattr(storage, valueStorageAttribute, UNDEFINED) 205 if val in (UNDEFINED, DATA_NOT_AVAILABLE): 206 if direction: 207 val = -99999999999999999999L 208 else: 209 val = 'zzzzzzzzzzzzzzzzzzzzzzzz' 210 return (val, structureName) 211 if headerKey == 'sovHubName': 212 return structureName 213 if headerKey == 'jumps': 214 return (entryController.GetNumJumps(), structureName) 215 if headerKey == 'region': 216 return (entryController.GetRegionName(), structureName) 217 if headerKey == 'vulnStatus': 218 return (entryController.GetVulnerabilityStateText(), structureName) 219 if headerKey == 'vulnStatus': 220 return (entryController.GetVulnerabilityTime()(), structureName) 221 return structureName 222 223 def GetMenu(self): 224 typeID = self.entryController.typeID 225 itemID = self.entryController.itemID 226 m = GetMenuService().GetMenuFromItemIDTypeID(itemID, typeID, includeMarketDetails=False) 227 if self.entryController.solarSystemID != session.solarsystemid2: 228 m.append(MenuEntryData(MenuLabel('UI/Menusvc/OpenSovHubConfigWindow'), func=lambda *args: self.entryController.OpenSovHubWindow(), texturePath=eveicon.settings)) 229 m.append(MenuEntryData(MenuLabel('UI/Common/Location'), subMenuData=GetMenuService().CelestialMenu(self.entryController.solarSystemID), texturePath=eveicon.location)) 230 return m 231 232 def OnClick(self, *args, **kwargs): 233 self.Toggle() 234 235 def Toggle(self, *args): 236 node = self.sr.node 237 if not node or node.get('toggling', 0): 238 return 239 node.toggling = 1 240 w = node.panel 241 if not w: 242 node.toggling = 0 243 return 244 node.open = not node.open 245 if node.open: 246 PlaySound(uiconst.SOUND_EXPAND) 247 node.scroll.CollapseAll() 248 else: 249 PlaySound(uiconst.SOUND_COLLAPSE) 250 self.ShowOpenState(node.open) 251 uicore.registry.SetListGroupOpenState(node.id, node.open) 252 node.scroll.PrepareSubContent(node) 253 if node.get('onToggle', None): 254 node.onToggle() 255 node.toggling = 0 256 257 def ShowOpenState(self, open_): 258 if self.expander: 259 if open_: 260 self.expander.SetTexturePath(eveicon.caret_down) 261 else: 262 self.expander.SetTexturePath(eveicon.caret_right) 263 264 def AddLoadingLabelCont(self, text): 265 column = LoadingLabelCont(parent=self, text=text) 266 self.columns.append(column) 267 return column 268 269 def UpdateVulnerabilityTimer(self): 270 if self.destroyed: 271 self.vulnerability_thread = None 272 return 273 self.vulnerabilityHourLabel.text = self.entryController.GetVulnerabilityTime() 274 275 def Close(self): 276 with ExceptionEater('Closing SovHubEntry'): 277 self.entryController = None 278 super(SovHubEntry, self).Close() 279 280 281 class LoadingLabelCont(Container): 282 default_align = carbonui.Align.TOLEFT 283 default_clipChildren = True 284 normalOpacity = TextColor.NORMAL[3] 285 286 def ApplyAttributes(self, attributes): 287 super(LoadingLabelCont, self).ApplyAttributes(attributes) 288 text = attributes.text 289 innerCont = Container(parent=self, left=uiconst.LABELTABMARGIN, width=uiconst.LABELTABMARGIN, clipChildren=True) 290 self._loadingAnimationPending = False 291 self.loadingWheel = LoadingWheel(parent=innerCont, align=carbonui.Align.CENTER, pos=(0, 0, 16, 16), opacity=0.0, color=eveColor.TUNGSTEN_GREY) 292 self.label = carbonui.text.styles.TextBody(parent=innerCont, text=text, align=uiconst.CENTERLEFT, left=uiconst.LABELTABMARGIN, autoFadeSides=6) 293 294 def SetText(self, text): 295 self.label.text = text 296 self.SetLoadingState(False) 297 298 def SetPendingLoadingAnimation(self): 299 if self._loadingAnimationPending: 300 return 301 self._loadingAnimationPending = True 302 303 def SetLoadingState(self, isLoading, animate = True): 304 self._loadingAnimationPending = False 305 if animate: 306 if isLoading: 307 animation.fade_in(self.loadingWheel) 308 animation.fade_out(self.label, duration=0.1) 309 else: 310 animation.fade_out(self.loadingWheel, duration=0.1) 311 animation.fade_in(self.label, end_value=self.normalOpacity) 312 elif isLoading: 313 self.loadingWheel.opacity = 1.0 314 self.label.opacity = 0.0 315 else: 316 self.loadingWheel.opacity = 0.0 317 self.label.opacity = self.normalOpacity 318 319 @property 320 def loadingAnimationPending(self): 321 return self._loadingAnimationPending 322 323 @property 324 def text(self): 325 return self.label.text 326 327 @text.setter 328 def text(self, value): 329 self.SetText(value)