NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

marketTransactionsPanel.py (12137B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\panels\marketTransactionsPanel.py
      2 import math
      3 import eveformat
      4 import evetypes
      5 import utillib
      6 from carbonui import Color, TextColor, uiconst
      7 from carbonui.control.combo import Combo
      8 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      9 from carbonui.primitives.container import Container
     10 from eve.client.script.ui.control.entries.generic import Generic
     11 from eve.client.script.ui.control.entries.util import GetFromClass
     12 from player_messaging.client.ui_message import message_player
     13 from eve.client.script.ui.shared.neocom.wallet.panels.baseTransactionsPanel import TransactionsScroll, BaseTransaction, BaseTransactionsList, BaseTransactionsPanel, GetTransactionKeyVal
     14 from eve.client.script.ui.shared.neocom.wallet.walletConst import WALLET_TRANSACTIONS_SCROLLID
     15 from eve.client.script.ui.shared.neocom.wallet.walletUtil import GetSettingValue, SafeGetName
     16 from eve.client.script.ui.util import searchOld
     17 from eve.common.script.sys import idCheckers
     18 from eveservices.menu import GetMenuService
     19 from inventorycommon.const import categoryOwner, groupCharacter
     20 from localization import GetByLabel
     21 from menu import MenuLabel
     22 COLOR_CORPORATION = Color.from_hex('#88bbff')
     23 
     24 class MarketTransaction(BaseTransaction):
     25 
     26     def __init__(self, transactionData):
     27         super(MarketTransaction, self).__init__(transactionData)
     28         self.quantity = self.data.quantity
     29         self.unitPrice = self.data.price
     30         self.total = self.data.totalPrice
     31         self.dateString = GetByLabel('UI/Wallet/WalletWindow/FmtWalletDate', dt=self.data.transactionDate)
     32         self.qtyString = eveformat.number(self.data.quantity)
     33         self.typeString = SafeGetName(self.data.typeID)
     34         self.unitPriceString = eveformat.isk(self.data.price, fraction=GetSettingValue('walletShowCents'))
     35         self.totalString = eveformat.isk(self.data.totalPrice, fraction=GetSettingValue('walletShowCents'))
     36         self.clientString = GetByLabel('UI/Wallet/WalletWindow/CharacterName', charID=self.data.clientID)
     37         self.whereString = GetByLabel('UI/Wallet/WalletWindow/StationName', station=self.data.stationID)
     38         if hasattr(self.data, 'characterID'):
     39             self.characterString = GetByLabel('UI/Wallet/WalletWindow/CharacterName', charID=self.data.characterID)
     40         else:
     41             self.characterString = None
     42         if hasattr(self.data, 'keyID'):
     43             self.keyString = sm.GetService('corp').GetCorpAccountName(self.data.keyID)
     44         else:
     45             self.keyString = None
     46 
     47 
     48 class MarketTransactionsList(BaseTransactionsList):
     49 
     50     def __init__(self, scrollHeaders):
     51         super(MarketTransactionsList, self).__init__(scrollHeaders)
     52         self._itemTypes = set()
     53         self._characterIDs = set()
     54 
     55     def LoadTransactions(self, transactions):
     56         super(MarketTransactionsList, self).LoadTransactions(transactions)
     57         self._itemTypes = {(evetypes.GetName(tr.data.typeID), tr.data.typeID) for tr in self._allTransactions}
     58         for tr in self._allTransactions:
     59             if hasattr(tr.data, 'characterID'):
     60                 self._characterIDs.add((cfg.eveowners.Get(tr.data.characterID).ownerName, tr.data.characterID))
     61 
     62     def GetAvailableItemTypes(self):
     63         return self._itemTypes
     64 
     65     def GetCharacterIDs(self):
     66         return self._characterIDs
     67 
     68 
     69 class MarketTransactionsPanel(BaseTransactionsPanel):
     70     default_name = 'MarketTransactionsPanel'
     71     default_clipChildren = False
     72 
     73     def ApplyAttributes(self, attributes):
     74         super(MarketTransactionsPanel, self).ApplyAttributes(attributes)
     75         self.scroll.sr.id = WALLET_TRANSACTIONS_SCROLLID
     76         self.scroll.sr.content.OnDropData = self.OnDropData
     77 
     78     def _BuildOptionsCont(self):
     79         return Container(name='transactionsOptions', parent=self, align=uiconst.TOTOP, height=32, padTop=16)
     80 
     81     def _BuildScroll(self):
     82         scroll = TransactionsScroll(parent=self, padTop=16)
     83         scroll.onSort.connect(self._OnSort)
     84         return scroll
     85 
     86     def _BuildTransactionsList(self, scrollHeaders):
     87         return MarketTransactionsList(scrollHeaders)
     88 
     89     def GetScrollHeaders(self):
     90         return [(GetByLabel('UI/Common/Date'), 'dateString'),
     91          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderQuantity'), 'quantity'),
     92          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderType'), 'typeString'),
     93          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderPrice'), 'unitPrice'),
     94          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderCredit'), 'total'),
     95          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderClient'), 'clientString'),
     96          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderWhere'), 'whereString')]
     97 
     98     def ConstructLayout(self):
     99         super(MarketTransactionsPanel, self).ConstructLayout()
    100         self.ConstructFilters()
    101 
    102     def ConstructFilters(self):
    103         buySellOptions = [(GetByLabel('UI/Wallet/WalletWindow/BuyAndSell'), None), (GetByLabel('UI/Wallet/WalletWindow/ComboBuy'), 1), (GetByLabel('UI/Wallet/WalletWindow/ComboSell'), 0)]
    104         self.sellBuyCombo = Combo(parent=self.transactionsOptionsCont, options=buySellOptions, name='accountkey', width=70, adjustWidth=1, align=uiconst.TOLEFT, padRight=6, callback=self.OnSellBuyCombo)
    105         self.qtyEdit = SingleLineEditInteger(name='qty', parent=self.transactionsOptionsCont, label=GetByLabel('UI/Wallet/WalletWindow/MinQty'), maxLength=10, top=0, width=70, setvalue=0, adjustWidth=True, align=uiconst.TOLEFT, padRight=6, OnChange=self.OnQuantityEditChange)
    106         self.minPriceEdit = SingleLineEditInteger(name='qty', parent=self.transactionsOptionsCont, label=GetByLabel('UI/Wallet/WalletWindow/MinValue'), maxLength=10, top=0, width=70, adjustWidth=True, align=uiconst.TOLEFT, padRight=6, OnChange=self.OnMinPriceEditChange)
    107         self.itemTypeCombo = Combo(name='type', parent=self.transactionsOptionsCont, top=0, width=120, align=uiconst.TOLEFT, padRight=6, callback=self.OnItemTypeCombo)
    108         self.itemTypeCombo.OnDropData = self.OnDropData
    109 
    110     def OnSellBuyCombo(self, *args):
    111         self.UpdateTransactionsByPage()
    112         self.PopulateScroll()
    113 
    114     def OnItemTypeCombo(self, *args):
    115         self.UpdateTransactionsByPage()
    116         self.PopulateScroll()
    117 
    118     def OnMinPriceEditChange(self, *args):
    119         self.UpdateTransactionsByPage()
    120         self.PopulateScroll()
    121 
    122     def OnQuantityEditChange(self, *args):
    123         self.UpdateTransactionsByPage()
    124         self.PopulateScroll()
    125 
    126     def GetIssuer(self, string, exact = 0):
    127         ownerID = searchOld.Search(string.lower(), groupID=groupCharacter, categoryID=categoryOwner, hideNPC=1, exact=exact, searchWndName='walletIssuerSearch')
    128         if ownerID:
    129             return (cfg.eveowners.Get(ownerID).name, ownerID)
    130         return (string, None)
    131 
    132     def UpdateTransactions(self):
    133         fromDate = None
    134         transactions = self._GetTransactions(fromDate)
    135         cfg.eveowners.Prime([ tr.clientID for tr in transactions ])
    136         self._transactionsList.LoadTransactions([ MarketTransaction(GetTransactionKeyVal(t)) for t in transactions ])
    137         self.UpdateItemTypeCombo()
    138         self.UpdateTransactionsByPage()
    139 
    140     def IsTransactionVisible(self, transaction):
    141         showBuyTransactions = self.sellBuyCombo.GetValue()
    142         if showBuyTransactions is not None:
    143             if showBuyTransactions != transaction.data.isBuyTransaction:
    144                 return False
    145         typeID = self.itemTypeCombo.GetValue()
    146         if typeID:
    147             if typeID != transaction.data.typeID:
    148                 return False
    149         quantity = self.GetQuantityFilterValue()
    150         if quantity:
    151             if quantity > transaction.data.quantity:
    152                 return False
    153         minPrice = self.GetMinPriceFilterValue()
    154         if minPrice:
    155             if minPrice > math.fabs(transaction.data.totalPrice):
    156                 return False
    157         return True
    158 
    159     def UpdateItemTypeCombo(self):
    160         options = self._transactionsList.GetAvailableItemTypes()
    161         options = sorted(list(options))
    162         options.insert(0, (GetByLabel('UI/Wallet/WalletWindow/AnyItem'), 0))
    163         self.itemTypeCombo.LoadOptions(options)
    164 
    165     def GetMinPriceFilterValue(self):
    166         minPrice = self.minPriceEdit.GetValue()
    167         if minPrice == '':
    168             minPrice = None
    169         else:
    170             minPrice = int(minPrice)
    171         return minPrice
    172 
    173     def GetQuantityFilterValue(self):
    174         quantity = self.qtyEdit.GetValue()
    175         if quantity == '':
    176             quantity = None
    177         else:
    178             quantity = int(quantity)
    179         return quantity
    180 
    181     def GetScrollEntry(self, tr):
    182         lines = self._GetTransactionEntryLines(tr)
    183         text = '<t>'.join(lines)
    184         data = self.GetScrollEntryData(text, tr)
    185         return GetFromClass(Generic, data)
    186 
    187     def GetScrollEntryData(self, text, tr):
    188         data = utillib.KeyVal()
    189         if tr.data.isForCorp:
    190             data.hint = eveformat.color(text=GetByLabel('UI/Wallet/WalletWindow/HintCorpTransaction'), color=COLOR_CORPORATION)
    191         data.OnDblClick = lambda *args: sm.StartService('marketutils').ShowMarketDetails(tr.data.typeID, None)
    192         data.rec = tr.data
    193         data.label = text
    194         data.name = 'marketTransaction_{}'.format(tr.data.typeID)
    195         data.clientID = tr.data.clientID
    196         data.GetMenu = self.OnTransactionMenu
    197         data.Set('sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderQuantity'), tr.data.quantity)
    198         data.Set('sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderPrice'), tr.data.price)
    199         data.Set('sort_%s' % GetByLabel('UI/Common/Date'), tr.data.transactionID)
    200         data.Set('sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderCredit'), tr.data.totalPrice)
    201         return data
    202 
    203     def _GetTransactionEntryLines(self, tr):
    204         lines = []
    205         dateText = tr.dateString
    206         if tr.data.isForCorp:
    207             dateText = eveformat.color(text=dateText, color=COLOR_CORPORATION)
    208         lines.append(dateText)
    209         rightQty = '<right>%s' % tr.qtyString
    210         lines.append(rightQty)
    211         lines.append(tr.typeString)
    212         rightPrice = '<right>%s' % eveformat.color(text=tr.unitPriceString, color=TextColor.HIGHLIGHT)
    213         lines.append(rightPrice)
    214         color = TextColor.DANGER if tr.data.isBuyTransaction else TextColor.SUCCESS
    215         rightCurrency = '<right>%s' % eveformat.color(text=tr.totalString, color=color)
    216         lines.append(rightCurrency)
    217         leftClient = '<left>%s' % tr.clientString
    218         lines.append(leftClient)
    219         leftLocation = '<left>%s' % tr.whereString
    220         lines.append(leftLocation)
    221         return lines
    222 
    223     def OnTransactionMenu(self, entry):
    224         m = GetMenuService().GetMenuFromItemIDTypeID(None, entry.sr.node.rec.typeID, includeMarketDetails=True)
    225         m += [None]
    226         stationID = entry.sr.node.rec.stationID
    227         stationTypeID = solarSystemID = None
    228         if idCheckers.IsStation(stationID):
    229             stationInfo = sm.GetService('ui').GetStationStaticInfo(stationID)
    230             stationTypeID = stationInfo.stationTypeID
    231             solarSystemID = stationInfo.solarSystemID
    232         else:
    233             structureInfo = sm.GetService('structureDirectory').GetStructureInfo(stationID)
    234             if structureInfo:
    235                 stationTypeID = structureInfo.typeID
    236                 solarSystemID = structureInfo.solarSystemID
    237         if stationTypeID and solarSystemID:
    238             m += [(MenuLabel('UI/Wallet/WalletWindow/MenuLocation'), GetMenuService().CelestialMenu(stationID, typeID=stationTypeID, parentID=solarSystemID))]
    239         m += [(MenuLabel('UI/Wallet/WalletWindow/ColHeaderClient'), GetMenuService().CharacterMenu(entry.sr.node.clientID))]
    240         return m
    241 
    242     def OnDropData(self, dragSource, dragData):
    243         typeID = dragData[0].invtype
    244         itemExists = self.itemTypeCombo.SelectItemByValue(typeID)
    245         if itemExists:
    246             self.OnItemTypeCombo()
    247         else:
    248             message_player(GetByLabel('UI/Wallet/WalletWindow/NoTransactionsFoundForType', typeID=typeID))