lpPanel.py (10283B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\panels\personal\lpPanel.py 2 import blue 3 import uthread2 4 from carbon.common.script.util.linkUtil import GetShowInfoLink 5 from carbonui import uiconst 6 from carbonui.control.combo import Combo 7 from carbonui.control.tabGroup import TabGroup, GetTabData 8 from carbonui.primitives.container import Container 9 from eve.client.script.ui.control.baseListEntry import BaseListEntryCustomColumns 10 from eve.client.script.ui.control.entries.util import GetFromClass 11 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 12 from eve.client.script.ui.control.eveScroll import Scroll 13 from eve.client.script.ui.shared.neocom.wallet import walletConst 14 from eve.client.script.ui.shared.neocom.wallet.panels.personal.lpIncursionsPanel import LPIncursionsPanel 15 from eve.client.script.ui.shared.neocom.wallet.panels.personal.personalDonateLPPanel import PersonalDonateLPPanel 16 from eve.common.lib import appConst 17 from eve.common.script.sys.idCheckers import IsStation 18 from localization import GetByLabel 19 from localization.formatters import FormatNumeric 20 from menu import MenuLabel 21 from npcs.npccorporations import get_corporation_faction_id 22 23 class PersonalLPPanel(Container): 24 panelID = walletConst.PANEL_LP 25 26 def ApplyAttributes(self, attributes): 27 Container.ApplyAttributes(self, attributes) 28 self.isInitialized = False 29 self.tabGroup = None 30 31 def OnTabSelect(self): 32 if not self.isInitialized: 33 self.ConstructLayout() 34 self.isInitialized = True 35 if self.tabGroup: 36 self.tabGroup.AutoSelect() 37 38 def ConstructLayout(self): 39 self.balancePanel = LPBalancePanel(parent=self, state=uiconst.UI_HIDDEN) 40 self.incursionsPanel = LPIncursionsPanel(parent=self, state=uiconst.UI_HIDDEN) 41 self.donatePanel = PersonalDonateLPPanel(parent=self, state=uiconst.UI_HIDDEN) 42 tabs = (GetTabData(label=GetByLabel('UI/Wallet/WalletWindow/TabOverview'), panel=self.balancePanel, tabID=walletConst.PANEL_LP_BALANCE), GetTabData(label=GetByLabel('UI/Incursion/Journal/LoyaltyPointLog'), panel=self.incursionsPanel, tabID=walletConst.PANEL_LP_INCURSIONS), GetTabData(label=GetByLabel('UI/Wallet/WalletWindow/TabDonate'), panel=self.donatePanel, tabID=walletConst.PANEL_LP_DONATE)) 43 self.tabGroup = TabGroup(name='WalletPersonalLPTabGroup', parent=self, tabs=tabs, padBottom=16, groupID='WalletPersonalLPTabs', idx=0) 44 45 46 class LPBalancePanel(Container): 47 panelID = walletConst.PANEL_LP_BALANCE 48 __notifyevents__ = ['OnCharacterLPBalanceChange_Local'] 49 50 def ApplyAttributes(self, attributes): 51 Container.ApplyAttributes(self, attributes) 52 self.loyaltyPointsWalletSvc = sm.GetService('loyaltyPointsWalletSvc') 53 self.factionSvc = sm.GetService('faction') 54 self.ConstructLayout() 55 sm.RegisterNotify(self) 56 57 def OnTabSelect(self): 58 uthread2.StartTasklet(self.Update) 59 60 def Update(self): 61 self.loadingWheel.Show() 62 self.PopulateFactionCombo() 63 uthread2.StartTasklet(self.PopulateScroll) 64 65 def PopulateFactionCombo(self): 66 factionIDs = {get_corporation_faction_id(corpID) for corpID, lpAmount in self.GetMyLoyaltyPointsData() if lpAmount > 0} 67 factionIDs = filter(None, factionIDs) 68 options = [ (cfg.eveowners.Get(factionID).ownerName, factionID) for factionID in factionIDs ] 69 options.sort() 70 options.insert(0, (GetByLabel('UI/Wallet/WalletWindow/AllFactions'), 0)) 71 self.factionCombo.LoadOptions(options) 72 73 def GetMyLoyaltyPointsData(self): 74 return self.loyaltyPointsWalletSvc.GetAllCharacterLPBalancesExcludingEvermarks() 75 76 def ConstructLayout(self): 77 topCont = Container(parent=self, align=uiconst.TOTOP, height=32, padBottom=6) 78 self.factionCombo = Combo(parent=topCont, align=uiconst.TOLEFT, width=200, callback=self.OnFactionCombo) 79 self.loadingWheel = LoadingWheel(parent=self, align=uiconst.CENTER) 80 self.ConstructScroll() 81 82 def OnFactionCombo(self, *args): 83 return self.PopulateScroll() 84 85 def ConstructScroll(self): 86 self.scroll = Scroll(name='loyaltyPointScroll', parent=self) 87 self.scroll.sr.id = 'walletLoyaltyPointScroll2' 88 self.scroll.sr.defaultColumnWidth = LPEntry.GetDefaultColumnWidth() 89 90 def PopulateScroll(self): 91 self.scroll.Clear() 92 entries = self.GetScrollEntries() 93 self.scroll.Load(contentList=entries, headers=LPEntry.GetHeaders(), noContentHint=GetByLabel('UI/Journal/JournalWindow/Agents/NoLP')) 94 self.loadingWheel.Hide() 95 96 def GetScrollEntries(self): 97 entries = [] 98 lpData = self.GetMyLoyaltyPointsData() 99 ownersToPrime = set() 100 stationToPrime = set() 101 locationsToPrime = set() 102 lpInfoByCorpID = {} 103 lpStoreSvc = sm.GetService('lpstore') 104 for corpID, lpAmount in lpData: 105 blue.pyos.BeNice() 106 if self.IsFilteredOut(corpID): 107 continue 108 ownersToPrime.add(corpID) 109 nearestDockableLocationID = lpStoreSvc.GetNearestDockableWithLPStoreForCorp(corpID) 110 if IsStation(nearestDockableLocationID): 111 stationToPrime.add(nearestDockableLocationID) 112 locationsToPrime.add(nearestDockableLocationID) 113 elif nearestDockableLocationID: 114 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(nearestDockableLocationID) 115 if not structureInfo: 116 continue 117 locationsToPrime.add(nearestDockableLocationID) 118 lpInfoByCorpID[corpID] = (lpAmount, nearestDockableLocationID) 119 120 if ownersToPrime: 121 cfg.eveowners.Prime(ownersToPrime) 122 if stationToPrime: 123 cfg.stations.Prime(stationToPrime) 124 if locationsToPrime: 125 cfg.evelocations.Prime(locationsToPrime) 126 for corpID, lpInfo in lpInfoByCorpID.iteritems(): 127 lpAmount, nearestDockableLocationID = lpInfo 128 if lpAmount <= 0: 129 continue 130 entry = self.GetScrollEntry(corpID, lpAmount, nearestDockableLocationID) 131 if entry: 132 entries.append(entry) 133 134 return entries 135 136 def IsFilteredOut(self, corpID): 137 factionID = self.factionCombo.GetValue() 138 return factionID and factionID != get_corporation_faction_id(corpID) 139 140 def GetScrollEntry(self, corpID, lpAmount, nearestDockableLocationID): 141 return GetFromClass(LPEntry, {'lpAmount': lpAmount, 142 'corpID': corpID, 143 'sortValues': LPEntry.GetColumnSortValues(corpID, lpAmount), 144 'nearestDockableLocationID': nearestDockableLocationID}) 145 146 def OnCharacterLPBalanceChange_Local(self, *args, **kwargs): 147 self.Update() 148 149 150 class LPEntry(BaseListEntryCustomColumns): 151 152 def ApplyAttributes(self, attributes): 153 BaseListEntryCustomColumns.ApplyAttributes(self, attributes) 154 self.lpStoreSvc = sm.GetService('lpstore') 155 self.nameColumn = self.AddColumnText() 156 self.lpColumn = self.AddColumnText() 157 self.stationColumn = self.AddColumnText() 158 self.stationColumn.state = uiconst.UI_NORMAL 159 160 def Load(self, node): 161 if node.selected: 162 self.Select() 163 else: 164 self.Deselect() 165 self.PopulateLabels(node) 166 167 def PopulateLabels(self, node): 168 node = node if node else self.sr.node 169 corpName = cfg.eveowners.Get(node.corpID).name 170 lpFormatted = FormatNumeric(value=node.lpAmount, useGrouping=True) 171 nearestDockableLocationID = node.nearestDockableLocationID 172 if IsStation(nearestDockableLocationID): 173 stationName = self._GetStationName(nearestDockableLocationID) 174 elif nearestDockableLocationID: 175 stationName = self._GetStrucureName(nearestDockableLocationID) 176 else: 177 stationName = GetByLabel('UI/Common/None') 178 self.nameColumn.text = corpName 179 self.lpColumn.text = lpFormatted 180 self.stationColumn.text = stationName 181 182 def _GetStationName(self, nearestStationID): 183 stationTypeID = cfg.stations.Get(nearestStationID).stationTypeID 184 nearestStationName = cfg.evelocations.Get(nearestStationID).name 185 return '<url=showinfo:%s//%s>%s</url>' % (stationTypeID, nearestStationID, nearestStationName) 186 187 def _GetStrucureName(self, nearestStructureID): 188 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(nearestStructureID) 189 return GetShowInfoLink(structureInfo.typeID, structureInfo.itemName, structureInfo.structureID) 190 191 def GetMenu(self, *args): 192 m = [(GetByLabel('UI/Commands/ShowInfo'), self.ShowCorpInfo)] 193 lpSvc = sm.GetService('lpstore') 194 loyaltyPointsWalletSvc = sm.GetService('loyaltyPointsWalletSvc') 195 xChangeRate = lpSvc.GetConcordLPExchangeRate(self.sr.node.corpID) 196 concordLPs = loyaltyPointsWalletSvc.GetCharacterConcordLPBalance() 197 if session.stationid is not None and xChangeRate is not None and xChangeRate > 0.0 and concordLPs > 0: 198 m.append((MenuLabel('UI/Journal/JournalWindow/Agents/ConvertConcordLoyaltyPoints'), self.ShowConcordExchangeDialog)) 199 return m 200 201 def ShowCorpInfo(self): 202 sm.GetService('info').ShowInfo(appConst.typeCorporation, self.sr.node.corpID) 203 204 def ShowConcordExchangeDialog(self): 205 sm.GetService('lpstore').OpenConcordExchange(self.sr.node.corpID) 206 207 @staticmethod 208 def GetHeaders(): 209 return (GetByLabel('UI/Journal/JournalWindow/Agents/HeaderIssuingCorporation'), GetByLabel('UI/Journal/JournalWindow/Agents/LoyaltyPoints'), GetByLabel('UI/Wallet/WalletWindow/ClosestLPStore')) 210 211 @staticmethod 212 def GetDynamicHeight(node, width): 213 return 24 214 215 @staticmethod 216 def GetDefaultColumnWidth(): 217 return {GetByLabel('UI/Journal/JournalWindow/Agents/HeaderIssuingCorporation'): 160, 218 GetByLabel('UI/Journal/JournalWindow/Agents/LoyaltyPoints'): 100, 219 GetByLabel('UI/Wallet/WalletWindow/ClosestLPStore'): 600} 220 221 @staticmethod 222 def GetColumnSortValues(corpID, lpAmount): 223 return (cfg.eveowners.Get(corpID).name, lpAmount, None)