mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
generalize and simplify animation
This commit is contained in:
75
osu.Game/Graphics/Sprites/HueAnimation.cs
Normal file
75
osu.Game/Graphics/Sprites/HueAnimation.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.OpenGL.Vertices;
|
||||
using osu.Framework.Graphics.Shaders;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics.Sprites
|
||||
{
|
||||
public class HueAnimation : Sprite
|
||||
{
|
||||
public HueAnimation()
|
||||
{
|
||||
Size = new Vector2(960);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ShaderManager shaders, TextureStore textures)
|
||||
{
|
||||
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, @"HueAnimation");
|
||||
RoundedTextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, @"HueAnimation"); // Masking isn't supported for now
|
||||
}
|
||||
|
||||
private float animationProgress;
|
||||
|
||||
public float AnimationProgress
|
||||
{
|
||||
get => animationProgress;
|
||||
set
|
||||
{
|
||||
if (animationProgress == value) return;
|
||||
|
||||
animationProgress = value;
|
||||
Invalidate(Invalidation.DrawInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsPresent => true;
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new HueAnimationDrawNode(this);
|
||||
|
||||
private class HueAnimationDrawNode : SpriteDrawNode
|
||||
{
|
||||
protected new HueAnimation Source => (HueAnimation)base.Source;
|
||||
|
||||
private float progress;
|
||||
|
||||
public HueAnimationDrawNode(HueAnimation source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
progress = Source.animationProgress;
|
||||
}
|
||||
|
||||
protected override void Blit(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
Shader.GetUniform<float>("progress").UpdateValue(ref progress);
|
||||
|
||||
base.Blit(vertexAction);
|
||||
}
|
||||
|
||||
protected override bool CanDrawOpaqueInterior => false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user