Browse Source

Integrated Say & Choose dialog pull request from lynxelia

[Tweaked the image sizes to avoid horizontal scroll bar appearing in
insepctor]
[Reverted changes to .gitignore file]
master
chrisgregan 10 years ago
parent
commit
ba8d7f430d
  1. 20
      Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
  2. 8
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs
  3. 55
      Assets/Fungus/Dialog/Editor/ChooseEditor.cs
  4. 81
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  5. 2
      Assets/Fungus/Dialog/Scripts/Character.cs
  6. 13
      Assets/Fungus/Dialog/Scripts/Commands/Choose.cs
  7. 20
      Assets/Fungus/Dialog/Scripts/Commands/Say.cs

20
Assets/Fungus/Dialog/Editor/AddOptionEditor.cs

@ -7,14 +7,14 @@ using Rotorz.ReorderableList;
namespace Fungus
{
[CustomEditor (typeof(AddOption))]
public class AddOptionEditor : SetVariableEditor
{
protected SerializedProperty optionTextProp;
protected SerializedProperty hideOnSelectedProp;
protected SerializedProperty targetSequenceProp;
protected override void OnEnable()
{
base.OnEnable();
@ -22,26 +22,28 @@ namespace Fungus
hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected");
targetSequenceProp = serializedObject.FindProperty("targetSequence");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
AddOption t = target as AddOption;
EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button."));
SequenceEditor.SequenceField(targetSequenceProp,
new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."),
new GUIContent("<Continue>"),
t.GetFungusScript());
EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."));
serializedObject.ApplyModifiedProperties();
base.DrawCommandGUI();
serializedObject.Update();
EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."));
serializedObject.ApplyModifiedProperties();
}
}
}

8
Assets/Fungus/Dialog/Editor/CharacterEditor.cs

@ -12,6 +12,8 @@ namespace Fungus
protected SerializedProperty nameTextProp;
protected SerializedProperty nameColorProp;
protected SerializedProperty sayDialogBoxProp;
protected SerializedProperty chooseDialogBoxProp;
protected SerializedProperty profileSpriteProp;
protected SerializedProperty soundEffectProp;
protected SerializedProperty notesProp;
@ -20,6 +22,8 @@ namespace Fungus
{
nameTextProp = serializedObject.FindProperty ("nameText");
nameColorProp = serializedObject.FindProperty ("nameColor");
sayDialogBoxProp = serializedObject.FindProperty ("sayDialogBox");
chooseDialogBoxProp = serializedObject.FindProperty ("chooseDialogBox");
profileSpriteProp = serializedObject.FindProperty ("profileSprite");
soundEffectProp = serializedObject.FindProperty ("soundEffect");
notesProp = serializedObject.FindProperty ("notes");
@ -43,6 +47,8 @@ namespace Fungus
EditorGUILayout.PropertyField(nameTextProp, new GUIContent("Name Text", "Name of the character display in the dialog"));
EditorGUILayout.PropertyField(nameColorProp, new GUIContent("Name Color", "Color of name text display in the dialog"));
EditorGUILayout.PropertyField(sayDialogBoxProp, new GUIContent("Say Dialog", "Say dialog box this character should use"));
EditorGUILayout.PropertyField(chooseDialogBoxProp, new GUIContent("Choose Dialog", "Choose dialog box this character should use"));
EditorGUILayout.PropertyField(profileSpriteProp, new GUIContent("Image", "Character image sprite to display in the dialog"));
EditorGUILayout.PropertyField(soundEffectProp, new GUIContent("Sound Effect", "Sound to play when the character is talking. Overrides the setting in the Dialog."));
EditorGUILayout.PropertyField(notesProp, new GUIContent("Notes", "Notes about this story character (personality, attibutes, etc.)"));
@ -56,7 +62,7 @@ namespace Fungus
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
float aspect = (float)t.profileSprite.texture.width / (float)t.profileSprite.texture.height;
Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(150), GUILayout.ExpandWidth(false));
Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(250), GUILayout.ExpandWidth(true));
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();

55
Assets/Fungus/Dialog/Editor/ChooseEditor.cs

@ -7,18 +7,18 @@ using Rotorz.ReorderableList;
namespace Fungus
{
[CustomEditor (typeof(Choose))]
public class ChooseEditor : CommandEditor
{
static public bool showTagHelp;
protected SerializedProperty chooseTextProp;
protected SerializedProperty characterProp;
protected SerializedProperty chooseDialogProp;
protected SerializedProperty voiceOverClipProp;
protected SerializedProperty timeoutDurationProp;
protected virtual void OnEnable()
{
chooseTextProp = serializedObject.FindProperty("chooseText");
@ -27,27 +27,46 @@ namespace Fungus
voiceOverClipProp = serializedObject.FindProperty("voiceOverClip");
timeoutDurationProp = serializedObject.FindProperty("timeoutDuration");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<ChooseDialog>(chooseDialogProp,
new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"),
new GUIContent("<Default>"),
ChooseDialog.activeDialogs);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(chooseTextProp);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
{
showTagHelp = !showTagHelp;
}
EditorGUILayout.EndHorizontal();
if (showTagHelp)
{
SayEditor.DrawTagHelpLabel();
}
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(chooseTextProp);
EditorGUILayout.Separator();
EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed"));
EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit."));
Choose t = target as Choose;
@ -58,30 +77,12 @@ namespace Fungus
Texture2D characterTexture = t.character.profileSprite.texture;
float aspect = (float)characterTexture.width / (float)characterTexture.height;
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false));
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor;
characterEditor.DrawPreview(previewRect, characterTexture);
DestroyImmediate(characterEditor);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<ChooseDialog>(chooseDialogProp,
new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"),
new GUIContent("<None>"),
ChooseDialog.activeDialogs);
EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed"));
EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit."));
serializedObject.ApplyModifiedProperties();
}
}

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

