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

buytItemEntry.py (12848B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\market\buytItemEntry.py
      2 from carbon.common.script.util.format import FmtAmt
      3 from carbon.common.script.util.linkUtil import GetShowInfoLink
      4 from carbon.common.script.util.timerstuff import AutoTimer
      5 from carbonui import const as uiconst
      6 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      9 from carbonui.primitives.sprite import Sprite
     10 from carbonui.control.buttonIcon import ButtonIcon
     11 from eve.client.script.ui.shared.market.util import get_regional_average_text, get_regional_best_text
     12 from eve.client.script.ui.control.eveLabel import EveLabelMediumBold, Label
     13 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     14 from eve.client.script.ui.control.itemIcon import ItemIcon
     15 from eve.client.script.ui.shared.industry.views.errorFrame import ErrorFrame
     16 from eve.client.script.ui.shared.market.buySellItemContainerBase import BuySellItemContainerBase
     17 from eve.client.script.ui.shared.market.deltaContainer import BuyDeltaContainer
     18 from eve.client.script.ui.util.uix import GetTechLevelIcon
     19 from eve.common.lib.appConst import rangeStation, rangeRegion, rangeSolarSystem
     20 from eve.common.script.util.eveFormat import FmtISK
     21 import evetypes
     22 from localization import GetByLabel
     23 from carbonui.uicore import uicore
     24 NA_CHAR = '-'
     25 
     26 class BuyItemContainer(BuySellItemContainerBase):
     27     __guid__ = 'uicls.BuytemContainer'
     28     default_height = 52
     29     belowColor = '<color=0xff00ff00>'
     30     aboveColor = '<color=0xffff5050>'
     31     totaLabelPath = 'UI/Market/MarketQuote/PayTotal'
     32 
     33     def ApplyAttributes(self, attributes):
     34         self.blinkBG = None
     35         self.typeID = attributes.typeID
     36         self.dropParentFunc = attributes.dropParentFunc
     37         BuySellItemContainerBase.ApplyAttributes(self, attributes)
     38         self.adjustQtyTimer = None
     39         self.isUpdating = False
     40         self.totalSum = 0.0
     41         self.orderMultiplier = attributes.orderMultiplier
     42         self.qty = attributes.qty
     43         self.stationID = attributes.stationID
     44         self.newBestPrice, self.numOrders = self.quoteSvc.GetBestAskPriceInStationAndNumberOrders(self.typeID, self.stationID, self.qty)
     45         self.DrawUI()
     46         self.UpdateUIElements()
     47         self.GetBestPrice()
     48 
     49     def DrawUI(self):
     50         self.errorBg = ErrorFrame(bgParent=self)
     51         self.rightCont = Container(name='rightCont', parent=self, align=uiconst.TORIGHT_PROP, width=0.3)
     52         self.priceCont = Container(name='priceCont', parent=self, align=uiconst.TORIGHT_PROP, width=0.22)
     53         self.qtyCont = Container(name='qtyCont', parent=self, align=uiconst.TORIGHT_PROP, width=0.15)
     54         self.itemCont = Container(name='itemCont', parent=self, align=uiconst.TORIGHT_PROP, width=0.33)
     55         self.deleteCont = Container(name='deleteCont', parent=self.itemCont, align=uiconst.TORIGHT, width=24)
     56         self.totalCont = ContainerAutoSize(name='totalCont', parent=self.rightCont, align=uiconst.CENTERRIGHT, padRight=4)
     57         self.deleteButton = ButtonIcon(texturePath='res:/UI/Texture/Icons/73_16_210.png', pos=(0, 0, 16, 16), align=uiconst.CENTERRIGHT, parent=self.deleteCont, hint=GetByLabel('UI/Generic/RemoveItem'), idx=0, func=self.RemoveItem)
     58         self.deleteCont.display = False
     59         self.textCont = Container(name='textCont', parent=self.itemCont, align=uiconst.TOALL)
     60         self.DrawItem()
     61         self.DrawQty()
     62         self.DrawPrice()
     63         self.DrawTotal()
     64         self.DrawDelta()
     65 
     66     def UpdateUIElements(self):
     67         self.UpdateOrderStateInUI()
     68         self.GetBestPrice()
     69         self.SetPrice()
     70         self.UpdateDelta()
     71 
     72     def GetBestOrderInRange(self):
     73         stationID = self.stationID
     74         bidRange = None
     75         return self.quoteSvc.GetBestAskInRange(typeID=self.typeID, stationID=stationID, bidRange=bidRange, amount=self.qty)
     76 
     77     def ShowNoSellOrders(self):
     78         if self.newBestPrice is None:
     79             uicore.animations.FadeIn(self.errorBg, 0.35, duration=0.3)
     80 
     81     def DrawQty(self):
     82         self.qtySubCont = ContainerAutoSize(name='qtySubCont', parent=self.qtyCont, align=uiconst.TOTOP, callback=self.PositionQtyContainer)
     83         qty = self.qty
     84         self.qtyEdit = SingleLineEditInteger(name='qtyEdit', parent=self.qtySubCont, align=uiconst.TOTOP, padLeft=4, minValue=1, setvalue=qty, OnChange=self.OnChange, hint=GetByLabel('UI/Common/Quantity'))
     85         self.qtyEdit.OnMouseWheel = self.OnMouseWheelForQtyEdit
     86         self.qtyTotal = EveLabelMediumBold(text='', parent=self.qtySubCont, padLeft=8, padTop=6, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, autoFadeSides=35)
     87         self.SetTotalQtyText()
     88 
     89     def OnMouseWheelForQtyEdit(self, *args):
     90         if uicore.registry.GetFocus() != self.qtyEdit:
     91             return
     92         SingleLineEditInteger.OnMouseWheel(self.qtyEdit, *args)
     93 
     94     def PositionQtyContainer(self):
     95         subContTop = self.height / 2.0 - self.qtySubCont.GetAutoSize()[1] / 2.0
     96         self.qtySubCont.top = int(subContTop)
     97 
     98     def DrawPrice(self):
     99         self.priceLabel = EveLabelMediumBold(name='priceLabel', text='', parent=self.priceCont, left=4, align=uiconst.CENTERRIGHT, state=uiconst.UI_NORMAL)
    100 
    101     def DrawDelta(self):
    102         self.deltaContainer = BuyDeltaContainer(parent=self.totalCont, delta=self.GetDelta(), func=self.OpenMarket, align=uiconst.TOPRIGHT, top=16)
    103         self.deltaContainer.LoadTooltipPanel = self.LoadDeltaTooltip
    104 
    105     def DrawItem(self):
    106         iconCont = Container(name='iconCont', parent=self.textCont, align=uiconst.TOLEFT, width=32, padding=4)
    107         iconInnerCont = Container(name='iconInnerCont', parent=iconCont, align=uiconst.CENTER, pos=(0, 0, 32, 32))
    108         self.wheel = LoadingWheel(parent=iconCont, pos=(0, 0, 48, 48), align=uiconst.CENTER, idx=0)
    109         self.wheel.display = False
    110         self.techIcon = Sprite(parent=iconInnerCont, pos=(0, 0, 16, 16), align=uiconst.TOPLEFT, state=uiconst.UI_NORMAL)
    111         GetTechLevelIcon(self.techIcon, 1, self.typeID)
    112         self.icon = ItemIcon(parent=iconInnerCont, typeID=self.typeID, state=uiconst.UI_DISABLED, align=uiconst.CENTER, pos=(0, 0, 32, 32))
    113         itemName = GetShowInfoLink(typeID=self.typeID, text=evetypes.GetName(self.typeID))
    114         self.itemNameLabel = Label(text=itemName, parent=self.textCont, left=40, align=uiconst.CENTERLEFT, state=uiconst.UI_NORMAL, autoFadeSides=35, fontsize=12)
    115 
    116     def SetPrice(self):
    117         self.priceLabel.text = self.GetPriceText()
    118 
    119     def GetPriceText(self):
    120         if self.newBestPrice:
    121             return FmtISK(self.newBestPrice)
    122         else:
    123             return NA_CHAR
    124 
    125     def GetBestPrice(self):
    126         totalQty = self.qty * self.orderMultiplier
    127         self.newBestPrice, self.numOrders = self.quoteSvc.GetBestAskPriceInStationAndNumberOrders(self.typeID, self.stationID, totalQty)
    128         self.UpdateOrderStateInUI()
    129 
    130     def UpdateOrderStateInUI(self):
    131         if self.newBestPrice:
    132             self.HideNoSellOrders()
    133         else:
    134             self.ShowNoSellOrders()
    135 
    136     def GetTotalSum(self):
    137         price = self.GetPrice() or 0
    138         totalQty = self.GetQty() * self.orderMultiplier
    139         self.totalSum = price * totalQty
    140         self.SetTotalText(self.totalSum)
    141         return self.totalSum
    142 
    143     def SetTotalText(self, totalSum):
    144         if totalSum:
    145             self.totalLabel.text = FmtISK(totalSum)
    146         else:
    147             self.totalLabel.text = NA_CHAR
    148 
    149     def UpdateOrderMultiplier(self, multiplier):
    150         self.orderMultiplier = multiplier
    151         self.OnChange()
    152 
    153     def UpdateStationID(self, stationID):
    154         self.stationID = stationID
    155         self.UpdateUIElements()
    156 
    157     def OnChange(self, *args):
    158         if self.adjustQtyTimer:
    159             self.adjustQtyTimer.KillTimer()
    160         self.adjustQtyTimer = AutoTimer(1000, self.AdjustQty_thread, *args)
    161         self.SetItemLoading()
    162 
    163     def OnMouseEnter(self, *args):
    164         BuySellItemContainerBase.OnMouseEnter(self, *args)
    165         self.icon.OnMouseEnter()
    166 
    167     def OnMouseExit(self, *args):
    168         BuySellItemContainerBase.OnMouseExit(self, *args)
    169         self.icon.OnMouseExit()
    170 
    171     def SetItemLoading(self):
    172         self.wheel.display = True
    173         self.qtyTotal.text = ''
    174         self.totalLabel.text = ''
    175         self.priceLabel.text = NA_CHAR
    176         self.deltaContainer.display = False
    177         self.totalLabel.text = NA_CHAR
    178         self.isUpdating = True
    179 
    180     def AdjustQty_thread(self, *args):
    181         self.adjustQtyTimer = None
    182         if self.destroyed:
    183             return
    184         self.qty = self.GetQty()
    185         self.SetTotalQtyText()
    186         self.GetBestPrice()
    187         self.SetPrice()
    188         self.deltaContainer.display = True
    189         self.UpdateDelta()
    190         self.GetTotalSum()
    191         self.wheel.display = False
    192         self.isUpdating = False
    193         if self.parentEditFunc:
    194             self.parentEditFunc(args)
    195 
    196     def SetTotalQtyText(self):
    197         totalQty = self.GetTotalQty()
    198         if totalQty is None:
    199             self.qtyTotal.text = ''
    200             self.qtyTotal.hint = ''
    201         elif self.orderMultiplier > 1:
    202             self.qtyTotal.display = True
    203             self.qtyTotal.text = '= %s' % FmtAmt(totalQty)
    204             self.qtyTotal.hint = GetByLabel('UI/Market/MarketQuote/TotalAmountToBuy', numOrders=self.orderMultiplier, qty=self.GetQty())
    205         else:
    206             self.qtyTotal.display = False
    207 
    208     def GetPrice(self):
    209         return self.newBestPrice
    210 
    211     def GetQty(self):
    212         qty = self.qtyEdit.GetValue()
    213         return qty
    214 
    215     def GetTotalQty(self):
    216         qty = self.GetQty()
    217         return self.orderMultiplier * qty
    218 
    219     def GetTradeWndClass(self):
    220         from eve.client.script.ui.shared.market.buyMultiFromBase import MultiBuy
    221         return MultiBuy
    222 
    223     def GetDiffFromAvgText(self):
    224         return '%s %s' % (get_regional_average_text(self.typeID), self.GetDeltaText())
    225 
    226     def LoadDeltaTooltip(self, tooltipPanel, *args):
    227         tooltipPanel.LoadGeneric2ColumnTemplate()
    228         tooltipPanel.cellPadding = (4, 1, 4, 1)
    229         tooltipPanel.AddLabelLarge(text=GetByLabel('UI/Market/Marketbase/PricePerUnit'))
    230         tooltipPanel.AddLabelLarge(text=self.GetPriceText(), align=uiconst.CENTERRIGHT)
    231         bestMatchDetails = tooltipPanel.AddLabelSmall(text='', align=uiconst.CENTERRIGHT, colSpan=tooltipPanel.columns)
    232         tooltipPanel.AddSpacer(1, 8, colSpan=tooltipPanel.columns)
    233         tooltipPanel.AddLabelMedium(text=self.GetDiffFromAvgText(), align=uiconst.CENTERRIGHT)
    234         tooltipPanel.AddLabelMedium(text=FmtISK(self.averagePrice), align=uiconst.CENTERRIGHT)
    235         tooltipPanel.AddSpacer(1, 8, colSpan=tooltipPanel.columns)
    236         tooltipPanel.AddLabelMedium(text=GetByLabel('UI/Market/MarketQuote/BestInStation'))
    237         stationBestPrice = self.GetBestMatchText(rangeStation)
    238         tooltipPanel.AddLabelMedium(text=stationBestPrice, align=uiconst.CENTERRIGHT)
    239         tooltipPanel.AddLabelMedium(text=GetByLabel('UI/Market/MarketQuote/BestInSystem'))
    240         stationBestPrice = self.GetBestMatchText(rangeSolarSystem)
    241         tooltipPanel.AddLabelMedium(text=stationBestPrice, align=uiconst.CENTERRIGHT)
    242         tooltipPanel.AddLabelMedium(text=get_regional_best_text(self.typeID))
    243         regBestPrice = self.GetBestMatchText(rangeRegion)
    244         tooltipPanel.AddLabelMedium(text=regBestPrice, align=uiconst.CENTERRIGHT)
    245         if not self.newBestPrice:
    246             bestMatchDetails.text = GetByLabel('UI/Market/MarketQuote/NoMatchForOrder')
    247             bestMatchDetails.color = (1.0, 0.275, 0.0, 1.0)
    248         else:
    249             bestMatchDetails.text = GetByLabel('UI/Market/MarketQuote/FromNumberOfOrders', numOrders=self.numOrders)
    250             bestMatchDetails.SetAlpha(0.6)
    251 
    252     def GetBestMatchText(self, orderRange):
    253         if not self.stationID:
    254             return NA_CHAR
    255         bestOrder = self.quoteSvc.GetBestAskInRange(self.typeID, self.stationID, orderRange)
    256         if bestOrder:
    257             return FmtISK(bestOrder.price)
    258         return NA_CHAR
    259 
    260     def AddQtyToEntry(self, extraQty):
    261         self.Blink()
    262         qty = self.qtyEdit.GetValue()
    263         newQty = extraQty + qty
    264         self.qtyEdit.SetValue(newQty)
    265 
    266     def Blink(self):
    267         self.ConstructBlinkBG()
    268         uicore.animations.FadeTo(self.blinkBG, 0.0, 0.25, duration=0.25, curveType=uiconst.ANIM_WAVE, loops=2)
    269 
    270     def ConstructBlinkBG(self):
    271         if self.blinkBG is None:
    272             self.blinkBG = Sprite(name='blinkBg', bgParent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/InvItem/bgSelected.png', opacity=0.0, idx=0)
    273 
    274     def OnDropData(self, dragSource, dragData):
    275         if self.dropParentFunc:
    276             self.dropParentFunc(dragSource, dragData)