mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-17 18:43:47 +00:00
Interaction manager and hud
This commit is contained in:
parent
b1afc7af1c
commit
5271b84923
20 changed files with 539 additions and 29 deletions
143
Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs
Normal file
143
Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Interactables;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class IsoActivationProvider: Area3D, IModule<PlayerState, CharacterBody3D>
|
||||
{
|
||||
|
||||
private bool _enabled = false;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => _enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled == value) return;
|
||||
_enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Export] private InputProvider _inputProvider;
|
||||
[Export] private SelectorController _selectorController;
|
||||
|
||||
[Export] private AudioStreamPlayer _errorSound;
|
||||
|
||||
[Export] public PackedScene SelectorScene { get; set; }
|
||||
|
||||
|
||||
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
|
||||
|
||||
public void EnterState(PlayerState state)
|
||||
{
|
||||
Enabled = true;
|
||||
AreaEntered += _on_interaction_controller_area_entered;
|
||||
AreaExited += _on_interaction_controller_area_exited;
|
||||
}
|
||||
|
||||
public void ExitState(PlayerState state)
|
||||
{
|
||||
Enabled = false;
|
||||
AreaEntered -= _on_interaction_controller_area_entered;
|
||||
AreaExited -= _on_interaction_controller_area_exited;
|
||||
}
|
||||
|
||||
public void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
StateMachine = machine;
|
||||
|
||||
_selectorController.Hide();
|
||||
|
||||
// TODO: Create selector UI element and link the signals
|
||||
|
||||
// if (SelectorScene is not null && _selector is null)
|
||||
// {
|
||||
// _selector = actor.CreateSibling<Selector>(SelectorScene, this.GlobalPosition);
|
||||
// _selector.Visible = false;
|
||||
// }
|
||||
}
|
||||
|
||||
public void Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HandleInteraction()
|
||||
{
|
||||
if (_inputProvider.GetUseJustPressed())
|
||||
{
|
||||
if (!TrySelect())
|
||||
{
|
||||
_selectorController.SelectNext();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inputProvider.GetScanJustPressed())
|
||||
{
|
||||
_selectorController.SelectNext();
|
||||
}
|
||||
}
|
||||
|
||||
private bool TrySelect()
|
||||
{
|
||||
var selected = _selectorController.SelectedInteractable;
|
||||
if (selected is null)
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return false;
|
||||
};
|
||||
if (!selected.CanActivate())
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return true;
|
||||
};
|
||||
bool success = selected.Activate(ActivationType.Use);
|
||||
|
||||
if (success)
|
||||
{
|
||||
// Deselect and scan for next
|
||||
_selectorController.SelectNext();
|
||||
//_selector.RemoveInteractable(selected);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorSound?.Play();
|
||||
}
|
||||
|
||||
return true;
|
||||
//var spaceState = GetWorld2D().DirectSpaceState;
|
||||
|
||||
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_entered(Area3D area)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (area.IsInGroup("Interactable") && area is IInteractable interactable && interactable.CanActivate())
|
||||
{
|
||||
|
||||
//if (_selector == null) return;
|
||||
|
||||
_selectorController.AddInteractable(interactable);
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_exited(Area3D area)
|
||||
{
|
||||
//if (!Enabled) return;
|
||||
if (area.IsInGroup("Interactable") && area is IInteractable interactable)
|
||||
{
|
||||
|
||||
//if (_selector == null) return;
|
||||
_selectorController.RemoveInteractable(interactable);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue