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

shipInfoCollapsibleGroup.py (11504B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\info\shipInfoCollapsibleGroup.py
      2 import eveformat
      3 import eveicon
      4 import localization
      5 from carbonui import Align, uiconst, TextColor
      6 from carbonui.text.styles import TextBody, TextDetail
      7 from carbonui.control.buttonIcon import ButtonIcon
      8 from carbonui.primitives.container import Container
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.primitives.fill import Fill
     11 from carbonui.primitives.sprite import Sprite
     12 from dogma.attributes.format import GetFormattedAttributeAndValue
     13 from eve.client.script.ui import eveColor
     14 from eve.client.script.ui.control.eveWindowUnderlay import ListEntryUnderlay
     15 from eve.client.script.ui.control.gauge import Gauge
     16 from eve.client.script.ui.shared.info.infoUtil import GetColoredText, LoadAttributeTooltipPanel
     17 
     18 class _CollapsibleGroupBase(ContainerAutoSize):
     19     default_state = uiconst.UI_NORMAL
     20     default_headerColor = (1, 1, 1, 0.05)
     21     default_expanderAlign = Align.TORIGHT
     22     default_expanderWidth = 32
     23     default_expanderPadding = (0, 0, 0, 0)
     24 
     25     def ApplyAttributes(self, attributes):
     26         self._hiliteFill = None
     27         self.default_state = uiconst.UI_NORMAL
     28         super(_CollapsibleGroupBase, self).ApplyAttributes(attributes)
     29         self.headerColor = attributes.get('headerColor', self.default_headerColor)
     30         self.expanderAlign = attributes.get('expanderAlign', self.default_expanderAlign)
     31         self.expanderWidth = attributes.get('expanderWidth', self.default_expanderWidth)
     32         self.expanderPadding = attributes.get('expanderPadding', self.default_expanderPadding)
     33         self._construct_layout()
     34 
     35     def _construct_layout(self):
     36         self._construct_header()
     37         self._construct_main_cont()
     38 
     39     def _construct_header(self):
     40         self.bgCont = ContainerAutoSize(name='bgCont', parent=self, align=Align.TOTOP)
     41         self._hiliteFill = ListEntryUnderlay(name='selectionHighlight', bgParent=self.bgCont)
     42         Fill(name='bgColor', bgParent=self.bgCont, color=self.headerColor)
     43         self.headerCont = Container(name='headerCont', parent=self.bgCont, align=Align.TOTOP, height=32)
     44         self.headerCont.OnClick = self.OnClick
     45         self._construct_expander()
     46 
     47     def _construct_expander(self):
     48         self.expanderCont = Container(name='expanderCont', parent=self.headerCont, align=self.expanderAlign, width=self.expanderWidth, padding=self.expanderPadding, state=uiconst.UI_PICKCHILDREN)
     49         self.expanderIcon = ButtonIcon(name='expander', parent=self.expanderCont, align=Align.CENTER, texturePath=eveicon.chevron_up, iconSize=18, func=self.OnClick)
     50 
     51     def _construct_main_cont(self):
     52         self.mainCont = ContainerAutoSize(name='mainCont', parent=self, align=Align.TOTOP, state=uiconst.UI_PICKCHILDREN, padTop=2)
     53 
     54     def SetCollapsed(self, collapsed):
     55         if collapsed:
     56             self.mainCont.Hide()
     57             self.expanderIcon.SetTexturePath(eveicon.chevron_down)
     58         else:
     59             self.mainCont.Show()
     60             self.expanderIcon.SetTexturePath(eveicon.chevron_up)
     61 
     62     def Toggle(self):
     63         self.SetCollapsed(self.mainCont.display)
     64 
     65     def OnClick(self, *args):
     66         super(_CollapsibleGroupBase, self).OnClick(*args)
     67         self.Toggle()
     68 
     69     def ConstructHiliteFill(self):
     70         if not self._hiliteFill:
     71             self._hiliteFill = ListEntryUnderlay(name='selectionHighlight', bgParent=self.bgCont)
     72 
     73     def ShowHilite(self, animate = True):
     74         self.ConstructHiliteFill()
     75         self._hiliteFill.set_hovered(True, animate)
     76 
     77     def HideHilite(self, animate = True):
     78         if self._hiliteFill:
     79             self._hiliteFill.set_hovered(False, animate)
     80 
     81     def OnMouseEnter(self, *args):
     82         self.ShowHilite()
     83 
     84     def OnMouseExit(self, *args):
     85         self.HideHilite()
     86 
     87 
     88 class CollapsibleGroup(_CollapsibleGroupBase):
     89 
     90     def ApplyAttributes(self, attributes):
     91         self.groupName = attributes.groupName
     92         self.iconID = attributes.groupIcon
     93         self._icon_color = attributes.get('iconColor', TextColor.SECONDARY)
     94         self._icon_size = attributes.get('iconSize', 16)
     95         self._bold = attributes.get('bold', True)
     96         super(CollapsibleGroup, self).ApplyAttributes(attributes)
     97 
     98     def _construct_header(self):
     99         super(CollapsibleGroup, self)._construct_header()
    100         self.iconCont = Container(name='iconCont', parent=self.headerCont, align=Align.TOLEFT, width=self._icon_size + 8, state=uiconst.UI_DISABLED)
    101         self.icon = Sprite(name='icon', parent=self.iconCont, align=Align.CENTERRIGHT, texturePath=self.iconID, width=self._icon_size, height=self._icon_size, state=uiconst.UI_DISABLED, color=self._icon_color)
    102         self._construct_label()
    103 
    104     def _construct_label(self):
    105         self.headerLabelWrapper = Container(name='headerLabelWrapper', parent=self.headerCont, align=Align.TOALL, clipChildren=True)
    106         self.labelCont = ContainerAutoSize(name='labelCont', parent=self.headerLabelWrapper, align=Align.TOLEFT, state=uiconst.UI_DISABLED)
    107         self.label = TextBody(name='label', parent=self.labelCont, align=Align.CENTERLEFT, text=self.groupName, padLeft=8, state=uiconst.UI_DISABLED, bold=self._bold)
    108 
    109     def OnMouseEnter(self, *args):
    110         super(CollapsibleGroup, self).OnMouseEnter(*args)
    111         self.expanderIcon.OnMouseEnter(*args)
    112 
    113     def OnMouseExit(self, *args):
    114         super(CollapsibleGroup, self).OnMouseExit(*args)
    115         self.expanderIcon.OnMouseExit(*args)
    116 
    117 
    118 class CollapsibleGaugeGroup(CollapsibleGroup):
    119 
    120     def ApplyAttributes(self, attributes):
    121         self.itemID = attributes.itemID
    122         self.groupedAttributes = attributes.groupedAttributes
    123         self.damageTypeIcons = attributes.damageTypeIcons
    124         self.damageTypeColors = attributes.damageTypeColors
    125         self.ehp_description_path = attributes.ehpDescriptionPath
    126         self._calculate_effective_hp(attributes.layerHp)
    127         super(CollapsibleGaugeGroup, self).ApplyAttributes(attributes)
    128 
    129     def _construct_layout(self):
    130         self._construct_header()
    131         self._construct_gauges()
    132         self._construct_main_cont()
    133 
    134     def _construct_label(self):
    135         self.headerLabelCont = Container(parent=self.headerCont, align=Align.TOALL, clipChildren=True)
    136         self.labelCont = ContainerAutoSize(name='labelCont', parent=self.headerLabelCont, align=Align.TOLEFT, state=uiconst.UI_DISABLED, clipChildren=True)
    137         self.label = TextBody(name='label', parent=self.labelCont, align=Align.CENTERLEFT, text=self.groupName, padLeft=8, state=uiconst.UI_DISABLED, bold=True)
    138         self.ehpCont = ContainerAutoSize(name='ehpCont', parent=self.headerLabelCont, align=Align.TOLEFT, hint='Effective Hit Points', state=uiconst.UI_NORMAL, clipChildren=True)
    139         self.ehpCont.LoadTooltipPanel = self._load_ehp_tooltip_panel
    140         self.ehpLabel = TextBody(name='ehp', parent=self.ehpCont, align=Align.CENTERLEFT, text=localization.GetByLabel('UI/InfoWindow/EhpFormat', value=self.effectiveHpString, valueColor=TextColor.NORMAL), padLeft=16, color=TextColor.SECONDARY)
    141 
    142     def _load_ehp_tooltip_panel(self, tooltip_panel, *args):
    143         tooltip_panel.LoadGeneric1ColumnTemplate()
    144         tooltip_panel.AddLabelMedium(text=localization.GetByLabel('UI/InfoWindow/EffectiveHpHeader'))
    145         tooltip_panel.AddLabelSmall(text=localization.GetByLabel(self.ehp_description_path), color=TextColor.SECONDARY, wrapWidth=220)
    146 
    147     def _construct_gauges(self):
    148         self.gaugeCont = Container(parent=self.bgCont, name='gaugeCont', align=Align.TOTOP, height=34)
    149         self.highestAttribute = self._get_highest_attribute()
    150         self.CreateGauge('em', self.gaugeCont)
    151         self.CreateGauge('thermal', self.gaugeCont)
    152         self.CreateGauge('kinetic', self.gaugeCont)
    153         self.CreateGauge('explosive', self.gaugeCont)
    154 
    155     def CreateGauge(self, damageType, parent):
    156         attribute, modifiedAttribute = self.groupedAttributes[damageType]
    157         return ResistanceAttributeGauge(name=damageType, parent=parent, align=Align.TOLEFT_PROP, width=0.25, itemID=self.itemID, damageType=damageType, attribute=attribute, modifiedAttribute=modifiedAttribute, damageTypeIcon=self.damageTypeIcons[damageType], damageTypeColor=self.damageTypeColors[damageType], padding=(8, 0, 8, 8), highest=attribute.value == self.highestAttribute.value)
    158 
    159     def _calculate_effective_hp(self, layerHp):
    160         totalResistance = 0
    161         for damageType, (attrib, modifiedAttrib) in self.groupedAttributes.iteritems():
    162             totalResistance += attrib.value
    163 
    164         avgResistance = totalResistance / 4
    165         layerHp = layerHp
    166         self.effectiveHp = layerHp / avgResistance
    167         self.effectiveHpString = localization.formatters.FormatNumeric(self.effectiveHp, decimalPlaces=2, useGrouping=True)
    168 
    169     def _get_highest_attribute(self):
    170         highestAttrib = None
    171         for attribute, modifiedAttribute in self.groupedAttributes.itervalues():
    172             if not highestAttrib:
    173                 highestAttrib = attribute
    174                 continue
    175             if highestAttrib.value > attribute.value:
    176                 highestAttrib = attribute
    177 
    178         return highestAttrib
    179 
    180 
    181 class ResistanceAttributeGauge(Container):
    182 
    183     def ApplyAttributes(self, attributes):
    184         super(ResistanceAttributeGauge, self).ApplyAttributes(attributes)
    185         self.itemID = attributes.itemID
    186         self.damageType = attributes.damageType
    187         self.attribute = attributes.attribute
    188         self.modifiedAttribute = attributes.modifiedAttribute
    189         self.extraModifyingAttrIDs = attributes.get('extraModifyingAttrIDs', None)
    190         self.extraModifyingFactors = attributes.get('extraModifyingFactors', None)
    191         texturePath = attributes.damageTypeIcon
    192         color = attributes.damageTypeColor
    193         highest = attributes.get('highest', False)
    194         glowBrightness = 0.5 if highest else 0
    195         self.upperCont = Container(name='mainCont', parent=self, align=Align.TOTOP, height=16, state=uiconst.UI_NORMAL)
    196         self.gaugeCont = Container(name='gaugeCont', parent=self, align=Align.TOTOP, height=6, state=uiconst.UI_DISABLED, padTop=4)
    197         self.gauge = Gauge(name='gauge', parent=self.gaugeCont, align=Align.TOTOP, showMarker=False, lineWidth=6, colorBg=eveColor.BLACK, glowBrightness=glowBrightness, color=color, value=1 - self.attribute.value, state=uiconst.UI_DISABLED)
    198         iconCont = Container(name='iconCont', parent=self.upperCont, align=Align.TOLEFT, width=18, state=uiconst.UI_PICKCHILDREN)
    199         self.icon = Sprite(name='icon', parent=iconCont, align=Align.CENTER, width=18, height=18, texturePath=texturePath, state=uiconst.UI_DISABLED)
    200         self.labelCont = ContainerAutoSize(name='labelCont', parent=self.upperCont, align=Align.TOLEFT)
    201         self.label = TextDetail(name='label', parent=self.labelCont, align=Align.CENTERLEFT, text=GetColoredText(self.modifiedAttribute, self.GetDisplayValue()), state=uiconst.UI_DISABLED, bold=1 if highest else 0)
    202         self.label.LoadTooltipPanel = lambda tooltipPanel, *args: LoadAttributeTooltipPanel(tooltipPanel, self)
    203         if self.modifiedAttribute:
    204             self.label.state = uiconst.UI_NORMAL
    205         formatInfo = GetFormattedAttributeAndValue(self.attribute.attributeID, self.attribute.value)
    206         if formatInfo:
    207             self.upperCont.hint = formatInfo.displayName
    208 
    209     def GetDisplayValue(self):
    210         return u'{}%'.format(int(round((1.0 - self.attribute.value) * 100)))