metadata special name handling

This commit is contained in:
Lightczx
2024-01-31 17:25:43 +08:00
parent 592525d149
commit a3dcfd3804
6 changed files with 56 additions and 4 deletions

View File

@@ -51,7 +51,7 @@ internal sealed partial class DescriptionTextBlock : ContentControl
private static void OnDescriptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextBlock textBlock = (TextBlock)((DescriptionTextBlock)d).Content;
ReadOnlySpan<char> description = (string)e.NewValue;
ReadOnlySpan<char> description = MetadataSpecialNames.Handle((string)e.NewValue);
UpdateDescription(textBlock, description);
}

View File

@@ -0,0 +1,34 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Text;
using System.Text.RegularExpressions;
namespace Snap.Hutao.Control.Text;
internal static partial class MetadataSpecialNames
{
public static string Handle(string input)
{
if (input.AsSpan()[0] is not '#')
{
return input;
}
StringBuilder resultBuilder = new(input);
resultBuilder
.Replace("{MATEAVATAR#SEXPRO[INFO_MALE_PRONOUN_BOYD|INFO_FEMALE_PRONOUN_GIRLD]}", SH.ControlTextMetadataSpecialNameMetaAvatarSexProD)
.Replace("{PLAYERAVATAR#SEXPRO[INFO_MALE_PRONOUN_HE|INFO_FEMALE_PRONOUN_SHE]}", SH.ControlTextMetadataSpecialNamePlayerAvatarSexPro)
.Replace("{REALNAME[ID(1)]}", SH.ControlTextMetadataSpecialNameRealNameId1);
input = resultBuilder.ToString();
// {M#.}{F#.}
input = MaleFemaleRegex().Replace(input, SH.ControlTextMetadataSpecialNameMaleFemale);
return input[1..];
}
[GeneratedRegex("\\{M#(.*?)\\}\\{F#(.*?)\\}")]
private static partial Regex MaleFemaleRegex();
}

View File

@@ -96,7 +96,7 @@ internal sealed class WindowSubclass : IDisposable
{
if (window is IMinMaxInfoHandler handler)
{
handler.HandleMinMaxInfo(ref *(MINMAXINFO*)lParam.Value, options.GetRasterizationScale());
handler.HandleMinMaxInfo(ref *(MINMAXINFO*)lParam, options.GetRasterizationScale());
}
break;
@@ -118,7 +118,7 @@ internal sealed class WindowSubclass : IDisposable
{
if (window.SystemBackdrop is IBackdropNeedEraseBackground)
{
return (LRESULT)(int)(BOOL)true;
return (LRESULT)(int)BOOL.TRUE;
}
break;

View File

@@ -159,6 +159,18 @@
<data name="ControlPanelPanelSelectorDropdownListName" xml:space="preserve">
<value>列表</value>
</data>
<data name="ControlTextMetadataSpecialNameMaleFemale" xml:space="preserve">
<value>旅行者(男):$1\r\n旅行者$2</value>
</data>
<data name="ControlTextMetadataSpecialNameMetaAvatarSexProD" xml:space="preserve">
<value>王子/公主</value>
</data>
<data name="ControlTextMetadataSpecialNamePlayerAvatarSexPro" xml:space="preserve">
<value>他/她</value>
</data>
<data name="ControlTextMetadataSpecialNameRealNameId1" xml:space="preserve">
<value>流浪者</value>
</data>
<data name="CoreExceptionServiceDatabaseCorruptedMessage" xml:space="preserve">
<value>数据库已损坏:{0}</value>
</data>

View File

@@ -5,13 +5,17 @@ namespace Snap.Hutao.Win32.Foundation;
internal readonly struct BOOL
{
public static readonly BOOL TRUE = 1;
public readonly int Value;
public BOOL(bool value) => Value = value ? 1 : 0;
public static unsafe implicit operator int(BOOL value) => *(int*)&value;
public static unsafe implicit operator BOOL(int value) => *(BOOL*)&value;
public static implicit operator BOOL(bool value) => new(value);
public static implicit operator bool(BOOL value) => value.Value != 0;
public static implicit operator bool(BOOL value) => value != 0;
}

View File

@@ -6,4 +6,6 @@ namespace Snap.Hutao.Win32.Foundation;
internal readonly struct LPARAM
{
public readonly nint Value;
public static unsafe implicit operator void*(LPARAM value) => *(void**)&value;
}