diff --git a/interface/wpf/.gitignore b/interface/AvaloniaUI_debug_interface/.gitignore similarity index 100% rename from interface/wpf/.gitignore rename to interface/AvaloniaUI_debug_interface/.gitignore diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml b/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml new file mode 100644 index 0000000..dcaa0f3 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml.cs b/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml.cs new file mode 100644 index 0000000..5129bd0 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/App.axaml.cs @@ -0,0 +1,80 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using Avalonia.Markup.Xaml; +using debug_interface.ViewModels; +using debug_interface.Views; +using System.Linq; + +namespace debug_interface +{ + /// + /// 应用程序的后置代码,负责初始化和启动主窗口。 + /// + public partial class App : Application + { + //GPT GENERATED + //public override void Initialize() + //{ + // AvaloniaXamlLoader.Load(this); + //} + + //public override void OnFrameworkInitializationCompleted() + //{ + // if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + // { + // // 创建主窗口的ViewModel实例 + // var mainWindowViewModel = new MainWindowViewModel(); + + // // 设置主窗口及其数据上下文 + // desktop.MainWindow = new MainWindow + // { + // DataContext = mainWindowViewModel + // }; + // } + + // base.OnFrameworkInitializationCompleted(); + //} + + + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + // Avoid duplicate validations from both Avalonia and the CommunityToolkit. + // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins + DisableAvaloniaDataAnnotationValidation(); + + var mainWindowViewModel = new MainWindowViewModel(); + + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } + + + } +} \ No newline at end of file diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Assets/avalonia-logo.ico b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/avalonia-logo.ico differ diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Assets/eesast_logo_32x32.png b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/eesast_logo_32x32.png new file mode 100644 index 0000000..49670ad Binary files /dev/null and b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/eesast_logo_32x32.png differ diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Assets/nailong.jpg b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/nailong.jpg new file mode 100644 index 0000000..729a90a Binary files /dev/null and b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/nailong.jpg differ diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Assets/tangseng.jpg b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/tangseng.jpg new file mode 100644 index 0000000..ec0ea9a Binary files /dev/null and b/interface/AvaloniaUI_debug_interface/debug_interface/Assets/tangseng.jpg differ diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Program.cs b/interface/AvaloniaUI_debug_interface/debug_interface/Program.cs new file mode 100644 index 0000000..b8f7177 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/Program.cs @@ -0,0 +1,22 @@ +锘縰sing Avalonia; +using System; + +namespace debug_interface +{ + internal sealed class Program + { + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); + } +} diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/ViewLocator.cs b/interface/AvaloniaUI_debug_interface/debug_interface/ViewLocator.cs new file mode 100644 index 0000000..fed91cc --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/ViewLocator.cs @@ -0,0 +1,32 @@ +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using debug_interface.ViewModels; +using System; + +namespace debug_interface +{ + public class ViewLocator : IDataTemplate + { + + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } + } +} diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/CharacterViewModel.cs b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/CharacterViewModel.cs new file mode 100644 index 0000000..a89f004 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/CharacterViewModel.cs @@ -0,0 +1,104 @@ +锘縰sing CommunityToolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; + +namespace debug_interface.ViewModels +{ + public partial class CharacterViewModel : ViewModelBase + { + [ObservableProperty] + private string name = "瑙掕壊"; // 榛樿瑙掕壊鍚嶏紝鍙敱鏈嶅姟鍣ㄦ洿鏂 + + [ObservableProperty] + private int hp = 1000; // 琛閲忥紝鍙敱鏈嶅姟鍣ㄥ姩鎬佹洿鏂 + + // 涓诲姩鐘舵侊紙鍗曚竴锛 + // 鍙兘鍊: "绌虹疆","寮閲","鏀诲嚮","閲婃斁鎶鑳","寤洪","绉诲姩" + [ObservableProperty] + private string activeState = "绌虹疆"; + //public string ActiveState + //{ + // get => activeState; + // set + // { + // if (value == activeState) return; + // activeState = value; + // OnPropertyChanged(nameof(DisplayStates)); + // } + //} + // 琚姩鐘舵侊紙鍙彔鍔狅級 + // 鍙兘鍊: "鑷寸洸","鍑婚","瀹氳韩","闅愯韩" 绛夛紝鍙敱鏈嶅姟鍣ㄦ帶鍒跺鍑 + public ObservableCollection PassiveStates { get; } + + // 瑁呭娓呭崟锛氱敤鍚嶇О+鏁伴噺琛ㄧず銆傚 {"灏忚鐡":2, "闉嬪瓙":1, "澶ф姢鐩":1, "鍑鍖栬嵂姘":3} + // 涓轰簡鏂逛究缁戝畾锛岀敤 ObservableCollection 鏉ュ瓨鍌ㄨ澶囨潯鐩紝姣忎釜鏉$洰鍖呭惈Name鍜孋ount + public ObservableCollection EquipmentInventory { get; } + + // 鐘舵侀夐」鍒楄〃鍜岃澶囬夐」鍒楄〃宸蹭笉鍐嶄娇鐢–omboBox閫夋嫨锛岃屾槸绾睍绀恒 + // 濡傛灉闇瑕佷粛淇濈暀鍙敱鏈嶅姟鍣ㄦ洿鏂帮紝浣嗚繖閲屼笉浼氬啀鐢ㄤ簬浜や簰銆 + + // 鏋勯犲嚱鏁 + public CharacterViewModel() + { + PassiveStates = new ObservableCollection(); + EquipmentInventory = new ObservableCollection(); + } + + // 鐢ㄤ簬UI灞曠ず鐘舵佸瓧绗︿覆 + // 鏍煎紡: 锛堜富鍔細xx 琚姩锛歺x yy zz锛 + public string DisplayStates + { + get + { + var sb = new StringBuilder(); + sb.Append("锛堜富鍔細").Append(ActiveState).Append(" 琚姩锛"); + if (PassiveStates.Count > 0) + sb.Append(string.Join(" ", PassiveStates)); + else + sb.Append("鏃"); + sb.Append("锛"); + return sb.ToString(); + } + } + + // 鐢ㄤ簬UI灞曠ず瑁呭瀛楃涓 + // 鏍煎紡: 瑁呭锛 灏忚鐡秞2 闉嬪瓙x1 澶ф姢鐩緓1 鍑鍖栬嵂姘磝3 + public string DisplayEquipments + { + get + { + if (EquipmentInventory.Count == 0) + { + return "瑁呭锛氭棤"; + } + var parts = EquipmentInventory.Select(e => $"{e.Name}x{e.Count}"); + return "瑁呭锛" + string.Join(" ", parts); + } + } + + // 褰揂ctiveState鎴朠assiveStates鍙樺寲鍚庯紝閫氱煡UI鏇存柊 DisplayStates + partial void OnActiveStateChanged(string oldValue, string newValue) + { + OnPropertyChanged(nameof(DisplayStates)); + } + + // 濡傛灉琚姩鐘舵佸垪琛ㄦ洿鏂帮紝闇瑕佽皟鐢∣nPropertyChanged(nameof(DisplayStates)) + // 鍙互鍦ㄦ湇鍔″櫒鏇存柊閫昏緫涓皟鐢ㄣ + + // 鍚岀悊锛屽綋EquipmentInventory鍙樺寲鏃讹紝闇瑕佹洿鏂癉isplayEquipments + // 鍙互鍦ㄦ坊鍔/绉婚櫎瑁呭鍚庤皟鐢∣nPropertyChanged(nameof(DisplayEquipments)) + } + + // 瀹氫箟瑁呭绫 + public class EquipmentItem + { + public string Name { get; set; } + public int Count { get; set; } + public EquipmentItem(string name, int count) + { + Name = name; + Count = count; + } + } +} diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/MainWindowViewModel.cs b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..4f56818 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,94 @@ +锘// ViewModels/MainWindowViewModel.cs +using CommunityToolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +using System; +using System.Timers; + +namespace debug_interface.ViewModels +{ + public partial class MainWindowViewModel : ViewModelBase + { + public ObservableCollection RedTeamCharacters { get; } + public ObservableCollection BlueTeamCharacters { get; } + + [ObservableProperty] + private string someBuildingInfo = "绾㈡柟寤虹瓚淇℃伅..."; + + [ObservableProperty] + private string anotherBuildingInfo = "钃濇柟寤虹瓚淇℃伅..."; + + [ObservableProperty] + private string currentTime = DateTime.Now.ToString("HH:mm:ss"); + + [ObservableProperty] + private int redScore = 0; + + [ObservableProperty] + private int blueScore = 0; + + [ObservableProperty] + private bool isBlueView = true; + + public bool IsRedView + { + get => !IsBlueView; + set => IsBlueView = !value; + } + + [ObservableProperty] + private string gameLog = "鍦板浘..."; + + private Timer _timer; + + public MainWindowViewModel() + { + RedTeamCharacters = new ObservableCollection(); + BlueTeamCharacters = new ObservableCollection(); + + // 鍒濆鍖栬鑹诧紝缁欐瘡涓鑹蹭笉鍚岀殑鏁版嵁浠ョず渚嬪彲鍙樻 + for (int i = 0; i < 6; i++) + { + var redChar = new CharacterViewModel() + { + Name = "绾㈡柟瑙掕壊" + (i + 1), + Hp = 1000 * (i + 1), + ActiveState = i % 2 == 0 ? "鏀诲嚮" : "绉诲姩", + }; + redChar.PassiveStates.Add("鑷寸洸"); + if (i % 3 == 0) redChar.PassiveStates.Add("瀹氳韩"); + redChar.EquipmentInventory.Add(new EquipmentItem("灏忚鐡", 2)); + if (i % 2 == 0) + redChar.EquipmentInventory.Add(new EquipmentItem("澶ф姢鐩", 1)); + + RedTeamCharacters.Add(redChar); + + var blueChar = new CharacterViewModel() + { + Name = "钃濇柟瑙掕壊" + (i + 1), + Hp = 1500 + i * 500, + ActiveState = "绌虹疆", + }; + blueChar.PassiveStates.Add("闅愯韩"); + //blueChar.PassiveStates.Remove("鑷寸洸"); + blueChar.EquipmentInventory.Add(new EquipmentItem("鍑鍖栬嵂姘", 3)); + if (i % 2 == 1) + blueChar.EquipmentInventory.Add(new EquipmentItem("闉嬪瓙", 1)); + + BlueTeamCharacters.Add(blueChar); + } + + _timer = new Timer(1000); + _timer.Elapsed += Timer_Elapsed; + _timer.Start(); + } + + private void Timer_Elapsed(object? sender, ElapsedEventArgs e) + { + CurrentTime = DateTime.Now.ToString("HH:mm:ss"); + Avalonia.Threading.Dispatcher.UIThread.Post(() => + { + OnPropertyChanged(nameof(CurrentTime)); + }); + } + } +} diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/ViewModelBase.cs b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..ad59015 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/ViewModels/ViewModelBase.cs @@ -0,0 +1,8 @@ +锘縰sing CommunityToolkit.Mvvm.ComponentModel; + +namespace debug_interface.ViewModels +{ + public class ViewModelBase : ObservableObject + { + } +} diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml b/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml new file mode 100644 index 0000000..8fa1df2 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml.cs b/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..a99b6fc --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/Views/MainWindow.axaml.cs @@ -0,0 +1,35 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace debug_interface.Views +{ + + //public partial class MainWindow : Window + //{ + // public MainWindow() + // { + // InitializeComComponent(); + // } + //} + + /// + /// 主窗口的后置代码,负责初始化组件。 + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); // 在调试模式下附加开发者工具 +#endif + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } + +} \ No newline at end of file diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/app.manifest b/interface/AvaloniaUI_debug_interface/debug_interface/app.manifest new file mode 100644 index 0000000..e82cc43 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/app.manifest @@ -0,0 +1,18 @@ +锘 + + + + + + + + + + + + + diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.csproj b/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.csproj new file mode 100644 index 0000000..e67c5d1 --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.csproj @@ -0,0 +1,34 @@ +锘 + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + + + + + + + None + All + + + + diff --git a/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.sln b/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.sln new file mode 100644 index 0000000..d738b5d --- /dev/null +++ b/interface/AvaloniaUI_debug_interface/debug_interface/debug_interface.sln @@ -0,0 +1,25 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35219.272 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "debug_interface", "debug_interface.csproj", "{4F12E13F-A324-4E71-8003-DB2D5C8C4643}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F12E13F-A324-4E71-8003-DB2D5C8C4643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F12E13F-A324-4E71-8003-DB2D5C8C4643}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F12E13F-A324-4E71-8003-DB2D5C8C4643}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F12E13F-A324-4E71-8003-DB2D5C8C4643}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D394446-2C5E-440D-9F3A-09B7DFD3714A} + EndGlobalSection +EndGlobal