Browse Source

Implemented ShowConditions for AddOption command

master
chrisgregan 11 years ago
parent
commit
b017ace490
  1. 48
      Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs
  2. 8
      Assets/Fungus/Editor/FungusScript/AddOptionEditor.cs.meta
  3. 64
      Assets/Fungus/VisualScripting/AddOption.cs
  4. BIN
      Assets/Shuttle/ShuttleGame.unity

48
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;
}
}
}
}

8
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:

64
Assets/Fungus/VisualScripting/AddOption.cs

@ -7,29 +7,63 @@ namespace Fungus.Script
public class AddOption : FungusCommand public class AddOption : FungusCommand
{ {
public enum Condition public enum ShowCondition
{ {
AlwaysShow, Always,
HideOnVisited, NotVisited,
ShowOnBoolean, BooleanIsTrue,
HideOnBoolean BooleanIsFalse
} }
public string text; public string optionText;
public Sequence sequence; public Sequence targetSequence;
public Condition condition; public ShowCondition showCondition;
public string booleanVariableKey; public string booleanVariableKey;
public override void OnEnter() public override void OnEnter()
{ {
Dialog dialog = Game.GetInstance().dialog; Dialog dialog = Game.GetInstance().dialog;
if (dialog != null &&
sequence != null && bool showOption = (dialog != null && targetSequence != null);
!(condition == Condition.HideOnVisited && sequence.GetExecutionCount() > 0))
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(); Stop();
parentFungusScript.ExecuteSequence(sequence); parentFungusScript.ExecuteSequence(targetSequence);
}); });
} }
Continue(); Continue();
@ -37,9 +71,9 @@ namespace Fungus.Script
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
{ {
if (sequence != null) if (targetSequence != null)
{ {
connectedSequences.Add(sequence); connectedSequences.Add(targetSequence);
} }
} }

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save