Abstract preset flags

centralize where flag names are stored, and hide from editor list by default
This commit is contained in:
pizzaboxer 2023-07-23 15:45:25 +01:00
parent 44c9d490b0
commit e5d6ac0e0a
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 144 additions and 140 deletions

View File

@ -1,4 +1,7 @@
namespace Bloxstrap
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace Bloxstrap
{
public class FastFlagManager : JsonManager<Dictionary<string, string>>
{
@ -7,22 +10,57 @@
// this is the value of the 'FStringPartTexturePackTablePre2022' flag
public const string OldTexturesFlagValue = "{\"foil\":{\"ids\":[\"rbxassetid://7546645012\",\"rbxassetid://7546645118\"],\"color\":[255,255,255,255]},\"brick\":{\"ids\":[\"rbxassetid://7546650097\",\"rbxassetid://7546645118\"],\"color\":[204,201,200,232]},\"cobblestone\":{\"ids\":[\"rbxassetid://7546652947\",\"rbxassetid://7546645118\"],\"color\":[212,200,187,250]},\"concrete\":{\"ids\":[\"rbxassetid://7546653951\",\"rbxassetid://7546654144\"],\"color\":[208,208,208,255]},\"diamondplate\":{\"ids\":[\"rbxassetid://7547162198\",\"rbxassetid://7546645118\"],\"color\":[170,170,170,255]},\"fabric\":{\"ids\":[\"rbxassetid://7547101130\",\"rbxassetid://7546645118\"],\"color\":[105,104,102,244]},\"glass\":{\"ids\":[\"rbxassetid://7547304948\",\"rbxassetid://7546645118\"],\"color\":[254,254,254,7]},\"granite\":{\"ids\":[\"rbxassetid://7547164710\",\"rbxassetid://7546645118\"],\"color\":[113,113,113,255]},\"grass\":{\"ids\":[\"rbxassetid://7547169285\",\"rbxassetid://7546645118\"],\"color\":[165,165,159,255]},\"ice\":{\"ids\":[\"rbxassetid://7547171356\",\"rbxassetid://7546645118\"],\"color\":[255,255,255,255]},\"marble\":{\"ids\":[\"rbxassetid://7547177270\",\"rbxassetid://7546645118\"],\"color\":[199,199,199,255]},\"metal\":{\"ids\":[\"rbxassetid://7547288171\",\"rbxassetid://7546645118\"],\"color\":[199,199,199,255]},\"pebble\":{\"ids\":[\"rbxassetid://7547291361\",\"rbxassetid://7546645118\"],\"color\":[208,208,208,255]},\"corrodedmetal\":{\"ids\":[\"rbxassetid://7547184629\",\"rbxassetid://7546645118\"],\"color\":[159,119,95,200]},\"sand\":{\"ids\":[\"rbxassetid://7547295153\",\"rbxassetid://7546645118\"],\"color\":[220,220,220,255]},\"slate\":{\"ids\":[\"rbxassetid://7547298114\",\"rbxassetid://7547298323\"],\"color\":[193,193,193,255]},\"wood\":{\"ids\":[\"rbxassetid://7547303225\",\"rbxassetid://7547298786\"],\"color\":[227,227,227,255]},\"woodplanks\":{\"ids\":[\"rbxassetid://7547332968\",\"rbxassetid://7546645118\"],\"color\":[212,209,203,255]},\"asphalt\":{\"ids\":[\"rbxassetid://9873267379\",\"rbxassetid://9438410548\"],\"color\":[123,123,123,234]},\"basalt\":{\"ids\":[\"rbxassetid://9873270487\",\"rbxassetid://9438413638\"],\"color\":[154,154,153,238]},\"crackedlava\":{\"ids\":[\"rbxassetid://9438582231\",\"rbxassetid://9438453972\"],\"color\":[74,78,80,156]},\"glacier\":{\"ids\":[\"rbxassetid://9438851661\",\"rbxassetid://9438453972\"],\"color\":[226,229,229,243]},\"ground\":{\"ids\":[\"rbxassetid://9439044431\",\"rbxassetid://9438453972\"],\"color\":[114,114,112,240]},\"leafygrass\":{\"ids\":[\"rbxassetid://9873288083\",\"rbxassetid://9438453972\"],\"color\":[121,117,113,234]},\"limestone\":{\"ids\":[\"rbxassetid://9873289812\",\"rbxassetid://9438453972\"],\"color\":[235,234,230,250]},\"mud\":{\"ids\":[\"rbxassetid://9873319819\",\"rbxassetid://9438453972\"],\"color\":[130,130,130,252]},\"pavement\":{\"ids\":[\"rbxassetid://9873322398\",\"rbxassetid://9438453972\"],\"color\":[142,142,144,236]},\"rock\":{\"ids\":[\"rbxassetid://9873515198\",\"rbxassetid://9438453972\"],\"color\":[154,154,154,248]},\"salt\":{\"ids\":[\"rbxassetid://9439566986\",\"rbxassetid://9438453972\"],\"color\":[220,220,221,255]},\"sandstone\":{\"ids\":[\"rbxassetid://9873521380\",\"rbxassetid://9438453972\"],\"color\":[174,171,169,246]},\"snow\":{\"ids\":[\"rbxassetid://9439632387\",\"rbxassetid://9438453972\"],\"color\":[218,218,218,255]}}";
public static IReadOnlyDictionary<string, string> PresetFlags = new Dictionary<string, string>
{
{ "HTTP.Log", "DFLogHttpTraceLight" },
{ "HTTP.Proxy.Enable", "DFFlagDebugEnableHttpProxy" },
{ "HTTP.Proxy.Address.1", "DFStringDebugPlayerHttpProxyUrl" },
{ "HTTP.Proxy.Address.2", "DFStringHttpCurlProxyHostAndPort" },
{ "HTTP.Proxy.Address.3", "DFStringHttpCurlProxyHostAndPortForExternalUrl" },
{ "Rendering.Framerate", "DFIntTaskSchedulerTargetFps" },
{ "Rendering.Fullscreen", "FFlagHandleAltEnterFullscreenManually" },
{ "Rendering.TexturePack", "FStringPartTexturePackTable2022" },
{ "Rendering.DPI.Disable", "DFFlagDisableDPIScale" },
{ "Rendering.DPI.Variable", "DFFlagVariableDPIScale2" },
{ "Rendering.Mode.D3D11", "FFlagDebugGraphicsPreferD3D11" },
{ "Rendering.Mode.D3D10", "FFlagDebugGraphicsPreferD3D11FL10" },
{ "Rendering.Mode.Vulkan", "FFlagDebugGraphicsPreferVulkan" },
{ "Rendering.Mode.Vulkan.Fix", "FFlagRenderVulkanFixMinimizeWindow" },
{ "Rendering.Mode.OpenGL", "FFlagDebugGraphicsPreferOpenGL" },
{ "Rendering.Lighting.Voxel", "DFFlagDebugRenderForceTechnologyVoxel" },
{ "Rendering.Lighting.ShadowMap", "FFlagDebugForceFutureIsBrightPhase2" },
{ "Rendering.Lighting.Future", "FFlagDebugForceFutureIsBrightPhase3" },
{ "UI.Hide", "DFIntCanHideGuiGroupId" },
{ "UI.FlagState", "FStringDebugShowFlagState" },
{ "UI.Menu.GraphicsSlider", "FFlagFixGraphicsQuality" },
{ "UI.Menu.Style.DisableV2", "FFlagDisableNewIGMinDUA" },
{ "UI.Menu.Style.EnableV4", "FFlagEnableInGameMenuControls" }
};
// only one missing here is Metal because lol
public static IReadOnlyDictionary<string, string> RenderingModes => new Dictionary<string, string>
{
{ "Automatic", "" },
{ "Vulkan", "FFlagDebugGraphicsPreferVulkan" },
{ "Direct3D 11", "FFlagDebugGraphicsPreferD3D11" },
{ "Direct3D 10", "FFlagDebugGraphicsPreferD3D11FL10" },
{ "OpenGL", "FFlagDebugGraphicsPreferOpenGL" }
{ "Automatic", "None" },
{ "Vulkan", "Vulkan" },
{ "Direct3D 11", "D3D11" },
{ "Direct3D 10", "D3D10" },
{ "OpenGL", "OpenGL" }
};
public static IReadOnlyDictionary<string, string> LightingTechnologies => new Dictionary<string, string>
public static IReadOnlyDictionary<string, string> LightingModes => new Dictionary<string, string>
{
{ "Chosen by game", "" },
{ "Voxel (Phase 1)", "DFFlagDebugRenderForceTechnologyVoxel" },
{ "ShadowMap (Phase 2)", "FFlagDebugForceFutureIsBrightPhase2" },
{ "Future (Phase 3)", "FFlagDebugForceFutureIsBrightPhase3" }
{ "Chosen by game", "None" },
{ "Voxel (Phase 1)", "Voxel" },
{ "ShadowMap (Phase 2)", "ShadowMap" },
{ "Future (Phase 3)", "Future" }
};
// this is one hell of a dictionary definition lmao
@ -33,8 +71,8 @@
"Default",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", null },
{ "FFlagEnableInGameMenuControls", null }
{ "DisableV2", null },
{ "EnableV4", null }
}
},
@ -42,8 +80,8 @@
"Version 1 (2015)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "True" },
{ "FFlagEnableInGameMenuControls", "False" }
{ "DisableV2", "True" },
{ "EnableV4", "False" }
}
},
@ -51,8 +89,8 @@
"Version 2 (2020)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "False" },
{ "FFlagEnableInGameMenuControls", "False" }
{ "DisableV2", "False" },
{ "EnableV4", "False" }
}
},
@ -60,8 +98,8 @@
"Version 4 (2023)",
new Dictionary<string, string?>
{
{ "FFlagDisableNewIGMinDUA", "True" },
{ "FFlagEnableInGameMenuControls", "True" }
{ "DisableV2", "True" },
{ "EnableV4", "True" }
}
}
};
@ -82,22 +120,6 @@
}
}
// this will set the flag to the corresponding value if the condition is true
// if the condition is not true, the flag will be erased
public void SetValueIf(bool condition, string key, object? value)
{
if (condition)
SetValue(key, value);
else if (GetValue(key) is not null)
SetValue(key, null);
}
public void SetValueOnce(string key, object? value)
{
if (GetValue(key) is null)
SetValue(key, value);
}
// this returns null if the fflag doesn't exist
public string? GetValue(string key)
{
@ -108,15 +130,54 @@
return null;
}
public void SetPreset(string prefix, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
SetValue(pair.Value, value);
}
public void SetPresetOnce(string key, object? value)
{
if (GetPreset(key) is null)
SetPreset(key, value);
}
public void SetPresetEnum(string prefix, string target, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
{
if (pair.Key.StartsWith($"{prefix}.{target}"))
SetValue(pair.Value, value);
else
SetValue(pair.Value, null);
}
}
public string? GetPreset(string name) => GetValue(PresetFlags[name]);
public string GetPresetEnum(IReadOnlyDictionary<string, string> mapping, string prefix, string value)
{
foreach (var mode in mapping)
{
if (mode.Key == mapping.First().Key)
continue;
if (App.FastFlags.GetPreset($"{prefix}.{mode.Value}") == value)
return mode.Key;
}
return mapping.First().Key;
}
public override void Load()
{
base.Load();
// set to 9999 by default if it doesnt already exist
SetValueOnce("DFIntTaskSchedulerTargetFps", 9999);
SetValueOnce("FFlagHandleAltEnterFullscreenManually", "False");
SetValueOnce("DFFlagDisableDPIScale", "True");
SetValueOnce("DFFlagVariableDPIScale2", "False");
SetPresetOnce("Rendering.Framerate", 9999);
SetPresetOnce("Rendering.Fullscreen", "False");
SetPresetOnce("Rendering.DPI.Disable", "True");
SetPresetOnce("Rendering.DPI.Variable", "False");
}
}
}

