feat: 白色主题UI + 签到接口修复 + 物理/地形Bug修复 + WPF启动器重构
CI / Go Backend (push) Canceled after 0s

This commit is contained in:
xyou
2026-08-09 21:32:55 +08:00
parent f70b061d1a
commit abd4548dff
20 changed files with 3559 additions and 449 deletions
+7
View File
@@ -4,4 +4,11 @@ namespace MRCC.Launcher;
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
DispatcherUnhandledException += (s, a) => Program.Log($"UI异常: {a.Exception}");
AppDomain.CurrentDomain.UnhandledException += (s, a) => Program.Log($"未处理异常: {a.ExceptionObject}");
TaskScheduler.UnobservedTaskException += (s, a) => Program.Log($"任务异常: {a.Exception}");
}
}
+5
View File
@@ -0,0 +1,5 @@
<Window x:Class="MRCC.Launcher.GameWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Game" Height="450" Width="800">
</Window>
+11
View File
@@ -0,0 +1,11 @@
using System.Windows;
namespace MRCC.Launcher;
public partial class GameWindow : Window
{
public GameWindow()
{
InitializeComponent();
}
}
+8 -14
View File
@@ -1,31 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<RootNamespace>MRCC.Launcher</RootNamespace>
<AssemblyName>MRCC.Launcher</AssemblyName>
<AssemblyName>RedCircuit</AssemblyName>
<PublishDir>..\..\build\</PublishDir>
<Nullable>enable</Nullable>
<LangVersion>14.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationManifest>app.manifest</ApplicationManifest>
<StartupObject>MRCC.Launcher.Program</StartupObject>
<StartupObject>Program</StartupObject>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4129.50" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCL-CE\PCL.Core\PCL.Core.csproj" />
<Content Include="..\..\prototype\**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" LinkBase="game\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="metadata.json">
<LogicalName>PCL.metadata.json</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
+6 -123
View File
@@ -1,128 +1,11 @@
<Window x:Class="MRCC.Launcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MRCC Launcher"
Height="600" Width="900"
Title="RedCircuit Launcher"
Height="720" Width="1100"
WindowStartupLocation="CenterScreen"
Background="#0E1116"
WindowStyle="SingleBorderWindow"
ResizeMode="CanResize"
MinHeight="500" MinWidth="700">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 侧边栏 -->
<Border Grid.Column="0" Background="#161B22" BorderBrush="#2A3441" BorderThickness="0,0,1,0">
<DockPanel Margin="0,20,0,0">
<!-- Logo -->
<StackPanel DockPanel.Dock="Top" Margin="20,0,20,20">
<TextBlock Text="MRCC" FontSize="20" FontWeight="Bold" Foreground="#E83229"
FontFamily="Consolas"/>
<TextBlock Text="MineRedCircuitcraft" FontSize="10" Foreground="#6B7280"
Margin="0,2,0,0"/>
</StackPanel>
<!-- 导航菜单 -->
<StackPanel DockPanel.Dock="Top" Margin="10,0">
<RadioButton x:Name="NavHome" Content="首页" IsChecked="True"
Style="{StaticResource NavRadioButtonStyle}"
Checked="OnNavChecked" Tag="home"/>
<RadioButton Content="下载"
Style="{StaticResource NavRadioButtonStyle}"
Checked="OnNavChecked" Tag="download"/>
<RadioButton Content="设置"
Style="{StaticResource NavRadioButtonStyle}"
Checked="OnNavChecked" Tag="settings"/>
<RadioButton Content="关于"
Style="{StaticResource NavRadioButtonStyle}"
Checked="OnNavChecked" Tag="about"/>
</StackPanel>
<!-- 底部版本信息 -->
<TextBlock DockPanel.Dock="Bottom" Text="v1.0.0-dev" Foreground="#4B5563"
FontSize="10" Margin="20,0,20,10" VerticalAlignment="Bottom"/>
</DockPanel>
</Border>
<!-- 主内容区 -->
<Grid Grid.Column="1">
<!-- 首页 -->
<StackPanel x:Name="PageHome" Margin="32,28" Visibility="Visible">
<TextBlock Text="欢迎来到 MRCC" FontSize="24" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="红石逻辑 x 像素方块 x 模拟电路" FontSize="13" Foreground="#6B7280"
Margin="0,6,0,24"/>
<Border Background="#161B22" CornerRadius="8" Padding="20" Margin="0,0,0,12">
<StackPanel>
<TextBlock Text="开始游戏" FontSize="14" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="点击下方按钮启动 MRCC 客户端" FontSize="11" Foreground="#6B7280"
Margin="0,4,0,12"/>
<Button Content="启动游戏" Width="120" Height="36" HorizontalAlignment="Left"
Background="#E83229" Foreground="White" BorderThickness="0"
FontSize="13" FontWeight="Bold" Click="OnLaunchGame"/>
</StackPanel>
</Border>
<Border Background="#161B22" CornerRadius="8" Padding="20" Margin="0,0,0,12">
<StackPanel>
<TextBlock Text="最新动态" FontSize="14" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="项目初始化中..." FontSize="11" Foreground="#6B7280" Margin="0,4,0,0"/>
</StackPanel>
</Border>
</StackPanel>
<!-- 下载页 -->
<StackPanel x:Name="PageDownload" Margin="32,28" Visibility="Collapsed">
<TextBlock Text="下载管理" FontSize="24" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="暂无下载任务" FontSize="13" Foreground="#6B7280" Margin="0,12,0,0"/>
</StackPanel>
<!-- 设置页 -->
<StackPanel x:Name="PageSettings" Margin="32,28" Visibility="Collapsed">
<TextBlock Text="设置" FontSize="24" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="设置项开发中..." FontSize="13" Foreground="#6B7280" Margin="0,12,0,0"/>
</StackPanel>
<!-- 关于页 -->
<StackPanel x:Name="PageAbout" Margin="32,28" Visibility="Collapsed">
<TextBlock Text="关于 MRCC" FontSize="24" FontWeight="Bold" Foreground="#E8EAED"/>
<TextBlock Text="MineRedCircuitcraft - 我的世界红石衍生版" FontSize="13" Foreground="#6B7280"
Margin="0,6,0,20"/>
<TextBlock Text="电路仿真游戏,红石逻辑 x 像素方块 x 模拟电路" FontSize="12" Foreground="#9BA3AE"/>
<TextBlock Text="核心库: PCL.Core (Apache 2.0)" FontSize="11" Foreground="#4B5563"
Margin="0,12,0,0"/>
</StackPanel>
</Grid>
</Grid>
<Window.Resources>
<Style x:Key="NavRadioButtonStyle" TargetType="RadioButton">
<Setter Property="Foreground" Value="#6B7280"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Padding" Value="16,10"/>
<Setter Property="Margin" Value="0,2"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Border x:Name="bd" Background="Transparent" CornerRadius="6" Padding="{TemplateBinding Padding}">
<ContentPresenter VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#1C2230"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="bd" Property="Background" Value="#1C2230"/>
<Setter Property="Foreground" Value="#E83229"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
Background="#0A0A14"
ResizeMode="CanResizeWithGrip"
MinHeight="400" MinWidth="600"
Loaded="OnWindowLoaded">
</Window>
+136 -10
View File
@@ -1,29 +1,155 @@
using System;
using System.IO;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
namespace MRCC.Launcher;
public partial class MainWindow : Window
{
private WebView2? _wv;
public MainWindow()
{
InitializeComponent();
}
private void OnNavChecked(object sender, RoutedEventArgs e)
private async void OnWindowLoaded(object sender, RoutedEventArgs e)
{
if (sender is not RadioButton rb) return;
var tag = rb.Tag?.ToString() ?? "home";
try
{
var gameDir = FindGamePath();
if (gameDir == null)
{
Content = new TextBlock { Text = "游戏文件未找到", Foreground = System.Windows.Media.Brushes.White, FontSize = 14, Margin = new Thickness(20) };
return;
}
PageHome.Visibility = tag == "home" ? Visibility.Visible : Visibility.Collapsed;
PageDownload.Visibility = tag == "download" ? Visibility.Visible : Visibility.Collapsed;
PageSettings.Visibility = tag == "settings" ? Visibility.Visible : Visibility.Collapsed;
PageAbout.Visibility = tag == "about" ? Visibility.Visible : Visibility.Collapsed;
var port = GameServer.Start(gameDir);
var url = $"http://localhost:{port}/voxel-world.html";
_wv = new WebView2();
Content = _wv;
await _wv.EnsureCoreWebView2Async();
_wv.CoreWebView2.Settings.IsWebMessageEnabled = true;
_wv.CoreWebView2.WebMessageReceived += OnWebMessage;
_wv.CoreWebView2.Navigate(url);
Program.Log($"Launcher UI loaded: {url}");
}
catch (Exception ex)
{
Program.Log($"Launcher load failed: {ex}");
}
}
private void OnLaunchGame(object sender, RoutedEventArgs e)
private void OnWebMessage(object? sender, CoreWebView2WebMessageReceivedEventArgs e)
{
// TODO: 启动 MRCC Unity 客户端
MessageBox.Show("游戏启动功能开发中", "MRCC Launcher", MessageBoxButton.OK, MessageBoxImage.Information);
try
{
// WebView2 的 postMessage 会 JSON 编码,需先解一层
var rawJson = e.TryGetWebMessageAsString();
if (string.IsNullOrEmpty(rawJson)) return;
using var doc = JsonDocument.Parse(rawJson);
var root = doc.RootElement;
if (!root.TryGetProperty("action", out var action) || action.GetString() != "launch_game") return;
var username = "Player";
if (root.TryGetProperty("username", out var u) && u.ValueKind == JsonValueKind.String)
username = u.GetString()!;
// 不再启动 Luanti —— HTML5 世界直接在 WebView2 内运行
Program.Log($"Game launch requested by: {username}");
}
catch (Exception ex) { Program.Log($"WebMessage error: {ex}"); }
}
public static string? FindGamePath()
{
var exeDir = AppContext.BaseDirectory;
foreach (var p in new[] { "game", "../game", "../../../prototype", "../../prototype", "../prototype" })
{
var full = Path.GetFullPath(Path.Combine(exeDir, p));
if (Directory.Exists(full) && File.Exists(Path.Combine(full, "voxel-world.html")))
return full;
}
return null;
}
}
// HTTP server for static files
public static class GameServer
{
private static HttpListener? _listener;
private static CancellationTokenSource? _cts;
private static string _gameDir = "";
public static int Start(string gameDir)
{
_gameDir = gameDir;
var port = FindFreePort();
_cts = new CancellationTokenSource();
_listener = new HttpListener();
_listener.Prefixes.Add($"http://localhost:{port}/");
_listener.Start();
Task.Run(() => ListenLoop(_cts.Token));
return port;
}
public static void Stop()
{
_cts?.Cancel();
try { _listener?.Stop(); } catch { }
try { _listener?.Close(); } catch { }
}
private static async Task ListenLoop(CancellationToken ct)
{
while (!ct.IsCancellationRequested)
{
try { var ctx = await _listener!.GetContextAsync().WaitAsync(ct); _ = Task.Run(() => Handle(ctx)); }
catch (OperationCanceledException) { break; }
catch (HttpListenerException) { break; }
}
}
private static async Task Handle(HttpListenerContext ctx)
{
try
{
var path = ctx.Request.Url!.AbsolutePath.TrimStart('/');
if (string.IsNullOrEmpty(path)) path = "voxel-world.html";
var fp = Path.GetFullPath(Path.Combine(_gameDir, path));
if (!fp.StartsWith(_gameDir, StringComparison.OrdinalIgnoreCase) || !File.Exists(fp))
{ ctx.Response.StatusCode = 404; ctx.Response.Close(); return; }
var ct = Path.GetExtension(fp).ToLowerInvariant() switch
{
".html" => "text/html; charset=utf-8", ".css" => "text/css",
".js" => "application/javascript", ".json" => "application/json",
".png" => "image/png", ".jpg" or ".jpeg" => "image/jpeg",
".svg" => "image/svg+xml", _ => "application/octet-stream"
};
var bytes = await File.ReadAllBytesAsync(fp);
ctx.Response.ContentType = ct;
ctx.Response.ContentLength64 = bytes.Length;
ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
ctx.Response.Headers.Add("Cache-Control", "no-cache");
await ctx.Response.OutputStream.WriteAsync(bytes);
ctx.Response.Close();
}
catch { try { ctx.Response.StatusCode = 500; ctx.Response.Close(); } catch { } }
}
private static int FindFreePort()
{
var l = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0);
l.Start(); var port = ((System.Net.IPEndPoint)l.LocalEndpoint).Port; l.Stop();
return port;
}
}
+38 -14
View File
@@ -1,26 +1,50 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using PCL.Core.App.Essentials;
using PCL.Core.App.IoC;
using MRCC.Launcher;
namespace MRCC.Launcher;
public static class Program
internal static class Program
{
public static bool IsDevMode;
private static readonly object _logLock = new();
private static readonly string LogPath = "redcircuit.log";
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
[STAThread]
public static void Main(string[] args)
{
// 设置 WPF Application 加载委托
ApplicationService.Loading = () =>
IsDevMode = args.Any(a => string.Equals(a, "dev", StringComparison.OrdinalIgnoreCase));
if (IsDevMode)
{
var app = new App();
return app;
};
AllocConsole();
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
Log("=== RedCircuit 开发模式 ===");
Log($"工作目录: {Environment.CurrentDirectory}");
Log($"EXE目录: {AppContext.BaseDirectory}");
Log("HTML5 世界直接运行于 WebView2 内,控制台用于查看日志。");
}
// 设置主窗口加载委托
MainWindowService.Loading = () => new MainWindow();
// 启动器 UIWebView2 加载 HTML5 世界
var app = new App();
app.Run(new MainWindow());
}
// 启动生命周期
Lifecycle.OnInitialize();
public static void Log(string message)
{
var line = $"[{DateTime.Now:HH:mm:ss.fff}] {message}";
lock (_logLock)
{
if (IsDevMode) Console.WriteLine(line);
Debug.WriteLine(line);
try { File.AppendAllText(LogPath, line + Environment.NewLine, Encoding.UTF8); } catch { }
}
}
}
@@ -1,29 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace MRCC.Launcher.ViewModels;
/// <summary>
/// 主窗口 ViewModel,管理导航状态与页面数据。
/// </summary>
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private string _versionText = "v1.0.0-dev";
[ObservableProperty]
private string _statusText = "就绪";
[ObservableProperty]
private bool _isGameInstalled;
[ObservableProperty]
private int _downloadProgress;
/// <summary>
/// 启动游戏命令(后续实现具体逻辑)
/// </summary>
public void LaunchGame()
{
// TODO: 检查游戏安装状态 -> 启动 Unity 客户端
}
}