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

blurredSceneUnderlay.py (7513B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\decorative\blurredSceneUnderlay.py
      2 import mathext
      3 import telemetry
      4 import trinity
      5 from carbonui import uiconst
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.uicore import uicore
      8 from carbonui.util.various_unsorted import GetWindowAbove
      9 from carbonui.window.settings import only_tint_active_window
     10 from chroma import Color
     11 from eve.client.script.ui import eveThemeColor
     12 from eve.client.script.ui.services.uiColorSettings import show_window_bg_blur_setting, window_transparency_light_mode_setting, window_transparency_noblur_setting, window_transparency_setting
     13 from eve.client.script.ui.shared.systemMenu.theme.feature_flag import is_only_tint_active_window_setting_enabled
     14 from evegraphics import settings as gfxsettings
     15 BRIGHTNESS_IDLE = 0.3
     16 BRIGHTNESS_IN_FOCUS = 0.2
     17 BRIGHTNESS_LIGHT_IDLE = 0.85
     18 BRIGHTNESS_LIGHT_IN_FOCUS = 0.5
     19 DEFAULT_BRIGHTNESS = 0.04
     20 SATURATION_MULTIPLIER_MAX = 0.3
     21 
     22 class BlurredSceneUnderlay(Sprite):
     23     default_name = 'BlurredSceneUnderlay'
     24     default_color = (DEFAULT_BRIGHTNESS,
     25      DEFAULT_BRIGHTNESS,
     26      DEFAULT_BRIGHTNESS,
     27      1.0)
     28     default_effectOpacity = 0.5
     29     default_saturation = 0.5
     30     default_opacity = 1.0
     31     default_state = uiconst.UI_DISABLED
     32     default_spriteEffect = trinity.TR2_SFX_BLURBACKGROUNDCOLORED
     33     default_isLightBackground = False
     34     __notifyevents__ = ['OnBlurredBufferCreated', 'OnGraphicSettingsChanged', 'OnUIColorsChanged']
     35 
     36     def OnColorThemeChanged(self):
     37         super(BlurredSceneUnderlay, self).OnColorThemeChanged()
     38         self.UpdateColor()
     39 
     40     @telemetry.ZONE_METHOD
     41     def ApplyAttributes(self, attributes):
     42         super(BlurredSceneUnderlay, self).ApplyAttributes(attributes)
     43         sm.RegisterNotify(self)
     44         isWindowActive = uicore.registry.GetActive() == GetWindowAbove(self)
     45         self.isInFocus = attributes.Get('isInFocus', isWindowActive)
     46         self.isLightBackground = attributes.Get('isLightBackground', self.default_isLightBackground)
     47         self.isCameraDragging = False
     48         if uicore.uilib.blurredBackBufferAtlas:
     49             self.texture.atlasTexture = uicore.uilib.blurredBackBufferAtlas
     50         trinity.device.RegisterResource(self)
     51         self.UpdateState(animate=False)
     52         window_transparency_light_mode_setting.on_change.connect(self.OnLightBackgroundTransparencySettingChanged)
     53         if is_only_tint_active_window_setting_enabled():
     54             only_tint_active_window.on_change.connect(self._on_only_tint_active_window_changed)
     55 
     56     def OnCreate(self, *args):
     57         pass
     58 
     59     def OnLightBackgroundTransparencySettingChanged(self, *args):
     60         self.UpdateState()
     61 
     62     def OnGraphicSettingsChanged(self, *args):
     63         self.UpdateState()
     64 
     65     def OnUIColorsChanged(self, *args):
     66         self.UpdateState()
     67 
     68     def OnWindowAboveSetActive(self):
     69         self.AnimEntry()
     70 
     71     def OnWindowAboveSetInactive(self):
     72         self.AnimExit()
     73 
     74     def OnBlurredBufferCreated(self, *args):
     75         if not self.destroyed:
     76             self.texture.atlasTexture = uicore.uilib.blurredBackBufferAtlas
     77 
     78     def AnimateEffectTo(self, value):
     79         uicore.animations.MorphScalar(self, 'effectOpacity', self.effectOpacity, value, curveType=uiconst.ANIM_LINEAR, duration=0.3)
     80 
     81     def AnimateBrightnessTo(self, value):
     82         uicore.animations.MorphScalar(self, 'saturation', self.saturation, value, curveType=uiconst.ANIM_LINEAR, duration=0.3)
     83 
     84     def AnimateOpacityTo(self, value, duration = 0.3, timeOffset = 0.0, callback = None):
     85         uicore.animations.FadeTo(self, self.opacity, value, curveType=uiconst.ANIM_LINEAR, duration=duration, timeOffset=timeOffset, callback=callback)
     86 
     87     def AnimEntry(self):
     88         self.isInFocus = True
     89         self.UpdateState()
     90 
     91     def AnimExit(self):
     92         self.isInFocus = False
     93         self.UpdateState()
     94 
     95     def GetTransparencySetting(self):
     96         if show_window_bg_blur_setting.is_enabled():
     97             return window_transparency_setting.get()
     98         else:
     99             return window_transparency_noblur_setting.get()
    100 
    101     def UpdateStateBlurEnabled(self, animate = True):
    102         self._GetSpriteEffect()
    103         effectOpacity = self._GetEffectOpacity()
    104         brightness = self._GetBrightness()
    105         if animate:
    106             self.AnimateEffectTo(effectOpacity)
    107             self.AnimateBrightnessTo(brightness)
    108         else:
    109             self.effectOpacity = effectOpacity
    110             self.saturation = brightness
    111 
    112     def GetOpacityValue(self):
    113         return self.default_opacity
    114 
    115     def _GetSpriteEffect(self):
    116         self.spriteEffect = trinity.TR2_SFX_BLURBACKGROUND
    117 
    118     def _GetBrightness(self):
    119         brightness = BRIGHTNESS_IN_FOCUS if self.isInFocus else BRIGHTNESS_IDLE
    120         brightness = mathext.lerp(0.0, brightness, self.GetTransparencySetting())
    121         if self.IsLightBackground():
    122             lBrightness = BRIGHTNESS_LIGHT_IN_FOCUS if self.isInFocus else BRIGHTNESS_LIGHT_IDLE
    123             brightness = mathext.lerp(brightness, lBrightness, window_transparency_light_mode_setting.get())
    124         return brightness
    125 
    126     def _GetEffectOpacity(self):
    127         if self.isInFocus:
    128             effectOpacity = 1.2
    129         elif self.IsLightBackground():
    130             effectOpacity = 1.0
    131         else:
    132             effectOpacity = 0.75
    133         return effectOpacity
    134 
    135     def UpdateStateBlurDisabled(self, animate = True):
    136         opacity = self._GetBlurDisabledOpacity()
    137         if animate:
    138             self.AnimateOpacityTo(opacity)
    139         else:
    140             self.opacity = opacity
    141         self.spriteEffect = trinity.TR2_SFX_FILL
    142 
    143     def _GetBlurDisabledOpacity(self):
    144         opacity = 0.95 if self.isInFocus else 0.75
    145         opacity = mathext.lerp(1.0, opacity, self.GetTransparencySetting())
    146         if self.IsLightBackground():
    147             lOpacity = 0.7 if self.isInFocus else 0.3
    148             opacity = mathext.lerp(opacity, lOpacity, window_transparency_light_mode_setting.get())
    149         return opacity
    150 
    151     @telemetry.ZONE_METHOD
    152     def UpdateState(self, animate = True):
    153         if self._IsBlurEnabled():
    154             self.UpdateStateBlurEnabled(animate)
    155         else:
    156             self.UpdateStateBlurDisabled(animate)
    157         self.UpdateColor()
    158 
    159     def _IsBlurEnabled(self):
    160         gfxQualitySupportsBlur = gfxsettings.Get(gfxsettings.GFX_SHADER_QUALITY) > gfxsettings.SHADER_MODEL_LOW
    161         return gfxQualitySupportsBlur and show_window_bg_blur_setting.is_enabled()
    162 
    163     def UpdateColor(self):
    164         if is_only_tint_active_window_setting_enabled() and only_tint_active_window.is_enabled():
    165             base_color = Color.from_rgba(*(eveThemeColor.THEME_TINT if self.isInFocus else self.default_color))
    166         else:
    167             base_color = Color.from_rgba(*eveThemeColor.THEME_TINT)
    168         t = self.GetTransparencySetting() if self._IsBlurEnabled() else 0.0
    169         s = SATURATION_MULTIPLIER_MAX + (1.0 - SATURATION_MULTIPLIER_MAX) * t
    170         final_color = Color.from_hsb(h=base_color.hue, s=base_color.saturation * s, b=base_color.brightness)
    171         self.SetRGB(*final_color.rgb)
    172 
    173     def IsLightBackground(self):
    174         return self.isLightBackground
    175 
    176     def EnableLightBackground(self, animate = True):
    177         self.isLightBackground = True
    178         self.UpdateState(animate)
    179 
    180     def DisableLightBackground(self, animate = True):
    181         self.isLightBackground = False
    182         self.UpdateState(animate)
    183 
    184     def _on_only_tint_active_window_changed(self, value):
    185         self.UpdateColor()