Add option for resetting flag config to defaults

This commit is contained in:
pizzaboxer 2024-10-01 23:56:32 +01:00
parent ed36e7f2dd
commit 5b9c035b16
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 74 additions and 24 deletions

View File

@ -2614,6 +2614,15 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Reset everything to defaults.
/// </summary>
public static string Menu_FastFlags_Reset_Title {
get {
return ResourceManager.GetString("Menu.FastFlags.Reset.Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fast Flags.
/// </summary>

View File

@ -1231,4 +1231,7 @@ Please manually delete Bloxstrap.exe from the install location or try restarting
<data name="Common.Analytics" xml:space="preserve">
<value>Analytics</value>
</data>
<data name="Menu.FastFlags.Reset.Title" xml:space="preserve">
<value>Reset everything to defaults</value>
</data>
</root>

View File

@ -165,7 +165,13 @@
</ComboBox>
</controls:OptionControl>
<ui:CardAction Margin="0,24,0,0" Icon="EditSettings24" Command="{Binding OpenFastFlagEditorCommand}">
<controls:OptionControl
Margin="0,24,0,0"
Header="{x:Static resources:Strings.Menu_FastFlags_Reset_Title}">
<ui:ToggleSwitch IsChecked="{Binding ResetConfiguration, Mode=TwoWay}" />
</controls:OptionControl>
<ui:CardAction Margin="0,8,0,0" Icon="EditSettings24" Command="{Binding OpenFastFlagEditorCommand}">
<StackPanel>
<TextBlock FontSize="14" Text="{x:Static resources:Strings.Menu_FastFlagEditor_Title}" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="{x:Static resources:Strings.Menu_FastFlags_Editor_Description}" Padding="0,0,16,0" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />

View File

@ -2,6 +2,7 @@
using System.Windows.Input;
using Bloxstrap.UI.ViewModels.Settings;
using Wpf.Ui.Mvvm.Contracts;
namespace Bloxstrap.UI.Elements.Settings.Pages
{
@ -10,14 +11,37 @@ namespace Bloxstrap.UI.Elements.Settings.Pages
/// </summary>
public partial class FastFlagsPage
{
bool _initialLoad = false;
private bool _initialLoad = false;
private FastFlagsViewModel _viewModel = null!;
public FastFlagsPage()
{
DataContext = new FastFlagsViewModel(this);
SetupViewModel();
InitializeComponent();
}
private void SetupViewModel()
{
_viewModel = new FastFlagsViewModel();
_viewModel.OpenFlagEditorEvent += OpenFlagEditor;
_viewModel.RequestPageReloadEvent += (_, _) => SetupViewModel();
DataContext = _viewModel;
}
private void OpenFlagEditor(object? sender, EventArgs e)
{
if (Window.GetWindow(this) is INavigationWindow window)
{
if (App.State.Prop.ShowFFlagEditorWarning)
window.Navigate(typeof(FastFlagEditorWarningPage));
else
window.Navigate(typeof(FastFlagEditorPage));
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// refresh datacontext on page load to synchronize with editor page
@ -28,7 +52,7 @@ namespace Bloxstrap.UI.Elements.Settings.Pages
return;
}
DataContext = new FastFlagsViewModel(this);
SetupViewModel();
}
private void ValidateInt32(object sender, TextCompositionEventArgs e) => e.Handled = e.Text != "-" && !Int32.TryParse(e.Text, out int _);

View File

@ -1,38 +1,24 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Wpf.Ui.Mvvm.Contracts;
using CommunityToolkit.Mvvm.Input;
using Bloxstrap.UI.Elements.Settings.Pages;
using Bloxstrap.Enums.FlagPresets;
namespace Bloxstrap.UI.ViewModels.Settings
{
public class FastFlagsViewModel : NotifyPropertyChangedViewModel
{
private readonly Page _page;
private Dictionary<string, object>? _preResetFlags;
public FastFlagsViewModel(Page page)
{
_page = page;
}
public event EventHandler? RequestPageReloadEvent;
public event EventHandler? OpenFlagEditorEvent;
private void OpenFastFlagEditor()
{
if (Window.GetWindow(_page) is INavigationWindow window)
{
if (App.State.Prop.ShowFFlagEditorWarning)
window.Navigate(typeof(FastFlagEditorWarningPage));
else
window.Navigate(typeof(FastFlagEditorPage));
}
}
private void OpenFastFlagEditor() => OpenFlagEditorEvent?.Invoke(this, EventArgs.Empty);
public ICommand OpenFastFlagEditorCommand => new RelayCommand(OpenFastFlagEditor);
#if DEBUG
public Visibility ShowDebugFlags => Visibility.Visible;
#else
@ -192,5 +178,27 @@ namespace Bloxstrap.UI.ViewModels.Settings
get => App.FastFlags.GetPreset("Rendering.TerrainTextureQuality") == "0";
set => App.FastFlags.SetPreset("Rendering.TerrainTextureQuality", value ? "0" : null);
}
public bool ResetConfiguration
{
get => _preResetFlags is not null;
set
{
if (value)
{
_preResetFlags = new(App.FastFlags.Prop);
App.FastFlags.Prop.Clear();
}
else
{
App.FastFlags.Prop = _preResetFlags!;
_preResetFlags = null;
}
RequestPageReloadEvent?.Invoke(this, EventArgs.Empty);
}
}
}
}