Skip to content

Commit

Permalink
[增加]1. 增加协议导出工具
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Jan 3, 2025
1 parent b2bce28 commit 09f5f82
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea
ProtoExport/obj
ProtoExport/bin
ToolGUI/bin
ToolGUI/obj
*.user
6 changes: 6 additions & 0 deletions GameFrameX.Tools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoExport", "ProtoExport\ProtoExport.csproj", "{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolGUI", "ToolGUI\ToolGUI.csproj", "{986FC612-FC98-41DD-894F-9DE6A55C9728}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +14,9 @@ Global
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Release|Any CPU.Build.0 = Release|Any CPU
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Debug|Any CPU.Build.0 = Debug|Any CPU
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Release|Any CPU.ActiveCfg = Release|Any CPU
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions ToolGUI/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ToolGUI.App"
xmlns:local="using:ToolGUI"
RequestedThemeVariant="Default">
<!-- "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>
47 changes: 47 additions & 0 deletions ToolGUI/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using System.Linq;
using Avalonia.Markup.Xaml;
using ToolGUI.ViewModels;
using ToolGUI.Views;

namespace ToolGUI;

public partial class App : Application
{
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();
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 added ToolGUI/Assets/logo.ico
Binary file not shown.
47 changes: 47 additions & 0 deletions ToolGUI/Models/SettingData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.IO;
using GameFrameX.ProtoExport;
using Newtonsoft.Json;

namespace ToolGUI.Models;

public class SettingData
{
Dictionary<string, LauncherOptions> Options { get; set; }

public SettingData()
{
Options = new Dictionary<string, LauncherOptions>();
Options.Add("Server", new LauncherOptions { Mode = ModeType.Server.ToString(), IsGenerateErrorCode = true, NamespaceName = "GameFrameX.Proto.Proto", OutputPath = "./../../../../../Server/GameFrameX.Proto/Proto", InputPath = "./../../../../../Protobuf" });
Options.Add("Unity", new LauncherOptions { Mode = ModeType.Unity.ToString(), IsGenerateErrorCode = true, NamespaceName = "Hotfix.Proto", OutputPath = "./../../../../../Unity/Assets/Hotfix/Proto", InputPath = "./../../../../../Protobuf" });
Options.Add("TypeScript", new LauncherOptions { Mode = ModeType.TypeScript.ToString(), IsGenerateErrorCode = true, NamespaceName = "", OutputPath = "./../../../../../Laya/src/gameframex/protobuf", InputPath = "./../../../../../Protobuf" });
}

public static SettingData Instance { get; } = new SettingData();

public static LauncherOptions GetOptions(string mode)
{
if (string.IsNullOrWhiteSpace(mode))
{
return default;
}

return Instance.Options.GetValueOrDefault(mode);
}

public const string SettingPath = "Setting.json";

public static void LoadSetting()
{
if (File.Exists(SettingPath))
{
var json = File.ReadAllText(SettingPath);
Instance.Options = JsonConvert.DeserializeObject<Dictionary<string, LauncherOptions>>(json);
}
}

public static void SaveSetting()
{
File.WriteAllText(SettingPath, JsonConvert.SerializeObject(Instance.Options, Formatting.Indented));
}
}
19 changes: 19 additions & 0 deletions ToolGUI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Avalonia;
using System;

namespace ToolGUI;

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();
}
35 changes: 35 additions & 0 deletions ToolGUI/ToolGUI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<LangVersion>10</LangVersion>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ProtoExport\ProtoExport.csproj" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions ToolGUI/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using ToolGUI.ViewModels;

namespace ToolGUI;

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;
}
}
6 changes: 6 additions & 0 deletions ToolGUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ToolGUI.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
public string Greeting { get; } = "Welcome to Avalonia!";
}
7 changes: 7 additions & 0 deletions ToolGUI/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace ToolGUI.ViewModels;

public class ViewModelBase : ObservableObject
{
}
80 changes: 80 additions & 0 deletions ToolGUI/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:ToolGUI.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="300"
x:Class="ToolGUI.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
CanResize="False"
WindowState="Normal"
Icon="/Assets/logo.ico"
Title="ToolGUI">

<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel />
</Design.DataContext>
<StackPanel Margin="20" Orientation="Vertical">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="导出类型:" Width="100" VerticalAlignment="Center" />
<ComboBox Name="Mode" Width="300" VerticalAlignment="Center" SelectedIndex="1" SelectionChanged="Mode_OnSelectionChanged">
<ComboBoxItem>Server</ComboBoxItem>
<ComboBoxItem>Unity</ComboBoxItem>
<ComboBoxItem>TypeScript</ComboBoxItem>
</ComboBox>
</StackPanel>

<!-- 第二行 -->
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="命名空间:" Width="100" VerticalAlignment="Center" />

<TextBox Name="NameSpace" Width="300" VerticalAlignment="Center" />
</StackPanel>

<!-- 第三行 -->
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="协议文件路径:" Width="100" VerticalAlignment="Center" />
<TextBox Name="InputPath" Width="300" VerticalAlignment="Center" />
</StackPanel>

<!-- 第四行 -->
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="导出文件路径:" Width="100" VerticalAlignment="Center" />
<TextBox Name="OutputPath" Width="300" VerticalAlignment="Center" />
</StackPanel>

<!-- 第五行 -->
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="生成错误码?:" Width="100" VerticalAlignment="Center" />
<CheckBox Name="IsGenerateErrorCode" VerticalAlignment="Center" IsChecked="True" />
</StackPanel>
<StackPanel>
<Button
Click="Button_OnClick"
Content="导出"
HorizontalAlignment="Center"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
FontSize="30"
Foreground="White"
BorderThickness="2"
CornerRadius="10"
BorderBrush="Yellow"
Width="200"
Height="50"
Background="DarkGreen" />
</StackPanel>
<StackPanel>
<Border Background="AliceBlue" Width="400" Height="120" Margin="0,10,0,0">
<ScrollViewer>
<StackPanel>
<TextBlock Name="ErrorLog" Foreground="Brown" VerticalAlignment="Center" />
</StackPanel>
</ScrollViewer>
</Border>
</StackPanel>
</StackPanel>
</Window>
Loading

0 comments on commit 09f5f82

Please sign in to comment.