6 changed files with 292 additions and 1 deletions
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -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(){ |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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…
Reference in new issue