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

logoEntries.py (10635B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\cosmetics\logoEntries.py
      2 import blue
      3 import uthread2
      4 from carbonui import const as uiconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.frame import Frame
      8 from carbonui.primitives.sprite import Sprite
      9 from carbonui.uianimations import animations
     10 from carbonui.util.color import Color
     11 from eve.client.script.ui import eveColor
     12 from eve.client.script.ui.control.eveIcon import GetLogoIcon
     13 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveCaptionMedium
     14 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     15 from eve.client.script.ui.control.themeColored import FillThemeColored
     16 from eve.client.script.ui.util.uiComponents import Component, ButtonEffect
     17 from shipcosmetics.common.const import CosmeticsType
     18 from localization import GetByLabel
     19 FRAME_PADDING = 8
     20 ENTRY_DEFAULT_HEIGHT = 124
     21 LOGO_SIZE = 96
     22 DELAY_BEFORE_SHOW_LOADING = 0.5
     23 
     24 @Component(ButtonEffect(opacityIdle=0.0, opacityHover=0.2, opacityMouseDown=0.3, bgElementFunc=lambda parent, _: parent.highlightFill, audioOnEntry=uiconst.SOUND_ENTRY_HOVER, audioOnClick=uiconst.SOUND_ENTRY_SELECT))
     25 
     26 class LogoEntry(Container):
     27     default_height = ENTRY_DEFAULT_HEIGHT
     28     default_state = uiconst.UI_NORMAL
     29     default_cosmeticsType = CosmeticsType.NONE
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(LogoEntry, self).ApplyAttributes(attributes)
     33         self._loading = False
     34         self._loadingTasklet = None
     35         self._showLoadingTasklet = None
     36         self._isSelected = False
     37         self._logoData = None
     38         self.cosmeticsType = attributes.get('cosmeticsType', self.default_cosmeticsType)
     39         self._errorCallback = attributes.errorCallback
     40         self.ConstructLayout()
     41 
     42     def Close(self):
     43         self._ClearLoadingThread()
     44         super(LogoEntry, self).Close()
     45 
     46     def ConstructLayout(self):
     47         self.mainContainer = Container(name='mainContainer', parent=self)
     48         self.loadingContainer = Container(name='loadingContainer', parent=self)
     49         self.selectionFrame = Frame(name='selectionFrame', parent=self.mainContainer, align=uiconst.TOALL, state=uiconst.UI_HIDDEN, texturePath='res:/UI/Texture/classes/Fitting/Heraldry/selectionFrame.png', color=eveColor.SUCCESS_GREEN, cornerSize=10, uiScaleVertices=True, fillCenter=False, padding=(-FRAME_PADDING,
     50          -FRAME_PADDING,
     51          -FRAME_PADDING,
     52          -FRAME_PADDING))
     53         self.selectionIcon = Sprite(name='selectionIcon', parent=self.mainContainer, align=uiconst.TOPRIGHT, texturePath='res:/UI/Texture/classes/SkillPlan/completedIcon.png', width=34, height=34)
     54         self.selectionIcon.display = False
     55         self.loadingWheel = LoadingWheel(name='loadingWheel', parent=self.loadingContainer, align=uiconst.CENTER, state=uiconst.UI_DISABLED, opacity=0.0)
     56         self.logoContainer = ContainerAutoSize(name='logoContainer', parent=self.mainContainer, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, padLeft=32)
     57         self.CreateLogoBackground()
     58         self.labelContainer = ContainerAutoSize(name='labelContainer', parent=self.mainContainer, align=uiconst.CENTERRIGHT, padRight=20, width=208)
     59         self.nameLabelWrapper = ContainerAutoSize(name='nameLabelWrapper', parent=self.labelContainer, align=uiconst.TOTOP)
     60         self.nameLabel = EveCaptionMedium(name='nameLabel', parent=self.nameLabelWrapper, align=uiconst.TOTOP, maxLines=2, padBottom=2)
     61         self.descriptionLabel = EveLabelMedium(name='descriptionLabel', parent=self.labelContainer, align=uiconst.TOTOP, color=Color.HextoRGBA('#B0B0B0'))
     62         self.highlightFill = FillThemeColored(name='highlightFill', parent=self.mainContainer, align=uiconst.TOALL, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=0.0)
     63         self.selectionFill = FillThemeColored(name='selectionFill', parent=self.mainContainer, align=uiconst.TOALL, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=0.0)
     64         self.backgroundFill = FillThemeColored(name='backgroundFill', parent=self.mainContainer, align=uiconst.TOALL, color=(0.0, 0.0, 0.0, 0.25))
     65 
     66     def CreateLogoBackground(self):
     67         self.logoBackground = Sprite(name='logoBackground', parent=self.logoContainer, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/Fitting/Heraldry/logoBackground.png', color=Color.HextoRGBA('#FFB845'), opacity=0.05, width=LOGO_SIZE, height=LOGO_SIZE)
     68 
     69     @property
     70     def logoData(self):
     71         return self._logoData
     72 
     73     @logoData.setter
     74     def logoData(self, value):
     75         self._logoData = value
     76         self.OnLogoDataChanged()
     77 
     78     def OnLogoDataChanged(self):
     79         self.UpdateDisplay()
     80 
     81     def UpdateDisplay(self):
     82         self.logoContainer.Flush()
     83         self.CreateLogoBackground()
     84 
     85     def OnClick(self, *args):
     86         if self.loading:
     87             return
     88         super(LogoEntry, self).OnClick(*args)
     89 
     90     @property
     91     def isSelected(self):
     92         return self._isSelected
     93 
     94     @isSelected.setter
     95     def isSelected(self, value):
     96         self._isSelected = value
     97         if self._isSelected:
     98             animations.FadeIn(self.selectionFill, endVal=0.2, duration=0.1, curveType=uiconst.ANIM_OVERSHOT)
     99             self.selectionFrame.state = uiconst.UI_DISABLED
    100             self.selectionIcon.display = True
    101         else:
    102             animations.FadeOut(self.selectionFill, duration=0.1)
    103             self.selectionFrame.state = uiconst.UI_HIDDEN
    104             self.selectionIcon.display = False
    105 
    106     @property
    107     def loading(self):
    108         return self._loading
    109 
    110     @loading.setter
    111     def loading(self, value):
    112         if value != self._loading:
    113             self._loading = value
    114         if self._loading:
    115             self._showLoadingTasklet = uthread2.StartTasklet(self._ShowLoadingThread)
    116         else:
    117             self._HideLoading()
    118             self._ClearLoadingThread()
    119 
    120     def IsEligible(self):
    121         raise NotImplementedError
    122 
    123     def Enable(self, *args):
    124         if self.loading:
    125             return
    126         if not self.IsEligible():
    127             return
    128         super(LogoEntry, self).Enable(*args)
    129 
    130     def _EnableLogo(self, license, groupIndex):
    131         if self.loading:
    132             return
    133         if sm.GetService('cosmeticsSvc').are_ship_emblems_disabled():
    134             return
    135         select = not self.isSelected
    136         sm.GetService('audio').SendUIEvent('fitting_window_emblem_select_play')
    137         self._loadingTasklet = uthread2.StartTasklet(self._EnableLogoThread, license, self.SLOT_INDEX, groupIndex, select)
    138 
    139     def _EnableLogoThread(self, license, slotIndex, groupIndex, enable):
    140         self.loading = True
    141         try:
    142             ok = sm.GetService('cosmeticsSvc').enable_ship_cosmetic_license(license=license, slotIndex=slotIndex, groupIndex=groupIndex, enable=enable)
    143             if ok:
    144                 self.isSelected = enable
    145                 sm.GetService('audio').SendUIEvent('fitting_window_emblem_select_play')
    146             else:
    147                 self._errorCallback()
    148         except RuntimeError:
    149             self._errorCallback()
    150         finally:
    151             self.loading = False
    152 
    153     def _ShowLoadingThread(self):
    154         blue.synchro.SleepSim(DELAY_BEFORE_SHOW_LOADING * 1000)
    155         self._ShowLoading()
    156 
    157     def _ClearLoadingThread(self):
    158         if self._showLoadingTasklet is not None:
    159             self._showLoadingTasklet.Kill()
    160             self._showLoadingTasklet = None
    161         if self._loadingTasklet is not None:
    162             self._loadingTasklet.Kill()
    163             self._loadingTasklet = None
    164 
    165     def _ShowLoading(self):
    166         animations.FadeTo(self.mainContainer, self.mainContainer.opacity, 0.1, duration=0.1)
    167         animations.FadeTo(self.loadingWheel, self.loadingWheel.opacity, 1.0, duration=0.05)
    168 
    169     def _HideLoading(self):
    170         animations.FadeTo(self.mainContainer, self.mainContainer.opacity, 1.0, duration=0.1)
    171         animations.FadeTo(self.loadingWheel, self.loadingWheel.opacity, 0.0, duration=0.05)
    172 
    173 
    174 class AllianceLogoEntry(LogoEntry):
    175     default_cosmeticsType = CosmeticsType.ALLIANCE_LOGO
    176     SLOT_INDEX = 1
    177 
    178     def UpdateDisplay(self):
    179         super(AllianceLogoEntry, self).UpdateDisplay()
    180         allianceID = session.allianceid
    181         self.display = True if allianceID and self.logoData.existence.alliance is not None else False
    182         if not allianceID or not self.logoData.existence.alliance:
    183             return
    184         self.logoIcon = GetLogoIcon(name='logoIcon', parent=self.logoContainer, align=uiconst.TOPLEFT, itemID=allianceID)
    185         self.logoIcon.width = LOGO_SIZE
    186         self.logoIcon.height = LOGO_SIZE
    187         self.descriptionLabel.text = GetByLabel('UI/ShipCosmetics/AllianceEmblem')
    188         self.nameLabel.text = cfg.eveowners.Get(session.allianceid).name
    189         if self.logoData.eligibility.alliance:
    190             self.isSelected = True if self.logoData.selection.alliance else False
    191             self.Enable()
    192         else:
    193             self.isSelected = False
    194             self.Disable()
    195 
    196     def IsEligible(self):
    197         return self.logoData and self.logoData.eligibility.alliance
    198 
    199     def OnClick(self, *args):
    200         super(AllianceLogoEntry, self).OnClick(*args)
    201         self._EnableLogo(self.logoData.eligibility.alliance, self.logoData.eligibility.alliance.slotGroup)
    202 
    203 
    204 class CorporationLogoEntry(LogoEntry):
    205     default_cosmeticsType = CosmeticsType.CORPORATION_LOGO
    206     SLOT_INDEX = 0
    207 
    208     def UpdateDisplay(self):
    209         super(CorporationLogoEntry, self).UpdateDisplay()
    210         self.display = self.logoData.existence.alliance is not None
    211         if not self.logoData.existence.alliance:
    212             return
    213         self.logoIcon = GetLogoIcon(name='logoIcon', itemID=session.corpid, parent=self.logoContainer, align=uiconst.TOPLEFT)
    214         self.logoIcon.width = LOGO_SIZE
    215         self.logoIcon.height = LOGO_SIZE
    216         self.descriptionLabel.text = GetByLabel('UI/ShipCosmetics/CorporationEmblem')
    217         self.nameLabel.text = cfg.eveowners.Get(session.corpid).name
    218         if self.logoData.eligibility.corporation:
    219             self.isSelected = True if self.logoData.selection.corporation else False
    220             self.Enable()
    221         else:
    222             self.isSelected = False
    223             self.Disable()
    224 
    225     def IsEligible(self):
    226         return self.logoData and self.logoData.eligibility.corporation
    227 
    228     def OnClick(self, *args):
    229         super(CorporationLogoEntry, self).OnClick(*args)
    230         self._EnableLogo(self.logoData.eligibility.corporation, self.logoData.eligibility.corporation.slotGroup)