Post merge fixes, tweaks, cleanup and improvements

This commit is contained in:
Wojtek Figat
2021-03-08 22:30:49 +01:00
parent 7fbb008ddd
commit 84265322d5
2 changed files with 66 additions and 59 deletions

View File

@@ -1,8 +1,8 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FlaxEditor.CustomEditors.Editors;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.GUI;
@@ -354,90 +354,91 @@ namespace FlaxEditor.CustomEditors.Dedicated
for (int i = 0; i < layout.Children.Count; i++)
{
//Debug.Log(((GroupElement)layout.Children[i])?.Panel?.HeaderText);
if (layout.Children[i] is GroupElement group && group.Panel.HeaderText == "Transform")
{
VerticalPanelElement mainHor = VerticalPanelWihtoutMargin(group);
CreateTransformElements(mainHor);
VerticalPanelElement mainHor = VerticalPanelWithoutMargin(group);
CreateTransformElements(mainHor, ValuesTypes);
group.ContainerControl.ChangeChildIndex(mainHor.Control, 0);
break;
}
}
}
void CreateTransformElements(LayoutElementsContainer main)
private void CreateTransformElements(LayoutElementsContainer main, ScriptType[] valueTypes)
{
main.Space(10);
HorizontalPanelElement sidePanel = main.HorizontalPanel();//HorizontalPanelWihtoutMargin(main);
HorizontalPanelElement sidePanel = main.HorizontalPanel();
sidePanel.Panel.ClipChildren = false;
ScriptMemberInfo anchorinfo = ValuesTypes[0].GetProperty("AnchorPreset");
ItemInfo anchorItem = new ItemInfo(anchorinfo);
ScriptMemberInfo anchorInfo = valueTypes[0].GetProperty("AnchorPreset");
ItemInfo anchorItem = new ItemInfo(anchorInfo);
sidePanel.Object(anchorItem.GetValues(Values));
VerticalPanelElement group = VerticalPanelWihtoutMargin(sidePanel);
VerticalPanelElement group = VerticalPanelWithoutMargin(sidePanel);
group.Panel.AnchorPreset = AnchorPresets.HorizontalStretchTop;
group.Panel.Offsets = new Margin(100, 10, 0, 0);
var horUp = UniformGridTwoByOne(group);
horUp.CustomControl.Height = TextBoxBase.DefaultHeight;
var horDown = UniformGridTwoByOne(group);
horDown.CustomControl.Height = TextBoxBase.DefaultHeight;
GetAnchorEquality(out cache_xEq, out cache_yEq);
GetAnchorEquality(out _cachedXEq, out _cachedYEq, valueTypes);
BuildLocationSizeOffsets(horUp, horDown, cache_xEq, cache_yEq);
BuildLocationSizeOffsets(horUp, horDown, _cachedXEq, _cachedYEq, valueTypes);
main.Space(10);
BuildAnchorsDropper(main);
BuildAnchorsDropper(main, valueTypes);
}
void BuildAnchorsDropper(LayoutElementsContainer main)
private void BuildAnchorsDropper(LayoutElementsContainer main, ScriptType[] valueTypes)
{
ScriptMemberInfo mininfo = ValuesTypes[0].GetProperty("AnchorMin");
ScriptMemberInfo maxinfo = ValuesTypes[0].GetProperty("AnchorMax");
ItemInfo minitem = new ItemInfo(mininfo);
ItemInfo maxitem = new ItemInfo(maxinfo);
ScriptMemberInfo minInfo = valueTypes[0].GetProperty("AnchorMin");
ScriptMemberInfo maxInfo = valueTypes[0].GetProperty("AnchorMax");
ItemInfo minItem = new ItemInfo(minInfo);
ItemInfo maxItem = new ItemInfo(maxInfo);
GroupElement ng = main.Group("Anchors", true);
ng.Panel.Close(false);
ng.Property("Min", minitem.GetValues(Values));
ng.Property("Max", maxitem.GetValues(Values));
ng.Property("Min", minItem.GetValues(Values));
ng.Property("Max", maxItem.GetValues(Values));
}
void GetAnchorEquality(out bool xEq, out bool yEq)
private void GetAnchorEquality(out bool xEq, out bool yEq, ScriptType[] valueTypes)
{
ScriptMemberInfo mininfo = ValuesTypes[0].GetProperty("AnchorMin");
ScriptMemberInfo maxinfo = ValuesTypes[0].GetProperty("AnchorMax");
ItemInfo minitem = new ItemInfo(mininfo);
ItemInfo maxitem = new ItemInfo(maxinfo);
ValueContainer minVal = minitem.GetValues(Values);
ValueContainer maxVal = maxitem.GetValues(Values);
ScriptMemberInfo minInfo = valueTypes[0].GetProperty("AnchorMin");
ScriptMemberInfo maxInfo = valueTypes[0].GetProperty("AnchorMax");
ItemInfo minItem = new ItemInfo(minInfo);
ItemInfo maxItem = new ItemInfo(maxInfo);
ValueContainer minVal = minItem.GetValues(Values);
ValueContainer maxVal = maxItem.GetValues(Values);
ItemInfo XItem = new ItemInfo(mininfo.ValueType.GetField("X"));
ItemInfo YItem = new ItemInfo(mininfo.ValueType.GetField("Y"));
ItemInfo xItem = new ItemInfo(minInfo.ValueType.GetField("X"));
ItemInfo yItem = new ItemInfo(minInfo.ValueType.GetField("Y"));
xEq = XItem.GetValues(minVal).ToList().Any(XItem.GetValues(maxVal).ToList().Contains);
yEq = YItem.GetValues(minVal).ToList().Any(YItem.GetValues(maxVal).ToList().Contains);
xEq = xItem.GetValues(minVal).ToList().Any(xItem.GetValues(maxVal).ToList().Contains);
yEq = yItem.GetValues(minVal).ToList().Any(yItem.GetValues(maxVal).ToList().Contains);
}
void BuildLocationSizeOffsets(LayoutElementsContainer horUp, LayoutElementsContainer horDown, bool xEq, bool yEq)
private void BuildLocationSizeOffsets(LayoutElementsContainer horUp, LayoutElementsContainer horDown, bool xEq, bool yEq, ScriptType[] valueTypes)
{
ScriptMemberInfo xInfo = ValuesTypes[0].GetProperty("X");
ScriptMemberInfo xInfo = valueTypes[0].GetProperty("X");
ItemInfo xItem = new ItemInfo(xInfo);
ScriptMemberInfo yInfo = ValuesTypes[0].GetProperty("Y");
ScriptMemberInfo yInfo = valueTypes[0].GetProperty("Y");
ItemInfo yItem = new ItemInfo(yInfo);
ScriptMemberInfo widthInfo = ValuesTypes[0].GetProperty("Width");
ScriptMemberInfo widthInfo = valueTypes[0].GetProperty("Width");
ItemInfo widthItem = new ItemInfo(widthInfo);
ScriptMemberInfo heightInfo = ValuesTypes[0].GetProperty("Height");
ScriptMemberInfo heightInfo = valueTypes[0].GetProperty("Height");
ItemInfo heightItem = new ItemInfo(heightInfo);
ScriptMemberInfo leftInfo = ValuesTypes[0].GetProperty("Proxy_Offset_Left");
ScriptMemberInfo leftInfo = valueTypes[0].GetProperty("Proxy_Offset_Left", BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
ItemInfo leftItem = new ItemInfo(leftInfo);
ScriptMemberInfo rightInfo = ValuesTypes[0].GetProperty("Proxy_Offset_Right");
ScriptMemberInfo rightInfo = valueTypes[0].GetProperty("Proxy_Offset_Right", BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
ItemInfo rightItem = new ItemInfo(rightInfo);
ScriptMemberInfo topInfo = ValuesTypes[0].GetProperty("Proxy_Offset_Top");
ScriptMemberInfo topInfo = valueTypes[0].GetProperty("Proxy_Offset_Top", BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
ItemInfo topItem = new ItemInfo(topInfo);
ScriptMemberInfo bottomInfo = ValuesTypes[0].GetProperty("Proxy_Offset_Bottom");
ScriptMemberInfo bottomInfo = valueTypes[0].GetProperty("Proxy_Offset_Bottom", BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
ItemInfo bottomItem = new ItemInfo(bottomInfo);
LayoutElementsContainer xEl;
@@ -475,16 +476,16 @@ namespace FlaxEditor.CustomEditors.Dedicated
hEl.Control.AnchorMin = new Vector2(0.5f, xEl.Control.AnchorMin.Y);
hEl.Control.AnchorMax = new Vector2(1, xEl.Control.AnchorMax.Y);
}
VerticalPanelElement VerticalPanelWihtoutMargin(LayoutElementsContainer cont)
private VerticalPanelElement VerticalPanelWithoutMargin(LayoutElementsContainer cont)
{
var horUp = cont.VerticalPanel();
horUp.Panel.Margin = Margin.Zero;
return horUp;
}
CustomElementsContainer<UniformGridPanel> UniformGridTwoByOne(LayoutElementsContainer cont)
private CustomElementsContainer<UniformGridPanel> UniformGridTwoByOne(LayoutElementsContainer cont)
{
var horUp = cont.CustomContainer<UniformGridPanel>();
horUp.CustomControl.SlotsHorizontally = 2;
@@ -494,7 +495,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
return horUp;
}
CustomElementsContainer<UniformGridPanel> UniformPanelCapsuleForObjectWithText(LayoutElementsContainer el,string text, ValueContainer values)
private CustomElementsContainer<UniformGridPanel> UniformPanelCapsuleForObjectWithText(LayoutElementsContainer el, string text, ValueContainer values)
{
CustomElementsContainer<UniformGridPanel> hor = UniformGridTwoByOne(el);
hor.CustomControl.SlotPadding = new Margin(5, 5, 0, 0);
@@ -503,8 +504,9 @@ namespace FlaxEditor.CustomEditors.Dedicated
return hor;
}
bool cache_xEq;
bool cache_yEq;
private bool _cachedXEq;
private bool _cachedYEq;
/// <summary>
/// Refreshes if equality of anchors does not correspond to the cached equality
/// </summary>
@@ -513,8 +515,8 @@ namespace FlaxEditor.CustomEditors.Dedicated
if (Values.HasNull)
return;
GetAnchorEquality(out bool xEq,out bool yEq);
if (xEq != cache_xEq || yEq != cache_yEq)
GetAnchorEquality(out bool xEq, out bool yEq, ValuesTypes);
if (xEq != _cachedXEq || yEq != _cachedYEq)
{
RebuildLayout();
return;

View File

@@ -84,42 +84,47 @@ namespace FlaxEngine.GUI
}
}
#if FLAX_EDITOR
/// <summary>
/// Helper for UI
/// Helper for Editor UI (see UIControlControlEditor).
/// </summary>
[NoSerialize, HideInEditor]
public float Proxy_Offset_Left
internal float Proxy_Offset_Left
{
get => Offsets.Left;
set => Offsets = new Margin(value, Offsets.Right, Offsets.Top, Offsets.Bottom);
}
/// <summary>
/// Helper for UI
/// Helper for Editor UI (see UIControlControlEditor).
/// </summary>
[NoSerialize, HideInEditor]
public float Proxy_Offset_Right
internal float Proxy_Offset_Right
{
get => Offsets.Right;
set => Offsets = new Margin(Offsets.Left, value, Offsets.Top, Offsets.Bottom);
}
/// <summary>
/// Helper for UI
/// Helper for Editor UI (see UIControlControlEditor).
/// </summary>
[NoSerialize, HideInEditor]
public float Proxy_Offset_Top
internal float Proxy_Offset_Top
{
get => Offsets.Top;
set => Offsets = new Margin(Offsets.Left, Offsets.Right, value, Offsets.Bottom);
}
/// <summary>
/// Helper for UI
/// Helper for Editor UI (see UIControlControlEditor).
/// </summary>
[NoSerialize, HideInEditor]
public float Proxy_Offset_Bottom
internal float Proxy_Offset_Bottom
{
get => Offsets.Bottom;
set => Offsets = new Margin(Offsets.Left, Offsets.Right, Offsets.Top, value);
}
#endif
/// <summary>
/// Gets or sets coordinates of the upper-left corner of the control relative to the upper-left corner of its container.