Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Moder.Core/App.axaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<Application
RequestedThemeVariant="Default"
x:Class="Moder.Core.App"
xmlns="https://github.com/avaloniaui"
xmlns:cv="using:Moder.Core.Converters"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:styling="clr-namespace:FluentAvalonia.Styling;assembly=FluentAvalonia"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
<styling:FluentAvaloniaTheme />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="avares://Moder.Core/Resources/AppThemeStyleSetter.axaml" />
<StyleInclude Source="/Controls/DirectorySelector.axaml" />
<StyleInclude Source="avares://Moder.Core/Controls/Controls.axaml" />
</Application.Styles>

<Application.Resources>
<ResourceDictionary>
<cv:EnumTypeToStringListConverter x:Key="EnumTypeToStringListConverter" />
<FontFamily x:Key="FluentIconFontFamily">Segoe Fluent Icons</FontFamily>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://Moder.Core/Resources/AppThemeResource.axaml" />
<MergeResourceInclude Source="avares://Moder.Core/Resources/AppThemeResource.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
2 changes: 2 additions & 0 deletions Moder.Core/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Moder.Core;
public class App : Application
{
public const string AppVersion = "0.1.0-alpha";
public const string CodeRepositoryUrl = "https://github.com/ModerCore/Moder";
public static new App Current => (App)Application.Current!;
public static IServiceProvider Services => Current._serviceProvider;
public static string AppConfigFolder { get; } =
Expand Down Expand Up @@ -131,6 +132,7 @@ private static HostApplicationBuilder CreateHostBuilder()
builder.Services.AddViewSingleton<SideBarControlView, SideBarControlViewModel>();
builder.Services.AddViewSingleton<WorkSpaceControlView, WorkSpaceControlViewModel>();
builder.Services.AddViewTransient<CharacterEditorControlView, CharacterEditorControlViewModel>();
builder.Services.AddViewTransient<AppSettingsView, AppSettingsViewModel>();
builder.Services.AddViewSingleton<StatusBarControlView, StatusBarControlViewModel>();
builder.Services.AddTransient<TraitSelectionWindowViewModel>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void ShowDropdown()
ipc.SetValue(AssociatedObject, true);
}

AssociatedObject.SetCurrentValue<bool>(AutoCompleteBox.IsDropDownOpenProperty, true);
AssociatedObject.SetCurrentValue(AutoCompleteBox.IsDropDownOpenProperty, true);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Moder.Core/Controls/Controls.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StyleInclude Source="avares://Moder.Core/Controls/DirectorySelector.axaml" />
</Styles>
15 changes: 8 additions & 7 deletions Moder.Core/Controls/DirectorySelector.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Styles
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Moder.Core.Controls">
xmlns:controls="clr-namespace:Moder.Core.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<controls:DirectorySelector />
</Design.PreviewWith>
Expand All @@ -11,19 +11,20 @@
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors
Errors="{TemplateBinding DataValidationErrors.Errors}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
Errors="{TemplateBinding DataValidationErrors.Errors}">
VerticalAlignment="Center">
<StackPanel
HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="4">
<TextBox
Width="280"
MaxHeight="55"
IsReadOnly="True"
Text="{TemplateBinding DirectoryPath}" />
MaxHeight="55"
Text="{TemplateBinding DirectoryPath,
Mode=TwoWay}"
Width="280" />
<Button Command="{TemplateBinding SelectDirectoryCommand}" Content="{TemplateBinding SelectorCaption}" />
</StackPanel>
</DataValidationErrors>
Expand Down
18 changes: 12 additions & 6 deletions Moder.Core/Controls/DirectorySelector.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public string SelectorCaption
get => GetValue(SelectorCaptionProperty);
set => SetValue(SelectorCaptionProperty, value);
}
public static readonly StyledProperty<string> SelectorCaptionProperty
= AvaloniaProperty.Register<DirectorySelector, string>(nameof(SelectorCaption));

public static readonly StyledProperty<string> SelectorCaptionProperty = AvaloniaProperty.Register<
DirectorySelector,
string
>(nameof(SelectorCaption));