View File

@ -39,6 +39,7 @@
</Style>
</ui:Button.Style>
</ui:Button>
<ToggleButton Content="Show preset flags" Click="ToggleButton_Click" Margin="12,0,0,0" />
</StackPanel>
</Grid>
</ui:UiPage>

View File

@ -1,20 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using Bloxstrap.UI.Elements.Dialogs;
@ -35,14 +22,17 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
private void ReloadList(bool showPresets = false)
{
// refresh list on page load to synchronize with preset page
_fastFlagList.Clear();
var presetFlags = FastFlagManager.PresetFlags.Values;
foreach (var pair in App.FastFlags.Prop)
{
if (!showPresets && presetFlags.Contains(pair.Key))
continue;
var entry = new FastFlag
{
Enabled = true,
@ -62,6 +52,9 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
DataGrid.ItemsSource = _fastFlagList;
}
// refresh list on page load to synchronize with preset page
private void Page_Loaded(object sender, RoutedEventArgs e) => ReloadList();
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
int index = e.Row.GetIndex();
@ -135,5 +128,11 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
App.FastFlags.SetValue(entry.Name, null);
}
}
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton button)
ReloadList(button.IsChecked ?? false);
}
}
}

View File

@ -122,7 +122,7 @@
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Choose which lighting technology should be forced enabled in all games." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ComboBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding LightingTechnologies.Keys, Mode=OneTime}" Text="{Binding SelectedLightingTechnology, Mode=TwoWay}" />
<ComboBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding LightingModes.Keys, Mode=OneTime}" Text="{Binding SelectedLightingMode, Mode=TwoWay}" />
</ui:CardControl>
<ui:CardControl Margin="0,8,0,0">
<ui:CardControl.Header>

