Skip to content

Commit 4c311ba

Browse files
committed
【协议导出工具改进】
1. 支持MemoryPack; 2. Debug - 撤销栈未重置, 导致 ctrl z 会清空整个文档; 3. 支持中日韩等非英文语言; 4. 改善标签页太多横向拖拽杆会遮挡顶部标签的问题; 5. 选中亮红色太过刺眼难以看清文字, 改成蓝底白字.
1 parent 4688691 commit 4c311ba

37 files changed

+1225
-42
lines changed

‎Fanatsy.sln‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36511.14 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
36
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{83FB151F-5881-4757-9505-8B70B8C38AA3}"
47
EndProject
58
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Net", "Fantasy.Packages\Fantasy.Net\Fantasy.Net.csproj", "{4782A7D1-2B43-48DD-AF50-EDC773436E20}"
69
EndProject
7-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{0CEB6A4D-8CE9-4EA7-A918-61FA62D6F6F0}"
8-
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.NetworkProtocol", "Tools\SourceCode\Fantasy.Tools.NetworkProtocol\Fantasy.Tools.NetworkProtocol.csproj", "{1951BC8A-0B3E-42F8-950B-DC142988B225}"
10-
EndProject
1110
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Cli", "Fantasy.Packages\Fantasy.Cil\Fantasy.Cli.csproj", "{9F4125F5-623E-4F01-9224-1F588934CEE3}"
1211
EndProject
1312
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.SourceGenerator", "Fantasy.Packages\Fantasy.SourceGenerator\Fantasy.SourceGenerator.csproj", "{8BDFA905-DC83-4DAC-8B7A-123266545683}"
@@ -21,27 +20,11 @@ Global
2120
Debug|Any CPU = Debug|Any CPU
2221
Release|Any CPU = Release|Any CPU
2322
EndGlobalSection
24-
GlobalSection(NestedProjects) = preSolution
25-
{1951BC8A-0B3E-42F8-950B-DC142988B225} = {0CEB6A4D-8CE9-4EA7-A918-61FA62D6F6F0}
26-
{4782A7D1-2B43-48DD-AF50-EDC773436E20} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
27-
{9F4125F5-623E-4F01-9224-1F588934CEE3} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
28-
{8BDFA905-DC83-4DAC-8B7A-123266545683} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
29-
{DE4A9C2B-304C-46C6-805F-583A8B165745} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
30-
{2A5E83A1-CEE7-4DFF-B91F-CC84881BBA11} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
31-
EndGlobalSection
3223
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3324
{4782A7D1-2B43-48DD-AF50-EDC773436E20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3425
{4782A7D1-2B43-48DD-AF50-EDC773436E20}.Debug|Any CPU.Build.0 = Debug|Any CPU
3526
{4782A7D1-2B43-48DD-AF50-EDC773436E20}.Release|Any CPU.ActiveCfg = Release|Any CPU
3627
{4782A7D1-2B43-48DD-AF50-EDC773436E20}.Release|Any CPU.Build.0 = Release|Any CPU
37-
{4E463740-00D2-4B4F-AC5B-A09B24487D35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38-
{4E463740-00D2-4B4F-AC5B-A09B24487D35}.Debug|Any CPU.Build.0 = Debug|Any CPU
39-
{4E463740-00D2-4B4F-AC5B-A09B24487D35}.Release|Any CPU.ActiveCfg = Release|Any CPU
40-
{4E463740-00D2-4B4F-AC5B-A09B24487D35}.Release|Any CPU.Build.0 = Release|Any CPU
41-
{1951BC8A-0B3E-42F8-950B-DC142988B225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42-
{1951BC8A-0B3E-42F8-950B-DC142988B225}.Debug|Any CPU.Build.0 = Debug|Any CPU
43-
{1951BC8A-0B3E-42F8-950B-DC142988B225}.Release|Any CPU.ActiveCfg = Release|Any CPU
44-
{1951BC8A-0B3E-42F8-950B-DC142988B225}.Release|Any CPU.Build.0 = Release|Any CPU
4528
{9F4125F5-623E-4F01-9224-1F588934CEE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4629
{9F4125F5-623E-4F01-9224-1F588934CEE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
4730
{9F4125F5-623E-4F01-9224-1F588934CEE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -59,4 +42,14 @@ Global
5942
{2A5E83A1-CEE7-4DFF-B91F-CC84881BBA11}.Release|Any CPU.ActiveCfg = Release|Any CPU
6043
{2A5E83A1-CEE7-4DFF-B91F-CC84881BBA11}.Release|Any CPU.Build.0 = Release|Any CPU
6144
EndGlobalSection
45+
GlobalSection(SolutionProperties) = preSolution
46+
HideSolutionNode = FALSE
47+
EndGlobalSection
48+
GlobalSection(NestedProjects) = preSolution
49+
{4782A7D1-2B43-48DD-AF50-EDC773436E20} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
50+
{9F4125F5-623E-4F01-9224-1F588934CEE3} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
51+
{8BDFA905-DC83-4DAC-8B7A-123266545683} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
52+
{DE4A9C2B-304C-46C6-805F-583A8B165745} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
53+
{2A5E83A1-CEE7-4DFF-B91F-CC84881BBA11} = {83FB151F-5881-4757-9505-8B70B8C38AA3}
54+
EndGlobalSection
6255
EndGlobal

‎Fantasy.Packages/Fantasy.Net/Runtime/Core/Network/Message/PacketParser/OpCode.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ public static implicit operator OpCodeIdStruct(uint opCodeId)
4242

4343
public static class OpCodeProtocolType
4444
{
45-
public const uint Bson = 1;
4645
public const uint ProtoBuf = 0;
46+
public const uint Bson = 1;
47+
public const uint MemoryPack = 2;
4748
}
4849

4950
public static class OpCodeType

‎Fantasy.Packages/Fantasy.ProtocolEditor/Resources/Protobuf.xshd‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
<!-- Message type name after 'message' keyword (e.g., message C2G_TestMessage) -->
101101
<Rule color="MessageType">
102-
(?&lt;=\bmessage\s+)[A-Z][A-Za-z0-9_]*\b
102+
(?&lt;=\bmessage\s+)[A-Z\u4E00-\u9FFF][A-Za-z0-9_\u4E00-\u9FFF\u3400-\u4DBF\u3040-\u30FF\uAC00-\uD7AF]*
103103
</Rule>
104104
</RuleSet>
105105

@@ -108,7 +108,7 @@
108108
<!-- Custom message type names in comments (e.g., G2C_TestResponse, C2G_TestMessage) -->
109109
<!-- This rule must come before Keywords to match longer identifiers -->
110110
<Rule color="MessageTypeInComment">
111-
\b[A-Z][A-Za-z0-9_]*\b
111+
[A-Z\u4E00-\u9FFF][A-Za-z0-9_\u4E00-\u9FFF\u3400-\u4DBF\u3040-\u30FF\uAC00-\uD7AF]*
112112
</Rule>
113113

114114
<!-- Fantasy Framework Interfaces in comments -->

‎Fantasy.Packages/Fantasy.ProtocolEditor/Services/CurrentLineHighlightRenderer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Draw(TextView textView, DrawingContext drawingContext)
5151

5252
// 绘制黑色背景
5353
drawingContext.DrawRectangle(
54-
new SolidColorBrush(Color.Parse("#000000")),
54+
new SolidColorBrush(Color.Parse("#131314")),
5555
null,
5656
expandedRect
5757
);

‎Fantasy.Packages/Fantasy.ProtocolEditor/Services/ProtobufValidator.cs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public List<ValidationError> Validate(string text)
4747
var trimmedLine = line.Trim();
4848
if (trimmedLine.StartsWith("message"))
4949
{
50-
var match = Regex.Match(trimmedLine, @"message\s+([A-Za-z0-9_]+)");
50+
var match = Regex.Match(trimmedLine, @"message\s+([\p{L}\p{N}_]+)");
5151
if (match.Success)
5252
{
5353
definedMessages.Add(match.Groups[1].Value);
@@ -156,7 +156,7 @@ private void ValidateRequestComment(string line, int lineNum, List<ValidationErr
156156
if (roamingMessageMatch.Success)
157157
{
158158
// IRoamingMessage 必须是格式:// IRoamingMessage,RoamingType
159-
var formatPattern = @"//\s*IRoamingMessage\s*,\s*[A-Za-z0-9_]+";
159+
var formatPattern = @"//\s*IRoamingMessage\s*,\s*[\p{L}\p{N}_]+";
160160
var formatMatch = Regex.Match(line, formatPattern);
161161

162162
System.Diagnostics.Debug.WriteLine($"Found IRoamingMessage in line: {line.Trim()}");
@@ -190,7 +190,7 @@ private void ValidateRequestComment(string line, int lineNum, List<ValidationErr
190190
if (customRouteMessageMatch.Success)
191191
{
192192
// ICustomRouteMessage 必须是格式:// ICustomRouteMessage,RouteType
193-
var formatPattern = @"//\s*ICustomRouteMessage\s*,\s*[A-Za-z0-9_]+";
193+
var formatPattern = @"//\s*ICustomRouteMessage\s*,\s*[\p{L}\p{N}_]+";
194194
var formatMatch = Regex.Match(line, formatPattern);
195195

196196
System.Diagnostics.Debug.WriteLine($"Found ICustomRouteMessage in line: {line.Trim()}");
@@ -224,7 +224,7 @@ private void ValidateRequestComment(string line, int lineNum, List<ValidationErr
224224
if (roamingRequestMatch.Success)
225225
{
226226
// IRoamingRequest 必须是格式:// IRoamingRequest,ResponseType,RoamingType
227-
var formatPattern = @"//\s*IRoamingRequest\s*,\s*([A-Z][A-Za-z0-9_]*)\s*,\s*[A-Za-z0-9_]+";
227+
var formatPattern = @"//\s*IRoamingRequest\s*,\s*([\p{L}_][\p{L}\p{N}_]*)\s*,\s*[\p{L}\p{N}_]+";
228228
var formatMatch = Regex.Match(line, formatPattern);
229229

230230
System.Diagnostics.Debug.WriteLine($"Found IRoamingRequest in line: {line.Trim()}");
@@ -278,7 +278,7 @@ private void ValidateRequestComment(string line, int lineNum, List<ValidationErr
278278
if (customRouteMatch.Success)
279279
{
280280
// ICustomRouteRequest 必须是格式:// ICustomRouteRequest,ResponseType,ChatRoute
281-
var formatPattern = @"//\s*ICustomRouteRequest\s*,\s*([A-Z][A-Za-z0-9_]*)\s*,\s*[A-Za-z0-9_]+";
281+
var formatPattern = @"//\s*ICustomRouteRequest\s*,\s*([\p{L}_][\p{L}\p{N}_]*)\s*,\s*[\p{L}\p{N}_]+";
282282
var formatMatch = Regex.Match(line, formatPattern);
283283

284284
System.Diagnostics.Debug.WriteLine($"Found ICustomRouteRequest in line: {line.Trim()}");
@@ -341,7 +341,8 @@ private void ValidateRequestComment(string line, int lineNum, List<ValidationErr
341341
if (match.Success)
342342
{
343343
// 检查格式是否为 // IRequest,ResponseType
344-
var formatPattern = $@"//\s*{requestInterface}\s*,\s*([A-Z][A-Za-z0-9_]*)";
344+
var formatPattern = "//\\s*" + requestInterface + "\\s*,\\s*([\\p{L}][\\p{L}\\p{N}_]*)";
345+
345346
var formatMatch = Regex.Match(line, formatPattern);
346347

347348
System.Diagnostics.Debug.WriteLine($"Found {requestInterface} in line: {line.Trim()}");

‎Fantasy.Packages/Fantasy.ProtocolEditor/Views/MainWindow.axaml‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<MenuItem Header="退出" Click="OnExitMenuClick"/>
5959
</MenuItem>
6060
<MenuItem Header="编辑">
61+
<MenuItem Header="撤销" Click="OnUndoClick" InputGesture="Ctrl+Z"/>
62+
<MenuItem Header="重做" Click="OnRedoClick" InputGesture="Ctrl+Y"/>
63+
<Separator/>
6164
<MenuItem Header="查找" Click="OnFindMenuClick" InputGesture="Ctrl+F"/>
6265
<MenuItem Header="替换" Click="OnReplaceMenuClick" InputGesture="Ctrl+H"/>
6366
<Separator/>
@@ -241,11 +244,18 @@
241244

242245
<!-- 标签页栏 -->
243246
<Border Grid.Row="0" Background="#2B2B2B" BorderBrush="Transparent" BorderThickness="0">
244-
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
245-
<ItemsControl x:Name="TabItemsControl" ItemsSource="{Binding OpenedTabs}">
247+
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
248+
249+
<ScrollViewer.Styles>
250+
<Style Selector="ScrollBar">
251+
<Setter Property="Opacity" Value="1"/>
252+
</Style>
253+
</ScrollViewer.Styles>
254+
255+
<ItemsControl x:Name="TabItemsControl" ItemsSource="{Binding OpenedTabs}">
246256
<ItemsControl.ItemsPanel>
247257
<ItemsPanelTemplate>
248-
<StackPanel Orientation="Horizontal" Height="35"/>
258+
<StackPanel Orientation="Horizontal" Height="35" Margin="0,0,0,8"/>
249259
</ItemsPanelTemplate>
250260
</ItemsControl.ItemsPanel>
251261
<ItemsControl.ItemTemplate>

‎Fantasy.Packages/Fantasy.ProtocolEditor/Views/MainWindow.axaml.cs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using AvaloniaEdit.CodeCompletion;
1818
using Fantasy.ProtocolEditor.ViewModels;
1919
using Fantasy.ProtocolEditor.Services;
20+
using Avalonia.Media;
2021

2122
namespace Fantasy.ProtocolEditor.Views;
2223

@@ -145,6 +146,9 @@ private void OnActiveTabChanged(Models.EditorTab? tab)
145146
// 切换到新标签的文档
146147
TextEditor.Document = tab.Document;
147148

149+
// 重置撤销栈,避免 Ctrl+Z 清空文本
150+
TextEditor.Document.UndoStack.ClearAll();
151+
148152
// 订阅新文档的文本变化事件
149153
if (TextEditor.Document != null)
150154
{
@@ -233,6 +237,9 @@ private void InitializeTextEditor()
233237
_currentLineRenderer = new CurrentLineHighlightRenderer(TextEditor, verticalPadding: 4);
234238
TextEditor.TextArea.TextView.BackgroundRenderers.Add(_currentLineRenderer);
235239

240+
TextEditor.TextArea.SelectionBrush = new SolidColorBrush(Color.Parse("#6599BB")); // 调整选中背景
241+
TextEditor.TextArea.SelectionForeground = new SolidColorBrush(Colors.White); // 调整选中文本颜色
242+
236243
// 订阅光标位置变化事件,重绘当前行
237244
TextEditor.TextArea.Caret.PositionChanged += (s, e) => TextEditor.TextArea.TextView.InvalidateVisual();
238245

@@ -333,8 +340,45 @@ private void OnKeyDown(object? sender, KeyEventArgs e)
333340
CloseFindPanel();
334341
e.Handled = true;
335342
}
343+
// Ctrl+Z 撤销
344+
else if (e.KeyModifiers.HasFlag(KeyModifiers.Control) && e.Key == Key.Z)
345+
{
346+
if (TextEditor.CanUndo)
347+
TextEditor.Undo();
348+
349+
e.Handled = true;
350+
return;
351+
}
352+
// Ctrl+Y 重做
353+
else if (e.KeyModifiers.HasFlag(KeyModifiers.Control) && e.Key == Key.Y)
354+
{
355+
if (TextEditor.CanRedo)
356+
TextEditor.Redo();
357+
358+
e.Handled = true;
359+
return;
360+
}
336361
}
337362

363+
/// <summary>
364+
/// 撤销
365+
/// </summary>
366+
private void OnUndoClick(object? sender, RoutedEventArgs e)
367+
{
368+
if (TextEditor.CanUndo)
369+
TextEditor.Undo();
370+
}
371+
372+
/// <summary>
373+
/// 重做
374+
/// </summary>
375+
private void OnRedoClick(object? sender, RoutedEventArgs e)
376+
{
377+
if (TextEditor.CanRedo)
378+
TextEditor.Redo();
379+
}
380+
381+
338382
/// <summary>
339383
/// 菜单打开文件夹点击事件
340384
/// </summary>

‎Fantasy.Packages/Fantasy.ProtocolExportTool/Generators/Interface/AProtocolExporter.cs‎ renamed to ‎Fantasy.Packages/Fantasy.ProtocolExportTool/Generators/Abstract/AProtocolExporter.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Fantasy.ProtocolExportTool.Models;
1212
using Spectre.Console;
1313

14-
namespace Fantasy.ProtocolExportTool.Interface;
14+
namespace Fantasy.ProtocolExportTool.Abstract;
1515

1616
public abstract partial class AProtocolExporter( string protocolDirectory, string clientDirectory, string serverDirectory, ProtocolExportType protocolExportType)
1717
{

‎Fantasy.Packages/Fantasy.ProtocolExportTool/Generators/CSharpExporter.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5-
using Fantasy.ProtocolExportTool.Interface;
5+
using Fantasy.ProtocolExportTool.Abstract;
66
using Fantasy.ProtocolExportTool.Models;
77
// ReSharper disable PossibleMultipleEnumeration
88

@@ -158,6 +158,7 @@ protected override string GenerateOuterMessages(IReadOnlyList<MessageDefinition>
158158
return messageDefinitions.Count == 0 ? string.Empty : $$"""
159159
using ProtoBuf;
160160
using System;
161+
using MemoryPack;
161162
using System.Collections.Generic;
162163
using Fantasy;
163164
using Fantasy.Network.Interface;
@@ -186,6 +187,7 @@ protected override string GenerateInnerMessages(IReadOnlyList<MessageDefinition>
186187
{
187188
return messageDefinitions.Count == 0 ? string.Empty : $$"""
188189
using ProtoBuf;
190+
using MemoryPack;
189191
using System;
190192
using System.Collections.Generic;
191193
using MongoDB.Bson.Serialization.Attributes;
@@ -416,7 +418,8 @@ private string GenerateMessages(string opcodeName, IReadOnlyList<MessageDefiniti
416418

417419
if (!string.IsNullOrEmpty(messageDefinition.Protocol.ClassAttribute))
418420
{
419-
builder.AppendLine($" {messageDefinition.Protocol.ClassAttribute}");
421+
builder.AppendLine($" [Serializable]\n" +
422+
$" {messageDefinition.Protocol.ClassAttribute}");
420423
}
421424

422425
if (string.IsNullOrEmpty(messageDefinition.InterfaceType))

‎Fantasy.Packages/Fantasy.ProtocolExportTool/Generators/Parsers/ProtocolFileParser.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private void ParseProtocolDeclaration(string line, int lineNumber)
120120
{
121121
"ProtoBuf" => ProtocolSettings.CreateProtoBuf(),
122122
"Bson" => ProtocolSettings.CreateBson(),
123+
"MemoryPack" => ProtocolSettings.CreateMemoryPack(),
123124
_ => throw new NotSupportedException($"Unsupported protocol type '{protocolName}' at {filePath} line {lineNumber}. Only 'ProtoBuf' and 'Bson' are supported.")
124125
};
125126
}
@@ -374,9 +375,9 @@ private static bool IsResponseType(MessageType type) =>
374375
type is MessageType.Response or MessageType.RouteTypeResponse or MessageType.RoamingResponse;
375376

376377
/// <summary>
377-
/// 字段解析正则表达式: type name = number (允许 Tab 和空格)
378+
/// 字段解析正则表达式: type name = number, 支持中日韩等非英文字符
378379
/// </summary>
379-
[GeneratedRegex(@"^\s*(\w+)\s+(\w+)\s*=\s*(\d+)\s*;\s*$")]
380+
[GeneratedRegex(@"^\s*([\p{L}_][\p{L}\p{N}_]*)\s+([\p{L}_][\p{L}\p{N}_]*)\s*=\s*(\d+)\s*;$")]
380381
private static partial Regex FieldRegex();
381382
}
382383

0 commit comments

Comments
 (0)