Skip to content

Commit

Permalink
Very basic start on an editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 5, 2024
1 parent 180b9ed commit 70cc5c1
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using Pulsar4X.Extensions;
using Pulsar4X.Datablobs;
using Pulsar4X.SDL2UI.ModFileEditing;

namespace Pulsar4X.SDL2UI
{
Expand Down Expand Up @@ -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);
Expand Down
134 changes: 134 additions & 0 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs
Original file line number Diff line number Diff line change
@@ -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<string, TechCategoryBlueprint > _techCategoryBlueprint;
private int _selectedTechCat = 0;
private string[] _techCatNames;
private TechCategoryBlueprint[] _techCatBluprints;


private Dictionary<string, TechBlueprint> _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();
}
}
}

0 comments on commit 70cc5c1

Please sign in to comment.