From f542de5421f8ca43e5912d5fbec6585245925d1d Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Wed, 25 Oct 2023 00:11:08 +0100 Subject: [PATCH] Rework converters and improve string formatting --- Bloxstrap/App.xaml | 3 +- .../{ => UI}/Converters/ResourceConverter.cs | 6 ++-- .../UI/Converters/StringFormatConverter.cs | 33 +++++++++++++++++++ .../UI/Elements/Menu/Pages/FastFlagsPage.xaml | 6 ++-- .../UI/ViewModels/Menu/FastFlagsViewModel.cs | 15 --------- 5 files changed, 40 insertions(+), 23 deletions(-) rename Bloxstrap/{ => UI}/Converters/ResourceConverter.cs (82%) create mode 100644 Bloxstrap/UI/Converters/StringFormatConverter.cs diff --git a/Bloxstrap/App.xaml b/Bloxstrap/App.xaml index 44454f3..6af052a 100644 --- a/Bloxstrap/App.xaml +++ b/Bloxstrap/App.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Bloxstrap" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - xmlns:converters="clr-namespace:Bloxstrap.Converters" + xmlns:converters="clr-namespace:Bloxstrap.UI.Converters" ShutdownMode="OnExplicitShutdown" DispatcherUnhandledException="GlobalExceptionHandler"> @@ -16,6 +16,7 @@ pack://application:,,,/Resources/Fonts/#Rubik Light + diff --git a/Bloxstrap/Converters/ResourceConverter.cs b/Bloxstrap/UI/Converters/ResourceConverter.cs similarity index 82% rename from Bloxstrap/Converters/ResourceConverter.cs rename to Bloxstrap/UI/Converters/ResourceConverter.cs index 0b443f7..ee1d696 100644 --- a/Bloxstrap/Converters/ResourceConverter.cs +++ b/Bloxstrap/UI/Converters/ResourceConverter.cs @@ -1,6 +1,6 @@ using System.Windows.Data; -namespace Bloxstrap.Converters +namespace Bloxstrap.UI.Converters { internal class ResourceConverter : IValueConverter { @@ -17,9 +17,7 @@ namespace Bloxstrap.Converters string parameterStr = parameter.ToString()!; string resourceName = parameterStr + valueStr; - string resourceValue = Resources.Strings.ResourceManager.GetStringSafe(resourceName); - - return resourceValue; + return Resources.Strings.ResourceManager.GetStringSafe(resourceName); } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) diff --git a/Bloxstrap/UI/Converters/StringFormatConverter.cs b/Bloxstrap/UI/Converters/StringFormatConverter.cs new file mode 100644 index 0000000..7830763 --- /dev/null +++ b/Bloxstrap/UI/Converters/StringFormatConverter.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Bloxstrap.UI.Converters +{ + public class StringFormatConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string? valueStr = value as string; + string? parameterStr = parameter as string; + + if (valueStr is null) + return ""; + + if (parameterStr is null) + return valueStr; + + string[] args = parameterStr.Split(new char[] { '|' }); + + return string.Format(valueStr, args); + } + + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotImplementedException(nameof(ConvertBack)); + } + } +} diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml index 57dd3ec..a0ce253 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml @@ -48,7 +48,7 @@ - + - + diff --git a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs index 9a50639..c596519 100644 --- a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs @@ -147,20 +147,5 @@ namespace Bloxstrap.UI.ViewModels.Menu get => App.FastFlags.GetPreset("UI.Hide") == "32380007"; set => App.FastFlags.SetPreset("UI.Hide", value ? "32380007" : null); } - - public string Direct3DExclusiveFullscreenInfoText - { - get => string.Format( - Resources.Strings.Menu_FastFlags_Presets_D3DExclusiveFullscreenInfo, - "https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#exclusive-fullscreen"); - } - - public string HideGuisDescriptionText - { - get => string.Format( - Resources.Strings.Menu_FastFlags_Presets_HideGuis_Description, - "https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#gui-hiding", - "https://www.roblox.com/groups/32380007/Bloxstrap"); - } } }