Files
VirtualChemistry.Demo/Scenes/FlaskContent.cs
2024-06-24 07:27:50 +08:00

78 lines
2.2 KiB
C#
Executable File

using System;
using Godot;
using Skeleton.DataStructure.Link;
using VirtualChemistry.Chemistry.Mixtures.Implements;
public partial class FlaskContent : ColorRect
{
public HomogeneousMixture Mixture { get; set; } = HomogeneousMixture.Null;
private const double ContainerHeight = 512d;
public double ContainerVolume => Mixture.HeterogeneousMixture.Container.Volume();
public double Volume => Mixture.Volume;
private TextureButton Mask { get; set; }
public double VolumeStartFrom {
get
{
double res = 0;
for (LinkNode<HomogeneousMixture> iter = Mixture.Layer.Previous; !iter.IsEnding; iter = iter.Previous)
res += iter.Value.Volume;
return res;
}
}
private ColorRect Bar { get; set; }
private AnimationPlayer AP { get; set; }
public double StartFrom => (VolumeStartFrom / ContainerVolume) * ContainerHeight;
public void UpdateVolumeAndPosition()
{
double height = (Volume / ContainerVolume) * ContainerHeight;
Position = new Vector2(Position.X, 512-(float)(StartFrom + height));
Size = new Vector2(Size.X, (float)height);
//Mask.Size = Size;
Color = Color.Color8(
Mixture.ColorRed,
Mixture.ColorGreen,
Mixture.ColorGreen,
Mixture.ColorTransparent
);
/*
Animation a = AP.GetAnimation("HeightChange");
a.TrackSetKeyValue(0, 0, Size);
a.TrackSetKeyValue(0, 1, new Vector2(Size.X, (float)height));
AP.Play("HeightChange");
AP.Play("PositionChange");
a = AP.GetAnimation("PositionChange");
a.TrackSetKeyValue(0,0,Position);
a.TrackSetKeyValue(0,1, new Vector2(Position.X, -(float)StartFrom));
Color = Color.Color8(Mixture.ColorRed, Mixture.ColorGreen, Mixture.ColorGreen, Mixture.ColorTransparent);
AP.Play();*/
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Bar = GetNode<ColorRect>("Bar");
AP = GetNode<AnimationPlayer>("AP");
Mask = GetNode<TextureButton>("Mask");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void OnSizeChange() => Mask.Size = Size;
private void OnMouseEnter() => AP.Play("MouseEntered");
private void OnMouseExit() => AP.PlayBackwards("MouseEntered");
private void OnClick()
{
GlobalScene.MainControlPanel.Update(Mixture);
}
}