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

window.py (10242B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\crate\window.py
      2 import carbonui.fontconst
      3 import localization
      4 import log
      5 import trinity
      6 import uthread
      7 from carbonui import const as uiconst
      8 from carbonui.text.styles import TextBody
      9 from carbonui.control.scrollContainer import ScrollContainer
     10 from carbonui.primitives.container import Container
     11 from carbonui.primitives.sprite import Sprite, StreamingVideoSprite
     12 from carbonui.primitives.transform import Transform
     13 from carbonui.uianimations import animations
     14 from carbonui.util import color
     15 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveStyleLabel
     16 from carbonui.control.window import Window
     17 from eve.client.script.ui.control.themeColored import FillThemeColored, FrameThemeColored, GradientThemeColored
     18 from eve.client.script.ui.crate.button import CrateButton
     19 from eve.client.script.ui.crate.controller import CreateController
     20 from eve.client.script.ui.crate.view import CreateView
     21 
     22 def getColorUIHighlight(alpha = 1.0):
     23     elementColor = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHT)
     24     return color.GetColor(elementColor, alpha=alpha)
     25 
     26 
     27 class CrateWindow(Window):
     28     __guid__ = 'form.CrateWindow'
     29     default_fixedWidth = 800
     30     default_fixedHeight = 420
     31     default_width = 800
     32     default_height = 420
     33     default_windowID = 'CrateWindow'
     34     default_clipChildren = False
     35     default_isCollapseable = False
     36     default_isLightBackgroundConfigurable = False
     37     default_isStackable = False
     38     default_isLockable = False
     39     default_isOverlayable = False
     40     default_isMinimizable = False
     41 
     42     @classmethod
     43     def Open(cls, *args, **kwargs):
     44         wnd = cls.GetIfOpen()
     45         if not wnd:
     46             return super(CrateWindow, cls).Open(*args, **kwargs)
     47         if not wnd.controller.isOpening:
     48             wnd.Close()
     49             return super(CrateWindow, cls).Open(*args, **kwargs)
     50         wnd.Maximize()
     51         return wnd
     52 
     53     def ApplyAttributes(self, attributes):
     54         super(CrateWindow, self).ApplyAttributes(attributes)
     55         typeID = attributes.typeID
     56         itemID = attributes.itemID
     57         stacksize = attributes.stacksize
     58         self.controller = CreateController(typeID, itemID, stacksize)
     59         self.view = None
     60         self.Layout()
     61         self.controller.onOpen.connect(self.OnCrateOpen)
     62         self.controller.onFinish.connect(self.Close)
     63         uthread.new(self.AnimEntry)
     64 
     65     def Layout(self):
     66         self.sr.headerParent.Hide()
     67         self.SetCaption(self.controller.caption)
     68         self.splash = Splash(parent=self.GetMainArea(), align=uiconst.CENTERLEFT, pos=(120, 0, 1, 1), controller=self.controller)
     69         CrateDetailView(parent=self.GetMainArea(), align=uiconst.TOALL, padding=(380, 36, 24, 24), controller=self.controller)
     70 
     71     def OnCrateOpen(self):
     72         if self.view:
     73             animations.FadeOut(self.view, duration=0.2, callback=self.view.Close)
     74         self.view = CreateView(parent=self.GetMainArea(), align=uiconst.TOALL, controller=self.controller, shouldAnimateView=True)
     75 
     76     def AnimEntry(self):
     77         self.splash.AnimEntry()
     78 
     79     def Prepare_Background_(self):
     80         self.sr.underlay = CrateWindowUnderlay(parent=self)
     81 
     82     def Close(self, *args, **kwargs):
     83         self.controller.Close()
     84         super(CrateWindow, self).Close(*args, **kwargs)
     85 
     86 
     87 class CrateWindowUnderlay(Container):
     88     default_state = uiconst.UI_DISABLED
     89 
     90     def ApplyAttributes(self, attributes):
     91         super(CrateWindowUnderlay, self).ApplyAttributes(attributes)
     92         self.frame = FrameThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, texturePath='res:/UI/Texture/classes/ItemPacks/windowFrame.png', cornerSize=10, fillCenter=False, opacity=0.5)
     93         self.outerGlow = FrameThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT, texturePath='res:/UI/Texture/classes/ItemPacks/boxGlow.png', cornerSize=5, offset=-2, opacity=0.0)
     94         self.underlay = GradientThemeColored(bgParent=self, padding=(1, 1, 1, 1), rgbData=[(0, (0.5, 0.5, 0.5))], alphaData=[(0, 0.0), (0.4, 0.9), (0.6, 1.0)], rotation=0)
     95         GradientThemeColored(parent=self, align=uiconst.TOTOP, height=1, alphaData=[(0, 0.0), (0.4, 0.08), (0.6, 0.1)], rotation=0, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW)
     96         GradientThemeColored(parent=self, align=uiconst.TOBOTTOM, height=1, alphaData=[(0, 0.0), (0.4, 0.08), (0.6, 0.1)], rotation=0, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW)
     97         FillThemeColored(parent=self, align=uiconst.TORIGHT, width=1, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.1)
     98 
     99     def AnimEntry(self):
    100         animations.FadeTo(self.frame, startVal=self.frame.opacity, endVal=1.0, duration=0.4, curveType=uiconst.ANIM_OVERSHOT3)
    101         animations.FadeTo(self.outerGlow, startVal=self.outerGlow.opacity, endVal=0.25, duration=0.4, curveType=uiconst.ANIM_OVERSHOT2)
    102         animations.FadeTo(self.underlay, startVal=self.underlay.opacity, endVal=1.0, duration=0.3, curveType=uiconst.ANIM_LINEAR)
    103 
    104     def AnimExit(self):
    105         animations.FadeTo(self.frame, startVal=self.frame.opacity, endVal=0.5, duration=0.6)
    106         animations.FadeTo(self.outerGlow, startVal=self.outerGlow.opacity, endVal=0.0, duration=0.6)
    107         animations.FadeTo(self.underlay, startVal=self.underlay.opacity, endVal=0.85, duration=0.3, curveType=uiconst.ANIM_LINEAR)
    108 
    109     def EnableLightBackground(self):
    110         pass
    111 
    112     def DisableLightBackground(self):
    113         pass
    114 
    115 
    116 class Splash(Container):
    117 
    118     def ApplyAttributes(self, attributes):
    119         super(Splash, self).ApplyAttributes(attributes)
    120         self.controller = attributes.controller
    121         self.flare = None
    122         self.Layout()
    123         self.controller.onOpen.connect(self.OnCrateOpen)
    124 
    125     def _NotifyOfFailedTextureLoad(self, sprite):
    126         trinity.WaitForResourceLoads()
    127         if not sprite.texture.atlasTexture or not sprite.texture.atlasTexture.IsGood():
    128             log.LogError('Failed to load crate static splash image from path:', sprite.texture.resPath)
    129 
    130     def Layout(self):
    131         if self.controller.staticSplash:
    132             staticSplashSprite = Sprite(parent=self, align=uiconst.TOPLEFT, left=-int(self.controller.staticSplash.width / 2.0), top=-int(self.controller.staticSplash.height / 2.0), texturePath=self.controller.staticSplash.resPath, width=self.controller.staticSplash.width, height=self.controller.staticSplash.height, color=self.controller.staticSplash.color or (1.0, 1.0, 1.0))
    133             uthread.new(self._NotifyOfFailedTextureLoad, staticSplashSprite)
    134         if self.controller.animatedSplash:
    135             try:
    136                 self.flare = StreamingVideoSprite(parent=self, align=uiconst.TOPLEFT, left=-int(self.controller.animatedSplash.width / 2.0), top=-int(self.controller.animatedSplash.height / 2.0), width=self.controller.animatedSplash.width, height=self.controller.animatedSplash.height, videoPath=self.controller.animatedSplash.resPath, videoLoop=True, blendMode=trinity.TR2_SBM_ADD, spriteEffect=trinity.TR2_SFX_COPY, color=self.controller.animatedSplash.color or getColorUIHighlight(), disableAudio=True)
    137             except RuntimeError:
    138                 log.LogError('Failed to load crate animated splash from path:', self.controller.animatedSplash.resPath)
    139 
    140     def AnimEntry(self):
    141         if self.flare:
    142             animations.FadeTo(self.flare, endVal=self.flare.opacity, duration=2.0)
    143 
    144     def OnCrateOpen(self):
    145         if self.flare:
    146             animations.FadeOut(self.flare)
    147 
    148 
    149 class CrateDetailView(Container):
    150 
    151     def ApplyAttributes(self, attributes):
    152         super(CrateDetailView, self).ApplyAttributes(attributes)
    153         self.controller = attributes.controller
    154         self.Layout()
    155         self.controller.onOpen.connect(self.OnCrateOpenedOrSkipped)
    156         self.controller.onSkip.connect(self.OnCrateOpenedOrSkipped)
    157 
    158     def _ConstructTitle(self):
    159         self.title = Transform(parent=self, align=uiconst.TOTOP, height=40, width=400)
    160         titleLabelWidth, titleLabelHeight = TitleLabel.MeasureTextSize(self.controller.caption)
    161         titleLabelClass = TitleLabel
    162         if titleLabelHeight > self.title.height or titleLabelWidth > self.title.width:
    163             titleLabelClass = SmallerTitleLabel
    164         titleLabel = titleLabelClass(parent=self.title, align=uiconst.TOPLEFT, padBottom=12, width=420, text=self.controller.caption)
    165         self.title.height = titleLabel.height
    166 
    167     def Layout(self):
    168         buttonCont = Container(parent=self, align=uiconst.TOBOTTOM, height=30)
    169         self._ConstructTitle()
    170         self.textScroll = ScrollContainer(parent=self, align=uiconst.TOTOP, padBottom=8, height=400)
    171         TextBody(parent=self.textScroll, align=uiconst.TOTOP, text=self.controller.description)
    172         self.button = CrateButton(parent=buttonCont, align=uiconst.CENTER, label=localization.GetByLabel('UI/Crate/InitHacking'), func=self.OpenCrate)
    173 
    174     def OpenCrate(self, button):
    175         button.disabled = True
    176         try:
    177             self.controller.OpenCrate()
    178         except Exception:
    179             button.disabled = False
    180             log.LogException()
    181 
    182     def OnCrateOpenedOrSkipped(self):
    183         self.Disable()
    184         self.controller.onOpen.disconnect(self.OnCrateOpenedOrSkipped)
    185         self.controller.onSkip.disconnect(self.OnCrateOpenedOrSkipped)
    186         animations.MorphScalar(self.title, 'top', endVal=-24, timeOffset=0.25)
    187         animations.MorphVector2(self.title, 'scale', startVal=(1.0, 1.0), endVal=(0.8, 0.8), timeOffset=0.25)
    188         animations.FadeOut(self.textScroll, duration=0.5)
    189         animations.FadeOut(self.button, duration=0.5)
    190 
    191 
    192 class TitleLabel(EveStyleLabel):
    193     default_fontsize = 30
    194     default_bold = True
    195     default_fontStyle = carbonui.fontconst.STYLE_HEADER
    196     default_shadowOffset = (0, 1)
    197 
    198 
    199 class SmallerTitleLabel(EveStyleLabel):
    200     default_fontsize = 20
    201     default_bold = True
    202     default_fontStyle = carbonui.fontconst.STYLE_HEADER
    203     default_shadowOffset = (0, 1)
    204 
    205 
    206 def center(text):
    207     return u'<center>{}</center>'.format(text)
    208 
    209 
    210 def __SakeReloadHook():
    211     try:
    212         instance = CrateWindow.GetIfOpen()
    213         if instance:
    214             CrateWindow.Reload(instance)
    215     except Exception:
    216         log.LogException()