Compare commits

...

85 Commits

Author SHA1 Message Date
jkpete f7476a9d99 move tree code to a special file 4 weeks ago
jkpete 3eaf912170 add EGodotTree and can init by json 4 weeks ago
jkpete 6de064afec add tree and menu 4 weeks ago
jkpete 519aee037b fix search in datasave tools for max search 4 weeks ago
jkpete 4bf6755941 add search 4 weeks ago
jkpete dedf4dce8e fix sqliteSave's get key 4 weeks ago
jkpete c53ebf7ebd add table output 4 weeks ago
jkpete 46611f8574 fix interface of IEGDatabase 1 month ago
jkpete 9181ac94c4 add drop table by key 1 month ago
jkpete 3190224018 fixed sql extension 1 month ago
jkpete 92ab4b4e58 fix bugs: file select options saved after will to line edit,now saved to file select 1 month ago
jkpete 5b4b9b5259 add execute in end of frame and complete the PopUp Node 1 month ago
jkpete 72eccbae0d fixed popup bugs 1 month ago
jkpete 4d1d119124 add popup method 1 month ago
jkpete 3e158ff96b fixed struct 2 months ago
jkpete 4f393ca54b add path select pararms 2 months ago
jkpete 3eeeeacf19 add function menu 2 months ago
jkpete 521815053e fixed add data by primary key 2 months ago
jkpete 6b67781961 add primary key get method,and add default data 2 months ago
jkpete e6af6d264b changed remove method to int,add a modify for egsave interface,new SaveTable for godot UI 2 months ago
jkpete 7596a60b51 add a savedata table 2 months ago
jkpete b943c4bba8 fix confirmation bugs 2 months ago
jkpete e3494c99cf fixed data 2 months ago
jkpete 67bef13490 fixed bugs 2 months ago
jkpete 570a28a3c5 fixed page 2 months ago
jkpete fb32fb41f5 fixed page adapter page 2 months ago
jkpete 9aa0561e75 add table test 2 months ago
jkpete 015b3ff47d fix generate rowdata and params 2 months ago
jkpete 5b626cd141 add basic interface type row data ,and param 2 months ago
jkpete 258b6e9ac2 fixed editparams 2 months ago
jkpete f6469d6d1e obsolete the clearchildren label 2 months ago
jkpete 09bbf71694 add basic dialog 2 months ago
jkpete f290bd1a8c fixed generate tools file construct 2 months ago
jkpete 78daceed74 fixed egmessage 2 months ago
jkpete a7daf802dd add a part of egmessage manual 2 months ago
jkpete d2de5d6af1 reset the file construct 2 months ago
jkpete dc38724f1d EGSave add contains and list method 2 months ago
jkpete cfb8572bec fixed connection to device 3 months ago
jkpete f6a5ece01b fixed terminal 3 months ago
jkpete 63d3dd1b99 fixed protocol data 3 months ago
jkpete 86fb9565cd add script 3 months ago
jkpete b52a480ed8 fixed functionlist 3 months ago
jkpete 3e3b5fbb66 fixed UI 3 months ago
jkpete 02d2418fae add protocol tools 3 months ago
jkpete 213546c490 fixed generator 3 months ago
jkpete fe4155580a fixed row data 3 months ago
jkpete 47d2cbd668 fixed row data 3 months ago
jkpete 086252a47b fixed add egodotEditDialog 3 months ago
jkpete 2d54fd12ac fixed cs 3 months ago
jkpete ab01db9bdf fixed to generate 3 months ago
jkpete cf6eef4dd5 fixed GenerateTools Interface 3 months ago
jkpete f5699fb880 add table creator 3 months ago
jkpete 68edad0a2d fixed table 3 months ago
jkpete ad1abe2b22 fixed Readme 3 months ago
jkpete ce1e07c49b fixed markdown with svg 3 months ago
jkpete 5f417b1aac change to PNG 3 months ago
jkpete 3462183375 fixed icon 3 months ago
jkpete 3bd3eae1e7 arrange the example 3 months ago
jkpete e1864beed2 add example 4 months ago
jkpete 4197e98978 add localmedia viewer 4 months ago
jkpete 0c6eefdd7e Update ReadMe 4 months ago
jkpete 8b368bf4c8 fixed ffmpeg test 4 months ago
jkpete 335067eebd add process test 4 months ago
jkpete 3bf9c30225 add protocolTools EGProcess 4 months ago
jkpete b5da22861f fixed host from Josn 4 months ago
jkpete 4e843c71a8 fixed FTPClient Save 4 months ago
jkpete 91c72ec254 fixed local file save 4 months ago
jkpete 5049d7ebcd fixed ftp any method 4 months ago
jkpete 3d98c5931c update third part license and notice 4 months ago
jkpete 2fd46bfb89 fixed codepath construct,add EGFileSave 4 months ago
jkpete ac878875f3 define the save file interface. 4 months ago
jkpete c28ce70106 add redis save for IEGSaveObject 4 months ago
jkpete 5d19433e15 old egsqlite and webdav move to other tools,absolute the egdapper for sqlite and mysql 4 months ago
jkpete d0421b4095 add sqlite save(dappper implement) 4 months ago
jkpete 2fdc11261c add websocket client 4 months ago
jkpete d1b7cee741 fixed egmysqlsave and savetoolsinterface 4 months ago
jkpete 82c7425044 fixed Dapper Mysql,changed interface IEGSaveData and all tools 4 months ago
jkpete 9946014202 marked egbyte save not use,define the protocol for the byte save,add sync and async for save tools interface,new Interface: ObjectSave add,update and remove 4 months ago
jkpete de24126549 tcp server support multi-server 4 months ago
jkpete 40493fcb55 change protocol tools to Concurrent Queue, fixed EGMessage Senddelay only enabled in single device 4 months ago
jkpete b411fb6030 remove godot in protocol schedule 4 months ago
jkpete f07142ea8c fixed schedule to Godot Node,add Godot Path Extension in Node Extension.remove godot method in some files,prepare for used in dotnet blazor 4 months ago
jkpete e49ca8486a fixed Platform class and changed all GD.Print to EG.Print 6 months ago
jkpete b644bf006c add Ssh client to egmessage protocol tools 6 months ago
jkpete 4cea5f8b78 fixed some texture import type for support android export 6 months ago
  1. 3
      EGFramework.csproj
  2. BIN
      EGFramework.png
  3. 34
      EGFramework.png.import
  4. 5
      EGFramework.svg
  5. 39
      EGFramework.svg.import
  6. 115
      Example/LocalMediaViewer/LocalMediaViewer.tscn
  7. 95
      Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs
  8. 6
      Example/OldTest/Action3D/MainGame.tscn
  9. 0
      Example/OldTest/Action3D/Script/ActionCamera.cs
  10. 0
      Example/OldTest/Action3D/Script/ActionPlayer.cs
  11. 0
      Example/OldTest/Action3D/SkyBox/lakeside.jpg
  12. 9
      Example/OldTest/Action3D/SkyBox/lakeside.jpg.import
  13. 8
      Example/OldTest/Gateway/Gateway.tscn
  14. 0
      Example/OldTest/Gateway/GatewayManual/BacnetGatewayManual_CN.md
  15. 2
      Example/OldTest/Gateway/ModbusGateway.tscn
  16. 0
      Example/OldTest/Gateway/Script/Data/DataBacNetGatewaySetting.cs
  17. 0
      Example/OldTest/Gateway/Script/Data/DataGatewayInfo.cs
  18. 0
      Example/OldTest/Gateway/Script/Data/DataModbusGatewaySettings.cs
  19. 0
      Example/OldTest/Gateway/Script/Data/DataTcpGatewaySetting.cs
  20. 0
      Example/OldTest/Gateway/Script/Interface/IGateway.cs
  21. 0
      Example/OldTest/Gateway/Script/OutData/ValueGenerator.cs
  22. 0
      Example/OldTest/Gateway/Script/View/ViewBacNetGateway.cs
  23. 0
      Example/OldTest/Gateway/Script/View/ViewBacnetHttpServer.cs
  24. 0
      Example/OldTest/Gateway/Script/View/ViewGateway.cs
  25. 0
      Example/OldTest/Gateway/Script/View/ViewModbusGateway.cs
  26. 0
      Example/OldTest/Gateway/Script/View/ViewTcpGateway.cs
  27. 2
      Example/OldTest/ModbusDebugTool/Component/modbus_item.tscn
  28. 0
      Example/OldTest/ModbusDebugTool/Script/DataModbusItem.cs
  29. 0
      Example/OldTest/ModbusDebugTool/Script/ViewEdit.cs
  30. 0
      Example/OldTest/ModbusDebugTool/Script/ViewMenu.cs
  31. 0
      Example/OldTest/ModbusDebugTool/Script/ViewMessage.cs
  32. 0
      Example/OldTest/ModbusDebugTool/Script/ViewModbusItem.cs
  33. 0
      Example/OldTest/ModbusDebugTool/Script/ViewSettings.cs
  34. 10
      Example/OldTest/ModbusDebugTool/TestModbus.tscn
  35. 2
      Example/OldTest/SystemExamples/ItemList/HPPotion.tres
  36. 0
      Example/OldTest/SystemExamples/ItemList/ItemList.CSV.import
  37. 0
      Example/OldTest/SystemExamples/ItemList/ItemList.json
  38. 0
      Example/OldTest/SystemExamples/ItemList/ItemList.txt
  39. 2
      Example/OldTest/SystemExamples/PlayerStorage/PlayerStorage.tscn
  40. 0
      Example/OldTest/SystemExamples/PlayerStorage/Script/DataStorageItem.cs
  41. 0
      Example/OldTest/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs
  42. 0
      Example/OldTest/SystemExamples/PlayerStorage/Script/ViewStorage.cs
  43. 229
      Example/ProtocolHelper/Scene/ProtocolHelper.tscn
  44. 9
      Example/ProtocolHelper/Script/Data/DataDevice.cs
  45. 29
      Example/ProtocolHelper/Script/ViewProtocolHelper.cs
  46. 6
      Example/ProtocolHelper/Script/ViewProtocolHelperDeviceList.cs
  47. 6
      Example/ProtocolHelper/Script/ViewProtocolHelperProtocolList.cs
  48. 6
      Example/ProtocolHelper/Script/ViewProtocolHelperSendArea.cs
  49. 26
      Example/ProtocolHelper/Script/ViewProtocolHelperTerminal.cs
  50. 30
      Example/SaveSystem/Scene/SaveSystem.tscn
  51. 129
      Example/SaveSystem/Script/ViewSaveSystem.cs
  52. 14
      Example/Theme/StyleBox/CardFrame.tres
  53. 3
      Example/Theme/White/White.tres
  54. 4
      Example/Tween/EGTween.tscn
  55. 26
      Example/UsingTest/Scene/TestEGFramework.tscn
  56. 45
      Example/UsingTest/Script/EGMDnsTest.cs
  57. 166
      Example/UsingTest/Script/EGSaveTest.cs
  58. 315
      Example/UsingTest/Script/EGTest.cs
  59. 250
      ReadMe.md
  60. 48
      addons/EGFramework/EGPlatform.cs
  61. 6
      addons/EGFramework/License_Third_Part/Dapper/License.txt
  62. 0
      addons/EGFramework/License_Third_Part/Dotnet/LICENSE.txt
  63. 7
      addons/EGFramework/License_Third_Part/FluentFTP/LICENSE.TXT
  64. 21
      addons/EGFramework/License_Third_Part/LiteDB/LICENSE.txt
  65. 21
      addons/EGFramework/License_Third_Part/Makaretu_Dns_Multicast/LICENSE.txt
  66. 3
      addons/EGFramework/License_Third_Part/Mysql_Data/Notice.txt
  67. 47
      addons/EGFramework/License_Third_Part/StackExchange_Redis/LICENSE.txt
  68. 224
      addons/EGFramework/Manual/EGMessage.md
  69. 146
      addons/EGFramework/Module/Extension/EGSqlExtension.cs
  70. 16
      addons/EGFramework/Module/GenerateTools/EGGenerate.cs
  71. 34
      addons/EGFramework/Module/GenerateTools/GenerateToolsInterface.cs
  72. 90
      addons/EGFramework/Module/GenerateTools/Templete/Code/EGSvgGenerator.cs
  73. 11
      addons/EGFramework/Module/GenerateTools/Templete/Code/EGSvgTempletes.cs
  74. 46
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs
  75. 20
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotConfirmationDialog.cs
  76. 104
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs
  77. 66
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs
  78. 120
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs
  79. 7
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Interface/EGGodotData.cs
  80. 197
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs
  81. 29
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotMenu.cs
  82. 34
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs
  83. 105
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotRowData.cs
  84. 156
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs
  85. 457
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs
  86. 79
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs
  87. 46
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTree.cs
  88. 59
      addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs
  89. 127
      addons/EGFramework/Module/GenerateTools/Templete/Variant/EGTree.cs
  90. 127
      addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs
  91. 48
      addons/EGFramework/Module/NodeExtension/EGCreate.cs
  92. 38
      addons/EGFramework/Module/NodeExtension/EGGodotPath.cs
  93. 22
      addons/EGFramework/Module/NodeExtension/EGNode.cs
  94. 37
      addons/EGFramework/Module/NodeExtension/EGProtocolScheduleGodot.cs
  95. 15
      addons/EGFramework/Module/NodeExtension/EGThread.cs
  96. 16
      addons/EGFramework/Module/NodeExtension/EGTweenExtension.cs
  97. 36
      addons/EGFramework/Module/OtherTools/EGModbus.cs
  98. 4
      addons/EGFramework/Module/OtherTools/EGSqlite.cs
  99. 19
      addons/EGFramework/Module/OtherTools/EGWebDav.cs
  100. 22
      addons/EGFramework/Module/ProtocolTools/EGMessage.cs
  101. Some files were not shown because too many files have changed in this diff Show More

3
EGFramework.csproj

@ -18,5 +18,8 @@ @@ -18,5 +18,8 @@
<PackageReference Include="BACnet" Version="2.0.4" />
<PackageReference Include="MySql.Data" Version="9.1.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.31" />
<PackageReference Include="FluentFTP" Version="52.1.0" />
</ItemGroup>
</Project>

BIN
EGFramework.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

