// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using System.Linq; using FlaxEditor.CustomEditors.Elements; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.CustomEditors.Editors { /// /// Default implementation of the inspector used to edit Int3 value type properties. /// [CustomEditor(typeof(Int3)), DefaultEditor] public class Int3Editor : CustomEditor { /// /// The X component editor. /// protected IntegerValueElement XElement; /// /// The Y component editor. /// protected IntegerValueElement YElement; /// /// The Z component editor. /// protected IntegerValueElement ZElement; /// public override DisplayStyle Style => DisplayStyle.Inline; /// public override void Initialize(LayoutElementsContainer layout) { var grid = layout.CustomContainer(); var gridControl = grid.CustomControl; gridControl.ClipChildren = false; gridControl.Height = TextBox.DefaultHeight; gridControl.SlotsHorizontally = 3; gridControl.SlotsVertically = 1; LimitAttribute limit = null; var attributes = Values.GetAttributes(); if (attributes != null) { limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute); } XElement = grid.IntegerValue(); XElement.SetLimits(limit); XElement.IntValue.ValueChanged += OnValueChanged; XElement.IntValue.SlidingEnd += ClearToken; YElement = grid.IntegerValue(); YElement.SetLimits(limit); YElement.IntValue.ValueChanged += OnValueChanged; YElement.IntValue.SlidingEnd += ClearToken; ZElement = grid.IntegerValue(); ZElement.SetLimits(limit); ZElement.IntValue.ValueChanged += OnValueChanged; ZElement.IntValue.SlidingEnd += ClearToken; } private void OnValueChanged() { if (IsSetBlocked) return; var isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding; var token = isSliding ? this : null; var value = new Int3( XElement.IntValue.Value, YElement.IntValue.Value, ZElement.IntValue.Value); SetValue(value, token); } /// public override void Refresh() { base.Refresh(); if (HasDifferentValues) { // TODO: support different values for ValueBox } else { var value = (Int3)Values[0]; XElement.IntValue.Value = value.X; YElement.IntValue.Value = value.Y; ZElement.IntValue.Value = value.Z; } } } }