mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-22 09:35:11 +00:00
Collapseable Properties Functionality (#534)
* all done * oop * two quick tweaks
This commit is contained in:
parent
8891689f68
commit
7b1269d155
9 changed files with 166 additions and 15 deletions
|
@ -39,13 +39,19 @@ namespace HeavenStudio.Games.Loaders
|
|||
defaultLength = 4f,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("preset", SpaceSoccer.EnterExitPresets.FiveKickers, "Preset", "Which preset should be used?"),
|
||||
new Param("choice", SpaceSoccer.AnimationToPlay.Enter, "Enter Or Exit", "Whether the kickers should exit or enter."),
|
||||
new Param("ease", EasingFunction.Ease.Linear, "Ease", "The Ease of the entering or exiting."),
|
||||
new Param("preset", SpaceSoccer.EnterExitPresets.FiveKickers, "Preset", "Which preset should be used?", new List<Param.CollapseParam>()
|
||||
{
|
||||
new Param.CollapseParam(x => (int)x == (int)SpaceSoccer.EnterExitPresets.Custom, new string[] { "amount", "x", "y", "z" })
|
||||
}),
|
||||
|
||||
|
||||
new Param("amount", new EntityTypes.Integer(2, 30, 5), "Amount", "Amount of Space Kickers."),
|
||||
new Param("x", new EntityTypes.Float(-30, 30, 2f), "X Distance", "How much distance should there be between the space kickers on the x axis?"),
|
||||
new Param("y", new EntityTypes.Float(-30, 30, -0.5f), "Y Distance", "How much distance should there be between the space kickers on the y axis?"),
|
||||
new Param("z", new EntityTypes.Float(-30, 30, 1.25f), "Z Distance", "How much distance should there be between the space kickers on the z axis?"),
|
||||
|
||||
new Param("choice", SpaceSoccer.AnimationToPlay.Enter, "Enter Or Exit", "Whether the kickers should exit or enter."),
|
||||
new Param("ease", EasingFunction.Ease.Linear, "Ease", "The Ease of the entering or exiting."),
|
||||
new Param("override", true, "Override Easing", "Should this block override the easing of the space kickers' positions?")
|
||||
},
|
||||
resizable = true
|
||||
|
@ -70,7 +76,10 @@ namespace HeavenStudio.Games.Loaders
|
|||
resizable = true,
|
||||
parameters = new List<Param>()
|
||||
{
|
||||
new Param("preset", SpaceSoccer.PlayerPresets.LaunchStart, "Preset", "Which preset should be used?"),
|
||||
new Param("preset", SpaceSoccer.PlayerPresets.LaunchStart, "Preset", "Which preset should be used?", new List<Param.CollapseParam>()
|
||||
{
|
||||
new Param.CollapseParam(x => (int)x == (int)SpaceSoccer.PlayerPresets.Custom, new string[] { "x", "y", "z", "ease", "sound" })
|
||||
}),
|
||||
new Param("x", new EntityTypes.Float(-30, 30, 0f), "X Pos", "Which position should the player move to on the x axis?"),
|
||||
new Param("y", new EntityTypes.Float(-30, 30, 0f), "Y Pos", "Which position should the player move to on the y axis?"),
|
||||
new Param("z", new EntityTypes.Float(-30, 30, 0f), "Z Pos", "Which position should the player move to on the z axis?"),
|
||||
|
|
|
@ -94,14 +94,31 @@ namespace HeavenStudio.Editor
|
|||
|
||||
DestroyParams();
|
||||
|
||||
Dictionary<string, GameObject> ePrefabs = new();
|
||||
|
||||
for (int i = 0; i < action.parameters.Count; i++)
|
||||
{
|
||||
object param = action.parameters[i].parameter;
|
||||
string caption = action.parameters[i].propertyCaption;
|
||||
string propertyName = action.parameters[i].propertyName;
|
||||
string tooltip = action.parameters[i].tooltip;
|
||||
ePrefabs.Add(propertyName, AddParam(propertyName, param, caption, tooltip));
|
||||
}
|
||||
|
||||
AddParam(propertyName, param, caption, tooltip);
|
||||
foreach (var p in action.parameters)
|
||||
{
|
||||
if (p.collapseParams == null) return;
|
||||
EventPropertyPrefab input = ePrefabs[p.propertyName].GetComponent<EventPropertyPrefab>();
|
||||
foreach (var c in p.collapseParams)
|
||||
{
|
||||
List<GameObject> collapseables = new();
|
||||
foreach (var s in c.collapseables)
|
||||
{
|
||||
collapseables.Add(ePrefabs[s]);
|
||||
}
|
||||
input.propertyCollapses.Add(new EventPropertyPrefab.PropertyCollapse(collapseables, c.CollapseOn));
|
||||
}
|
||||
input.SetCollapses(p.parameter);
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
@ -112,7 +129,7 @@ namespace HeavenStudio.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private void AddParam(string propertyName, object type, string caption, string tooltip = "")
|
||||
private GameObject AddParam(string propertyName, object type, string caption, string tooltip = "")
|
||||
{
|
||||
GameObject prefab = IntegerP;
|
||||
GameObject input;
|
||||
|
@ -164,8 +181,9 @@ namespace HeavenStudio.Editor
|
|||
else
|
||||
{
|
||||
Debug.LogError("Can't make property interface of type: " + type.GetType());
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
private GameObject InitPrefab(GameObject prefab, string tooltip = "")
|
||||
|
|
|
@ -16,8 +16,10 @@ namespace HeavenStudio.Editor
|
|||
public TMP_Text caption;
|
||||
public EventParameterManager parameterManager;
|
||||
public string propertyName;
|
||||
public List<PropertyCollapse> propertyCollapses = new List<PropertyCollapse>();
|
||||
|
||||
public void SetProperties(string propertyName, object type, string caption) {}
|
||||
public virtual void SetCollapses(object type) { }
|
||||
|
||||
public void InitProperties(string propertyName, string caption)
|
||||
{
|
||||
|
@ -25,5 +27,28 @@ namespace HeavenStudio.Editor
|
|||
this.propertyName = propertyName;
|
||||
this.caption.text = caption;
|
||||
}
|
||||
|
||||
public void UpdateCollapse(object type)
|
||||
{
|
||||
foreach (var p in propertyCollapses)
|
||||
{
|
||||
foreach (var c in p.collapseables)
|
||||
{
|
||||
c.SetActive(p.collapseOn(type) && gameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyCollapse
|
||||
{
|
||||
public List<GameObject> collapseables;
|
||||
public Func<object, bool> collapseOn;
|
||||
|
||||
public PropertyCollapse(List<GameObject> collapseables, Func<object, bool> collapseOn)
|
||||
{
|
||||
this.collapseables = collapseables;
|
||||
this.collapseOn = collapseOn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,14 @@ namespace HeavenStudio.Editor
|
|||
);
|
||||
}
|
||||
|
||||
public override void SetCollapses(object type)
|
||||
{
|
||||
toggle.onValueChanged.AddListener(
|
||||
_ => UpdateCollapse(toggle.isOn)
|
||||
);
|
||||
UpdateCollapse(toggle.isOn);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ namespace HeavenStudio.Editor
|
|||
ColorTable.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public override void SetCollapses(object type)
|
||||
{
|
||||
colorPreview.colorPicker.onColorChanged += _ => UpdateCollapse(colorPreview.colorPicker.color);
|
||||
UpdateCollapse(colorPreview.colorPicker.color);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (colorTableActive)
|
||||
|
|
|
@ -17,13 +17,14 @@ namespace HeavenStudio.Editor
|
|||
[Header("Dropdown")]
|
||||
[Space(10)]
|
||||
public TMP_Dropdown dropdown;
|
||||
private Array enumVals;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
var enumType = type.GetType();
|
||||
var enumVals = Enum.GetValues(enumType);
|
||||
enumVals = Enum.GetValues(enumType);
|
||||
var enumNames = Enum.GetNames(enumType).ToList();
|
||||
|
||||
// Can we assume non-holey enum?
|
||||
|
@ -42,6 +43,12 @@ namespace HeavenStudio.Editor
|
|||
);
|
||||
}
|
||||
|
||||
public override void SetCollapses(object type)
|
||||
{
|
||||
dropdown.onValueChanged.AddListener(_ => UpdateCollapse((int)enumVals.GetValue(dropdown.value)));
|
||||
UpdateCollapse((int)enumVals.GetValue(dropdown.value));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -94,6 +94,56 @@ namespace HeavenStudio.Editor
|
|||
}
|
||||
}
|
||||
|
||||
public override void SetCollapses(object type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EntityTypes.Integer integer:
|
||||
slider.onValueChanged.AddListener(
|
||||
_ =>
|
||||
{
|
||||
UpdateCollapse((int)slider.value);
|
||||
}
|
||||
);
|
||||
|
||||
inputField.onEndEdit.AddListener(
|
||||
_ =>
|
||||
{
|
||||
UpdateCollapse((int)slider.value);
|
||||
}
|
||||
);
|
||||
|
||||
UpdateCollapse((int)slider.value);
|
||||
|
||||
break;
|
||||
|
||||
case EntityTypes.Float fl:
|
||||
slider.onValueChanged.AddListener(
|
||||
_ =>
|
||||
{
|
||||
var newValue = (float)Math.Round(slider.value, 4);
|
||||
UpdateCollapse(newValue);
|
||||
}
|
||||
);
|
||||
|
||||
var newValue = (float)Math.Round(slider.value, 4);
|
||||
UpdateCollapse(newValue);
|
||||
|
||||
inputField.onEndEdit.AddListener(
|
||||
_ =>
|
||||
{
|
||||
UpdateCollapse(slider.value);
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(type), type, "I don't know how to make a property of this type!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -42,6 +42,16 @@ namespace HeavenStudio.Editor
|
|||
);
|
||||
}
|
||||
|
||||
public override void SetCollapses(object type)
|
||||
{
|
||||
inputFieldString.onValueChanged.AddListener(
|
||||
_ =>
|
||||
{
|
||||
UpdateCollapse(inputFieldString.text);
|
||||
});
|
||||
UpdateCollapse(inputFieldString.text);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -467,6 +467,7 @@ namespace HeavenStudio
|
|||
public object parameter;
|
||||
public string propertyCaption;
|
||||
public string tooltip;
|
||||
public List<CollapseParam> collapseParams;
|
||||
|
||||
/// <summary>
|
||||
/// A parameter that changes the function of a GameAction.
|
||||
|
@ -474,12 +475,29 @@ namespace HeavenStudio
|
|||
/// <param name="propertyName">The name of the variable that's being changed.</param>
|
||||
/// <param name="parameter">The value of the parameter</param>
|
||||
/// <param name="propertyCaption">The name shown in the editor. Can be anything you want.</param>
|
||||
public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "")
|
||||
public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "", List<CollapseParam> collapseParams = null)
|
||||
{
|
||||
this.propertyName = propertyName;
|
||||
this.parameter = parameter;
|
||||
this.propertyCaption = propertyCaption;
|
||||
this.tooltip = tooltip;
|
||||
this.collapseParams = collapseParams;
|
||||
}
|
||||
|
||||
public class CollapseParam
|
||||
{
|
||||
public Func<object, bool> CollapseOn;
|
||||
public string[] collapseables;
|
||||
/// <summary>
|
||||
/// Class that decides how other parameters will be collapsed
|
||||
/// </summary>
|
||||
/// <param name="collapseOn">What values should make it collapse/uncollapse?</param>
|
||||
/// <param name="collapseables">IDs of the parameters to collapse</param>
|
||||
public CollapseParam(Func<object, bool> collapseOn, string[] collapseables)
|
||||
{
|
||||
CollapseOn = collapseOn;
|
||||
this.collapseables = collapseables;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue