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

shipscan.py (11660B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\shipscan.py
      2 from carbonui.primitives.frame import Frame
      3 from collections import OrderedDict, defaultdict
      4 import dogma.data
      5 import evetypes
      6 import localization
      7 import utillib
      8 from carbonui import uiconst
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.fill import Fill
     11 from carbonui.util.sortUtil import SortListOfTuples
     12 from dogma import units
     13 from eve.client.script.ui.control.entries.item import Item
     14 from eve.client.script.ui.control.entries.text import Text
     15 from eve.client.script.ui.control.entries.util import GetFromClass
     16 from carbonui.control.window import Window
     17 from eve.client.script.ui.util import uix
     18 from eve.client.script.ui.control import eveLabel, eveScroll
     19 from eve.client.script.ui.control.themeColored import FillThemeColored, SpriteThemeColored
     20 from eve.client.script.ui.shared.fittingScreen.fittingSearchUtil import SearchFittingHelper
     21 from eve.client.script.ui.shared.info.panels.panelFitting import FITTING_SLOT_INFO
     22 from eve.common.script.util.eveFormat import FmtISKAndRound, GetAveragePrice
     23 
     24 class ShipScan(Window):
     25     default_windowID = 'shipscan'
     26     default_iconNum = 'res:/ui/Texture/WindowIcons/shipScan.png'
     27     default_minSize = (200, 200)
     28     default_width = 400
     29     default_height = 300
     30 
     31     def ApplyAttributes(self, attributes):
     32         Window.ApplyAttributes(self, attributes)
     33         self.DefineButtons(uiconst.CLOSE)
     34         self.topParent = Container(name='topParent', parent=self.GetMainArea(), align=uiconst.TOTOP, height=52, clipChildren=True)
     35         self.sr.capacityText = eveLabel.EveHeaderSmall(text=' ', name='capacityText', parent=self.topParent, left=8, top=4, align=uiconst.TOPRIGHT, state=uiconst.UI_DISABLED)
     36         self.sr.gaugeParent = Container(name='gaugeParent', align=uiconst.TOPRIGHT, parent=self.topParent, left=const.defaultPadding, height=7, width=100, state=uiconst.UI_DISABLED, top=self.sr.capacityText.top + self.sr.capacityText.textheight + 1)
     37         Frame(parent=self.sr.gaugeParent, color=(0.5, 0.5, 0.5, 0.3))
     38         self.sr.gauge = Container(name='gauge', align=uiconst.TOLEFT, parent=self.sr.gaugeParent, state=uiconst.UI_PICKCHILDREN, width=0)
     39         Fill(parent=self.sr.gaugeParent, color=(0.0, 0.521, 0.67, 0.1), align=uiconst.TOALL)
     40         Fill(parent=self.sr.gauge, color=(0.0, 0.521, 0.67, 0.6))
     41         self.sr.scroll = eveScroll.Scroll(parent=self.sr.main, padding=(const.defaultPadding,
     42          const.defaultPadding,
     43          const.defaultPadding,
     44          const.defaultPadding))
     45         t = eveLabel.EveHeaderSmall(text=localization.GetByLabel('UI/Ship/ShipScan/hdrModulesFitted'), parent=self.topParent, left=8, state=uiconst.UI_DISABLED, align=uiconst.BOTTOMLEFT)
     46         self.LoadResult(*attributes.results)
     47 
     48     def LoadResult(self, capacitorCharge, capacitorCapacity, moduleList):
     49         total, full = capacitorCapacity, capacitorCharge
     50         if total:
     51             proportion = min(1.0, max(0.0, full / float(total)))
     52         else:
     53             proportion = 1.0
     54         self.sr.gauge.width = int(proportion * self.sr.gaugeParent.width)
     55         unit = units.get_display_name(const.unitCapacitorUnits)
     56         self.sr.capacityText.text = localization.GetByLabel('UI/Ship/ShipScan/CapacityResults', full=full, total=total, units=unit)
     57         scrolllist = []
     58         slotTypeDict = OrderedDict([(const.effectHiPower, defaultdict(int)),
     59          (const.effectMedPower, defaultdict(int)),
     60          (const.effectLoPower, defaultdict(int)),
     61          (const.effectSubSystem, defaultdict(int)),
     62          (const.effectRigSlot, defaultdict(int)),
     63          (const.effectServiceSlot, defaultdict(int))])
     64         slotInfoBySlotType = {x['effectID']:x for x in FITTING_SLOT_INFO}
     65         charges = set()
     66         other = defaultdict(int)
     67         fittingHelper = SearchFittingHelper(cfg)
     68         for info in moduleList:
     69             if type(info) == type(()):
     70                 typeID, quantity = info
     71             else:
     72                 typeID, quantity = info.typeID, info.stacksize
     73             if evetypes.GetCategoryID(typeID) == const.categoryCharge:
     74                 charges.add(typeID)
     75             else:
     76                 slotType = fittingHelper.GetSlotTypeForModuleType(typeID)
     77                 if slotType in slotTypeDict:
     78                     slotTypeDict[slotType][typeID] += quantity
     79                 else:
     80                     other[typeID] += quantity
     81 
     82         scrolllist = []
     83         for slotType, moduleList in slotTypeDict.iteritems():
     84             if not moduleList:
     85                 continue
     86             toSort = []
     87             for typeID, quantity in moduleList.iteritems():
     88                 typeName = evetypes.GetName(typeID)
     89                 for i in range(quantity):
     90                     entry = self.GetData(typeID, typeName)
     91                     toSort.append((typeName, entry))
     92 
     93             slotInfo = slotInfoBySlotType.get(slotType)
     94             if slotInfo:
     95                 iconID = dogma.data.get_attribute_icon_id(slotInfo['attributeID'])
     96                 scrolllist.append(GetFromClass(HeaderEntry, {'text': self.GetFittingSlotEntryLabel(slotInfo),
     97                  'iconID': iconID,
     98                  'line': 1}))
     99                 scrolllist += SortListOfTuples(toSort)
    100 
    101         if charges:
    102             scrolllist.append(GetFromClass(HeaderEntry, {'text': localization.GetByLabel('UI/Common/ItemTypes/Charges'),
    103              'line': 1}))
    104             toSort = []
    105             for eachChargeTypeID in charges:
    106                 entry = self.GetData(eachChargeTypeID, evetypes.GetName(eachChargeTypeID))
    107                 toSort.append((evetypes.GetName(eachChargeTypeID), entry))
    108 
    109             scrolllist += SortListOfTuples(toSort)
    110         if other:
    111             scrolllist.append(GetFromClass(HeaderEntry, {'text': localization.GetByLabel('UI/Common/Other'),
    112              'line': 1}))
    113             toSort = []
    114             for typeID, quantity in other.iteritems():
    115                 typeName = evetypes.GetName(typeID)
    116                 label = '%sx %s' % (quantity, typeName)
    117                 entry = self.GetData(typeID, label)
    118                 toSort.append((typeName, entry))
    119 
    120             scrolllist += SortListOfTuples(toSort)
    121         self.sr.scroll.Load(contentList=scrolllist)
    122         if len(scrolllist) == 0:
    123             self.SetHint(localization.GetByLabel('UI/Ship/ShipScan/hintNoModulesDetected'))
    124         else:
    125             self.SetHint(None)
    126 
    127     def GetFittingSlotEntryLabel(self, slotInfo):
    128         if slotInfo['attributeID'] == const.attributeUpgradeSlotsLeft:
    129             return localization.GetByLabel('UI/Corporations/Wars/Killmails/RigSlots')
    130         return localization.GetByLabel(slotInfo['label'])
    131 
    132     def GetData(self, typeID, typeName):
    133         entry = GetFromClass(Item, {'label': typeName,
    134          'itemID': None,
    135          'typeID': typeID,
    136          'getIcon': 1,
    137          'sublevel': 1})
    138         return entry
    139 
    140     def SetHint(self, hintstr = None):
    141         if self.sr.scroll:
    142             self.sr.scroll.ShowHint(hintstr)
    143 
    144 
    145 class CargoScan(Window):
    146     default_windowID = 'cargoScan'
    147     default_iconNum = 'res:/ui/Texture/WindowIcons/cargoScan.png'
    148     default_minSize = (200, 200)
    149     default_width = 400
    150     default_height = 300
    151 
    152     def ApplyAttributes(self, attributes):
    153         Window.ApplyAttributes(self, attributes)
    154         shipID = attributes.shipID
    155         cargoList = attributes.cargoList
    156         bp = sm.GetService('michelle').GetBallpark()
    157         if not bp:
    158             return
    159         slimItem = bp.slimItems[shipID]
    160         shipName = uix.GetSlimItemName(slimItem)
    161         self.SetCaption(localization.GetByLabel('UI/Ship/ShipScan/ShipNameCargo', shipName=shipName, cargoListLen=len(cargoList)))
    162         self.DefineButtons(uiconst.CLOSE)
    163         eveLabel.EveHeaderSmall(text=localization.GetByLabel('UI/Ship/ShipScan/hdrCargoScan'), parent=self.sr.main, state=uiconst.UI_DISABLED, align=uiconst.TOTOP)
    164         self.bottomRightCont = Container(name='bottomRightcont', parent=self.sr.main, align=uiconst.TOBOTTOM, height=40, clipChildren=True)
    165         self.bottomRightLabelCont = Container(name='bottomRightLabelCont', parent=self.bottomRightCont, clipChildren=True)
    166         self.totalPriceLabel = eveLabel.Label(name='totalPriceLabel', parent=self.bottomRightLabelCont, align=uiconst.BOTTOMRIGHT, pos=(5, 4, 0, 0))
    167         self.numItemsLabel = eveLabel.Label(name='numItemsLabel', parent=self.bottomRightLabelCont, align=uiconst.BOTTOMRIGHT, pos=(5, 20, 0, 0))
    168         self.sr.scroll = eveScroll.Scroll(parent=self.sr.main, padding=(const.defaultPadding,
    169          const.defaultPadding,
    170          const.defaultPadding,
    171          const.defaultPadding))
    172         self.sr.scroll.OnSelectionChange = self.OnItemSelectionChanged
    173 
    174     def ShowInfo(self, typeID, isCopy):
    175         sm.GetService('info').ShowInfo(typeID)
    176 
    177     def LoadResult(self, cargoList):
    178         scrolllist = []
    179         for typeID, quantity in cargoList:
    180             qty = quantity if quantity > 0 else 1
    181             isCopy = False
    182             param = {'qty': qty,
    183              'typeID': typeID}
    184             categoryID = evetypes.GetCategoryID(typeID)
    185             if categoryID == const.categoryBlueprint:
    186                 if quantity == -const.singletonBlueprintCopy:
    187                     typeName = 'UI/Ship/ShipScan/BlueprintCopy'
    188                     quantity = 1
    189                     isCopy = True
    190                 else:
    191                     typeName = 'UI/Ship/ShipScan/BlueprintOriginal'
    192             else:
    193                 typeName = 'UI/Ship/ShipScan/FoundTypes'
    194             data = {'label': localization.GetByLabel(typeName, **param),
    195              'itemID': None,
    196              'typeID': typeID,
    197              'isCopy': isCopy,
    198              'getIcon': True,
    199              'qty': qty}
    200             if categoryID == const.categoryBlueprint:
    201                 data['abstractinfo'] = utillib.KeyVal(categoryID=const.categoryBlueprint, isCopy=isCopy)
    202             scrolllist.append(GetFromClass(Item, data))
    203 
    204         self.sr.scroll.Load(contentList=scrolllist, noContentHint=localization.GetByLabel('UI/Ship/ShipScan/NoBookmarksFound'))
    205         self.UpdateNumbers()
    206 
    207     def OnItemSelectionChanged(self, *args):
    208         self.UpdateNumbers()
    209 
    210     def UpdateNumbers(self):
    211         self.UpdateNumberOfItems()
    212         self.UpdateIskPriceLabel()
    213 
    214     def UpdateNumberOfItems(self):
    215         numSelected = len(self.sr.scroll.GetSelected())
    216         numTotal = len(self.sr.scroll.sr.nodes)
    217         if numSelected:
    218             text = localization.GetByLabel('UI/Inventory/NumItemsAndSelected', numItems=numTotal, numSelected=numSelected, numFilteredTxt='')
    219         else:
    220             text = localization.GetByLabel('UI/Inventory/NumItems', numItems=numTotal, numFilteredTxt='')
    221         self.numItemsLabel.text = text
    222 
    223     def UpdateIskPriceLabel(self):
    224         total = 0
    225         numSelected = len(self.sr.scroll.GetSelected())
    226         for eachNode in self.sr.scroll.GetNodes():
    227             if eachNode.isCopy:
    228                 continue
    229             if numSelected and not eachNode.selected:
    230                 continue
    231             price = GetAveragePrice(eachNode)
    232             if price:
    233                 total += price * eachNode.qty
    234 
    235         text = localization.GetByLabel('UI/Inventory/EstIskPrice', iskString=FmtISKAndRound(total, False))
    236         self.totalPriceLabel.text = text
    237 
    238 
    239 class HeaderEntry(Text):
    240 
    241     def Startup(self, *args):
    242         super(HeaderEntry, self).Startup(*args)
    243         FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT)
    244 
    245     def GetHeight(self, *args):
    246         node, width = args
    247         node.height = 28
    248         return 28