Lots of SzGui work
This commit is contained in:
76
SzGui/Windows/SettingsWindow.cs
Normal file
76
SzGui/Windows/SettingsWindow.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace SzGui.Windows;
|
||||
|
||||
public class SettingsWindow : SzGuiWindowBase
|
||||
{
|
||||
private bool _settingsDirty = false;
|
||||
|
||||
public SettingsWindow() => WindowName = "App Settings";
|
||||
|
||||
protected override void RenderContent()
|
||||
{
|
||||
ImGui.SeparatorText("Application Settings");
|
||||
|
||||
foreach (var setting in ApplicationSettings.GetAllSettings().ToList())
|
||||
{
|
||||
string key = setting.Key;
|
||||
object val = setting.Value;
|
||||
bool changed = false;
|
||||
|
||||
if (val is bool boolVal)
|
||||
{
|
||||
if (ImGui.Checkbox(key, ref boolVal))
|
||||
{
|
||||
ApplicationSettings.SetSettingValue(key, boolVal);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (val is float floatVal || val is double)
|
||||
{
|
||||
float f = Convert.ToSingle(val);
|
||||
if (ImGui.DragFloat(key, ref f, 0.01f))
|
||||
{
|
||||
ApplicationSettings.SetSettingValue(key, f);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (val is string strVal)
|
||||
{
|
||||
if (ImGui.InputText(key, ref strVal, 256))
|
||||
{
|
||||
ApplicationSettings.SetSettingValue(key, strVal);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.SetTooltip($"Internal Key: {key}");
|
||||
}
|
||||
|
||||
if (changed) _settingsDirty = true;
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("Save Changes"))
|
||||
{
|
||||
ApplicationSettings.SaveSettings();
|
||||
_settingsDirty = false;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.Button("Reload from Disk"))
|
||||
{
|
||||
ApplicationSettings.LoadSettings();
|
||||
}
|
||||
|
||||
if (_settingsDirty)
|
||||
{
|
||||
ImGui.TextColored(new Vector4(1, 0.5f, 0, 1), "You have unsaved changes!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user