View File

@ -15,85 +15,51 @@ namespace Bloxstrap.UI.ViewModels.Menu
public bool HttpRequestLogging
{
get => App.FastFlags.GetValue("DFLogHttpTraceLight") is not null;
set => App.FastFlags.SetValue("DFLogHttpTraceLight", value ? 12 : null);
get => App.FastFlags.GetPreset("HTTP.Log") is not null;
set => App.FastFlags.SetPreset("HTTP.Log", value ? 12 : null);
}
public string HttpRequestProxy
{
get => App.FastFlags.GetValue("DFStringDebugPlayerHttpProxyUrl") ?? "";
get => App.FastFlags.GetPreset("HTTP.Proxy.Address.1") ?? "";
set
{
bool? boolValue = null;
string? stringValue = null;
if (!String.IsNullOrEmpty(value))
{
boolValue = true;
stringValue = value;
}
App.FastFlags.SetValue("DFFlagDebugEnableHttpProxy", boolValue);
App.FastFlags.SetValue("DFStringDebugPlayerHttpProxyUrl", stringValue);
App.FastFlags.SetValue("DFStringHttpCurlProxyHostAndPort", stringValue);
App.FastFlags.SetValue("DFStringHttpCurlProxyHostAndPortForExternalUrl", stringValue);
App.FastFlags.SetPreset("HTTP.Proxy.Enable", String.IsNullOrEmpty(value) ? null : true);
App.FastFlags.SetPreset("HTTP.Proxy.Address", String.IsNullOrEmpty(value) ? null : value);
}
}
public string StateOverlayFlags
{
get => App.FastFlags.GetValue("FStringDebugShowFlagState") ?? "";
set => App.FastFlags.SetValue("FStringDebugShowFlagState", String.IsNullOrEmpty(value) ? null : value);
get => App.FastFlags.GetPreset("UI.FlagState") ?? "";
set => App.FastFlags.SetPreset("UI.FlagState", String.IsNullOrEmpty(value) ? null : value);
}
public int FramerateLimit
{
get => int.TryParse(App.FastFlags.GetValue("DFIntTaskSchedulerTargetFps"), out int x) ? x : 60;
set => App.FastFlags.SetValue("DFIntTaskSchedulerTargetFps", value);
get => int.TryParse(App.FastFlags.GetPreset("Rendering.Framerate"), out int x) ? x : 60;
set => App.FastFlags.SetPreset("Rendering.Framerate", value);
}
public IReadOnlyDictionary<string, string> RenderingModes => FastFlagManager.RenderingModes;
public string SelectedRenderingMode
{
get
{
foreach (var mode in RenderingModes)
{
if (App.FastFlags.GetValue(mode.Value) == "True")
return mode.Key;
}
return "Automatic";
}
set
{
foreach (var mode in RenderingModes)
{
if (mode.Key != "Automatic")
App.FastFlags.SetValue(mode.Value, null);
}
if (value == "Automatic")
return;
App.FastFlags.SetValue(RenderingModes[value], "True");
App.FastFlags.SetValueIf(value == "Vulkan", "FFlagRenderVulkanFixMinimizeWindow", "True");
}
get => App.FastFlags.GetPresetEnum(RenderingModes, "Rendering.Mode", "True");
set => App.FastFlags.SetPresetEnum("Rendering.Mode", RenderingModes[value], "True");
}
public bool AlternateGraphicsSelectorEnabled
{
get => App.FastFlags.GetValue("FFlagFixGraphicsQuality") == "True";
set => App.FastFlags.SetValue("FFlagFixGraphicsQuality", value ? "True" : null);
get => App.FastFlags.GetPreset("UI.Menu.GraphicsSlider") == "True";
set => App.FastFlags.SetPreset("UI.Menu.GraphicsSlider", value ? "True" : null);
}
public bool Pre2022TexturesEnabled
{
get => App.FastFlags.GetValue("FStringPartTexturePackTable2022") == FastFlagManager.OldTexturesFlagValue;
set => App.FastFlags.SetValue("FStringPartTexturePackTable2022", value ? FastFlagManager.OldTexturesFlagValue : null);
get => App.FastFlags.GetPreset("Rendering.TexturePack") == FastFlagManager.OldTexturesFlagValue;
set => App.FastFlags.SetPreset("Rendering.TexturePack", value ? FastFlagManager.OldTexturesFlagValue : null);
}
public IReadOnlyDictionary<string, Dictionary<string, string?>> IGMenuVersions => FastFlagManager.IGMenuVersions;
@ -109,7 +75,7 @@ namespace Bloxstrap.UI.ViewModels.Menu
foreach (var flag in version.Value)
{
if (App.FastFlags.GetValue(flag.Key) != flag.Value)
if (App.FastFlags.GetPreset($"UI.Menu.Style.{flag.Key}") != flag.Value)
flagsMatch = false;
}
@ -117,51 +83,28 @@ namespace Bloxstrap.UI.ViewModels.Menu
return version.Key;
}
return "Default";
return IGMenuVersions.First().Key;
}
set
{
foreach (var flag in IGMenuVersions[value])
{
App.FastFlags.SetValue(flag.Key, flag.Value);
}
App.FastFlags.SetPreset($"UI.Menu.Style.{flag.Key}", flag.Value);
}
}
public IReadOnlyDictionary<string, string> LightingTechnologies => FastFlagManager.LightingTechnologies;
public IReadOnlyDictionary<string, string> LightingModes => FastFlagManager.LightingModes;
// this is basically the same as the code for rendering selection, maybe this could be abstracted in some way?
public string SelectedLightingTechnology
public string SelectedLightingMode
{
get
{
foreach (var mode in LightingTechnologies)
{
if (App.FastFlags.GetValue(mode.Value) == "True")
return mode.Key;
}
return LightingTechnologies.First().Key;
}
set
{
foreach (var mode in LightingTechnologies)
{
if (mode.Key != LightingTechnologies.First().Key)
App.FastFlags.SetValue(mode.Value, null);
}
if (value != LightingTechnologies.First().Key)
App.FastFlags.SetValue(LightingTechnologies[value], "True");
}
get => App.FastFlags.GetPresetEnum(LightingModes, "Rendering.Lighting", "True");
set => App.FastFlags.SetPresetEnum("Rendering.Lighting", LightingModes[value], "True");
}
public bool GuiHidingEnabled
{
get => App.FastFlags.GetValue("DFIntCanHideGuiGroupId") == "32380007";
set => App.FastFlags.SetValue("DFIntCanHideGuiGroupId", value ? "32380007" : null);
get => App.FastFlags.GetPreset("UI.Hide") == "32380007";
set => App.FastFlags.SetPreset("UI.Hide", value ? "32380007" : null);
}
}
}