Browse Source

Fixed hide on selected logic and optionAction closure bug

master
chrisgregan 10 years ago
parent
commit
6c79e656fe
  1. 9
      Assets/Fungus/Dialog/Commands/AddOption.cs
  2. 7
      Assets/Fungus/Dialog/Commands/Choose.cs

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

@ -14,10 +14,11 @@ namespace Fungus
public Sequence targetSequence;
public bool hideOnSelected;
protected bool wasSelected;
public override void OnEnter()
{
if (targetSequence == null || (hideOnSelected && targetSequence.GetExecutionCount() > 0))
if (hideOnSelected && wasSelected)
{
Continue();
return;
@ -26,7 +27,11 @@ namespace Fungus
Choose.Option option = new Choose.Option();
option.optionText = optionText;
option.targetSequence = targetSequence;
option.action = () => DoSetOperation();
option.action = () => {
wasSelected = true;
DoSetOperation(); // Set variable (if one is specified)
};
Choose.options.Add(option);

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

@ -56,14 +56,17 @@ namespace Fungus
foreach (Option option in options)
{
ChooseDialog.Option dialogOption = new ChooseDialog.Option();
// Store these in local variables so they get closed over correctly by the delegate call
dialogOption.text = option.optionText;
Sequence onSelectSequence = option.targetSequence;
Action optionAction = option.action;
dialogOption.onSelect = delegate {
if (option.action != null)
if (optionAction != null)
{
option.action();
optionAction();
}
chooseDialog.ShowDialog(false);

Loading…
Cancel
Save