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

redeemItem.py (13161B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\redeem\redeemItem.py
      2 from carbon.common.lib.const import MIN, HOUR, DAY
      3 from carbon.common.script.util.commonutils import GetAttrs
      4 from carbonui import uiconst, fontconst
      5 from carbonui.control.scrollentries import SE_BaseClassCore
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.sprite import Sprite
      9 from eve.client.script.ui import eveColor
     10 from eve.client.script.ui.control.eveIcon import Icon
     11 from eve.client.script.ui.control.eveLabel import EveLabelMediumBold, EveLabelSmall, EveLabelSmallBold, Label
     12 from eve.client.script.ui.control.eveWindowUnderlay import ListEntryUnderlay
     13 from eve.client.script.ui.control.infoIcon import InfoIcon
     14 from eve.client.script.ui.shared.container import ItemSortData
     15 from eve.client.script.ui.shared.redeem.redeemUiConst import CREATION_DATE_SORT_KEY, EXPIRY_DATE_SORT_KEY
     16 from eve.client.script.ui.shared.tooltip.blueprints import AddBlueprintInfo
     17 from evetypes import GetName, GetCategoryID, GetGroupID
     18 from gametime import GetWallclockTime
     19 from inventorycommon.const import flagHangar
     20 from localization import GetByLabel
     21 from localization.formatters import FormatTimeIntervalShortWritten, TIME_CATEGORY_DAY, TIME_CATEGORY_HOUR, TIME_CATEGORY_MINUTE, TIME_CATEGORY_SECOND
     22 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     23 from utillib import KeyVal
     24 PICTURE_CONTAINER_HEIGHT = 75
     25 ITEM_NAME_HEIGHT = 32
     26 ITEM_DESCRIPTION_HEIGHT = 15
     27 ITEM_EXPIRY_HEIGHT = 15
     28 BOTTOM_PADDING = 3
     29 ITEM_NAME_PADDING = 4
     30 REDEEM_ITEM_WIDTH = 140
     31 PICTURE_SIZE = 64
     32 
     33 def GetRedeemItemHeight():
     34     return PICTURE_CONTAINER_HEIGHT + ITEM_NAME_HEIGHT + ITEM_DESCRIPTION_HEIGHT + ITEM_EXPIRY_HEIGHT + BOTTOM_PADDING
     35 
     36 
     37 def GetRedeemItemHeightWithoutDescription():
     38     return GetRedeemItemHeight() - ITEM_DESCRIPTION_HEIGHT
     39 
     40 
     41 class RedeemItemEntryUnderlay(ListEntryUnderlay):
     42     OPACITY_IDLE = 0.03
     43     OPACITY_HOVER = 0.3
     44     OPACITY_MOUSEDOWN = 0.35
     45     OPACITY_SELECTED = 0.2
     46     IDLE_COLOR = (1.0,
     47      1.0,
     48      1.0,
     49      OPACITY_IDLE)
     50     MOUSEDOWN_COLOR = (1.0,
     51      1.0,
     52      1.0,
     53      OPACITY_MOUSEDOWN)
     54     SELECTION_COLOR = (1.0,
     55      1.0,
     56      1.0,
     57      OPACITY_SELECTED)
     58     default_color = IDLE_COLOR
     59     default_opacity = OPACITY_IDLE
     60 
     61     def OnMouseDown(self, *args):
     62         super(RedeemItemEntryUnderlay, self).OnMouseDown(*args)
     63         self.color = self.MOUSEDOWN_COLOR
     64 
     65     def OnMouseUp(self, *args):
     66         super(RedeemItemEntryUnderlay, self).OnMouseUp(*args)
     67         self.color = self.SELECTION_COLOR
     68 
     69 
     70 class RedeemItem(SE_BaseClassCore):
     71     __guid__ = 'xtriui.InvItem'
     72     default_name = 'RedeemItem'
     73     default_showInfo = True
     74     default_showDescription = True
     75 
     76     def ApplyAttributes(self, attributes):
     77         super(RedeemItem, self).ApplyAttributes(attributes)
     78         self.showInfo = attributes.get('showInfo', self.default_showInfo)
     79         self.showDescription = attributes.get('showDescription', self.default_showDescription)
     80         self.redeemSvc = sm.GetService('redeem')
     81 
     82     @classmethod
     83     def GetEntryHeight(cls):
     84         return GetRedeemItemHeight()
     85 
     86     @classmethod
     87     def GetEntryWidth(cls):
     88         return REDEEM_ITEM_WIDTH
     89 
     90     @classmethod
     91     def GetEntryColMargin(cls):
     92         return 16
     93 
     94     @classmethod
     95     def IsFixedWidth(cls):
     96         return True
     97 
     98     def ConstructLayout(self):
     99         self.ConstructHiliteFill()
    100         self.itemContainer = Container(parent=self, name='itemContainer', align=uiconst.NOALIGN, width=REDEEM_ITEM_WIDTH, height=GetRedeemItemHeight() if self.showDescription else GetRedeemItemHeightWithoutDescription(), state=uiconst.UI_PICKCHILDREN)
    101         self.ConstructShowInfo()
    102         self.ConstructAutoInjectIcon()
    103         self.ConstructPicture()
    104         self.ConstructName()
    105         self.ConstructDescription()
    106         self.ConstructExpiry()
    107 
    108     def ConstructShowInfo(self):
    109         if not self.showInfo:
    110             return
    111         bpData = self.GetBpData()
    112         if bpData:
    113             abstractInfo = KeyVal(fullBlueprintData=bpData)
    114         else:
    115             abstractInfo = None
    116         InfoIcon(parent=self.itemContainer, align=uiconst.TOPRIGHT, idx=0, top=8, left=8, itemID=self.itemID, typeID=self.typeID, abstractinfo=abstractInfo)
    117 
    118     def GetBpData(self):
    119         bpInfo = self.token.blueprintInfo
    120         if not bpInfo:
    121             return None
    122         bpData = sm.GetService('blueprintSvc').GetBlueprintTypeCopy(typeID=self.typeID, original=not bpInfo.isCopy, runsRemaining=bpInfo.runs, materialEfficiency=bpInfo.materialEfficiency, timeEfficiency=bpInfo.timeEfficiency)
    123         return bpData
    124 
    125     def ConstructAutoInjectIcon(self):
    126         if not self.isAutoInject:
    127             return
    128         Sprite(parent=self.itemContainer, align=uiconst.TOPLEFT, idx=0, pos=(8, 8, 24, 24), texturePath='res://UI/Texture/Classes/RedeemPanel/autoInject.png', hint=GetByLabel('UI/RedeemWindow/AutoInjectHint'))
    129 
    130     def ConstructPicture(self):
    131         pictureParent = Container(parent=self.itemContainer, name='pictureParent', align=uiconst.TOTOP, height=PICTURE_CONTAINER_HEIGHT, state=uiconst.UI_DISABLED)
    132         pictureCenter = Container(parent=pictureParent, name='pictureCenter', align=uiconst.CENTER, width=PICTURE_SIZE, height=PICTURE_SIZE)
    133         itemPicture = Icon(parent=pictureCenter, align=uiconst.CENTER, width=pictureCenter.height, height=pictureCenter.width)
    134         isCopy = self.token.blueprintInfo and self.token.blueprintInfo.isCopy
    135         itemPicture.LoadIconByTypeID(typeID=self.typeID, ignoreSize=True, isCopy=isCopy)
    136         quantityContainer = ContainerAutoSize(parent=pictureCenter, idx=0, name='qtypar', pos=(2, 48, 0, 0), align=uiconst.TOPRIGHT, state=uiconst.UI_DISABLED, bgColor=(0, 0, 0, 0.9))
    137         Label(parent=quantityContainer, maxLines=1, bold=True, fontsize=fontconst.EVE_SMALL_FONTSIZE, opacity=1.0, padding=(4, 1, 4, 0), text=self.quantity)
    138 
    139     def ConstructName(self):
    140         nameContainer = Container(parent=self.itemContainer, name='nameContainer', align=uiconst.TOTOP, height=ITEM_NAME_HEIGHT)
    141         self.itemName = EveLabelMediumBold(parent=nameContainer, name='redeemItemName', align=uiconst.CENTER, maxLines=2, width=self.itemContainer.width - ITEM_NAME_PADDING * 2, text='<center>' + GetName(self.typeID) + '</center>')
    142 
    143     def ConstructDescription(self):
    144         if self.showDescription:
    145             maxWidth = self.itemContainer.width
    146             descriptionContainer = Container(parent=self.itemContainer, name='descriptionContainer', align=uiconst.TOTOP, height=ITEM_DESCRIPTION_HEIGHT, description=self.description)
    147             itemDescription = EveLabelSmall(parent=descriptionContainer, name='redeemItemDescription', align=uiconst.TOTOP, padLeft=4, maxWidth=maxWidth, maxLines=1, showEllipsis=True)
    148             if self.description:
    149                 itemDescription.text = '<center>' + self.description + '</center>'
    150 
    151     def ConstructExpiry(self):
    152         expiryContainer = Container(parent=self.itemContainer, name='expiryContainer', align=uiconst.TOTOP, height=ITEM_EXPIRY_HEIGHT)
    153         self.itemExpiryDate = EveLabelSmallBold(parent=expiryContainer, name='redeemItemExpiryDate', align=uiconst.TOALL, color=(1.0, 0.539, 0.0, 1.0), padLeft=4)
    154         self.SetExpiryDate()
    155 
    156     def SetExpiryDate(self):
    157         if self.expireDateTime and self.expireDateTime > 0:
    158             now = GetWallclockTime()
    159             timeLeft = self.expireDateTime - now
    160             if timeLeft > 0:
    161                 if timeLeft > DAY:
    162                     time = FormatTimeIntervalShortWritten(timeLeft, showFrom=TIME_CATEGORY_DAY, showTo=TIME_CATEGORY_HOUR)
    163                 elif timeLeft > HOUR:
    164                     time = FormatTimeIntervalShortWritten(timeLeft, showFrom=TIME_CATEGORY_HOUR, showTo=TIME_CATEGORY_MINUTE)
    165                 elif timeLeft > MIN:
    166                     time = FormatTimeIntervalShortWritten(timeLeft, showFrom=TIME_CATEGORY_MINUTE, showTo=TIME_CATEGORY_SECOND)
    167                 else:
    168                     time = FormatTimeIntervalShortWritten(timeLeft, showFrom=TIME_CATEGORY_SECOND, showTo=TIME_CATEGORY_SECOND)
    169                 text = GetByLabel('UI/RedeemWindow/RedeemExpires', timeLeftToExpiry=time)
    170                 self.itemExpiryDate.fontsize = 9
    171                 self.itemExpiryDate.text = '<center>' + text + '</center>'
    172             else:
    173                 self.itemExpiryDate.fontsize = 9
    174                 (self.itemExpiryDate.SetTextColor(eveColor.DANGER_RED),)
    175                 self.itemExpiryDate.text = '<center>%s</center>' % GetByLabel('UI/Generic/Expired')
    176 
    177     def Load(self, node):
    178         self.sr.node = node
    179         self.token = node.item
    180         self.itemID = None
    181         self.typeID = int(self.token.typeID)
    182         self.ownerID = session.charid
    183         self.locationID = session.stationid
    184         self.flagID = flagHangar
    185         self.quantity = int(self.token.quantity)
    186         self.categoryID = GetCategoryID(self.token.typeID)
    187         self.groupID = GetGroupID(self.token.typeID)
    188         self.customInfo = None
    189         self.stacksize = None
    190         self.singleton = None
    191         self.tokenID = self.token.tokenID
    192         self.massTokenID = self.token.massTokenID
    193         self.stationID = self.token.stationID
    194         self.expireDateTime = self.token.expireDateTime
    195         self.createDateTime = self.token.dateTime
    196         self.description = self.token.description
    197         self.isAutoInject = self.token.isAutoInject
    198         self.Flush()
    199         self.ConstructLayout()
    200         if self.sr.node.Get('selected', 0):
    201             self.Select(animate=False)
    202         else:
    203             self.Deselect(animate=False)
    204 
    205     def OnClick(self, *args):
    206         if self.sr.node:
    207             if self.sr.node.Get('OnClick', None):
    208                 self.sr.node.OnClick(self)
    209             else:
    210                 self.sr.node.scroll.SelectNode(self.sr.node)
    211                 prompt_player_fsd_dialog('ListEntryClick')
    212 
    213     def OnMouseDown(self, *args):
    214         super(RedeemItem, self).OnMouseDown(*args)
    215         self._hiliteFill.OnMouseDown(*args)
    216 
    217     def OnMouseUp(self, *args):
    218         super(RedeemItem, self).OnMouseUp(*args)
    219         self._hiliteFill.OnMouseUp(*args)
    220 
    221     def LoadTooltipPanel(self, tooltipPanel, *args):
    222         tooltipPanel.LoadGeneric1ColumnTemplate()
    223         tooltipPanel.AddLabelMedium(text=self.description, wrapWidth=400)
    224         bpInfo = self.token.blueprintInfo
    225         if bpInfo:
    226             if bpInfo.materialEfficiency or bpInfo.timeEfficiency:
    227                 bpData = self.GetBpData()
    228                 AddBlueprintInfo(tooltipPanel, bpData=bpData)
    229             else:
    230                 text = GetByLabel('UI/Industry/CopyRunsRemaining', runsRemaining=bpInfo.runs)
    231                 tooltipPanel.AddLabelMedium(text=text, wrapWidth=400)
    232 
    233 
    234 class RedeemItemSortData(ItemSortData):
    235 
    236     def __init__(self, rec):
    237         super(RedeemItemSortData, self).__init__(rec)
    238         self.createDataTime = rec.dateTime
    239         self.expireDateTime = rec.expireDateTime
    240 
    241     def GetSortKey(self, sortby, direction):
    242         baseSortKey = (self.createDataTime,
    243          self.name,
    244          self.typeName,
    245          self.quantity,
    246          self.itemID,
    247          self.rec)
    248         if sortby == CREATION_DATE_SORT_KEY:
    249             return (self.createDataTime,) + baseSortKey
    250         if sortby == EXPIRY_DATE_SORT_KEY:
    251             expirySortVal = self.expireDateTime or const.maxLong
    252             return (expirySortVal,) + baseSortKey
    253         return super(RedeemItemSortData, self).GetSortKey(sortby, direction)
    254 
    255 
    256 class DraggableRedeemItem(RedeemItem):
    257     default_showInfo = False
    258     default_showDescription = False
    259     isDragObject = True
    260     isDropLocation = False
    261     TOOLTIP_LABEL_PATH = 'UI/RedeemWindow/DragAndDropToGive'
    262 
    263     @classmethod
    264     def GetEntryHeight(cls):
    265         return GetRedeemItemHeightWithoutDescription()
    266 
    267     def GetDragData(self, *args):
    268         if not self.sr.node:
    269             return
    270         nodesToDrag = []
    271         for node in self.sr.node.scroll.GetSelectedNodes(self.sr.node):
    272             nodeToDrag = node.Copy()
    273             nodeToDrag.Set('tokenID', node.tokenID)
    274             nodeToDrag.Set('massTokenID', node.massTokenID)
    275             nodesToDrag.append(nodeToDrag)
    276 
    277         return nodesToDrag
    278 
    279     def OnDragEnter(self, dragObj, nodes):
    280         if self.sr.node.container:
    281             self.sr.node.container.OnDragEnter(dragObj, nodes)
    282 
    283     def OnDragExit(self, dragObj, nodes):
    284         if self.sr.node.container:
    285             self.sr.node.container.OnDragExit(dragObj, nodes)
    286 
    287     def OnDropData(self, dragObj, nodes):
    288         if len(nodes) and getattr(nodes[0], 'scroll', None):
    289             nodes[0].scroll.ClearSelection()
    290         nodesToDrop = [ node for node in nodes if isinstance(node, RedeemItem) ]
    291         if nodesToDrop and GetAttrs(self, 'sr', 'node', 'container', 'OnDropData'):
    292             self.sr.node.container.OnDropData(dragObj, nodesToDrop)
    293 
    294     def LoadTooltipPanel(self, tooltipPanel, *args):
    295         tooltipPanel.LoadGeneric1ColumnTemplate()
    296         tooltipPanel.AddLabelMedium(text=GetByLabel(self.TOOLTIP_LABEL_PATH))