refactor: 插件 UI 从 WinForms 迁移到 CycleGUI,并修复代码质量问题
将 StandardScene 各插件的配置/监控窗体从 WinForms 迁移到 CycleGUI(删除 .Designer.cs/.resx,重写为 PanelBuilder 立即模式 UI,新增 CycleUiHelper 统一对话框)。 同时修复代码审核中的问题: - 后台文件写入加锁 + try/catch(ButtonBoxManager / DoorManager,对齐 LoopViewer.SaveTasks 模式) - CoderFieldsMetadata.cs 启用 #nullable enable,消除 CS8632 警告 - DummyCar 移除已废弃的 rightClickAction()/SetPosition() - CarRemoteHelper.OpenVehicleWebPage 的 Process.Start 加 try/catch - 重命名名不副实的 Mstsc()(现为打开网页) - 统一弃元命名为 _ - TrafficInterlockViewer 改用稳定 Id(GUID)做选择/编辑,替代行索引 - csproj 改用 $(CGUILibDir) 解析 CycleGUI,绝对路径收敛到 Directory.Build.props 构建:dotnet build StandardScene.sln → 0 错误,30 警告(均为历史遗留)。 注:static 单例状态重构(审核第 8 项)暂未处理,留待单独任务。
This commit is contained in:
@@ -1,28 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using CycleGUI;
|
||||
|
||||
namespace StandardScene.CarTypes
|
||||
{
|
||||
public partial class TextViewer : Form
|
||||
/// <summary>
|
||||
/// 长文本只读查看面板(CycleGUI 版,替代原 WinForms <c>TextViewer</c> 窗体)。
|
||||
/// 保留可实例化 + <see cref="Show"/> 以兼容 <c>new TextViewer().Show()</c> 与 <see cref="UpdateText"/> 调用。
|
||||
/// </summary>
|
||||
public class TextViewer
|
||||
{
|
||||
public TextViewer()
|
||||
private Panel _panel;
|
||||
private volatile string _text = "";
|
||||
|
||||
/// <summary>打开(或置前)文本查看面板。</summary>
|
||||
public void Show() => Open();
|
||||
|
||||
/// <summary>打开(或置前)文本查看面板。</summary>
|
||||
public void Open()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (_panel != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_panel.BringToFront();
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_panel = null;
|
||||
}
|
||||
}
|
||||
|
||||
var panel = GUI.DeclarePanel()
|
||||
.ShowTitle("TextViewer")
|
||||
.SetDefaultDocking(Panel.Docking.None)
|
||||
.InitSize(800, 600)
|
||||
.InitPos(false, 0, 0, 0.5f, 0.5f, 0.5f, 0.5f);
|
||||
_panel = panel;
|
||||
panel.IfTerminalQuit(() => { if (_panel == panel) _panel = null; });
|
||||
|
||||
panel.Define(pb =>
|
||||
{
|
||||
if (pb.Closing())
|
||||
{
|
||||
panel.Exit();
|
||||
if (_panel == panel) _panel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
pb.SelectableText(null, _text ?? "", copyButton: true);
|
||||
pb.Panel.Repaint(repaintTimeMs: 200);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>更新显示文本并触发面板重绘(可从非渲染线程调用)。</summary>
|
||||
public void UpdateText(string str)
|
||||
{
|
||||
richTextBox1.Invoke((Action)delegate
|
||||
{
|
||||
richTextBox1.Text = str;
|
||||
});
|
||||
_text = str ?? "";
|
||||
_panel?.Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user