Browse Source

Moved command properties to inspector. Fixed dialog bugs.

master
chrisgregan 11 years ago
parent
commit
7a45f92873
  1. 5
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  2. 13
      Assets/Fungus/Dialog/Scripts/ChooseDialog.cs
  3. 4
      Assets/Fungus/Dialog/Scripts/Dialog.cs
  4. 123
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  5. 8
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  6. 8
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  7. 5
      Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs
  8. 3
      Assets/Fungus/FungusScript/Scripts/FungusCommand.cs
  9. 2
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  10. 1
      Assets/Fungus/FungusScript/Scripts/Sequence.cs
  11. BIN
      Assets/Shuttle/ShuttleGame.unity

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

@ -55,8 +55,7 @@ namespace Fungus.Script
EditorGUILayout.BeginHorizontal();
float minHeight = sayStyle.CalcHeight(new GUIContent(t.storyText), EditorGUIUtility.currentViewWidth);
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(minHeight + 10), GUILayout.ExpandHeight(true));
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(60));
if (t.character != null &&
t.character.characterImage != null &&
@ -65,7 +64,7 @@ namespace Fungus.Script
Texture2D characterTexture = t.character.characterImage.texture;
float aspect = (float)characterTexture.width / (float)characterTexture.height;
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(40), GUILayout.ExpandWidth(false));
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false));
CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor;
if (characterEditor != null)
{

13
Assets/Fungus/Dialog/Scripts/ChooseDialog.cs

@ -11,7 +11,7 @@ namespace Fungus.Script
[ExecuteInEditMode]
public class ChooseDialog : Dialog
{
public Slider slider;
public Slider timeoutSlider;
public class Option
{
@ -36,6 +36,12 @@ namespace Fungus.Script
activeDialogs.Remove(this);
}
public override void ShowDialog (bool visible)
{
base.ShowDialog (visible);
timeoutSlider.gameObject.SetActive(false);
}
public void Choose(string text, List<Option> options, float timeoutDuration, Action onTimeout)
{
Clear();
@ -48,6 +54,7 @@ namespace Fungus.Script
if (timeoutDuration > 0)
{
timeoutSlider.gameObject.SetActive(true);
StartCoroutine(WaitForTimeout(timeoutDuration, onTimeout));
}
};
@ -61,10 +68,10 @@ namespace Fungus.Script
while (elapsedTime < timeoutDuration)
{
if (slider != null)
if (timeoutSlider != null)
{
float t = elapsedTime / timeoutDuration;
slider.value = t;
timeoutSlider.value = t;
}
elapsedTime += Time.deltaTime;

4
Assets/Fungus/Dialog/Scripts/Dialog.cs

@ -59,7 +59,7 @@ namespace Fungus.Script
public string param = "";
}
public void ShowDialog(bool visible)
public virtual void ShowDialog(bool visible)
{
if (dialogCanvas != null)
{
@ -214,7 +214,7 @@ namespace Fungus.Script
if (italicActive)
{
start += "<i>";
end += "</i>";
end = "</i>" + end; // Have to nest tags correctly
}
if (colorActive)
{

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

@ -21,16 +21,15 @@ namespace Fungus.Script
}
}
public virtual void DrawInspectorGUI()
public virtual void DrawCommandRowGUI()
{
FungusCommand t = target as FungusCommand;
if (t == null)
{
return;
}
GUILayout.BeginVertical();
FungusScript fungusScript = t.GetFungusScript();
GUILayout.BeginHorizontal();
@ -53,7 +52,7 @@ namespace Fungus.Script
{
GUI.backgroundColor = Color.red;
}
else if (t.expanded)
else if (fungusScript.selectedCommand == t)
{
GUI.backgroundColor = Color.yellow;
}
@ -61,8 +60,7 @@ namespace Fungus.Script
string commandName = FungusScriptEditor.GetCommandName(t.GetType());
if (GUILayout.Button(commandName, EditorStyles.miniButton, GUILayout.MinWidth(80)))
{
Undo.RecordObject(t, "Toggle Expanded");
t.expanded = !t.expanded;
fungusScript.selectedCommand = t;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
}
GUI.backgroundColor = Color.white;
@ -83,74 +81,87 @@ namespace Fungus.Script
GUILayout.EndHorizontal();
if (t.expanded)
if (Event.current.type == EventType.Repaint &&
t.IsExecuting())
{
GUILayout.BeginHorizontal();
Rect rect = GUILayoutUtility.GetLastRect();
GLDraw.DrawBox(rect, Color.green, 1.5f);
}
}
GUILayout.FlexibleSpace();
public virtual void DrawCommandInspectorGUI()
{
FungusCommand t = target as FungusCommand;
if (t == null)
{
return;
}
bool enabled = GUILayout.Toggle(t.enabled, "");
if (t.enabled != enabled)
{
Undo.RecordObject(t, "Set Enabled");
t.enabled = enabled;
}
FungusScript fungusScript = t.GetFungusScript();
if (GUILayout.Button("Up", EditorStyles.miniButtonLeft))
{
UnityEditorInternal.ComponentUtility.MoveComponentUp(t);
}
if (GUILayout.Button("Down", EditorStyles.miniButtonMid))
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginHorizontal();
string commandName = FungusScriptEditor.GetCommandName(t.GetType());
GUILayout.Label(commandName, EditorStyles.largeLabel);
GUILayout.FlexibleSpace();
bool enabled = GUILayout.Toggle(t.enabled, "");
if (t.enabled != enabled)
{
Undo.RecordObject(t, "Set Enabled");
t.enabled = enabled;
}
if (GUILayout.Button("Up", EditorStyles.miniButtonLeft))
{
UnityEditorInternal.ComponentUtility.MoveComponentUp(t);
}
if (GUILayout.Button("Down", EditorStyles.miniButtonMid))
{
UnityEditorInternal.ComponentUtility.MoveComponentDown(t);
}
if (fungusScript != null)
{
if (GUILayout.Button("Copy", EditorStyles.miniButtonMid))
{
UnityEditorInternal.ComponentUtility.MoveComponentDown(t);
fungusScript.copyCommand = t;
}
FungusScript fungusScript = t.GetFungusScript();
if (fungusScript != null)
if (fungusScript.copyCommand != null)
{
if (GUILayout.Button("Copy", EditorStyles.miniButtonMid))
{
fungusScript.copyCommand = t;
}
if (fungusScript.copyCommand != null)
if (GUILayout.Button("Paste", EditorStyles.miniButtonMid))
{
if (GUILayout.Button("Paste", EditorStyles.miniButtonMid))
{
CopyComponent<FungusCommand>(fungusScript.copyCommand, t.gameObject);
}
CopyComponent<FungusCommand>(fungusScript.copyCommand, t.gameObject);
}
}
if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
{
Undo.DestroyObjectImmediate(t);
return;
}
}
if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
{
Undo.DestroyObjectImmediate(t);
return;
}
GUILayout.EndHorizontal();
GUILayout.EndHorizontal();
DrawCommandGUI();
EditorGUILayout.Separator();
DrawCommandGUI();
EditorGUILayout.Separator();
EditorGUILayout.Separator();
if (t.errorMessage.Length > 0)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
}
if (t.errorMessage.Length > 0)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
}
GUILayout.EndVertical();
if (Event.current.type == EventType.Repaint &&
t.IsExecuting())
{
Rect rect = GUILayoutUtility.GetLastRect();
GLDraw.DrawBox(rect, Color.green, 1.5f);
}
}
public virtual void DrawCommandGUI()

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

@ -63,7 +63,11 @@ namespace Fungus.Script
EditorGUILayout.Separator();
if (t.selectedCommand != null)
{
FungusCommandEditor commandEditor = Editor.CreateEditor(t.selectedCommand) as FungusCommandEditor;
commandEditor.DrawCommandInspectorGUI();
}
EditorGUILayout.Separator();
@ -105,7 +109,7 @@ namespace Fungus.Script
foreach (FungusCommand command in commands)
{
FungusCommandEditor commandEditor = Editor.CreateEditor(command) as FungusCommandEditor;
commandEditor.DrawInspectorGUI();
commandEditor.DrawCommandRowGUI();
}
if (Application.isPlaying)

8
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -202,6 +202,7 @@ namespace Fungus.Script
Sequence newSequence = fungusScript.CreateSequence(fungusScript.scriptScrollPos);
Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence");
fungusScript.selectedSequence = newSequence;
fungusScript.selectedCommand = null;
}
if (fungusScript.selectedSequence == null)
@ -215,6 +216,7 @@ namespace Fungus.Script
{
Undo.DestroyObjectImmediate(fungusScript.selectedSequence.gameObject);
fungusScript.selectedSequence = null;
fungusScript.selectedCommand = null;
}
if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight))
{
@ -228,6 +230,7 @@ namespace Fungus.Script
Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence");
fungusScript.selectedSequence = sequenceCopy;
fungusScript.selectedCommand = null;
}
}
@ -271,6 +274,7 @@ namespace Fungus.Script
{
FungusScript fungusScript = s.GetFungusScript();
fungusScript.selectedSequence = s;
fungusScript.selectedCommand = null;
Selection.activeGameObject = fungusScript.gameObject;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
@ -303,7 +307,9 @@ namespace Fungus.Script
FungusCommand[] commands = sequence.GetComponentsInChildren<FungusCommand>();
foreach (FungusCommand command in commands)
{
bool highlight = command.IsExecuting() || (sequenceIsSelected && command.expanded);
bool commandIsSelected = (fungusScript.selectedCommand == command);
bool highlight = command.IsExecuting() || (sequenceIsSelected && commandIsSelected);
if (highlightedOnly && !highlight ||
!highlightedOnly && highlight)

5
Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs

@ -195,12 +195,13 @@ namespace Fungus.Script
else
{
// Is an expanded command referencing this variable?
if (fungusScript.selectedSequence != null)
if (fungusScript.selectedSequence != null &&
fungusScript.selectedCommand != null)
{
FungusCommand[] commands = fungusScript.selectedSequence.GetComponents<FungusCommand>();
foreach (FungusCommand command in commands)
{
if (command.expanded &&
if (fungusScript.selectedCommand == command &&
command.HasReference(variable))
{
highlight = true;

3
Assets/Fungus/FungusScript/Scripts/FungusCommand.cs

@ -50,9 +50,6 @@ namespace Fungus.Script
[HideInInspector]
public Sequence parentSequence;
[HideInInspector]
public bool expanded;
public virtual void Start()
{
parentSequence = GetComponent<Sequence>();

2
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -33,6 +33,8 @@ namespace Fungus.Script
public Sequence selectedSequence;
public FungusCommand selectedCommand;
public bool startAutomatically = false;
public List<FungusVariable> variables = new List<FungusVariable>();

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

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

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save