Skip to content

Commit 2f0d96a

Browse files
authored
Feat: 添加设置页面 (#47)
1 parent 059281f commit 2f0d96a

32 files changed

+505
-214
lines changed

Moder.Core/App.axaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
<Application
2-
RequestedThemeVariant="Default"
32
x:Class="Moder.Core.App"
43
xmlns="https://github.com/avaloniaui"
5-
xmlns:cv="using:Moder.Core.Converters"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
65
xmlns:styling="clr-namespace:FluentAvalonia.Styling;assembly=FluentAvalonia"
7-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
6+
RequestedThemeVariant="Default">
87
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
98

109
<Application.Styles>
1110
<FluentTheme />
1211
<styling:FluentAvaloniaTheme />
1312
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
1413
<StyleInclude Source="avares://Moder.Core/Resources/AppThemeStyleSetter.axaml" />
15-
<StyleInclude Source="/Controls/DirectorySelector.axaml" />
14+
<StyleInclude Source="avares://Moder.Core/Controls/Controls.axaml" />
1615
</Application.Styles>
1716

1817
<Application.Resources>
1918
<ResourceDictionary>
20-
<cv:EnumTypeToStringListConverter x:Key="EnumTypeToStringListConverter" />
19+
<FontFamily x:Key="FluentIconFontFamily">Segoe Fluent Icons</FontFamily>
2120
<ResourceDictionary.MergedDictionaries>
22-
<ResourceInclude Source="avares://Moder.Core/Resources/AppThemeResource.axaml" />
21+
<MergeResourceInclude Source="avares://Moder.Core/Resources/AppThemeResource.axaml" />
2322
</ResourceDictionary.MergedDictionaries>
2423
</ResourceDictionary>
2524
</Application.Resources>

Moder.Core/App.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace Moder.Core;
3232
public class App : Application
3333
{
3434
public const string AppVersion = "0.1.0-alpha";
35+
public const string CodeRepositoryUrl = "https://github.com/ModerCore/Moder";
3536
public static new App Current => (App)Application.Current!;
3637
public static IServiceProvider Services => Current._serviceProvider;
3738
public static string AppConfigFolder { get; } =
@@ -131,6 +132,7 @@ private static HostApplicationBuilder CreateHostBuilder()
131132
builder.Services.AddViewSingleton<SideBarControlView, SideBarControlViewModel>();
132133
builder.Services.AddViewSingleton<WorkSpaceControlView, WorkSpaceControlViewModel>();
133134
builder.Services.AddViewTransient<CharacterEditorControlView, CharacterEditorControlViewModel>();
135+
builder.Services.AddViewTransient<AppSettingsView, AppSettingsViewModel>();
134136
builder.Services.AddViewSingleton<StatusBarControlView, StatusBarControlViewModel>();
135137
builder.Services.AddTransient<TraitSelectionWindowViewModel>();
136138

Moder.Core/Behaviors/AutoCompleteZeroMinimumPrefixLengthDropdownBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void ShowDropdown()
9393
ipc.SetValue(AssociatedObject, true);
9494
}
9595

96-
AssociatedObject.SetCurrentValue<bool>(AutoCompleteBox.IsDropDownOpenProperty, true);
96+
AssociatedObject.SetCurrentValue(AutoCompleteBox.IsDropDownOpenProperty, true);
9797
}
9898
}
9999
}

Moder.Core/Controls/Controls.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2+
<StyleInclude Source="avares://Moder.Core/Controls/DirectorySelector.axaml" />
3+
</Styles>

Moder.Core/Controls/DirectorySelector.axaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Styles
22
xmlns="https://github.com/avaloniaui"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:controls="clr-namespace:Moder.Core.Controls">
3+
xmlns:controls="clr-namespace:Moder.Core.Controls"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
55
<Design.PreviewWith>
66
<controls:DirectorySelector />
77
</Design.PreviewWith>
@@ -11,19 +11,20 @@
1111
<Setter Property="Template">
1212
<ControlTemplate>
1313
<DataValidationErrors
14+
Errors="{TemplateBinding DataValidationErrors.Errors}"
1415
HorizontalAlignment="Center"
15-
VerticalAlignment="Center"
1616
HorizontalContentAlignment="Center"
17-
Errors="{TemplateBinding DataValidationErrors.Errors}">
17+
VerticalAlignment="Center">
1818
<StackPanel
1919
HorizontalAlignment="Center"
2020
Orientation="Horizontal"
2121
Spacing="4">
2222
<TextBox
23-
Width="280"
24-
MaxHeight="55"
2523
IsReadOnly="True"
26-
Text="{TemplateBinding DirectoryPath}" />
24+
MaxHeight="55"
25+
Text="{TemplateBinding DirectoryPath,
26+
Mode=TwoWay}"
27+
Width="280" />
2728
<Button Command="{TemplateBinding SelectDirectoryCommand}" Content="{TemplateBinding SelectorCaption}" />
2829
</StackPanel>
2930
</DataValidationErrors>

