Browse Source

Added SetDialog command

master
chrisgregan 10 years ago
parent
commit
e8783b6071
  1. 96
      Assets/Fungus/Dialog/Commands/AddOption.cs
  2. 9
      Assets/Fungus/Dialog/Commands/Say.cs
  3. 36
      Assets/Fungus/Dialog/Commands/SetDialog.cs
  4. 2
      Assets/Fungus/Dialog/Commands/SetDialog.cs.meta
  5. 48
      Assets/Fungus/Dialog/Editor/OptionEditor.cs
  6. 8
      Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta
  7. 5
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  8. 6
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  9. 1
      Assets/Fungus/FungusScript/Scripts/Sequence.cs

96
Assets/Fungus/Dialog/Commands/AddOption.cs

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

9
Assets/Fungus/Dialog/Commands/Say.cs

@ -9,7 +9,8 @@ namespace Fungus.Script
[HelpText("Writes a line of story text to the dialog. A condition can be specified for when the story text should be shown.")] [HelpText("Writes a line of story text to the dialog. A condition can be specified for when the story text should be shown.")]
public class Say : FungusCommand public class Say : FungusCommand
{ {
public DialogController dialogController; static public DialogController dialogController;
public Character character; public Character character;
public string storyText; public string storyText;
public bool displayOnce; public bool displayOnce;
@ -43,6 +44,8 @@ namespace Fungus.Script
executionCount++; executionCount++;
dialogController.ShowDialog(true);
if (character != null) if (character != null)
{ {
dialogController.SetCharacter(character); dialogController.SetCharacter(character);
@ -58,6 +61,9 @@ namespace Fungus.Script
Sequence onSelectSequence = sayOption.targetSequence; Sequence onSelectSequence = sayOption.targetSequence;
dialogOption.onSelect = delegate { dialogOption.onSelect = delegate {
dialogController.ShowDialog(false);
if (onSelectSequence == null) if (onSelectSequence == null)
{ {
Continue (); Continue ();
@ -76,6 +82,7 @@ namespace Fungus.Script
else else
{ {
dialogController.Say(storyText, delegate { dialogController.Say(storyText, delegate {
dialogController.ShowDialog(false);
Continue(); Continue();
}); });
} }

36
Assets/Fungus/Dialog/Commands/SetDialog.cs

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

2
Assets/Fungus/Dialog/Commands/AddOption.cs.meta → Assets/Fungus/Dialog/Commands/SetDialog.cs.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 74826d5144cf64adeb6dd522f32dfb94 guid: 7c2d26a03c0c04cad97b8739546dd6ed
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []

48
Assets/Fungus/Dialog/Editor/OptionEditor.cs

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

8
Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 3fbc2ac2326a64bb08cf8d7a7b9f4534
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

5
Assets/Fungus/Dialog/Editor/SayEditor.cs

@ -26,10 +26,6 @@ namespace Fungus.Script
sayStyle.wordWrap = true; sayStyle.wordWrap = true;
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30)); string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30));
DialogController dialogController = EditorGUILayout.ObjectField(new GUIContent("Dialog", "Dialog to display story text with"),
t.dialogController,
typeof(DialogController), true) as DialogController;
Character character = EditorGUILayout.ObjectField(new GUIContent("Character", "Character to display in dialog"), Character character = EditorGUILayout.ObjectField(new GUIContent("Character", "Character to display in dialog"),
t.character, t.character,
typeof(Character), true) as Character; typeof(Character), true) as Character;
@ -39,7 +35,6 @@ namespace Fungus.Script
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject(t, "Set Say"); Undo.RecordObject(t, "Set Say");
t.dialogController = dialogController;
t.character = character; t.character = character;
t.storyText = text; t.storyText = text;
t.displayOnce = displayOnce; t.displayOnce = displayOnce;

6
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -178,6 +178,12 @@ namespace Fungus.Script
fungusScript.selectedCommandIndex = selectedCommandIndex; fungusScript.selectedCommandIndex = selectedCommandIndex;
} }
if (selectedCommandIndex >= commandTypes.Count)
{
EditorGUILayout.EndHorizontal();
return;
}
System.Type selectedType = commandTypes[selectedCommandIndex]; System.Type selectedType = commandTypes[selectedCommandIndex];
if (fungusScript.selectedSequence == null || if (fungusScript.selectedSequence == null ||
selectedType == null) selectedType == null)

1
Assets/Fungus/FungusScript/Scripts/Sequence.cs

@ -134,6 +134,7 @@ namespace Fungus.Script
{ {
activeCommand = null; activeCommand = null;
fungusScript.executingSequence = null; fungusScript.executingSequence = null;
fungusScript.selectedSequence = null;
} }
} }
} }

Loading…
Cancel
Save