@ -7,12 +7,12 @@ using Rotorz.ReorderableList;
namespace Fungus
{
[CustomEditor (typeof(Say))]
public class SayEditor : CommandEditor
{
static public bool showTagHelp;
static public void DrawTagHelpLabel()
{
string tagsText = "\t{b} Bold Text {/b}\n" +
@ -31,14 +31,14 @@ namespace Fungus
float pixelHeight = EditorStyles.miniLabel.CalcHeight(new GUIContent(tagsText), EditorGUIUtility.currentViewWidth);
EditorGUILayout.SelectableLabel(tagsText, EditorStyles.miniLabel, GUILayout.MinHeight(pixelHeight));
}
protected SerializedProperty storyTextProp;
protected SerializedProperty characterProp;
protected SerializedProperty sayDialogProp;
protected SerializedProperty voiceOverClipProp;
protected SerializedProperty showAlwaysProp;
protected SerializedProperty showCountProp;
protected virtual void OnEnable()
{
storyTextProp = serializedObject.FindProperty("storyText");
@ -48,66 +48,69 @@ namespace Fungus
showAlwaysProp = serializedObject.FindProperty("showAlways");
showCountProp = serializedObject.FindProperty("showCount");
}
public override void DrawCommandGUI()
{
serializedObject.Update();
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<SayDialog>(sayDialogProp,
new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"),
new GUIContent("<Default>"),
SayDialog.activeDialogs);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(storyTextProp);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
{
showTagHelp = !showTagHelp;
}
EditorGUILayout.EndHorizontal();
if (showTagHelp)
{
DrawTagHelpLabel();
}
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(storyTextProp);
EditorGUILayout.Separator();
EditorGUILayout.PropertyField(voiceOverClipProp,
new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"));
EditorGUILayout.PropertyField(showAlwaysProp);
if (showAlwaysProp.boolValue == false)
{
EditorGUILayout.PropertyField(showCountProp);
}
Say t = target as Say;
if (t.character != null &&
t.character.profileSprite != null &&
t.character.profileSprite.texture != null)
{
Texture2D characterTexture = t.character.profileSprite.texture;
float aspect = (float)characterTexture.width / (float)characterTexture.height;
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false));
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor;
characterEditor.DrawPreview(previewRect, characterTexture);
DestroyImmediate(characterEditor);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<SayDialog>(sayDialogProp,
new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"),
new GUIContent("<None>"),
SayDialog.activeDialogs);
EditorGUILayout.PropertyField(voiceOverClipProp);
EditorGUILayout.PropertyField(showAlwaysProp);
if (showAlwaysProp.boolValue == false)
{
EditorGUILayout.PropertyField(showCountProp);
}
serializedObject.ApplyModifiedProperties();
}
}

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

@ -10,6 +10,8 @@ namespace Fungus
{
public string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad")
public Color nameColor = Color.white;
public SayDialog sayDialogBox;
public ChooseDialog chooseDialogBox;
public Sprite profileSprite;
public AudioClip soundEffect;

13
Assets/Fungus/Dialog/Scripts/Commands/Choose.cs

@ -44,8 +44,17 @@ namespace Fungus
showBasicGUI = false;
if (chooseDialog == null)
{
// Try to get any SayDialog in the scene
chooseDialog = GameObject.FindObjectOfType<ChooseDialog>();
if ( character != null ) {
// Try to get character's choose box
chooseDialog = character.chooseDialogBox;
}
if (chooseDialog == null)
{
// Try to get any SayDialog in the scene
chooseDialog = GameObject.FindObjectOfType<ChooseDialog>();
}
if (chooseDialog == null)
{
showBasicGUI = true;

20
Assets/Fungus/Dialog/Scripts/Commands/Say.cs

@ -48,10 +48,19 @@ namespace Fungus
showBasicGUI = false;
if (sayDialog == null)
{
// Try to get any SayDialog in the scene
sayDialog = GameObject.FindObjectOfType<SayDialog>();
if ( character != null ) {
// Try to get character's dialog box
sayDialog = character.sayDialogBox;
}
if (sayDialog == null)
{
// Try to get any SayDialog in the scene
sayDialog = GameObject.FindObjectOfType<SayDialog>();
}
if (sayDialog == null)
{
// No custom dialog box exists, just use basic gui
showBasicGUI = true;
return;
}
@ -77,7 +86,12 @@ namespace Fungus
public override string GetSummary()
{
return "\"" + storyText + "\"";
string namePrefix = "";
if (character != null)
{
namePrefix = character.nameText + ": ";
}
return namePrefix + "\"" + storyText + "\"";
}
protected virtual void OnGUI()

Loading…
Cancel
Save