34
EGFramework.png.import

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cvw1gq522fjiw"
path="res://.godot/imported/EGFramework.png-34687d3295fa60912fa513ef2547d661.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://EGFramework.png"
dest_files=["res://.godot/imported/EGFramework.png-34687d3295fa60912fa513ef2547d661.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

5
EGFramework.svg

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<svg height="128" width="128" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
<path d="M 64 0 L 116 48 L 64 12L 32 56 L 64 64 L32 72 L64 116L 96 72 L 80 64 L128 64 L 64 128 L 0 64 " fill="#DDDDDD" stroke-width="0" stroke="#000000" />
<path d="M 64 0 L 0 64 L 64 128 L 32 72 L 48 64L 32 56Z" fill="#000000" stroke-width="0" stroke="#000000" />
</svg>

After

Width:  |  Height:  |  Size: 371 B

39
EGFramework.svg.import

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpmhdi6qsq8xk"
path.s3tc="res://.godot/imported/EGFramework.svg-659d185b06d3cb441710fca89d9b4015.s3tc.ctex"
path.etc2="res://.godot/imported/EGFramework.svg-659d185b06d3cb441710fca89d9b4015.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://EGFramework.svg"
dest_files=["res://.godot/imported/EGFramework.svg-659d185b06d3cb441710fca89d9b4015.s3tc.ctex", "res://.godot/imported/EGFramework.svg-659d185b06d3cb441710fca89d9b4015.etc2.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

115
Example/LocalMediaViewer/LocalMediaViewer.tscn

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
[gd_scene load_steps=4 format=3 uid="uid://df4gmjq2o1ttn"]
[ext_resource type="Script" path="res://Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs" id="1_hfhp3"]
[sub_resource type="VideoStreamTheora" id="VideoStreamTheora_6wg02"]
[sub_resource type="ImageTexture" id="ImageTexture_2g46x"]
[node name="LocalMediaViewer" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_hfhp3")
[node name="ViewVideo" type="VideoStreamPlayer" parent="."]
visible = false
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
anchor_right = 1.0
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
stream = SubResource("VideoStreamTheora_6wg02")
expand = true
metadata/_edit_use_anchors_ = true
[node name="ViewImage" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
anchor_right = 1.0
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("ImageTexture_2g46x")
expand_mode = 1
metadata/_edit_use_anchors_ = true
[node name="Tab" type="TabContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_right = 0.2
anchor_bottom = 0.8
grow_horizontal = 2
grow_vertical = 2
current_tab = 0
metadata/_edit_use_anchors_ = true
[node name="Media" type="ScrollContainer" parent="Tab"]
layout_mode = 2
metadata/_edit_use_anchors_ = true
metadata/_tab_index = 0
[node name="MediaList" type="VBoxContainer" parent="Tab/Media"]
layout_mode = 2
size_flags_horizontal = 3
[node name="ControlList" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
anchor_top = 0.8
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="ImportList" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_top = 0.8
anchor_right = 0.2
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="UploadImage" type="Button" parent="ImportList"]
layout_mode = 2
size_flags_horizontal = 3
text = "导入图片"
[node name="UploadVideo" type="Button" parent="ImportList"]
layout_mode = 2
size_flags_horizontal = 3
text = "导入视频"
[node name="ImportImage" type="FileDialog" parent="."]
title = "Open a File"
initial_position = 1
size = Vector2i(960, 640)
ok_button_text = "Open"
file_mode = 0
access = 2
filters = PackedStringArray("*.png", "*.jpg")
[node name="ImportVideo" type="FileDialog" parent="."]
auto_translate_mode = 1
title = "Open a File"
initial_position = 1
size = Vector2i(960, 640)
ok_button_text = "Open"
file_mode = 0
access = 2
filters = PackedStringArray("*.ogv")
[connection signal="pressed" from="ImportList/UploadImage" to="." method="OpenImportImage"]
[connection signal="pressed" from="ImportList/UploadVideo" to="." method="OpenImportVideo"]
[connection signal="file_selected" from="ImportImage" to="." method="UploadImage"]
[connection signal="file_selected" from="ImportVideo" to="." method="UploadVideo"]

95
Example/LocalMediaViewer/Script/ViewLocalVideoMediaViewer.cs

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
using Godot;
using System;
using EGFramework;
using System.IO;
public partial class ViewLocalVideoMediaViewer : Node,IEGFramework
{
public EGLocalFileSave localFileSave { get; set; }
public VideoStreamPlayer ViewVideo { get; set; }
public TextureRect ViewImage { get; set; }
public VBoxContainer VideoList { get; set; }
public FileDialog ImportImage { get; set; }
public FileDialog ImportVideo { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
ViewVideo = this.GetNode<VideoStreamPlayer>("ViewVideo");
ViewImage = this.GetNode<TextureRect>("ViewImage");
VideoList = this.GetNode<VBoxContainer>("Tab/Media/MediaList");
ImportImage = this.GetNode<FileDialog>("ImportImage");
ImportVideo = this.GetNode<FileDialog>("ImportVideo");
LoadFileSystem();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void LoadFileSystem(){
this.localFileSave = new EGLocalFileSave();
localFileSave.RootPath = "SaveData";
if(!localFileSave.IsRemoteDirectoryExist("Media")){
localFileSave.MakeDirectory("Media");
}
RefreshList();
}
public void RefreshList(){
string combinedPath = Path.Combine(localFileSave.RootPath, "Media");
VideoList.ClearChildren();
foreach (var file in localFileSave.ListRemoteFilePath("Media")){
if(file.FileName.GetStrBehindSymbol('.')!="ogv" && file.FileName.GetStrBehindSymbol('.')!="jpg" && file.FileName.GetStrBehindSymbol('.')!="png"){
continue;
}
Button button= new Button();
button.Name = file.FileName;
button.Text = file.FileName;
string combinedFile = Path.Combine(combinedPath, button.Text);
button.Connect("pressed",Callable.From(()=>{
if(button.Text.GetStrBehindSymbol('.')=="ogv"){
PlayVideo(combinedFile);
}
if(button.Text.GetStrBehindSymbol('.')=="jpg" || button.Text.GetStrBehindSymbol('.')=="png"){
PlayImage(combinedFile);
}
}));
VideoList.AddChild(button);
}
}
public void PlayVideo(string videoName){
ViewVideo.Visible = true;
ViewImage.Visible = false;
GD.Print("PlayVideo: " + videoName);
ViewVideo.Stream.File = videoName;
ViewVideo.Play();
}
public void PlayImage(string imageName){
ViewVideo.Visible = false;
ViewImage.Visible = true;
GD.Print("PlayImage: " + imageName);
Image image = Image.LoadFromFile(imageName);
ImageTexture texture = ImageTexture.CreateFromImage(image);
ViewImage.Texture = texture;
// ViewImage.Texture = imageName;
}
public void OpenImportVideo(){
ImportVideo.Popup();
}
public void OpenImportImage(){
ImportImage.Popup();
}
public void UploadVideo(string localVideoPath){
localFileSave.UploadFile(localVideoPath,"Media\\"+Path.GetFileName(localVideoPath));
RefreshList();
OS.Alert("Video Upload Success!","success");
}
public void UploadImage(string localImagePath){
localFileSave.UploadFile(localImagePath,"Media\\"+Path.GetFileName(localImagePath));
RefreshList();
OS.Alert("Image Upload Success!","success");
}
}

6
Example/Action3D/MainGame.tscn → Example/OldTest/Action3D/MainGame.tscn

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
[gd_scene load_steps=19 format=3 uid="uid://05atvgqt8tku"]
[ext_resource type="Texture2D" uid="uid://ss8dh8aaqc4w" path="res://Example/Action3D/SkyBox/lakeside.jpg" id="1_akq3m"]
[ext_resource type="Texture2D" uid="uid://ss8dh8aaqc4w" path="res://Example/OldTest/Action3D/SkyBox/lakeside.jpg" id="1_akq3m"]
[ext_resource type="Texture2D" uid="uid://31r216hix0wk" path="res://icon.svg" id="2_b66wh"]
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionPlayer.cs" id="2_c0s4j"]
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionCamera.cs" id="3_ue0e3"]
[ext_resource type="Script" path="res://Example/OldTest/Action3D/Script/ActionPlayer.cs" id="2_c0s4j"]
[ext_resource type="Script" path="res://Example/OldTest/Action3D/Script/ActionCamera.cs" id="3_ue0e3"]
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_hbme1"]
panorama = ExtResource("1_akq3m")

0
Example/Action3D/Script/ActionCamera.cs → Example/OldTest/Action3D/Script/ActionCamera.cs

0
Example/Action3D/Script/ActionPlayer.cs → Example/OldTest/Action3D/Script/ActionPlayer.cs

0
Example/Action3D/SkyBox/lakeside.jpg → Example/OldTest/Action3D/SkyBox/lakeside.jpg

Before

Width:  |  Height:  |  Size: 4.1 MiB

After

Width:  |  Height:  |  Size: 4.1 MiB

9
Example/Action3D/SkyBox/lakeside.jpg.import → Example/OldTest/Action3D/SkyBox/lakeside.jpg.import

@ -3,16 +3,17 @@ @@ -3,16 +3,17 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://ss8dh8aaqc4w"
path.s3tc="res://.godot/imported/lakeside.jpg-33a4031d53286dbc1f7dd66477cda464.s3tc.ctex"
path.s3tc="res://.godot/imported/lakeside.jpg-73a51a0ded8953c63fe1a3672086bc03.s3tc.ctex"
path.etc2="res://.godot/imported/lakeside.jpg-73a51a0ded8953c63fe1a3672086bc03.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://Example/Action3D/SkyBox/lakeside.jpg"
dest_files=["res://.godot/imported/lakeside.jpg-33a4031d53286dbc1f7dd66477cda464.s3tc.ctex"]
source_file="res://Example/OldTest/Action3D/SkyBox/lakeside.jpg"
dest_files=["res://.godot/imported/lakeside.jpg-73a51a0ded8953c63fe1a3672086bc03.s3tc.ctex", "res://.godot/imported/lakeside.jpg-73a51a0ded8953c63fe1a3672086bc03.etc2.ctex"]
[params]

8
Example/Gateway/Gateway.tscn → Example/OldTest/Gateway/Gateway.tscn

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://hp4ae14r3hpm"]
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewGateway.cs" id="1_tas7d"]
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewTcpGateway.cs" id="2_ct4oh"]
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewBacNetGateway.cs" id="3_ip8nj"]
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewBacnetHttpServer.cs" id="4_plubp"]
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewGateway.cs" id="1_tas7d"]
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewTcpGateway.cs" id="2_ct4oh"]
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewBacNetGateway.cs" id="3_ip8nj"]
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewBacnetHttpServer.cs" id="4_plubp"]
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="5_q4lsg"]
[node name="Gateway" type="Control"]

0
Example/Gateway/GatewayManual/BacnetGatewayManual_CN.md → Example/OldTest/Gateway/GatewayManual/BacnetGatewayManual_CN.md

2
Example/Gateway/ModbusGateway.tscn → Example/OldTest/Gateway/ModbusGateway.tscn

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://c8vhi8ojdtjnb"]
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewModbusGateway.cs" id="1_34uaa"]
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewModbusGateway.cs" id="1_34uaa"]
[node name="ModbusGateway" type="Control"]
layout_mode = 3

0
Example/Gateway/Script/Data/DataBacNetGatewaySetting.cs → Example/OldTest/Gateway/Script/Data/DataBacNetGatewaySetting.cs

0
Example/Gateway/Script/Data/DataGatewayInfo.cs → Example/OldTest/Gateway/Script/Data/DataGatewayInfo.cs

0
Example/Gateway/Script/Data/DataModbusGatewaySettings.cs → Example/OldTest/Gateway/Script/Data/DataModbusGatewaySettings.cs

0
Example/Gateway/Script/Data/DataTcpGatewaySetting.cs → Example/OldTest/Gateway/Script/Data/DataTcpGatewaySetting.cs

0
Example/Gateway/Script/Interface/IGateway.cs → Example/OldTest/Gateway/Script/Interface/IGateway.cs

0
Example/Gateway/Script/OutData/ValueGenerator.cs → Example/OldTest/Gateway/Script/OutData/ValueGenerator.cs

0
Example/Gateway/Script/View/ViewBacNetGateway.cs → Example/OldTest/Gateway/Script/View/ViewBacNetGateway.cs

0
Example/Gateway/Script/View/ViewBacnetHttpServer.cs → Example/OldTest/Gateway/Script/View/ViewBacnetHttpServer.cs

0
Example/Gateway/Script/View/ViewGateway.cs → Example/OldTest/Gateway/Script/View/ViewGateway.cs

0
Example/Gateway/Script/View/ViewModbusGateway.cs → Example/OldTest/Gateway/Script/View/ViewModbusGateway.cs

0
Example/Gateway/Script/View/ViewTcpGateway.cs → Example/OldTest/Gateway/Script/View/ViewTcpGateway.cs

2
Example/ModbusDebugTool/Component/modbus_item.tscn → Example/OldTest/ModbusDebugTool/Component/modbus_item.tscn

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://c8kk7iegicmdr"]
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewModbusItem.cs" id="1_ih8g3"]
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewModbusItem.cs" id="1_ih8g3"]
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="1_upshn"]
[node name="ModbusItem" type="Control"]

0
Example/ModbusDebugTool/Script/DataModbusItem.cs → Example/OldTest/ModbusDebugTool/Script/DataModbusItem.cs

0
Example/ModbusDebugTool/Script/ViewEdit.cs → Example/OldTest/ModbusDebugTool/Script/ViewEdit.cs

0
Example/ModbusDebugTool/Script/ViewMenu.cs → Example/OldTest/ModbusDebugTool/Script/ViewMenu.cs

0
Example/ModbusDebugTool/Script/ViewMessage.cs → Example/OldTest/ModbusDebugTool/Script/ViewMessage.cs

0
Example/ModbusDebugTool/Script/ViewModbusItem.cs → Example/OldTest/ModbusDebugTool/Script/ViewModbusItem.cs

0
Example/ModbusDebugTool/Script/ViewSettings.cs → Example/OldTest/ModbusDebugTool/Script/ViewSettings.cs

10
Example/ModbusDebugTool/TestModbus.tscn → Example/OldTest/ModbusDebugTool/TestModbus.tscn

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
[gd_scene load_steps=7 format=3 uid="uid://qo2w16ececmu"]
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewMenu.cs" id="1_7ubyu"]
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewMenu.cs" id="1_7ubyu"]
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="1_tw1qu"]
[ext_resource type="PackedScene" uid="uid://c8kk7iegicmdr" path="res://Example/ModbusDebugTool/Component/modbus_item.tscn" id="3_c8jeq"]
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewEdit.cs" id="4_smsvf"]
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewMessage.cs" id="5_8s6lk"]
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewSettings.cs" id="6_38tri"]
[ext_resource type="PackedScene" uid="uid://c8kk7iegicmdr" path="res://Example/OldTest/ModbusDebugTool/Component/modbus_item.tscn" id="3_c8jeq"]
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewEdit.cs" id="4_smsvf"]
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewMessage.cs" id="5_8s6lk"]
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewSettings.cs" id="6_38tri"]
[node name="Menu" type="Control"]
layout_mode = 3

2
Example/SystemExamples/ItemList/HPPotion.tres → Example/OldTest/SystemExamples/ItemList/HPPotion.tres

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bhsavl0d80s6j"]
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs" id="1_j773b"]
[ext_resource type="Script" path="res://Example/OldTest/SystemExamples/PlayerStorage/Script/DataStorageItem.cs" id="1_j773b"]
[resource]
script = ExtResource("1_j773b")

0
Example/SystemExamples/ItemList/ItemList.CSV.import → Example/OldTest/SystemExamples/ItemList/ItemList.CSV.import

0
Example/SystemExamples/ItemList/ItemList.json → Example/OldTest/SystemExamples/ItemList/ItemList.json

0
Example/SystemExamples/ItemList/ItemList.txt → Example/OldTest/SystemExamples/ItemList/ItemList.txt

2
Example/SystemExamples/PlayerStorage/PlayerStorage.tscn → Example/OldTest/SystemExamples/PlayerStorage/PlayerStorage.tscn

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://tee7nc525si7"]
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs" id="1_goow2"]
[ext_resource type="Script" path="res://Example/OldTest/SystemExamples/PlayerStorage/Script/ViewStorage.cs" id="1_goow2"]
[node name="PlayerStorage" type="Control"]
layout_mode = 3

0
Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs → Example/OldTest/SystemExamples/PlayerStorage/Script/DataStorageItem.cs

0
Example/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs → Example/OldTest/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs

0
Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs → Example/OldTest/SystemExamples/PlayerStorage/Script/ViewStorage.cs

229
Example/ProtocolHelper/Scene/ProtocolHelper.tscn

@ -0,0 +1,229 @@ @@ -0,0 +1,229 @@
[gd_scene load_steps=2 format=3 uid="uid://byi2cseim0chx"]
[ext_resource type="Script" path="res://Example/ProtocolHelper/Script/ViewProtocolHelper.cs" id="1_47a58"]
[node name="ProtocolHelper" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_47a58")
[node name="DeviceMenu" type="VSplitContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.01
anchor_top = 0.01
anchor_right = 0.19
anchor_bottom = 0.99
[node name="DeviceScroll" type="ScrollContainer" parent="DeviceMenu"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
[node name="DeviceList" type="VBoxContainer" parent="DeviceMenu/DeviceScroll"]
layout_mode = 2
size_flags_horizontal = 3
[node name="Device1" type="HSplitContainer" parent="DeviceMenu/DeviceScroll/DeviceList"]
layout_mode = 2
[node name="Button" type="Button" parent="DeviceMenu/DeviceScroll/DeviceList/Device1"]
layout_mode = 2
size_flags_horizontal = 3
text = "Device1
"
expand_icon = true
[node name="CheckBox" type="CheckBox" parent="DeviceMenu/DeviceScroll/DeviceList/Device1"]
layout_mode = 2
[node name="DeviceFunctionList" type="VBoxContainer" parent="DeviceMenu"]
layout_mode = 2
size_flags_vertical = 3
[node name="Open" type="Button" parent="DeviceMenu/DeviceFunctionList"]
layout_mode = 2
text = "启动设备"
[node name="Close" type="Button" parent="DeviceMenu/DeviceFunctionList"]
layout_mode = 2
text = "关闭设备"
[node name="Add" type="Button" parent="DeviceMenu/DeviceFunctionList"]
layout_mode = 2
text = "增加设备"
[node name="Modify" type="Button" parent="DeviceMenu/DeviceFunctionList"]
layout_mode = 2
text = "修改设备"
[node name="Delete" type="Button" parent="DeviceMenu/DeviceFunctionList"]
layout_mode = 2
text = "删除设备"
[node name="ProtocolMenu" type="VSplitContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.81
anchor_top = 0.01
anchor_right = 0.99
anchor_bottom = 0.99
grow_horizontal = 2
grow_vertical = 2
[node name="ProtocolScroll" type="ScrollContainer" parent="ProtocolMenu"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
[node name="Protocol" type="VBoxContainer" parent="ProtocolMenu/ProtocolScroll"]
layout_mode = 2
size_flags_horizontal = 3
[node name="ProtocolName" type="HSplitContainer" parent="ProtocolMenu/ProtocolScroll/Protocol"]
layout_mode = 2
[node name="Button" type="Button" parent="ProtocolMenu/ProtocolScroll/Protocol/ProtocolName"]
layout_mode = 2
size_flags_horizontal = 3
text = "协议1"
[node name="CheckBox" type="CheckBox" parent="ProtocolMenu/ProtocolScroll/Protocol/ProtocolName"]
layout_mode = 2
[node name="FunctionList" type="VBoxContainer" parent="ProtocolMenu"]
layout_mode = 2
size_flags_vertical = 3
[node name="Add" type="Button" parent="ProtocolMenu/FunctionList"]
layout_mode = 2
text = "增加协议"
[node name="Modify" type="Button" parent="ProtocolMenu/FunctionList"]
layout_mode = 2
text = "修改协议"
[node name="Delete" type="Button" parent="ProtocolMenu/FunctionList"]
layout_mode = 2
text = "删除协议"
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
anchor_right = 0.8
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VSplitContainer" type="VSplitContainer" parent="PanelContainer"]
layout_mode = 2
[node name="Terminal" type="RichTextLabel" parent="PanelContainer/VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
bbcode_enabled = true
text = "[color=gray]【13:45:55:105】【TCP】127.0.0.1@6000 has been connected[/color]
[color=green]【13:45:55:265】【TCP】127.0.0.1@6000:[/color]Request
[color=cyan]【13:45:55:358】【TCP】127.0.0.1@6000:[/color][color=yellow]Response[/color]"
[node name="SettingGroup" type="VSplitContainer" parent="PanelContainer/VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="VSplitContainer" type="VSplitContainer" parent="PanelContainer/VSplitContainer/SettingGroup"]
layout_mode = 2
size_flags_vertical = 3
[node name="FunctionList2" type="HBoxContainer" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="Button" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
text = "报文筛选"
[node name="Button2" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
text = "报文分析"
[node name="Button4" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
text = "保存记录"
[node name="Button3" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
text = "清空记录"
[node name="Button5" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
text = "报文显示格式"
[node name="Button6" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList2"]
layout_mode = 2
size_flags_horizontal = 3
[node name="FunctionList1" type="HBoxContainer" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="Button" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
text = "连接设置"
[node name="Button2" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
text = "服务设置"
[node name="Button3" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
text = "发送设置"
[node name="Button4" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
text = "协议设置"
[node name="Button5" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
[node name="Button6" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/VSplitContainer/FunctionList1"]
layout_mode = 2
size_flags_horizontal = 3
[node name="SendArea" type="VSplitContainer" parent="PanelContainer/VSplitContainer/SettingGroup"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 2.0
[node name="SendEdit" type="TextEdit" parent="PanelContainer/VSplitContainer/SettingGroup/SendArea"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 2.0
[node name="SendButton" type="HBoxContainer" parent="PanelContainer/VSplitContainer/SettingGroup/SendArea"]
layout_mode = 2
size_flags_vertical = 3
[node name="Send" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/SendArea/SendButton"]
layout_mode = 2
size_flags_horizontal = 3
text = "发送"
[node name="HexSend" type="Button" parent="PanelContainer/VSplitContainer/SettingGroup/SendArea/SendButton"]
layout_mode = 2
size_flags_horizontal = 3
text = "Hex发送"

9
Example/ProtocolHelper/Script/Data/DataDevice.cs

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
namespace EGFramework.ProtocolHelper
{
public struct DataDevice
{
public string Sender { set; get; }
public ProtocolType ProtocolType { set; get; }
private bool IsConnected { set; get; }
}
}

29
Example/ProtocolHelper/Script/ViewProtocolHelper.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using Godot;
using System;
namespace EGFramework.ProtocolHelper
{
public partial class ViewProtocolHelper : Node
{
public override void _Ready()
{
}
public override void _ExitTree()
{
}
public void RefreshConnectList()
{
}
public void RefreshProtocolList()
{
}
}
}

6
Example/ProtocolHelper/Script/ViewProtocolHelperDeviceList.cs

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
using Godot;
using System;
public partial class ViewProtocolHelperDeviceList : Node
{
}

6
Example/ProtocolHelper/Script/ViewProtocolHelperProtocolList.cs

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
using Godot;
using System;
public partial class ViewProtocolHelperProtocolList : Node
{
}

6
Example/ProtocolHelper/Script/ViewProtocolHelperSendArea.cs

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
using Godot;
using System;
public partial class ViewProtocolHelperSendArea : Node
{
}

26
Example/ProtocolHelper/Script/ViewProtocolHelperTerminal.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
using EGFramework;
using Godot;
using System;
using System.Collections.Generic;
namespace EGFramework.ProtocolHelper
{
public partial class ViewProtocolHelperTerminal : RichTextLabel
{
public Dictionary<long, ResponseMsg> MessageMappings { set; get; } = new Dictionary<long, ResponseMsg>();
public override void _Ready()
{
}
public void ClearArea()
{
}
public void RefreshProtocol()
{
}
}
}

30
Example/SaveSystem/Scene/SaveSystem.tscn

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
[gd_scene load_steps=3 format=3 uid="uid://bvnma1n064xbx"]
[ext_resource type="Script" path="res://Example/SaveSystem/Script/ViewSaveSystem.cs" id="1_mtdgp"]
[ext_resource type="Texture2D" uid="uid://bpmhdi6qsq8xk" path="res://EGFramework.svg" id="2_qt8hb"]
[node name="SaveSystem" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("1_mtdgp")
[node name="TextureRect" type="TextureRect" parent="."]
visible = false
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
texture = ExtResource("2_qt8hb")
[node name="TabContainer" type="TabContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2

129
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using EGFramework.UI;
using Godot;
using LiteDB;
using Newtonsoft.Json;
using Renci.SshNet;
namespace EGFramework.Examples.Test {
public partial class ViewSaveSystem : Node, IEGFramework
{
public string[][] DataList { get; set; }
public string[][] DataList2 { get; set; }
Container container{ set; get; }
public override void _Ready()
{
TestTree();
}
public override void _ExitTree()
{
}
public void TestJson()
{
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
'Drives': [
'DVD read/writer'
/*(broken)*/,
'500 gigabyte hard drive',
'200 gigabyte hard drive'
],
'My' : {
'AA':'BB',
'Date': new Date(123456789)
}
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
if (reader.Value != null)
{
GD.Print("Token: {"+reader.TokenType+"}, Value: {"+ reader.Value+"}");
}
else
{
GD.Print("Token: {"+ reader.TokenType+"}");
}
}
}
public void TestTree()
{
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
'My' : {
'AA':'BB',
'Date': 111
}
}";
container = this.GetNode<TabContainer>("TabContainer");
EGodotTree eGodotTree = container.CreateNode<EGodotTree>("TestTree");
eGodotTree.InitByJson(json);
}
public void TestTable()
{
container = this.GetNode<TabContainer>("TabContainer");
List<DataStudent> dataStudents = new List<DataStudent>();
for (int stu = 0; stu < 10; stu++)
{
dataStudents.Add(new DataStudent("stu" + stu, 18));
}
for (int stu = 0; stu < 11; stu++)
{
dataStudents.Add(new DataStudent("A" + stu, 20 + stu));
}
EGodotTable table = container.CreateNode<EGodotTable>("Default");
table.InitData<DataStudent>(dataStudents);
EGSqliteSave SqliteTest = this.EGSave().Load<EGSqliteSave>("SaveData/test.db");
// IEnumerable<string> dataBaseKey = SqliteTest.GetKeys();
// GD.Print(dataBaseKey);
// foreach (string data in dataBaseKey)
// {
// GD.Print(data);
// }
EGodotSaveTable PersonTable = container.CreateNode<EGodotSaveTable>("SQLite");
PersonTable.InitSaveData<EGSqliteSave>(SqliteTest);
PersonTable.InitData<DataPerson>("person");
// EGodotTableRowData rowData = container.CreateNode<EGodotTableRowData>("RowData");
// rowData.Init(new Dictionary<string, object>() { { "Name", "Tom" }, { "Age", 18 } });
// EGodotRowData rowData2 = container.CreateNode<EGodotRowData>("RowData2");
// rowData2.Init(new Dictionary<string, object>() { { "Name", "Z" }, { "Age", 1 } });
// EGodotEditParam editParam = container.CreateNode<EGodotEditParam>("editParam");
// editParam.Init(new KeyValuePair<string, object>("数量",1));
}
}
public struct DataStudent
{
public string Name { get; set; }
public int Age;
public int ID;
public EGPathSelect Path { set; get; }
public DataStudent(string name, int age)
{
Name = name;
Age = age;
ID = 0;
Path = new EGPathSelect();
}
}
public struct DataPerson{
public string id { get; set; }
public string namee { set; get; }
public string workPlace { set; get; }
public string policeNum { set; get; }
}
}

14
Example/Theme/StyleBox/CardFrame.tres

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://t4prctf3uxtb"]
[resource]
bg_color = Color(0.858824, 0.858824, 0.858824, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0, 0, 0, 1)
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16
corner_detail = 1

3
Example/Theme/White/White.tres

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
[gd_resource type="Theme" format=3 uid="uid://cbf2s7b2p1p2j"]
[resource]

4
Example/Tween/EGTween.tscn

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://1garq2laye1n"]
[gd_scene load_steps=2 format=3 uid="uid://1garq2laye1n"]
[ext_resource type="Script" path="res://Example/Tween/Script/TweenTest.cs" id="1_jpym0"]
[ext_resource type="StyleBox" uid="uid://t4prctf3uxtb" path="res://Example/Theme/StyleBox/CardFrame.tres" id="2_cbb73"]
[node name="EgTween" type="Control" node_paths=PackedStringArray("Target", "Target2D")]
layout_mode = 3
@ -20,7 +19,6 @@ Target2D = NodePath("Polygon2D") @@ -20,7 +19,6 @@ Target2D = NodePath("Polygon2D")
offset_right = 90.0
offset_bottom = 160.0
pivot_offset = Vector2(45, 80)
theme_override_styles/panel = ExtResource("2_cbb73")
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(146, 80)

26
Example/UsingTest/Scene/TestEGFramework.tscn

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://dfa86yq8m28rk"]
[ext_resource type="Script" path="res://Example/UsingTest/Script/EGSaveTest.cs" id="1_eij2h"]
[node name="Test" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_eij2h")
[node name="Timer" type="Timer" parent="."]
autostart = true
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 361.0
offset_bottom = 164.0
[node name="Button1" type="Button" parent="."]
visible = false
layout_mode = 0
offset_right = 50.0
offset_bottom = 50.0

45
Example/UsingTest/Script/EGMDnsTest.cs

@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
using Godot;
using System;
using EGFramework;
using WebDav;
using System.Threading.Tasks;
using System.Net;
public partial class EGMDnsTest : Node, IEGFramework
{
private string serverUrl = "http://192.168.1.170:5212/dav";
private string username = "ZK@zk.com";
private string password = "uQTl7lzLSMZQ1QBd7sZZMlG2Gya65XKM";
public override void _Ready()
{
//TestDav();
}
public async void TestDav(){
this.EGWebDav().InitClient(serverUrl,username,password);
await InitClient();
}
public async Task<bool> InitClient()
{
string result = EncodeCredentials(username,password);
GD.Print(result);
//ScanWebDavAndDownload();
//await this.EGWebDav().DownloadFile("/dav/Picture/风景1.jpg",ProjectSettings.GlobalizePath("user://"),"风景1.jpg");
//Print("download success!");
//await this.EGWebDav().UploadFile(ProjectSettings.GlobalizePath("user://4.mp4"),"/dav/Picture","4.mp4");
await this.EGWebDav().UploadFile(ProjectSettings.GlobalizePath("user://PPT_Test.jpg"),"/dav/Picture","PPT_Test.jpg");
GD.Print("upload success!");
//var result = await this.EGWebDav().GetList("/Video");
//Print(JsonConvert.SerializeObject(result));
return true;
}
public static string EncodeCredentials(string username, string password)
{
string credentials = $"{username}:{password}";
byte[] credentialsBytes = System.Text.Encoding.UTF8.GetBytes(credentials);
string encodedCredentials = Convert.ToBase64String(credentialsBytes);
return encodedCredentials;
}
}

166
Example/UsingTest/Script/EGSaveTest.cs

@ -1,166 +0,0 @@ @@ -1,166 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
using LiteDB;
namespace EGFramework.Examples.Test{
public partial class EGSaveTest : Node,IEGFramework
{
public Label Label { set; get; }
public override void _Ready()
{
this.Label = this.GetNode<Label>("Label");
this.EGEnabledThread();
this.ExecuteAfterSecond(TestMainThreadFunc,2.0f);
//base._Ready();
//TestCode();
}
public async void TestThread(){
await Task.Run(()=>{
//this.ExecuteInMainThread(TestMainThreadFunc);
this.ExecuteAfterSecond(TestMainThreadFunc,2.0f);
});
}
public void TestMainThreadFunc(){
this.Label.Text = "Thread Test";
GD.Print("Invoked!");
}
public void TestSqlite(){
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>();
this.EGSqlite().SaveData(new SqliteBackpackItem{
ItemID = 10,
ItemCount = 1,
BackpackID = 1,
});
GD.Print(this.EGSqlite().ExceptionMsg);
// var properties = typeof(SqliteBackpackItem).GetFields();
// Godot.GD.Print(properties.Count() + " Readed ");
}
public void TestCode(){
// this.EGSave().OpenUserPath();
// GD.Print(ProjectSettings.GlobalizePath("res://SaveData/Default.json"));
// GD.Print(ProjectSettings.GlobalizePath("user://SaveData/Default.json"));
// GD.Print(Path.GetDirectoryName(ProjectSettings.GlobalizePath("res://SaveData/Default.json")));
// string Path2 = "Data1.json".GetGodotResPath();
// this.EGSave().LoadObjectFile<EGJsonSave>(Path2);
// this.EGSave().SetObject(Path2,"Customer1",new Customer() { Name = "Andy" });
// this.EGSave().SetObject(Path2,"Customer3",new Customer() { Name = "Terry" });
// string CardPath1 = "Card1";
// FileAccess fileAccess = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read);
// GD.Print(fileAccess.GetAsText());
// FileAccess testJson = FileAccess.Open("res://TestJson.json", FileAccess.ModeFlags.Read);
// this.EGSave().ReadObject<EGJsonSave>("TestJson",testJson.GetAsText());
// Customer customer = this.EGSave().GetObject<Customer>("TestJson","Customer3");
// GD.Print("ReadName is "+customer.Name);
// FileAccess testCSV = FileAccess.Open("res://SaveData/TestCSV.json", FileAccess.ModeFlags.Read);
// EGCsvSave csvSave = new EGCsvSave();
// csvSave.InitSaveFile("SaveData/TestCsv.csv");
// Customer testData = csvSave.GetData<Customer>("",1);
// GD.Print("Name = "+testData.Name +" || ID = "+testData.Id);
// CustomerByte testData = new CustomerByte(){
// Id = 1008,
// Name = "AddDataDefault",
// IsActive = true
// };
// csvSave.SetData("",testData,2)
string Path1 = "SaveData/TestCsv.csv".GetGodotResPath();
this.EGSave().LoadDataFile<EGCsvSave>(Path1);
IEnumerable<Customer> allResult = this.EGSave().FindData<Customer>(Path1,"",cus=>cus.Id==0);
foreach(Customer customer in allResult){
GD.Print(customer.Id +"|" + customer.Name);
}
// this.EGSave().SetData(Path1,"Customer1",new Customer() { Name = "Andy" },9);
// IEnumerable<Customer> allResult = this.EGSave().GetAllData<Customer>(Path1,"");
// foreach(Customer customer in allResult){
// GD.Print(customer.Id +"|" + customer.Name);
// }
// Customer customer1 = this.EGSave().GetData<Customer>(Path1,"",0);
// GD.Print(customer1.Id +"|" + customer1.Name);
// FileAccess testCsv = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read);
// this.EGSave().ReadData<EGCsvSave>("TestCsv",testCsv.GetAsText());
// this.EGSave().LoadObjectFile<EGByteSave>("SaveData/testDat.dat");
// // this.EGSave().SetObject("SaveData/testDat.dat","",testData);
// CustomerByte testDat = this.EGSave().GetObject<CustomerByte>("SaveData/testDat.dat","");
// GD.Print(testDat.Id);
// System.Linq.Expressions.Expression<Func<Customer, bool>> expr = i => i.Name == "Creature";
// IEnumerable<Customer> linqResult = csvSave.FindData<Customer>("",expr);
// GD.Print("Find result " + linqResult.Count());
// foreach(Customer customer in linqResult){
// GD.Print(customer.Id);
// }
// GD.Print(typeof(Customer));
// Type type = typeof(Customer);
// foreach(PropertyInfo property in type.GetProperties()){
// GD.Print(property.Name);
// CsvParamAttribute csvParam = property.GetCustomAttribute<CsvParamAttribute>();
// if(csvParam != null){
// GD.Print("["+csvParam._name+"]");
// }
// }
// foreach(FieldInfo property in type.GetFields()){
// GD.Print(property.Name);
// }
}
}
public struct SqliteBackpackItem{
public int Id { get; set; }
public int ItemID { get; set; }
public int ItemCount { get; set; }
public int BackpackID { get; set; }
}
public class Customer
{
[CsvParam("ID")]
public int Id { get; set; }
[CsvParam("Name")]
public string Name { get; set; }
public string[] Phones { get; set; }
[CsvParam("是否启用")]
public bool IsActive { get; set; }
}
public class CustomerByte : Customer, IResponse, IRequest
{
public byte[] ToProtocolByteData()
{
byte[] data = new byte[0];
data = data.Concat(((uint)Id).ToBytesLittleEndian()).ToArray();
return data;
}
public string ToProtocolData()
{
return "";
}
public bool TrySetData(string protocolData, byte[] protocolBytes)
{
if(protocolBytes != null && protocolBytes.Length >= 4){
Id = (int)protocolBytes.ToUINTLittleEndian();
return true;
}else{
return false;
}
}
}
}

315
Example/UsingTest/Script/EGTest.cs

@ -1,315 +0,0 @@ @@ -1,315 +0,0 @@
using Godot;
using static Godot.GD;
using System.Collections.Generic;
using EGFramework;
using Newtonsoft.Json;
using System;
using System.Net;
namespace EGFramework.Examples{
public partial class EGTest : Node,IEGFramework
{
public Label label { set; get; }
public override void _Ready()
{
this.EGEnabledProtocolTools();
this.EGMqtt().ConnectMQTTServer("192.168.1.220");
//this.EGUDP().UDPDevices[5555].Connect(IPAddress.Parse("224.0.0.251"),5353);
//byte[] sendData = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x5F, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5F, 0x64, 0x6E, 0x73, 0x2D, 0x73, 0x64, 0x04, 0x5F, 0x75, 0x64, 0x70, 0x05, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0x0C, 0x00, 0x01 };
//this.EGUDP().UDPDevices[5555].Send(sendData);
// this.EGRegisterMessageEvent<PrintResponse>((e,sender,protocol)=>{
// Print(sender);
// });
// this.EGOnMessage<PrintResponse>();
// this.EGReadFromFile("SaveData/MySeg2.seg2");
//TestTCPClient();
//TestSerialPort();
//TestTCPServer();
//this.EGUDP();
//this.EGUDPListen(11000);
//this.EGSendMessage(new MessageStruct(1,"xxx"),"192.168.1.192:9002",ProtocolType.UDP);
//this.EGHttpClient();
//this.EGHttpServer().Listen("http://+:6555/index/");
}
public override void _Process(double delta)
{
//Print(this.EGMqtt().MqttDevices["192.168.1.220"].IsConnected);
}
public override void _ExitTree()
{
}
public void OnButton1Click(){
this.EGMqtt().SubScribeTheme("192.168.1.220","test");
byte[] testData = {0x3A,0x55};
this.EGMqtt().PublishTheme("192.168.1.220","test",testData);
}
public void RefreshMsg(bool coil){
label.Text += coil+" ";
}
public void OnTimer(){
//this.EGSendMessage(new MessageStruct(1,"山东博裕1"),"COM4",ProtocolType.SerialPort);
//this.EGSendMessage(new MessageStruct(1,"山东博裕1"),"192.168.1.244:6060",ProtocolType.TCPClient);
//this.EGSendMessage(new ModbusTCP_WriteMultiCoil(1,0,sendData),"192.168.1.200:3000",ProtocolType.TCPClient);
//TestSingleCoil();
//TestMultiCoil();
//TestSingleHoldingRegister();
//TestMultiHoldingRegister();
}
public void TestModbus(){
label = this.GetNode<Label>("Label");
label.Text = "[Modbus]";
this.EGRegisterMessageEvent<MessageResponse>((e,sender,type)=>{
Print("[Got Response]"+"[sender = "+sender+"]"+"["+type+"]"+ e.MessageId+"||"+e.Author);
});
this.EGOnMessage<MessageResponse>();
this.EGRegisterMessageEvent<ModbusTCP_Response>((e,sender,type)=>{
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadCoil){
int registerId = 0;
foreach(bool coil in e.Coil){
Print(registerId + "Status:" + coil);
registerId++;
}
}
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadDiscreteInput){
int registerId = 0;
foreach(bool discreteInput in e.DiscreteInput){
Print(registerId + "Status:" + discreteInput);
registerId++;
}
}
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadHoldingRegisters){
int registerId = 0;
foreach(ushort holdingRegister in e.HoldingRegister){
Print(registerId + "Status:" + holdingRegister);
registerId++;
}
}
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadInputRegisters){
int registerId = 0;
foreach(ushort inputRegister in e.InputRegister){
Print(registerId + "Status:" + inputRegister);
label.Text+=registerId + "Status:" + inputRegister;
registerId++;
}
}
//this.EGOffMessage<ModbusTCP_Response>();
});
this.EGRegisterMessageEvent<ModbusRTU_Response>((e,sender,type)=>{
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadCoil){
int registerId = 0;
foreach(bool coil in e.Coil){
Print(registerId + "Status:" + coil);
registerId++;
}
}
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadDiscreteInput){
int registerId = 0;
foreach(bool discreteInput in e.DiscreteInput){
Print(registerId + "Status:" + discreteInput);
registerId++;
}
}
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadHoldingRegisters){
int registerId = 0;
foreach(ushort holdingRegister in e.HoldingRegister){
Print(registerId + "Status:" + holdingRegister);
registerId++;
}
}
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadInputRegisters){
int registerId = 0;
foreach(ushort inputRegister in e.InputRegister){
Print(registerId + "Status:" + inputRegister);
label.Text+=registerId + "Status:" + inputRegister;
registerId++;
}
}
//this.EGOffMessage<ModbusRTU_Response>();
});
}
public void TestTCPServer(){
this.EGTCPServer().OnClientConnect.Register(e=>{
Print(e +" is connected");
this.EGSendMessage(new MessageStruct(1,"Hello"),e,ProtocolType.TCPServer);
});
this.EGTCPServer().OnClientDisconnect.Register(e=>{
Print(e +" is disconnect");
});
this.EGTCPServerListen(9999);
}
public void TestSqlite(){
this.EGSqlite().SaveData(new TestBoxMessage());
List<TestBoxMessage> result = this.EGSqlite().GetDataSet<TestBoxMessage>();
if(result == null){
PrintErr(this.EGSqlite().ExceptionMsg);
}
Print("Result = " + result[0].TestDouble + result[0].TestFloat);
}
public void TestSerialPort(){
this.EGSerialPort().SetBaudRate(9600);
this.EGSendMessage(new ModbusRTU_ReadInputRegisters(1,0,2),"COM4",ProtocolType.SerialPort);
this.EGSendMessage(new ModbusRTU_ReadCoils(1,0,8),"COM4",ProtocolType.SerialPort);
this.EGOnMessage<ModbusRTU_Response>();
}
public void TestTCPClient(){
this.EGTCPClient();
this.EGSendMessage(new ModbusTCP_ReadDiscreteInput(1,0,8),"192.168.1.196:6000",ProtocolType.TCPClient);
this.EGSendMessage(new ModbusTCP_ReadInputRegisters(1,0,2),"192.168.1.196:6000",ProtocolType.TCPClient);
this.EGOnMessage<ModbusTCP_Response>();
}
private bool IsOpen = false;
public void TestSingleCoil(){
if(IsOpen){
//this.EGSendMessage(new ModbusRTU_WriteSingleCoil(1,0,false),"COM4",ProtocolType.SerialPort);
this.EGSendMessage(new ModbusTCP_WriteSingleCoil(1,0,false),"192.168.1.196:6000",ProtocolType.TCPClient);
IsOpen = false;
}else{
//this.EGSendMessage(new ModbusRTU_WriteSingleCoil(1,0,true),"COM4",ProtocolType.SerialPort);
this.EGSendMessage(new ModbusTCP_WriteSingleCoil(1,0,true),"192.168.1.196:6000",ProtocolType.TCPClient);
IsOpen = true;
}
}
public void TestMultiCoil(){
byte[] OpenCode = {0xFF};
byte[] CloseCode = {0x00};
if(IsOpen){
this.EGSendMessage(new ModbusRTU_WriteMultiCoil(1,0,CloseCode.ToBoolArray()),"COM4",ProtocolType.SerialPort);
IsOpen = false;
}else{
this.EGSendMessage(new ModbusRTU_WriteMultiCoil(1,0,OpenCode.ToBoolArray()),"COM4",ProtocolType.SerialPort);
IsOpen = true;
}
}
public void TestSingleHoldingRegister(){
if(IsOpen){
this.EGSendMessage(new ModbusRTU_WriteSingleHoldingRegister(1,0,0x00),"COM4",ProtocolType.SerialPort);
IsOpen = false;
}else{
this.EGSendMessage(new ModbusRTU_WriteSingleHoldingRegister(1,0,0x01),"COM4",ProtocolType.SerialPort);
IsOpen = true;
}
}
public void TestMultiHoldingRegister(){
ushort[] OpenCode = {1,1,1,1,1,1,1,1};
ushort[] CloseCode = {0,0,0,0,0,0,0,0};
if(IsOpen){
this.EGSendMessage(new ModbusRTU_WriteMultiHoldingRegister(1,0,CloseCode),"COM4",ProtocolType.SerialPort);
IsOpen = false;
}else{
this.EGSendMessage(new ModbusRTU_WriteMultiHoldingRegister(1,0,OpenCode),"COM4",ProtocolType.SerialPort);
IsOpen = true;
}
}
}
public class TestBoxMessage {
public int Code = 0;
public float TestFloat = 0.1f;
public double TestDouble;
public bool IsHaveMessage;
public string MessageInfo;
public MessageType MsgType;
public MessageStruct MsgStruct;
public MessagePair MsgPair;
public TestBoxMessage(){
this.Code = 1;
this.TestFloat = 1.2f;
this.TestDouble = 2.52;
this.IsHaveMessage = true;
this.MessageInfo = "DefaultInfo";
MsgType = MessageType.TypeInt;
MsgPair = new MessagePair();
MsgStruct = new MessageStruct(5,"Ad");
}
public string ToProtocolData()
{
return JsonConvert.SerializeObject(this);
}
}
public class MessagePair{
public int MessageId;
public string Author;
public string MessageInfo;
public int TimeStamp;
public MessagePair(){
this.MessageId = 10001;
this.Author = "Admin";
this.MessageInfo = "Hello every one!";
this.TimeStamp = 1690188342;
}
}
public struct MessageStruct : IRequest,IEGFramework{
public string FunctionCode;
public int MessageId;
public string Author;
public MessageStruct(int messageId,string author){
FunctionCode = "Message";
MessageId = messageId;
Author = author;
}
public byte[] ToProtocolByteData()
{
return JsonConvert.SerializeObject(this).ToBytesByEncoding("GBK");
}
public string ToProtocolData()
{
return "";
//return JsonConvert.SerializeObject(this);
}
}
public struct MessageResponse : IResponse
{
public string FunctionCode { set; get; }
public int MessageId;
public string Author;
public bool TrySetData(string protocolData, byte[] protocolBytes)
{
try
{
//GD.Print(protocolData);
MessageResponse res = JsonConvert.DeserializeObject<MessageResponse>(protocolData);
if(res.FunctionCode == "Message"){
this.FunctionCode = res.FunctionCode;
this.MessageId = res.MessageId;
this.Author = res.Author;
return true;
}
return false;
}
catch (Exception)
{
return false;
}
}
}
public struct PrintResponse : IResponse
{
public bool TrySetData(string protocolData, byte[] protocolBytes)
{
//Print("Received String is " + protocolData);
Print("Received bytes is " + protocolBytes.ToStringByHex());
return true;
}
}
public enum MessageType{
TypeString = 1,
TypeInt = 2,
TypeObject = 3,
TypeArray = 4
}
}

250
ReadMe.md

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
![Logo](EGFramework.png)
# EGFramework 使用手册
---
@ -5,8 +8,10 @@ @@ -5,8 +8,10 @@
# 引言
> `EGFramework`全称Everyone's Godot framework,基于`Godot`开源引擎,使用C#编写,目前仅兼容`Godot4.3 - .NET`,部分兼容`Godot3.5 - .NET`,是完全开源的组件式,功能分布的框架,使用时可以自己根据需求安装对应的`Module`来实现对应的功能,同样也可以裁剪对应的`Module`来删减对应的功能。
>
> `Module` 是`EGFramework`的核心组成部分,也是`EGFramework`中重要的扩展依据。详细可以查看第二部分-Module。
>
> `Module` 是`EGFramework`的核心组成部分,也是`EGFramework`中重要的扩展依据。
>
> 目前该框架可能还有很多欠缺与不足,最终目的是做一个方便可靠好用的通讯&存储&资源生成&界面生成框架、用户无需过多学习、开箱即用。
# 关于Godot引擎(摘自[Godot Engine (4.x) 简体中文文档](https://docs.godotengine.org/zh-cn/4.x/about/introduction.html))
@ -16,11 +21,15 @@ @@ -16,11 +21,15 @@
>
> Godot 在 [宽松的 MIT 许可证](https://docs.godotengine.org/zh-cn/4.x/about/complying_with_licenses.html#doc-complying-with-licenses) 下完全自由且开源,没有附加条件、没有抽成、什么都没有。用户的游戏乃至引擎的每一行代码,都归用户自己所有。Godot 的开发完全独立且由社区驱动,允许用户为满足需求重塑引擎。它受到不以盈利为目标的 [Godot 基金会](https://godot.foundation/)支持。
---
# 一、准备工作
## 1.下载开发环境
本章节所有环境均在开源IDE `VSCode`,`Godot4.2 - .NET` 的环境下进行,请确保已经下载好`VSCode`,`Godot4.2 - .NET`,如果您有购买Rider或者其他编码工具可以根据自己的喜好来替代VSCode。
本章节所有环境均在开源IDE `VSCode`,`Godot4.3 - .NET` 的环境下进行,请确保已经下载好`VSCode`,`Godot4.3 - .NET`,<b>本项目Godot版本可能并非最新</b>,但作者会尽可能的升级至最新版的Godot,在此之间请按照如下方式进行框架的集成工作,如果您有购买Rider或者其他编码工具可以根据自己的喜好来替代VSCode。
## 2.VSCode 插件安装
@ -30,15 +39,29 @@ @@ -30,15 +39,29 @@
## 3.Nuget包的安装
打开VSCode,按下`Ctrl+Shift+P`,在搜索栏里面搜索`Nuget Package ManagerGUI`,选择右侧`Install New Pakage` ,依次安装以下依赖包:
- System.IO.Ports(仅EGSerialPort 使用)
- Newtonsoft.Json(使用场合较多)
打开VSCode,将如下部分替换或增加至您名称为*.csproj后缀的工程文件下。
- Microsoft.Data.Sqlite(仅EGSQLite使用)
```xml
<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="WebDav.Client" Version="2.8.0" />
<PackageReference Include="MQTTnet" Version="4.3.3.952" />
<PackageReference Include="Makaretu.Dns.Multicast" Version="0.27.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
<PackageReference Include="LiteDB" Version="5.0.21" />
<PackageReference Include="BACnet" Version="2.0.4" />
<PackageReference Include="MySql.Data" Version="9.1.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.31" />
<PackageReference Include="FluentFTP" Version="52.1.0" />
</ItemGroup>
```
- System.Text.Encoding.CodePages(ProtocolTools目录下均有使用)
首次编译确保计算机可以联网,并可以连接该网站[NuGet Gallery | Home](https://www.nuget.org/)
注意:这些Nuget包仅为目前框架版本所用,后续可能会有新的Nuget包导入,会在此处列出。
@ -48,63 +71,22 @@ @@ -48,63 +71,22 @@
无需担心,除了部分Module存在相关依赖,大部分Module是支持直接删除的。
## 5.EG插件库简介
### 5.1 EGSave篇
---
#### Sqlite数据持久化扩展:
注意:本功能需要依赖安装 `Microsoft.Data.Sqlite` Nuget扩展,将以下代码放入*.csproj 工程文件中,或者通过Nuget安装上述包。
```xml
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.1" />
```
使用案例(保存数据=>保存单一数据,目前来看该功能仍需改进):
```csharp
public partial class EGSaveTest : Node,IEGFramework
{
public override void _Ready()
{
TestSqlite();
}
public void TestSqlite(){
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>();
this.EGSqlite().SaveData(new SqliteBackpackItem{
ItemID = 10,
ItemCount = 1,
BackpackID = 1,
});
GD.Print(this.EGSqlite().ExceptionMsg);
}
}
public struct SqliteBackpackItem{
public int ItemID;
public int ItemCount;
public int BackpackID;
}
```
结构类要求:保存字段不能使用 {get;set;},所有数据会自动生成自增序列的ID,字段名称不能为ID。
# 二、框架简介
由于该框架使用了较多的Nuget包实现相关的功能,所以安装较为繁琐,同时因为用到较多的扩展方法,提示词可能比较冗余。您可以通过删除对应的Module来定制化自己的框架,也可以新增自己的Module来扩展自己的框架。
本框架所使用的一切Nuget包均满足MIT开源协议,如果使用的Nuget包牵扯有其他协议请联系作者QQ:1031139173,会删除对应的Module功能保证该框架满足MIT协议
如果使用的Nuget包牵扯有侵犯您的许可,请联系作者Mail:1031139173@qq.com,作者尽可能第一时间删除对应的Module功能。
协议文件均存放在目录addons\EGFramework\License_Third_Part下面
第三方许可文件均存放在目录addons\EGFramework\License_Third_Part下面
## 1.使用框架
## 2.1 使用框架
添加using,并继承接口IEGFramework,即可使用该框架了。
以下以一个EGSave的例子,来展示一下框架的存档功能,其他详细用法可以参阅查看Manual-EGSave对应的部分。
```csharp
using Godot;
using static Godot.GD;
@ -112,121 +94,73 @@ using System.Collections.Generic; @@ -112,121 +94,73 @@ using System.Collections.Generic;
using EGFramework;
public partial class EGTest : Node,IEGFramework{
DataTest dataTest = this.EGSave().GetDataByFile<DataTest>();
if (dataTest == null)
{
dataTest = new DataTest();
dataTest.PlayerName = "Player1";
dataTest.Hp = 100;
        this.EGSave().SetDataToFile(dataTest);
}
}
public class DataTest{
public string PlayerName;
public int Hp;
}
```
## 2.直接使用Module
更多可参考Example。
继承接口IEGFramework时,可以直接通过this.GetModule这个扩展方法直接获取该模块。上面的代码可以通过直接调用的方式改写成如下:
## 2.2 发送与监听消息
```csharp
using Godot;
using static Godot.GD;
using System.Collections.Generic;
using EGFramework;
public partial class EGTest : Node,IEGFramework{
DataTest dataTest = this.GetModule<EGSave>().GetDataByFile<DataTest>();
if (dataTest == null)
{
dataTest = new DataTest();
dataTest.PlayerName = "Player1";
dataTest.Hp = 100;
this.GetModule<EGSave>().SetDataToFile(dataTest);
}
}
public class DataTest{
public string PlayerName;
public int Hp;
}
```
## 3.扩展框架(编写Module)
## 2.3 使用本地存储
编写框架时,要用到IModule这个接口,任何继承了该接口的类均视为Module,可以被上面的方法Get到。
同时我们提供了一个简单的实现接口的抽象类EGModule,继承该类等同于实现接口IModule。
注意的是,因为C#仅支持单继承,如果您需要继承其他工具类或者是Godot的对应类,您应该使用接口而不是抽象类,具体用法可以参考ProtocolTools.EGProtocolSchedule这个类,它通过一个Node的生命周期的_Process()方法实现了特定线程中的消息拾取到主线程的功能。
# 三、EGFramework-API
一个简单的单例对象扩展可以写成如下:
目前已有的EGFramework功能组件。标记是目前已编写完成,未标记是未编写完成或未测试。
```csharp
using System;
using System.Collections.Generic;
- [x] ProtocolTools&ProtocolExtension
- [x] SaveTools
- [x] OtherTools
- [x] Extension
- [x] NodeExtension(仅Godot下可用)
- [ ] GenerateTools
- [ ] UITools
namespace EGFramework
{
public interface IEGObject
{
void RegisterObject<T>(T object_);
T GetObject<T>() where T : class,new();
}
public class EGObject : EGModule,IEGObject
{
private IOCContainer ObjectContainer = new IOCContainer();
public override void Init()
{
}
public TObject GetObject<TObject>() where TObject : class,new()
{
if (!ObjectContainer.self.ContainsKey(typeof(TObject)))
{
this.RegisterObject(new TObject());
}
return ObjectContainer.Get<TObject>();
}
public void RegisterObject<TObject>(TObject object_)
{
ObjectContainer.Register(object_);
}
public bool ContainsObject<TObject>(){
return ObjectContainer.self.ContainsKey(typeof(TObject));
}
}
public static class CanGetObjectExtension
{
public static T EGGetObject<T>(this IEGFramework self) where T : class,new()
{
return EGArchitectureImplement.Interface.GetModule<EGObject>().GetObject<T>();
}
}
public static class CanRegisterObjectExtension
{
public static void EGRegisterObject<T>(this IArchitecture self,T object_) where T : class,new()
{
self.GetModule<EGObject>().RegisterObject(object_);
}
public static void EGRegisterObject<T>(this IEGFramework self,T object_) where T : class,new()
{
EGArchitectureImplement.Interface.GetModule<EGObject>().RegisterObject(object_);
}
}
public static class CanContainsObjectExtension{
public static bool EGContainsObject<T>(this IEGFramework self)
{
return EGArchitectureImplement.Interface.GetModule<EGObject>().ContainsObject<T>();
}
}
### 3.1 消息篇(EGMessage-ProtocolTools)
}
```
---
#### 通讯支持
- [x] TCPClient
- [x] TCPServer
- [x] UDP(Listen&Send)
- [x] SerialPort
- [x] Ssh
- [x] WebSocketClient
- [x] Bacnet
- [x] MQTT
- [ ] HttpClient
- [ ] HttpServer
#### 异步处理支持
- [x] FileStream
- [x] Process
### 3.2 存储篇(EGMessage-ProtocolTools)
#### 键值对象存储支持
- [x] Json
- [x] Redis
- [ ] Byte
#### 数据存储支持
- [x] Csv
- [x] LiteDB
- [x] MySQL(Dapper)
- [x] Sqlite(Dapper)
- [x] Dapper
#### 文件存储支持
- [x] FTP
- [x] LocalFile
- [ ] Sftp
- [ ] WebDav

48
addons/EGFramework/EGPlatform.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
using System;
using System.Diagnostics;
namespace EGFramework{
public interface IPlatform{
void Log(string message);
void Log(params object[] what);
}
public class EGPlatformGodot : IPlatform{
public void Log(string message){
Godot.GD.Print(message);
// Console.WriteLine(message);
}
public void Log(params object[] what){
Godot.GD.Print(what);
// Console.WriteLine(what);
}
}
// if not use please explain this
public class EGPlatformDotnet : IPlatform{
public void Log(string message){
Console.WriteLine(message);
}
public void Log(params object[] what){
Console.WriteLine(what);
}
}
public static class EG
{
public static EGPlatformGodot Platform = new EGPlatformGodot();
public static void Print(string message){
Platform.Log(message);
}
public static void Print(params object[] what){
Platform.Log(what);
}
}
// public enum SupportPlatform{
// Godot = 0x01,
// Unity = 0x02,
// WebApi = 0x03,
// WPF = 0x04,
// Form = 0x05,
// }
}

6
addons/EGFramework/License_Third_Part/Dapper/License.txt

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
The Dapper library and tools are licenced under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
The Dapper logo is copyright Marc Gravell 2021 onwards; it is fine to use the Dapper logo when referencing the Dapper library and utilities, but
the Dapper logo (including derivatives) must not be used in a way that misrepresents an external product or library as being affiliated or endorsed
with Dapper. For example, you must not use the Dapper logo as the package icon on your own external tool (even if it uses Dapper internally),
without written permission. If in doubt: ask.

0
addons/EGFramework/License_Third_Part/Microsoft_Data_SQLite/LICENSE.txt → addons/EGFramework/License_Third_Part/Dotnet/LICENSE.txt

7
addons/EGFramework/License_Third_Part/FluentFTP/LICENSE.TXT

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
Copyright (c) 2015 Robin Rodricks and FluentFTP Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21
addons/EGFramework/License_Third_Part/LiteDB/LICENSE.txt

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2022 Mauricio David
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

21
addons/EGFramework/License_Third_Part/Makaretu_Dns_Multicast/LICENSE.txt

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Richard Schneider
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
addons/EGFramework/License_Third_Part/Mysql_Data/Notice.txt

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
GPL-2.0-only license licenseWITH license licenseUniversal-FOSS-exception-1.0 license
https://licenses.nuget.org/GPL-2.0-only
https://licenses.nuget.org/Universal-FOSS-exception-1.0

47
addons/EGFramework/License_Third_Part/StackExchange_Redis/LICENSE.txt

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
The MIT License (MIT)
Copyright (c) 2014 Stack Exchange
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
===============================================
Third Party Licenses:
The Redis project (https://redis.io/) is independent of this client library, and
is licensed separately under the three clause BSD license. The full license
information can be viewed here: https://redis.io/topics/license
This tool makes use of the "redis-doc" library from https://redis.io/documentation
in the intellisense comments, which is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International license; full
details are available here:
https://github.com/antirez/redis-doc/blob/master/COPYRIGHT
The development solution uses the Redis-64 package from nuget
(https://www.nuget.org/packages/Redis-64) by Microsoft Open Technologies, inc.
This is licensed under the BSD license; full details are available here:
https://github.com/MSOpenTech/redis/blob/2.6/license.txt
This tool is not used in the release binaries.
The development solution uses the BookSleeve package from nuget
(https://code.google.com/p/booksleeve/) by Marc Gravell. This is licensed
under the Apache 2.0 license; full details are available here:
https://www.apache.org/licenses/LICENSE-2.0
This tool is not used in the release binaries.

224
addons/EGFramework/Manual/EGMessage.md

@ -0,0 +1,224 @@ @@ -0,0 +1,224 @@
# Protocol Tools 使用指南
> 本指南首次修订于:2025.6.13
>
> 最后修改日期:2025.6.13
Protocol Tools允许您在任何通讯物理层发送信息、接受服务器返回的信息、过滤您的脏数据。
目前工具以发布+订阅的方式处理消息,后续会增加问答的方式处理消息。
本指南中,您将学到以下内容
- 如何在互联网&串口通讯&文件读写&进程吞吐中,发送您的请求,获取您的响应消息。
- 如何自定义消息类,发送您的消息,处理远端响应的消息。
- 自定义插拔式的开启或关闭消息处理功能。
- Protocol Tools的消息解耦原理
---
# 目录
[TOC]
---
# 发送请求部分
## 1. 定义您的请求
发送请求是通讯的第一步,如果您只需要连接到对应的服务器,接受对应的推送,而无需发送任何消息请移步至 [4. 定义您的响应](## 4. 定义您的响应)
新建一个结构类`DataStudent`
```csharp
public struct DataStudent{
public string Name { get; set; }
public int Age;
public int ID;
public DataStudent(string name,int age){
Name = name;
Age = age;
ID = 0;
}
}
```
实现`IRequest`接口
`IRequest`包含两种输出最终发送结果的方法,如果您需要发送字符类型的数据格式,请实现`ToProtocolData`这个方法,如果您需要发送Hex类型的数据格式,请实现`ToProcotolByteData`这个方法。
注意:切勿实现两个方法,实现两个方法会同时发送字符类型+Hex类型两种数据格式的拼接(字符在前,Hex在后,因为字符根据Encoding会转码成未知的Hex数据,不推荐这样做),请实现其中一个,另外一个使用 `return null` 来填补空缺
```csharp
public struct DataStudent :IRequest{
public string Name { get; set; }
public int Age;
public int ID;
public DataStudent(string name,int age){
Name = name;
Age = age;
ID = 0;
}
public string ToProtocolData()
{
return JsonConvert.SerializeObject(this);
}
public byte[] ToProtocolByteData()
{
return null;
}
}
```
## 2. 发送您的请求
定义好您的请求后,在特定类的代码域里可以通过`this.EGSendMessage<T>(T t)`发送您的请求,该类需要实现`IEGFramework`
该方法包含三个参数,实现`IRequest`的数据对象,发送对象(sender),以及协议类型。
发送对象一般为注册过的连接,包含IP地址以及端口等参数。
```csharp
public partial class ViewTestStudent : Node,IEGFramework
{
public override void _Ready()
{
this.EGSendMessage<DataStudent>(new DataStudent(), "127.0.0.1:6000", ProtocolType.TCPClient);
}
}
```
## 3. 设定您的发送间隔
您有没有发现,在您连续发送两条消息的时候,会产生一个0.1s左右的间隔,这个设计是为了防止连续多次发送消息的时候产生粘包现象,如果您需要立即发送,或者是延长这个间隔,可以通过以下方式设定发送间隔。
```csharp
// 两消息之间设定无间隔,立刻发送
this.GetModule<EGMessage>().SetDelay(0);
// 两消息之间设定间隔1s后再发送
this.GetModule<EGMessage>().SetDelay(1000);
```
---
# 处理响应部分
## 4. 定义您的响应
当连接到服务器时,如果您先发起请求,此时服务器会处理您的请求,有一段时间的空白期,或者该服务器是广播型服务器,即使不发送请求,也会推送数据给您。
新建一个结构类`DataStudent`
```csharp
public struct DataStudent{
public string Name { get; set; }
public int Age;
public int ID;
public DataStudent(string name,int age){
Name = name;
Age = age;
ID = 0;
}
}
```
实现`IResponse`接口
`IResponse`包含两个输入数据的参数的方法用来过滤请求数据,建议您在这个方法内使用try catch 函数,以防止在程序处理异常时中断程序。如果您需要按照hex格式处理或者按照字符格式处理,请在这个函数里面写明对应的方法。
该实现方法会返回一个布尔值的变量,如果返回true,则认同这个消息为该类型的消息并对该条消息进行事件处理。如果返回false,则不认同,也不会对该条消息进行事件处理。
```csharp
public struct DataStudent :IResponse{
public string Name { get; set; }
public int Age;
public int ID;
public DataStudent(string name,int age){
Name = name;
Age = age;
ID = 0;
}
public bool TrySetData(string protocolData, byte[] protocolBytes)
{
try
{
DataStudent input = JsonConvert.DeserializeObject<DataStudent>(protocolData);
if (this.Name == "")
{
return false;
}
else
{
this.Name = input.Name;
this.Age = input.Age;
this.ID = input.ID;
return true;
}
}
catch (System.Exception)
{
return false;
}
}
}
```
## 5. 注册响应的处理事件
定义好您的响应后,您可以通过注册响应处理事件`this.EGRegisterMessageEvent<T>(Action<T> a)`实现收到该消息并处理。注册事件中有三个参数可以选择,分别是收到的消息本身的结构体&对象,发送对象(sender),以及协议类型。消息可以无关通讯协议的类型,做到任何连接推送的消息都能收到并按照注册的事件进行处理。
同时,注册事件结束后,必须手动开启消息处理`EGOnMessage`,如果有需要,也可以在处理完消息之后关闭消息处理。
```csharp
public partial class ViewSaveSystem : Node,IEGFramework
{
public override void _Ready()
{
this.EGRegisterMessageEvent<DataStudent>((data,sender,protocol) =>
{
GD.Print(data.Name);
// 关闭消息处理
this.EGOffMessage<DataStudent>();
});
// 开启消息处理
this.EGOnMessage<DataStudent>();
}
}
```
## 6. 启用对应的协议工具
在场景中的Node下,注册改脚本并启用对应的协议工具,切记,所有通讯工具必须实现`IProtocolReceived`接口,大部分可用的通讯工具均以EG开头。
```csharp
public partial class ViewSaveSystem : Node,IEGFramework
{
public override void _Ready()
{
// 启用对应的协议工具,此处以TCP客户端为例,需要其它协议开启对应的工具即可
this.EGEnabledProtocolTool<EGTCPClient>();
// 处理消息部分
this.EGRegisterMessageEvent<DataStudent>((data,sender,protocol) =>
{
GD.Print(data.Name);
// 关闭消息处理
this.EGOffMessage<DataStudent>();
});
// 开启消息处理
this.EGOnMessage<DataStudent>();
}
}
```

146
addons/EGFramework/Module/Extension/EGSqlExtension.cs

@ -0,0 +1,146 @@ @@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace EGFramework
{
public static class EGSqlExtension
{
public static string ToCreateTableSQL(this PropertyInfo property)
{
string sqlCommand;
if (property.Name == "ID" || property.Name == "id" || property.Name == "Id")
{
return "";
}
if (property.PropertyType == typeof(int) || property.PropertyType.IsEnum)
{
sqlCommand = "`" + property.Name + "` INTEGER" + " NOT NULL,";
}
else if (property.PropertyType == typeof(double) || property.PropertyType == typeof(float))
{
sqlCommand = "`" + property.Name + "` REAL" + " NOT NULL,";
}
else if (property.PropertyType == typeof(bool))
{
sqlCommand = "`" + property.Name + "` REAL" + " NOT NULL,";
}
else if (property.PropertyType == typeof(long))
{
sqlCommand = "`" + property.Name + "` BIGINT(20)" + " NOT NULL,";
}
else if (property.PropertyType == typeof(string))
{
sqlCommand = "`" + property.Name + "` VARCHAR(255)" + " NOT NULL,";
}
else
{
sqlCommand = "`" + property.Name + "` VARCHAR(255)" + " NOT NULL,";
}
return sqlCommand;
}
public static string ToCreateTableSQL(this FieldInfo field)
{
string sqlCommand;
if (field.Name == "ID" || field.Name == "id" || field.Name == "Id")
{
return "";
}
if (field.FieldType == typeof(int) || field.FieldType.IsEnum)
{
sqlCommand = "`" + field.Name + "` INTEGER" + " NOT NULL,";
}
else if (field.FieldType == typeof(double) || field.FieldType == typeof(float))
{
sqlCommand = "`" + field.Name + "` REAL" + " NOT NULL,";
}
else if (field.FieldType == typeof(bool))
{
sqlCommand = "`" + field.Name + "` REAL" + " NOT NULL,";
}
else if (field.FieldType == typeof(long))
{
sqlCommand = "`" + field.Name + "` BIGINT(20)" + " NOT NULL,";
}
else if (field.FieldType == typeof(string))
{
sqlCommand = "`" + field.Name + "` VARCHAR(255)" + " NOT NULL,";
}
else
{
sqlCommand = "`" + field.Name + "` VARCHAR(255)" + " NOT NULL,";
}
return sqlCommand;
}
public static string ToCreateTableSQL(this KeyValuePair<string, Type> param)
{
string sqlCommand;
if (param.Key == "ID" || param.Key == "id" || param.Key == "Id")
{
return "";
}
if (param.Value == typeof(int) || param.Value.IsEnum)
{
sqlCommand = "`" + param.Key + "` INTEGER" + " NOT NULL,";
}
else if (param.Value == typeof(double) || param.Value == typeof(float))
{
sqlCommand = "`" + param.Key + "` REAL" + " NOT NULL,";
}
else if (param.Value == typeof(bool))
{
sqlCommand = "`" + param.Key + "` REAL" + " NOT NULL,";
}
else if (param.Value == typeof(long))
{
sqlCommand = "`" + param.Key + "` BIGINT(20)" + " NOT NULL,";
}
else if (param.Value == typeof(string))
{
sqlCommand = "`" + param.Key + "` VARCHAR(255)" + " NOT NULL,";
}
else
{
sqlCommand = "`" + param.Key + "` VARCHAR(255)" + " NOT NULL,";
}
return sqlCommand;
}
public static string ToCreateTableSQL(this Type type, string tableName)
{
var properties = type.GetProperties();
FieldInfo[] fields = type.GetFields();
string keySet = "";
foreach (PropertyInfo key in properties)
{
keySet += key.ToCreateTableSQL();
}
foreach (FieldInfo key in fields)
{
keySet += key.ToCreateTableSQL();
}
keySet = keySet.TrimEnd(',');
string createSql = @"CREATE TABLE " + tableName + " (" +
"`ID` INTEGER PRIMARY KEY AUTOINCREMENT, " + keySet
+ ");";
return createSql;
}
public static string ToCreateTableSQL(this Dictionary<string,Type> tableParam,string tableName)
{
string keySet = "";
foreach(KeyValuePair<string,Type> key in tableParam){
keySet += key.ToCreateTableSQL();
}
keySet = keySet.TrimEnd(',');
string createSql = @"CREATE TABLE "+tableName+" ("+
"`ID` INTEGER PRIMARY KEY AUTOINCREMENT, "+keySet
+");";
return createSql;
}
}
}

16
addons/EGFramework/Module/GenerateTools/EGGenerate.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
namespace EGFramework
{
public class EGGenerate : EGModule
{
public override void Init()
{
}
public T GenerateUI<T>(object data) where T : new()
{
T ui = new T();
return ui;
}
}
}

34
addons/EGFramework/Module/GenerateTools/GenerateToolsInterface.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
namespace EGFramework
{
public interface IGenerateToolsInterface
{
public string GenerateCode<T>();
}
public interface IGodotTable
{
}
public interface IGodotRowData
{
}
public interface ITableData
{
/// <summary>
/// Get the data of the table.
/// </summary>
/// <returns></returns>
string[][] GetTableData();
/// <summary>
/// Get the header of the table.
/// </summary>
/// <returns></returns>
string[] GetTableHeader();
}
public interface ITableRowData
{
string[] GetRowData();
}
}

90
addons/EGFramework/Module/GenerateTools/Templete/Code/EGSvgGenerator.cs

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
namespace EGFramework.Code{
public class EGSvgGenerator : IGenerateToolsInterface
{
public string SvgHeader { get ; private set;}
public const string SvgFooter = "</svg>";
public int Width { get; set; }
public int Height { get; set; }
public EGSvgViewBox ViewBox { get; set; }
public EGSvgGenerator(int width, int height, EGSvgViewBox viewBox)
{
Width = width;
Height = height;
ViewBox = viewBox;
SvgHeader = $"<svg width=\"{width}\" height=\"{height}\" viewBox=\"{viewBox.X} {viewBox.Y} {viewBox.Width} {viewBox.Height}\" xmlns=\"http://www.w3.org/2000/svg\">";
}
public void DrawCircle(float x, float y, float radius, string color)
{
// Implementation for drawing a circle in SVG format
string svgCircle = $"<circle cx=\"{x}\" cy=\"{y}\" r=\"{radius}\" fill=\"{color}\" />";
}
public void DrawEllipse(float cx, float cy, float rx, float ry, string color)
{
// Implementation for drawing an ellipse in SVG format
string svgEllipse = $"<ellipse cx=\"{cx}\" cy=\"{cy}\" rx=\"{rx}\" ry=\"{ry}\" fill=\"{color}\" />";
}
public void DrawPolygon(float[] points, string color)
{
// Implementation for drawing a polygon in SVG format
string svgPolygon = "<polygon points=\"";
for (int i = 0; i < points.Length; i += 2)
{
svgPolygon += $"{points[i]},{points[i + 1]} ";
}
svgPolygon += $"\" fill=\"{color}\" />";
}
public void DrawPolyline(float[] points, string color)
{
// Implementation for drawing a polyline in SVG format
string svgPolyline = "<polyline points=\"";
for (int i = 0; i < points.Length; i += 2)
{
svgPolyline += $"{points[i]},{points[i + 1]} ";
}
svgPolyline += $"\" stroke=\"{color}\" fill=\"none\" />";
}
public void DrawPath(string d, string color)
{
// Implementation for drawing a path in SVG format
string svgPath = $"<path d=\"{d}\" fill=\"{color}\" />";
}
public void DrawRectangle(float x, float y, float width, float height, string color)
{
// Implementation for drawing a rectangle in SVG format
string svgRectangle = $"<rect x=\"{x}\" y=\"{y}\" width=\"{width}\" height=\"{height}\" fill=\"{color}\" />";
}
public void DrawLine(float x1, float y1, float x2, float y2, string color)
{
// Implementation for drawing a line in SVG format
string svgLine = $"<line x1=\"{x1}\" y1=\"{y1}\" x2=\"{x2}\" y2=\"{y2}\" stroke=\"{color}\" />";
}
public void DrawText(float x, float y, string text, string color)
{
// Implementation for drawing text in SVG format
string svgText = $"<text x=\"{x}\" y=\"{y}\" fill=\"{color}\">{text}</text>";
}
public string GenerateCode<T>()
{
return typeof(T).Name;
}
}
public struct EGSvgViewBox {
public float X { get; set; }
public float Y { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public EGSvgViewBox(float x, float y, float width, float height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}
}

11
addons/EGFramework/Module/GenerateTools/Templete/Code/EGSvgTempletes.cs

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
namespace EGFramework
{
public static class EGSVG16PX
{
public const string Circle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg width=\"48\" height=\"48\" viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"24\" cy=\"24\" r=\"20\" fill=\"none\" stroke=\"#ffffff\" stroke-width=\"3\"/></svg>";
public const string Rect = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg width=\"48\" height=\"48\" viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M39 6H9C7.34315 6 6 7.34315 6 9V39C6 40.6569 7.34315 42 9 42H39C40.6569 42 42 40.6569 42 39V9C42 7.34315 40.6569 6 39 6Z\" fill=\"none\" stroke=\"#ffffff\" stroke-width=\"3\"/></svg>";
public const string Heart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg width=\"48\" height=\"48\" viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M15 8C8.92487 8 4 12.9249 4 19C4 30 17 40 24 42.3262C31 40 44 30 44 19C44 12.9249 39.0751 8 33 8C29.2797 8 25.9907 9.8469 24 12.6738C22.0093 9.8469 18.7203 8 15 8Z\" fill=\"none\" stroke=\"#ffffff\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"miter\"/></svg>";
public const string Star = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg width=\"48\" height=\"48\" viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.9986 5L17.8856 17.4776L4 19.4911L14.0589 29.3251L11.6544 43L23.9986 36.4192L36.3454 43L33.9586 29.3251L44 19.4911L30.1913 17.4776L23.9986 5Z\" fill=\"none\" stroke=\"#ffffff\" stroke-width=\"3\" stroke-linejoin=\"miter\"/></svg>";
}
}

46
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
using System;
using Godot;
namespace EGFramework.UI
{
public static class EGodotBasicDialogExtension
{
public static void EGAlert(this Node self, string alertMsg, string title = "Alert")
{
AcceptDialog acceptDialog = self.PopupNode<AcceptDialog>("AlertDialog");
acceptDialog.Title = title;
acceptDialog.DialogText = alertMsg;
}
public static void EGConfirm(this Node self, string alertMsg, Action<bool> callback, string title = "Confirm")
{
EGodotConfirmationDialog confirmDialog = self.PopupNode<EGodotConfirmationDialog>("ConfirmDialog");
confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg;
confirmDialog.Init(callback);
}
public static void EGFileOpen(this Node self, string filePath, Action<string> selectPath, string title = "Open a file")
{
EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title;
fileDialog.RootSubfolder = filePath;
fileDialog.InitFileSelect(selectPath);
}
public static void EGFileSave(this Node self, string filePath, Action<string> selectPath, string title = "Save a file")
{
EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title;
fileDialog.CurrentFile = filePath;
fileDialog.InitSaveFileSelect(selectPath);
}
public static void EGDocumentOpen(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{
EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title;
fileDialog.RootSubfolder = filePath;
fileDialog.InitDirSelect(selectPath);
}
}
}

20
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotConfirmationDialog.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
using System;
using Godot;
namespace EGFramework.UI {
public partial class EGodotConfirmationDialog : ConfirmationDialog, IEGFramework
{
private EasyEventOnce<bool> OnConfirm { set; get; } = new EasyEventOnce<bool>();
private bool IsInit { set; get; } = false;
public void Init(Action<bool> callback)
{
OnConfirm.Register(callback);
if (!IsInit)
{
this.Confirmed += () => OnConfirm.Invoke(true);
this.Canceled += () => OnConfirm.Invoke(false);
IsInit = true;
}
}
}
}

104
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs

@ -0,0 +1,104 @@ @@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public partial class EGodotEditDialog : ConfirmationDialog, IEGFramework
{
public VBoxContainer EditList { get; set; }
public List<HBoxContainer> EditListItem { get; set; }
public Label ErrorTips { get; set; }
public EasyEvent<Dictionary<string, object>> OnEdit { set; get; } = new EasyEvent<Dictionary<string, object>>();
private Dictionary<string, object> EditCache { set; get; } = new Dictionary<string, object>();
private IUnRegister OnDataEdit { set; get; }
public List<EGodotEditParam> ParamUIs { set; get; } = new List<EGodotEditParam>();
private bool IsInit { set; get; } = false;
const int DefaultWidth = 640;
const int DefaultHeight = 320;
public void InitDialog(Dictionary<string, object> data, Action<Dictionary<string, object>> onDataEdit, string title = "Edit Data", int width = DefaultWidth, int height = DefaultHeight)
{
if (!IsInit)
{
EditList = new VBoxContainer();
EditList.Name = "EditList";
EditList.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(EditList);
this.Connect("confirmed", Callable.From(OnConfirm));
this.Size = new Vector2I(width, height);
IsInit = true;
}
this.EditList.ClearChildren();
ParamUIs.Clear();
this.Title = title;
OnDataEdit = OnEdit.Register(onDataEdit);
this.ErrorTips = new Label();
ErrorTips.Name = "ErrorTips";
ErrorTips.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
EditList.AddChild(ErrorTips);
ErrorTips.Visible = false;
foreach (KeyValuePair<string, object> param in data)
{
EGodotEditParam paramUI = new EGodotEditParam();
this.EditList.AddChild(paramUI);
paramUI.Init(param);
ParamUIs.Add(paramUI);
}
this.PopupCentered();
}
public void OnConfirm()
{
EditCache.Clear();
foreach (EGodotEditParam paramUI in ParamUIs)
{
EditCache.Add(paramUI.GetKey(), paramUI.GetValue());
}
try
{
OnEdit.Invoke(EditCache);
OnDataEdit.UnRegister();
this.Visible = false;
}
catch (NullReferenceException)
{
this.OnErrorTips("某项数据不能为空!");
}
catch (FormatException)
{
this.OnErrorTips("某项数据格式不准确!");
}
catch (Exception e)
{
this.OnErrorTips(e.ToString());
throw;
}
}
public void OnErrorTips(string tips)
{
ErrorTips.Visible = true;
ErrorTips.Text = tips;
}
public void OnCancel()
{
OnDataEdit.UnRegister();
this.Visible = false;
}
}
public static class EGodotEditDialogExtension
{
public static EGodotEditDialog EGEditDialog(this Node self, Dictionary<string, object> data, Action<Dictionary<string, object>> onDataEdit, string title = "Edit")
{
EGodotEditDialog editDialog = self.PopupNode<EGodotEditDialog>("Edit");
editDialog.InitDialog(data, onDataEdit, title);
// editDialog.PopupCentered();
return editDialog;
}
}
}

66
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
using System;
using Godot;
namespace EGFramework.UI
{
public partial class EGodotFileDialog : FileDialog, IEGFramework
{
private EasyEventOnce<string> OnFileSelect { set; get; } = new EasyEventOnce<string>();
private EasyEventOnce<string> OnDirSelect { set; get; } = new EasyEventOnce<string>();
private EasyEventOnce<string[]> OnFilesSelect { set; get; } = new EasyEventOnce<string[]>();
private bool IsInit { set; get; } = false;
public void Init()
{
if (!IsInit)
{
this.FileSelected += OnFileSelect.Invoke;
this.DirSelected += OnDirSelect.Invoke;
this.FilesSelected += OnFilesSelect.Invoke;
this.Size = new Vector2I(480, 320);
this.Access = AccessEnum.Filesystem;
IsInit = true;
}
}
public void InitFileSelect(Action<string> callback)
{
OnFileSelect.Register(callback);
Init();
this.FileMode = FileModeEnum.OpenFile;
}
public void InitDirSelect(Action<string> callback)
{
OnDirSelect.Register(callback);
this.FileMode = FileModeEnum.OpenDir;
Init();
}
public void InitFilesSelect(Action<string[]> callback)
{
OnFilesSelect.Register(callback);
this.FileMode = FileModeEnum.OpenFiles;
Init();
}
public void InitAnySelect(Action<string> singleSelectCallback, Action<string[]> multiSelectCallback)
{
OnFileSelect.Register(singleSelectCallback);
OnDirSelect.Register(singleSelectCallback);
OnFilesSelect.Register(multiSelectCallback);
this.FileMode = FileModeEnum.OpenAny;
Init();
}
public void InitSaveFileSelect(Action<string> callback)
{
OnFileSelect.Register(callback);
this.FileMode = FileModeEnum.SaveFile;
Init();
}
}
}

120
addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs

@ -0,0 +1,120 @@ @@ -0,0 +1,120 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using Godot;
using Mysqlx.Crud;
using static Godot.GD;
namespace EGFramework{
public class EGSingletonNode : IEGFramework, IModule
{
public IOCContainer NodeContainer = new IOCContainer();
public Stack<Window> WindowCache = new Stack<Window>();
public Window CurrentWindow { set; get; }
private bool PopUpFlag { set; get; }
public void Init()
{
}
public void PopupNode(Window window)
{
PopUpFlag = true;
if (CurrentWindow != null)
{
this.CurrentWindow.Hide();
CurrentWindow.VisibilityChanged -= OnPopUpUnitVisibleChanged;
WindowCache.Push(CurrentWindow);
}
window.PopupCentered();
this.CurrentWindow = window;
CurrentWindow.VisibilityChanged += OnPopUpUnitVisibleChanged;
PopUpFlag = false;
}
public void OnPopUpUnitVisibleChanged()
{
if (CurrentWindow != null && !CurrentWindow.Visible && !PopUpFlag)
{
CurrentWindow.VisibilityChanged -= OnPopUpUnitVisibleChanged;
if (this.WindowCache.Count > 0)
{
Window lastWindow = WindowCache.Pop();
CurrentWindow = lastWindow;
Callable.From(() => CurrentWindow.PopupCentered()).CallDeferred();
CurrentWindow.VisibilityChanged += OnPopUpUnitVisibleChanged;
}
else
{
CurrentWindow = null;
}
}
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGCanCreateNodeExtension
{
public static TNode CreateNode<TNode>(this Node self) where TNode : Node, new()
{
TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode CreateNode<TNode>(this Node self, string name) where TNode : Node, new()
{
TNode nodeData = new TNode();
nodeData.Name = name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode SingletoneNode<TNode>(this Node self, string name) where TNode : Node, new()
{
TNode nodeData;
if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null)
{
nodeData = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>();
}
else
{
nodeData = self.GetTree().Root.CreateNode<TNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData);
}
nodeData.Name = name;
return nodeData;
}
public static TWindowNode PopupNode<TWindowNode>(this Node self, string name) where TWindowNode : Window, new()
{
TWindowNode nodeData;
EGSingletonNode singletonNode = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>();
if (singletonNode.NodeContainer.Get<TWindowNode>() != null)
{
nodeData = singletonNode.NodeContainer.Get<TWindowNode>();
}
else
{
nodeData = self.GetTree().Root.CreateNode<TWindowNode>();
singletonNode.NodeContainer.Register(nodeData);
}
singletonNode.PopupNode(nodeData);
nodeData.Name = name;
return nodeData;
}
}
}

7
addons/EGFramework/Module/GenerateTools/Templete/Godot/Interface/EGGodotData.cs

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
namespace EGFramework.UI
{
public interface IEGodotData
{
public void RefreshData();
}
}

197
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs

@ -0,0 +1,197 @@ @@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public partial class EGodotEditParam : EGodotParam, IEGFramework
{
public LineEdit ParamEdit { get; set; }
public OptionButton ParamOption { get; set; }
public CheckButton ParamCheck { get; set; }
public List<CheckBox> ParamCheckList { get; set; }
public Label ParamReadOnly { get; set; }
public Label ParamPathSelect { get; set; }
public SpinBox ParamSpinBox { get; set; }
public HSlider ParamSlider { get; set; }
public Button ParamOperate { get; set; }
private Type ValueType { set; get; }
public override void Init(KeyValuePair<string, object> editValue)
{
base.Init(editValue);
if (editValue.Key == "id" || editValue.Key == "ID" || editValue.Key == "Id")
{
this.ParamReadOnly = new Label();
ParamReadOnly.Name = "ParamReadOnly";
ParamReadOnly.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamReadOnly.Text = editValue.Value.ToString();
this.AddChild(ParamReadOnly);
return;
}
if (editValue.Value is string || editValue.Value is null)
{
this.ParamEdit = new LineEdit();
ParamEdit.Name = "ParamEdit";
ParamEdit.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamEdit.PlaceholderText = "Please input " + editValue.Key;
this.AddChild(ParamEdit);
ParamEdit.Text = (string)editValue.Value;
}
else if (editValue.Value is bool)
{
this.ParamCheck = new CheckButton();
ParamCheck.Name = "ParamCheck";
ParamCheck.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamCheck.Text = "";
ParamCheck.ButtonPressed = (bool)editValue.Value;
this.AddChild(ParamCheck);
}
else if (editValue.Value is IEGReadOnlyString)
{
this.ParamReadOnly = new Label();
ParamReadOnly.Name = "ParamReadOnly";
ParamReadOnly.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamReadOnly.Text = ((IEGReadOnlyString)editValue.Value).GetString();
this.AddChild(ParamReadOnly);
}
else if (editValue.Value is EGSelectParam)
{
this.ParamOption = new OptionButton();
ParamOption.Name = "ParamOption";
ParamOption.SizeFlagsHorizontal = SizeFlags.ExpandFill;
this.AddChild(ParamOption);
foreach (KeyValuePair<int, string> selectOptions in ((EGSelectParam)editValue.Value).SelectList)
{
this.ParamOption.AddItem(selectOptions.Value, selectOptions.Key);
}
this.ParamOption.Selected = this.ParamOption.GetItemIndex(((EGSelectParam)editValue.Value).SelectID);
}
else if (editValue.Value is int)
{
this.ParamSpinBox = new SpinBox();
ParamSpinBox.Name = "ParamSpinBox";
ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamSpinBox.MaxValue = int.MaxValue;
ParamSpinBox.MinValue = int.MinValue;
ParamSpinBox.Value = (int)editValue.Value;
this.AddChild(ParamSpinBox);
ValueType = typeof(int);
}
else if (editValue.Value is float)
{
this.ParamSpinBox = new SpinBox();
ParamSpinBox.Name = "ParamSpinBox";
ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamSpinBox.MaxValue = float.MaxValue;
ParamSpinBox.MinValue = float.MinValue;
ParamSpinBox.Value = (float)editValue.Value;
ParamSpinBox.Step = 0.01f;
this.AddChild(ParamSpinBox);
ValueType = typeof(float);
}
else if (editValue.Value is double)
{
this.ParamSpinBox = new SpinBox();
ParamSpinBox.Name = "ParamSpinBox";
ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamSpinBox.MaxValue = double.MaxValue;
ParamSpinBox.MinValue = double.MinValue;
ParamSpinBox.Value = (double)editValue.Value;
ParamSpinBox.Step = 0.0001f;
this.AddChild(ParamSpinBox);
ValueType = typeof(double);
}
else if (editValue.Value is EGRangeParam)
{
this.ParamSlider = new HSlider();
ParamSlider.Name = "ParamSlider";
ParamSlider.SizeFlagsHorizontal = SizeFlags.ExpandFill;
EGRangeParam rangeParam = (EGRangeParam)editValue.Value;
ParamSlider.MinValue = rangeParam.Min;
ParamSlider.MaxValue = rangeParam.Max;
ParamSlider.Step = rangeParam.Step;
ParamSlider.Value = rangeParam.Value;
this.AddChild(ParamSlider);
}
else if (editValue.Value is EGPathSelect)
{
EGPathSelect pathSelect = (EGPathSelect)editValue.Value;
this.ParamPathSelect = new Label();
ParamPathSelect.Name = "ParamReadOnly";
ParamPathSelect.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamPathSelect.Text = pathSelect.Path;
this.AddChild(ParamPathSelect);
this.ParamOperate = new Button();
ParamOperate.Name = "SelectBtn";
ParamOperate.Text = "Select file";
ParamOperate.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamOperate.Pressed += () =>
{
this.EGFileOpen("res://", str =>
{
ParamPathSelect.Text = str;
});
};
// ParamOperate.Pressed +=
this.AddChild(ParamOperate);
}
}
public string GetKey()
{
return ParamValue.Key;
}
public object GetValue()
{
if (ParamEdit != null)
{
return ParamEdit.Text;
}
else if (ParamCheck != null)
{
return ParamCheck.ButtonPressed;
}
else if (ParamOption != null)
{
return ParamOption.Selected;
}
else if (ParamReadOnly != null)
{
return ParamReadOnly.Text;
}
else if (ParamSpinBox != null)
{
if (ValueType == typeof(int))
{
return (int)ParamSpinBox.Value;
}
else if (ValueType == typeof(float))
{
return (float)ParamSpinBox.Value;
}
return ParamSpinBox.Value;
}
else if (ParamSlider != null)
{
return ParamSlider.Value;
}
else if (ParamPathSelect != null)
{
return new EGPathSelect(){Path = ParamPathSelect.Text};
}
return null;
}
public override KeyValuePair<string, object> GetData()
{
return new KeyValuePair<string, object>(GetKey(), GetValue());
}
public override void RefreshData(KeyValuePair<string, object> data)
{
//this param cannot be Refreshed,please remove and recreate a new EGodotEditParam.
}
}
}

29
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotMenu.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public partial class EGodotMenu : Control, IEGFramework
{
public Dictionary<string, Control> PageContainer { set; get; } = new Dictionary<string, Control>();
public void RegisterPage<T>(string name,T page) where T : Control
{
if (PageContainer.ContainsKey(name))
{
PageContainer[name] = page;
}
else
{
PageContainer.Add(name,page);
}
}
public void OpenPage<T>(string name,T page) where T : Control
{
page.Visible = true;
}
}
}

34
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public interface IEGodotParam : IEGodotData
{
public void Init(KeyValuePair<string, object> data);
public void RefreshData(KeyValuePair<string, object> data);
public KeyValuePair<string, object> GetData();
}
public abstract partial class EGodotParam : BoxContainer, IEGFramework, IEGodotParam
{
public Label ParamName { get; set; }
public KeyValuePair<string, object> ParamValue { get; set; }
public virtual void Init(KeyValuePair<string, object> paramValue)
{
ParamValue = paramValue;
this.ParamName = new Label();
ParamName.Name = "ParamName";
ParamName.Text = ParamValue.Key;
ParamName.SizeFlagsHorizontal = SizeFlags.ExpandFill;
this.AddChild(ParamName);
}
public void RefreshData()
{
this.RefreshData(this.ParamValue);
}
public abstract KeyValuePair<string, object> GetData();
public abstract void RefreshData(KeyValuePair<string, object> data);
}
}

105
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotRowData.cs

@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
using Godot;
using System;
using System.Collections.Generic;
namespace EGFramework.UI
{
public interface IEGodotRowData:IEGodotData
{
public void Init(Dictionary<string, object> data);
public void RefreshData(Dictionary<string, object> data);
public Dictionary<string, object> GetData();
}
public partial class EGodotRowData : PanelContainer, IEGFramework, IEGodotRowData
{
public Button ItemHover { get; set; }
public ColorRect Line { get; set; }
public ColorRect BackGround { get; set; }
public HBoxContainer List { get; set; }
protected Dictionary<string, object> Data { get; set; }
protected bool IsInit { set; get; } = false;
public Dictionary<string, object> GetData()
{
return this.Data;
}
public virtual void Init(Dictionary<string, object> data)
{
if (IsInit)
{
this.Data = data;
this.RefreshData(data);
return;
}
this.Data = data;
BackGround = new ColorRect();
BackGround.Name = "BackGround";
BackGround.Color = new Color(0f, 0f, 0f, 0f);
BackGround.SizeFlagsHorizontal = SizeFlags.ExpandFill;
BackGround.SizeFlagsVertical = SizeFlags.ExpandFill;
this.AddChild(BackGround);
List = new HBoxContainer();
List.Name = "TableRow_" + Resource.GenerateSceneUniqueId();
List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(List);
Line = new ColorRect();
Line.Name = "Line";
Line.Color = new Color(0f, 0f, 0f, 0f);
Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd;
Line.CustomMinimumSize = new Vector2(0, 1);
this.AddChild(Line);
foreach (KeyValuePair<string, object> kv in data)
{
this.List.AddChild(new Label()
{
Name = kv.Key,
Text = kv.Value?.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
this.AddThemeStyleboxOverride("panel", new StyleBoxEmpty());
IsInit = true;
}
public virtual void RefreshData(Dictionary<string, object> data)
{
this.List.ClearChildren<Label>();
foreach (KeyValuePair<string, object> kv in data)
{
this.List.AddChild(new Label()
{
Name = kv.Key,
Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
}
public void RefreshData()
{
this.RefreshData(this.Data);
}
public void SetBackgroundColor(Color color)
{
if (this.BackGround != null)
{
this.BackGround.Color = color;
}
}
public void SetLineColor(Color color)
{
if (this.Line != null)
{
this.Line.Color = color;
}
}
}
}

156
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs

@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
using System.Collections.Generic;
using System.Linq;
namespace EGFramework.UI
{
public partial class EGodotSaveTable : EGodotTable, IEGFramework
{
public IEGSaveData SaveData { set; get; }
public Dictionary<string, string> TitleList { set; get; } = new Dictionary<string, string>();
public string CurrentDataKey { set; get; }
public EasyEvent QueryPage { set; get; } = new EasyEvent();
public EasyEvent SearchKey { set; get; } = new EasyEvent();
public void InitSaveData<TSaveData>(IEGSaveData eGSaveData) where TSaveData : IEGSaveData
{
this.SaveData = eGSaveData;
}
public void InitData<T>(string key) where T : new()
{
int count = SaveData.GetDataCount(key);
if (PageAdapter == null)
{
PageAdapter = new EGodotTablePageAdapter(count, PageLimit);
}
else
{
PageAdapter.Reload(count, PageLimit);
}
this.Vertical = true;
CurrentDataKey = key;
EmptyData = typeof(T).EGenerateEmptyDictiontaryByType();
QueryPage.Register(() => QueryPageData<T>());
SearchKey.Register(() => SearchDataByKeyword<T>());
TableName = typeof(T).Name;
TitleData = typeof(T).EGenerateDictiontaryByType();
InitFunctionMenu();
InitTitle(TitleData);
InitRowData(null);
InitPageMenu();
}
public void QueryPageData<T>() where T : new()
{
if (PageAdapter.CurrentPage <= 1)
{
PageAdapter.CurrentPage = 1;
}
TableData = SaveData.GetPage<T>(CurrentDataKey, PageAdapter.CurrentPage, PageAdapter.PageLimit).EGenerateDictionaryByGroup();
}
public void SearchDataByKeyword<T>() where T : new()
{
string fieldName = FieldSelect.Text;
string keyWords = SearchEdit.Text;
TableData = SaveData.FindData<T>(CurrentDataKey, fieldName, keyWords).EGenerateDictionaryByGroup();
}
public override void OnAddData(Dictionary<string, object> data)
{
// base.OnAddData(data);
SaveData.AddData(CurrentDataKey, data);
}
public void ModifyData(Dictionary<string, object> eData)
{
string primaryKey = "";
if (eData.ContainsKey("ID")) primaryKey = "ID";
if (eData.ContainsKey("id")) primaryKey = "id";
if (eData.ContainsKey("Id")) primaryKey = "Id";
if (primaryKey == "")
{
this.EGAlert("Parmary key 'id' not defined!", "Error");
return;
}
SaveData.UpdateData(CurrentDataKey, eData, eData[primaryKey]);
InitPageData();
}
public override void InitPageData()
{
RowDataContainer.ClearChildren();
QueryPage.Invoke();
int pointer = 0;
foreach (Dictionary<string, object> data in TableData)
{
EGodotTableRowData rowData = RowDataContainer.CreateNode<EGodotTableRowData>("row" + pointer);
rowData.Init(data);
rowData.OnModify.Register(eData =>
{
this.EGEditDialog(eData, ModifyData, "Modify");
});
rowData.OnDelete.Register(() =>
{
string primaryKey = "";
if (rowData.GetData().ContainsKey("ID")) primaryKey = "ID";
if (rowData.GetData().ContainsKey("id")) primaryKey = "id";
if (rowData.GetData().ContainsKey("Id")) primaryKey = "Id";
if (primaryKey == "")
{
this.EGAlert("Parmary key 'id' not defined!", "Error");
return;
}
int remove_count = SaveData.RemoveData(CurrentDataKey, rowData.GetData()[primaryKey]);
PageAdapter.DataLength -= remove_count;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
});
}
ResetSearch();
//base.InitPageData();
}
public override void ExecuteSearch()
{
RowDataContainer.ClearChildren();
string fieldName = FieldSelect.Text;
string keyWords = SearchEdit.Text;
SearchKey.Invoke();
int dataPointer = 0;
foreach (Dictionary<string, object> data in TableData)
{
EGodotTableRowData rowData = RowDataContainer.CreateNode<EGodotTableRowData>("row" + dataPointer);
dataPointer++;
rowData.Init(data);
rowData.OnModify.Register(eData =>
{
this.EGEditDialog(eData, ModifyData, "Modify");
});
rowData.OnDelete.Register(() =>
{
string primaryKey = "";
if (rowData.GetData().ContainsKey("ID")) primaryKey = "ID";
if (rowData.GetData().ContainsKey("id")) primaryKey = "id";
if (rowData.GetData().ContainsKey("Id")) primaryKey = "Id";
if (primaryKey == "")
{
this.EGAlert("Parmary key 'id' not defined!", "Error");
return;
}
int remove_count = SaveData.RemoveData(CurrentDataKey, rowData.GetData()[primaryKey]);
PageAdapter.DataLength -= remove_count;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
});
}
}
}
}

457
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs

@ -0,0 +1,457 @@ @@ -0,0 +1,457 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using Godot;
namespace EGFramework.UI
{
public interface IEGodotTable
{
}
public partial class EGodotTable : BoxContainer, IEGFramework, IEGodotTable
{
public BoxContainer FunctionContainer { set; get; }
public EGodotRowData Title { set; get; }
public BoxContainer RowDataContainer { set; get; }
public ScrollContainer RowDataScroll { set; get; }
public BoxContainer PageContainer { set; get; }
public Color MainColor { set; get; } = new Color();
public Color MinorColor { set; get; } = new Color();
protected EGodotTablePageAdapter PageAdapter { set; get; }
protected bool IsSearched { set; get; }
protected EasyEvent OnPageChanged { set; get; } = new EasyEvent();
protected IUnRegister PageChangedRealease { set; get; }
protected List<Dictionary<string, object>> TableData { set; get; }
protected Dictionary<string, object> EmptyData { set; get; }
protected Dictionary<string, object> TitleData { set; get; } = new Dictionary<string, object>();
protected EasyEvent<Dictionary<string, object>> AddData { set; get; } = new EasyEvent<Dictionary<string, object>>();
public Vector2 MinimumFunctionButtonSize = new Vector2(120,0);
public string TableName { set; get; } = "-";
/// <summary>
/// The max data count for one page.
/// </summary>
/// <value></value>
[Export]
public int PageLimit { set; get; } = 10;
public void InitData<T>(IEnumerable<T> tableData) where T : new()
{
int count = tableData.Count();
if (PageAdapter == null)
{
PageAdapter = new EGodotTablePageAdapter(count, PageLimit);
}
else
{
PageAdapter.Reload(count, PageLimit);
}
this.Vertical = true;
EmptyData = typeof(T).EGenerateEmptyDictiontaryByType();
TitleData = typeof(T).EGenerateDictiontaryByType();
TableName = typeof(T).Name;
InitFunctionMenu();
InitTitle(TitleData);
InitRowData(tableData.EGenerateDictionaryByGroup());
InitPageMenu();
}
public virtual void OnAddData(Dictionary<string, object> data)
{
GD.Print("Add : " + data["Name"]);
string primaryKey = data.EGetDefaultPrimaryKey();
if (primaryKey != "")
{
data[primaryKey] = TableData.Count.ToString();
}
TableData.Add(new Dictionary<string, object>(data));
PageAdapter.DataLength++;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
}
public virtual void OnOutputFile(string path)
{
GD.Print("File has been Saved at " + path);
EGCsvSave eGCsvSave = new EGCsvSave();
eGCsvSave.InitSave(path);
eGCsvSave.AddGroup("",TableData);
OS.ShellOpen(path);
}
public virtual void OnInputFile(string path)
{
}
protected OptionButton FieldSelect { set; get; }
protected LineEdit SearchEdit { set; get; }
public virtual void InitFunctionMenu()
{
if (FunctionContainer == null)
{
FunctionContainer = this.CreateNode<BoxContainer>("FunctionContainer");
FunctionContainer.Vertical = false;
Button add = FunctionContainer.CreateNode<Button>("add");
add.Text = "Add";
add.Connect("pressed", Callable.From(() => this.EGEditDialog(EmptyData, OnAddData, "Add")));
add.FocusMode = FocusModeEnum.None;
add.CustomMinimumSize = MinimumFunctionButtonSize;
Button refresh = FunctionContainer.CreateNode<Button>("refresh");
refresh.Text = "Refresh";
refresh.Connect("pressed", Callable.From(InitPageData));
refresh.FocusMode = FocusModeEnum.None;
refresh.CustomMinimumSize = MinimumFunctionButtonSize;
Button output = FunctionContainer.CreateNode<Button>("output");
output.Text = "Output";
output.Connect("pressed", Callable.From(() => this.EGFileSave(TableName + ".csv", OnOutputFile)));
output.FocusMode = FocusModeEnum.None;
output.CustomMinimumSize = MinimumFunctionButtonSize;
Button input = FunctionContainer.CreateNode<Button>("input");
input.Text = "Input";
input.FocusMode = FocusModeEnum.None;
input.CustomMinimumSize = MinimumFunctionButtonSize;
FieldSelect = FunctionContainer.CreateNode<OptionButton>("fieldSelect");
FieldSelect.FocusMode = FocusModeEnum.None;
FieldSelect.SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkEnd;
FieldSelect.CustomMinimumSize = MinimumFunctionButtonSize;
foreach (string titleParam in TitleData.Keys)
{
FieldSelect.AddItem(titleParam);
}
SearchEdit = FunctionContainer.CreateNode<LineEdit>("searchEdit");
SearchEdit.PlaceholderText = "Please input search key";
SearchEdit.SizeFlagsHorizontal = SizeFlags.ShrinkEnd;
SearchEdit.CustomMinimumSize = new Vector2(MinimumFunctionButtonSize.X * 2, MinimumFunctionButtonSize.Y);
Button search = FunctionContainer.CreateNode<Button>("search");
search.Text = "Search";
search.FocusMode = FocusModeEnum.None;
search.SizeFlagsHorizontal = SizeFlags.ShrinkEnd;
search.CustomMinimumSize = MinimumFunctionButtonSize;
search.Connect("pressed", Callable.From(Search));
Button reset = FunctionContainer.CreateNode<Button>("reset");
reset.Text = "Reset";
reset.FocusMode = FocusModeEnum.None;
reset.SizeFlagsHorizontal = SizeFlags.ShrinkEnd;
reset.CustomMinimumSize = MinimumFunctionButtonSize;
reset.Connect("pressed", Callable.From(ResetSearch));
}
}
public virtual void InitTitle(Dictionary<string, object> titleData)
{
if (Title == null)
{
Title = this.CreateNode<EGodotRowData>("TitleContainer");
titleData.Add("Operate", "Operate");
Title.Init(titleData);
}
else
{
Title.RefreshData(titleData);
}
}
public void InitRowData(List<Dictionary<string, object>> rowDataList)
{
RowDataScroll = this.CreateNode<ScrollContainer>("Scroll");
RowDataScroll.SizeFlagsVertical = SizeFlags.ExpandFill;
RowDataContainer = RowDataScroll.CreateNode<BoxContainer>("RowData");
RowDataContainer.SizeFlagsHorizontal = SizeFlags.ExpandFill;
RowDataContainer.Vertical = true;
this.TableData = rowDataList;
ToFirstPage();
InitPageData();
}
public virtual void InitPageData()
{
if (PageAdapter.CurrentPage <= 1)
{
PageAdapter.CurrentPage = 1;
}
int dataPointer = (PageAdapter.CurrentPage - 1) * PageAdapter.PageLimit;
int dataEndPointer = dataPointer + PageAdapter.PageLimit;
if (dataEndPointer >= PageAdapter.DataLength)
{
dataEndPointer = PageAdapter.DataLength;
}
RowDataContainer.ClearChildren();
for (int dataId = dataPointer; dataId < dataEndPointer; dataId++)
{
EGodotTableRowData rowData = RowDataContainer.CreateNode<EGodotTableRowData>("row" + dataPointer);
rowData.Init(TableData[dataId]);
rowData.OnModify.Register(data =>
{
this.EGEditDialog(data, rowData.OnDataEdit, "Modify");
});
rowData.OnDelete.Register(() =>
{
GD.Print("Delete : " + rowData.GetData()["Name"]);
this.TableData.Remove(rowData.GetData());
PageAdapter.DataLength--;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
});
}
ResetSearch();
}
public void InitPageMenu()
{
if (PageContainer == null)
{
PageContainer = this.CreateNode<BoxContainer>("PageContainer");
PageContainer.Vertical = false;
PageContainer.Alignment = AlignmentMode.End;
Label labelCount = PageContainer.CreateNode<Label>("to");
labelCount.Text = "Data count : " + PageAdapter.DataLength;
Control empty1 = PageContainer.CreateNode<Control>("empty1");
empty1.CustomMinimumSize = new Vector2(32, 0);
Button firstPage = PageContainer.CreateNode<Button>("firstPage");
firstPage.Text = "<<";
firstPage.Connect("pressed", Callable.From(ToFirstPage));
firstPage.FocusMode = FocusModeEnum.None;
Button lastPage = PageContainer.CreateNode<Button>("lastPage");
lastPage.Text = "<";
lastPage.Connect("pressed", Callable.From(LastPage));
lastPage.FocusMode = FocusModeEnum.None;
Label currentPage = PageContainer.CreateNode<Label>("currenLabel");
currentPage.Text = PageAdapter.CurrentPage.ToString();
Button nextPage = PageContainer.CreateNode<Button>("next");
nextPage.Text = ">";
nextPage.Connect("pressed", Callable.From(NextPage));
nextPage.FocusMode = FocusModeEnum.None;
Button endPage = PageContainer.CreateNode<Button>("firstPage");
endPage.Text = ">>";
endPage.Connect("pressed", Callable.From(ToEndPage));
endPage.FocusMode = FocusModeEnum.None;
Control empty2 = PageContainer.CreateNode<Control>("empty2");
empty2.CustomMinimumSize = new Vector2(32, 0);
Label labelTo = PageContainer.CreateNode<Label>("to");
labelTo.Text = "To";
SpinBox inputPage = PageContainer.CreateNode<SpinBox>("pageEdit");
inputPage.SetSize(new Vector2(120, 60));
inputPage.MinValue = 1;
inputPage.MaxValue = PageAdapter.MaxPage;
inputPage.Alignment = HorizontalAlignment.Center;
inputPage.Connect("value_changed", Callable.From<int>(ToPage));
Label labelPage = PageContainer.CreateNode<Label>("page");
labelPage.Text = "page";
firstPage.Disabled = true;
lastPage.Disabled = true;
PageChangedRealease = this.OnPageChanged.Register(() =>
{
labelCount.Text = "Data count : " + PageAdapter.DataLength + " Page : " + PageAdapter.CurrentPage;
currentPage.Text = PageAdapter.CurrentPage.ToString();
if (PageAdapter.IsFirstPage())
{
firstPage.Disabled = true;
lastPage.Disabled = true;
}
else
{
firstPage.Disabled = false;
lastPage.Disabled = false;
}
if (PageAdapter.IsLastPage())
{
endPage.Disabled = true;
nextPage.Disabled = true;
}
else
{
endPage.Disabled = false;
nextPage.Disabled = false;
}
InitPageData();
});
}
}
public void ToFirstPage()
{
this.PageAdapter.CurrentPage = 1;
OnPageChanged.Invoke();
}
public void ToEndPage()
{
this.PageAdapter.CurrentPage = this.PageAdapter.MaxPage;
OnPageChanged.Invoke();
}
public void LastPage()
{
if (this.PageAdapter.CurrentPage > 1)
{
this.PageAdapter.CurrentPage--;
OnPageChanged.Invoke();
}
}
public void NextPage()
{
if (this.PageAdapter.CurrentPage < this.PageAdapter.MaxPage)
{
this.PageAdapter.CurrentPage++;
OnPageChanged.Invoke();
}
}
public void ToPage(int pageId)
{
if (pageId >= 1 && pageId <= this.PageAdapter.MaxPage)
{
this.PageAdapter.CurrentPage = pageId;
OnPageChanged.Invoke();
}
}
public void Search()
{
if (SearchEdit.Text == "" && FieldSelect.Text == "")
{
this.EGAlert("Please input key word in search edit and select a field.", "Message not enough!");
}
else
{
IsSearched = true;
PageContainer.Visible = false;
ExecuteSearch();
}
}
public void ResetSearch()
{
if (IsSearched)
{
IsSearched = false;
PageContainer.Visible = true;
InitPageData();
}
}
public virtual void ExecuteSearch()
{
RowDataContainer.ClearChildren();
string fieldName = FieldSelect.Text;
string keyWords = SearchEdit.Text;
List<Dictionary<string, object>> SearchData = TableData.ESearchByKeyword(fieldName, keyWords);
int dataPointer = 0;
foreach (Dictionary<string, object> searchrow in SearchData)
{
EGodotTableRowData rowData = RowDataContainer.CreateNode<EGodotTableRowData>("row" + dataPointer);
dataPointer++;
rowData.Init(searchrow);
rowData.OnModify.Register(data =>
{
this.EGEditDialog(data, rowData.OnDataEdit, "Modify");
});
rowData.OnDelete.Register(() =>
{
GD.Print("Delete : " + rowData.GetData()["Name"]);
this.TableData.Remove(rowData.GetData());
PageAdapter.DataLength--;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
});
}
}
public override void _ExitTree()
{
this.PageChangedRealease.UnRegister();
base._ExitTree();
}
}
public static class EGGodotTableGenerator
{
// public static EGodotTable CreateTable(this Node self, string[][] tableStr, string tableName = "Table")
// {
// VBoxContainer Table = new VBoxContainer();
// Table.Name = tableName;
// int dataPointer = 0;
// foreach (string[] s in tableStr)
// {
// Table.CreateRowData(s, "tableRowData" + dataPointer);
// dataPointer++;
// }
// self.AddChild(Table);
// return Table;
// }
}
public class EGodotTablePageAdapter
{
public int DataLength { set; get; }
public int CurrentPage { set; get; }
public int MaxPage { set; get; }
public int PageLimit { set; get; }
public EasyEvent OnLoad = new EasyEvent();
public EGodotTablePageAdapter(int dataLength, int pageLimit = 10)
{
this.DataLength = dataLength;
this.PageLimit = pageLimit;
this.MaxPage = dataLength / PageLimit + 1;
if (dataLength % pageLimit == 0)
{
this.MaxPage -= 1;
}
this.CurrentPage = 1;
}
public void Reload(int dataLength, int pageLimit = 10)
{
this.DataLength = dataLength;
this.PageLimit = pageLimit;
this.MaxPage = dataLength / PageLimit + 1;
this.CurrentPage = 1;
OnLoad.Invoke();
}
public bool IsFirstPage()
{
return this.CurrentPage == 1;
}
public bool IsLastPage()
{
return this.CurrentPage == MaxPage;
}
}
}

79
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using Godot;
using Tmds.Linux;
namespace EGFramework.UI{
public partial class EGodotTableRowData : EGodotRowData
{
public Control Operate { get; set; }
public Button Modify { get; set; }
public Button Delete { get; set; }
public EasyEvent<Dictionary<string, object>> OnModify { set; get; } = new EasyEvent<Dictionary<string, object>>();
public EasyEvent OnDelete { set; get; } = new EasyEvent();
public override void Init(Dictionary<string, object> data)
{
base.Init(data);
Operate = new HBoxContainer();
Operate.Name = "Operate";
Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
List.AddChild(Operate);
Modify = new Button();
Modify.Name = "Modify";
Modify.Text = "Modify";
Modify.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Modify);
Delete = new Button();
Delete.Name = "Delete";
Delete.Text = "Delete";
Delete.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Delete);
Modify.Connect("pressed", Callable.From(OnEdit));
Delete.Connect("pressed", Callable.From(OnDeleteSelf));
this.CustomMinimumSize = new Vector2(0, 32);
}
public void OnEdit()
{
if (Data == null)
{
return;
}
OnModify.Invoke(Data);
}
public virtual void OnDataEdit(Dictionary<string, object> e)
{
foreach (var pair in e)
{
this.Data[pair.Key] = pair.Value;
}
// this.Data = e;
this.RefreshData();
}
public override void RefreshData(Dictionary<string, object> data)
{
base.RefreshData(data);
Operate.ToEnd();
}
public void OnDeleteSelf()
{
this.EGConfirm("Delete this data? this operate cannot be canceled.", e =>
{
if (e)
{
OnDelete.Invoke();
}
}, "Delete");
}
public override void _ExitTree()
{
Modify.Disconnect("pressed", Callable.From(OnEdit));
Delete.Disconnect("pressed", Callable.From(OnDeleteSelf));
base._ExitTree();
}
}
}

46
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTree.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public interface IEGodotTree
{
void RenderTree();
}
public partial class EGodotTree : Tree, IEGFramework, IEGodotTree
{
public EGTree Tree { set; get; }
public void Init(EGTree tree)
{
this.Tree = tree;
RenderTree();
}
public void InitByJson(string json)
{
EGTree eGTree = EGTreeFactory.CreateTreeByJson(json);
this.Tree = eGTree;
RenderTree();
}
public void RenderTree()
{
this.HideRoot = true;
CreateTreeItem(Tree, this.GetRoot());
}
public void CreateTreeItem(EGTree tree,TreeItem parent)
{
TreeItem current = this.CreateItem(parent);
current.SetText(0,tree.Name);
current.SetTooltipText(0, tree.StrValue);
foreach (EGTree child in tree.GetChilds())
{
CreateTreeItem(child, current);
}
}
}
}

59
addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
namespace EGFramework
{
public struct EGSelectParam
{
public int SelectID { set; get; }
public Dictionary<int, string> SelectList { set; get; }
public EGSelectParam(int selectID, Dictionary<int, string> selectList)
{
SelectID = selectID;
SelectList = selectList;
}
}
public struct EGRangeParam
{
public double Min { set; get; }
public double Max { set; get; }
public double Step { set; get; }
public double Value { set; get; }
public EGRangeParam(double min, double max, double step, double value)
{
Min = min;
Max = max;
Step = step;
Value = value;
}
}
public struct EGPathSelect
{
public string Path { set; get; }
public bool IsDir { set; get; }
public override string ToString()
{
return Path;
}
}
public interface IEGReadOnlyString
{
public string GetString();
}
public struct EGReadOnlyString : IEGReadOnlyString
{
public string Value { get; private set; }
public EGReadOnlyString(string value)
{
Value = value;
}
public string GetString()
{
return Value;
}
}
}

127
addons/EGFramework/Module/GenerateTools/Templete/Variant/EGTree.cs

@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace EGFramework
{
public interface IEGTree
{
public string Name { set; get; }
public IEGTree GetParent();
public void SetParent(IEGTree tree);
public IEnumerable<IEGTree> GetChilds();
public void AppendTree(IEGTree tree);
}
public class EGTree : IEGTree
{
public string Name { set; get; }
public string StrValue { set; get; }
public long IntegerValue { set; get; }
public byte[] ByteValue { set; get; }
public float FloatValue { set; get; }
public bool BoolValue { set; get; }
public IEGTree Parent { set; get; }
public List<IEGTree> Childs { set; get; } = new List<IEGTree>();
public EGTree()
{
}
public EGTree(string name)
{
this.Name = name;
}
public void AppendTree(IEGTree tree)
{
tree.SetParent(this);
Childs.Add(tree);
}
public virtual IEnumerable<IEGTree> GetChilds()
{
return Childs;
}
public virtual IEGTree GetParent()
{
return Parent;
}
public void SetParent(IEGTree tree)
{
this.Parent = tree;
}
}
public static class EGTreeFactory
{
public static EGTree CreateTreeByJson(string json)
{
JsonTextReader reader = new JsonTextReader(new StringReader(json));
Stack<IEGTree> TreeStack = new Stack<IEGTree>();
EGTree resultTree = new EGTree();
EGTree lastTree = null;
while (reader.Read())
{
if (reader.TokenType == JsonToken.StartObject)
{
if (lastTree != null)
{
TreeStack.Push(lastTree);
}
}
if (reader.TokenType == JsonToken.EndObject)
{
if(TreeStack.Count>0)
TreeStack.Pop();
}
if (reader.TokenType == JsonToken.PropertyName)
{
EGTree newTree = new EGTree();
if (reader.Value != null)
{
newTree.Name = reader.Value.ToString();
}
if (TreeStack.Count > 0)
{
TreeStack.Peek().AppendTree(newTree);
}
else
{
resultTree.AppendTree(newTree);
}
lastTree = newTree;
}
if (lastTree != null && reader.TokenType == JsonToken.Integer)
{
lastTree.IntegerValue = (long)reader.Value;
}
if (lastTree != null && reader.TokenType == JsonToken.Boolean)
{
lastTree.BoolValue = (bool)reader.Value;
}
if (lastTree != null && reader.TokenType == JsonToken.String)
{
lastTree.StrValue = (string)reader.Value;
}
if (lastTree != null && reader.TokenType == JsonToken.Float)
{
lastTree.FloatValue = (float)reader.Value;
}
if (lastTree!=null && reader.TokenType == JsonToken.Bytes)
{
lastTree.ByteValue = (byte[])reader.Value;
}
}
return resultTree;
}
}
}

127
addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs

@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace EGFramework{
public static class EGenerateVariant
{
public static Dictionary<string, object> EGenerateDictiontaryByType(this Type self)
{
PropertyInfo[] propertyNames = self.GetProperties();
FieldInfo[] fieldNames = self.GetFields();
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
result.Add(pName.Name, pName.Name);
}
foreach (FieldInfo fName in fieldNames)
{
result.Add(fName.Name, fName.Name);
}
return result;
}
public static Dictionary<string, object> EGenerateEmptyDictiontaryByType(this Type self)
{
PropertyInfo[] propertyNames = self.GetProperties();
FieldInfo[] fieldNames = self.GetFields();
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
result.Add(pName.Name, "");
}
foreach (FieldInfo fName in fieldNames)
{
result.Add(fName.Name, "");
}
return result;
}
public static Dictionary<string, Type> EGenerateTypeDictiontaryByType(this Type self)
{
PropertyInfo[] propertyNames = self.GetProperties();
FieldInfo[] fieldNames = self.GetFields();
Dictionary<string, Type> result = new Dictionary<string, Type>();
foreach (PropertyInfo pName in propertyNames)
{
result.Add(pName.Name, pName.PropertyType);
}
foreach (FieldInfo fName in fieldNames)
{
result.Add(fName.Name, fName.FieldType);
}
return result;
}
public static Dictionary<string, object> EGenerateDictiontaryByObject<T>(this T self)
{
PropertyInfo[] propertyNames = typeof(T).GetProperties();
FieldInfo[] fieldNames = typeof(T).GetFields();
// object[] s = propertyNames.Select(p => p.GetValue(self)).ToArray();
// object[] a = fieldNames.Select(p => p.GetValue(self)).ToArray();
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
object p = pName.GetValue(self);
result.Add(pName.Name, p);
}
foreach (FieldInfo fName in fieldNames)
{
object p = fName.GetValue(self);
result.Add(fName.Name, p);
}
return result;
}
public static List<Dictionary<string, object>> EGenerateDictionaryByGroup<T>(this IEnumerable<T> self)
{
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
PropertyInfo[] propertyNames = typeof(T).GetProperties();
FieldInfo[] fieldNames = typeof(T).GetFields();
foreach (T member in self)
{
Dictionary<string, object> mResult = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
object p = pName.GetValue(member);
mResult.Add(pName.Name, p);
}
foreach (FieldInfo fName in fieldNames)
{
object p = fName.GetValue(member);
mResult.Add(fName.Name, p);
}
result.Add(mResult);
}
return result;
}
//Default primary key is id,Id,ID.
public static string EGetDefaultPrimaryKey(this Dictionary<string, object> self)
{
foreach (KeyValuePair<string, object> param in self)
{
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id")
{
return param.Key;
}
}
return "";
}
public static List<Dictionary<string, object>> ESearchByKeyword(this List<Dictionary<string, object>> data, string fieldName, string keyWords)
{
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
foreach (Dictionary<string, object> tablerow in data)
{
if (tablerow.ContainsKey(fieldName))
{
if (tablerow[fieldName].ToString().Contains(keyWords))
{
result.Add(tablerow);
}
}
}
return result;
}
}
}

48
addons/EGFramework/Module/NodeExtension/EGCreate.cs

@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
using Godot;
using static Godot.GD;
namespace EGFramework{
public class EGSingletonNode : IEGFramework, IModule
{
public IOCContainer NodeContainer = new IOCContainer();
public void Init()
{
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGCanCreateNodeExtension
{
public static TNode CreateNode<TNode>(this Node self) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode CreateNode<TNode>(this Node self,string name) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode SingletonNode<TNode>(this Node self) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData);
return nodeData;
}
public static void Alert(this Node self,string alertMsg){
}
}
}

38
addons/EGFramework/Module/NodeExtension/EGGodotPath.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
using Godot;
namespace EGFramework{
public partial class EGGodotPath : IModule, IEGFramework
{
public void Init()
{
}
public void OpenResPath(){
OS.ShellOpen("".GetGodotResPath());
}
public void OpenUserPath(){
OS.ShellOpen("".GetGodotUserPath());
}
public IArchitecture GetArchitecture()
{
throw new System.NotImplementedException();
}
}
public static class GodotPathExtension{
public static string GetGodotResPath(this string path){
return ProjectSettings.GlobalizePath("res://"+path);
}
public static string GetGodotUserPath(this string path){
return ProjectSettings.GlobalizePath("user://"+path);
}
}
}

22
addons/EGFramework/Module/NodeExtension/EGNode.cs

@ -4,15 +4,19 @@ using System; @@ -4,15 +4,19 @@ using System;
namespace EGFramework{
public static class EGNodeExtension
{
public static TModule NodeModule<TModule>(this Node self) where TModule : Node,IModule,new(){
if(EGArchitectureImplement.Interface.IsInitModule<TModule>()){
public static TModule NodeModule<TModule>(this Node self) where TModule : Node, IModule, new()
{
if (EGArchitectureImplement.Interface.IsInitModule<TModule>())
{
TModule module = new TModule();
module.Name = typeof(TModule).ToString();
Print(module.Name);
self.AddChild(module);
EGArchitectureImplement.Interface.RegisterModule(module);
return module;
}else{
}
else
{
return EGArchitectureImplement.Interface.GetModule<TModule>();
}
}
@ -29,21 +33,29 @@ namespace EGFramework{ @@ -29,21 +33,29 @@ namespace EGFramework{
{
foreach (Node child in itemContainer.GetChildren())
{
if(child.GetType()==typeof(T)){
if (child.GetType() == typeof(T))
{
child.QueueFree();
}
}
}
[Obsolete("This method can be replaced by ClearChildren<Label>")]
public static void ClearChildrenLabel(this Node itemContainer)
{
foreach (Node child in itemContainer.GetChildren())
{
if(child.GetType()==typeof(Label)){
if (child.GetType() == typeof(Label))
{
child.QueueFree();
}
}
}
public static void ToEnd(this Node child)
{
child.GetParent()?.MoveChild(child,-1);
}
}
}

37
addons/EGFramework/Module/NodeExtension/EGProtocolScheduleGodot.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
using Godot;
namespace EGFramework{
/// <summary>
/// In Godot engine, the async method return cannot operate the godot main thread such as Screen Trees Node.
/// The protocol schedule provide a main thread to check the message in protocol tools 's response message.
/// If you have more idea ,please issue to me, thanks.
/// </summary>
public partial class EGProtocolScheduleGodot : Node, IModule, IEGFramework
{
public EGProtocolSchedule ProtocolSchedule { set; get; } = new EGProtocolSchedule();
public override void _Process(double delta)
{
ProtocolSchedule.CheckedProcess();
}
public void Init()
{
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class CanGetEGProtocolInGodotExtension{
public static EGProtocolSchedule EGProtocolSchedule(this Node self){
return self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule;
}
public static void EGEnabledProtocolTools(this Node self){
self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule.EnabledAllTools();
}
public static void EGEnabledProtocolTool<TProtocolReceived>(this Node self) where TProtocolReceived : class, IModule,IProtocolReceived,new(){
self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule.EnabledTool<TProtocolReceived>();
}
}
}

15
addons/EGFramework/Module/NodeExtension/EGThread.cs

@ -44,17 +44,24 @@ namespace EGFramework{ @@ -44,17 +44,24 @@ namespace EGFramework{
}
public static class EGThreadExtension
{
public static void ExecuteInMainThread(this Node self, Action action){
public static void ExecuteInMainThread(this Node self, Action action)
{
//action.Invoke();
self.NodeModule<EGThread>().ExecuteInMainThread(action);
}
public static void ExecuteAfterSecond(this Node self, Action action,double delay){
self.NodeModule<EGThread>().ExecuteAfterSecond(action,delay);
public static void ExecuteAfterSecond(this Node self, Action action, double delay)
{
self.NodeModule<EGThread>().ExecuteAfterSecond(action, delay);
}
public static void EGEnabledThread(this Node self){
public static void EGEnabledThread(this Node self)
{
self.NodeModule<EGThread>();
}
public static void ExecuteInEndOfFrame(this object self, Action action)
{
Callable.From(action).CallDeferred();
}
}
}

16
addons/EGFramework/Module/NodeExtension/EGTweenExtension.cs

@ -52,6 +52,22 @@ namespace EGFramework.EGTween{ @@ -52,6 +52,22 @@ namespace EGFramework.EGTween{
tween.TweenProperty(self,"rotation",angle*Mathf.Pi/180,delay);
return tween;
}
public static Tween TweenRotationByRad(this Node3D self,Vector3 rad,float delay){
Tween tween = self.CreateTween();
tween.TweenProperty(self,"rotation",rad,delay);
return tween;
}
public static Tween TweenRotationByAngle(this Node3D self,Vector3 eulerAngle,float delay){
Tween tween = self.CreateTween();
tween.TweenProperty(self,"rotation",eulerAngle*Mathf.Pi/180,delay);
return tween;
}
public static Vector3 EulerAngleToRad(this Vector3 eulerAngle){
return new Vector3(eulerAngle.X*Mathf.Pi/180,eulerAngle.Y*Mathf.Pi/180,eulerAngle.Z*Mathf.Pi/180);
}
public static Vector3 RadToEulerAngle(this Vector3 rad){
return new Vector3(rad.X/Mathf.Pi*180,rad.Y/Mathf.Pi*180,rad.Z/Mathf.Pi*180);
}
#endregion

36
addons/EGFramework/Module/ProtocolTools/EGModbus.cs → addons/EGFramework/Module/OtherTools/EGModbus.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using Godot;
namespace EGFramework{
/// <summary>
@ -9,16 +9,16 @@ namespace EGFramework{ @@ -9,16 +9,16 @@ namespace EGFramework{
/// </summary>
public class EGModbus : IEGFramework, IModule
{
public Queue<ModbusRTU_Response> RTUCache = new Queue<ModbusRTU_Response>();
public Queue<ModbusTCP_Response> TCPCache = new Queue<ModbusTCP_Response>();
public ConcurrentQueue<ModbusRTU_Response?> RTUCache = new ConcurrentQueue<ModbusRTU_Response?>();
public ConcurrentQueue<ModbusTCP_Response?> TCPCache = new ConcurrentQueue<ModbusTCP_Response?>();
public int Delay = 2000;
public Queue<int> WaitForSendRTU = new Queue<int>();
public ConcurrentQueue<int> WaitForSendRTU = new ConcurrentQueue<int>();
public int NextSendRTU = 0;
public int SendPointerRTU = 1;
public Queue<int> WaitForSendTCP = new Queue<int>();
public ConcurrentQueue<int> WaitForSendTCP = new ConcurrentQueue<int>();
public int NextSendTCP = 0;
public int SendPointerTCP = 1;
@ -55,7 +55,7 @@ namespace EGFramework{ @@ -55,7 +55,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Read"+messageId+" ----");
EG.Print("-----Read"+messageId+" ----");
//return null;
}
RTUCache.Clear();
@ -91,7 +91,7 @@ namespace EGFramework{ @@ -91,7 +91,7 @@ namespace EGFramework{
timeout+=10;
}
if(RTUCache.Count>0){
res = RTUCache.Dequeue();
RTUCache.TryDequeue(out res);
}else{
//Print Error Timeout
OnReadTimeOut.Invoke();
@ -100,7 +100,7 @@ namespace EGFramework{ @@ -100,7 +100,7 @@ namespace EGFramework{
this.EGSerialPort().ClearReceivedCache(serialPort);
IsRequestRTU = false;
if(this.WaitForSendRTU.Count>0){
NextSendRTU = this.WaitForSendRTU.Dequeue();
this.WaitForSendRTU.TryDequeue(out NextSendRTU);
}
return res;
}
@ -118,7 +118,7 @@ namespace EGFramework{ @@ -118,7 +118,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Write"+messageId+" ----");
EG.Print("-----Write"+messageId+" ----");
//return null;
}
RTUCache.Clear();
@ -144,7 +144,7 @@ namespace EGFramework{ @@ -144,7 +144,7 @@ namespace EGFramework{
timeout+=10;
}
if(RTUCache.Count>0){
res = RTUCache.Dequeue();
RTUCache.TryDequeue(out res);
}else{
//Print Error Timeout
OnReadTimeOut.Invoke();
@ -153,7 +153,7 @@ namespace EGFramework{ @@ -153,7 +153,7 @@ namespace EGFramework{
this.EGSerialPort().ClearReceivedCache(serialPort);
IsRequestRTU = false;
if(this.WaitForSendRTU.Count>0){
NextSendRTU = this.WaitForSendRTU.Dequeue();
this.WaitForSendRTU.TryDequeue(out NextSendRTU);
}
return res;
}
@ -175,7 +175,7 @@ namespace EGFramework{ @@ -175,7 +175,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Read"+messageId+" ----");
EG.Print("-----Read"+messageId+" ----");
//return null;
}
TCPCache.Clear();
@ -196,7 +196,7 @@ namespace EGFramework{ @@ -196,7 +196,7 @@ namespace EGFramework{
timeout += 10;
}
if(TCPCache.Count>0){
res = TCPCache.Dequeue();
TCPCache.TryDequeue(out res);
}else{
//Print Error Timeout
OnReadTimeOut.Invoke();
@ -204,7 +204,7 @@ namespace EGFramework{ @@ -204,7 +204,7 @@ namespace EGFramework{
});
IsRequestTCP = false;
if(this.WaitForSendTCP.Count>0){
NextSendTCP = this.WaitForSendTCP.Dequeue();
this.WaitForSendTCP.TryDequeue(out NextSendTCP);
}
return res;
}
@ -222,7 +222,7 @@ namespace EGFramework{ @@ -222,7 +222,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Write"+messageId+" ----");
EG.Print("-----Write"+messageId+" ----");
//return null;
}
TCPCache.Clear();
@ -251,7 +251,7 @@ namespace EGFramework{ @@ -251,7 +251,7 @@ namespace EGFramework{
timeout+=10;
}
if(TCPCache.Count>0){
res = TCPCache.Dequeue();
TCPCache.TryDequeue(out res);
}else{
//Print Error Timeout
OnReadTimeOut.Invoke();
@ -259,10 +259,10 @@ namespace EGFramework{ @@ -259,10 +259,10 @@ namespace EGFramework{
});
IsRequestTCP = false;
if(this.WaitForSendTCP.Count>0){
NextSendTCP = this.WaitForSendTCP.Dequeue();
this.WaitForSendTCP.TryDequeue(out NextSendTCP);
}
if(this.WaitForSendTCP.Count>0){
NextSendTCP = this.WaitForSendTCP.Dequeue();
this.WaitForSendTCP.TryDequeue(out NextSendTCP);
}
return res;
}

4
addons/EGFramework/Module/SaveTools/EGSqlite.cs → addons/EGFramework/Module/OtherTools/EGSqlite.cs

@ -77,7 +77,7 @@ namespace EGFramework{ @@ -77,7 +77,7 @@ namespace EGFramework{
string sqlCommand = "CREATE TABLE " + typeof(TData).Name;
sqlCommand += "(\"ID\" INTEGER NOT NULL UNIQUE,";
var properties = typeof(TData).GetProperties();
Godot.GD.Print(properties.Count() + " Readed ");
EG.Print(properties.Count() + " Readed ");
foreach(var property in properties){
if(property.PropertyType == typeof(int) || property.PropertyType == typeof(bool) || property.PropertyType.IsEnum){
sqlCommand += "\"" + property.Name + "\" INTEGER" + " NOT NULL,";
@ -89,7 +89,7 @@ namespace EGFramework{ @@ -89,7 +89,7 @@ namespace EGFramework{
}
}
sqlCommand += "PRIMARY KEY(\"ID\" AUTOINCREMENT))";
Godot.GD.Print(sqlCommand);
EG.Print(sqlCommand);
SqliteCommand createCommand = new SqliteCommand(sqlCommand,SqliteConn);
result = result + createCommand.ExecuteNonQuery().ToString();
}

19
addons/EGFramework/Module/WebDav/EGWebDav.cs → addons/EGFramework/Module/OtherTools/EGWebDav.cs

@ -130,7 +130,7 @@ namespace EGFramework{ @@ -130,7 +130,7 @@ namespace EGFramework{
ResultFileList.Add(new WebDavFileMsg{
FileName = res.DisplayName ,
IsCollection = res.IsCollection ,
ContentLength = res.ContentLength ,
Size = res.ContentLength ,
Uri = res.Uri ,
LastUpdateTime = res.LastModifiedDate
});
@ -155,7 +155,7 @@ namespace EGFramework{ @@ -155,7 +155,7 @@ namespace EGFramework{
CurrentFileList.Add(new WebDavFileMsg{
FileName = res.DisplayName ,
IsCollection = res.IsCollection ,
ContentLength = res.ContentLength ,
Size = res.ContentLength ,
Uri = res.Uri ,
LastUpdateTime = res.LastModifiedDate
});
@ -202,16 +202,27 @@ namespace EGFramework{ @@ -202,16 +202,27 @@ namespace EGFramework{
}
}
public struct WebDavFileMsg{
public struct WebDavFileMsg : IEGFileMsg{
public string FileName { set; get; }
public bool IsCollection { set; get; }
/// <summary>
/// unit is kb
/// </summary>
public long? ContentLength { set; get; }
public long? Size { set; get; }
public string Uri { set; get; }
public DateTime? LastUpdateTime { set; get; }
public DateTime? LastModify { set; get; }
public void Init(string fileName, bool isCollection, string uri, long? size = null, DateTime? lastModify = null)
{
this.FileName = fileName;
this.IsCollection = isCollection;
this.Uri = uri;
this.Size = size;
this.LastModify = lastModify;
}
}
public static class EGWebDavExtension{

22
addons/EGFramework/Module/EGMessage.cs → addons/EGFramework/Module/ProtocolTools/EGMessage.cs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Timers;
namespace EGFramework
@ -15,11 +15,11 @@ namespace EGFramework @@ -15,11 +15,11 @@ namespace EGFramework
public EasyEvent<RequestMsgEvent> OnRequest { set; get; } = new EasyEvent<RequestMsgEvent>();
/// <summary>
/// Send delay in millisecond,if you don't need a Timer to delay send message,you can set it to 0.
/// Send delay in millisecond,if you don't need a Timer to delay send message,you can set it to 0. ( this delay options is prevent for sticky package )
/// </summary>
/// <value></value>
public int SendDelay { set; get; } = 100;
public Queue<RequestMsgEvent> RequestCache { set; get; } = new Queue<RequestMsgEvent>();
public ConcurrentDictionary<string,ConcurrentQueue<RequestMsgEvent>> RequestCache { set; get; } = new ConcurrentDictionary<string,ConcurrentQueue<RequestMsgEvent>>();
private System.Timers.Timer RequestTimer { set; get; }
public override void Init()
@ -58,7 +58,10 @@ namespace EGFramework @@ -58,7 +58,10 @@ namespace EGFramework
public void SendRequest<TRequest>(TRequest request,string sender,ProtocolType protocolType) where TRequest:IRequest
{
if(SendDelay>0){
RequestCache.Enqueue(new RequestMsgEvent(request,sender,protocolType));
if(!RequestCache.ContainsKey(sender)){
RequestCache[sender] = new ConcurrentQueue<RequestMsgEvent>();
}
RequestCache[sender].Enqueue(new RequestMsgEvent(request,sender,protocolType));
}else{
OnRequest.Invoke(new RequestMsgEvent(request,sender,protocolType));
}
@ -67,8 +70,11 @@ namespace EGFramework @@ -67,8 +70,11 @@ namespace EGFramework
}
private void ExecuteRequest(object source, ElapsedEventArgs e){
if(RequestCache.Count>0){
OnRequest.Invoke(RequestCache.Dequeue());
foreach(ConcurrentQueue<RequestMsgEvent> singleCache in RequestCache.Values){
if(singleCache.Count>0){
singleCache.TryDequeue(out RequestMsgEvent msg);
OnRequest.Invoke(msg);
}
}
}
@ -321,7 +327,9 @@ namespace EGFramework @@ -321,7 +327,9 @@ namespace EGFramework
FileStream = 0x50,
MemoryStream = 0x60,
MQTTClient = 0x70,
Bacnet = 0x80
Bacnet = 0x80,
SSHClient = 0x90,
Process = 0xA0,
//MQTT,SSH,etc...
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save