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

contractutils.py (7388B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\util\contractutils.py
      2 import blue
      3 from eve.client.script.ui.util import uix
      4 from eve.common.script.util.contractscommon import *
      5 from eve.common.script.util.eveFormat import FmtISK
      6 from localization import GetByLabel
      7 from localization.util import IsSessionLanguageConcise
      8 import evetypes
      9 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     10 from utillib import KeyVal
     11 COL_PAY = '0xffcc2222'
     12 COL_GET = '0xff00bb00'
     13 
     14 def FmtISKWithDescription(isk, justDesc = False):
     15     iskFmt = FmtISK(isk, showFractionsAlways=0)
     16     isk = float(isk)
     17     if abs(isk) >= 1000000000000L:
     18         isk = long(isk / 10000000000L)
     19         if justDesc:
     20             iskFmt = GetByLabel('UI/Contracts/Util/AmountInTrillions', amount=isk / 100.0)
     21         else:
     22             iskFmt = GetByLabel('UI/Contracts/Util/AmountInTrillionsDetailed', iskAmount=iskFmt, amount=isk / 100.0)
     23     elif abs(isk) >= 1000000000:
     24         isk = long(isk / 10000000)
     25         if justDesc:
     26             iskFmt = GetByLabel('UI/Contracts/Util/AmountInBillions', amount=isk / 100.0)
     27         else:
     28             iskFmt = GetByLabel('UI/Contracts/Util/AmountInBillionsDetailed', iskAmount=iskFmt, amount=isk / 100.0)
     29     elif abs(isk) >= 1000000:
     30         isk = long(isk / 10000)
     31         if justDesc:
     32             iskFmt = GetByLabel('UI/Contracts/Util/AmountInMillions', amount=isk / 100.0)
     33         else:
     34             iskFmt = GetByLabel('UI/Contracts/Util/AmountInMillionDetailed', iskAmount=iskFmt, amount=isk / 100.0)
     35     elif abs(isk) >= 10000:
     36         isk = long(isk / 10)
     37         if justDesc:
     38             iskFmt = GetByLabel('UI/Contracts/Util/AmountInThousands', amount=isk / 100.0)
     39         else:
     40             iskFmt = GetByLabel('UI/Contracts/Util/AmountInThousandsDetailed', iskAmount=iskFmt, amount=isk / 100.0)
     41     return iskFmt
     42 
     43 
     44 def GetMarketTypes():
     45     data = []
     46     for typeID in evetypes.Iterate():
     47         blue.pyos.BeNice()
     48         if evetypes.IsPublished(typeID) and evetypes.IsGroupPublished(typeID) and evetypes.IsCategoryPublished(typeID):
     49             data.append(KeyVal(typeID=typeID, marketGroupID=evetypes.GetMarketGroupID(typeID), typeName=evetypes.GetName(typeID)))
     50 
     51     return data
     52 
     53 
     54 def GetContractIcon(type):
     55     icons = {const.conTypeNothing: 'res:/ui/Texture/WindowIcons/contracts.png',
     56      const.conTypeItemExchange: 'res:/ui/Texture/WindowIcons/contractItemExchange.png',
     57      const.conTypeAuction: 'res:/ui/Texture/WindowIcons/contractAuction.png',
     58      const.conTypeCourier: 'res:/ui/Texture/WindowIcons/contractCourier.png',
     59      const.conTypeLoan: '64_15'}
     60     return icons.get(type, 'res:/ui/Texture/WindowIcons/contracts.png')
     61 
     62 
     63 def GetColoredContractStatusText(status):
     64     cols = {0: 'ffffff',
     65      1: 'ffffff',
     66      2: 'ffffff',
     67      3: 'ffffff',
     68      4: 'ffffff',
     69      5: 'ffffff',
     70      6: 'ffffff',
     71      7: 'aa0000',
     72      8: 'ffffff'}
     73     col = cols[status]
     74     st = GetContractStatusText(status)
     75     return '<color=0xff%s>%s</color>' % (col, st)
     76 
     77 
     78 def ConFmtDate(time, isText = False):
     79     if time < 0:
     80         return GetByLabel('UI/Contracts/Util/ContractExpiredEmphasized')
     81     res = ''
     82     d = time / const.DAY
     83     h = (time - d * const.DAY) / const.HOUR
     84     if isText:
     85         if d >= 1:
     86             res = GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Day', units=d)
     87         elif d < 0:
     88             res = GetByLabel('UI/Contracts/Util/ContractExpiredEmphasized')
     89         elif h >= 1:
     90             res = GetByLabel('UI/Contracts/Util/LessThanADay')
     91         else:
     92             res = GetByLabel('UI/Contracts/Util/LessThanAnHour')
     93     else:
     94         if d >= 1:
     95             if h > 0:
     96                 res = GetByLabel('UI/Contracts/Util/DayToHour', days=d, hours=h)
     97             else:
     98                 res = GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Day', units=d)
     99         elif h >= 1 and d == 0:
    100             res = GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Hour', units=h)
    101         if time / const.HOUR == 0:
    102             res = GetByLabel('UI/Contracts/Util/LessThanAnHour')
    103     return res
    104 
    105 
    106 def GetContractTimeLeftText(c):
    107     if c.status == const.conStatusOutstanding:
    108         if c.dateExpired < blue.os.GetWallclockTime():
    109             return GetByLabel('UI/Contracts/Util/ContractExpired')
    110         else:
    111             return ConFmtDate(c.dateExpired - blue.os.GetWallclockTime(), c.type == const.conTypeAuction)
    112     else:
    113         return ''
    114 
    115 
    116 def CutAt(txt, l):
    117     if len(txt) > l:
    118         return txt[:l - 3] + '...'
    119     else:
    120         return txt
    121 
    122 
    123 def SelectItemTypeDlg(itemTypes):
    124     tmplst = []
    125     for typeID in itemTypes:
    126         itemTypeRow = GetByLabel('UI/Contracts/Util/ItemTypeLine', item=typeID, categoryName=evetypes.GetCategoryName(typeID))
    127         tmplst.append((itemTypeRow, typeID))
    128 
    129     if not tmplst:
    130         prompt_player_fsd_dialog('ConNoItemsFound')
    131         return
    132     elif len(tmplst) == 1:
    133         return tmplst[0][1]
    134     else:
    135         ret = uix.ListWnd(tmplst, 'generic', GetByLabel('UI/Contracts/Util/SelectItemType'), None, 1, windowName='contractSelectItemTypeDlg')
    136         return ret and ret[1]
    137 
    138 
    139 def MatchInvTypeName(s, typeID):
    140     localized = evetypes.GetName(typeID)
    141     english = evetypes.GetEnglishName(typeID)
    142     return CaseInsensitiveSubMatch(s, localized) or CaseInsensitiveSubMatch(s, english)
    143 
    144 
    145 def CaseInsensitiveSubMatch(matchStr, inStr):
    146     return matchStr.lower() in inStr.lower()
    147 
    148 
    149 def TypeName(typeID):
    150     return evetypes.GetName(typeID)
    151 
    152 
    153 def GroupName(groupID):
    154     return evetypes.GetCategoryNameByGroup(groupID)
    155 
    156 
    157 def CategoryName(categoryID):
    158     return evetypes.GetCategoryNameByCategory(categoryID)
    159 
    160 
    161 def IsSearchStringLongEnough(txt):
    162     error = None
    163     isLanguageConcise = IsSessionLanguageConcise()
    164     if isLanguageConcise and not txt:
    165         error = 'ConNeedAtLeastOneLetter'
    166     if not isLanguageConcise and (not txt or len(txt) < 3):
    167         error = 'ConNeedAtLeastThreeLetters'
    168     if error:
    169         prompt_player_fsd_dialog(error)
    170     return not error
    171 
    172 
    173 def DoParseItemType(wnd, prevVal = None, marketOnly = False):
    174     itemTypes = []
    175     txt = wnd.GetValue()
    176     if len(txt) == 0 or not IsSearchStringLongEnough(txt):
    177         return
    178     if txt == prevVal:
    179         return
    180     for t in GetMarketTypes():
    181         if t.marketGroupID is None and marketOnly:
    182             continue
    183         if MatchInvTypeName(txt, t.typeID):
    184             itemTypes.append(t.typeID)
    185 
    186     typeID = SelectItemTypeDlg(itemTypes)
    187     if typeID:
    188         wnd.SetValue(TypeName(typeID))
    189     return typeID
    190 
    191 
    192 def GetContractLabel(contract, contractItems, additionalColumns = ''):
    193     if contract.forCorp:
    194         issuerID = contract.issuerCorpID
    195     else:
    196         issuerID = contract.issuerID
    197     fromName = cfg.eveowners.Get(issuerID).ownerName
    198     if contract.acceptorID:
    199         toID = contract.acceptorID
    200     else:
    201         toID = contract.assigneeID
    202     if toID == 0:
    203         toName = GetByLabel('UI/Contracts/ContractEntry/NoneParen')
    204     else:
    205         toName = cfg.eveowners.Get(toID).ownerName
    206     name = GetContractTitle(contract, contractItems)
    207     label = '%s<t>%s<t>%s<t>%s%s' % (name,
    208      GetContractTypeText(contract.type),
    209      fromName,
    210      toName,
    211      additionalColumns)
    212     return label
    213 
    214 
    215 def GetCorpseName(itemID):
    216     try:
    217         return cfg.evelocations.Get(itemID).name
    218     except Exception:
    219         pass