8 changed files with 205 additions and 117 deletions
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
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()); |
||||
|
||||
GD.Print(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.SingletoneNode<EGodotEditDialog>("FileDialog"); |
||||
editDialog.InitDialog(data, onDataEdit, title); |
||||
editDialog.PopupCentered(); |
||||
return editDialog; |
||||
} |
||||
} |
||||
} |
@ -1,78 +0,0 @@
@@ -1,78 +0,0 @@
|
||||
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; |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
Loading…
Reference in new issue