mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-20 00:53:47 +00:00
Selector changes
This commit is contained in:
parent
176c1050b7
commit
690ac102dc
3 changed files with 140 additions and 34 deletions
|
|
@ -328,7 +328,7 @@ _selectorController = NodePath("SelectorController")
|
||||||
_errorSound = NodePath("AudioStreamPlayer")
|
_errorSound = NodePath("AudioStreamPlayer")
|
||||||
SelectorScene = ExtResource("24_j6bpw")
|
SelectorScene = ExtResource("24_j6bpw")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="ActivationProvider"]
|
[node name="CollisionShape" type="CollisionShape3D" parent="ActivationProvider"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.294313, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.294313, 0)
|
||||||
shape = SubResource("CylinderShape3D_6d8x8")
|
shape = SubResource("CylinderShape3D_6d8x8")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using Cirno.Scripts.Components.Actors;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Cirno.Scripts.Components.Actors;
|
||||||
using Cirno.Scripts.Interactables;
|
using Cirno.Scripts.Interactables;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
|
|
@ -29,6 +31,8 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
|
|
||||||
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
|
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
|
||||||
|
|
||||||
|
private CollisionShape3D _collisionShape;
|
||||||
|
|
||||||
public void EnterState(PlayerState state)
|
public void EnterState(PlayerState state)
|
||||||
{
|
{
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
|
|
@ -47,6 +51,8 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
{
|
{
|
||||||
StateMachine = machine;
|
StateMachine = machine;
|
||||||
|
|
||||||
|
_collisionShape = GetNode<CollisionShape3D>("CollisionShape");
|
||||||
|
|
||||||
_selectorController.Hide();
|
_selectorController.Hide();
|
||||||
|
|
||||||
SpawnSelector();
|
SpawnSelector();
|
||||||
|
|
@ -102,13 +108,14 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
|
|
||||||
public void PhysicsProcess(double delta)
|
public void PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
//_selectorController.PhysicsProcess(delta);
|
_selectorController.PhysicsProcess(delta);
|
||||||
|
|
||||||
HandleInteraction();
|
HandleInteraction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleInteraction()
|
public void HandleInteraction()
|
||||||
{
|
{
|
||||||
|
if (!_selectorController.CanSelect) return;
|
||||||
if (_inputProvider.GetUseJustPressed())
|
if (_inputProvider.GetUseJustPressed())
|
||||||
{
|
{
|
||||||
if (!TrySelect())
|
if (!TrySelect())
|
||||||
|
|
@ -121,6 +128,7 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
|
|
||||||
if (_inputProvider.GetScanJustPressed())
|
if (_inputProvider.GetScanJustPressed())
|
||||||
{
|
{
|
||||||
|
var items = ScanTargets();
|
||||||
_selectorController.SelectNext();
|
_selectorController.SelectNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,9 +151,13 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// Deselect and scan for next
|
// Deselect and scan for next
|
||||||
_selectorController.RemoveInteractable(selected);
|
//_selectorController.RemoveInteractable(selected);
|
||||||
_selectorController.SelectNext();
|
_selectorController.DeselectWithCooldown();
|
||||||
//_selector.RemoveInteractable(selected);
|
|
||||||
|
// Do this at end of frame instead
|
||||||
|
//_selectorController.SelectNext();
|
||||||
|
_selectorController.SelectNextDelayed();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -157,6 +169,41 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
||||||
|
|
||||||
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private List<IInteractable> ScanTargets()
|
||||||
|
{
|
||||||
|
var spaceState = GetWorld3D().DirectSpaceState;
|
||||||
|
var query = new PhysicsShapeQueryParameters3D()
|
||||||
|
{
|
||||||
|
Shape = _collisionShape.Shape,
|
||||||
|
CollideWithBodies = false,
|
||||||
|
CollideWithAreas = true,
|
||||||
|
CollisionMask = this.CollisionMask,
|
||||||
|
Exclude = [GetRid()],
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var targets = spaceState.IntersectShape(query);
|
||||||
|
if (targets.Count is 0) return null;
|
||||||
|
var found = targets.Select(resDict =>
|
||||||
|
{
|
||||||
|
var collider = resDict["collider"].As<Node3D>();
|
||||||
|
if (collider.IsInGroup("Interactable") && collider is IInteractable interactable &&
|
||||||
|
interactable.CanActivate())
|
||||||
|
{
|
||||||
|
return interactable;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).Where(x => x is not null).ToList();
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
private void _on_interaction_controller_area_entered(Area3D area)
|
private void _on_interaction_controller_area_entered(Area3D area)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,25 @@ namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||||
|
|
||||||
public partial class SelectorController : Node
|
public partial class SelectorController : Node
|
||||||
{
|
{
|
||||||
[Signal] public delegate void ShowSelectorEventHandler();
|
[Signal]
|
||||||
[Signal] public delegate void HideSelectorEventHandler();
|
public delegate void ShowSelectorEventHandler();
|
||||||
[Signal] public delegate void ChangePositionEventHandler(Vector2 position);
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void HideSelectorEventHandler();
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void ChangePositionEventHandler(Vector2 position);
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void ChangeParent3DEventHandler(Node3D node);
|
||||||
|
|
||||||
|
private bool _canSelect = true;
|
||||||
|
|
||||||
|
public bool CanSelect => _canSelect;
|
||||||
|
|
||||||
|
private bool _autoSelect = false;
|
||||||
|
|
||||||
[Signal] public delegate void ChangeParent3DEventHandler(Node3D node);
|
private double _cooldownTimer = 0f;
|
||||||
|
|
||||||
private Interactable _lastInteractable;
|
private Interactable _lastInteractable;
|
||||||
|
|
||||||
|
|
@ -31,18 +45,25 @@ public partial class SelectorController : Node
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
_selectedInteractable = _interactables.Count - 1;
|
_selectedInteractable = _interactables.Count - 1;
|
||||||
|
// if (_selectedInteractable < 0)
|
||||||
|
// {
|
||||||
|
// _selectedInteractable = 0;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IInteractable SelectedInteractable
|
public IInteractable SelectedInteractable
|
||||||
{
|
{
|
||||||
|
// The problem here is that if it's deselected the index is -1
|
||||||
get =>
|
get =>
|
||||||
_interactables.Count > 0
|
SelectedInteractableIndex < 0
|
||||||
? SelectedInteractableIndex >= _interactables.Count
|
? null
|
||||||
? _interactables[^1]
|
: _interactables.Count > 0
|
||||||
: _interactables[SelectedInteractableIndex]
|
? SelectedInteractableIndex >= _interactables.Count
|
||||||
: null;
|
? _interactables[^1]
|
||||||
|
: _interactables[SelectedInteractableIndex]
|
||||||
|
: null;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// Passing null deselects the interactable
|
// Passing null deselects the interactable
|
||||||
|
|
@ -63,7 +84,7 @@ public partial class SelectorController : Node
|
||||||
NotifyChanged(value);
|
NotifyChanged(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNext()
|
public void SelectNext()
|
||||||
{
|
{
|
||||||
SelectedInteractableIndex += 1;
|
SelectedInteractableIndex += 1;
|
||||||
|
|
@ -73,28 +94,48 @@ public partial class SelectorController : Node
|
||||||
// _selectedInteractable = 0;
|
// _selectedInteractable = 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (_interactables.Count > 0)
|
if (_interactables.Count <= 0)
|
||||||
{
|
{
|
||||||
SelectedInteractable = _interactables[_selectedInteractable];
|
SelectedInteractable = null;
|
||||||
}
|
//SelectedInteractableIndex = -1;
|
||||||
else
|
|
||||||
{
|
|
||||||
_selectedInteractable = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No need to set it because the selection is already handled when reading
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// SelectedInteractable = _interactables[_selectedInteractable];
|
||||||
|
// }
|
||||||
|
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SelectNextDelayed()
|
||||||
|
{
|
||||||
|
if (!_canSelect)
|
||||||
|
{
|
||||||
|
_autoSelect = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectNext();
|
||||||
|
}
|
||||||
|
//CallDeferred(MethodName.SelectNext);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddInteractable(IInteractable interactable)
|
public void AddInteractable(IInteractable interactable)
|
||||||
{
|
{
|
||||||
if (!_interactables.Contains(interactable))
|
if (!_interactables.Contains(interactable))
|
||||||
{
|
{
|
||||||
_interactables.Add(interactable);
|
_interactables.Add(interactable);
|
||||||
|
|
||||||
if (_interactables.Count == 1)
|
// Always set the current one to the newest
|
||||||
{
|
SelectedInteractable = interactable;
|
||||||
_selectedInteractable = 0;
|
|
||||||
}
|
// if (_interactables.Count == 1)
|
||||||
|
// {
|
||||||
|
// SelectedInteractable = interactable;
|
||||||
|
// //_selectedInteractable = 0;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
|
|
@ -109,8 +150,17 @@ public partial class SelectorController : Node
|
||||||
|
|
||||||
public void Deselect()
|
public void Deselect()
|
||||||
{
|
{
|
||||||
_selectedInteractable = -1;
|
SelectedInteractable = null;
|
||||||
|
//SelectedInteractableIndex = -1;
|
||||||
EmitSignalHideSelector();
|
EmitSignalHideSelector();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeselectWithCooldown()
|
||||||
|
{
|
||||||
|
Deselect();
|
||||||
|
_canSelect = false;
|
||||||
|
_cooldownTimer = 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePosition()
|
public void UpdatePosition()
|
||||||
|
|
@ -127,7 +177,7 @@ public partial class SelectorController : Node
|
||||||
EmitSignalHideSelector();
|
EmitSignalHideSelector();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NotifyChanged(IInteractable interactable)
|
private void NotifyChanged(IInteractable interactable)
|
||||||
{
|
{
|
||||||
//EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
|
//EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
|
||||||
|
|
@ -138,9 +188,18 @@ public partial class SelectorController : Node
|
||||||
EmitSignalHideSelector();
|
EmitSignalHideSelector();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void PhysicsProcess(double delta)
|
public void PhysicsProcess(double delta)
|
||||||
// {
|
{
|
||||||
// if (SelectedInteractable is null) return;
|
if (_canSelect is true) return;
|
||||||
// //EmitSignalChangePosition(SelectedInteractable.GetScreenPosition());
|
_cooldownTimer += delta;
|
||||||
// }
|
|
||||||
|
if (!(_cooldownTimer >= 0.2d)) return;
|
||||||
|
_canSelect = true;
|
||||||
|
_cooldownTimer = 0;
|
||||||
|
if (!_autoSelect) return;
|
||||||
|
_autoSelect = false;
|
||||||
|
SelectNext();
|
||||||
|
//if (SelectedInteractable is null) return;
|
||||||
|
//EmitSignalChangePosition(SelectedInteractable.GetScreenPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue