Browse Source

New dialog option buttons

master
chrisgregan 10 years ago
parent
commit
05a5dc9268
  1. 96
      Assets/Fungus/Dialog/Commands/Say.cs
  2. 5
      Assets/Fungus/Dialog/Editor.meta
  3. 0
      Assets/Fungus/Dialog/Editor/OptionEditor.cs
  4. 0
      Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta
  5. 86
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  6. 0
      Assets/Fungus/Dialog/Editor/SayEditor.cs.meta
  7. 15
      Assets/Fungus/Dialog/Scripts/Character.cs
  8. 8
      Assets/Fungus/Dialog/Scripts/Character.cs.meta
  9. 151
      Assets/Fungus/Dialog/Scripts/DialogController.cs
  10. 51
      Assets/Fungus/FungusScript/Editor/SayEditor.cs
  11. 38
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  12. BIN
      Assets/Shuttle/NewDialog.prefab
  13. 4
      Assets/Shuttle/NewDialog.prefab.meta
  14. BIN
      Assets/Shuttle/NewDialog.unity
  15. 4
      Assets/Shuttle/NewDialog.unity.meta
  16. BIN
      Assets/Shuttle/ShuttleGame.unity

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

@ -9,85 +9,89 @@ 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.")]
public class Say : FungusCommand
{
public enum ShowCondition
public DialogController dialogController;
public Character character;
public string storyText;
public bool displayOnce;
[Serializable]
public class SayOption
{
Always,
Once,
BooleanIsTrue,
BooleanIsFalse
public string optionText;
public Sequence targetSequence;
}
public string character;
public string text;
public ShowCondition showCondition;
public BooleanVariable booleanVariable;
public List<SayOption> options = new List<SayOption>();
public float timeoutDuration;
int executionCount;
public override void OnEnter()
{
Dialog dialog = Game.GetInstance().dialog;
if (dialog == null)
if (dialogController == null)
{
Continue();
return;
}
bool showSayText = true;
if (showCondition == ShowCondition.Always)
if (displayOnce && executionCount > 0)
{
// Always show option
Continue();
return;
}
else if (showCondition == ShowCondition.Once)
{
if (executionCount > 0)
executionCount++;
if (character != null)
{
showSayText = false;
dialogController.SetCharacter(character);
}
}
else
{
if (booleanVariable == null)
if (options.Count > 0)
{
showSayText = false;
}
else
List<DialogController.Option> dialogOptions = new List<DialogController.Option>();
foreach (SayOption sayOption in options)
{
if (showCondition == ShowCondition.BooleanIsTrue &&
booleanVariable.Value != true)
DialogController.Option dialogOption = new DialogController.Option();
dialogOption.text = sayOption.optionText;
Sequence onSelectSequence = sayOption.targetSequence;
dialogOption.onSelect = delegate {
if (onSelectSequence == null)
{
showSayText = false;
Continue ();
}
else if (showCondition == ShowCondition.BooleanIsFalse &&
booleanVariable.Value != false)
else
{
showSayText = false;
}
}
ExecuteSequence(onSelectSequence);
}
};
if (!showSayText)
{
Continue();
return;
dialogOptions.Add(dialogOption);
}
executionCount++;
if (character.Length > 0)
{
dialog.SetCharacter(character);
dialogController.Say(storyText, dialogOptions);
}
dialog.Say (text, delegate {
else
{
dialogController.Say(storyText, delegate {
Continue();
});
}
}
public override string GetSummary()
{
return "\"" + text + "\"";
return "\"" + storyText + "\"";
}
public override void GetConnectedSequences (ref List<Sequence> connectedSequences)
{
foreach (SayOption option in options)
{
connectedSequences.Add(option.targetSequence);
}
}
}

5
Assets/Fungus/Dialog/Editor.meta

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 805471f08101f4ad8a705fc863435758
folderAsset: yes
DefaultImporter:
userData:

0
Assets/Fungus/FungusScript/Editor/OptionEditor.cs → Assets/Fungus/Dialog/Editor/OptionEditor.cs

0
Assets/Fungus/FungusScript/Editor/OptionEditor.cs.meta → Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta

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

@ -0,0 +1,86 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Rotorz.ReorderableList;
namespace Fungus.Script
{
[CustomEditor (typeof(Say))]
public class SayEditor : FungusCommandEditor
{
public override void DrawCommandGUI()
{
serializedObject.Update();
SerializedProperty optionListProperty = serializedObject.FindProperty("options");
Say t = target as Say;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea);
sayStyle.wordWrap = true;
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"),
t.character,
typeof(Character), true) as Character;
bool displayOnce = EditorGUILayout.Toggle(new GUIContent("Display Once", "Display this text once and never show it again."), t.displayOnce);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Say");
t.dialogController = dialogController;
t.character = character;
t.storyText = text;
t.displayOnce = displayOnce;
}
ReorderableListGUI.Title("Options");
ReorderableListGUI.ListField(optionListProperty);
serializedObject.ApplyModifiedProperties();
}
}
[CustomPropertyDrawer (typeof(Say.SayOption))]
public class SayOptionDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty optionTextProp = property.FindPropertyRelative("optionText");
SerializedProperty targetSequenceProp = property.FindPropertyRelative("targetSequence");
Rect optionTextRect = position;
optionTextRect.width *= 0.5f;
Rect targetSequenceRect = position;
targetSequenceRect.width *= 0.5f;
targetSequenceRect.x += optionTextRect.width;
FungusScript fungusScript = FungusScriptWindow.GetFungusScript();
optionTextProp.stringValue = EditorGUI.TextField(optionTextRect, optionTextProp.stringValue);
if (fungusScript != null)
{
targetSequenceProp.objectReferenceValue = SequenceEditor.SequenceField(targetSequenceRect,
new GUIContent("<Continue>"),
fungusScript,
targetSequenceProp.objectReferenceValue as Sequence);
}
EditorGUI.EndProperty();
}
}
}

