using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using Barotrauma;
using Microsoft.Xna.Framework;
namespace QICrabUI
{
///
/// WIP, can animate any property on any object
/// Can run back and forth in [0..1] interval and
/// interpolate any property between StartValue and EndValue
///
public class CUIAnimation
{
internal static void InitStatic()
{
CUI.OnDispose += () => ActiveAnimations.Clear();
}
public static HashSet ActiveAnimations = new();
///
/// This is called in CUIUpdate
///
internal static void UpdateAllAnimations(double time)
{
foreach (CUIAnimation animation in ActiveAnimations)
{
animation.Step(time);
}
}
public bool Debug { get; set; }
public static float StartLambda = 0.0f;
public static float EndLambda = 1.0f;
private object target;
///
/// Object containing animated property
///
public object Target
{
get => target;
set
{
target = value;
UpdateSetter();
}
}
private bool active;
public bool Active
{
get => active;
set
{
if (Blocked || active == value) return;
active = value;
if (active) ActiveAnimations.Add(this);
else ActiveAnimations.Remove(this);
ApplyValue();
}
}
///
/// In seconds
///
public double Duration
{
get => 1.0 / Speed * Timing.Step;
set
{
double steps = value / Timing.Step;
Speed = 1.0 / steps;
}
}
public double ReverseDuration
{
get => 1.0 / (BackSpeed ?? 0) * Timing.Step;
set
{
double steps = value / Timing.Step;
BackSpeed = 1.0 / steps;
}
}
///
/// Will prevent it from starting
///
public bool Blocked { get; set; }
///
/// Progress of animation [0..1]
///
public double Lambda { get; set; }
///
/// Lambda increase per update step, calculated when you set Duration
///
public double Speed { get; set; } = 0.01;
public double? BackSpeed { get; set; }
///
/// If true animation won't stop when reaching end, it will change direction
///
public bool Bounce { get; set; }
///
/// Straight, Reverse
///
public CUIDirection Direction { get; set; }
///
/// Value will be interpolated between these values
///
public object StartValue { get; set; }
public object EndValue { get; set; }
private string property;
private Action