From fa1238a58dbd420791be1044484c1f1233b5a8f0 Mon Sep 17 00:00:00 2001 From: se5a Date: Fri, 24 May 2024 18:39:09 +1200 Subject: [PATCH] Added Minerals to the Editor. --- .../ModFileEditing/BluePrintsUI.cs | 119 ++++++++++++++++-- .../ModFileEditing/EditorWidgets.cs | 37 ++++++ .../ModFileEditing/ModFileEditor.cs | 7 +- 3 files changed, 148 insertions(+), 15 deletions(-) diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs index 03c39b8aa..8e6c3f1a6 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs @@ -169,7 +169,7 @@ public override void DisplayEditorWindow(int selectedIndex) var selectedItem = (TechCategoryBlueprint)_itemBlueprints[selectedIndex]; string name = selectedItem.Name; string desc = selectedItem.Description; - if (ImGui.Begin("Tech Category Editor: " + name)) + if (ImGui.Begin("Tech Category Editor: " + name, ref _isActive[selectedIndex])) { ImGui.Columns(2); ImGui.SetColumnWidth(0,150); @@ -227,7 +227,7 @@ public override void DisplayEditorWindow(int selectedIndex) var selectedItem = (TechBlueprint)_itemBlueprints[selectedIndex]; string name = selectedItem.Name; string editStr; - if (ImGui.Begin("Tech Editor: " + name)) + if (ImGui.Begin("Tech Editor: " + name, ref _isActive[selectedIndex])) { ImGui.Columns(2); ImGui.SetColumnWidth(0,150); @@ -348,13 +348,12 @@ public override void DisplayEditorWindow(int selectedIndex) string name = selectedItem.Name; string editStr; - if (ImGui.Begin("Tech Category Editor: " + name)) + if (ImGui.Begin("Tech Category Editor: " + name, ref _isActive[selectedIndex])) { ImGui.Columns(2); ImGui.SetColumnWidth(0, 150); ImGui.SetColumnWidth(1, 500); - ImGui.Text("Name: "); ImGui.NextColumn(); editStr = selectedItem.Name; @@ -466,7 +465,7 @@ public override void DisplayEditorWindow(int selectedIndex) var selectedItem = (ArmorBlueprint)_itemBlueprints[selectedIndex]; _editStr = selectedItem.UniqueID; //string desc = selectedItem.Description; - if (ImGui.Begin("Tech Category Editor: " + _editStr)) + if (ImGui.Begin("Tech Category Editor: " + _editStr, ref _isActive[selectedIndex])) { ImGui.Columns(2); ImGui.SetColumnWidth(0,150); @@ -496,18 +495,13 @@ public override void DisplayEditorWindow(int selectedIndex) { selectedItem.Density = editDoub; } - - - - + ImGui.End(); } } } - - public class ProcessedMateralsUI : BluePrintsUI { private int _selectedIndex = -1; @@ -541,7 +535,7 @@ public override void DisplayEditorWindow(int selectedIndex) return; var selectedItem = (ProcessedMaterialBlueprint)_itemBlueprints[selectedIndex]; - if (ImGui.Begin("Processed Materials Editor: " + selectedItem.Name)) + if (ImGui.Begin("Processed Materials Editor: " + selectedItem.Name, ref _isActive[selectedIndex])) { ImGui.Columns(2); ImGui.SetColumnWidth(0,150); @@ -657,7 +651,7 @@ public override void DisplayEditorWindow(int selectedIndex) ImGui.Text("Mass: "); ImGui.NextColumn(); _editInt = (int)selectedItem.MassPerUnit; - if (IntEditWidget.Display("##mass" + selectedItem.UniqueID, ref editInt)) + if (IntEditWidget.Display("##mass" + selectedItem.UniqueID, ref _editInt)) { selectedItem.MassPerUnit = _editInt; } @@ -668,6 +662,105 @@ public override void DisplayEditorWindow(int selectedIndex) } } +public class MineralBlueprintUI : BluePrintsUI +{ + public MineralBlueprintUI(ModDataStore modDataStore) : base(modDataStore) + { + var blueprints = modDataStore.Minerals; + _itemBlueprints = blueprints.Values.ToArray(); + Refresh(); + } + + public override void Refresh() + { + _itemNames = new string[_itemBlueprints.Length]; + _isActive = new bool[_itemBlueprints.Length]; + int i = 0; + foreach (MineralBlueprint item in _itemBlueprints) + { + _itemNames[i] = item.Name; + _isActive[i] = false; + i++; + } + var newEmpty = new MineralBlueprint(); + newEmpty.Name = "New Blueprint"; + _newEmpty = newEmpty; + } + + public override void DisplayEditorWindow(int selectedIndex) + { + if(!_isActive[selectedIndex]) + return; + var selectedItem = (MineralBlueprint)_itemBlueprints[selectedIndex]; + + if (ImGui.Begin("Processed Materials Editor: " + selectedItem.Name, ref _isActive[selectedIndex])) + { + ImGui.Columns(2); + ImGui.SetColumnWidth(0, 150); + ImGui.SetColumnWidth(1, 500); + ImGui.Text("Name: "); + ImGui.NextColumn(); + + + _editStr = selectedItem.Name; + if (TextEditWidget.Display("##name" + selectedItem.UniqueID, ref _editStr)) + { + selectedItem.Name = _editStr; + } + ImGui.NextColumn(); + + + ImGui.Text("Description: "); + ImGui.NextColumn(); + _editStr = selectedItem.Description; + if (TextEditWidget.Display("##desc" + selectedItem.UniqueID, ref _editStr)) + { + selectedItem.Name = _editStr; + } + ImGui.NextColumn(); + + ImGui.Text("Cargo Type: "); + ImGui.NextColumn(); + _editInt = Array.IndexOf(_cargoTypes, selectedItem.CargoTypeID); + if (SelectFromListWiget.Display("##ctype" + selectedItem.UniqueID, _cargoTypes, ref _editInt)) + { + selectedItem.CargoTypeID = _cargoTypes[_editInt]; + _editInt = -1; + } + ImGui.NextColumn(); + + ImGui.Text("Mass: "); + ImGui.NextColumn(); + _editInt = (int)selectedItem.MassPerUnit; + if (IntEditWidget.Display("##mass" + selectedItem.UniqueID, ref _editInt)) + { + selectedItem.MassPerUnit = _editInt; + } + ImGui.NextColumn(); + + ImGui.Text("Volume: "); + ImGui.NextColumn(); + var editDouble= selectedItem.VolumePerUnit; + if (DoubleEditWidget.Display("##vol" + selectedItem.UniqueID, ref editDouble)) + { + selectedItem.VolumePerUnit = editDouble; + } + ImGui.NextColumn(); + + ImGui.Text("Abundance: "); + ImGui.NextColumn(); + var editDict = selectedItem.Abundance; + if (DictEditWidget.Display("##Abundance" + selectedItem.UniqueID, ref editDict)) + { + selectedItem.Abundance = editDict; + } + ImGui.NextColumn(); + + ImGui.End(); + } + } +} + diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs index dc737d651..12a867ae4 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs @@ -4,6 +4,7 @@ using System.Numerics; using ImGuiNET; using ImGuiSDL2CS; +using Pulsar4X.DataStructures; namespace Pulsar4X.SDL2UI.ModFileEditing; @@ -113,6 +114,7 @@ public static class DictEditWidget private static int _editInt; private static string _editStr; private static long _editLong; + private static double _editDouble; private static uint _buffSize = 128; private static byte[] _strInputBuffer = new byte[128]; private static int _techIndex = 0; @@ -273,6 +275,41 @@ public static bool Display(string label, ref Dictionary dict) return isChanged; } + + public static bool Display(string label, ref Dictionary dict) + { + ImGui.BeginChild("##dic" + label, new Vector2(400,160), true); + ImGui.Columns(2); + bool isChanged = false; + if (dict is null) + { + dict = new Dictionary(); + foreach (var bodyType in Enum.GetValues(typeof(BodyType))) + { + dict.Add((BodyType)bodyType, 0); + } + } + _addKey = -1; + foreach (var kvp in dict) + { + _editStr = Enum.GetName(kvp.Key); + _editDouble = kvp.Value; + + ImGui.Text(_editStr); + ImGui.NextColumn(); + + if(DoubleEditWidget.Display(label+_editStr,ref _editDouble)) + { + dict[kvp.Key] = _editDouble; + } + ImGui.NextColumn(); + + } + + ImGui.EndChild(); + return isChanged; + } + } public static class SelectFromListWiget diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs index fa37cc6fb..3403ae777 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs @@ -13,7 +13,7 @@ public class ModFileEditor : PulsarGuiWindow private AttributeBlueprintUI _attributeBlueprintUI; private ArmorBlueprintUI _armorBlueprintUI; private ProcessedMateralsUI _processedMateralsUI; - + private MineralBlueprintUI _mineralsBlueprintUI; private ModFileEditor() @@ -48,6 +48,7 @@ void refresh() _armorBlueprintUI = new ArmorBlueprintUI(modDataStore); _processedMateralsUI = new ProcessedMateralsUI(modDataStore); + _mineralsBlueprintUI = new MineralBlueprintUI(modDataStore); } @@ -57,7 +58,7 @@ internal override void Display() if (IsActive) { - if (ImGui.Begin("Debug GUI Window", ref IsActive)) + if (ImGui.Begin("Editor", ref IsActive)) { _techCatBlueprintUI.Display("Tech Categorys"); ImGui.NewLine(); @@ -70,6 +71,8 @@ internal override void Display() ImGui.NewLine(); _processedMateralsUI.Display("Processed Materials"); ImGui.NewLine(); + _mineralsBlueprintUI.Display("Minerals"); + ImGui.NewLine(); } ImGui.End();