using Godot; using VirtualChemistry.Constants; public partial class AddAtom : MenuButton { public CompoundConstructor CompoundConstructor => GlobalScene.CompoundConstructor; private void BuildMenu() { PopupMenu menu = GetPopup(); menu.Clear(); foreach (var w in menu.GetSignalConnectionList(PopupMenu.SignalName.IdPressed)) menu.Disconnect(PopupMenu.SignalName.IdPressed, w["callable"].AsCallable()); for (int i = 1; i <= 15; i++) menu.AddItem(ChemistryConstant.ElementSymbols[i-1], i); menu.Connect(PopupMenu.SignalName.IdPressed, Callable.From((int idx) => MenuHandle(idx))); } private void MenuHandle(int idx) => CompoundConstructor.AddAtomOf(idx); // 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) { } }