Moder.Core/Controls/DirectorySelector.axaml.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ public string SelectorCaption
1313
get => GetValue(SelectorCaptionProperty);
1414
set => SetValue(SelectorCaptionProperty, value);
1515
}
16-
public static readonly StyledProperty<string> SelectorCaptionProperty
17-
= AvaloniaProperty.Register<DirectorySelector, string>(nameof(SelectorCaption));
18-
16+
public static readonly StyledProperty<string> SelectorCaptionProperty = AvaloniaProperty.Register<
17+
DirectorySelector,
18+
string
19+
>(nameof(SelectorCaption));
20+
1921
public string DirectoryPath
2022
{
2123
get => GetValue(DirectoryPathProperty);
@@ -24,7 +26,7 @@ public string DirectoryPath
2426
public static readonly StyledProperty<string> DirectoryPathProperty = AvaloniaProperty.Register<
2527
DirectorySelector,
2628
string
27-
>(nameof(DirectoryPath), enableDataValidation:true);
29+
>(nameof(DirectoryPath), enableDataValidation: true, defaultBindingMode: BindingMode.TwoWay);
2830

2931
public ICommand SelectDirectoryCommand
3032
{
@@ -33,8 +35,12 @@ public ICommand SelectDirectoryCommand
3335
}
3436
public static readonly StyledProperty<ICommand> SelectDirectoryCommandProperty =
3537
AvaloniaProperty.Register<DirectorySelector, ICommand>(nameof(SelectDirectoryCommand));
36-
37-
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
38+
39+
protected override void UpdateDataValidation(
40+
AvaloniaProperty property,
41+
BindingValueType state,
42+
Exception? error
43+
)
3844
{
3945
if (property == DirectoryPathProperty)
4046
{

Moder.Core/Converters/EnumTypeToStringListConverter.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

Moder.Core/Extensions/EnumExtensions.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
using System.Globalization;
22
using Avalonia.Styling;
3-
using EnumsNET;
43
using Moder.Core.Models;
54
using Moder.Core.Models.Game;
65

76
namespace Moder.Core.Extensions;
87

98
public static class EnumExtensions
109
{
11-
public static object? ToEnum(this string str, Type enumType)
12-
{
13-
try
14-
{
15-
if (Enums.TryParse(enumType, str, true, out var result))
16-
{
17-
return result;
18-
}
19-
}
20-
catch (Exception)
21-
{
22-
// ignored
23-
}
24-
25-
return null;
26-
}
27-
2810
public static string ToGameLocalizationLanguage(this GameLanguage language)
2911
{
3012
if (language == GameLanguage.Default)
@@ -47,7 +29,7 @@ public static string ToGameLocalizationLanguage(this GameLanguage language)
4729
_ => throw new ArgumentOutOfRangeException(nameof(language), language, null)
4830
};
4931
}
50-
32+
5133
private static GameLanguage GetSystemLanguage()
5234
{
5335
var cultureInfo = CultureInfo.CurrentUICulture;
@@ -88,15 +70,15 @@ private static GameLanguage GetSystemLanguage()
8870

8971
return GameLanguage.English;
9072
}
91-
73+
9274
public static ThemeVariant ToThemeVariant(this ThemeMode type)
9375
{
9476
return type switch
9577
{
96-
ThemeMode.Light => new ThemeVariant(nameof(ThemeMode.Light), ThemeVariant.Light),
97-
ThemeMode.Dark => new ThemeVariant(nameof(ThemeMode.Dark), ThemeVariant.Dark),
98-
ThemeMode.DarkSlateGray => new ThemeVariant(nameof(ThemeMode.DarkSlateGray), ThemeVariant.Dark),
99-
_ => ThemeVariant.Default,
78+
ThemeMode.Light => ThemeVariant.Light,
79+
ThemeMode.Dark => ThemeVariant.Dark,
80+
ThemeMode.Default => ThemeVariant.Default,
81+
_ => ThemeVariant.Default
10082
};
10183
}
10284
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
namespace Moder.Core.Messages;
22

3-
public sealed record CompleteAppInitializeMessage;
3+
public sealed record CompleteAppInitializeMessage;
4+
5+
public sealed record CompleteAppSettingsMessage;

Moder.Core/Models/AppThemeInfo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Moder.Core.Models;
2+
3+
public sealed class AppThemeInfo(string displayName, ThemeMode mode)
4+
{
5+
public string DisplayName { get; } = displayName;
6+
public ThemeMode Mode { get; } = mode;
7+
}

0 commit comments

Comments
 (0)