Browse Source

fixed add egodotEditDialog

master
jkpete 3 months ago
parent
commit
086252a47b
  1. 15
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 78
      addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotEditDialog.cs
  3. 129
      addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotEditParam.cs
  4. 27
      addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotTableRowData.cs
  5. 27
      addons/EGFramework/Module/Struct/EGDataStruct.cs
  6. 17
      addons/EGFramework/Module/Struct/EGReadOnly.cs

15
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EGFramework.UI;
using Godot;
using LiteDB;
using Renci.SshNet;
@ -26,7 +27,18 @@ namespace EGFramework.Examples.Test{ @@ -26,7 +27,18 @@ namespace EGFramework.Examples.Test{
dataStudents.Add(dataStudent);
dataStudents.Add(dataStudent2);
this.GetNode<TabContainer>("TabContainer").CreateTable<DataStudent>(dataStudents,"Teacher");
this.Alert("Hello World");
// Button btn = this.CreateNode<Button>("Test");
// btn.Text = "Test";
// btn.Position = new Vector2(100,100);
// btn.Connect("pressed",Callable.From (() => {
// this.Alert("Test");
// }));
EGodotEditDialog Edit = this.CreateNode<EGodotEditDialog>("Edit");
Edit.InitDialog(new Dictionary<string, object>() {{"Name","Tom"},{"Age",18}},(data) => {
GD.Print(data["Name"]);
GD.Print(data["Age"]);
});
}
public override void _ExitTree()
@ -34,6 +46,7 @@ namespace EGFramework.Examples.Test{ @@ -34,6 +46,7 @@ namespace EGFramework.Examples.Test{
}
}
public struct DataStudent{
public string Name { get; set; }

78
addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotEditDialog.cs

@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
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;
public void InitDialog(Dictionary<string,object> data,Action<Dictionary<string,object>> onDataEdit,string title = "Edit Data"){
if(!IsInit){
EditList = new VBoxContainer();
EditList.Name = "EditList";
EditList.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(EditList);
this.ErrorTips = new Label();
ErrorTips.Name = "ErrorTips";
ErrorTips.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
EditList.AddChild(ErrorTips);
IsInit = true;
}
this.Title = title;
ErrorTips.Visible = false;
OnDataEdit = OnEdit.Register(onDataEdit);
this.EditList.ClearChildren();
ParamUIs.Clear();
foreach(KeyValuePair<string,object> param in data){
EGodotEditParam paramUI = new EGodotEditParam();
this.EditList.AddChild(paramUI);
paramUI.Init(param);
ParamUIs.Add(paramUI);
}
this.Connect("confirmed",Callable.From(OnConfirm));
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;
}
}
}

129
addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotEditParam.cs

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public partial class EGodotEditParam : HBoxContainer,IEGFramework
{
public Label ParamName { get; set; }
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 SpinBox ParamSpinBox { get; set; }
public HSlider ParamSlider { get; set; }
public KeyValuePair<string,object> EditValue { get; set; }
public void Init(KeyValuePair<string,object> editValue){
EditValue = editValue;
this.ParamName = new Label();
ParamName.Name = "ParamName";
ParamName.Text = editValue.Key;
ParamName.SizeFlagsHorizontal = SizeFlags.ExpandFill;
this.AddChild(ParamName);
ParamName.Text = editValue.Key;
if(editValue.Value is string){
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.Value = (int)editValue.Value;
ParamSpinBox.MaxValue = int.MaxValue;
ParamSpinBox.MinValue = int.MinValue;
this.AddChild(ParamSpinBox);
}
else if(editValue.Value is float){
this.ParamSpinBox = new SpinBox();
ParamSpinBox.Name = "ParamSpinBox";
ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamSpinBox.Value = (float)editValue.Value;
ParamSpinBox.MaxValue = float.MaxValue;
ParamSpinBox.MinValue = float.MinValue;
ParamSpinBox.Step = 0.01f;
this.AddChild(ParamSpinBox);
}
else if(editValue.Value is double){
this.ParamSpinBox = new SpinBox();
ParamSpinBox.Name = "ParamSpinBox";
ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamSpinBox.Value = (double)editValue.Value;
ParamSpinBox.MaxValue = double.MaxValue;
ParamSpinBox.MinValue = double.MinValue;
ParamSpinBox.Step = 0.0001f;
this.AddChild(ParamSpinBox);
}
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);
}
}
public string GetKey(){
return EditValue.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){
return ParamSpinBox.Value;
}
else if(ParamSlider != null){
return ParamSlider.Value;
}
return null;
}
}
}

27
addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotTableRowData.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI{
public partial class EGodotTableRowData : Control,IEGFramework
{
public Button ItemHover { get; set; }
public ColorRect Line { get; set; }
public ColorRect BackGround { get; set; }
public HBoxContainer List { get; set; }
public Control Operate { get; set; }
public Button Modify { get; set; }
public Button Delete { get; set; }
public string[] Data { get; set; }
// private Action<Dictionary<string,string>> OnDataEdit;
public void InitRowData(){
}
public void RefreshRow(){
}
}
}

27
addons/EGFramework/Module/Struct/EGDataStruct.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
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;
}
}
}

17
addons/EGFramework/Module/Struct/EGReadOnly.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
namespace EGFramework{
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;
}
}
}
Loading…
Cancel
Save