1+ using System . Text ;
12using CommunityToolkit . Mvvm . ComponentModel ;
23using CommunityToolkit . Mvvm . Messaging ;
34using Microsoft . Extensions . DependencyInjection ;
45using Microsoft . UI . Xaml . Controls ;
56using Microsoft . UI . Xaml . Documents ;
67using Moder . Core . Messages ;
78using Moder . Core . Models . Character ;
9+ using Moder . Core . Parser ;
810using Moder . Core . Services ;
11+ using Moder . Core . Services . GameResources ;
912using Moder . Language . Strings ;
1013
1114namespace Moder . Core . Models . Vo ;
1215
13- public sealed partial class TraitVo ( Trait trait , string localisationName ) : ObservableObject , IEquatable < TraitVo >
16+ public sealed partial class TraitVo ( Trait trait , string localisationName )
17+ : ObservableObject ,
18+ IEquatable < TraitVo >
1419{
1520 public string Name => trait . Name ;
1621 public Trait Trait => trait ;
1722 public string LocalisationName => localisationName ;
1823 public TextBlock Description => GetDescription ( ) ;
1924
25+ private static readonly ModifierService ModifierService =
26+ App . Current . Services . GetRequiredService < ModifierService > ( ) ;
27+ private static readonly LocalisationService LocalisationService =
28+ App . Current . Services . GetRequiredService < LocalisationService > ( ) ;
29+
30+ private static readonly string Separator = new ( '-' , 25 ) ;
31+
2032 /// <summary>
2133 /// 是否已选择, 当值改变时, 发送 <see cref="SelectedTraitChangedMessage"/> 通知
2234 /// </summary>
@@ -31,11 +43,7 @@ partial void OnIsSelectedChanged(bool value)
3143 private TextBlock GetDescription ( )
3244 {
3345 var textBox = new TextBlock ( ) ;
34- foreach (
35- var inline in App
36- . Current . Services . GetRequiredService < ModifierService > ( )
37- . GetModifierInlines ( trait . AllModifiers )
38- )
46+ foreach ( var inline in ModifierService . GetModifierInlines ( trait . AllModifiers ) )
3947 {
4048 textBox . Inlines . Add ( inline ) ;
4149 }
@@ -45,9 +53,47 @@ var inline in App
4553 textBox . Inlines . Add ( new Run { Text = Resource . ModifierDisplay_Empty } ) ;
4654 }
4755
56+ textBox . Inlines . Add ( new LineBreak ( ) ) ;
57+ textBox . Inlines . Add ( new Run { Text = Separator } ) ;
58+ textBox . Inlines . Add ( new LineBreak ( ) ) ;
59+
60+ var traitDesc = LocalisationService . GetValue ( $ "{ trait . Name } _desc") ;
61+
62+ foreach ( var chars in GetCleanText ( traitDesc ) . Chunk ( 15 ) )
63+ {
64+ textBox . Inlines . Add ( new Run { Text = new string ( chars ) } ) ;
65+ textBox . Inlines . Add ( new LineBreak ( ) ) ;
66+ }
67+
68+ if ( textBox . Inlines [ ^ 1 ] is LineBreak )
69+ {
70+ textBox . Inlines . RemoveAt ( textBox . Inlines . Count - 1 ) ;
71+ }
4872 return textBox ;
4973 }
5074
75+ private static string GetCleanText ( string rawText )
76+ {
77+ string text ;
78+ if ( LocalizationFormatParser . TryParse ( rawText , out var formats ) )
79+ {
80+ var sb = new StringBuilder ( ) ;
81+ foreach ( var format in formats )
82+ {
83+ sb . Append (
84+ format . Type == LocalizationFormatType . TextWithColor ? format . Text [ 1 ..] : format . Text
85+ ) ;
86+ }
87+ text = sb . ToString ( ) ;
88+ }
89+ else
90+ {
91+ text = rawText ;
92+ }
93+
94+ return text ;
95+ }
96+
5197 public bool Equals ( TraitVo ? other )
5298 {
5399 if ( other is null )
@@ -72,4 +118,4 @@ public override int GetHashCode()
72118 {
73119 return Name . GetHashCode ( ) ;
74120 }
75- }
121+ }
0 commit comments