/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { // Get the target options _options = Options; if (_options == null) { throw new ArgumentNullException(); } int selectedIndex = -1; bool hasDifferentTypes = Values.HasDifferentTypes; var type = Type; _type = type; // Type var typeEditor = layout.ComboBox("Type", "Type of the object value. Use it to change the object."); for (int i = 0; i < _options.Length; i++) { typeEditor.ComboBox.AddItem(_options[i].Name); selectedIndex = _options[i].Type == type ? i : selectedIndex; } typeEditor.ComboBox.SupportMultiSelect = false; typeEditor.ComboBox.SelectedIndex = hasDifferentTypes ? -1 : selectedIndex; typeEditor.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged; // Editing different types is not supported if (Values.HasDifferentTypes) { var property = layout.AddPropertyItem("Value"); property.Label("Different Values"); return; } // Nothing to edit if (Values.HasNull) { var property = layout.AddPropertyItem("Value"); property.Label("<null>"); return; } // Value var values = new CustomValueContainer(type, (instance, index) => instance, (instance, index, value) => { }); values.AddRange(Values); var editor = CustomEditorsUtil.CreateEditor(type); layout.Property("Value", values, editor); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { // Set control type button var space = layout.Space(20); float setTypeButtonWidth = 60.0f; var setTypeButton = new Button((layout.ContainerControl.Width - setTypeButtonWidth) / 2, 1, setTypeButtonWidth, 18) { TooltipText = "Sets the control to the given type", AnchorStyle = AnchorStyle.UpperCenter, Text = "Set Type", Parent = space.Spacer }; setTypeButton.ButtonClicked += OnSetTypeButtonClicked; // Don't show editor if any control is invalid if (Values.HasNull) { var label = layout.Label("Select control type to create", TextAlignment.Center); label.Label.Enabled = false; return; } // Add control type helper label { var type = Values[0].GetType(); var label = layout.AddPropertyItem("Type", "The type of the created control."); label.Label(type.FullName); } // Show control properties base.Initialize(layout); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { // Atlas var atlasField = typeof(Sprite).GetField("Atlas"); var atlasValues = new ValueContainer(atlasField, Values); layout.Property("Atlas", atlasValues, null, "The target atlas texture used as a sprite image source."); _atlasValues = atlasValues; // Sprite var spriteIndexField = typeof(Sprite).GetField("Index"); _indexValues = new ValueContainer(spriteIndexField, Values); var spriteLabel = layout.AddPropertyItem("Sprite", "The selected sprite from the atlas."); // Check state if (atlasValues.HasDifferentValues) { spriteLabel.Label("Different values"); return; } var value = (SpriteAtlas)atlasValues[0]; if (value == null) { spriteLabel.Label("Pick atlas first"); return; } // TODO: don't stall use Refresh to rebuild UI when sprite atlas gets loaded if (value.WaitForLoaded()) { return; } // List all sprites from the atlas asset var spritesCount = value.SpritesCount; var spritePicker = spriteLabel.ComboBox(); spritePicker.ComboBox.Items.Capacity = spritesCount; for (int i = 0; i < spritesCount; i++) { spritePicker.ComboBox.AddItem(value.GetSprite(i).Name); } spritePicker.ComboBox.SupportMultiSelect = false; spritePicker.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged; _spritePicker = spritePicker.ComboBox; }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var layers = LayersAndTagsSettings.GetCurrentLayers(); if (layers == null || layers.Length == 0) { layout.Label("Missing layers and tags settings"); return; } _checkBoxes = new CheckBox[layers.Length]; for (int i = 0; i < layers.Length; i++) { var layer = layers[i]; var property = layout.AddPropertyItem(layer); var checkbox = property.Checkbox().CheckBox; UpdateCheckbox(checkbox, i); checkbox.Tag = i; checkbox.StateChanged += OnCheckboxStateChanged; _checkBoxes[i] = checkbox; } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var settings = GameSettings.Load <NavigationSettings>(); if (settings.NavMeshes == null || settings.NavMeshes.Length == 0) { layout.Label("Missing navmesh settings"); return; } _checkBoxes = new CheckBox[settings.NavMeshes.Length]; for (int i = 0; i < settings.NavMeshes.Length; i++) { ref var navmesh = ref settings.NavMeshes[i]; var property = layout.AddPropertyItem(navmesh.Name, navmesh.Agent.ToString()); property.Labels.Last().TextColorHighlighted = navmesh.Color; var checkbox = property.Checkbox().CheckBox; UpdateCheckbox(checkbox, i); checkbox.Tag = i; checkbox.StateChanged += OnCheckboxStateChanged; _checkBoxes[i] = checkbox; }
/// <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); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { // Get the target options _options = Options; if (_options == null) { throw new ArgumentNullException(); } int selectedIndex = -1; bool hasDifferentTypes = Values.HasDifferentTypes; var type = Type; _type = type; // Type var typeEditor = layout.ComboBox(TypeComboBoxName, "Type of the object value. Use it to change the object."); for (int i = 0; i < _options.Length; i++) { typeEditor.ComboBox.AddItem(_options[i].Name); selectedIndex = _options[i].Type == type.Type ? i : selectedIndex; } typeEditor.ComboBox.SupportMultiSelect = false; typeEditor.ComboBox.SelectedIndex = hasDifferentTypes ? -1 : selectedIndex; typeEditor.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged; // Editing different types is not supported if (Values.HasDifferentTypes) { var property = layout.AddPropertyItem("Value"); property.Label("Different Values"); return; } // Nothing to edit if (Values.HasNull) { var property = layout.AddPropertyItem("Value"); property.Label("<null>"); return; } // Value var values = new CustomValueContainer(type, (instance, index) => instance, (instance, index, value) => { }); values.AddRange(Values); var editor = CustomEditorsUtil.CreateEditor(type); var style = editor.Style; if (style == DisplayStyle.InlineIntoParent) { layout.Object(values, editor); } else if (style == DisplayStyle.Group) { var group = layout.Group("Value", true); group.Panel.Open(false); group.Object(values, editor); // Remove empty group if (group.ContainerControl.ChildrenCount == 0) { layout.Children.Remove(group); group.Panel.Dispose(); } } else { layout.AddPropertyItem("Value").Object(values, editor); } }