Browse Source

AddOption command can now set a variable on selection

master
chrisgregan 10 years ago
parent
commit
84dde98153
  1. 4
      Assets/Fungus/Dialog/Commands/AddOption.cs
  2. 6
      Assets/Fungus/Dialog/Commands/Choose.cs
  3. 7
      Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
  4. 140
      Assets/Fungus/FungusScript/Commands/SetVariable.cs

4
Assets/Fungus/Dialog/Commands/AddOption.cs

@ -8,7 +8,7 @@ namespace Fungus
[CommandInfo("Dialog", [CommandInfo("Dialog",
"Add Option", "Add Option",
"Adds an option for the player to select, displayed by the next Say command.")] "Adds an option for the player to select, displayed by the next Say command.")]
public class AddOption : Command public class AddOption : SetVariable
{ {
public string optionText; public string optionText;
public Sequence targetSequence; public Sequence targetSequence;
@ -26,6 +26,8 @@ namespace Fungus
Choose.Option option = new Choose.Option(); Choose.Option option = new Choose.Option();
option.optionText = optionText; option.optionText = optionText;
option.targetSequence = targetSequence; option.targetSequence = targetSequence;
option.action = () => DoSetOperation();
Choose.options.Add(option); Choose.options.Add(option);
Continue(); Continue();

6
Assets/Fungus/Dialog/Commands/Choose.cs

@ -14,6 +14,7 @@ namespace Fungus
{ {
public string optionText; public string optionText;
public Sequence targetSequence; public Sequence targetSequence;
public Action action;
} }
static public List<Option> options = new List<Option>(); static public List<Option> options = new List<Option>();
@ -60,6 +61,11 @@ namespace Fungus
dialogOption.onSelect = delegate { dialogOption.onSelect = delegate {
if (option.action != null)
{
option.action();
}
chooseDialog.ShowDialog(false); chooseDialog.ShowDialog(false);
if (onSelectSequence == null) if (onSelectSequence == null)

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

@ -9,14 +9,15 @@ namespace Fungus
{ {
[CustomEditor (typeof(AddOption))] [CustomEditor (typeof(AddOption))]
public class AddOptionEditor : CommandEditor public class AddOptionEditor : SetVariableEditor
{ {
protected SerializedProperty optionTextProp; protected SerializedProperty optionTextProp;
protected SerializedProperty hideOnSelectedProp; protected SerializedProperty hideOnSelectedProp;
protected SerializedProperty targetSequenceProp; protected SerializedProperty targetSequenceProp;
protected virtual void OnEnable() protected override void OnEnable()
{ {
base.OnEnable();
optionTextProp = serializedObject.FindProperty("optionText"); optionTextProp = serializedObject.FindProperty("optionText");
hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected"); hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected");
targetSequenceProp = serializedObject.FindProperty("targetSequence"); targetSequenceProp = serializedObject.FindProperty("targetSequence");
@ -38,6 +39,8 @@ namespace Fungus
EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it.")); EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."));
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
base.DrawCommandGUI();
} }
} }

140
Assets/Fungus/FungusScript/Commands/SetVariable.cs

@ -31,10 +31,78 @@ namespace Fungus
public StringData stringData; public StringData stringData;
public override void OnEnter() public override void OnEnter()
{
DoSetOperation();
Continue();
}
public override string GetSummary()
{
if (variable == null)
{
return "Error: Variable not selected";
}
string description = variable.key;
switch (setOperator)
{
default:
case SetOperator.Assign:
description += " = ";
break;
case SetOperator.Negate:
description += " != ";
break;
case SetOperator.Add:
description += " += ";
break;
case SetOperator.Subtract:
description += " -= ";
break;
case SetOperator.Multiply:
description += " *= ";
break;
case SetOperator.Divide:
description += " /= ";
break;
}
if (variable.GetType() == typeof(BooleanVariable))
{
description += booleanData.GetDescription();
}
else if (variable.GetType() == typeof(IntegerVariable))
{
description += integerData.GetDescription();
}
else if (variable.GetType() == typeof(FloatVariable))
{
description += floatData.GetDescription();
}
else if (variable.GetType() == typeof(StringVariable))
{
description += stringData.GetDescription();
}
return description;
}
public override bool HasReference(Variable variable)
{
return (variable == this.variable);
}
public override Color GetButtonColor()
{
return new Color32(253, 253, 150, 255);
}
protected virtual void DoSetOperation()
{ {
if (variable == null) if (variable == null)
{ {
Continue();
return; return;
} }
@ -42,7 +110,7 @@ namespace Fungus
{ {
BooleanVariable lhs = (variable as BooleanVariable); BooleanVariable lhs = (variable as BooleanVariable);
bool rhs = booleanData.Value; bool rhs = booleanData.Value;
switch (setOperator) switch (setOperator)
{ {
default: default:
@ -58,7 +126,7 @@ namespace Fungus
{ {
IntegerVariable lhs = (variable as IntegerVariable); IntegerVariable lhs = (variable as IntegerVariable);
int rhs = integerData.Value; int rhs = integerData.Value;
switch (setOperator) switch (setOperator)
{ {
default: default:
@ -108,7 +176,7 @@ namespace Fungus
{ {
StringVariable lhs = (variable as StringVariable); StringVariable lhs = (variable as StringVariable);
string rhs = stringData.Value; string rhs = stringData.Value;
switch (setOperator) switch (setOperator)
{ {
default: default:
@ -117,70 +185,6 @@ namespace Fungus
break; break;
} }
} }
Continue();
}
public override string GetSummary()
{
if (variable == null)
{
return "Error: Variable not selected";
}
string description = variable.key;
switch (setOperator)
{
default:
case SetOperator.Assign:
description += " = ";
break;
case SetOperator.Negate:
description += " != ";
break;
case SetOperator.Add:
description += " += ";
break;
case SetOperator.Subtract:
description += " -= ";
break;
case SetOperator.Multiply:
description += " *= ";
break;
case SetOperator.Divide:
description += " /= ";
break;
}
if (variable.GetType() == typeof(BooleanVariable))
{
description += booleanData.GetDescription();
}
else if (variable.GetType() == typeof(IntegerVariable))
{
description += integerData.GetDescription();
}
else if (variable.GetType() == typeof(FloatVariable))
{
description += floatData.GetDescription();
}
else if (variable.GetType() == typeof(StringVariable))
{
description += stringData.GetDescription();
}
return description;
}
public override bool HasReference(Variable variable)
{
return (variable == this.variable);
}
public override Color GetButtonColor()
{
return new Color32(253, 253, 150, 255);
} }
} }

Loading…
Cancel
Save