diff --git a/Scenes/Bottle.cs b/Scenes/Bottle.cs index cc7186a..ffd491c 100755 --- a/Scenes/Bottle.cs +++ b/Scenes/Bottle.cs @@ -82,8 +82,6 @@ public partial class Bottle : MenuButton, IChemicalContainer m.Volume = m.FreeVolume; GlobalScene.Flask.Content.AddLayer(m); } - //GlobalScene.Flask.Content = Content; - //Content.Container = GlobalScene.Flask; Content = HeterogeneousMixture.Null; GlobalScene.Flask.Update(); break; diff --git a/Scenes/CompoundConstructor.cs b/Scenes/CompoundConstructor.cs index 5661743..1b2d73f 100755 --- a/Scenes/CompoundConstructor.cs +++ b/Scenes/CompoundConstructor.cs @@ -1,9 +1,7 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using Godot; -using VirtualChemDemo; using VirtualChemDemo.Concepts; using VirtualChemistry.Chemistry.Atoms.Implements; using VirtualChemistry.Chemistry.Atoms.Resolver; @@ -19,13 +17,14 @@ public partial class CompoundConstructor : Panel public BaseBond ConnectPending { get; set; } = BaseBond.Null; public Atom PendingAtom { get; set; } public Dictionary> BondMap { get; set; } = new(); + private Viewer PanelViewer { get; set; } - // Called when the node enters the scene tree for the first time. public override void _Ready() { GlobalScene.CompoundConstructor = this; HeterogeneousMixture = new(); HomogeneousMixture = HeterogeneousMixture.AddLayer(); + PanelViewer = GetNode("Viewer"); } private static class AtomPositionFixMemory @@ -214,4 +213,5 @@ public partial class CompoundConstructor : Panel } private void ForceClear() => Clear(false); + private void BackToCenter() => PanelViewer.BackToCenter(); } diff --git a/Scenes/CompoundConstructor.tscn b/Scenes/CompoundConstructor.tscn index d19d08b..db1e9b0 100644 --- a/Scenes/CompoundConstructor.tscn +++ b/Scenes/CompoundConstructor.tscn @@ -1,7 +1,9 @@ -[gd_scene load_steps=3 format=3 uid="uid://c1ww4cmceq16t"] +[gd_scene load_steps=5 format=3 uid="uid://c1ww4cmceq16t"] [ext_resource type="Script" path="res://Scenes/CompoundConstructor.cs" id="1_bhwhs"] [ext_resource type="Script" path="res://Scenes/AddAtom.cs" id="2_ddlyc"] +[ext_resource type="Script" path="res://Scenes/Viewer.cs" id="3_4yky0"] +[ext_resource type="Script" path="res://Scenes/ViewerCamera.cs" id="4_1i4tm"] [node name="CompoundConstructor" type="Panel"] offset_left = -370.0 @@ -14,9 +16,9 @@ script = ExtResource("1_bhwhs") [node name="Controller" type="HBoxContainer" parent="ControlLayer"] offset_left = 57.0 -offset_top = 588.0 +offset_top = 572.0 offset_right = 877.0 -offset_bottom = 632.0 +offset_bottom = 649.0 [node name="AddAtom" type="MenuButton" parent="ControlLayer/Controller"] layout_mode = 2 @@ -36,6 +38,20 @@ text = "Clear" layout_mode = 2 text = "Back" +[node name="BackToOrigin" type="Button" parent="ControlLayer/Controller"] +layout_mode = 2 +text = "\\/ +>o< +^" + +[node name="Viewer" type="Node2D" parent="."] +position = Vector2(946, 506) +script = ExtResource("3_4yky0") + +[node name="ViewerCamera" type="Camera2D" parent="Viewer"] +script = ExtResource("4_1i4tm") + [connection signal="pressed" from="ControlLayer/Controller/BuildMixture" to="." method="Build"] [connection signal="pressed" from="ControlLayer/Controller/Clear" to="." method="ForceClear"] [connection signal="pressed" from="ControlLayer/Controller/Back" to="." method="Back"] +[connection signal="pressed" from="ControlLayer/Controller/BackToOrigin" to="." method="BackToCenter"] diff --git a/Scenes/FlaskContent.cs b/Scenes/FlaskContent.cs index 14c6c1f..243bc69 100755 --- a/Scenes/FlaskContent.cs +++ b/Scenes/FlaskContent.cs @@ -1,4 +1,3 @@ -using System; using Godot; using Skeleton.DataStructure.Link; using VirtualChemistry.Chemistry.Mixtures.Implements; @@ -37,17 +36,6 @@ public partial class FlaskContent : ColorRect 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, 512-(float)(StartFrom + height))); - 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. @@ -62,15 +50,8 @@ public partial class FlaskContent : ColorRect 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); - } + private void OnClick() => GlobalScene.MainControlPanel.Update(Mixture); } diff --git a/Scenes/MainControlPanel.cs b/Scenes/MainControlPanel.cs index 499d043..87679c2 100644 --- a/Scenes/MainControlPanel.cs +++ b/Scenes/MainControlPanel.cs @@ -57,12 +57,14 @@ public partial class MainControlPanel : HBoxContainer { Compounds.Clear(); TreeItem root = Compounds.CreateItem(); - root.SetText(0, "Mixtures: "); + root.SetText(0, $"Mixtures({GlobalScene.Flask.Content.Layers.Count}): "); + root.SetMeta("isoExp", GlobalScene.Flask.Content.Dump()); int i = 1; foreach (HomogeneousMixture h in GlobalScene.Flask.Content.LayerOrder) { TreeItem sRoot = Compounds.CreateItem(root); sRoot.SetText(0,$"Mixture{i} Amt{h.Amount}"); + sRoot.SetMeta("isoExp", h.Dump()); foreach (var group in h.Compounds.GroupBy(x => x.Expression)) { TreeItem t = Compounds.CreateItem(root); diff --git a/Scenes/Viewer.cs b/Scenes/Viewer.cs new file mode 100644 index 0000000..9c63371 --- /dev/null +++ b/Scenes/Viewer.cs @@ -0,0 +1,24 @@ +using Godot; +public partial class Viewer : Node2D +{ + private Vector2 Origin => GetParent().Size / 2; + + public ViewerCamera ViewerCamera { get; private set; } + + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + ViewerCamera = GetNode("ViewerCamera"); + base._Ready(); + } + + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseMotion em) + if (em.ButtonMask == MouseButtonMask.Middle) + Position -= em.Relative; + base._Input(@event); + } + + public void BackToCenter() => Position = Origin; +} diff --git a/Scenes/ViewerCamera.cs b/Scenes/ViewerCamera.cs new file mode 100644 index 0000000..23a1cf8 --- /dev/null +++ b/Scenes/ViewerCamera.cs @@ -0,0 +1,24 @@ +using Godot; + +public partial class ViewerCamera : Camera2D +{ + private static readonly Vector2 ZoomMin = new(0.02001f, 0.02001f); + + private static readonly Vector2 ZoomMax = new(4f, 4f); + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseButton eb) + { + if (eb.IsPressed()) + { + if (eb.ButtonIndex == MouseButton.WheelDown) + if (Zoom.X > ZoomMin.X && Zoom.Y > ZoomMin.Y) + Zoom -= new Vector2(0.01f, 0.01f); + if(eb.ButtonIndex == MouseButton.WheelUp) + if (Zoom.X < ZoomMax.X && Zoom.Y < ZoomMax.Y) + Zoom += new Vector2(0.01f, 0.01f); + } + } + base._Input(@event); + } +} diff --git a/VirtualChemDemo.csproj b/VirtualChemDemo.csproj index eeaa336..4695850 100755 --- a/VirtualChemDemo.csproj +++ b/VirtualChemDemo.csproj @@ -1,4 +1,4 @@ - + net6.0 net7.0