mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:45:33 +00:00
Better handling of selection
This commit is contained in:
parent
acf3857129
commit
1c7afec7e2
2 changed files with 47 additions and 23 deletions
|
|
@ -37,7 +37,12 @@ public partial class ActivationProvider : Area2D
|
|||
{
|
||||
if (_inputProvider.GetUseJustPressed())
|
||||
{
|
||||
TrySelect();
|
||||
if (!TrySelect())
|
||||
{
|
||||
_selector.SelectNext();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inputProvider.GetScanJustPressed())
|
||||
|
|
@ -46,33 +51,33 @@ public partial class ActivationProvider : Area2D
|
|||
}
|
||||
}
|
||||
|
||||
private void TrySelect()
|
||||
private bool TrySelect()
|
||||
{
|
||||
var selected = _selector.SelectedInteractable;
|
||||
if (selected is null)
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
if (!selected.CanActivate())
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return;
|
||||
return true;
|
||||
};
|
||||
bool success = selected.Activate();
|
||||
|
||||
if (success)
|
||||
{
|
||||
// Deselect and scan for next
|
||||
_selector.RemoveInteractable(selected);
|
||||
//_selector.SelectedInteractable = null;
|
||||
//_selector.SelectNext();
|
||||
_selector.SelectNext();
|
||||
//_selector.RemoveInteractable(selected);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorSound?.Play();
|
||||
}
|
||||
|
||||
return true;
|
||||
//var spaceState = GetWorld2D().DirectSpaceState;
|
||||
|
||||
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
||||
|
|
|
|||
|
|
@ -11,6 +11,23 @@ public partial class Selector : Node2D
|
|||
|
||||
private int _selectedInteractable;
|
||||
|
||||
private int SelectedInteractableIndex
|
||||
{
|
||||
get => _selectedInteractable;
|
||||
set
|
||||
{
|
||||
if (value >= _interactables.Count)
|
||||
{
|
||||
_selectedInteractable = 0;
|
||||
}
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
_selectedInteractable = _interactables.Count - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//[Signal]
|
||||
//public delegate void SelectedItemInteractableChangedEventHandler(IInteractable interactable);
|
||||
|
||||
|
|
@ -18,9 +35,9 @@ public partial class Selector : Node2D
|
|||
{
|
||||
get =>
|
||||
_interactables.Count > 0
|
||||
? _selectedInteractable >= _interactables.Count
|
||||
? SelectedInteractableIndex >= _interactables.Count
|
||||
? _interactables[^1]
|
||||
: _interactables[_selectedInteractable]
|
||||
: _interactables[SelectedInteractableIndex]
|
||||
: null;
|
||||
set
|
||||
{
|
||||
|
|
@ -38,7 +55,7 @@ public partial class Selector : Node2D
|
|||
AddInteractable(value);
|
||||
}
|
||||
|
||||
_selectedInteractable = _interactables.IndexOf(value);
|
||||
SelectedInteractableIndex = _interactables.IndexOf(value);
|
||||
NotifyChanged(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,11 +79,12 @@ public partial class Selector : Node2D
|
|||
|
||||
public void SelectNext()
|
||||
{
|
||||
_selectedInteractable += 1;
|
||||
if (_selectedInteractable >= _interactables.Count)
|
||||
{
|
||||
_selectedInteractable = 0;
|
||||
}
|
||||
SelectedInteractableIndex += 1;
|
||||
// _selectedInteractable += 1;
|
||||
// if (_selectedInteractable >= _interactables.Count)
|
||||
// {
|
||||
// _selectedInteractable = 0;
|
||||
// }
|
||||
|
||||
if (_interactables.Count > 0)
|
||||
{
|
||||
|
|
@ -87,15 +105,16 @@ public partial class Selector : Node2D
|
|||
|
||||
public void AddInteractable(IInteractable interactable)
|
||||
{
|
||||
if (!_interactables.Contains(interactable)) {
|
||||
if (!_interactables.Contains(interactable))
|
||||
{
|
||||
_interactables.Add(interactable);
|
||||
|
||||
if (_interactables.Count == 1)
|
||||
{
|
||||
_selectedInteractable = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UpdatePosition();
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +124,7 @@ public partial class Selector : Node2D
|
|||
{
|
||||
_interactables.Remove(interactable);
|
||||
}
|
||||
|
||||
UpdatePosition();
|
||||
}
|
||||
|
||||
|
|
@ -126,5 +146,4 @@ public partial class Selector : Node2D
|
|||
this.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue