From b017ace490e2fadc15e226f735fdcacdedef061a Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 6 Aug 2014 12:48:38 +0100 Subject: [PATCH] Implemented ShowConditions for AddOption command --- .../Editor/FungusScript/AddOptionEditor.cs | 48 +++++++++++++ .../FungusScript/AddOptionEditor.cs.meta | 8 +++ Assets/Fungus/VisualScripting/AddOption.cs | 64 ++++++++++++++---- Assets/Shuttle/ShuttleGame.unity | Bin 78468 -> 78500 bytes 4 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs create mode 100644 Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs.meta diff --git a/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs new file mode 100644 index 00000000..00c3ff00 --- /dev/null +++ b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs @@ -0,0 +1,48 @@ +using UnityEditor; +using UnityEditorInternal; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus.Script +{ + + [CustomEditor (typeof(AddOption))] + public class AddOptionEditor : FungusCommandEditor + { + public override void DrawCommandInspectorGUI() + { + AddOption t = target as AddOption; + + EditorGUI.BeginChangeCheck(); + + + string optionText = EditorGUILayout.TextField(new GUIContent("Option Text", "Text for option button label"), t.optionText); + Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to execute when option is selected"), t.GetFungusScript(), t.targetSequence); + AddOption.ShowCondition showCondition = (AddOption.ShowCondition)EditorGUILayout.EnumPopup(new GUIContent("Show Condition", "Condition when this option should be visible."), t.showCondition); + + string booleanVariableKey = t.booleanVariableKey; + + if (showCondition == AddOption.ShowCondition.BooleanIsFalse || + showCondition == AddOption.ShowCondition.BooleanIsTrue) + { + VariableType type = VariableType.Boolean; + booleanVariableKey = SequenceEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), + t.GetFungusScript (), + t.booleanVariableKey, + ref type, + v => { return v.type == VariableType.Boolean; }); + } + + if (EditorGUI.EndChangeCheck()) + { + Undo.RecordObject(t, "Set Option"); + t.optionText = optionText; + t.targetSequence = targetSequence; + t.showCondition = showCondition; + t.booleanVariableKey = booleanVariableKey; + } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs.meta b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs.meta new file mode 100644 index 00000000..bf253032 --- /dev/null +++ b/Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3fbc2ac2326a64bb08cf8d7a7b9f4534 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/VisualScripting/AddOption.cs b/Assets/Fungus/VisualScripting/AddOption.cs index 78489fd1..c3bbf5df 100644 --- a/Assets/Fungus/VisualScripting/AddOption.cs +++ b/Assets/Fungus/VisualScripting/AddOption.cs @@ -7,29 +7,63 @@ namespace Fungus.Script public class AddOption : FungusCommand { - public enum Condition + public enum ShowCondition { - AlwaysShow, - HideOnVisited, - ShowOnBoolean, - HideOnBoolean + Always, + NotVisited, + BooleanIsTrue, + BooleanIsFalse } - public string text; - public Sequence sequence; - public Condition condition; + public string optionText; + public Sequence targetSequence; + public ShowCondition showCondition; public string booleanVariableKey; public override void OnEnter() { Dialog dialog = Game.GetInstance().dialog; - if (dialog != null && - sequence != null && - !(condition == Condition.HideOnVisited && sequence.GetExecutionCount() > 0)) + + bool showOption = (dialog != null && targetSequence != null); + + if (showCondition == ShowCondition.Always) + { + // Always show option + } + else if (showCondition == ShowCondition.NotVisited) + { + if (targetSequence.GetExecutionCount () > 0) + { + showOption = false; + } + } + else + { + Variable v = parentFungusScript.GetVariable(booleanVariableKey); + if (v == null) + { + showOption = false; + } + else + { + if (showCondition == ShowCondition.BooleanIsTrue && + v.booleanValue != true) + { + showOption = false; + } + else if (showCondition == ShowCondition.BooleanIsFalse && + v.booleanValue != false) + { + showOption = false; + } + } + } + + if (showOption) { - dialog.AddOption(text, () => { + dialog.AddOption(optionText, () => { Stop(); - parentFungusScript.ExecuteSequence(sequence); + parentFungusScript.ExecuteSequence(targetSequence); }); } Continue(); @@ -37,9 +71,9 @@ namespace Fungus.Script public override void GetConnectedSequences(ref List connectedSequences) { - if (sequence != null) + if (targetSequence != null) { - connectedSequences.Add(sequence); + connectedSequences.Add(targetSequence); } } diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index bd37e46b7ccb8c2754ddc3c6036ca118504020fe..494ca919ae8d80e69d93cb90ff8a5dae0049b538 100644 GIT binary patch delta 284 zcmZp9%Ch7sivR<|_bUvHMoSnN7&w9K4;uwGvI^uElw{`Tg``%LF#HDsrO6jWl_v-A zhEF~qBQUvYp77)(wj|!-jQn!v{JfM*klM)!a*~^$u{pe{F9DkL38<+ENawzAC^Rr+ zU_chj1B$Hxin##g|3TF$KG|6K0Voy=6k~*9C7@V<5d%XAkk10e%0RIdK(PcMALKBQ z9d7(vYdDM<7}l^eFuY`D*u3IQW1{7}$W=#xFlF)oya&54q_I Vnv5Poj}@OsVajcvpvm}!0|2MbTkZe= delta 259 zcmZ4Tl%?eU&@NxXuScd$utCg