public string DirectoryPath
{
get => GetValue(DirectoryPathProperty);
Expand All @@ -24,7 +26,7 @@ public string DirectoryPath
public static readonly StyledProperty<string> DirectoryPathProperty = AvaloniaProperty.Register<
DirectorySelector,
string
>(nameof(DirectoryPath), enableDataValidation:true);
>(nameof(DirectoryPath), enableDataValidation: true, defaultBindingMode: BindingMode.TwoWay);

public ICommand SelectDirectoryCommand
{
Expand All @@ -33,8 +35,12 @@ public ICommand SelectDirectoryCommand
}
public static readonly StyledProperty<ICommand> SelectDirectoryCommandProperty =
AvaloniaProperty.Register<DirectorySelector, ICommand>(nameof(SelectDirectoryCommand));

protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)

protected override void UpdateDataValidation(
AvaloniaProperty property,
BindingValueType state,
Exception? error
)
{
if (property == DirectoryPathProperty)
{
Expand Down
34 changes: 0 additions & 34 deletions Moder.Core/Converters/EnumTypeToStringListConverter.cs

This file was deleted.

30 changes: 6 additions & 24 deletions Moder.Core/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
using System.Globalization;
using Avalonia.Styling;
using EnumsNET;
using Moder.Core.Models;
using Moder.Core.Models.Game;

namespace Moder.Core.Extensions;

public static class EnumExtensions
{
public static object? ToEnum(this string str, Type enumType)
{
try
{
if (Enums.TryParse(enumType, str, true, out var result))
{
return result;
}
}
catch (Exception)
{
// ignored
}

return null;
}

public static string ToGameLocalizationLanguage(this GameLanguage language)
{
if (language == GameLanguage.Default)
Expand All @@ -47,7 +29,7 @@ public static string ToGameLocalizationLanguage(this GameLanguage language)
_ => throw new ArgumentOutOfRangeException(nameof(language), language, null)
};
}

private static GameLanguage GetSystemLanguage()
{
var cultureInfo = CultureInfo.CurrentUICulture;
Expand Down Expand Up @@ -88,15 +70,15 @@ private static GameLanguage GetSystemLanguage()

return GameLanguage.English;
}

public static ThemeVariant ToThemeVariant(this ThemeMode type)
{
return type switch
{
ThemeMode.Light => new ThemeVariant(nameof(ThemeMode.Light), ThemeVariant.Light),
ThemeMode.Dark => new ThemeVariant(nameof(ThemeMode.Dark), ThemeVariant.Dark),
ThemeMode.DarkSlateGray => new ThemeVariant(nameof(ThemeMode.DarkSlateGray), ThemeVariant.Dark),
_ => ThemeVariant.Default,
ThemeMode.Light => ThemeVariant.Light,
ThemeMode.Dark => ThemeVariant.Dark,
ThemeMode.Default => ThemeVariant.Default,
_ => ThemeVariant.Default
};
}
}
4 changes: 3 additions & 1 deletion Moder.Core/Messages/CompleteAppInitializeMessage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Moder.Core.Messages;

public sealed record CompleteAppInitializeMessage;
public sealed record CompleteAppInitializeMessage;

public sealed record CompleteAppSettingsMessage;
7 changes: 7 additions & 0 deletions Moder.Core/Models/AppThemeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Moder.Core.Models;

public sealed class AppThemeInfo(string displayName, ThemeMode mode)
{
public string DisplayName { get; } = displayName;
public ThemeMode Mode { get; } = mode;
}
2 changes: 1 addition & 1 deletion Moder.Core/Models/Game/Modifiers/LeafModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class LeafModifier : IModifier, IEquatable<LeafModifier>
public const string CustomModifierTooltipKey = "custom_modifier_tooltip";

/// <summary>
/// 从 <see cref="Leaf"/> 构建一个叶子修饰符, <see cref="LocalizationKey"/> 属性被设置为 <c>leaf.Key</c>
/// 从 <see cref="Leaf"/> 构建一个叶子修饰符
/// </summary>
/// <param name="leaf">叶子</param>
/// <returns></returns>
Expand Down
4 changes: 2 additions & 2 deletions Moder.Core/Models/ThemeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Moder.Core.Models;

public enum ThemeMode : byte
{
Default,
Light,
Dark,
DarkSlateGray
Dark
}
13 changes: 0 additions & 13 deletions Moder.Core/Models/ThemeVariants.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Moder.Core/Models/Vo/TraitVo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed partial class TraitVo : ObservableObject, IEquatable<TraitVo>
// }

/// <summary>
/// 是否已选择, 当值改变时, 发送 <see cref="SelectedTraitChangedMessage"/> 通知
/// 是否已选择
/// </summary>
[ObservableProperty]
public partial bool IsSelected { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Moder.Core/Moder.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@
<ItemGroup>
<Folder Include="Assets\CodeEditor\Grammars\" />
<Folder Include="Assets\CodeEditor\Themes\" />
<Folder Include="Converters\" />
</ItemGroup>
</Project>
13 changes: 3 additions & 10 deletions Moder.Core/Resources/AppThemeResource.axaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:Moder.Core.Models">
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="{x:Static res:ThemeVariants.Light}">
<ResourceDictionary x:Key="{x:Static ThemeVariant.Light}">
<SolidColorBrush x:Key="BackgroundBrush">#fafafa</SolidColorBrush>
<SolidColorBrush x:Key="ForegroundBrush">#1e1e1e</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="{x:Static res:ThemeVariants.Dark}">
<ResourceDictionary x:Key="{x:Static ThemeVariant.Dark}">
<SolidColorBrush x:Key="BackgroundBrush">#252526</SolidColorBrush>
<SolidColorBrush x:Key="ForegroundBrush">#f5f5f5</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="{x:Static res:ThemeVariants.DarkSlateGray}">
<SolidColorBrush x:Key="BackgroundBrush">DarkSlateGray</SolidColorBrush>
<SolidColorBrush x:Key="ForegroundBrush">Azure</SolidColorBrush>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

</ResourceDictionary>
2 changes: 1 addition & 1 deletion Moder.Core/Services/Config/AppSettingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GameLanguage GameLanguage
} = GameLanguage.Default;

[MemoryPackOrder(3)]
public string AppLanguage
public string AppLanguageCode
{
get;
set => SetProperty(ref field, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ public string GetDisplayValue(LeafModifier leafModifier, string modifierDisplayF
return leafModifier.Value;
}

private static bool IsAllUppercase(string value)
{
return value.All(char.IsUpper);
}

private static char GetDisplayDigits(string modifierDescription)
{
var displayDigits = '1';
Expand Down
5 changes: 1 addition & 4 deletions Moder.Core/Services/GameResources/TerrainService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Frozen;
using MethodTimer;
using Moder.Core.Services.GameResources.Base;
using Moder.Core.Services.GameResources.Localization;
using ParadoxPower.Process;

namespace Moder.Core.Services.GameResources;
Expand All @@ -17,13 +16,11 @@ public sealed class TerrainService : CommonResourcesService<TerrainService, Froz
/// 未在文件中定义的地形
/// </summary>
private readonly FrozenSet<string> _unitTerrain;
private readonly LocalizationService _localizationService;

[Time("加载地形资源")]
public TerrainService(LocalizationService localizationService)
public TerrainService()
: base(Path.Combine(Keywords.Common, "terrain"), WatcherFilter.Text)
{
_localizationService = localizationService;
//TODO: 从数据库读取
_unitTerrain = ["fort", "river"];
}
Expand Down
11 changes: 11 additions & 0 deletions Moder.Core/Services/MessageBoxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ public async Task ErrorAsync(string message)
);
await dialog.ShowAsync();
}

public async Task InfoAsync(string message)
{
var dialog = MessageBoxManager.GetMessageBoxStandard(
Resource.Common_Tip,
message,
ButtonEnum.Ok,
Icon.Info
);
await dialog.ShowAsync();
}
}
2 changes: 1 addition & 1 deletion Moder.Core/Views/Game/CharacterEditorControlView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CharacterEditorControlView()
// TODO: 状态栏
private void InitializeTextEditor()
{
var options = new ParadoxRegistryOptions(App.Current.RequestedThemeVariant);
var options = new ParadoxRegistryOptions(App.Current.ActualThemeVariant);
Editor.Options.HighlightCurrentLine = true;
var installation = Editor.InstallTextMate(options);

Expand Down
Loading
Loading