Skip to content

Commit

Permalink
Some unfinished editor work.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 26, 2024
1 parent fa1238a commit a433e5f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Pulsar4X/GameEngine/Blueprints/Blueprint.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Newtonsoft.Json;

namespace Pulsar4X.Blueprints
{
public abstract class Blueprint
{
public string UniqueID { get; set; }
[JsonIgnore]
public string FullIdentifier { get; protected set; }

public void SetFullIdentifier(string modNamespace)
Expand Down
64 changes: 60 additions & 4 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using ImGuiNET;
using Newtonsoft.Json;
using Pulsar4X.Blueprints;
using Pulsar4X.DataStructures;
using Pulsar4X.Interfaces;
Expand Down Expand Up @@ -59,14 +61,21 @@ protected BluePrintsUI(ModDataStore modDataStore)

public abstract void Refresh();

public abstract void SaveAs(string path);


public void Display(string label)
{
int i = 0;
if(ImGui.TreeNode(label))
{
ImGui.Button("Save");
ImGui.SameLine();
ImGui.Button("SaveAs");
if (ImGui.Button("SaveAs"))
{
SaveAs("foo");
//FileDialog.Display();
}
ImGui.SameLine();
ImGui.Button("SaveToMemory");

Expand Down Expand Up @@ -162,6 +171,23 @@ public sealed override void Refresh()
_newEmpty = newEmpty;
}

public override void SaveAs(string path)
{

path = "Data/basemod";
FileDialog.Display(path);
/*
using (StreamWriter outputFile = new StreamWriter(Path.Combine(path, "tcb.json")))
{
foreach (TechCategoryBlueprint blueprint in _itemBlueprints)
{
var json = JsonConvert.SerializeObject(blueprint, Formatting.Indented);
outputFile.WriteLine(json);
}
}
*/
}

public override void DisplayEditorWindow(int selectedIndex)
{
if(!_isActive[selectedIndex])
Expand Down Expand Up @@ -219,6 +245,11 @@ public override void Refresh()
_newEmpty = newEmpty;
}

public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public override void DisplayEditorWindow(int selectedIndex)
{

Expand Down Expand Up @@ -334,7 +365,12 @@ public sealed override void Refresh()
newEmpty.Name = "New Blueprint";
_newEmpty = newEmpty;
}


public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public override void DisplayEditorWindow(int selectedIndex)
{

Expand Down Expand Up @@ -457,7 +493,12 @@ public sealed override void Refresh()
newEmpty.UniqueID = "New Blueprint";
_newEmpty = newEmpty;
}


public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public override void DisplayEditorWindow(int selectedIndex)
{
if(!_isActive[selectedIndex])
Expand Down Expand Up @@ -528,6 +569,11 @@ public sealed override void Refresh()
_newEmpty = newEmpty;
}

public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public override void DisplayEditorWindow(int selectedIndex)
{

Expand Down Expand Up @@ -687,6 +733,11 @@ public override void Refresh()
_newEmpty = newEmpty;
}

public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public override void DisplayEditorWindow(int selectedIndex)
{
if(!_isActive[selectedIndex])
Expand Down Expand Up @@ -817,7 +868,12 @@ public sealed override void Refresh()
i++;
}
}


public override void SaveAs(string path)
{
throw new NotImplementedException();
}

public void Display()
{
ImGui.Columns(2);
Expand Down
52 changes: 52 additions & 0 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/FileDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using ImGuiNET;

namespace Pulsar4X.SDL2UI.ModFileEditing;

public static class FileDialog
{
public enum SaveOrLoad
{
Save,
Load
}
private static byte[] _strInputBuffer = new byte[128];
private static string _pathString;

public static SaveOrLoad DialogType = SaveOrLoad.Save;

public static void Display(string path)
{
_pathString = path;
ImGui.Begin("File Dialog");
ImGui.Text("Name:");
ImGui.SameLine();
ImGui.InputText("##Name", _strInputBuffer, 128);

ImGui.Columns(2);
ImGui.SetColumnWidth(0,128);

ImGui.NextColumn();

ImGui.BeginTable("", 4);

ImGui.TableHeader("Name");
ImGui.TableNextColumn();
ImGui.TableHeader("Size");
ImGui.TableNextColumn();
ImGui.TableHeader("Type");
ImGui.TableNextColumn();
ImGui.TableHeader("Modified");
ImGui.TableNextColumn();

var files = System.IO.Directory.EnumerateFiles(_pathString);
foreach (var file in files)
{

}

ImGui.EndTable();


ImGui.End();
}
}

0 comments on commit a433e5f

Please sign in to comment.