/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { if (HasDifferentTypes) { // No support for different enum types } else { element = layout.Enum(Values[0].GetType()); element.ValueChanged += OnValueChanged; } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var mode = EnumDisplayAttribute.FormatMode.Default; var attributes = Values.GetAttributes(); if (attributes?.FirstOrDefault(x => x is EnumDisplayAttribute) is EnumDisplayAttribute enumDisplay) { mode = enumDisplay.Mode; } if (HasDifferentTypes) { // No support for different enum types } else { element = layout.Enum(Values[0].GetType(), null, mode); element.ValueChanged += OnValueChanged; } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var mode = EnumDisplayAttribute.FormatMode.Default; var attributes = Values.GetAttributes(); if (attributes?.FirstOrDefault(x => x is EnumDisplayAttribute) is EnumDisplayAttribute enumDisplay) { mode = enumDisplay.Mode; } if (HasDifferentTypes) { // No support for different enum types } else { var enumType = Values.Type.Type != typeof(object) || Values[0] == null?TypeUtils.GetType(Values.Type) : Values[0].GetType(); element = layout.Enum(enumType, null, mode); element.ComboBox.ValueChanged += OnValueChanged; } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var window = Values[0] as VisjectSurfaceWindow <TAsset, TSurface, TPreview>; var asset = window?.Asset; if (asset == null) { layout.Label("No parameters"); return; } if (!asset.IsLoaded) { layout.Label("Loading..."); return; } var parameters = window.Surface.Parameters; for (int i = 0; i < parameters.Count; i++) { var p = parameters[i]; if (!p.IsPublic) { continue; } var pIndex = i; var pValue = p.Value; Type pType; object[] attributes = null; switch (p.Type) { case ParameterType.CubeTexture: pType = typeof(CubeTexture); break; case ParameterType.Texture: case ParameterType.NormalMap: pType = typeof(Texture); break; case ParameterType.RenderTarget: case ParameterType.RenderTargetArray: case ParameterType.RenderTargetCube: case ParameterType.RenderTargetVolume: pType = typeof(RenderTarget); break; default: pType = p.Value.GetType(); // TODO: support custom attributes with defined value range for parameter (min, max) attributes = DefaultAttributes; break; } var propertyValue = new CustomValueContainer ( pType, pValue, (instance, index) => ((VisjectSurfaceWindow <TAsset, TSurface, TPreview>)instance).GetParameter(pIndex), (instance, index, value) => ((VisjectSurfaceWindow <TAsset, TSurface, TPreview>)instance).SetParameter(pIndex, value), attributes ); var propertyLabel = new DragablePropertyNameLabel(p.Name) { Tag = pIndex, Drag = DragParameter }; propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label); propertyLabel.MouseRightClick += (label, location) => ShowParameterMenu(pIndex, label, ref location); var property = layout.AddPropertyItem(propertyLabel); property.Object(propertyValue); } // Parameters creating var newParameterTypes = window.NewParameterTypes; if (newParameterTypes != null) { if (parameters.Count > 0) { layout.Space(10); } var paramType = layout.Enum(newParameterTypes); paramType.Value = (int)ParameterType.Float; var newParam = layout.Button("Add parameter"); newParam.Button.Clicked += () => AddParameter((ParameterType)paramType.Value); } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var materialWin = Values[0] as MaterialWindow; var material = materialWin?.Asset; if (material == null) { _parametersHash = -1; layout.Label("No parameters"); return; } if (!material.IsLoaded) { _parametersHash = -2; layout.Label("Loading..."); return; } _parametersHash = material._parametersHash; var parameters = material.Parameters; for (int i = 0; i < parameters.Length; i++) { var p = parameters[i]; if (!p.IsPublic) { continue; } var pIndex = i; var pValue = p.Value; var pGuidType = false; Type pType; switch (p.Type) { case MaterialParameterType.CubeTexture: pType = typeof(CubeTexture); pGuidType = true; break; case MaterialParameterType.Texture: case MaterialParameterType.NormalMap: pType = typeof(Texture); pGuidType = true; break; case MaterialParameterType.RenderTarget: pType = typeof(RenderTarget); pGuidType = true; break; default: pType = p.Value.GetType(); break; } var propertyValue = new CustomValueContainer( pType, pValue, (instance, index) => { // Get material parameter var win = (MaterialWindow)instance; return(win.Asset.Parameters[pIndex].Value); }, (instance, index, value) => { // Set material parameter and surface parameter var win = (MaterialWindow)instance; // Visject surface paramaters are only value type objects so convert value if need to (eg. instead of texture ref write texture id) var surfaceParam = value; if (pGuidType) { surfaceParam = (value as FlaxEngine.Object)?.ID ?? Guid.Empty; } win.Asset.Parameters[pIndex].Value = value; win.Surface.Parameters[pIndex].Value = surfaceParam; win._paramValueChange = true; } ); var propertyLabel = new DragablePropertyNameLabel(p.Name); propertyLabel.Tag = pIndex; propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label); propertyLabel.MouseRightClick += (label, location) => ShowParameterMenu(pIndex, label, ref location); propertyLabel.Drag = DragParameter; var property = layout.AddPropertyItem(propertyLabel); property.Object(propertyValue); } if (parameters.Length > 0) { layout.Space(10); } // Parameters creating var paramType = layout.Enum(typeof(NewParameterType)); paramType.Value = (int)NewParameterType.Float; var newParam = layout.Button("Add parameter"); newParam.Button.Clicked += () => AddParameter((ParameterType)paramType.Value); }