outputCont.py (9206B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\moonmining\outputCont.py 2 import evetypes 3 import trinity 4 from carbon.common.script.util.format import FmtAmt 5 from carbonui.primitives.container import Container 6 import carbonui.const as uiconst 7 from carbonui.util.bunch import Bunch 8 from eve.client.script.ui.control.baseListEntry import BaseListEntryCustomColumns 9 from eve.client.script.ui.control.eveIcon import Icon 10 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelSmall 11 from eve.client.script.ui.control.eveScroll import Scroll 12 from eve.client.script.ui.control.gauge import Gauge 13 from eve.client.script.ui.control.themeColored import LineThemeColored, FillThemeColored 14 from eve.client.script.ui.moonmining import GetPrice 15 from eve.client.script.ui.shared.ledger.ledgerUtil import GetColorForBaseTypeID 16 from eve.common.script.util.eveFormat import FmtISK 17 from eveservices.menu import GetMenuService 18 from localization import GetByLabel 19 from moonmining.util import CalculateExtractionTotalYield 20 21 class SchedulingOutputPanel(Container): 22 default_align = uiconst.TOALL 23 24 def ApplyAttributes(self, attributes): 25 Container.ApplyAttributes(self, attributes) 26 self.moonMaterialInfo = attributes.moonMaterialInfo 27 outputHeaderText = attributes.outputHeaderText or GetByLabel('UI/Moonmining/Output') 28 EveLabelMedium(parent=self, text=outputHeaderText, align=uiconst.TOTOP) 29 self.totalCont = TotalContainer(parent=self) 30 self.scroll = Scroll(parent=self, id='schedulingOutputPanelScroll', padTop=4) 31 self.scroll.sr.fixedColumns = MoonminingOutputEntry.GetFixedColumns() 32 contentList, header = self.GetScrollContents() 33 self.scroll.Load(contentList=contentList, headers=header) 34 self.totalCont.UpdateColumns(self.scroll.sr.tabs) 35 self.scroll.OnColumnChanged = self.OnScrollColumnChanged 36 37 def OnScrollColumnChanged(self, tabstops, *args): 38 self.totalCont.UpdateColumns(tabstops) 39 40 def GetScrollContents(self): 41 headers = [GetByLabel('UI/Moonmining/MoonProductHeader'), GetByLabel('UI/Moonmining/EstVolumeHeader'), GetByLabel('UI/Moonmining/EstPriceHeader')] 42 scrollList = [] 43 totalWorth = 0 44 worthByTypeID = {} 45 for typeID, abundancy in self.moonMaterialInfo.iteritems(): 46 volume = abundancy * CalculateExtractionTotalYield(3600) 47 units = volume / evetypes.GetVolume(typeID) 48 price = GetPrice(typeID, units) 49 worthByTypeID[typeID] = price 50 totalWorth += price 51 52 for typeID, abundancy in self.moonMaterialInfo.iteritems(): 53 data = Bunch(decoClass=MoonminingOutputEntry, estVolume=0, estPrice=0, typeID=typeID, gaugeColor=GetColorForBaseTypeID(typeID)[:3] + (0.6,), abundancy=abundancy, pricePerc=worthByTypeID.get(typeID, 0) / float(totalWorth), GetSortValue=MoonminingOutputEntry.GetSortValue) 54 scrollList.append(data) 55 56 return (scrollList, headers) 57 58 def SetEstimation(self, numSec, yieldMultiplier): 59 totalVol = 0 60 totalPrice = 0 61 totalYield = CalculateExtractionTotalYield(numSec, yieldMultiplier) 62 for eachNode in self.scroll.GetNodes(): 63 percentageOfOutput = self.moonMaterialInfo.get(eachNode.typeID, None) 64 estVol = percentageOfOutput * totalYield 65 eachNode.estVolume = estVol 66 units = estVol / evetypes.GetVolume(eachNode.typeID) 67 estPrice = GetPrice(eachNode.typeID, units) 68 eachNode.estPrice = estPrice 69 totalVol += estVol 70 totalPrice += estPrice 71 if eachNode.panel: 72 eachNode.panel.UpdateGauges() 73 74 self.totalCont.SetTotals(totalVol, totalPrice) 75 76 def GetOutputHeight(self): 77 return self.scroll.GetTotalHeight() + 100 78 79 80 class TotalContainer(Container): 81 default_align = uiconst.TOBOTTOM 82 default_height = 30 83 84 def ApplyAttributes(self, attributes): 85 Container.ApplyAttributes(self, attributes) 86 FillThemeColored(name='underlay', bgParent=self) 87 LineThemeColored(parent=self, align=uiconst.TOLEFT_NOPUSH, name='line', opacity=uiconst.OPACITY_FRAME) 88 LineThemeColored(parent=self, align=uiconst.TORIGHT_NOPUSH, name='line', opacity=uiconst.OPACITY_FRAME) 89 LineThemeColored(parent=self, align=uiconst.TOBOTTOM_NOPUSH, name='line', opacity=uiconst.OPACITY_FRAME) 90 self.totalCont = Container(parent=self, align=uiconst.TOLEFT, width=100) 91 EveLabelMedium(parent=self.totalCont, text=GetByLabel('UI/Moonmining/Total'), align=uiconst.CENTERLEFT, left=10) 92 self.volCont = Container(parent=self, align=uiconst.TOLEFT, width=100) 93 self.AddLine(self.volCont) 94 self.volLabel = EveLabelMedium(parent=self.volCont, text='volCont', align=uiconst.CENTER) 95 self.priceCont = Container(parent=self, align=uiconst.TOLEFT, width=100) 96 self.AddLine(self.priceCont) 97 line = self.AddLine(self.priceCont, align=uiconst.TORIGHT) 98 line.left = -1 99 self.priceLabel = EveLabelMedium(parent=self.priceCont, text='priceCont', align=uiconst.CENTER) 100 101 def AddLine(self, parent, align = uiconst.TOLEFT): 102 line = LineThemeColored(parent=parent, align=align, name='__columnLine', opacity=uiconst.OPACITY_FRAME) 103 return line 104 105 def UpdateColumns(self, tabStops): 106 self.totalCont.width = tabStops[0] 107 self.volCont.width = tabStops[1] - tabStops[0] 108 self.priceCont.width = tabStops[2] - tabStops[1] 109 110 def SetTotals(self, vol, price): 111 self.volLabel.text = GetByLabel('UI/Moonmining/NumM3', amount=FmtAmt(vol, showFraction=False)) 112 self.priceLabel.text = FmtISK(price, showFractionsAlways=False) 113 114 115 class MoonminingOutputEntry(BaseListEntryCustomColumns): 116 default_height = 40 117 118 def ApplyAttributes(self, attributes): 119 BaseListEntryCustomColumns.ApplyAttributes(self, attributes) 120 self.BuildUI() 121 122 def BuildUI(self): 123 self.typeCont = self.AddColumnContainer() 124 self.typeCont.name = 'typeCont' 125 self.volumeCont = self.AddColumnContainer() 126 self.volumeCont.name = 'volumeCont' 127 self.priceCont = self.AddColumnContainer() 128 self.priceCont.name = 'priceCont' 129 self.typeIcon = Icon(name='typeIcon', parent=self.typeCont, pos=(0, 0, 32, 32), align=uiconst.CENTERLEFT) 130 self.typeLabel = EveLabelMedium(name='typeLabel', parent=self.typeCont, left=40, align=uiconst.CENTERLEFT) 131 self.volumeGauge = MoonminingGauge(parent=self.volumeCont, name='productGauge', value=0.0, color=(1, 1, 1, 0), pos=(5, 10, 5, 0), gradientBrightnessFactor=1.5) 132 self.priceGauge = MoonminingGauge(parent=self.priceCont, name='priceGauge', value=0.0, color=(1, 1, 1, 0), pos=(5, 10, 5, 0), gradientBrightnessFactor=1.5) 133 134 def Load(self, node): 135 self.typeIcon.LoadIconByTypeID(typeID=node.typeID) 136 self.typeLabel.text = evetypes.GetName(node.typeID) 137 self.volumeGauge.SetValue(node.abundancy) 138 self.volumeGauge.SetColor(node.gaugeColor) 139 self.priceGauge.SetValue(node.pricePerc) 140 self.priceGauge.SetColor(node.gaugeColor) 141 self.UpdateGauges() 142 143 def UpdateGauges(self): 144 node = self.sr.node 145 text = GetByLabel('UI/Moonmining/NumM3', amount=FmtAmt(node.estVolume, showFraction=False)) 146 self.volumeGauge.SetValueText(text) 147 text = FmtISK(node.estPrice, showFractionsAlways=False) 148 self.priceGauge.SetValueText(text) 149 150 def GetMenu(self): 151 return GetMenuService().GetMenuFromItemIDTypeID(None, self.sr.node.typeID, includeMarketDetails=True) 152 153 @classmethod 154 def GetCopyData(cls, node): 155 name = evetypes.GetName(node.typeID) 156 volume = GetByLabel('UI/Moonmining/NumM3', amount=FmtAmt(node.estVolume, showFraction=False)) 157 price = FmtISK(node.estPrice, showFractionsAlways=False) 158 return '<t>'.join([name, volume, price]) 159 160 @staticmethod 161 def GetFixedColumns(): 162 return {GetByLabel('UI/Moonmining/EstVolumeHeader'): 150, 163 GetByLabel('UI/Moonmining/EstPriceHeader'): 150} 164 165 @classmethod 166 def GetSortValue(cls, node, by, sortDir, idx): 167 if idx == 0: 168 return evetypes.GetName(node.typeID) 169 if idx == 1: 170 return node.abundancy 171 if idx == 2: 172 return node.pricePerc 173 174 175 class MoonminingGauge(Gauge): 176 __guid__ = 'MoonminingGauge' 177 default_gaugeHeight = 20 178 default_align = uiconst.TOALL 179 default_state = uiconst.UI_DISABLED 180 181 def ApplyAttributes(self, attributes): 182 Gauge.ApplyAttributes(self, attributes) 183 self.valueText = EveLabelSmall(parent=self.gaugeCont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, idx=0) 184 self.valueText.opacity = 1.5 185 self.shadowLabel = EveLabelSmall(parent=self.gaugeCont, text='', align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=(0, 0, 0, 1), idx=1) 186 self.shadowLabel.renderObject.spriteEffect = trinity.TR2_SFX_BLUR 187 188 def SetValueText(self, text): 189 Gauge.SetValueText(self, text) 190 if self.shadowLabel.text != text: 191 self.shadowLabel.text = text