moonScanner.py (15642B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\scannerFiles\moonScanner.py 2 import carbonui.const as uiconst 3 import evetypes 4 import gametime 5 from carbon.common.script.util.format import FmtDate 6 from carbon.common.script.util.linkUtil import GetShowInfoLink 7 from carbon.common.script.util.timerstuff import AutoTimer 8 from carbonui.control.dragResizeCont import DragResizeCont 9 from carbonui.decorative.panelUnderlay import PanelUnderlay 10 from carbonui.primitives.container import Container 11 from carbonui.primitives.containerAutoSize import ContainerAutoSize 12 from carbonui.primitives.sprite import Sprite 13 from carbonui.util.color import Color 14 from carbonui.util.sortUtil import SortListOfTuples 15 from eve.client.script.ui.control.baseListEntry import BaseListEntryCustomColumns 16 from carbonui.button.group import ButtonGroup 17 from carbonui.control.buttonIcon import ButtonIcon 18 from eve.client.script.ui.control.entries.util import GetFromClass 19 from eve.client.script.ui.control.eveLabel import EveLabelMedium, Label 20 from eve.client.script.ui.control.eveScroll import Scroll 21 from carbonui.control.window import Window 22 from eve.client.script.ui.control.gauge import Gauge 23 from eve.client.script.ui.control.infoIcon import InfoIcon 24 from eve.client.script.ui.control.itemIcon import ItemIcon 25 from eve.client.script.ui.control.tooltips import TooltipPanel 26 from eve.client.script.ui.inflight.moonscan import MoonScanView 27 from eve.client.script.ui.shared.fitting.fittingUtil import EatSignalChangingErrors 28 from eve.client.script.ui.tooltips.tooltipsWrappers import TooltipBaseWrapper 29 from eve.common.lib import appConst as const 30 import inventorycommon.const as invConst 31 from eveservices.menu import GetMenuService 32 from localization import GetByLabel 33 from localization.formatters import FormatGenericList 34 from signals.signalUtil import ChangeSignalConnect 35 from utillib import KeyVal 36 from fsdBuiltData.common.iconIDs import GetIconFile 37 import blue 38 import mathext 39 LINEBREAK = '\r\n' 40 GAUGE_COLOR = (0.1, 0.37, 0.55, 1.0) 41 42 class MoonScanner(Window): 43 __notifyevents__ = ['OnSessionChanged'] 44 default_windowID = 'MoonScanner' 45 default_width = 360 46 default_height = 420 47 default_minSize = (360, 420) 48 default_captionLabelPath = 'UI/Inflight/Scanner/MoonAnalysis' 49 50 def ApplyAttributes(self, attributes): 51 Window.ApplyAttributes(self, attributes) 52 self.moonScanSvc = sm.GetService('moonScan') 53 self.scope = uiconst.SCOPE_INFLIGHT 54 self.topParent = Container(name='topParent', parent=self.GetMainArea(), align=uiconst.TOTOP, height=32, clipChildren=True) 55 self.AddCopyBtn() 56 self.ConstructHeader() 57 self.BuildProbeCont() 58 self.sr.moonscanner = MoonScanView(name='moonparent', parent=self.sr.main, align=uiconst.TOALL, pos=(const.defaultPadding, 59 const.defaultPadding, 60 const.defaultPadding, 61 const.defaultPadding)) 62 self.sr.moonscanner.Startup() 63 self.LoadWnd(attributes.moonID) 64 self.UpdateInfo() 65 self.ChangeSignalConnection() 66 67 def ChangeSignalConnection(self, connect = True): 68 signalAndCallback = [(self.moonScanSvc.moonProbeTracker.on_probes_changed, self.OnProbesChanged)] 69 ChangeSignalConnect(signalAndCallback, connect) 70 71 def OnProbesChanged(self): 72 self.UpdateInfo() 73 74 def UpdateInfo(self): 75 self.LoadProbeIcon() 76 self.LoadProbeScroll() 77 self.UpdateProbeInfoText() 78 79 def AddCopyBtn(self): 80 self.btnGroup = ButtonGroup(parent=self.sr.main, idx=0) 81 text = GetByLabel('UI/Fitting/FittingWindow/FittingManagement/ExportToClipboard') 82 self.btnGroup.AddButton(GetByLabel('UI/Generic/Close'), self.CloseByUser, ()) 83 self.btnGroup.AddButton(text, self.CopyToClipboard, ()) 84 85 def BuildProbeCont(self): 86 self.probeCont = DragResizeCont(name='probeCont', parent=self.sr.main, align=uiconst.TOTOP_PROP, minSize=0.15, maxSize=0.7, defaultSize=0.45, padding=4, settingsID='moonminingDivider') 87 self.scroll = Scroll(parent=self.probeCont) 88 self.scroll.sr.id = 'moonsprobeScroll' 89 self.scroll.GetStrengir = self.GetScrollStrengir 90 self.scroll.sr.minColumnWidth = {GetByLabel('UI/Inflight/Scanner/ProbeTimeLeftHeader'): 90} 91 92 def GetScrollStrengir(self, node, fontsize, letterspace, shift, idx = None): 93 shift = MoonProbeItemEntry.GetShift(node) 94 return Scroll.GetStrengir(self.scroll, node, fontsize, letterspace, shift, idx) 95 96 def ConstructHeader(self): 97 self.headerContainer = Container(name='HeaderContainer', parent=self.topParent, align=uiconst.TOTOP, height=32) 98 PanelUnderlay(name='HeaderUnderlay', bgParent=self.headerContainer) 99 self.probeInfoContainer = ContainerAutoSize(name='probeInfoContainer', parent=self.headerContainer, align=uiconst.TOLEFT, state=uiconst.UI_NORMAL, left=4) 100 self.probeSprite = Sprite(name='ProbeSprite', parent=self.probeInfoContainer, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, pos=(1, 0, 32, 32)) 101 self.probeSpriteFrame = Sprite(name='probeSpriteFrame', texturePath='res:/UI/Texture/classes/ProbeScanner/probeFrame.png', parent=self.probeInfoContainer, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, width=32, height=32) 102 self.probesLaunchedLabel = EveLabelMedium(name='ProbesLaunchedLabel', parent=self.probeInfoContainer, align=uiconst.CENTERLEFT, left=36) 103 infoIcon = ButtonIcon(name='infoIcon', parent=self.headerContainer, texturePath='res:/UI/Texture/Icons/generic/more_info_16.png', align=uiconst.BOTTOMRIGHT, pos=(6, 4, 16, 16), state=uiconst.UI_NORMAL) 104 infoIcon.hint = GetByLabel('UI/Inflight/Scanner/MoonScanHint') 105 106 def LoadWnd(self, moonID = None): 107 scans = self.moonScanSvc.GetScans() 108 self.sr.moonscanner.SetEntries(scans, moonID=moonID) 109 self.LoadProbeScroll() 110 111 def ClearMoons(self): 112 self.sr.moonscanner.Clear() 113 114 def UpdateProbeInfoText(self): 115 probeData = self.moonScanSvc.GetProbeData() 116 numProbes = len(probeData) 117 if numProbes: 118 text = 'X %s' % numProbes 119 elif not self.moonScanSvc.HasOnlineProbeLauncher(): 120 text = GetByLabel('UI/Inflight/Scanner/NoLauncherFitted') 121 elif self.moonScanSvc.GetChargesInProbeLauncher(): 122 text = GetByLabel('UI/Inflight/Scanner/NoProbesLaunched') 123 else: 124 text = GetByLabel('UI/Inflight/Scanner/NoProbesInLauncher') 125 self.probesLaunchedLabel.SetText(text) 126 color = Label.default_color if numProbes else Color.ORANGE 127 self.probesLaunchedLabel.SetRGBA(*color) 128 self.probeSpriteFrame.SetRGBA(*color) 129 130 def LoadProbeIcon(self): 131 typeID = self.moonScanSvc.GetActiveProbeTypeID() 132 if not typeID: 133 self.probeSprite.opacity = 0.3 134 self.probeInfoContainer.tooltipPanelClassInfo = MoonProbeTooltip(typeID, 0) 135 typeID = invConst.typeSurveyProbeLauncher 136 else: 137 numProbes = self.moonScanSvc.moonProbeTracker.GetNumProbes() 138 self.probeSprite.opacity = 1.0 139 self.probeInfoContainer.tooltipPanelClassInfo = MoonProbeTooltip(typeID, numProbes) 140 iconID = evetypes.GetIconID(typeID) 141 texturePath = GetIconFile(iconID) 142 self.probeSprite.texturePath = texturePath 143 144 def LoadProbeScroll(self): 145 probesInScroll = {node.itemID for node in self.scroll.GetNodes()} 146 scrolllist = [] 147 for eachProbe in self.moonScanSvc.GetProbeData().itervalues(): 148 moonID = self.moonScanSvc.GetMoonForProbe(eachProbe.probeID) 149 moonName = MoonProbeItemEntry.GetMoonName(moonID) 150 probeName = GetByLabel('UI/Inflight/Scanner/ProbeLabel', probeIndex=eachProbe.probeNumber) 151 data = KeyVal() 152 data.typeID = eachProbe.typeID 153 data.moonID = moonID 154 data.expiry = eachProbe.expiry 155 data.delay = eachProbe.delay 156 data.probeName = probeName 157 data.destinationText = moonName 158 data.getIcon = True 159 data.label = MoonProbeItemEntry.GetProbeText(data) 160 data.Set('sort_%s' % GetByLabel('UI/Inflight/Scanner/ProbeTimeLeftHeader'), eachProbe.expiry) 161 data.Set('sort_%s' % GetByLabel('UI/Inflight/Scanner/Probe'), eachProbe.probeNumber) 162 data.isNewEntry = eachProbe.probeID not in probesInScroll 163 entry = GetFromClass(MoonProbeItemEntry, data) 164 scrolllist.append(entry) 165 166 headers = [GetByLabel('UI/Inflight/Scanner/Probe'), GetByLabel('UI/Inflight/Scanner/ProbeTimeLeftHeader'), GetByLabel('UI/Inflight/Scanner/ProbeDestination')] 167 self.scroll.LoadContent(contentList=scrolllist, headers=headers, noContentHint=GetByLabel('UI/Inflight/Scanner/NoProbesInSpace')) 168 169 def Close(self, *args, **kwargs): 170 with EatSignalChangingErrors(errorMsg='Container'): 171 self.ChangeSignalConnection(connect=False) 172 Window.Close(self, *args, **kwargs) 173 174 def CopyToClipboard(self): 175 allScans = self.moonScanSvc.GetScans() 176 allScansSorted = SortListOfTuples([ (celestialID, (celestialID, products)) for celestialID, products in allScans.iteritems() ]) 177 headerList = [GetByLabel('UI/Common/Groups/Moon'), 178 GetByLabel('UI/Inflight/Scanner/MoonProduct'), 179 GetByLabel('UI/Common/Quantity'), 180 GetByLabel('UI/Ledger/OreTypeID'), 181 GetByLabel('UI/Ledger/SolarSystemID'), 182 GetByLabel('UI/Moonmining/PlanetID'), 183 GetByLabel('UI/Moonmining/MoonID')] 184 lineList = ['\t'.join(headerList)] 185 for eachCelestialID, products in allScansSorted: 186 try: 187 celestialInfo = cfg.evelocations.Get(eachCelestialID) 188 celestialName = celestialInfo.name 189 lineList.append(celestialName) 190 moonInfo = cfg.mapSolarSystemContentCache.moons[eachCelestialID] 191 planetID = moonInfo.orbitID 192 sortedProducts = SortListOfTuples([ (evetypes.GetName(typeID), (evetypes.GetName(typeID), typeID, qty)) for typeID, qty in products.iteritems() ]) 193 for typeName, typeID, qty in sortedProducts: 194 stringList = ['', 195 typeName, 196 unicode(float(qty)), 197 unicode(typeID), 198 unicode(celestialInfo.solarSystemID), 199 unicode(planetID), 200 unicode(eachCelestialID)] 201 line = '\t'.join(stringList) 202 lineList.append(line) 203 204 except Exception as e: 205 self.moonScanSvc.LogException(e) 206 continue 207 208 text = LINEBREAK.join(lineList) 209 blue.pyos.SetClipboardData(text) 210 211 212 class MoonProbeItemEntry(BaseListEntryCustomColumns): 213 default_name = 'MoonProbeItemEntry' 214 updateLabelTimer = None 215 default_height = 29 216 217 def ApplyAttributes(self, attributes): 218 BaseListEntryCustomColumns.ApplyAttributes(self, attributes) 219 self.sr.infoicon = InfoIcon(left=2, parent=self, idx=0, align=uiconst.CENTERLEFT) 220 self.sr.infoicon.OnClick = self.ShowInfo 221 probeNameCont = self.AddColumnContainer() 222 self.icon = ItemIcon(parent=probeNameCont, pos=(20, 2, 24, 24), align=uiconst.TOPLEFT, idx=0) 223 self.probeLabel = Label(parent=probeNameCont, text='', align=uiconst.CENTERLEFT, left=48) 224 timeCont = self.AddColumnContainer() 225 self.gauge = Gauge(parent=timeCont, name='timeGauge', value=0.0, color=GAUGE_COLOR, gaugeHeight=16, align=uiconst.TOALL, pos=(5, 5, 5, 0), state=uiconst.UI_DISABLED, gradientBrightnessFactor=1.5) 226 self.destinationLabel = self.AddColumnText(text='') 227 self.destinationLabel.state = uiconst.UI_NORMAL 228 229 def Load(self, node): 230 self.sr.node = node 231 self.itemID = node.itemID 232 self.typeID = node.typeID 233 isNew = node.isNewEntry 234 node.isNewEntry = False 235 self.icon.SetTypeID(self.typeID) 236 self.probeLabel.text = node.probeName 237 self.destinationLabel.text = node.destinationText 238 self.UpdateTime(isNew=isNew) 239 self.updateLabelTimer = AutoTimer(1000, self.UpdateTime) 240 241 def UpdateTime(self, isNew = False): 242 if self.destroyed: 243 self.updateLabelTimer = None 244 return 245 node = self.sr.node 246 timeLeftText, timeLeft = self.GetProbTimeLeft(node) 247 if node.moonID == -1: 248 node.moonID = sm.GetService('moonScan').GetMoonForProbe(node.itemID) 249 if node.moonID != -1: 250 node.destinationText = self.GetMoonName(node.moonID) 251 self.destinationLabel.text = node.destinationText 252 totalDelay = node.delay 253 percentage = round(1.0 - mathext.clamp(max(0, timeLeft) / float(totalDelay * const.MSEC), 0.0, 1.0), 2) 254 self.gauge.SetValue(percentage, animate=isNew) 255 self.gauge.SetValueText(timeLeftText) 256 257 def GetMenu(self): 258 return GetMenuService().GetMenuFromItemIDTypeID(self.itemID, self.typeID, includeMarketDetails=True) 259 260 @classmethod 261 def GetProbTimeLeft(cls, node): 262 timeLeft = node.expiry - gametime.GetSimTime() 263 timeLeft = max(0, timeLeft) 264 timeLeftText = FmtDate(timeLeft, 'ns') 265 return (timeLeftText, timeLeft) 266 267 def ShowInfo(self): 268 sm.GetService('info').ShowInfo(self.typeID) 269 270 @classmethod 271 def GetProbeText(cls, node): 272 timeLeft = node.expiry - gametime.GetWallclockTime() 273 timeLeft = max(0, timeLeft) 274 timeLeftText = FmtDate(timeLeft, 'ns') 275 text = '%s<t><right>%s</right><t>%s' % (node.probeName, timeLeftText, node.destinationText) 276 return text 277 278 @classmethod 279 def GetMoonName(cls, moonID): 280 if moonID > 0: 281 return GetShowInfoLink(invConst.typeMoon, cfg.evelocations.Get(moonID).name, moonID) 282 else: 283 return GetByLabel('UI/Inflight/Scanner/ProbeDestinationUnknown') 284 285 @staticmethod 286 def GetShift(node): 287 return 28 288 289 290 class MoonProbeTooltip(TooltipBaseWrapper): 291 292 def __init__(self, probeTypeID, numProbes): 293 super(MoonProbeTooltip, self).__init__() 294 self.probeTypeID = probeTypeID 295 self.numProbes = numProbes 296 297 def CreateTooltip(self, parent, owner, idx): 298 self.tooltipPanel = TooltipPanel(parent=parent, owner=owner, idx=idx) 299 self.tooltipPanel.LoadGeneric2ColumnTemplate() 300 self.tooltipPanel.SetState(uiconst.UI_NORMAL) 301 if not self.probeTypeID: 302 text = GetNoProbesTooltipText() 303 else: 304 text = GetByLabel('UI/Inflight/Scanner/NumSurveyProbesInSpace', numProbes=self.numProbes) 305 self.tooltipPanel.AddLabelMedium(text=text, state=uiconst.UI_NORMAL, wrapWidth=200) 306 return self.tooltipPanel 307 308 309 def GetNoProbesTooltipText(): 310 typeLinks = [] 311 for eachTypeID in evetypes.GetTypeIDsByGroup(invConst.groupSurveyProbe): 312 if not evetypes.IsPublished(eachTypeID): 313 continue 314 typeName = evetypes.GetName(eachTypeID) 315 link = GetShowInfoLink(eachTypeID, typeName) 316 typeLinks.append((typeName, link)) 317 318 typeLinks = SortListOfTuples(typeLinks) 319 typeText = FormatGenericList(typeLinks) 320 groupName = evetypes.GetGroupNameByGroup(invConst.groupSurveyProbe) 321 probeLauncherLink = GetShowInfoLink(invConst.typeSurveyProbeLauncher, evetypes.GetName(invConst.typeSurveyProbeLauncher)) 322 return GetByLabel('UI/Inflight/Scanner/NoSurveyProbesTooltip', groupName=groupName, listOfLinksToTypes=typeText, probeLauncherLink=probeLauncherLink)