diff --git a/Example/SaveSystem/Script/ViewSaveSystem.cs b/Example/SaveSystem/Script/ViewSaveSystem.cs index ffcb517..19ca704 100644 --- a/Example/SaveSystem/Script/ViewSaveSystem.cs +++ b/Example/SaveSystem/Script/ViewSaveSystem.cs @@ -40,7 +40,9 @@ namespace EGFramework.Examples.Test{ // }); EGodotTableRowData rowData = table.CreateNode("RowData"); - rowData.InitRowData(new Dictionary() { { "Name", "Tom" }, { "Age", 18 } }); + rowData.Init(new Dictionary() { { "Name", "Tom" }, { "Age", 18 } }); + EGodotRowData rowData2 = table.CreateNode("RowData2"); + rowData2.Init(new Dictionary() { { "Name", "Z" }, { "Age", 1 } }); } public override void _ExitTree() diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs index 80f84dc..943fda1 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using Godot; namespace EGFramework.UI{ - public partial class EGodotTableRowData : EGRowData + public partial class EGodotTableRowData : EGodotRowData { public Control Operate { get; set; } public Button Modify { get; set; } @@ -11,9 +11,9 @@ namespace EGFramework.UI{ private Action> OnDataEdit; - public override void InitRowData(Dictionary data) + public override void Init(Dictionary data) { - base.InitRowData(data); + base.Init(data); Operate = new HBoxContainer(); Operate.Name = "Operate"; diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Interface/EGGodotData.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Interface/EGGodotData.cs new file mode 100644 index 0000000..2ff4500 --- /dev/null +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Interface/EGGodotData.cs @@ -0,0 +1,7 @@ +namespace EGFramework.UI +{ + public interface IEGodotData + { + public void RefreshData(); + } +} \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs index b4be3c4..9e42f1a 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs @@ -3,7 +3,13 @@ using Godot; namespace EGFramework.UI { - public partial class EGodotEditParam : HBoxContainer,IEGFramework + public interface IEGodotParam : IEGodotData + { + public void Init(KeyValuePair data); + public void RefreshData(KeyValuePair data); + public KeyValuePair GetData(); + } + public partial class EGodotEditParam : HBoxContainer, IEGFramework { public Label ParamName { get; set; } public LineEdit ParamEdit { get; set; } @@ -14,9 +20,10 @@ namespace EGFramework.UI public SpinBox ParamSpinBox { get; set; } public HSlider ParamSlider { get; set; } - public KeyValuePair EditValue { get; set; } + public KeyValuePair EditValue { get; set; } - public void Init(KeyValuePair editValue){ + public void Init(KeyValuePair editValue) + { EditValue = editValue; this.ParamName = new Label(); ParamName.Name = "ParamName"; @@ -24,7 +31,8 @@ namespace EGFramework.UI ParamName.SizeFlagsHorizontal = SizeFlags.ExpandFill; this.AddChild(ParamName); ParamName.Text = editValue.Key; - if(editValue.Value is string){ + if (editValue.Value is string) + { this.ParamEdit = new LineEdit(); ParamEdit.Name = "ParamEdit"; ParamEdit.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -32,7 +40,8 @@ namespace EGFramework.UI this.AddChild(ParamEdit); ParamEdit.Text = (string)editValue.Value; } - else if(editValue.Value is bool){ + else if (editValue.Value is bool) + { this.ParamCheck = new CheckButton(); ParamCheck.Name = "ParamCheck"; ParamCheck.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -40,24 +49,28 @@ namespace EGFramework.UI ParamCheck.ButtonPressed = (bool)editValue.Value; this.AddChild(ParamCheck); } - else if(editValue.Value is IEGReadOnlyString){ + 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){ + else if (editValue.Value is EGSelectParam) + { this.ParamOption = new OptionButton(); ParamOption.Name = "ParamOption"; ParamOption.SizeFlagsHorizontal = SizeFlags.ExpandFill; this.AddChild(ParamOption); - foreach(KeyValuePair selectOptions in ((EGSelectParam)editValue.Value).SelectList){ - this.ParamOption.AddItem(selectOptions.Value,selectOptions.Key); + foreach (KeyValuePair 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){ + else if (editValue.Value is int) + { this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -66,7 +79,8 @@ namespace EGFramework.UI ParamSpinBox.MinValue = int.MinValue; this.AddChild(ParamSpinBox); } - else if(editValue.Value is float){ + else if (editValue.Value is float) + { this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -76,7 +90,8 @@ namespace EGFramework.UI ParamSpinBox.Step = 0.01f; this.AddChild(ParamSpinBox); } - else if(editValue.Value is double){ + else if (editValue.Value is double) + { this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -86,7 +101,8 @@ namespace EGFramework.UI ParamSpinBox.Step = 0.0001f; this.AddChild(ParamSpinBox); } - else if(editValue.Value is EGRangeParam){ + else if (editValue.Value is EGRangeParam) + { this.ParamSlider = new HSlider(); ParamSlider.Name = "ParamSlider"; ParamSlider.SizeFlagsHorizontal = SizeFlags.ExpandFill; @@ -99,27 +115,35 @@ namespace EGFramework.UI } } - public string GetKey(){ + public string GetKey() + { return EditValue.Key; } - public object GetValue(){ - if(ParamEdit != null){ + public object GetValue() + { + if (ParamEdit != null) + { return ParamEdit.Text; } - else if(ParamCheck != null){ + else if (ParamCheck != null) + { return ParamCheck.ButtonPressed; } - else if(ParamOption != null){ + else if (ParamOption != null) + { return ParamOption.Selected; } - else if(ParamReadOnly != null){ + else if (ParamReadOnly != null) + { return ParamReadOnly.Text; } - else if(ParamSpinBox != null){ + else if (ParamSpinBox != null) + { return ParamSpinBox.Value; } - else if(ParamSlider != null){ + else if (ParamSlider != null) + { return ParamSlider.Value; } return null; diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotRowData.cs similarity index 73% rename from addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs rename to addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotRowData.cs index 191c94c..2314a8c 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotRowData.cs @@ -4,12 +4,14 @@ using System.Collections.Generic; namespace EGFramework.UI { - public interface IEGRowData + + public interface IEGodotRowData:IEGodotData { - public void InitRowData(Dictionary data); + public void Init(Dictionary data); public void RefreshData(Dictionary data); + public Dictionary GetData(); } - public partial class EGRowData : PanelContainer, IEGFramework,IEGRowData + public partial class EGodotRowData : PanelContainer, IEGFramework, IEGodotRowData { public Button ItemHover { get; set; } @@ -19,14 +21,20 @@ namespace EGFramework.UI protected Dictionary Data { get; set; } protected bool IsInit { set; get; } = false; - - public virtual void InitRowData(Dictionary data) + + public Dictionary GetData() + { + return this.Data; + } + + + public virtual void Init(Dictionary data) { if (IsInit) { this.Data = data; this.RefreshData(data); - return; + return; } this.Data = data; BackGround = new ColorRect(); @@ -57,6 +65,7 @@ namespace EGFramework.UI }); } this.AddThemeStyleboxOverride("panel", new StyleBoxEmpty()); + IsInit = true; } public virtual void RefreshData(Dictionary data) @@ -73,5 +82,24 @@ namespace EGFramework.UI }); } } + + 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; + } + } } }