private UserControl CreateEditorElementView(ValueEditorAttribute elementAttr) { UserControl view; if (elementAttr is ValueEditor_NumberBoxAttribute) { view = new ValueEditorElement_NumberBox(); } else if (elementAttr is ValueEditor_SliderAttribute) { view = new ValueEditorElement_Slider(); } else if (elementAttr is ValueEditor_SwitchAttribute) { view = new ValueEditorElement_Switch(); } else if (elementAttr is ValueEditor_TextBoxAttribute) { var attr = elementAttr as ValueEditor_TextBoxAttribute; view = new ValueEditorElement_TextBox(attr); } else if (elementAttr is ValueEditor_NumberBoxAttribute) { var attr = elementAttr as ValueEditor_NumberBoxAttribute; view = new ValueEditorElement_NumberBox(attr); } else if (elementAttr is ValueEditor_Vector2Attribute) { var attr = elementAttr as ValueEditor_Vector2Attribute; view = new ValueEditorElement_Vector2(attr); } else if (elementAttr is ValueEditor_Vector3Attribute) { var attr = elementAttr as ValueEditor_Vector3Attribute; view = new ValueEditorElement_Vector3(attr); } else if (elementAttr is ValueEditor_ColorBoxAttribute) { var attr = elementAttr as ValueEditor_ColorBoxAttribute; view = new ValueEditorElement_ColorBox(); } else if (elementAttr is ValueEditor_AnchorPresetAttribute) { view = new ValueEditorElement_AnchorPreset(); } else { throw new NotImplementedException(); } return(view); }
public static void CreateValueEditorViews(IEditableModel model, StackPanel editorViewContext, ModelValueChangedDelegate modelValueChanged = null) { Type modelType = model.GetType(); FieldInfo[] fields = modelType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo field in fields) { ValueEditorAttribute editorAttribute = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute; if (editorAttribute == null) { continue; } ValueEditorView valueEditorView = new ValueEditorView(model, field, modelValueChanged); editorViewContext.Children.Add(valueEditorView); } }
public ValueEditorView(object model, FieldInfo field, ModelValueChangedDelegate modelValueChanged = null) : this() { this.model = model; this.field = field; //Classify components : 헤더 등등 ValueEditorComponentAttribute[] components = field.GetCustomAttributes(typeof(ValueEditorComponentAttribute)).Select(x => (ValueEditorComponentAttribute)x).ToArray(); foreach (ValueEditorComponentAttribute component in components) { UserControl view = CreateEditorComponentView(component); ValueEditorComponentContext.Children.Add(view); } //Classify elements : 실제 값 //ValueName ValueEditorAttribute element = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute; ValueNameText = element.valueName; //ValueEditor UserControl editorElement = CreateEditorElementView(element); valueEditorElement = (IValueEditorElement)editorElement; valueEditorElement.EditableValueChanged += IEditorElement_ElementValueChanged; valueEditorElement.EditableValue = field.GetValue(model); //Outter event valueEditorElement.EditableValueChanged += (object value) => { modelValueChanged?.Invoke(model, field); }; switch (element.layout) { case ValueEditorLayout.Wide: SetWideEditorElementContext(); break; } Children.Add(editorElement); }
public virtual JObject ToJObject() { JObject jOrder = new JObject(); jOrder.Add("Type", OrderType.ToString()); JObject jAttributes = new JObject(); jOrder.Add("Attributes", jAttributes); Type modelType = GetType(); FieldInfo[] fields = modelType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo field in fields) { ValueEditorAttribute editorAttribute = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute; if (editorAttribute == null) { continue; } object value = field.GetValue(this); string stringValue; if (value == null) { stringValue = string.Empty; } else { stringValue = value.ToString(); } jAttributes.Add(field.Name, stringValue); } return(jOrder); }