mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Settings / SettingsWindow
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
FileVersion = 1
|
||||
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", DirectXTK = "*", FreeType = "*", cgltf-beef = "*", msdfgen-beef = "*", ImGui = "*", ImGuiImplDX11 = "*", ImGuiImplWin32 = "*", ImGuizmo = "*", Beefy2D = "*", LodePng = "*", GlitchyEngineHelper = "*"}
|
||||
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", DirectXTK = "*", FreeType = "*", cgltf-beef = "*", msdfgen-beef = "*", ImGui = "*", ImGuiImplDX11 = "*", ImGuiImplWin32 = "*", ImGuizmo = "*", Beefy2D = "*", LodePng = "*", GlitchyEngineHelper = "*", bon = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "GlitchyEngine"
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace GlitchyEngine
|
||||
[Inline]
|
||||
public static Application Get() => s_Instance;
|
||||
|
||||
public Settings Settings {get; private set;} = new .() ~ delete _;
|
||||
|
||||
public this()
|
||||
{
|
||||
Profiler.ProfileFunction!();
|
||||
@@ -70,6 +72,9 @@ namespace GlitchyEngine
|
||||
_imGuiLayer = new ImGuiLayer();
|
||||
PushOverlay(_imGuiLayer);
|
||||
#endif
|
||||
|
||||
GlitchyEngine.Settings.Load();
|
||||
Settings.Apply();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace GlitchyEngine.Content
|
||||
|
||||
interface IContentManager
|
||||
{
|
||||
void GetFilePath(String outFilename, String filename);
|
||||
|
||||
Stream GetFile(String filename);
|
||||
}
|
||||
|
||||
@@ -41,10 +43,15 @@ namespace GlitchyEngine.Content
|
||||
Runtime.Assert(Directory.Exists(contentRoot), "Content root directory doesn't exist.");
|
||||
}
|
||||
|
||||
public void GetFilePath(String outFilename, String filename)
|
||||
{
|
||||
Path.InternalCombine(outFilename, _contentRoot, filename);
|
||||
}
|
||||
|
||||
public Stream GetFile(String filename)
|
||||
{
|
||||
String fullpath = scope .(_contentRoot.Length + 1 + filename.Length);
|
||||
Path.InternalCombine(fullpath, _contentRoot, filename);
|
||||
GetFilePath(fullpath, filename);
|
||||
|
||||
FileStream stream = new FileStream();
|
||||
var result = stream.Open(fullpath, .Read, .Read);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace System
|
||||
{
|
||||
extension Runtime
|
||||
{
|
||||
[NoReturn, Warn("The method is not implemented.")]
|
||||
#unwarn
|
||||
public static void NotImplemented(String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
|
||||
{
|
||||
String failStr = scope .()..AppendF("Not Implemented at line {} in {}", line, filePath);
|
||||
Internal.FatalError(failStr, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ using System;
|
||||
using ImGui;
|
||||
using GlitchyEngine.Events;
|
||||
using ImGuizmo;
|
||||
using GlitchyEngine.Renderer;
|
||||
using System.IO;
|
||||
|
||||
using internal ImGui;
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using GlitchyEngine.Platform.DX11;
|
||||
using GlitchyEngine.Renderer;
|
||||
using internal GlitchyEngine.Platform.DX11;
|
||||
|
||||
#endif
|
||||
@@ -19,6 +20,8 @@ namespace GlitchyEngine.ImGui
|
||||
{
|
||||
ImGui.IO* _io;
|
||||
|
||||
public bool SettingsInvalid;
|
||||
|
||||
public this() : base("ImGuiLayer") { }
|
||||
|
||||
public override void OnAttach()
|
||||
@@ -87,6 +90,30 @@ namespace GlitchyEngine.ImGui
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
if (SettingsInvalid)
|
||||
{
|
||||
var settings = Application.Get().Settings.ImGuiSettings;
|
||||
|
||||
ImGui.GetIO().Fonts.Clear();
|
||||
|
||||
String fullpath = scope String();
|
||||
Application.Get().ContentManager.GetFilePath(fullpath, settings.FontName);
|
||||
if (File.Exists(fullpath))
|
||||
{
|
||||
ImGui.GetIO().Fonts.AddFontFromFileTTF(fullpath, settings.FontSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
}
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
ImGuiImplDX11.CreateDeviceObjects();
|
||||
#endif
|
||||
|
||||
SettingsInvalid = false;
|
||||
}
|
||||
|
||||
Begin();
|
||||
|
||||
{
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using ImGui;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Bon;
|
||||
|
||||
namespace GlitchyEngine
|
||||
{
|
||||
interface ISettings
|
||||
{
|
||||
void Apply();
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be scanned for Settings.
|
||||
[AttributeUsage(.Field, .ReflectAttribute)]
|
||||
struct SettingContainerAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be exposed as settings.
|
||||
[AttributeUsage(.Field, .ReflectAttribute)]
|
||||
struct SettingAttribute : Attribute
|
||||
{
|
||||
public String Category;
|
||||
public String Name;
|
||||
|
||||
public this(String category, String name)
|
||||
{
|
||||
Category = category;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
[Reflect, BonTarget]
|
||||
class Settings
|
||||
{
|
||||
#if IMGUI
|
||||
[SettingContainer, BonInclude]
|
||||
public readonly ImGuiSettings ImGuiSettings = new .() ~ delete _;
|
||||
#endif
|
||||
|
||||
/*
|
||||
[BonInclude]
|
||||
private List<ISettings> _userSettings ~ ClearAndDeleteItems!(_);
|
||||
*/
|
||||
|
||||
[AllowAppend]
|
||||
public this()
|
||||
{
|
||||
/*List<ISettings> userSettings = append .();
|
||||
_userSettings = userSettings;*/
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
#if IMGUI
|
||||
ImGuiSettings.Apply();
|
||||
#endif
|
||||
|
||||
/*for (let settings in _userSettings)
|
||||
{
|
||||
settings.Apply();
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
Settings settings = Application.Get().Settings;
|
||||
|
||||
var result = Bon.DeserializeFromFile(ref settings, "./settings.bon");
|
||||
|
||||
if (result case .Err)
|
||||
Log.EngineLogger.Error("Failed to deserialze settings.");
|
||||
|
||||
Application.Get().Settings.Apply();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
gBonEnv.serializeFlags |= .Verbose;
|
||||
Bon.SerializeIntoFile(this, "./settings.bon");
|
||||
}
|
||||
|
||||
/*
|
||||
/// Registers a instance of a settings interface. Note: Takes ownership of the instance.
|
||||
public void RegisterUserSettings(ISettings settings)
|
||||
{
|
||||
_userSettings.Add(settings);
|
||||
}
|
||||
|
||||
public T GetUserSettings<T>() where T : ISettings, class
|
||||
{
|
||||
for (let v in _userSettings)
|
||||
{
|
||||
if (v is T)
|
||||
{
|
||||
return (T)v;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
|
||||
#if IMGUI
|
||||
[Reflect]
|
||||
class ImGuiSettings
|
||||
{
|
||||
[Setting("UI", "Font Size"), BonInclude]
|
||||
public int32 FontSize = 16;
|
||||
|
||||
[Setting("UI", "Font name"), BonInclude]
|
||||
public readonly String FontName = new .("Fonts/CascadiaCode.ttf") ~ delete _;
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Application.Get().[Friend]_imGuiLayer.SettingsInvalid = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+1
Submodule GlitchyEngine/vendor/bon added at 515b606cf3
Reference in New Issue
Block a user