Skip to content

Commit

Permalink
Added Minerals to the Editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 24, 2024
1 parent 04710bb commit fa1238a
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 15 deletions.
119 changes: 106 additions & 13 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -496,18 +495,13 @@ public override void DisplayEditorWindow(int selectedIndex)
{
selectedItem.Density = editDoub;
}





ImGui.End();
}
}
}




public class ProcessedMateralsUI : BluePrintsUI
{
private int _selectedIndex = -1;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
}
}




Expand Down
37 changes: 37 additions & 0 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Numerics;
using ImGuiNET;
using ImGuiSDL2CS;
using Pulsar4X.DataStructures;

namespace Pulsar4X.SDL2UI.ModFileEditing;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -273,6 +275,41 @@ public static bool Display(string label, ref Dictionary<string, long> dict)

return isChanged;
}

public static bool Display(string label, ref Dictionary<BodyType, double> dict)
{
ImGui.BeginChild("##dic" + label, new Vector2(400,160), true);
ImGui.Columns(2);
bool isChanged = false;
if (dict is null)
{
dict = new Dictionary<BodyType, double>();
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
Expand Down
7 changes: 5 additions & 2 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ModFileEditor : PulsarGuiWindow
private AttributeBlueprintUI _attributeBlueprintUI;
private ArmorBlueprintUI _armorBlueprintUI;
private ProcessedMateralsUI _processedMateralsUI;

private MineralBlueprintUI _mineralsBlueprintUI;


private ModFileEditor()
Expand Down Expand Up @@ -48,6 +48,7 @@ void refresh()

_armorBlueprintUI = new ArmorBlueprintUI(modDataStore);
_processedMateralsUI = new ProcessedMateralsUI(modDataStore);
_mineralsBlueprintUI = new MineralBlueprintUI(modDataStore);

}

Expand All @@ -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();
Expand All @@ -70,6 +71,8 @@ internal override void Display()
ImGui.NewLine();
_processedMateralsUI.Display("Processed Materials");
ImGui.NewLine();
_mineralsBlueprintUI.Display("Minerals");
ImGui.NewLine();
}

ImGui.End();
Expand Down

0 comments on commit fa1238a

Please sign in to comment.