Demo Finish

This commit is contained in:
h z
2024-06-27 04:16:35 +08:00
parent b8af5f3ccd
commit 8703f92b4e
8 changed files with 75 additions and 30 deletions

View File

@@ -82,8 +82,6 @@ public partial class Bottle : MenuButton, IChemicalContainer
m.Volume = m.FreeVolume; m.Volume = m.FreeVolume;
GlobalScene.Flask.Content.AddLayer(m); GlobalScene.Flask.Content.AddLayer(m);
} }
//GlobalScene.Flask.Content = Content;
//Content.Container = GlobalScene.Flask;
Content = HeterogeneousMixture.Null; Content = HeterogeneousMixture.Null;
GlobalScene.Flask.Update(); GlobalScene.Flask.Update();
break; break;

View File

@@ -1,9 +1,7 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Godot; using Godot;
using VirtualChemDemo;
using VirtualChemDemo.Concepts; using VirtualChemDemo.Concepts;
using VirtualChemistry.Chemistry.Atoms.Implements; using VirtualChemistry.Chemistry.Atoms.Implements;
using VirtualChemistry.Chemistry.Atoms.Resolver; using VirtualChemistry.Chemistry.Atoms.Resolver;
@@ -19,13 +17,14 @@ public partial class CompoundConstructor : Panel
public BaseBond ConnectPending { get; set; } = BaseBond.Null; public BaseBond ConnectPending { get; set; } = BaseBond.Null;
public Atom PendingAtom { get; set; } public Atom PendingAtom { get; set; }
public Dictionary<Atom, HashSet<Bond2D>> BondMap { get; set; } = new(); public Dictionary<Atom, HashSet<Bond2D>> 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() public override void _Ready()
{ {
GlobalScene.CompoundConstructor = this; GlobalScene.CompoundConstructor = this;
HeterogeneousMixture = new(); HeterogeneousMixture = new();
HomogeneousMixture = HeterogeneousMixture.AddLayer(); HomogeneousMixture = HeterogeneousMixture.AddLayer();
PanelViewer = GetNode<Viewer>("Viewer");
} }
private static class AtomPositionFixMemory private static class AtomPositionFixMemory
@@ -214,4 +213,5 @@ public partial class CompoundConstructor : Panel
} }
private void ForceClear() => Clear(false); private void ForceClear() => Clear(false);
private void BackToCenter() => PanelViewer.BackToCenter();
} }

View File

@@ -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/CompoundConstructor.cs" id="1_bhwhs"]
[ext_resource type="Script" path="res://Scenes/AddAtom.cs" id="2_ddlyc"] [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"] [node name="CompoundConstructor" type="Panel"]
offset_left = -370.0 offset_left = -370.0
@@ -14,9 +16,9 @@ script = ExtResource("1_bhwhs")
[node name="Controller" type="HBoxContainer" parent="ControlLayer"] [node name="Controller" type="HBoxContainer" parent="ControlLayer"]
offset_left = 57.0 offset_left = 57.0
offset_top = 588.0 offset_top = 572.0
offset_right = 877.0 offset_right = 877.0
offset_bottom = 632.0 offset_bottom = 649.0
[node name="AddAtom" type="MenuButton" parent="ControlLayer/Controller"] [node name="AddAtom" type="MenuButton" parent="ControlLayer/Controller"]
layout_mode = 2 layout_mode = 2
@@ -36,6 +38,20 @@ text = "Clear"
layout_mode = 2 layout_mode = 2
text = "Back" 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/BuildMixture" to="." method="Build"]
[connection signal="pressed" from="ControlLayer/Controller/Clear" to="." method="ForceClear"] [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/Back" to="." method="Back"]
[connection signal="pressed" from="ControlLayer/Controller/BackToOrigin" to="." method="BackToCenter"]

View File

@@ -1,4 +1,3 @@
using System;
using Godot; using Godot;
using Skeleton.DataStructure.Link; using Skeleton.DataStructure.Link;
using VirtualChemistry.Chemistry.Mixtures.Implements; using VirtualChemistry.Chemistry.Mixtures.Implements;
@@ -37,17 +36,6 @@ public partial class FlaskContent : ColorRect
Mixture.ColorGreen, Mixture.ColorGreen,
Mixture.ColorTransparent 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. // 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) public override void _Process(double delta)
{ {
} }
private void OnSizeChange() => Mask.Size = Size; private void OnSizeChange() => Mask.Size = Size;
private void OnMouseEnter() => AP.Play("MouseEntered"); private void OnMouseEnter() => AP.Play("MouseEntered");
private void OnMouseExit() => AP.PlayBackwards("MouseEntered"); private void OnMouseExit() => AP.PlayBackwards("MouseEntered");
private void OnClick() => GlobalScene.MainControlPanel.Update(Mixture);
private void OnClick()
{
GlobalScene.MainControlPanel.Update(Mixture);
}
} }

View File

@@ -57,12 +57,14 @@ public partial class MainControlPanel : HBoxContainer
{ {
Compounds.Clear(); Compounds.Clear();
TreeItem root = Compounds.CreateItem(); 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; int i = 1;
foreach (HomogeneousMixture h in GlobalScene.Flask.Content.LayerOrder) foreach (HomogeneousMixture h in GlobalScene.Flask.Content.LayerOrder)
{ {
TreeItem sRoot = Compounds.CreateItem(root); TreeItem sRoot = Compounds.CreateItem(root);
sRoot.SetText(0,$"Mixture{i} Amt{h.Amount}"); sRoot.SetText(0,$"Mixture{i} Amt{h.Amount}");
sRoot.SetMeta("isoExp", h.Dump());
foreach (var group in h.Compounds.GroupBy(x => x.Expression)) foreach (var group in h.Compounds.GroupBy(x => x.Expression))
{ {
TreeItem t = Compounds.CreateItem(root); TreeItem t = Compounds.CreateItem(root);

24
Scenes/Viewer.cs Normal file
View File

@@ -0,0 +1,24 @@
using Godot;
public partial class Viewer : Node2D
{
private Vector2 Origin => GetParent<CompoundConstructor>().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>("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;
}

24
Scenes/ViewerCamera.cs Normal file
View File

@@ -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);
}
}

View File

@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.3.0-beta.1"> <Project Sdk="Godot.NET.Sdk/4.3.0-beta.2">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework> <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>