Browse Source

AddCommand button and help text

master
chrisgregan 10 years ago
parent
commit
93836f860b
  1. 2
      Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs
  2. 58
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  3. 3
      Assets/Fungus/VisualScripting/Call.cs
  4. 18
      Assets/Fungus/VisualScripting/FungusCommand.cs
  5. 11
      Assets/Fungus/VisualScripting/FungusScript.cs
  6. 4
      Assets/Fungus/VisualScripting/Option.cs
  7. 3
      Assets/Fungus/VisualScripting/Say.cs
  8. 4
      Assets/Fungus/VisualScripting/Set.cs
  9. 4
      Assets/Fungus/VisualScripting/View.cs
  10. 2
      Assets/Fungus/VisualScripting/Wait.cs
  11. BIN
      Assets/Shuttle/ShuttleGame.unity

2
Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs

@ -38,7 +38,7 @@ namespace Fungus.Script
}
GUIStyle labelStyle = EditorStyles.miniLabel;
GUILayout.Label(t.GetDescription().Replace("\n", "").Replace("\r", ""), labelStyle);
GUILayout.Label(t.GetSummary().Replace("\n", "").Replace("\r", ""), labelStyle);
GUILayout.FlexibleSpace();

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

@ -135,10 +135,12 @@ namespace Fungus.Script
{
DrawSequenceGUI(t.selectedSequence);
if (!Application.isPlaying)
{
EditorGUILayout.Separator();
DrawAddCommandGUI(t.selectedSequence);
}
}
serializedObject.ApplyModifiedProperties();
}
@ -171,11 +173,63 @@ namespace Fungus.Script
public void DrawAddCommandGUI(Sequence sequence)
{
// FungusScript t = target as FungusScript;
FungusScript t = target as FungusScript;
GUI.backgroundColor = Color.yellow;
GUILayout.Box("Add Command", GUILayout.ExpandWidth(true));
GUI.backgroundColor = Color.white;
// Build list of categories
List<System.Type> commandTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList();
if (commandTypes.Count == 0)
{
return;
}
List<string> commandNames = new List<string>();
foreach(System.Type type in commandTypes)
{
commandNames.Add(type.Name);
}
EditorGUI.BeginChangeCheck();
int selectedCommandIndex = EditorGUILayout.Popup("Command", t.selectedCommandIndex, commandNames.ToArray());
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Select Command");
t.selectedCommandIndex = selectedCommandIndex;
}
System.Type selectedType = commandTypes[selectedCommandIndex];
if (selectedType == null)
{
return;
}
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence")))
{
Undo.AddComponent(sequence.gameObject, selectedType);
}
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
object[] attributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false);
foreach (object obj in attributes)
{
HelpTextAttribute helpTextAttr = obj as HelpTextAttribute;
if (helpTextAttr != null)
{
GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel);
labelStyle.wordWrap = true;
GUILayout.Label(helpTextAttr.HelpText, labelStyle);
break;
}
}
}
public void DrawVariablesGUI()

3
Assets/Fungus/VisualScripting/Call.cs

@ -20,6 +20,7 @@ namespace Fungus.Script
GreaterThanOrEquals // >=
}
[HelpText("Start running another sequence. Can use a variable comparision to decide which sequence to run.")]
public class Call : FungusCommand
{
public CallCondition callCondition;
@ -185,7 +186,7 @@ namespace Fungus.Script
}
}
public override string GetDescription()
public override string GetSummary()
{
if (callCondition == CallCondition.CallAlways)
{

18
Assets/Fungus/VisualScripting/FungusCommand.cs

@ -2,11 +2,22 @@
using UnityEditor;
#endif
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
public class HelpTextAttribute : Attribute
{
public HelpTextAttribute(string helpText)
{
this.HelpText = helpText;
}
public string HelpText { get; set; }
}
[RequireComponent(typeof(Sequence))]
public class FungusCommand : MonoBehaviour
{
@ -88,7 +99,12 @@ namespace Fungus.Script
public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences)
{}
public virtual string GetDescription()
public virtual string GetSummary()
{
return "";
}
public virtual string GetHelpText()
{
return "";
}

11
Assets/Fungus/VisualScripting/FungusScript.cs

@ -11,19 +11,22 @@ namespace Fungus.Script
public class FungusScript : MonoBehaviour
{
public float stepTime;
public Sequence startSequence;
[System.NonSerialized]
public Sequence executingSequence;
[System.NonSerialized]
public FungusCommand copyCommand;
[HideInInspector]
public int selectedCommandIndex;
[HideInInspector]
public Vector2 scrollPos;
public float stepTime;
public Sequence startSequence;
public Sequence selectedSequence;
public bool startAutomatically = false;

4
Assets/Fungus/VisualScripting/Option.cs

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Fungus.Script
{
[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 Option : FungusCommand
{
public enum ShowCondition
@ -76,7 +76,7 @@ namespace Fungus.Script
}
}
public override string GetDescription()
public override string GetSummary()
{
string description = "\"" + optionText + "\"";
if (targetSequence != null)

3
Assets/Fungus/VisualScripting/Say.cs

@ -5,6 +5,7 @@ using System.Collections.Generic;
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
@ -83,7 +84,7 @@ namespace Fungus.Script
});
}
public override string GetDescription()
public override string GetSummary()
{
return "\"" + text + "\"";
}

4
Assets/Fungus/VisualScripting/Set.cs

@ -3,7 +3,7 @@ using System.Collections;
namespace Fungus.Script
{
[HelpText("Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.")]
public class Set : FungusCommand
{
public enum SetOperator
@ -119,7 +119,7 @@ namespace Fungus.Script
Continue();
}
public override string GetDescription()
public override string GetSummary()
{
if (variable == null)
{

4
Assets/Fungus/VisualScripting/View.cs

@ -4,7 +4,7 @@ using System.Collections;
namespace Fungus.Script
{
[HelpText("Moves the camera to a location specified by a View object. Supports Move and Fade transitions over a period of time.")]
public class View : FungusCommand
{
public enum Transition
@ -58,7 +58,7 @@ namespace Fungus.Script
}
}
public override string GetDescription()
public override string GetSummary()
{
string description = "";

2
Assets/Fungus/VisualScripting/Wait.cs

@ -4,7 +4,7 @@ using System.Collections;
namespace Fungus.Script
{
[HelpText("Waits for period of time before executing the next command in the sequence.")]
public class Wait : FungusCommand
{
public float duration;

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save