Browse Source

Initial If, Else & EndIf commands with indenting

master
chrisgregan 11 years ago
parent
commit
240bf9667b
  1. 29
      Assets/Fungus/FungusScript/Commands/Else.cs
  2. 8
      Assets/Fungus/FungusScript/Commands/Else.cs.meta
  3. 24
      Assets/Fungus/FungusScript/Commands/EndIf.cs
  4. 8
      Assets/Fungus/FungusScript/Commands/EndIf.cs.meta
  5. 5
      Assets/Fungus/FungusScript/Commands/If.cs
  6. 17
      Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs
  7. 14
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  8. 20
      Assets/Fungus/FungusScript/Scripts/FungusCommand.cs
  9. BIN
      Assets/Shuttle/ShuttleGame.unity

29
Assets/Fungus/FungusScript/Commands/Else.cs

@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[CommandInfo("Scripting",
"Else",
"Marks the start of a sequence block to be executed when the preceding If statement is false.",
253, 253, 150)]
public class Else : FungusCommand
{
public override void OnEnter()
{
Continue();
}
public override int GetPreIndent()
{
return -1;
}
public override int GetPostIndent()
{
return 1;
}
}
}

8
Assets/Fungus/FungusScript/Commands/Else.cs.meta

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

24
Assets/Fungus/FungusScript/Commands/EndIf.cs

@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[CommandInfo("Scripting",
"EndIf",
"Marks the end of an If statement block.",
253, 253, 150)]
public class EndIf : FungusCommand
{
public override void OnEnter()
{
Continue();
}
public override int GetPreIndent()
{
return -1;
}
}
}

8
Assets/Fungus/FungusScript/Commands/EndIf.cs.meta

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

5
Assets/Fungus/FungusScript/Commands/If.cs

@ -239,6 +239,11 @@ namespace Fungus.Script
{ {
return (variable == this.variable); return (variable == this.variable);
} }
public override int GetPostIndent()
{
return 1;
}
} }
} }

17
Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs

@ -146,6 +146,18 @@ namespace Fungus.Script
error = true; error = true;
} }
float indentWidth = 20;
for (int i = 0; i < command.indentLevel; ++i)
{
Rect indentRect = position;
indentRect.x += i * indentWidth;
indentRect.width = indentWidth + 1;
indentRect.y -= 2;
indentRect.height += 5;
GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f, 0.1f);
GUI.Box(indentRect, "");
}
if (!command.enabled) if (!command.enabled)
{ {
GUI.backgroundColor = Color.grey; GUI.backgroundColor = Color.grey;
@ -164,6 +176,7 @@ namespace Fungus.Script
float buttonWidth = Mathf.Max(commandStyle.CalcSize(new GUIContent(commandName)).x, 80f); float buttonWidth = Mathf.Max(commandStyle.CalcSize(new GUIContent(commandName)).x, 80f);
Rect buttonRect = position; Rect buttonRect = position;
buttonRect.x += command.indentLevel * indentWidth;
buttonRect.width = buttonWidth; buttonRect.width = buttonWidth;
buttonRect.y -= 2; buttonRect.y -= 2;
buttonRect.height += 5; buttonRect.height += 5;
@ -171,8 +184,8 @@ namespace Fungus.Script
GUI.Box(buttonRect, commandName, commandStyle); GUI.Box(buttonRect, commandName, commandStyle);
Rect summaryRect = position; Rect summaryRect = position;
summaryRect.x += buttonWidth + 5; summaryRect.x = buttonRect.x + buttonWidth + 5;
summaryRect.width -= (buttonWidth + 5); summaryRect.width = position.width - buttonWidth - 5;
if (!Application.isPlaying && if (!Application.isPlaying &&
Event.current.type == EventType.MouseDown && Event.current.type == EventType.MouseDown &&

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

@ -43,8 +43,9 @@ namespace Fungus.Script
sequence.description = desc; sequence.description = desc;
} }
ReorderableListGUI.Title("Command Sequence"); UpdateIndentLevels(sequence);
ReorderableListGUI.Title("Command Sequence");
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); SerializedProperty commandListProperty = serializedObject.FindProperty("commandList");
FungusCommandListAdaptor adaptor = new FungusCommandListAdaptor(commandListProperty, 0); FungusCommandListAdaptor adaptor = new FungusCommandListAdaptor(commandListProperty, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, 0); ReorderableListControl.DrawControlFromState(adaptor, null, 0);
@ -156,6 +157,17 @@ namespace Fungus.Script
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
void UpdateIndentLevels(Sequence sequence)
{
int indentLevel = 0;
foreach(FungusCommand command in sequence.commandList)
{
indentLevel += command.GetPreIndent();
command.indentLevel = Math.Max(indentLevel, 0);
indentLevel += command.GetPostIndent();
}
}
static public Sequence SequenceField(GUIContent label, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) static public Sequence SequenceField(GUIContent label, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence)
{ {
if (fungusScript == null) if (fungusScript == null)

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

@ -23,6 +23,7 @@ namespace Fungus.Script
public string CommandName { get; set; } public string CommandName { get; set; }
public string HelpText { get; set; } public string HelpText { get; set; }
public Color ButtonColor { get; set; } public Color ButtonColor { get; set; }
public Color IndentOffset { get; set; }
} }
[RequireComponent(typeof(Sequence))] [RequireComponent(typeof(Sequence))]
@ -37,6 +38,9 @@ namespace Fungus.Script
[HideInInspector] [HideInInspector]
public Sequence parentSequence; public Sequence parentSequence;
[HideInInspector]
public int indentLevel;
public virtual void Start() public virtual void Start()
{ {
parentSequence = GetComponent<Sequence>(); parentSequence = GetComponent<Sequence>();
@ -117,6 +121,22 @@ namespace Fungus.Script
{ {
return ""; return "";
} }
/**
* Indent offset for this command.
*/
public virtual int GetPreIndent()
{
return 0;
}
/**
* Indent offset for subsequent commands.
*/
public virtual int GetPostIndent()
{
return 0;
}
} }
} }

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save