label.py (4798B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\vgs\label.py 2 import carbonui.fontconst 3 from carbon.common.script.util.format import FmtAmt 4 import carbonui.const as uiconst 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.containerAutoSize import ContainerAutoSize 7 from carbonui.primitives.sprite import Sprite 8 from eve.client.script.ui.control.eveLabel import Label 9 from eve.client.script.ui.plex.textures import PLEX_32_GRADIENT_YELLOW 10 from eve.common.script.util.eveFormat import RoundISK 11 from inventorycommon.const import typePlex 12 import localization 13 import inventorycommon.typeHelpers 14 FONTSIZE_LARGE = 28 15 FONTSIZE_MEDIUM = 18 16 FONTSIZE_SMALL = 12 17 FONT_COLOR_WHITE = (1.0, 1.0, 1.0, 0.75) 18 FONT_COLOR_DISCOUNT = (0.627, 0.145, 0.094, 1.0) 19 20 class VgsLabel(Label): 21 default_center = False 22 23 def ApplyAttributes(self, attributes): 24 self.center = attributes.get('center', self.default_center) 25 super(VgsLabel, self).ApplyAttributes(attributes) 26 27 def GetText(self): 28 return super(VgsLabel, self).GetText() 29 30 def SetText(self, text): 31 if self.center: 32 text = '<center>%s</center>' % text 33 super(VgsLabel, self).SetText(text) 34 35 text = property(GetText, SetText) 36 37 38 class VgsLabelLarge(VgsLabel): 39 default_name = 'VgsLabelLarge' 40 default_fontsize = FONTSIZE_LARGE 41 BASELINE = 0 42 43 44 class VgsLabelMedium(VgsLabel): 45 default_name = 'VgsLabelMedium' 46 default_fontsize = FONTSIZE_MEDIUM 47 BASELINE = 0 48 49 50 class VgsLabelSmall(VgsLabel): 51 default_name = 'VgsLabelSmall' 52 default_fontsize = FONTSIZE_SMALL 53 BASELINE = 4 54 55 56 class VgsHeaderLarge(VgsLabel): 57 default_name = 'VgsHeaderLarge' 58 default_fontsize = FONTSIZE_LARGE 59 default_fontStyle = carbonui.fontconst.STYLE_HEADER 60 BASELINE = 8 61 62 63 class VgsHeaderMedium(VgsLabel): 64 default_name = 'VgsHeaderMedium' 65 default_fontsize = FONTSIZE_MEDIUM 66 default_fontStyle = carbonui.fontconst.STYLE_HEADER 67 BASELINE = 5 68 69 70 class VgsHeaderSmall(VgsLabel): 71 default_name = 'VgsHeaderSmall' 72 default_fontsize = FONTSIZE_SMALL 73 default_fontStyle = carbonui.fontconst.STYLE_HEADER 74 BASELINE = 4 75 76 77 class VgsButtonLabelMedium(VgsLabel): 78 default_name = 'VgsButtonLabelMedium' 79 default_fontsize = FONTSIZE_MEDIUM 80 default_fontStyle = carbonui.fontconst.STYLE_HEADER 81 default_uppercase = True 82 BASELINE = 5 83 84 85 class PlexPriceTag(ContainerAutoSize): 86 default_alignMode = uiconst.TOLEFT 87 PLEX_FONT_CLASS = VgsHeaderMedium 88 ISK_FONT_CLASS = VgsLabelSmall 89 ISK_FONT_COLOR = (0.5, 0.5, 0.5, 1.0) 90 WORD_PADDING = 8 91 92 def ApplyAttributes(self, attributes): 93 super(PlexPriceTag, self).ApplyAttributes(attributes) 94 self.height = self.PLEX_FONT_CLASS.default_fontsize 95 amount = attributes.amount 96 baseAmount = attributes.get('baseAmount', None) 97 cont = Container(parent=self, align=uiconst.TOLEFT, padRight=4, width=32) 98 Sprite(parent=cont, align=uiconst.BOTTOMLEFT, state=uiconst.UI_DISABLED, texturePath=PLEX_32_GRADIENT_YELLOW, height=32, width=32, top=-7) 99 self.AddPlexAmount(amount) 100 if baseAmount is not None and baseAmount > amount: 101 self.AddPlexAmount(baseAmount, color=FONT_COLOR_DISCOUNT, strikeThrough=True) 102 iskWorth = self._CalculateEstimatedIskWorth(amount) 103 if iskWorth is not None: 104 self.AddEstimatedIskPrice(iskWorth) 105 106 def AddPlexAmount(self, amount, color = None, strikeThrough = False): 107 self.AddLabel(FmtAmt(amount), font=self.PLEX_FONT_CLASS, color=color, strikeThrough=strikeThrough) 108 109 def AddEstimatedIskPrice(self, amount): 110 label = localization.GetByLabel('UI/VirtualGoodsStore/EstimatedIskPrice', amount=amount) 111 self.AddLabel(label, font=self.ISK_FONT_CLASS, color=self.ISK_FONT_COLOR) 112 113 def AddLabel(self, text, font, color = None, strikeThrough = False): 114 color = color or FONT_COLOR_WHITE 115 cont = Container(parent=self, align=uiconst.TOLEFT, padRight=self.WORD_PADDING) 116 if strikeThrough: 117 Sprite(parent=cont, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/strikethrough.png', color=color, state=uiconst.UI_DISABLED) 118 label = font(parent=cont, align=uiconst.BOTTOMLEFT, top=-font.BASELINE, text=text, color=color) 119 cont.width = label.textwidth 120 121 def _CalculateEstimatedIskWorth(self, plexPrice): 122 try: 123 plexValue = inventorycommon.typeHelpers.GetAveragePrice(typePlex) 124 except KeyError: 125 return None 126 127 if not plexValue: 128 return None 129 return RoundISK(plexPrice * plexValue) 130 131 132 class PlexPriceTagLarge(PlexPriceTag): 133 PLEX_FONT_CLASS = VgsHeaderLarge 134 ISK_FONT_CLASS = VgsLabelSmall