Add scale lock button

This commit is contained in:
Chandler Cox
2023-02-04 21:56:18 -06:00
parent d8a9b699ad
commit 9c591b3c08
2 changed files with 133 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEditor.CustomEditors.GUI;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors.Editors
{
@@ -87,10 +89,54 @@ namespace FlaxEditor.CustomEditors.Editors
var grayOutFactor = 0.6f;
XElement.ValueBox.BorderColor = Color.Lerp(AxisColorX, back, grayOutFactor);
XElement.ValueBox.BorderSelectedColor = AxisColorX;
if (XElement.ValueBox.Parent.Parent is PropertiesList list)
{
foreach (var child in list.Children)
{
if (!(child is PropertyNameLabel))
continue;
var nameLabel = child as PropertyNameLabel;
if (!string.Equals(nameLabel.Text, "Scale"))
continue;
var lockButton = new Button
{
Parent = nameLabel,
Width = 18,
Height = 18,
BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Link32),
BackgroundColor = Color.White,
BorderColor = Color.Transparent,
BorderColorSelected = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
AnchorPreset = AnchorPresets.TopLeft,
TooltipText = "Locks/Unlocks setting the scale values.",
};
lockButton.LocalX += 40;
lockButton.LocalY += 1;
lockButton.Clicked += () =>
{
ChangeValuesTogether = !ChangeValuesTogether;
// TODO: change image
Debug.Log(ChangeValuesTogether);
};
break;
}
}
YElement.ValueBox.BorderColor = Color.Lerp(AxisColorY, back, grayOutFactor);
YElement.ValueBox.BorderSelectedColor = AxisColorY;
ZElement.ValueBox.BorderColor = Color.Lerp(AxisColorZ, back, grayOutFactor);
ZElement.ValueBox.BorderSelectedColor = AxisColorZ;
Debug.Log(YElement.ValueBox.Parent);
Debug.Log(YElement.ValueBox.Parent.Parent);
Debug.Log(YElement.ValueBox.Parent.Parent.Parent);
Debug.Log(YElement.ValueBox.Parent.Parent.Parent.Parent);
Debug.Log(YElement.ValueBox.Parent.Parent.Parent.Parent.Parent);
}
}
}

View File

@@ -44,6 +44,14 @@ namespace FlaxEditor.CustomEditors.Editors
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.Inline;
/// <summary>
/// If true, when one value is changed, the other 2 will change as well.
/// </summary>
protected bool ChangeValuesTogether = false;
private bool _xChanged;
private bool _yChanged;
private bool _zChanged;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
@@ -63,28 +71,96 @@ namespace FlaxEditor.CustomEditors.Editors
XElement = grid.FloatValue();
XElement.SetLimits(limit);
XElement.ValueBox.ValueChanged += OnValueChanged;
XElement.ValueBox.ValueChanged += OnXValueChanged;
XElement.ValueBox.SlidingEnd += ClearToken;
YElement = grid.FloatValue();
YElement.SetLimits(limit);
YElement.ValueBox.ValueChanged += OnValueChanged;
YElement.ValueBox.ValueChanged += OnYValueChanged;
YElement.ValueBox.SlidingEnd += ClearToken;
ZElement = grid.FloatValue();
ZElement.SetLimits(limit);
ZElement.ValueBox.ValueChanged += OnValueChanged;
ZElement.ValueBox.ValueChanged += OnZValueChanged;
ZElement.ValueBox.SlidingEnd += ClearToken;
}
private void OnXValueChanged()
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
{
_xChanged = true;
_yChanged = false;
_zChanged = false;
}
OnValueChanged();
}
private void OnYValueChanged()
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
{
_xChanged = false;
_yChanged = true;
_zChanged = false;
}
OnValueChanged();
}
private void OnZValueChanged()
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
{
_xChanged = false;
_yChanged = false;
_zChanged = true;
}
OnValueChanged();
}
private void OnValueChanged()
{
if (IsSetBlocked)
return;
var xValue = XElement.ValueBox.Value;
var yValue = YElement.ValueBox.Value;
var zValue = ZElement.ValueBox.Value;
if (ChangeValuesTogether)
{
var adder = 0.0f;
if (_xChanged)
{
adder = xValue - ((Float3)Values[0]).X;
yValue += adder;
zValue += adder;
}
if (_yChanged)
{
adder = yValue - ((Float3)Values[0]).Y;
xValue += adder;
zValue += adder;
}
if (_zChanged)
{
adder = zValue - ((Float3)Values[0]).Z;
xValue += adder;
yValue += adder;
}
}
var isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding;
var token = isSliding ? this : null;
var value = new Float3(XElement.ValueBox.Value, YElement.ValueBox.Value, ZElement.ValueBox.Value);
var value = new Float3(xValue, yValue, zValue);
object v = Values[0];
if (v is Vector3)
v = (Vector3)value;
@@ -93,6 +169,13 @@ namespace FlaxEditor.CustomEditors.Editors
else if (v is Double3)
v = (Double3)value;
SetValue(v, token);
if (ChangeValuesTogether)
{
_xChanged = false;
_yChanged = false;
_zChanged = false;
}
}
/// <inheritdoc />