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