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

overviewBracketLabelPreview.py (5810B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\overviewSettings\overviewBracketLabelPreview.py
      2 import evetypes
      3 from carbonui import const as uiconst
      4 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      5 from carbonui.primitives.frame import Frame
      6 from carbonui.control.button import Button
      7 from eve.client.script.ui.control.eveLabel import EveLabelMedium, Label
      8 from carbonui.fontconst import EVE_SMALL_FONTSIZE
      9 from eve.client.script.ui.inflight.bracketsAndTargets.bracketNameFormatting import TagWithUnderLine, TagWithBold, TagWithColor, TagWithSize, TagWithItalic
     10 from eve.client.script.ui.inflight.overview.overviewConst import LABEL_TYPE_SHIP_TYPE, LABEL_TYPE_PILOT, LABEL_TYPE_CORP, LABEL_TYPE_ALLIANCE, LABEL_TYPE_SHIP_NAME, LABEL_STATE, LABEL_TYPE, PRE, POST, LABEL_UNDERLINE, LABEL_BOLD, LABEL_TYPE_NONE, LABEL_COLOR, LABEL_SIZE, LABEL_TYPE_LINEBREAK, CHAR_BR, LABEL_ITALIC
     11 from eve.common.script.sys.idCheckers import IsNPC
     12 from carbonui.uicore import uicore
     13 from localization import GetByLabel
     14 
     15 class OverviewBracketLabelPreview(ContainerAutoSize):
     16     __notifyevents__ = ['OnShipLabelsUpdated', 'OnOverviewLabelOrderChanged', 'OnReloadingOverviewProfile']
     17     default_name = 'overviewBracketLabelPreview'
     18     default_align = uiconst.TOBOTTOM
     19     default_height = 50
     20     default_alignMode = uiconst.TOTOP
     21 
     22     def ApplyAttributes(self, attributes):
     23         ContainerAutoSize.ApplyAttributes(self, attributes)
     24         self.lineBreakFunc = attributes.lineBreakFunc
     25         text = GetByLabel('UI/Overview/AddLinebreak')
     26         btn = Button(parent=self, label=text, func=self.lineBreakFunc, align=uiconst.CENTERTOP)
     27         textTop = btn.height + 10
     28         text = GetByLabel('UI/Overview/LabelPreview')
     29         EveLabelMedium(parent=self, text=text, align=uiconst.TOTOP, padding=(10,
     30          textTop,
     31          10,
     32          2))
     33         textCont = ContainerAutoSize(name='textCont', parent=self, align=uiconst.TOTOP, padding=(10, 2, 10, 10), alignMode=uiconst.TOTOP, maxHeight=100, clipChildren=True)
     34         Frame(bgParent=textCont, opacity=0.1)
     35         self.exampleText = Label(parent=textCont, align=uiconst.TOTOP, padding=4, fontsize=EVE_SMALL_FONTSIZE)
     36         self.LoadText()
     37         sm.RegisterNotify(self)
     38 
     39     def LoadText(self):
     40         shipLabels = sm.GetService('stateSvc').GetShipLabels()
     41         exampleTextDict = self.GetExampleLabels()
     42         textList = []
     43         for label in shipLabels:
     44             labelType = label[LABEL_TYPE]
     45             isVisible = label[LABEL_STATE]
     46             if not isVisible and labelType != LABEL_TYPE_LINEBREAK:
     47                 continue
     48             pre = label[PRE]
     49             post = label[POST]
     50             if labelType is LABEL_TYPE_NONE:
     51                 textList.append(pre)
     52                 continue
     53             elif labelType == LABEL_TYPE_LINEBREAK:
     54                 if not textList or textList[-1] != CHAR_BR:
     55                     textList.append(CHAR_BR)
     56                 continue
     57             if labelType == LABEL_TYPE_CORP:
     58                 labelText = exampleTextDict[LABEL_TYPE_CORP]
     59             elif labelType == LABEL_TYPE_ALLIANCE:
     60                 labelText = exampleTextDict[LABEL_TYPE_ALLIANCE]
     61             elif labelType == LABEL_TYPE_PILOT:
     62                 labelText = exampleTextDict[LABEL_TYPE_PILOT]
     63             elif labelType == LABEL_TYPE_SHIP_TYPE:
     64                 labelText = exampleTextDict[LABEL_TYPE_SHIP_TYPE]
     65             elif labelType == LABEL_TYPE_SHIP_NAME:
     66                 labelText = exampleTextDict[LABEL_TYPE_SHIP_NAME]
     67             else:
     68                 continue
     69             labelsForType = [labelText]
     70             isBold = label.get(LABEL_BOLD, False)
     71             isUnderlined = label.get(LABEL_UNDERLINE, False)
     72             isItalic = label.get(LABEL_ITALIC, False)
     73             labelsForType = TagWithBold(labelsForType, isBold)
     74             labelsForType = TagWithUnderLine(labelsForType, isUnderlined)
     75             labelsForType = TagWithItalic(labelsForType, isItalic)
     76             labelsForType.insert(0, pre)
     77             labelsForType.append(post)
     78             color = label.get(LABEL_COLOR, None)
     79             fontsize = label.get(LABEL_SIZE)
     80             labelsForType = TagWithColor(labelsForType, color)
     81             labelsForType = TagWithSize(labelsForType, fontsize)
     82             textList += labelsForType
     83 
     84         text = ''.join(textList)
     85         self.exampleText.text = text
     86 
     87     def GetExampleLabels(self):
     88         try:
     89             shipTypeName = evetypes.GetName(uicore.layer.shipui.controller.GetTypeID())
     90         except Exception:
     91             shipTypeName = GetByLabel('UI/Overview/ShipTypeExample')
     92 
     93         try:
     94             shipName = cfg.evelocations.Get(session.shipid).name
     95         except Exception:
     96             shipName = GetByLabel('UI/Overview/ShipNameExample')
     97 
     98         corpTicker = GetByLabel('UI/Overview/CorpTickerExample')
     99         try:
    100             if not IsNPC(session.corpid):
    101                 corpTicker = cfg.corptickernames.Get(session.corpid).tickerName
    102         except Exception:
    103             pass
    104 
    105         allianceTicker = GetByLabel('UI/Overview/AllianceTickerExample')
    106         try:
    107             if session.allianceid:
    108                 allianceTicker = cfg.allianceshortnames.Get(session.allianceid).shortName
    109         except Exception:
    110             pass
    111 
    112         example = {LABEL_TYPE_SHIP_TYPE: shipTypeName,
    113          LABEL_TYPE_PILOT: cfg.eveowners.Get(session.charid).name,
    114          LABEL_TYPE_CORP: corpTicker,
    115          LABEL_TYPE_ALLIANCE: allianceTicker,
    116          LABEL_TYPE_SHIP_NAME: shipName}
    117         return example
    118 
    119     def OnShipLabelsUpdated(self):
    120         self.LoadText()
    121 
    122     def OnOverviewLabelOrderChanged(self):
    123         self.LoadText()
    124 
    125     def OnReloadingOverviewProfile(self):
    126         self.LoadText()