private void SetDictValue(string key, IRedType value) { if (value == null) { _properties.Remove(key); } else { if (value.GetType().IsGenericType) { if (value.GetType().GetGenericTypeDefinition() == typeof(CArrayFixedSize <>)) { var propertyInfo = RedReflection.GetPropertyByRedName(GetType(), key); var flags = propertyInfo.Flags; var size = flags.MoveNext() ? flags.Current : 0; if (((IRedArray)value).Count > size) { throw new ArgumentException(); } } if (value.GetType().GetGenericTypeDefinition() == typeof(CStatic <>)) { var propertyInfo = RedReflection.GetPropertyByRedName(GetType(), key); var flags = propertyInfo.Flags; var maxSize = flags.MoveNext() ? flags.Current : 0; ((IRedArray)value).MaxSize = maxSize; } } _properties[key] = value; } }
internal void InternalSetPropertyValue(string redPropertyName, IRedType value, bool native) { object oldValue = null; if (_properties.ContainsKey(redPropertyName)) { oldValue = _properties[redPropertyName]; } if (!Equals(oldValue, value)) { //if (oldValue != null) //{ // RemoveEventHandler(redPropertyName); //} SetDictValue(redPropertyName, value); if (!native) { _dynamicProperties.Add(redPropertyName); } //if (value != null) //{ // AddEventHandler(redPropertyName); //} // //OnObjectChanged(redPropertyName, oldValue, value); } }
public (bool, IRedType) GetFromXPath(string[] xPath) { IRedType result = null; var currentProps = _properties; foreach (var part in xPath) { if (currentProps == null) { return(false, null); } var arrPath = part.Split(':'); if (currentProps.ContainsKey(arrPath[0])) { result = currentProps[arrPath[0]]; currentProps = null; if (result is IList lst) { if (arrPath.Length == 2 && int.TryParse(arrPath[1], out var index)) { if (index >= lst.Count) { return(false, null); } result = (IRedType)lst[index]; } } if (result is RedBaseClass subCls) { currentProps = subCls._properties; } if (result is IRedBaseHandle handle) { var cCls = handle.GetValue(); currentProps = cCls._properties; } continue; } return(false, null); } return(true, result); }
private object GetSerializableValue(IRedType value) { if (value is CColor col) { return(new Dictionary <string, byte> { { nameof(col.Red), col.Red }, { nameof(col.Green), col.Green }, { nameof(col.Blue), col.Blue }, { nameof(col.Alpha), col.Alpha }, }); } if (value is CName cName) { return((string)cName); } if (value is CFloat cFloat) { return((float)cFloat); } if (value is Vector4 vec) { return(new Dictionary <string, float> { { nameof(vec.X), vec.X }, { nameof(vec.Y), vec.Y }, { nameof(vec.Z), vec.Z }, { nameof(vec.W), vec.W }, }); } if (value is IRedResourceReference rRef) { return((string)rRef.DepotPath); } throw new NotImplementedException(value.GetType().Name); }
public ChunkPropertyViewModel(IRedType prop) { Property = prop; //IsSerialized = prop.IsSerialized; //_ = Property.ChildrEditableVariables // .AsObservableChangeSet() // .Transform(GetViewModel) // .ObserveOn(RxApp.MainThreadScheduler) // .Bind(out _children) // .Subscribe(); PreviewTextInputCommand = ReactiveCommand.Create( () => { //if (!Property.IsSerialized) //{ // Property.IsSerialized = true; // IsSerialized = true; // this.RaisePropertyChanged(nameof(IsSerialized)); //} }); //this.WhenAnyValue(x => x.IsSerialized).Subscribe(b => //{ // if (prop.IsSerialized != b) // { // prop.IsSerialized = b; // IsSerialized = b; // this.RaisePropertyChanged(nameof(IsSerialized)); // } //}); //Property.PropertyChanged += OnPropertyChanged; }
public RedTypeDto(IRedType cls) { Data = cls; }
public CurveEditorWindow(IRedType property) { InitializeComponent(); if (property is not IRedLegacySingleChannelCurve model) { return; } _model = model; _elementType = model.ElementType; var points = model.GetCurvePoints().ToArray(); var times = points.Select(x => (double)x.GetPoint()).ToArray(); var values = points.Select(x => x.GetValue()).ToArray(); var type = model.InterpolationType; switch (_elementType) { case "HDRColor": { var colors = values.OfType <HDRColor>().ToList(); var blue = colors.Select(x => (double)x.Blue).ToArray(); var red = colors.Select(x => (double)x.Red).ToArray(); var green = colors.Select(x => (double)x.Green).ToArray(); var alpha = colors.Select(x => (double)x.Alpha).ToArray(); if (DataContext is CurveEditorViewModel vm) { vm.LoadCurve(times, alpha, type); } break; } case "Float": { var floats = values.OfType <CFloat>().ToList(); var ys = floats.Select(x => (double)x).ToArray(); if (DataContext is CurveEditorViewModel vm) { vm.LoadCurve(times, ys, type); } break; } //case "Vector2": //{ // var floats = values.OfType<Vector2>().ToList(); // var xs = floats.Select(x => (double)x.X).ToArray(); // var ys = floats.Select(x => (double)x.Y).ToArray(); // // // break; //} //case "Vector3": //{ // var floats = values.OfType<Vector3>().ToList(); // var xs = floats.Select(x => (double)x.X).ToArray(); // var ys = floats.Select(x => (double)x.Y).ToArray(); // var zs = floats.Select(x => (double)x.Z).ToArray(); // // // break; //} //case "Vector4": //{ // var floats = values.OfType<Vector4>().ToList(); // var xs = floats.Select(x => (double)x.X).ToArray(); // var ys = floats.Select(x => (double)x.Y).ToArray(); // var zs = floats.Select(x => (double)x.Z).ToArray(); // var ws = floats.Select(x => (double)x.W).ToArray(); // // // break; //} default: { throw new NotImplementedException($"CurveEditor: {_elementType}"); } } }
private DataTemplate GetTemplate(IRedType variable) => variable switch {
internal FindResult(string path, IRedType value) { Path = path; Value = value; }
public void SetValue(RedBaseClass instance, IRedType value) { instance.InternalForceSetPropertyValue(RedName, value, true); instance._writtenProperties.Add(RedName); }
public CKeyValuePair(CName key, IRedType value) { Key = key; Value = value; }
public void WriteWidgetAttributes(XmlWriter writer, IRedType value, string property = "") { if (property != "") { property += "."; } var childSets = new List <IRedType>(); var pis = RedReflection.GetTypeInfo(value.GetType()).PropertyInfos; pis.Sort((a, b) => a.Name.CompareTo(b.Name)); pis.ForEach((pi) => { IRedType propertyValue; if (pi.RedName == null) { propertyValue = (IRedType)value.GetType().GetProperty(pi.Name).GetValue(value, null); } else { propertyValue = (IRedType)pi.GetValue((RedBaseClass)value); } var redType = RedReflection.GetRedTypeFromCSType(pi.Type); if (!RedReflection.IsDefault(value.GetType(), pi, propertyValue)) { var propertyName = pi.RedName; switch (propertyName) { case "children": case "backendData": case "parentWidget": return; default: break; } switch (propertyValue) { case IRedBaseHandle handle: var resolvedValue = handle.GetValue(); if (resolvedValue is inkWidget widget) { writer.WriteAttributeString(property + propertyName + "Path", widget.GetPath()); } else { WriteWidgetAttributes(writer, resolvedValue, property + propertyName); } break; case inkWidgetReference inkRef: if (inkRef.Widget != null && inkRef.Widget.GetValue() is inkWidget widgetRef) { writer.WriteAttributeString(property + propertyName, widgetRef.GetPath()); } break; case CArray <CHandle <inkIEffect> > : case CArray <CHandle <inkWidgetLogicController> > : case CArray <CHandle <inkUserData> > : childSets.Add(propertyValue); break; case CArray <inkPropertyBinding> ary: //writer.WriteStartElement("bindings"); foreach (var ipb in ary) { //writer.WriteStartElement("propertyBinding"); writer.WriteAttributeString(ipb.PropertyName + ".binding", ipb.StylePath); //writer.WriteEndElement(); } //writer.WriteEndElement(); break; case inkMargin margin: writer.WriteAttributeString(property + propertyName, margin.Left + "," + margin.Top + "," + margin.Right + "," + margin.Bottom); break; case inkUITransform: case inkWidgetLayout: case textWrappingInfo: WriteWidgetAttributes(writer, propertyValue, property + propertyName); break; case LocalizationString lockey: writer.WriteAttributeString(property + propertyName, lockey.Value.ToString()); break; case HDRColor color: writer.WriteAttributeString(property + propertyName, $"color(srgb {color.Red} {color.Green} {color.Blue} / {color.Alpha})"); //writer.WriteAttributeString(property + propertyName + ".Red", color.Red.ToString()); //writer.WriteAttributeString(property + propertyName + ".Green", color.Green.ToString()); //writer.WriteAttributeString(property + propertyName + ".Blue", color.Blue.ToString()); //writer.WriteAttributeString(property + propertyName + ".Alpha", color.Alpha.ToString()); break; case Vector2 vector2: writer.WriteAttributeString(property + propertyName, $"{vector2.X},{vector2.Y}"); //writer.WriteAttributeString(property + propertyName + ".X", vector2.X.ToString()); //writer.WriteAttributeString(property + propertyName + ".Y", vector2.Y.ToString()); break; default: writer.WriteAttributeString(property + propertyName, propertyValue.ToString()); break; } } }); foreach (var childSet in childSets) { switch (childSet) { case CArray <CHandle <inkIEffect> > effects: writer.WriteStartElement("effects"); foreach (var handle in effects) { var effect = handle.GetValue(); if (effect != null) { writer.WriteStartElement(effect.GetType().Name); WriteWidgetAttributes(writer, effect); writer.WriteEndElement(); } } writer.WriteEndElement(); break; case CArray <CHandle <inkWidgetLogicController> > controllers: writer.WriteStartElement("secondaryControllers"); foreach (var handle in controllers) { var controller = handle.GetValue(); if (controller != null) { writer.WriteStartElement(controller.GetType().Name); WriteWidgetAttributes(writer, controller); writer.WriteEndElement(); } } writer.WriteEndElement(); break; case CArray <CHandle <inkUserData> > ary: writer.WriteStartElement("userData"); foreach (var handle in ary) { var item = handle.GetValue(); if (item != null) { writer.WriteStartElement(item.GetType().Name); WriteWidgetAttributes(writer, item); writer.WriteEndElement(); } } writer.WriteEndElement(); break; } } }
//public string Name => Property.REDName; //public string Type => Property.REDType; //public string Value => Property.REDValue; //[Reactive] public bool IsSerialized { get; set; } //private readonly ReadOnlyObservableCollection<ChunkPropertyViewModel> _children; //public ReadOnlyObservableCollection<ChunkPropertyViewModel> Children => _children; //public System.Windows.Media.Brush ForegroundColor => Property.IsSerialized // ? System.Windows.Media.Brushes.Green // : System.Windows.Media.Brushes.Azure; #endregion Properties private static ChunkPropertyViewModel GetViewModel(IRedType editableVariable) => editableVariable switch {