11 changed files with 198 additions and 175 deletions
@ -0,0 +1,115 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
[CommandCategory("Dialog")] |
||||
[HelpText("Presents a list of options for the player to choose from, with an optional timeout. Add options using preceding AddOption commands.")] |
||||
public class Choose : FungusCommand |
||||
{ |
||||
public Dialog dialog; |
||||
static public Dialog activeDialog; |
||||
|
||||
public class Option |
||||
{ |
||||
public string optionText; |
||||
public Sequence targetSequence; |
||||
} |
||||
|
||||
static public List<Option> options = new List<Option>(); |
||||
|
||||
public string chooseText; |
||||
public Character character; |
||||
public float timeoutDuration; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
// Remember active dialog between Choose calls |
||||
if (dialog == null) |
||||
{ |
||||
if (Choose.activeDialog == null) |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
else |
||||
{ |
||||
dialog = Choose.activeDialog; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
activeDialog = dialog; |
||||
} |
||||
|
||||
dialog.ShowDialog(true); |
||||
|
||||
dialog.SetCharacter(character); |
||||
|
||||
if (options.Count == 0) |
||||
{ |
||||
Continue(); |
||||
} |
||||
else |
||||
{ |
||||
List<Dialog.Option> dialogOptions = new List<Dialog.Option>(); |
||||
foreach (Option sayOption in options) |
||||
{ |
||||
Dialog.Option dialogOption = new Dialog.Option(); |
||||
dialogOption.text = sayOption.optionText; |
||||
Sequence onSelectSequence = sayOption.targetSequence; |
||||
|
||||
dialogOption.onSelect = delegate { |
||||
|
||||
dialog.ShowDialog(false); |
||||
|
||||
if (onSelectSequence == null) |
||||
{ |
||||
Continue (); |
||||
} |
||||
else |
||||
{ |
||||
ExecuteSequence(onSelectSequence); |
||||
} |
||||
}; |
||||
|
||||
dialogOptions.Add(dialogOption); |
||||
} |
||||
|
||||
options.Clear(); |
||||
|
||||
dialog.Choose(chooseText, dialogOptions, timeoutDuration, delegate { |
||||
dialog.ShowDialog(false); |
||||
Continue(); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
string summary = ""; |
||||
if (character != null) |
||||
{ |
||||
summary = character.characterName + ": "; |
||||
} |
||||
|
||||
summary += "\"" + chooseText + "\""; |
||||
|
||||
return summary; |
||||
} |
||||
|
||||
public override void GetConnectedSequences (ref List<Sequence> connectedSequences) |
||||
{ |
||||
foreach (Option option in options) |
||||
{ |
||||
if (option.targetSequence != null) |
||||
{ |
||||
connectedSequences.Add(option.targetSequence); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 7c2d26a03c0c04cad97b8739546dd6ed |
||||
guid: d1dc785fd3508440db335f3b5654c96c |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
@ -1,36 +0,0 @@
|
||||
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 Dialog dialogController; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (dialogController != null) |
||||
{ |
||||
Say.dialog = dialogController; |
||||
} |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (dialogController == null) |
||||
{ |
||||
return "Error: No dialog selected"; |
||||
} |
||||
|
||||
return dialogController.name; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@
|
||||
using UnityEditor; |
||||
using UnityEditorInternal; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Rotorz.ReorderableList; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
|
||||
[CustomEditor (typeof(Choose))] |
||||
public class ChooseEditor : FungusCommandEditor |
||||
{ |
||||
public override void DrawCommandGUI() |
||||
{ |
||||
Choose t = target as Choose; |
||||
|
||||
EditorGUI.BeginChangeCheck(); |
||||
|
||||
EditorGUILayout.PrefixLabel(new GUIContent("Choose Text", "Text to display in dialog")); |
||||
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea); |
||||
sayStyle.wordWrap = true; |
||||
string chooseText = EditorGUILayout.TextArea(t.chooseText, sayStyle, GUILayout.MinHeight(30)); |
||||
|
||||
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"), |
||||
new GUIContent("<None>"), |
||||
t.character); |
||||
|
||||
Dialog dialog = FungusCommandEditor.ObjectField<Dialog>(new GUIContent("Dialog", "Dialog to use when displaying choices"), |
||||
new GUIContent("<Default>"), |
||||
t.dialog); |
||||
|
||||
float timeoutDuration = EditorGUILayout.FloatField(new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit."), t.timeoutDuration); |
||||
|
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
Undo.RecordObject(t, "Set Choose"); |
||||
t.chooseText = chooseText; |
||||
t.character = character; |
||||
t.dialog = dialog; |
||||
t.timeoutDuration = timeoutDuration; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: f77de3c7e9e264872bfb94713e4c4844 |
||||
guid: 9596f36d69e664a97936a2f6409eb495 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
@ -1,31 +0,0 @@
|
||||
using UnityEditor; |
||||
using UnityEditorInternal; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using Rotorz.ReorderableList; |
||||
|
||||
namespace Fungus.Script |
||||
{ |
||||
|
||||
[CustomEditor (typeof(SetDialog))] |
||||
public class SetDialogEditor : FungusCommandEditor |
||||
{ |
||||
public override void DrawCommandGUI() |
||||
{ |
||||
SetDialog t = target as SetDialog; |
||||
|
||||
EditorGUI.BeginChangeCheck(); |
||||
|
||||
Dialog dialogController = FungusCommandEditor.ObjectField<Dialog>(new GUIContent("Active Dialog", "Dialog to use when displaying Say command story text"), |
||||
new GUIContent("<None>"), |
||||
t.dialogController); |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
Undo.RecordObject(t, "Set Dialog"); |
||||
t.dialogController = dialogController; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
Binary file not shown.
Loading…
Reference in new issue