From a429b0c0149739aa7c16c45382d66a4cda887ff7 Mon Sep 17 00:00:00 2001 From: Kashnox Date: Sat, 23 Sep 2023 16:47:44 -0400 Subject: [PATCH 01/19] Added the framework for changing and seeing the reproduction order of early multicellular species. --- Thrive.csproj | 3 +- .../CellBodyPlanEditorComponent.Callbacks.cs | 4 + .../editor/CellBodyPlanEditorComponent.cs | 60 +++++++++ .../editor/CellBodyPlanEditorComponent.tscn | 28 +++- .../editor/ReproductionOrder.cs | 95 ++++++++++++++ .../editor/ReproductionOrder.tscn | 121 ++++++++++++++++++ src/general/HexLayout.cs | 11 ++ 7 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 src/early_multicellular_stage/editor/ReproductionOrder.cs create mode 100644 src/early_multicellular_stage/editor/ReproductionOrder.tscn diff --git a/Thrive.csproj b/Thrive.csproj index d4addfcbc57..8d3af84b576 100644 --- a/Thrive.csproj +++ b/Thrive.csproj @@ -116,6 +116,7 @@ + @@ -839,4 +840,4 @@ - + \ No newline at end of file diff --git a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.Callbacks.cs b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.Callbacks.cs index 2f6e369e1be..b27aca4dba1 100644 --- a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.Callbacks.cs +++ b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.Callbacks.cs @@ -8,12 +8,16 @@ public partial class CellBodyPlanEditorComponent private void OnCellAdded(HexWithData hexWithData) { cellDataDirty = true; + + UpdateReproductionOrderList(); } [DeserializedCallbackAllowed] private void OnCellRemoved(HexWithData hexWithData) { cellDataDirty = true; + + UpdateReproductionOrderList(); } [DeserializedCallbackAllowed] diff --git a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.cs b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.cs index 1dd325165d3..2be34f9fb36 100644 --- a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.cs +++ b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.cs @@ -57,6 +57,9 @@ public partial class CellBodyPlanEditorComponent : [Export] public NodePath CellPopupMenuPath = null!; + [Export] + public NodePath ReproductionOrderListPath = null!; + private static Vector3 microbeModelOffset = new(0, -0.1f, 0); private readonly Dictionary cellTypeSelectionButtons = new(); @@ -96,6 +99,10 @@ public partial class CellBodyPlanEditorComponent : private PackedScene microbeScene = null!; private CellPopupMenu cellPopupMenu = null!; + + private VBoxContainer reproductionOrderList = null!; + + private PackedScene reproductionOrderScene = null!; #pragma warning restore CA2213 // Microbe scale applies done with 3 frame delay (that's why there are multiple list variables) @@ -146,6 +153,9 @@ public override void _Ready() cellTypeSelectionButtonScene = GD.Load("res://src/early_multicellular_stage/editor/CellTypeSelection.tscn"); + reproductionOrderScene = + GD.Load("res://src/early_multicellular_stage/editor/ReproductionOrder.tscn"); + ApplySelectionMenuTab(); RegisterTooltips(); @@ -190,6 +200,8 @@ public override void ResolveNodeReferences() duplicateCellTypeName = GetNode(DuplicateCellTypeNamePath); cellPopupMenu = GetNode(CellPopupMenuPath); + + reproductionOrderList = GetNode(ReproductionOrderListPath); } public override void Init(EarlyMulticellularEditor owningEditor, bool fresh) @@ -597,6 +609,7 @@ protected override void Dispose(bool disposing) DuplicateCellTypeDialogPath.Dispose(); DuplicateCellTypeNamePath.Dispose(); CellPopupMenuPath.Dispose(); + ReproductionOrderListPath.Dispose(); } } @@ -915,6 +928,53 @@ private void OnCellToPlaceSelected(string cellTypeName) OnCurrentActionChanged(); } + private void UpdateReproductionOrderList() + { + // Clear the existing list using QueueFree because a simple Free will cause problems when MoveCellUp and + // MoveCellDown call this method + reproductionOrderList.QueueFreeChildren(); + + for (var index = 0; index < editedMicrobeCells.Count; index++) + { + var control = (ReproductionOrder)reproductionOrderScene.Instance(); + + control.Index = $"{index + 1}."; + var cell = editedMicrobeCells[index]; + control.CellDescription = $"{cell.Data?.FormattedName} ({cell.Position.Q},{cell.Position.R})"; + + control.Connect(nameof(ReproductionOrder.OnCellUp), this, nameof(MoveCellUp)); + control.Connect(nameof(ReproductionOrder.OnCellDown), this, nameof(MoveCellDown)); + + reproductionOrderList.AddChild(control); + } + } + + private void MoveCellUp(int index) + { + // The displayed index for ReproductionOrder starts at 1 instead of 0, so subtract 1 + --index; + + if (index <= 0) + return; + + editedMicrobeCells.SwapIndexes(index, index - 1); + + UpdateReproductionOrderList(); + } + + private void MoveCellDown(int index) + { + // The displayed index for ReproductionOrder starts at 1 instead of 0, so subtract 1 + --index; + + if (index >= editedMicrobeCells.Count - 1) + return; + + editedMicrobeCells.SwapIndexes(index, index + 1); + + UpdateReproductionOrderList(); + } + private void OnCurrentActionChanged() { // Enable the duplicate, delete, edit buttons for the cell type diff --git a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.tscn b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.tscn index e12702e01f0..6965e4611b6 100644 --- a/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.tscn +++ b/src/early_multicellular_stage/editor/CellBodyPlanEditorComponent.tscn @@ -332,6 +332,7 @@ CannotDeleteInUseTypeDialogPath = NodePath("CannotDeleteInUseType") DuplicateCellTypeDialogPath = NodePath("NewCellTypeSetup") DuplicateCellTypeNamePath = NodePath("NewCellTypeSetup/VBoxContainer2/NewName") CellPopupMenuPath = NodePath("CellPopupMenu") +ReproductionOrderListPath = NodePath("LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/OrderMarginContainer/OrderList") [node name="LeftPanel" type="MarginContainer" parent="."] anchor_bottom = 1.0 @@ -572,14 +573,18 @@ custom_styles/panel = SubResource( 8 ) [node name="ScrollContainer" type="ScrollContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction"] margin_right = 414.0 -margin_bottom = 516.0 +margin_bottom = 518.0 mouse_filter = 1 scroll_horizontal_enabled = false __meta__ = { "_edit_use_anchors_": true } -[node name="MarginContainer" type="MarginContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer"] +margin_right = 414.0 +margin_bottom = 23.0 + +[node name="MethodMarginContainer" type="MarginContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer"] margin_right = 414.0 margin_bottom = 19.0 mouse_filter = 1 @@ -589,29 +594,29 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="VBoxContainer" type="VBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/MarginContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/MethodMarginContainer"] margin_right = 404.0 margin_bottom = 19.0 custom_constants/separation = 15 -[node name="HBoxContainer" type="HBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/MarginContainer/VBoxContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/MethodMarginContainer/VBoxContainer"] margin_right = 404.0 margin_bottom = 19.0 -[node name="Label" type="Label" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer"] +[node name="Label" type="Label" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/MethodMarginContainer/VBoxContainer/HBoxContainer"] margin_top = 1.0 margin_right = 179.0 margin_bottom = 18.0 custom_fonts/font = ExtResource( 14 ) text = "REPRODUCTION_METHOD" -[node name="Control" type="Control" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer"] +[node name="Control" type="Control" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/MethodMarginContainer/VBoxContainer/HBoxContainer"] margin_left = 183.0 margin_right = 183.0 margin_bottom = 19.0 size_flags_horizontal = 3 -[node name="OptionButton" type="OptionButton" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/MarginContainer/VBoxContainer/HBoxContainer"] +[node name="OptionButton" type="OptionButton" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/MethodMarginContainer/VBoxContainer/HBoxContainer"] margin_left = 187.0 margin_right = 404.0 margin_bottom = 19.0 @@ -620,6 +625,15 @@ text = "REPRODUCTION_BUDDING" items = [ "REPRODUCTION_BUDDING", null, false, 0, null ] selected = 0 +[node name="OrderMarginContainer" type="MarginContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer"] +margin_top = 23.0 +margin_right = 414.0 +margin_bottom = 23.0 +size_flags_horizontal = 3 + +[node name="OrderList" type="VBoxContainer" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel/Reproduction/ScrollContainer/VBoxContainer/OrderMarginContainer"] +margin_right = 414.0 + [node name="Behaviour" parent="LeftPanel/MainPanel/VBoxContainer/MarginContainer/EditingPanel" instance=ExtResource( 9 )] visible = false margin_top = 40.0 diff --git a/src/early_multicellular_stage/editor/ReproductionOrder.cs b/src/early_multicellular_stage/editor/ReproductionOrder.cs new file mode 100644 index 00000000000..acbeee06936 --- /dev/null +++ b/src/early_multicellular_stage/editor/ReproductionOrder.cs @@ -0,0 +1,95 @@ +using Godot; + +/// +/// Handles showing and changing the order in which cells in an early multicellular creature will divide. +/// +public class ReproductionOrder : MarginContainer +{ +#pragma warning disable CA2213 + [Export] + public NodePath IndexPath = null!; + + [Export] + public NodePath CellDescriptionPath = null!; + + private Label? indexLabel; + + private Label? cellDescriptionLabel; +#pragma warning restore CA2213 + + private string index = "Error: unset"; + private string cellDescription = "Error: unset"; + + [Signal] + public delegate void OnCellUp(int index); + + [Signal] + public delegate void OnCellDown(int index); + + /// + /// When this cell will be created. 1 is the starting cell. + /// + public string Index + { + get => index; + set + { + index = value; + UpdateIndex(); + } + } + + /// + /// The name and location of this cell. + /// + public string CellDescription + { + get => cellDescription; + set + { + cellDescription = value; + UpdateCellDescription(); + } + } + + public override void _Ready() + { + indexLabel = GetNode