/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(MemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; if (!IsReadOnly && info is FieldInfo fieldInfo && fieldInfo.IsInitOnly) { // Field declared with `readonly` keyword IsReadOnly = true; } if (!IsReadOnly && info is PropertyInfo propertyInfo && !propertyInfo.CanWrite) { // Property without a setter IsReadOnly = true; } if (Display?.Name != null) { // Use name provided by the attribute DisplayName = Display.Name; } else { // Use filtered member name DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name); } }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(MemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; if (Display?.Name != null) { // Use name provided by the attribute DisplayName = Display.Name; } else { // Use filtered member name DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name); } }
public override void Initialize(LayoutElementsContainer layout) { var proxy = (BuildTabProxy)Values[0]; _platform = proxy.Selector.Selected; var platformObj = proxy.PerPlatformOptions[_platform]; if (!platformObj.IsSupported) { layout.Label("This platform is not supported on this system.", TextAlignment.Center); } else if (platformObj.IsAvailable) { string name; switch (_platform) { case PlatformType.Windows: name = "Windows"; break; case PlatformType.XboxOne: name = "Xbox One"; break; case PlatformType.UWP: name = "Windows Store"; break; case PlatformType.Linux: name = "Linux"; break; case PlatformType.PS4: name = "PlayStation 4"; break; case PlatformType.XboxScarlett: name = "Xbox Scarlett"; break; case PlatformType.Android: name = "Android"; break; default: name = CustomEditorsUtil.GetPropertyNameUI(_platform.ToString()); break; } var group = layout.Group(name); group.Object(new ReadOnlyValueContainer(platformObj)); _buildButton = layout.Button("Build").Button; _buildButton.Clicked += OnBuildClicked; } else { platformObj.OnNotAvailableLayout(layout); } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { _scripts.Clear(); // Area for drag&drop scripts var dragArea = layout.Custom <DragAreaControl>(); dragArea.CustomControl.ScriptsEditor = this; // No support to show scripts for more than one actor selected if (Values.Count != 1) { return; } // Scripts var scripts = (Script[])Values[0]; _scripts.AddRange(scripts); var elementType = typeof(Script); for (int i = 0; i < scripts.Length; i++) { var script = scripts[i]; if (script == null) { layout.Group("Missing script"); continue; } var values = new ListValueContainer(elementType, i, Values); var type = script.GetType(); var editor = CustomEditorsUtil.CreateEditor(type, false); // Create group var title = CustomEditorsUtil.GetPropertyNameUI(type.Name); var group = layout.Group(title); group.Panel.Open(false); // Add settings button to the group const float settingsButtonSize = 14; var settingsButton = new Image(group.Panel.Width - settingsButtonSize, 0, settingsButtonSize, settingsButtonSize) { CanFocus = true, AnchorStyle = AnchorStyle.UpperRight, IsScrollable = false, Color = new Color(0.7f), Margin = new Margin(1), ImageSource = new SpriteImageSource(FlaxEngine.GUI.Style.Current.Settings), Tag = script, Parent = group.Panel }; settingsButton.Clicked += SettingsButtonOnClicked; group.Object(values, editor); } base.Initialize(layout); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var options = (IList <Type>)Presenter.Panel.Tag; _options = new OptionType[options.Count]; for (int i = 0; i < options.Count; i++) { var type = options[i]; _options[i] = new OptionType(CustomEditorsUtil.GetPropertyNameUI(type.Name), type, Creator); } base.Initialize(layout); }
public override void Initialize(LayoutElementsContainer layout) { var proxy = (BuildTabProxy)Values[0]; _platform = proxy.Selector.Selected; var platformObj = proxy.PerPlatformOptions[_platform]; var group = layout.Group(CustomEditorsUtil.GetPropertyNameUI(_platform.ToString())); group.Object(new ReadOnlyValueContainer(platformObj)); _buildButton = layout.Button("Build").Button; _buildButton.Clicked += OnBuildClicked; }
/// <inheritdoc /> protected override void OnShowAddContextMenu(ContextMenu.ContextMenu menu) { base.OnShowAddContextMenu(menu); OnSelectActorContextMenu(menu); var actor = Actor; if (actor == null) { return; } var type = actor.GetType(); menu.AddSeparator(); // Properties and events if (AddProperties(this, menu, type) != 0) { menu.AddSeparator(); } if (AddEvents(this, menu, type) != 0) { menu.AddSeparator(); } // Child scripts var scripts = actor.Scripts; for (int i = 0; i < scripts.Length; i++) { var script = scripts[i]; // Skip invalid or hidden scripts if (script == null || script.GetType().GetCustomAttributes(true).Any(x => x is HideInEditorAttribute)) { continue; } // Prevent from adding the same track twice if (SubTracks.Any(x => x is IObjectTrack y && y.Object == script)) { continue; } var name = CustomEditorsUtil.GetPropertyNameUI(script.GetType().Name); menu.AddButton(name, OnAddScriptTrack).Tag = script; } }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); }
public override void Initialize(LayoutElementsContainer layout) { var proxy = (BuildTabProxy)Values[0]; _platform = proxy.Selector.Selected; var platformObj = proxy.PerPlatformOptions[_platform]; if (platformObj.IsAvailable) { string name; switch (_platform) { case PlatformType.Windows: name = "Windows"; break; case PlatformType.XboxOne: name = "Xbox One"; break; case PlatformType.WindowsStore: name = "Windows Store"; break; case PlatformType.Linux: name = "Linux"; break; default: name = CustomEditorsUtil.GetPropertyNameUI(_platform.ToString()); break; } var group = layout.Group(name); group.Object(new ReadOnlyValueContainer(platformObj)); _buildButton = layout.Button("Build").Button; _buildButton.Clicked += OnBuildClicked; } else { platformObj.OnNotAvailableLayout(layout); } }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); var editor = Editor.Instance; TooltipText = editor.CodeDocs.GetTooltip(info, attributes); _membersOrder = editor.Options.Options.General.ScriptMembersOrder; }
private TreeNode CreateDiffNode(CustomEditor editor) { var node = new TreeNode(false) { Tag = editor }; // Removed Script if (editor is RemovedScriptDummy removed) { node.TextColor = Color.OrangeRed; node.Text = CustomEditorsUtil.GetPropertyNameUI(removed.PrefabObject.GetType().Name); } // Actor or Script else if (editor.Values[0] is ISceneObject sceneObject) { node.TextColor = sceneObject.HasPrefabLink ? FlaxEngine.GUI.Style.Current.ProgressNormal : FlaxEngine.GUI.Style.Current.BackgroundSelected; node.Text = CustomEditorsUtil.GetPropertyNameUI(sceneObject.GetType().Name); } // Array Item else if (editor.ParentEditor?.Values?.Type.IsArray ?? false) { node.Text = "Element " + editor.ParentEditor.ChildrenEditors.IndexOf(editor); } // Common type else if (editor.Values.Info != ScriptMemberInfo.Null) { node.Text = CustomEditorsUtil.GetPropertyNameUI(editor.Values.Info.Name); } // Custom type else if (editor.Values[0] != null) { node.Text = editor.Values[0].ToString(); } node.Expand(true); return(node); }
/// <summary> /// Creates new Combo Box element description for enum editing. /// </summary> /// <param name="x">The x location (in node area space).</param> /// <param name="y">The y location (in node area space).</param> /// <param name="width">The width of the element.</param> /// <param name="valueIndex">The index of the node variable linked as the input. Useful to make a physical connection between input box and default value for it.</param> /// <param name="enumType">The enum type to present all it's values. Important: first value should be 0 and so on.</param> /// <returns>The archetype.</returns> public static NodeElementArchetype ComboBox(float x, float y, int width, int valueIndex, Type enumType) { if (enumType == null || !enumType.IsEnum) { throw new ArgumentException(); } FieldInfo[] fields = enumType.GetFields(); List <string> values = new List <string>(fields.Length); for (int i = 0; i < fields.Length; i++) { var field = fields[i]; if (field.Name.Equals("value__")) { continue; } var name = CustomEditorsUtil.GetPropertyNameUI(field.Name); values.Add(name); } return(ComboBox(x, y, width, valueIndex, values.ToArray())); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { _scripts.Clear(); // Area for drag&drop scripts var dragArea = layout.CustomContainer <DragAreaControl>(); dragArea.CustomControl.ScriptsEditor = this; // No support to show scripts for more than one actor selected // TODO: support showing scripts from objects that has the same scripts layout if (Values.Count != 1) { return; } // Scripts arrange bar var dragBar = layout.Custom <ScriptArrangeBar>(); dragBar.CustomControl.Init(0, this); // Scripts var scripts = (Script[])Values[0]; _scripts.AddRange(scripts); var elementType = typeof(Script); for (int i = 0; i < scripts.Length; i++) { var script = scripts[i]; if (script == null) { AddMissingScript(i, layout); continue; } var values = new ListValueContainer(elementType, i, Values); var type = script.GetType(); var editor = CustomEditorsUtil.CreateEditor(type, false); // Create group var title = CustomEditorsUtil.GetPropertyNameUI(type.Name); var group = layout.Group(title); group.Panel.Open(false); // Customize var typeAttributes = type.GetCustomAttributes(true); var tooltip = (TooltipAttribute)typeAttributes.FirstOrDefault(x => x is TooltipAttribute); if (tooltip != null) { group.Panel.TooltipText = tooltip.Text; } // Add toggle button to the group var scriptToggle = new CheckBox(2, 0, script.Enabled) { TooltipText = "If checked, script will be enabled", IsScrollable = false, Size = new Vector2(14, 14), BoxSize = 12.0f, Tag = script, Parent = group.Panel }; scriptToggle.StateChanged += ScriptToggleOnCheckChanged; // Add drag button to the group const float dragIconSize = 14; var scriptDrag = new ScriptDragIcon(this, script, scriptToggle.Right, 0.5f, dragIconSize) { TooltipText = "Script reference", CanFocus = true, IsScrollable = false, Color = new Color(0.7f), Margin = new Margin(1), ImageSource = new SpriteImageSource(Editor.Instance.UI.DragBar12), Tag = script, Parent = group.Panel }; // Add settings button to the group const float settingsButtonSize = 14; var settingsButton = new Image(group.Panel.Width - settingsButtonSize, 0, settingsButtonSize, settingsButtonSize) { TooltipText = "Settings", CanFocus = true, AnchorStyle = AnchorStyle.UpperRight, IsScrollable = false, Color = new Color(0.7f), Margin = new Margin(1), ImageSource = new SpriteImageSource(FlaxEngine.GUI.Style.Current.Settings), Tag = script, Parent = group.Panel }; settingsButton.Clicked += SettingsButtonOnClicked; group.Panel.HeaderTextMargin = new Margin(scriptDrag.Right, 15, 2, 2); group.Object(values, editor); // Scripts arrange bar dragBar = layout.Custom <ScriptArrangeBar>(); dragBar.CustomControl.Init(i + 1, this); } base.Initialize(layout); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { // Area for drag&drop scripts var dragArea = layout.CustomContainer <DragAreaControl>(); dragArea.CustomControl.ScriptsEditor = this; // No support for showing scripts from multiple actors that have different set of scripts var scripts = (Script[])Values[0]; _scripts.Clear(); _scripts.AddRange(scripts); for (int i = 1; i < Values.Count; i++) { var e = (Script[])Values[i]; if (scripts.Length != e.Length) { return; } for (int j = 0; j < e.Length; j++) { var t1 = scripts[j]?.TypeName; var t2 = e[j]?.TypeName; if (t1 != t2) { return; } } } // Scripts arrange bar var dragBar = layout.Custom <ScriptArrangeBar>(); dragBar.CustomControl.Init(0, this); // Scripts var elementType = new ScriptType(typeof(Script)); _scriptToggles = new CheckBox[scripts.Length]; for (int i = 0; i < scripts.Length; i++) { var script = scripts[i]; if (script == null) { AddMissingScript(i, layout); continue; } var values = new ScriptsContainer(elementType, i, Values); var scriptType = TypeUtils.GetObjectType(script); var editor = CustomEditorsUtil.CreateEditor(scriptType, false); // Create group var title = CustomEditorsUtil.GetPropertyNameUI(scriptType.Name); var group = layout.Group(title); if (Presenter.CacheExpandedGroups) { if (Editor.Instance.ProjectCache.IsCollapsedGroup(title)) { group.Panel.Close(false); } else { group.Panel.Open(false); } group.Panel.IsClosedChanged += panel => Editor.Instance.ProjectCache.SetCollapsedGroup(panel.HeaderText, panel.IsClosed); } else { group.Panel.Open(false); } // Customize var typeAttributes = scriptType.GetAttributes(true); var tooltip = (TooltipAttribute)typeAttributes.FirstOrDefault(x => x is TooltipAttribute); if (tooltip != null) { group.Panel.TooltipText = tooltip.Text; } if (script.HasPrefabLink) { group.Panel.HeaderTextColor = FlaxEngine.GUI.Style.Current.ProgressNormal; } // Add toggle button to the group var scriptToggle = new CheckBox { TooltipText = "If checked, script will be enabled.", IsScrollable = false, Checked = script.Enabled, Parent = group.Panel, Size = new Vector2(14, 14), Bounds = new Rectangle(2, 0, 14, 14), BoxSize = 12.0f, Tag = script, }; scriptToggle.StateChanged += OnScriptToggleCheckChanged; _scriptToggles[i] = scriptToggle; // Add drag button to the group const float dragIconSize = 14; var scriptDrag = new ScriptDragIcon(this, script) { TooltipText = "Script reference", AutoFocus = true, IsScrollable = false, Color = FlaxEngine.GUI.Style.Current.ForegroundGrey, Parent = group.Panel, Bounds = new Rectangle(scriptToggle.Right, 0.5f, dragIconSize, dragIconSize), Margin = new Margin(1), Brush = new SpriteBrush(Editor.Instance.Icons.DragBar12), Tag = script, }; // Add settings button to the group const float settingsButtonSize = 14; var settingsButton = new Image { TooltipText = "Settings", AutoFocus = true, AnchorPreset = AnchorPresets.TopRight, Parent = group.Panel, Bounds = new Rectangle(group.Panel.Width - settingsButtonSize, 0, settingsButtonSize, settingsButtonSize), IsScrollable = false, Color = FlaxEngine.GUI.Style.Current.ForegroundGrey, Margin = new Margin(1), Brush = new SpriteBrush(FlaxEngine.GUI.Style.Current.Settings), Tag = script, }; settingsButton.Clicked += OnSettingsButtonClicked; group.Panel.HeaderTextMargin = new Margin(scriptDrag.Right, 15, 2, 2); group.Object(values, editor); // Scripts arrange bar dragBar = layout.Custom <ScriptArrangeBar>(); dragBar.CustomControl.Init(i + 1, this); } base.Initialize(layout); }