diff --git a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs index 9617cf943..f9a0ea19d 100644 --- a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs +++ b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs @@ -20,7 +20,7 @@ namespace HeavenStudio.Games.Loaders new Param("toggle", false, "Disable Sound", "Disables the dispense sound"), new Param("down", false, "Down Sound", "Will the Down sound be played?") }, - inactiveFunction = delegate + inactiveFunction = delegate { if (!eventCaller.currentEntity["toggle"]) { SpaceSoccer.DispenseSound(eventCaller.currentEntity.beat, eventCaller.currentEntity["down"]);} } @@ -39,13 +39,19 @@ namespace HeavenStudio.Games.Loaders defaultLength = 4f, parameters = new List() { - 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() + { + 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() { - 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() + { + 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?"), @@ -92,7 +101,7 @@ namespace HeavenStudio.Games.Loaders new Param("ease", Util.EasingFunction.Ease.Linear, "Ease") } }, - new GameAction("scroll", "Scrolling Background") + new GameAction("scroll", "Scrolling Background") { function = delegate { var e = eventCaller.currentEntity; SpaceSoccer.instance.UpdateScrollSpeed(e["x"], e["y"]); }, defaultLength = 1f, @@ -118,8 +127,8 @@ namespace HeavenStudio.Games.Loaders }, new GameAction("npc kickers instant enter or exit", "NPC Kickers Instant Enter or Exit") { - function = delegate - { + function = delegate + { var e = eventCaller.currentEntity; int choice; if (e["toggle"]) @@ -140,9 +149,9 @@ namespace HeavenStudio.Games.Loaders hidden = true }, }, - new List() {"ntr", "keep"}, + new List() { "ntr", "keep" }, "ntrsoccer", "en", - new List() {"en"} + new List() { "en" } ); } } diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs index 67494a262..17650d817 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs @@ -94,14 +94,31 @@ namespace HeavenStudio.Editor DestroyParams(); + Dictionary 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(); + foreach (var c in p.collapseParams) + { + List 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 = "") diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs index 91af6a2f9..606baf30b 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs @@ -16,8 +16,10 @@ namespace HeavenStudio.Editor public TMP_Text caption; public EventParameterManager parameterManager; public string propertyName; + public List propertyCollapses = new List(); 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 collapseables; + public Func collapseOn; + + public PropertyCollapse(List collapseables, Func collapseOn) + { + this.collapseables = collapseables; + this.collapseOn = collapseOn; + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs index 5aae8e626..fa2d0e5e8 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs @@ -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() { } diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs index 1de8499b4..1e36a1ee9 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs @@ -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) diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/EnumPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/EnumPropertyPrefab.cs index f0edf4aff..bc98a8c3f 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/EnumPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/EnumPropertyPrefab.cs @@ -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() { } diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs index 1ce2d4daa..15cdb6f21 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs @@ -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() { } diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs index 4a112b8d0..ecae26ceb 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs @@ -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() { } diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 9c91392f4..286fee43f 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -467,6 +467,7 @@ namespace HeavenStudio public object parameter; public string propertyCaption; public string tooltip; + public List collapseParams; /// /// A parameter that changes the function of a GameAction. @@ -474,12 +475,29 @@ namespace HeavenStudio /// The name of the variable that's being changed. /// The value of the parameter /// The name shown in the editor. Can be anything you want. - public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "") + public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "", List collapseParams = null) { this.propertyName = propertyName; this.parameter = parameter; this.propertyCaption = propertyCaption; this.tooltip = tooltip; + this.collapseParams = collapseParams; + } + + public class CollapseParam + { + public Func CollapseOn; + public string[] collapseables; + /// + /// Class that decides how other parameters will be collapsed + /// + /// What values should make it collapse/uncollapse? + /// IDs of the parameters to collapse + public CollapseParam(Func collapseOn, string[] collapseables) + { + CollapseOn = collapseOn; + this.collapseables = collapseables; + } } }