Browse Source

Improved Label & Jump commands in inspector #78

master
chrisgregan 10 years ago
parent
commit
f9f2b175bd
  1. 17
      Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs
  2. 29
      Assets/Fungus/FungusScript/Editor/LabelEditor.cs
  3. 3
      Assets/Fungus/FungusScript/Scripts/Commands/If.cs
  4. 2
      Assets/Fungus/FungusScript/Scripts/Commands/Jump.cs
  5. 2
      Assets/Fungus/FungusScript/Scripts/Commands/Label.cs
  6. 44
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  7. 12
      Assets/Fungus/FungusScript/Scripts/Sequence.cs

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

@ -161,7 +161,8 @@ namespace Fungus
return;
}
bool isComment = command.GetType() == typeof(Comment);
bool isComment = (command.GetType() == typeof(Comment));
bool isLabel = (command.GetType() == typeof(Label));
bool error = false;
string summary = command.GetSummary();
@ -177,7 +178,15 @@ namespace Fungus
{
error = true;
}
summary = "<i>" + summary + "</i>";
if (isComment || isLabel)
{
summary = "<b> " + summary + "</b>";
}
else
{
summary = "<i>" + summary + "</i>";
}
bool commandIsSelected = false;
foreach (Command selectedCommand in fungusScript.selectedCommands)
@ -267,7 +276,7 @@ namespace Fungus
GUI.backgroundColor = commandLabelColor;
if (isComment)
if (isComment || isLabel)
{
GUI.Label(commandLabelRect, "", commandLabelStyle);
}
@ -286,7 +295,7 @@ namespace Fungus
}
Rect summaryRect = new Rect(commandLabelRect);
if (!isComment)
if (!isComment && !isLabel)
{
summaryRect.x += commandNameWidth;
summaryRect.width -= commandNameWidth;

29
Assets/Fungus/FungusScript/Editor/LabelEditor.cs

@ -8,9 +8,11 @@ using System.Linq;
namespace Fungus
{
public class LabelEditor
[CustomEditor (typeof(Label))]
public class LabelEditor : CommandEditor
{
protected SerializedProperty keyProp;
static public void LabelField(SerializedProperty property,
GUIContent labelText,
Sequence sequence)
@ -48,6 +50,29 @@ namespace Fungus
property.objectReferenceValue = labelObjects[selectedIndex];
}
protected virtual void OnEnable()
{
keyProp = serializedObject.FindProperty("key");
}
public override void DrawCommandGUI()
{
Label t = target as Label;
FungusScript fungusScript = t.GetFungusScript();
if (fungusScript == null)
{
return;
}
serializedObject.Update();
EditorGUILayout.PropertyField(keyProp);
keyProp.stringValue = fungusScript.GetUniqueLabelKey(keyProp.stringValue, t);
serializedObject.ApplyModifiedProperties();
}
}
}

3
Assets/Fungus/FungusScript/Scripts/Commands/If.cs

@ -103,9 +103,10 @@ namespace Fungus
Command nextCommand = parentSequence.commandList[i];
// Find next command at same indent level as this If command
// Skip disabled commands & comments
// Skip disabled commands, comments & labels
if (!nextCommand.enabled ||
nextCommand.GetType() == typeof(Comment) ||
nextCommand.GetType() == typeof(Label) ||
nextCommand.indentLevel != indentLevel)
{
continue;

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

@ -39,7 +39,7 @@ namespace Fungus
return "Error: No label selected";
}
return "To " + targetLabel.key;
return targetLabel.key;
}
public override Color GetButtonColor()

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

@ -19,7 +19,7 @@ namespace Fungus
public override string GetSummary()
{
return key;
return key + ":";
}
public override Color GetButtonColor()

44
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -265,6 +265,50 @@ namespace Fungus
}
}
/**
* Returns a new Label key that is guaranteed not to clash with any existing Label in the Sequence.
*/
public virtual string GetUniqueLabelKey(string originalKey, Label ignoreLabel)
{
int suffix = 0;
string baseKey = originalKey.Trim();
// No empty keys allowed
if (baseKey.Length == 0)
{
baseKey = "Label";
}
Sequence sequence = ignoreLabel.parentSequence;
string key = baseKey;
while (true)
{
bool collision = false;
foreach(Command command in sequence.commandList)
{
Label label = command as Label;
if (label == null ||
label == ignoreLabel)
{
continue;
}
if (label.key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{
collision = true;
suffix++;
key = baseKey + suffix;
}
}
if (!collision)
{
return key;
}
}
}
/**
* Returns the variable with the specified key, or null if the key is not found.
* You can then access the variable's value using the Value property. e.g.

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

@ -135,13 +135,21 @@ namespace Fungus
FungusScript fungusScript = GetFungusScript();
// Skip disabled commands and comments
// Skip disabled commands, comments and labels
while (commandIndex < commandList.Count &&
(!commandList[commandIndex].enabled || commandList[commandIndex].GetType() == typeof(Comment)))
(!commandList[commandIndex].enabled ||
commandList[commandIndex].GetType() == typeof(Comment) ||
commandList[commandIndex].GetType() == typeof(Label)))
{
commandIndex = commandList[commandIndex].commandIndex + 1;
}
if (commandIndex >= commandList.Count)
{
Stop();
return;
}
Command nextCommand = commandList[commandIndex];
activeCommand = null;

Loading…
Cancel
Save