0
Assets/Fungus/FungusScript/Editor/SayEditor.cs.meta → Assets/Fungus/Dialog/Editor/SayEditor.cs.meta

15
Assets/Fungus/Dialog/Scripts/Character.cs

@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
namespace Fungus.Script
{
public class Character : MonoBehaviour
{
public string characterName;
public Sprite characterImage;
public DialogController.DialogSide dialogSide;
public Color characterColor;
}
}

8
Assets/Fungus/Dialog/Scripts/Character.cs.meta

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

151
Assets/Fungus/Dialog/Scripts/DialogController.cs

@ -5,30 +5,50 @@ using System;
using System.Collections;
using System.Collections.Generic;
public class DialogController : MonoBehaviour
namespace Fungus.Script
{
public Sprite testCharacter;
public class DialogController : MonoBehaviour
{
public enum DialogSide
{
Left,
Right
};
public class Option
{
public string text;
public Action onSelect;
}
public Canvas dialogCanvas;
public List<Button> optionButtons = new List<Button>();
public List<UnityEngine.UI.Button> optionButtons = new List<UnityEngine.UI.Button>();
public Text nameText;
public Text storyText;
public Image continueImage;
public Image leftImage;
public Image rightImage;
public enum ImageSide
List<Action> optionActions = new List<Action>();
public void SetCharacter(Character character)
{
Left,
Right
};
if (character == null)
{
return;
}
SetCharacterImage(character.characterImage, character.dialogSide);
SetCharacterName(character.name, character.characterColor);
}
public void SetCharacterImage(Sprite image, ImageSide side)
public void SetCharacterImage(Sprite image, DialogSide side)
{
if (leftImage != null)
{
if (image != null &&
side == ImageSide.Left)
side == DialogSide.Left)
{
leftImage.sprite = image;
leftImage.enabled = true;
@ -43,7 +63,7 @@ public class DialogController : MonoBehaviour
{
rightImage.sprite = null;
if (image != null &&
side == ImageSide.Right)
side == DialogSide.Right)
{
rightImage.sprite = image;
rightImage.enabled = true;
@ -65,15 +85,55 @@ public class DialogController : MonoBehaviour
}
}
public void SetStoryText(string text)
public void Say(string text, Action onComplete)
{
Clear();
if (storyText != null)
{
storyText.text = text;
}
// TODO: Wait for text to finish writing
ShowContinueIcon(true);
StartCoroutine(WaitForInput(onComplete));
}
public void ShowContinueIcon(bool visible)
public void Say(string text, List<Option> options)
{
Clear();
if (storyText != null)
{
storyText.text = text;
}
ShowContinueIcon(false);
foreach (Option option in options)
{
AddOption(option.text, option.onSelect);
}
}
IEnumerator WaitForInput(Action onComplete)
{
// TODO: Handle touch input
while (!Input.GetMouseButtonDown(0))
{
yield return null;
}
Clear();
if (onComplete != null)
{
onComplete();
}
}
void ShowContinueIcon(bool visible)
{
if (continueImage != null)
{
@ -81,27 +141,47 @@ public class DialogController : MonoBehaviour
}
}
public void ClearOptions()
void Clear()
{
ClearStoryText();
ClearOptions();
}
void ClearStoryText()
{
if (storyText != null)
{
storyText.text = "";
}
}
void ClearOptions()
{
if (optionButtons == null)
{
return;
}
foreach (Button button in optionButtons)
optionActions.Clear();
foreach (UnityEngine.UI.Button button in optionButtons)
{
if (button != null)
{
button.gameObject.SetActive(false);
}
}
}
public void AddOption(string text, Action action)
bool AddOption(string text, Action action)
{
if (optionButtons == null)
{
return;
return false;
}
foreach (Button button in optionButtons)
bool addedOption = false;
foreach (UnityEngine.UI.Button button in optionButtons)
{
if (!button.gameObject.activeSelf)
{
@ -113,37 +193,28 @@ public class DialogController : MonoBehaviour
textComponent.text = text;
}
// TODO: Connect action
optionActions.Add(action);
addedOption = true;
break;
}
}
}
public void Start()
{
SetCharacterImage(testCharacter, ImageSide.Left);
SetCharacterName("Podrick", Color.red);
SetStoryText("Simple story text");
ShowContinueIcon(false);
ClearOptions();
AddOption("Something 1", Callback );
AddOption("Something 2", Callback );
return addedOption;
}
void Callback()
public void SelectOption(int index)
{
if (index < optionActions.Count)
{
Debug.Log ("Callback");
Action optionAction = optionActions[index];
if (optionAction != null)
{
Clear();
optionAction();
}
}
}
}
//public UnityEvent testEvent;
// Write story text over time
// Show character image (with side, fade in?)
// Hide / Show canvas
// Show continue image
// Show one button
// Show button grid
}

