ini
This commit is contained in:
66
Scenes/AtomActions.cs
Executable file
66
Scenes/AtomActions.cs
Executable file
@@ -0,0 +1,66 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using VirtualChemistry.Chemistry.Bonds.Implements;
|
||||
|
||||
public partial class AtomActions : MenuButton
|
||||
{
|
||||
|
||||
public Atom Atom => GetParent<Atom>();
|
||||
private Dictionary<int, BaseBond> BondMap { get; set; } = new();
|
||||
private CompoundConstructor CompoundConstructor => GlobalScene.CompoundConstructor;
|
||||
public void BuildMenu()
|
||||
{
|
||||
PopupMenu menu = GetPopup();
|
||||
menu.Clear();
|
||||
foreach (var w in menu.GetSignalConnectionList(PopupMenu.SignalName.IdPressed))
|
||||
menu.Disconnect(PopupMenu.SignalName.IdPressed, w["callable"].AsCallable());
|
||||
menu.AddItem("Remove Atom", 0);
|
||||
int idx = 1;
|
||||
BondMap.Clear();
|
||||
foreach (BaseBond b in Atom.BaseAtom.UnconnectedBonds)
|
||||
{
|
||||
BondMap[idx] = b;
|
||||
menu.AddItem(b.BondType, idx);
|
||||
if(CompoundConstructor.ConnectPending == b)
|
||||
menu.SetItemDisabled(idx, true);
|
||||
idx++;
|
||||
}
|
||||
menu.Connect(PopupMenu.SignalName.IdPressed, Callable.From((int id) => MenuHandle(id)));
|
||||
}
|
||||
|
||||
private void MenuHandle(int idx)
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
CompoundConstructor.RemoveAtomOf(Atom);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CompoundConstructor.ConnectPending == BaseBond.Null)
|
||||
{
|
||||
CompoundConstructor.ConnectPending = BondMap[idx];
|
||||
CompoundConstructor.PendingAtom = Atom;
|
||||
}
|
||||
else
|
||||
{
|
||||
CompoundConstructor.ConnectAtoms(Atom, BondMap[idx]);
|
||||
}
|
||||
BuildMenu();
|
||||
}
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
BuildMenu();
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public override Variant _GetDragData(Vector2 atPosition)
|
||||
{
|
||||
return GetParent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user