Rework converters and improve string formatting

This commit is contained in:
pizzaboxer 2023-10-25 00:11:08 +01:00
parent db8edbc94f
commit f542de5421
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 40 additions and 23 deletions

View File

@ -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">
<Application.Resources>
@ -16,6 +16,7 @@
<FontFamily x:Key="Rubik">pack://application:,,,/Resources/Fonts/#Rubik Light</FontFamily>
<converters:ResourceConverter x:Key="ResourceConverter" />
<converters:StringFormatConverter x:Key="StringFormatConverter" />
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -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)

View File

@ -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));
}
}
}

View File

@ -48,7 +48,7 @@
<controls:OptionControl
Header="{x:Static resources:Strings.Menu_FastFlags_Presets_Debug_HttpProxyAddress_Title}"
Description="{x:Static resources:Strings.Menu_FastFlags_Presets_Debug_HttpProxyAddress_Description}">
<ui:ToggleSwitch IsChecked="{Binding HttpRequestProxy, Mode=TwoWay}" />
<ui:TextBox Margin="5,0,0,0" Padding="10,5,10,5" Width="200" Text="{Binding HttpRequestProxy, Mode=TwoWay}" />
</controls:OptionControl>
<controls:OptionControl
@ -59,7 +59,7 @@
</StackPanel>
<TextBlock Text="{x:Static resources:Strings.Common_Presets}" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<controls:MarkdownTextBlock MarkdownText="{Binding Direct3DExclusiveFullscreenInfoText}"/>
<controls:MarkdownTextBlock MarkdownText="{Binding Source={x:Static resources:Strings.Menu_FastFlags_Presets_D3DExclusiveFullscreenInfo}, Converter={StaticResource StringFormatConverter}, ConverterParameter='https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#exclusive-fullscreen'}" />
<controls:OptionControl
Header="{x:Static resources:Strings.Menu_FastFlags_Presets_FPSLimit_Title}"
@ -95,7 +95,7 @@
<controls:OptionControl
Header="{x:Static resources:Strings.Menu_FastFlags_Presets_HideGuis_Title}"
Description="{Binding HideGuisDescriptionText}"
Description="{Binding Source={x:Static resources:Strings.Menu_FastFlags_Presets_HideGuis_Description}, Converter={StaticResource StringFormatConverter}, ConverterParameter='https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#gui-hiding|https://www.roblox.com/groups/32380007/Bloxstrap'}"
HelpLink="https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#gui-hiding">
<ui:ToggleSwitch IsChecked="{Binding GuiHidingEnabled, Mode=TwoWay}" />
</controls:OptionControl>

View File

@ -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");
}
}
}