chrisgregan
10 years ago
9 changed files with 52 additions and 159 deletions
@ -1,96 +0,0 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
[CommandCategory("Dialog")] |
||||
[CommandName("Add Option")] |
||||
[HelpText("Adds an option button to be displayed by the next Say command. The target sequence is run when the player selects the option. A condition can be specified for when the option should be shown.")] |
||||
public class AddOption : FungusCommand |
||||
{ |
||||
public enum ShowCondition |
||||
{ |
||||
Always, |
||||
NotVisited, |
||||
BooleanIsTrue, |
||||
BooleanIsFalse |
||||
} |
||||
|
||||
public string optionText; |
||||
public Sequence targetSequence; |
||||
public ShowCondition showCondition; |
||||
public BooleanVariable booleanVariable; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
Dialog dialog = Game.GetInstance().dialog; |
||||
bool showOption = (dialog != null && targetSequence != null); |
||||
|
||||
if (showCondition == ShowCondition.Always) |
||||
{ |
||||
// Always show option |
||||
} |
||||
else if (showCondition == ShowCondition.NotVisited) |
||||
{ |
||||
if (targetSequence == null || |
||||
targetSequence.GetExecutionCount () > 0) |
||||
{ |
||||
showOption = false; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
if (booleanVariable == null) |
||||
{ |
||||
showOption = false; |
||||
} |
||||
else |
||||
{ |
||||
if (showCondition == ShowCondition.BooleanIsTrue && |
||||
booleanVariable.Value != true) |
||||
{ |
||||
showOption = false; |
||||
} |
||||
else if (showCondition == ShowCondition.BooleanIsFalse && |
||||
booleanVariable.Value != false) |
||||
{ |
||||
showOption = false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (showOption) |
||||
{ |
||||
dialog.AddOption(optionText, () => { |
||||
Stop(); |
||||
parentFungusScript.ExecuteSequence(targetSequence); |
||||
}); |
||||
} |
||||
Continue(); |
||||
} |
||||
|
||||
public override void GetConnectedSequences(ref List<Sequence> connectedSequences) |
||||
{ |
||||
if (targetSequence != null) |
||||
{ |
||||
connectedSequences.Add(targetSequence); |
||||
} |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
string description = "\"" + optionText + "\""; |
||||
if (targetSequence == null) |
||||
{ |
||||
description += " <Continue>"; |
||||
} |
||||
else |
||||
{ |
||||
description += " (" + targetSequence.name + ")"; |
||||
} |
||||
return description; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,36 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
[CommandName("Set Dialog")] |
||||
[CommandCategory("Dialog")] |
||||
[HelpText("Sets the active dialog for displaying story text with the Say command.")] |
||||
public class SetDialog : FungusCommand |
||||
{ |
||||
public DialogController dialogController; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (dialogController != null) |
||||
{ |
||||
Say.dialogController = dialogController; |
||||
} |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (dialogController == null) |
||||
{ |
||||
return "Error: No dialog selected"; |
||||
} |
||||
|
||||
return dialogController.name; |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 74826d5144cf64adeb6dd522f32dfb94 |
||||
guid: 7c2d26a03c0c04cad97b8739546dd6ed |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
@ -1,48 +0,0 @@
|
||||
using UnityEditor; |
||||
using UnityEditorInternal; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
|
||||
[CustomEditor (typeof(AddOption))] |
||||
public class OptionEditor : FungusCommandEditor |
||||
{ |
||||
public override void DrawCommandGUI() |
||||
{ |
||||
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"), |
||||
new GUIContent("<Continue>"), |
||||
t.GetFungusScript(), |
||||
t.targetSequence); |
||||
AddOption.ShowCondition showCondition = (AddOption.ShowCondition)EditorGUILayout.EnumPopup(new GUIContent("Show Condition", "Condition when this option should be visible."), t.showCondition); |
||||
|
||||
BooleanVariable booleanVariable = t.booleanVariable; |
||||
|
||||
if (showCondition == AddOption.ShowCondition.BooleanIsFalse || |
||||
showCondition == AddOption.ShowCondition.BooleanIsTrue) |
||||
{ |
||||
booleanVariable = FungusVariableEditor.VariableField (new GUIContent ("Boolean Variable", "Boolean variable to test for condition"), |
||||
t.GetFungusScript (), |
||||
t.booleanVariable, |
||||
v => { return v.GetType() == typeof(BooleanVariable); }) as BooleanVariable; |
||||
} |
||||
|
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
Undo.RecordObject(t, "Set Option"); |
||||
t.optionText = optionText; |
||||
t.targetSequence = targetSequence; |
||||
t.showCondition = showCondition; |
||||
t.booleanVariable = booleanVariable; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3fbc2ac2326a64bb08cf8d7a7b9f4534 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Loading…
Reference in new issue