Add event handling improvements; implement timeout for event choices and new event definitions
This commit is contained in:
@@ -50,7 +50,6 @@ public partial class EventManager : Node
|
||||
|
||||
private void FireEvent(EventDefinition eventDef)
|
||||
{
|
||||
GD.Print($"Firing event: {eventDef.Title}");
|
||||
GetTree().Paused = true;
|
||||
|
||||
var popup = _eventPopupScene.Instantiate<EventPopup>();
|
||||
|
@@ -11,9 +11,15 @@ public partial class EventPopup : PanelContainer
|
||||
[Export] private RichTextLabel _descriptionLabel;
|
||||
[Export] private VBoxContainer _optionsContainer;
|
||||
[Export] private PackedScene _optionButtonScene; // A scene for a single button
|
||||
[Export] private float _choiceTimeout = 30.0f;
|
||||
|
||||
private EventDefinition _eventDef;
|
||||
private Timer _timeoutTimer;
|
||||
private readonly RandomNumberGenerator _rng = new();
|
||||
|
||||
public void DisplayEvent(EventDefinition eventDef)
|
||||
{
|
||||
_eventDef = eventDef;
|
||||
_titleLabel.Text = eventDef.Title;
|
||||
_descriptionLabel.Text = eventDef.Description;
|
||||
|
||||
@@ -30,11 +36,36 @@ public partial class EventPopup : PanelContainer
|
||||
|
||||
button.Pressed += () =>
|
||||
{
|
||||
GameBus.Instance.ExecuteEffects(option.Effects);
|
||||
QueueFree();
|
||||
_timeoutTimer.Stop();
|
||||
HandleChoice(option);
|
||||
};
|
||||
|
||||
_optionsContainer.AddChild(button);
|
||||
}
|
||||
|
||||
_timeoutTimer = new Timer { WaitTime = _choiceTimeout, OneShot = true };
|
||||
AddChild(_timeoutTimer);
|
||||
_timeoutTimer.Timeout += OnTimeout;
|
||||
_timeoutTimer.Start();
|
||||
}
|
||||
|
||||
private void OnTimeout()
|
||||
{
|
||||
if (_eventDef.Options.Count > 0)
|
||||
{
|
||||
var randomIndex = _rng.RandiRange(0, _eventDef.Options.Count - 1);
|
||||
HandleChoice(_eventDef.Options[randomIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueFree();
|
||||
GetTree().Paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleChoice(EventOptionDefinition option)
|
||||
{
|
||||
GameBus.Instance.ExecuteEffects(option.Effects);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user