dynamicItem.py (7619B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\tooltip\dynamicItem.py 2 import dogma.data as dogma_data 3 from carbonui import uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 from carbonui.primitives.fill import Fill 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.util.color import Color 9 from eve.client.script.ui.control import eveLabel 10 from eve.client.script.ui.control.eveIcon import Icon 11 from eve.client.script.ui.control.itemIcon import ItemIcon 12 from eve.client.script.ui.control.themeColored import FillThemeColored 13 from eve.client.script.ui.shared.dynamicItem.const import COLOR_NEGATIVE, COLOR_POSITIVE 14 from eve.client.script.ui.shared.info.attribute import Attribute, MutatedAttribute 15 import dynamicitemattributes as dynamicitems 16 import math 17 import evetypes 18 RES_BAR_FILL = 'res:/UI/Texture/Classes/DynamicItem/arrows.png' 19 20 def AddDynamicItemAttributes(panel, itemID, typeID, spacerHeight = None): 21 if not dynamicitems.IsDynamicType(typeID): 22 return 23 if spacerHeight: 24 panel.AddSpacer(height=spacerHeight, colSpan=panel.columns) 25 container = ContainerAutoSize(align=uiconst.TOTOP, alignMode=uiconst.TOTOP) 26 dynamicItem = GetDynamicItem(itemID) 27 attributes = GetDynamicAttributes(dynamicItem) 28 sortedAttributes = sorted(attributes, key=lambda a: dogma_data.get_attribute_display_name(a.attributeID)) 29 InputItemsEntry(parent=container, align=uiconst.TOTOP, mutatorTypeID=dynamicItem.mutatorTypeID, sourceTypeID=dynamicItem.sourceTypeID) 30 for attribute in sortedAttributes: 31 AttributeEntry(parent=container, align=uiconst.TOTOP, top=4, attribute=attribute) 32 33 panel.AddSpacer(width=360, colSpan=panel.columns) 34 panel.AddCell(container, colSpan=panel.columns) 35 36 37 def GetDynamicItem(itemID): 38 dynamicItemSvc = sm.GetService('dynamicItemSvc') 39 return dynamicItemSvc.GetDynamicItem(itemID) 40 41 42 def GetDynamicAttributes(item): 43 attributes = [] 44 for attributeID in item.modifiers.keys(): 45 attributes.append(GetDynamicAttribute(item, attributeID)) 46 47 return attributes 48 49 50 def GetDynamicAttribute(item, attributeID): 51 static = sm.GetService('clientDogmaStaticSvc') 52 base = static.GetTypeAttribute(item.sourceTypeID, attributeID) 53 mutatorAttributes = dynamicitems.GetMutatorAttributes(item.mutatorTypeID) 54 bonusLow = mutatorAttributes[attributeID].min 55 bonusHigh = mutatorAttributes[attributeID].max 56 highIsGood = getattr(mutatorAttributes[attributeID], 'highIsGood', None) 57 value = item.attributes[attributeID] 58 return MutatedAttribute(attribute=Attribute(attributeID, value), sourceValue=base, minValue=base * bonusLow, maxValue=base * bonusHigh, highIsGood=highIsGood) 59 60 61 class InputItemsEntry(Container): 62 default_height = 64 63 64 def ApplyAttributes(self, attributes): 65 super(InputItemsEntry, self).ApplyAttributes(attributes) 66 self.mutatorTypeID = attributes.mutatorTypeID 67 self.sourceTypeID = attributes.sourceTypeID 68 self.Layout() 69 70 def Layout(self): 71 FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT) 72 InputItemEntry(parent=self, align=uiconst.TOTOP, typeID=self.mutatorTypeID) 73 InputItemEntry(parent=self, align=uiconst.TOTOP, typeID=self.sourceTypeID) 74 75 76 class InputItemEntry(Container): 77 default_height = 32 78 79 def ApplyAttributes(self, attributes): 80 super(InputItemEntry, self).ApplyAttributes(attributes) 81 self.typeID = attributes.typeID 82 self.Layout() 83 84 def Layout(self): 85 iconCont = Container(parent=self, align=uiconst.TOLEFT, width=32) 86 ItemIcon(parent=iconCont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=24, height=24, typeID=self.typeID) 87 eveLabel.EveLabelSmall(parent=self, align=uiconst.TOTOP, top=4, text=evetypes.GetName(self.typeID), opacity=0.6) 88 89 90 class AttributeEntry(Container): 91 default_state = uiconst.UI_DISABLED 92 default_height = 34 93 94 def ApplyAttributes(self, attributes): 95 super(AttributeEntry, self).ApplyAttributes(attributes) 96 self.attribute = attributes.attribute 97 self.Layout() 98 99 def Layout(self): 100 FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT) 101 iconCont = Container(parent=self, align=uiconst.TOLEFT, width=32) 102 Icon(parent=iconCont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, size=24, icon=self.attribute.iconID) 103 labelName = eveLabel.EveLabelSmall(parent=self, align=uiconst.TOTOP, top=2, maxLines=1, text=dogma_data.get_attribute_display_name(self.attribute.attributeID), opacity=0.6) 104 labelName.SetRightAlphaFade(fadeEnd=300, maxFadeWidth=200) 105 FinalAttributeValueLabel(parent=self, align=uiconst.TOTOP_NOPUSH, height=14, attribute=self.attribute) 106 MutationBar(parent=self, align=uiconst.TOBOTTOM, idx=0, attribute=self.attribute) 107 108 109 class FinalAttributeValueLabel(Container): 110 default_clipChildren = True 111 112 def ApplyAttributes(self, attributes): 113 super(FinalAttributeValueLabel, self).ApplyAttributes(attributes) 114 self.attribute = attributes.attribute 115 self.Layout() 116 117 def Layout(self): 118 self.valueLabel = eveLabel.EveLabelSmall(parent=self, align=uiconst.BOTTOMLEFT, text=self.attribute.displayValue, autoFitToText=True) 119 self.diffLabel = eveLabel.EveLabelSmall(parent=self, align=uiconst.BOTTOMLEFT) 120 self.UpdateDiff() 121 122 def UpdateDiff(self): 123 diff = self.attribute.value - self.attribute.sourceValue 124 diffStr = self.attribute.FormatDiff(diff) 125 if self.attribute.isMutationPositive: 126 color = Color(*COLOR_POSITIVE).GetHex() 127 else: 128 color = Color(*COLOR_NEGATIVE).GetHex() 129 text = u'<color={color}>({diff})</color>'.format(color=color, diff=diffStr) 130 self.diffLabel.SetText(text) 131 self.diffLabel.left = self.valueLabel.textwidth + 8 132 133 134 class MutationBar(Container): 135 default_height = 4 136 default_clipChildren = False 137 138 def ApplyAttributes(self, attributes): 139 super(MutationBar, self).ApplyAttributes(attributes) 140 self.attribute = attributes.attribute 141 self.Layout() 142 self.UpdateBar() 143 144 def Layout(self): 145 FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT) 146 self.barPin = Container(parent=self, align=uiconst.TOPLEFT_PROP, left=0.5, height=1.0, width=1.0) 147 Fill(parent=self.barPin, align=uiconst.TOPLEFT, height=self.height, width=1, color=(0.7, 0.7, 0.7, 1.0)) 148 self.barFill = Sprite(parent=self, align=uiconst.TOLEFT_PROP, left=0.5, width=0.0, texturePath=RES_BAR_FILL, tileX=True) 149 150 def UpdateBar(self): 151 attribute = self.attribute 152 trueSource = max(attribute.sourceValue, attribute.mutationMin) 153 if attribute.isMutationPositive: 154 self.barFill.align = uiconst.TOLEFT_PROP 155 self.barFill.SetRGB(*COLOR_POSITIVE) 156 self.barFill.rotation = 0.0 157 rangeWidth = abs(attribute.mutationHigh - trueSource) 158 else: 159 self.barFill.align = uiconst.TORIGHT_PROP 160 self.barFill.SetRGB(*COLOR_NEGATIVE) 161 self.barFill.rotation = math.pi 162 rangeWidth = abs(attribute.mutationLow - trueSource) 163 if rangeWidth > 0.0: 164 width = abs(attribute.value - trueSource) / rangeWidth 165 else: 166 width = 0.0 167 sign = 1.0 if attribute.isMutationPositive else -1.0 168 self.barPin.left = 0.5 + sign * (width / 2.0) 169 self.barFill.width = width / 2.0