51
Assets/Fungus/FungusScript/Editor/SayEditor.cs

@ -1,51 +0,0 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[CustomEditor (typeof(Say))]
public class SayEditor : FungusCommandEditor
{
public override void DrawCommandGUI()
{
Say t = target as Say;
EditorGUI.BeginChangeCheck();
string character = EditorGUILayout.TextField(new GUIContent("Character", "Character to display in dialog"), t.character);
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea);
sayStyle.wordWrap = true;
string text = EditorGUILayout.TextArea(t.text, sayStyle, GUILayout.MinHeight(30));
Say.ShowCondition showCondition = (Say.ShowCondition)EditorGUILayout.EnumPopup(new GUIContent("Show Condition", "Condition when this say text should be visible."), t.showCondition);
BooleanVariable booleanVariable = t.booleanVariable;
if (showCondition == Say.ShowCondition.BooleanIsFalse ||
showCondition == Say.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 Say");
t.character = character;
t.text = text;
t.showCondition = showCondition;
t.booleanVariable = booleanVariable;
}
}
}
}

38
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -47,6 +47,44 @@ namespace Fungus.Script
return result;
}
static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence)
{
if (fungusScript == null)
{
return null;
}
Sequence result = sequence;
// Build dictionary of child sequences
List<GUIContent> sequenceNames = new List<GUIContent>();
int selectedIndex = 0;
sequenceNames.Add(nullLabel);
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>();
for (int i = 0; i < sequences.Length; ++i)
{
sequenceNames.Add(new GUIContent(sequences[i].name));
if (sequence == sequences[i])
{
selectedIndex = i + 1;
}
}
selectedIndex = EditorGUI.Popup(position, selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Option 'None'
}
else
{
result = sequences[selectedIndex - 1];
}
return result;
}
}
}

BIN
Assets/Shuttle/NewDialog.prefab

Binary file not shown.

4
Assets/Shuttle/NewDialog.prefab.meta

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 4417bf892b8c448528ef7c527b82338a
NativeFormatImporter:
userData:

BIN
Assets/Shuttle/NewDialog.unity

Binary file not shown.

4
Assets/Shuttle/NewDialog.unity.meta

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 9ffd6f62d04cb4c33aedde50a56aa90c
DefaultImporter:
userData:

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save