Commit Description:
Relegate local variables to debug builds.
Commit Description:
Relegate local variables to debug builds.
File last commit:
Show/Diff file:
Action:
isometric-park-fna/UI/OptionsWindow.cs
201 lines | 6.3 KiB | text/x-csharp | CSharpLexer
using System;
using ImGuiNET;
using Num = System.Numerics;
using Microsoft.Xna.Framework;
using isometricparkfna.Engines;
using isometricparkfna.Messages;
using isometricparkfna.UI;
namespace isometricparkfna.UI
{
public static class OptionsWindow
{
public static bool hadFocus = false;
public static bool newFullscreen;
public static Vector2 newResolution;
private static string fontName = "Iosevka";
private static int fontSize = 15;
private static ProfanityLevel profanityLevel = default;
public static void Initialize(Vector2 resolution, bool fullscreen, ProfanityLevel profanityLevel)
{
OptionsWindow.newFullscreen = fullscreen;
OptionsWindow.newResolution = resolution;
OptionsWindow.profanityLevel = profanityLevel;
}
public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine bridgeEngine, int width, ProfanityLevel profanityLevel)
{
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
bool newShow = true;
StyleSets.defaultSet.push();
ImGui.PushFont(font);
if(OptionsWindow.hadFocus)
{
ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
}
ImGui.Begin("Options", ref newShow, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse);
if (OptionsWindow.hadFocus)
{
ImGui.PopStyleColor();
}
OptionsWindow.hadFocus = ImGui.IsWindowFocused();
ImGui.PushFont(italicFont);
ImGui.Text("Graphics");
ImGui.PopFont();
ImGui.Text("Resolution:");
ImGui.SameLine();
if (ImGui.BeginCombo("", string.Format("{0}x{1}",
newResolution.X, newResolution.Y)))
{
foreach(var (width_option, height_option) in new[] {(1280, 640),
(640, 320), (960, 480), (1600, 800),
(2560, 1440), (1280, 720), (1920, 1080)
})
{
if (ImGui.Selectable(string.Format("{0}x{1}", width_option, height_option)))
{
newResolution.X = width_option;
newResolution.Y = height_option;
}
}
ImGui.EndCombo();
}
ImGui.Text("Font:\t");
ImGui.SameLine();
if (ImGui.BeginCombo("##Font", fontName))
{
foreach(var font_name in new[] {"Iosevka", "Roboto"})
{
if(ImGui.Selectable(font_name))
{
OptionsWindow.fontName = font_name;
}
}
ImGui.EndCombo();
}
ImGui.Text("Size:\t");
ImGui.SameLine();
if (ImGui.BeginCombo("##FontSize", fontSize.ToString()))
{
foreach(var size in new[] {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25})
{
if(ImGui.Selectable(size.ToString()))
{
OptionsWindow.fontSize = size;
}
}
ImGui.EndCombo();
}
ImGuiIOPtr io = ImGui.GetIO();
ImGui.Text("Scale:\t");
ImGui.SameLine();
ImGui.DragFloat("##Scale", ref io.FontGlobalScale, 0.005f, 0.2f, 5.0f, "%.2f");
ImGui.SameLine();
Widgets.LabelTooltip("(?)", "Adjust this if increasing font size isn't enough.");
ImGui.Checkbox("Fullscreen", ref newFullscreen);
ImGui.Separator();
ImGui.PushFont(italicFont);
ImGui.Text("Text");
ImGui.PopFont();
ImGui.Text("Profanity:");
ImGui.SameLine();
if (ImGui.BeginCombo("##Profanity", profanityLevel.ToString()))
{
foreach(var level in Enum.GetValues(typeof(ProfanityLevel)))
{
if(ImGui.Selectable(level.ToString()))
{
bridgeEngine.setOptionMessages.Add(new SetOptionMessage { NewProfanitySetting = (ProfanityLevel)level});
OptionsWindow.profanityLevel = (ProfanityLevel)level;
}
}
ImGui.EndCombo();
}
ImGui.SameLine();
Widgets.LabelTooltip("(?)", "Removes profanity from the game, if you must.");
ImGui.Separator();
if (ImGui.Button("Okay"))
{
bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Options});
bridgeEngine.resolutionMessages.Add(new SetResolutionMessage {
resolution = newResolution,
fullscreen = newFullscreen
});
bridgeEngine.fontMessages.Add(new SetFontMessage {
fontSize = OptionsWindow.fontSize,
fontName = OptionsWindow.fontName
});
}
ImGui.SameLine();
if (ImGui.Button("Apply"))
{
bridgeEngine.resolutionMessages.Add(new SetResolutionMessage {
resolution = newResolution,
fullscreen = newFullscreen
});
bridgeEngine.fontMessages.Add(new SetFontMessage {
fontSize = OptionsWindow.fontSize,
fontName = OptionsWindow.fontName
});
}
ImGui.End();
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
StyleSets.defaultSet.pop();
ImGui.PopFont();
if (!newShow)
{
bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Options});
}
}
public static void setFont(string fontName, int fontSize)
{
OptionsWindow.fontName = fontName;
OptionsWindow.fontSize = fontSize;
}
}
}