Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调试界面v1 #72

Merged
merged 3 commits into from
Dec 24, 2024
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
File renamed without changes.
20 changes: 20 additions & 0 deletions interface/AvaloniaUI_debug_interface/debug_interface/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- App.axaml -->

<Application
x:Class="debug_interface.App"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:debug_interface"
xmlns:views="using:YourAppNamespace.Views"
RequestedThemeVariant="Light">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>

<FluentTheme />
</Application.Styles>
</Application>
80 changes: 80 additions & 0 deletions interface/AvaloniaUI_debug_interface/debug_interface/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 应用程序的后置代码,负责初始化和启动主窗口。
/// </summary>
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<DataAnnotationsValidationPlugin>().ToArray();

// remove each entry found
foreach (var plugin in dataValidationPluginsToRemove)
{
BindingPlugins.DataValidators.Remove(plugin);
}
}


}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions interface/AvaloniaUI_debug_interface/debug_interface/Program.cs
Original file line number Diff line number Diff line change
@@ -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<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<string> PassiveStates { get; }

// 瑁呭娓呭崟锛氱敤鍚嶇О+鏁伴噺琛ㄧず銆傚 {"灏忚鐡�":2, "闉嬪瓙":1, "澶ф姢鐩�":1, "鍑�鍖栬嵂姘�":3}
// 涓轰簡鏂逛究缁戝畾锛岀敤 ObservableCollection 鏉ュ瓨鍌ㄨ澶囨潯鐩紝姣忎釜鏉$洰鍖呭惈Name鍜孋ount
public ObservableCollection<EquipmentItem> EquipmentInventory { get; }

// 鐘舵�侀�夐」鍒楄〃鍜岃澶囬�夐」鍒楄〃宸蹭笉鍐嶄娇鐢–omboBox閫夋嫨锛岃�屾槸绾睍绀恒��
// 濡傛灉闇�瑕佷粛淇濈暀鍙敱鏈嶅姟鍣ㄦ洿鏂帮紝浣嗚繖閲屼笉浼氬啀鐢ㄤ簬浜や簰銆�

// 鏋勯�犲嚱鏁�
public CharacterViewModel()
{
PassiveStates = new ObservableCollection<string>();
EquipmentInventory = new ObservableCollection<EquipmentItem>();
}

// 鐢ㄤ簬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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<CharacterViewModel> RedTeamCharacters { get; }
public ObservableCollection<CharacterViewModel> 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<CharacterViewModel>();
BlueTeamCharacters = new ObservableCollection<CharacterViewModel>();

// 鍒濆鍖栬鑹诧紝缁欐瘡涓鑹蹭笉鍚岀殑鏁版嵁浠ョず渚嬪彲鍙樻��
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));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
锘縰sing CommunityToolkit.Mvvm.ComponentModel;

namespace debug_interface.ViewModels
{
public class ViewModelBase : ObservableObject
{
}
}
Loading
Loading