Added saving the users choice in the properties window and adding link and unlink to the scale context menu.

This commit is contained in:
Chandler Cox
2023-02-05 15:07:12 -06:00
parent b113bdb774
commit e4afc49ac6
3 changed files with 51 additions and 60 deletions

View File

@@ -79,66 +79,54 @@ namespace FlaxEditor.CustomEditors.Editors
/// <seealso cref="FlaxEditor.CustomEditors.Editors.Float3Editor" />
public class ScaleEditor : Float3Editor
{
private Image _linkImage;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
var scaleLocked = Editor.Instance.Windows.PropertiesWin.ScaleLocked;
if (scaleLocked)
{
ChangeValuesTogether = scaleLocked;
}
base.Initialize(layout);
LinkValuesTogether = Editor.Instance.Windows.PropertiesWin.ScaleLocked;
_linkImage = new Image
{
Parent = LinkedLabel,
Width = 18,
Height = 18,
Brush = LinkValuesTogether ? new SpriteBrush(Editor.Instance.Icons.Link32) : new SpriteBrush(),
AnchorPreset = AnchorPresets.TopLeft,
TooltipText = "Scale values are linked together.",
};
_linkImage.LocalX += 40;
_linkImage.LocalY += 1;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
menu.AddSeparator();
menu.AddButton(LinkValuesTogether ? "Unlink" : "Link", ToggleLink);
};
// Override colors
var back = FlaxEngine.GUI.Style.Current.TextBoxBackground;
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), // TODO change on scale lock
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;
Editor.Instance.Windows.PropertiesWin.ScaleLocked = 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;
}
/// <summary>
/// Toggles the linking functionality.
/// </summary>
public void ToggleLink()
{
LinkValuesTogether = !LinkValuesTogether;
Editor.Instance.Windows.PropertiesWin.ScaleLocked = LinkValuesTogether;
_linkImage.Brush = LinkValuesTogether ? new SpriteBrush(Editor.Instance.Icons.Link32) : new SpriteBrush();
}
}
}
}

View File

@@ -47,7 +47,7 @@ namespace FlaxEditor.CustomEditors.Editors
/// <summary>
/// If true, when one value is changed, the other 2 will change as well.
/// </summary>
protected bool ChangeValuesTogether = false;
public bool LinkValuesTogether = false;
private enum ValueChanged
{
@@ -95,7 +95,7 @@ namespace FlaxEditor.CustomEditors.Editors
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
if (LinkValuesTogether)
_valueChanged = ValueChanged.X;
OnValueChanged();
@@ -105,7 +105,7 @@ namespace FlaxEditor.CustomEditors.Editors
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
if (LinkValuesTogether)
_valueChanged = ValueChanged.Y;
OnValueChanged();
@@ -115,7 +115,7 @@ namespace FlaxEditor.CustomEditors.Editors
{
if (IsSetBlocked)
return;
if (ChangeValuesTogether)
if (LinkValuesTogether)
_valueChanged = ValueChanged.Z;
OnValueChanged();
@@ -130,25 +130,25 @@ namespace FlaxEditor.CustomEditors.Editors
var yValue = YElement.ValueBox.Value;
var zValue = ZElement.ValueBox.Value;
if (ChangeValuesTogether)
if (LinkValuesTogether)
{
var adder = 0.0f;
var valueChange = 0.0f;
switch (_valueChanged)
{
case ValueChanged.X:
adder = xValue - ((Float3)Values[0]).X;
yValue += adder;
zValue += adder;
valueChange = xValue - ((Float3)Values[0]).X;
yValue += valueChange;
zValue += valueChange;
break;
case ValueChanged.Y:
adder = yValue - ((Float3)Values[0]).Y;
xValue += adder;
zValue += adder;
valueChange = yValue - ((Float3)Values[0]).Y;
xValue += valueChange;
zValue += valueChange;
break;
case ValueChanged.Z:
adder = zValue - ((Float3)Values[0]).Z;
xValue += adder;
yValue += adder;
valueChange = zValue - ((Float3)Values[0]).Z;
xValue += valueChange;
yValue += valueChange;
break;
default:
break;