From 70cc5c1ae47b90f007c217824e8179748a4f6892 Mon Sep 17 00:00:00 2001 From: se5a Date: Mon, 6 May 2024 11:35:45 +1200 Subject: [PATCH] Very basic start on an editor. --- .../GameManagment/MainMenuItems.cs | 6 + .../ModFileEditing/ModFileEditor.cs | 134 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs diff --git a/Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs b/Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs index f8e279d31..dd0214e23 100644 --- a/Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs +++ b/Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs @@ -8,6 +8,7 @@ using System.Linq; using Pulsar4X.Extensions; using Pulsar4X.Datablobs; +using Pulsar4X.SDL2UI.ModFileEditing; namespace Pulsar4X.SDL2UI { @@ -76,6 +77,11 @@ internal override void Display() SettingsWindow.GetInstance().ToggleActive(); this.SetActive(false); } + if (ImGui.Button("Editor", buttonSize)) + { + ModFileEditor.GetInstance().ToggleActive(); + this.SetActive(false); + } } ImGui.Button("Resume a Current Game", buttonSize); ImGui.Button("Connect to a Network Game", buttonSize); diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs new file mode 100644 index 000000000..d1a6deac3 --- /dev/null +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using ImGuiNET; +using Pulsar4X.Blueprints; +using Pulsar4X.DataStructures; + +namespace Pulsar4X.SDL2UI.ModFileEditing; + +public class ModFileEditor : PulsarGuiWindow +{ + private SafeDictionary _techCategoryBlueprint; + private int _selectedTechCat = 0; + private string[] _techCatNames; + private TechCategoryBlueprint[] _techCatBluprints; + + + private Dictionary _startingTechBlueprints; + private int _selectedTech = 0; + private string[] _techNames; + private TechBlueprint[] _techBlueprints; + + private ModFileEditor() + { + + } + internal static ModFileEditor GetInstance() + { + ModFileEditor instance; + if (!_uiState.LoadedWindows.ContainsKey(typeof(ModFileEditor))) + { + instance = new ModFileEditor(); + instance.refresh(); + } + else + { + instance = (ModFileEditor)_uiState.LoadedWindows[typeof(ModFileEditor)]; + } + return instance; + } + + void refresh() + { + _techCategoryBlueprint = _uiState.Game.TechCategories; + _techCatNames = new string[_techCategoryBlueprint.Count]; + _techCatBluprints = new TechCategoryBlueprint[_techCategoryBlueprint.Count]; + + + + int i = 0; + foreach (var kvp in _techCategoryBlueprint) + { + _techCatNames[i] = kvp.Key; + _techCatBluprints[i] = kvp.Value; + i++; + } + + + _startingTechBlueprints = _uiState.Game.StartingGameData.Techs; + _techNames = new string[_startingTechBlueprints.Count]; + _techBlueprints = new TechBlueprint[_startingTechBlueprints.Count]; + + i = 0; + foreach (var kvp in _startingTechBlueprints) + { + _techNames[i] = kvp.Key; + _techBlueprints[i] = kvp.Value; + i++; + } + } + + + internal override void Display() + { + + if (IsActive) + { + if (ImGui.Begin("Debug GUI Window", ref IsActive)) + { + BorderListOptions.Begin("Tech Categores", _techCatNames, ref _selectedTechCat, 200); + var selectedcat = _techCatBluprints[_selectedTechCat]; + + ImGui.Text("Name: "); + ImGui.SameLine(); + ImGui.Text(selectedcat.Name); + + ImGui.Text("Description: "); + ImGui.SameLine(); + ImGui.Text(selectedcat.Description); + + BorderListOptions.End(new Vector2(400, 600)); + + ImGui.NewLine(); + + BorderListOptions.Begin("Tech Blueprints", _techNames, ref _selectedTech, 200); + + var selectedTechBnt = _techBlueprints[_selectedTech]; + + ImGui.Text("Name: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.Name); + + ImGui.Text("Description: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.Description); + + ImGui.Text("Category: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.Category); + + ImGui.Text("CostFormula: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.CostFormula); + + ImGui.Text("DataFormula: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.DataFormula); + + ImGui.Text("MaxLevel: "); + ImGui.SameLine(); + ImGui.Text(selectedTechBnt.MaxLevel.ToString()); + + ImGui.Text("Unlocks: "); + ImGui.SameLine(); + //ImGui.Text(selected.); + + BorderListOptions.End(new Vector2(400, 600)); + + } + + ImGui.End(); + } + } +} \ No newline at end of file