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

weaponsView.py (12696B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\empireTechnologyViews\weaponsView.py
      2 import carbonui.const as uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.fill import Fill
      5 from carbonui.primitives.sprite import Sprite, StreamingVideoSprite
      6 from carbonui.uicore import uicore
      7 from charactercreator.client.scalingUtils import SMALL_SCREEN_HEIGHT, BIG_SCREEN_HEIGHT
      8 from eve.client.script.ui.control.eveLabel import Label
      9 from eve.client.script.ui.login.charcreation.empireTechnologyViews.technologyView import TechnologyView
     10 from eve.client.script.ui.login.charcreation.technologyViewUtils import LineDecoration, LINE_DECORATION_GRADIENT_HEIGHT
     11 from eve.client.script.ui.util.uix import GetTextHeight
     12 import trinity
     13 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar
     14 ELEMENTS_PADDING_TOP = -100
     15 LINE_DECORATION_WIDTH = 1000
     16 LINE_DECORATION_HEIGHT = 4
     17 WEAPONS_DESCRIPTION_WIDTH = 400
     18 WEAPONS_DESCRIPTION_FONTSIZE = 16
     19 WEAPONS_DESCRIPTION_PAD_TOP = 60
     20 TURRET_VIEW_WIDTH = 450
     21 TURRET_VIEW_HEIGHT = 308
     22 TURRET_PAD_LEFT = 30
     23 ATTRIBUTE_COLUMN_WIDTH = 400
     24 ATTRIBUTE_TEXT_WIDTH = 400
     25 ATTRIBUTE_TEXT_FONTSIZE = 16
     26 SCALE_FACTOR_AT_SMALL_SCREEN_HEIGHT = 0.71
     27 INTERNAL_MARGIN_H = 40
     28 INTERNAL_MARGIN_V = 40
     29 ATTRIBUTE_ICON_SIZE = 30
     30 ATTRIBUTE_ICON_SEPARATION = 8
     31 ATTRIBUTE_ROWS_SEPARATION = 20
     32 ATTRIBUTE_TEXTS_SEPARATION = 4
     33 ATTRIBUTE_ICON_FILL_COLOR = (0.0, 0.0, 0.0, 0.25)
     34 ATTRIBUTE_ICON_FILL_LIGHT_COLOR = (1.0, 1.0, 1.0, 0.25)
     35 
     36 class Attribute(object):
     37 
     38     def __init__(self, order, iconPath, title, description, textWidth, fontsize):
     39         self.order = order
     40         self.iconPath = iconPath
     41         self.title = title
     42         self.description = description
     43         self.fontsize = fontsize
     44         self.textHeight = self._CalculateTextHeight(textWidth)
     45 
     46     def _CalculateTextHeight(self, textWidth):
     47         titleTextHeight = GetTextHeight(strng=self.title, width=textWidth, fontsize=self.fontsize, uppercase=1)
     48         descriptionTextHeight = GetTextHeight(strng=self.description, width=textWidth, fontsize=self.fontsize)
     49         textHeight = titleTextHeight + ATTRIBUTE_TEXTS_SEPARATION + descriptionTextHeight
     50         return max(textHeight, ATTRIBUTE_ICON_SIZE)
     51 
     52 
     53 class AttributeView(Container):
     54 
     55     def ApplyAttributes(self, attributes):
     56         Container.ApplyAttributes(self, attributes)
     57         iconPath = attributes.Get('iconPath')
     58         title = attributes.Get('title')
     59         description = attributes.Get('description')
     60         fontsize = attributes.Get('fontsize')
     61         self.AddIcon(iconPath)
     62         self.AddText(title, description, fontsize)
     63 
     64     def AddIcon(self, iconPath):
     65         iconContainer = Container(name='attributeIconContainer', parent=self, align=uiconst.TOLEFT, width=ATTRIBUTE_ICON_SIZE, height=ATTRIBUTE_ICON_SIZE, padRight=ATTRIBUTE_ICON_SEPARATION)
     66         iconWrapperContainer = Container(name='iconWrapperContainer', parent=iconContainer, align=uiconst.TOTOP, width=ATTRIBUTE_ICON_SIZE, height=ATTRIBUTE_ICON_SIZE)
     67         self.iconFill = Fill(bgParent=iconWrapperContainer, color=ATTRIBUTE_ICON_FILL_COLOR)
     68         self.icon = Sprite(name='attributeIcon', parent=iconWrapperContainer, align=uiconst.TOTOP, width=ATTRIBUTE_ICON_SIZE, height=ATTRIBUTE_ICON_SIZE, texturePath=iconPath, spriteEffect=trinity.TR2_SFX_COLOROVERLAY)
     69 
     70     def AddText(self, title, description, fontsize):
     71         textContainer = Container(name='textContainer', parent=self, align=uiconst.TOLEFT, width=self.width - ATTRIBUTE_ICON_SIZE, height=self.height)
     72         Label(name='attributeTitleLabel', parent=textContainer, align=uiconst.TOTOP, text=title, padBottom=ATTRIBUTE_TEXTS_SEPARATION, fontsize=fontsize)
     73         Label(name='attributeDescriptionLabel', parent=textContainer, align=uiconst.TOTOP, text=description, fontsize=fontsize)
     74 
     75 
     76 class WeaponsView(TechnologyView):
     77     racialAnimationSounds = {raceAmarr: 'sfx_es_weaponry_amarr_play',
     78      raceCaldari: 'sfx_es_weaponry_caldari_play',
     79      raceGallente: 'sfx_es_weaponry_gallente_play',
     80      raceMinmatar: 'sfx_es_weaponry_minmatar_play'}
     81 
     82     def ApplyAttributes(self, attributes):
     83         self.attributeViews = []
     84         TechnologyView.ApplyAttributes(self, attributes)
     85         centralContainer = Container(name='centralContainer', parent=self, align=uiconst.ANCH_TOPLEFT, width=self.width, height=self.height)
     86         self._PrepareAttributes()
     87         weaponsDescriptionText = self.technology.GetMainText(self.raceID)
     88         turretWidth, turretHeight = self._GetTurretViewSize()
     89         weaponsWidth, weaponsHeight = self._GetWeaponsDescriptionSize(weaponsDescriptionText)
     90         weaponsHeight += WEAPONS_DESCRIPTION_PAD_TOP * self._GetScaleFactor()
     91         attributesWidth, attributesHeight = self._GetAttributesSize()
     92         topViewHeight = max(turretHeight, weaponsHeight)
     93         lineViewHeight = 2 * INTERNAL_MARGIN_V + LINE_DECORATION_GRADIENT_HEIGHT
     94         centralViewWidth = (2 * ATTRIBUTE_COLUMN_WIDTH + INTERNAL_MARGIN_H) * self._GetScaleFactor()
     95         centralViewHeight = topViewHeight + lineViewHeight + attributesHeight
     96         centralView = Container(name='centralView', parent=centralContainer, align=uiconst.CENTER, width=centralViewWidth, height=centralViewHeight, top=ELEMENTS_PADDING_TOP * self._GetScaleFactor())
     97         self.BuildTopView(parent=centralView, width=centralViewWidth, height=topViewHeight, turretWidth=turretWidth, turretHeight=turretHeight, weaponsText=weaponsDescriptionText, weaponsWidth=weaponsWidth)
     98         self.BuildLineView(parent=centralView, width=centralViewWidth, height=lineViewHeight)
     99         self.BuildBottomView(parent=centralView, width=centralViewWidth, height=attributesHeight)
    100         self.PlayTurretVideoAndSound()
    101 
    102     def _PrepareAttributes(self):
    103         attributeTextWidth = self._GetAttributeTextWidth()
    104         attributeFontsize = self._GetAttributeFontsize()
    105         numberOfAttributes = self.technology.GetNumberOfExamples()
    106         self.attributesLeft = []
    107         self.attributesRight = []
    108         maxOrderLeft = numberOfAttributes / 2
    109         for order, attribute in self.technology.GetTechExamples():
    110             attribute = Attribute(order=order, iconPath=attribute.GetIcon(self.raceID), title=attribute.GetTitle(self.raceID), description=attribute.GetSubtitle(self.raceID), textWidth=attributeTextWidth, fontsize=attributeFontsize)
    111             if order <= maxOrderLeft:
    112                 self.attributesLeft.append(attribute)
    113             else:
    114                 self.attributesRight.append(attribute)
    115 
    116     def BuildTopView(self, parent, width, height, turretWidth, turretHeight, weaponsText, weaponsWidth):
    117         self.topView = Container(name='topView', parent=parent, align=uiconst.TOTOP, width=width, height=height, opacity=1.0)
    118         self.AddTurretView(turretWidth, turretHeight)
    119         self.AddWeaponsDescription(weaponsText, weaponsWidth, height)
    120 
    121     def AddWeaponsDescription(self, text, width, height):
    122         topLeftView = Container(name='topLeftView', parent=self.topView, align=uiconst.TOLEFT, width=self.topView.width / 2, height=self.topView.height)
    123         weaponsDescriptionContainer = Container(name='weaponsDescriptionContainer', parent=topLeftView, width=width, height=height, align=uiconst.TORIGHT)
    124         Label(name='weaponsDescriptionLabel', parent=weaponsDescriptionContainer, width=width, height=height, text=text, fontsize=self._GetWeaponsDescriptionFontsize(), top=WEAPONS_DESCRIPTION_PAD_TOP * self._GetScaleFactor())
    125 
    126     def AddTurretView(self, turretWidth, turretHeight):
    127         topRightView = Container(name='topRightView', parent=self.topView, align=uiconst.TORIGHT, width=self.topView.width / 2, height=self.topView.height)
    128         turretView = self.technology.GetMainView(self.raceID)
    129         if not turretView:
    130             return
    131         turretViewContainer = Container(name='turretViewContainer', parent=topRightView, align=uiconst.TOPLEFT, width=turretWidth, height=turretHeight, padLeft=TURRET_PAD_LEFT)
    132         self.turretVideo = StreamingVideoSprite(parent=turretViewContainer, name='turretView', videoPath=turretView, videoLoop=False, align=uiconst.TOALL, state=uiconst.UI_DISABLED, spriteEffect=trinity.TR2_SFX_COPY, disableAudio=True, opacity=0.0)
    133         self.turretVideo.Pause()
    134 
    135     def BuildLineView(self, parent, width, height):
    136         lineView = Container(name='lineView', parent=parent, align=uiconst.TOTOP, width=width, height=height)
    137         self.line = LineDecoration(name='lineDecoration', parent=lineView, align=uiconst.TOTOP, width=width, height=LINE_DECORATION_HEIGHT, lineWidth=width, opacity=1.0, padTop=INTERNAL_MARGIN_V)
    138 
    139     def BuildBottomView(self, parent, width, height):
    140         self.bottomView = Container(name='bottomView', parent=parent, align=uiconst.TOTOP, width=width, height=height)
    141         self.AddAttributes(width, height)
    142 
    143     def AddAttributes(self, width, height):
    144         attributesContainer = Container(name='attributesContainer', parent=self.bottomView, align=uiconst.CENTER, width=width, height=height)
    145         attributesContainerWidth = width / 2 - INTERNAL_MARGIN_H
    146         attributesContainerLeft = Container(name='attributesContainerLeft', parent=attributesContainer, align=uiconst.TOLEFT, width=attributesContainerWidth, height=height, padRight=INTERNAL_MARGIN_H)
    147         attributesContainerRight = Container(name='attributesContainerRight', parent=attributesContainer, align=uiconst.TOLEFT, width=attributesContainerWidth, height=height, padLeft=INTERNAL_MARGIN_H)
    148         self.AddAttributesColumn(self.attributesLeft, attributesContainerLeft)
    149         self.AddAttributesColumn(self.attributesRight, attributesContainerRight)
    150 
    151     def AddAttributesColumn(self, attributes, attributesColumn):
    152         isFirstAttribute = True
    153         for attribute in attributes:
    154             attributeView = AttributeView(name='attributeView%s' % attribute.order, parent=attributesColumn, align=uiconst.TOTOP, width=ATTRIBUTE_COLUMN_WIDTH * self._GetScaleFactor(), height=attribute.textHeight, iconPath=attribute.iconPath, title=attribute.title, description=attribute.description, fontsize=attribute.fontsize, padTop=0 if isFirstAttribute else ATTRIBUTE_ROWS_SEPARATION, opacity=1.0)
    155             isFirstAttribute = False
    156             self.attributeViews.append(attributeView)
    157 
    158     def _GetLineDecorationWidth(self):
    159         scaleFactor = self._GetScaleFactor()
    160         width = LINE_DECORATION_WIDTH * scaleFactor
    161         return width
    162 
    163     def _GetAttributeTextWidth(self):
    164         scaleFactor = self._GetScaleFactor()
    165         width = ATTRIBUTE_TEXT_WIDTH * scaleFactor
    166         return width
    167 
    168     def _GetAttributeFontsize(self):
    169         return ATTRIBUTE_TEXT_FONTSIZE * self._GetScaleFactor()
    170 
    171     def _GetAttributesSize(self):
    172         textWidth = self._GetAttributeTextWidth()
    173         columnWidth = ATTRIBUTE_ICON_SIZE + ATTRIBUTE_ICON_SEPARATION + textWidth + INTERNAL_MARGIN_H
    174         columnHeightLeft = self._GetAttributesColumnHeight(self.attributesLeft)
    175         columnHeightRight = self._GetAttributesColumnHeight(self.attributesRight)
    176         width = 2 * columnWidth
    177         height = max(columnHeightLeft, columnHeightRight)
    178         return (width, height)
    179 
    180     def _GetAttributesColumnHeight(self, attributesColumn):
    181         height = 0
    182         for attribute in attributesColumn:
    183             if height > 0:
    184                 height += ATTRIBUTE_ROWS_SEPARATION
    185             height += attribute.textHeight
    186 
    187         return height
    188 
    189     def _GetTurretViewSize(self):
    190         scaleFactor = self._GetScaleFactor()
    191         width = TURRET_VIEW_WIDTH * scaleFactor
    192         height = TURRET_VIEW_HEIGHT * scaleFactor
    193         return (width, height)
    194 
    195     def _GetWeaponsDescriptionFontsize(self):
    196         return WEAPONS_DESCRIPTION_FONTSIZE * self._GetScaleFactor()
    197 
    198     def _GetWeaponsDescriptionSize(self, text):
    199         width = WEAPONS_DESCRIPTION_WIDTH * self._GetScaleFactor()
    200         height = GetTextHeight(strng=text, width=width, fontsize=self._GetWeaponsDescriptionFontsize())
    201         return (width, height)
    202 
    203     def _GetScaleFactor(self):
    204         desktopHeight = uicore.desktop.height
    205         if desktopHeight > BIG_SCREEN_HEIGHT:
    206             desktopHeight = BIG_SCREEN_HEIGHT
    207         return SCALE_FACTOR_AT_SMALL_SCREEN_HEIGHT * desktopHeight / SMALL_SCREEN_HEIGHT
    208 
    209     def PlayTurretVideoAndSound(self):
    210         sm.GetService('audio').SendUIEvent(self.racialAnimationSounds[self.raceID])
    211         self.turretVideo.Play()
    212         self.turretVideo.opacity = 1.0
    213         self.turretVideo.UnmuteAudio()
    214 
    215     def Close(self):
    216         self.turretVideo.MuteAudio()
    217         self.turretVideo.opacity = 0.0
    218         TechnologyView.Close(self)