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

empireThemedTooltip.py (9923B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\empireui\empireThemedTooltip.py
      2 import carbonui.const as uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.frame import Frame
      5 from carbonui.primitives.gradientSprite import GradientSprite
      6 from carbonui.primitives.sprite import Sprite
      7 from charactercreator.client.scalingUtils import GetScaleFactor
      8 from eve.client.script.ui.login.charcreation.label import CCLabel
      9 from eve.client.script.ui.login.charcreation.technologyViewUtils import VerticalLineDecoration
     10 from eve.client.script.ui.util.uix import GetTextHeight
     11 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar
     12 from math import pi
     13 BOX_WIDTH_MIN_RES = 284
     14 OUTER_BOX_PADDING_MIN_RES = 10
     15 ICON_SIZE_MIN_RES = 23
     16 ICON_PADDING_MIN_RES = 3
     17 TEXT_PADDING_TOP_MIN_RES = 9
     18 TEXT_PADDING_RIGHT_MIN_RES = 9
     19 TEXT_PADDING_BOTTOM_MIN_RES = 11
     20 TEXT_PADDING_INTERNAL_MIN_RES = 9
     21 TEXT_WIDTH_MIN_RES = BOX_WIDTH_MIN_RES - 2 * ICON_PADDING_MIN_RES - ICON_SIZE_MIN_RES - TEXT_PADDING_RIGHT_MIN_RES
     22 TITLE_FONTSIZE_MIN_RES = 11
     23 TEXT_FONTSIZE_MIN_RES = 11
     24 LINE_WIDTH = 4
     25 LINE_DECO_HEIGHT_MIN_RES = 41
     26 CURVED_GRADIENT_WIDTH_MIN_RES = 17
     27 CURVED_GRADIENT_TEXTURE_BY_RACE = {raceAmarr: 'res:/UI/Texture/Classes/EmpireSelection/curvedGradientAmarr.png',
     28  raceCaldari: 'res:/UI/Texture/Classes/EmpireSelection/curvedGradientCaldari.png',
     29  raceGallente: 'res:/UI/Texture/Classes/EmpireSelection/curvedGradientGallente.png',
     30  raceMinmatar: 'res:/UI/Texture/Classes/EmpireSelection/curvedGradientMinmatar.png'}
     31 BLURR_TEXTURE = 'res:/UI/Texture/Classes/EmpireSelection/shipTooltipBlur.png'
     32 TITLE_OPACITY = 1.0
     33 TEXT_OPACITY = 0.75
     34 LINE_OPACITY = 1.0
     35 CURVED_GRADIENT_OPACITY = 0.5
     36 BACKGROUND_GRADIENT_OPACITY = 0.5
     37 BLURR_BOX_OPACITY = 0.8
     38 BACKGROUND_GRADIENT_TINT_BY_RACE = {raceAmarr: (0.51, 0.44, 0.32),
     39  raceCaldari: (0.29, 0.43, 0.5),
     40  raceGallente: (0.21, 0.4, 0.4),
     41  raceMinmatar: (0.4, 0.22, 0.2)}
     42 BLURR_CORNERSIZE = 20
     43 
     44 def get_tooltip_width():
     45     return BOX_WIDTH_MIN_RES * GetScaleFactor()
     46 
     47 
     48 class EmpireThemedTooltip(object):
     49     default_state = uiconst.UI_DISABLED
     50 
     51     def __init__(self, raceID, icon, title, text, name, parent, left, top):
     52         self.raceID = raceID
     53         self.icon = icon
     54         self.title = title.upper()
     55         self.text = text
     56         self.name = name
     57         self.parent = parent
     58         self.left = left
     59         self.top = top
     60         self.calculate_sizes()
     61         self.add_tooltip_text()
     62         self.add_tooltip_box()
     63 
     64     def close(self):
     65         if self.is_box_available():
     66             self.tooltip_box_wrapper.Close()
     67         if self.is_text_available():
     68             self.tooltip_text_wrapper.Close()
     69 
     70     def is_box_available(self):
     71         return self.tooltip_box_wrapper and not self.tooltip_box_wrapper.destroyed
     72 
     73     def is_text_available(self):
     74         return self.tooltip_text_wrapper and not self.tooltip_text_wrapper.destroyed
     75 
     76     def calculate_sizes(self):
     77         self.label_width = TEXT_WIDTH_MIN_RES * GetScaleFactor()
     78         self.title_fontsize = TITLE_FONTSIZE_MIN_RES * GetScaleFactor()
     79         self.text_fontsize = TEXT_FONTSIZE_MIN_RES * GetScaleFactor()
     80         self.text_padding_top = TEXT_PADDING_TOP_MIN_RES * GetScaleFactor()
     81         self.text_padding_bottom = TEXT_PADDING_BOTTOM_MIN_RES * GetScaleFactor()
     82         self.text_padding_right = TEXT_PADDING_BOTTOM_MIN_RES * GetScaleFactor()
     83         self.text_padding_internal = TEXT_PADDING_INTERNAL_MIN_RES * GetScaleFactor()
     84         self.icon_size = ICON_SIZE_MIN_RES * GetScaleFactor()
     85         self.icon_padding = ICON_PADDING_MIN_RES * GetScaleFactor()
     86         self.title_height = self.calculate_title_height()
     87         self.text_height = self.calculate_text_height()
     88         self.label_height = self.title_height + self.text_padding_internal + self.text_height
     89         self.box_width = BOX_WIDTH_MIN_RES * GetScaleFactor()
     90         self.box_height = self.text_padding_top + self.label_height + self.text_padding_bottom
     91         self.outer_box_padding = OUTER_BOX_PADDING_MIN_RES * GetScaleFactor()
     92 
     93     def calculate_title_height(self):
     94         title_height = GetTextHeight(strng=self.title, fontsize=self.title_fontsize, hspace=1, uppercase=1, width=self.label_width)
     95         return title_height
     96 
     97     def calculate_text_height(self):
     98         text_height = GetTextHeight(strng=self.text, fontsize=self.text_fontsize, hspace=1, uppercase=0, width=self.label_width)
     99         return text_height
    100 
    101     def add_tooltip_text(self):
    102         self.tooltip_text_wrapper = Container(name='TooltipTextWrapper_%s' % self.name, parent=self.parent, align=uiconst.TOTOP_NOPUSH, width=self.box_width, height=self.box_height, top=self.top, left=self.left, opacity=0.0, state=uiconst.UI_DISABLED)
    103         self.tooltip_text_wrapper.SetOrder(0)
    104         tooltip_text_container = Container(name='TooltipTextContainer_%s' % self.name, parent=self.tooltip_text_wrapper, align=uiconst.TOLEFT, width=self.box_width, height=self.box_height)
    105         self.add_icon(tooltip_text_container)
    106         self.add_label(tooltip_text_container)
    107 
    108     def add_icon(self, parent_container):
    109         icon_container = Container(name='IconContainer_%s' % self.name, parent=parent_container, align=uiconst.TOLEFT, width=self.icon_size, height=self.icon_size, padding=self.icon_padding)
    110         Sprite(name='Icon_%s' % self.name, parent=icon_container, align=uiconst.CENTERTOP, width=self.icon_size, height=self.icon_size, texturePath=self.icon)
    111 
    112     def add_label(self, parent_container):
    113         label_wrapper = Container(name='LabelWrapper_%s' % self.name, parent=parent_container, align=uiconst.TOLEFT, width=self.label_width, height=self.label_height)
    114         label_container = Container(name='LabelContainer_%s' % self.name, parent=label_wrapper, align=uiconst.TOTOP, width=self.label_width, height=self.label_height, padTop=self.text_padding_top, padBottom=self.text_padding_bottom)
    115         self.add_title(label_container)
    116         self.add_text(label_container)
    117 
    118     def add_title(self, parent_container):
    119         title_container = Container(name='TitleContainer_%s' % self.name, parent=parent_container, align=uiconst.TOTOP, width=self.label_width, height=self.title_height)
    120         CCLabel(text=self.title, name='Title_%s' % self.name, parent=title_container, align=uiconst.TOALL, fontsize=self.title_fontsize, uppercase=1, letterspace=1, bold=True, opacity=TITLE_OPACITY)
    121 
    122     def add_text(self, parent_container):
    123         text_container = Container(name='TextContainer_%s' % self.name, parent=parent_container, align=uiconst.TOTOP, width=self.label_width, height=self.text_height, padTop=self.text_padding_internal)
    124         CCLabel(text=self.text, name='Text_%s' % self.name, parent=text_container, align=uiconst.TOALL, fontsize=self.text_fontsize, uppercase=0, letterspace=1, bold=False, opacity=TEXT_OPACITY)
    125 
    126     def add_tooltip_box(self):
    127         self.tooltip_box_wrapper = Container(name='TooltipBoxWrapper_%s' % self.name, parent=self.parent, align=uiconst.TOTOP_NOPUSH, width=self.box_width, height=self.box_height, top=self.top, left=self.left, opacity=0.0, state=uiconst.UI_DISABLED)
    128         tooltip_box_container = Container(name='TooltipBoxContainer_%s' % self.name, parent=self.tooltip_box_wrapper, align=uiconst.TOLEFT, width=self.box_width, height=self.box_height)
    129         self.add_line(tooltip_box_container)
    130         self.add_curved_gradient(tooltip_box_container)
    131         self.add_background_gradient(tooltip_box_container)
    132         self.add_tooltip_blurr(tooltip_box_container)
    133 
    134     def add_line(self, parent_container):
    135         VerticalLineDecoration(name='LineDecoration_%s' % self.name, parent=parent_container, align=uiconst.TOLEFT_NOPUSH, width=LINE_WIDTH, height=parent_container.height, lineHeight=parent_container.height, lineDecorationHeight=LINE_DECO_HEIGHT_MIN_RES * GetScaleFactor(), opacity=LINE_OPACITY)
    136 
    137     def add_curved_gradient(self, parent_container):
    138         Sprite(name='CurvedGradient_%s' % self.name, parent=parent_container, align=uiconst.TOLEFT_NOPUSH, width=CURVED_GRADIENT_WIDTH_MIN_RES * GetScaleFactor(), height=parent_container.height, texturePath=CURVED_GRADIENT_TEXTURE_BY_RACE[self.raceID], opacity=CURVED_GRADIENT_OPACITY, rotation=3 * pi / 2)
    139 
    140     def add_background_gradient(self, parent_container):
    141         GradientSprite(name='BackgroundGradient_%s' % self.name, parent=parent_container, align=uiconst.TOLEFT_NOPUSH, width=parent_container.width, height=parent_container.height, opacity=BACKGROUND_GRADIENT_OPACITY, rgbData=((0.0, BACKGROUND_GRADIENT_TINT_BY_RACE[self.raceID]),), alphaData=((0.0, 1.0), (1.0, 0.0)))
    142 
    143     def add_tooltip_blurr(self, parent_container):
    144         tooltip_blurr_wrapper = Container(name='TooltipBlurrWrapper_%s' % self.name, parent=parent_container, align=uiconst.TOTOP_NOPUSH, width=self.box_width + 2 * self.outer_box_padding, height=self.box_height + 2 * self.outer_box_padding, top=-self.outer_box_padding, left=-self.outer_box_padding)
    145         tooltip_blurr_container = Container(name='TooltipBlurrContainer_%s' % self.name, parent=tooltip_blurr_wrapper, align=uiconst.TOLEFT, width=self.box_width + 2 * self.outer_box_padding, height=self.box_height + 2 * self.outer_box_padding)
    146         Frame(name='TooltipBlurr_%s' % self.name, parent=tooltip_blurr_container, align=uiconst.TOTOP, width=self.box_width + 2 * self.outer_box_padding, height=self.box_height + 2 * self.outer_box_padding, cornerSize=BLURR_CORNERSIZE, texturePath=BLURR_TEXTURE, opacity=BLURR_BOX_OPACITY)
    147 
    148     def set_visibility(self, is_visible):
    149         opacity = 1.0 if is_visible else 0.0
    150         if self.is_box_available():
    151             self.tooltip_box_wrapper.SetOrder(0)
    152             self.tooltip_box_wrapper.opacity = opacity
    153         if self.is_text_available():
    154             self.tooltip_text_wrapper.SetOrder(0)
    155             self.tooltip_text_wrapper.opacity = opacity