ini
This commit is contained in:
65
Scenes/FlaskContent.cs
Executable file
65
Scenes/FlaskContent.cs
Executable file
@@ -0,0 +1,65 @@
|
||||
using Godot;
|
||||
using Mathool.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;
|
||||
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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user