mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-22 19:43:55 +00:00
Interactable handling
This commit is contained in:
parent
a4b39a97dc
commit
d804441378
5 changed files with 89 additions and 17 deletions
|
|
@ -26,9 +26,8 @@ animations = [{
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("_selector")]
|
[node name="HUD" type="CanvasLayer"]
|
||||||
script = ExtResource("1_m0hb0")
|
script = ExtResource("1_m0hb0")
|
||||||
_selector = NodePath("AnimatedSprite2D")
|
|
||||||
|
|
||||||
[node name="HealthLabel" type="Label" parent="."]
|
[node name="HealthLabel" type="Label" parent="."]
|
||||||
anchors_preset = 2
|
anchors_preset = 2
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,5 @@ z_as_relative = false
|
||||||
script = ExtResource("1_pp2dj")
|
script = ExtResource("1_pp2dj")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
top_level = true
|
|
||||||
z_index = -5
|
z_index = -5
|
||||||
sprite_frames = SubResource("SpriteFrames_kehny")
|
sprite_frames = SubResource("SpriteFrames_kehny")
|
||||||
|
|
|
||||||
|
|
@ -215,8 +215,6 @@ BulletCapacity = 100
|
||||||
ReloadTime = 0.4
|
ReloadTime = 0.4
|
||||||
BulletSpeed = 300.0
|
BulletSpeed = 300.0
|
||||||
|
|
||||||
[node name="Selector" parent="." instance=ExtResource("3_8wt6s")]
|
|
||||||
|
|
||||||
[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"]
|
[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"]
|
||||||
[connection signal="area_exited" from="InteractionController" to="." method="_on_interaction_controller_area_exited"]
|
[connection signal="area_exited" from="InteractionController" to="." method="_on_interaction_controller_area_exited"]
|
||||||
[connection signal="area_entered" from="DamageHitBox" to="." method="_on_damage_hit_box_area_entered"]
|
[connection signal="area_entered" from="DamageHitBox" to="." method="_on_damage_hit_box_area_entered"]
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
[Export]
|
[Export]
|
||||||
public string GameOverScene { get; set; }
|
public string GameOverScene { get; set; }
|
||||||
|
|
||||||
private Node2D _selector;
|
private Selector _selector;
|
||||||
|
|
||||||
private Interactable _lastInteractable;
|
//private Interactable _lastInteractable;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public Marker2D Muzzle { get; set; }
|
public Marker2D Muzzle { get; set; }
|
||||||
|
|
@ -94,7 +94,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
if (SelectorScene != null)
|
if (SelectorScene != null)
|
||||||
{
|
{
|
||||||
_selector = this.CreateSibling<Node2D>(SelectorScene, this.GlobalPosition);
|
_selector = this.CreateSibling<Selector>(SelectorScene, this.GlobalPosition);
|
||||||
_selector.Visible = true;
|
_selector.Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,9 +121,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
private void FindInteractable()
|
private void FindInteractable()
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("Use") && _lastInteractable != null)
|
if (Input.IsActionJustPressed("Use") && _selector.SelectedInteractable != null)
|
||||||
{
|
{
|
||||||
_lastInteractable.Activate();
|
_selector.SelectedInteractable.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
//var spaceState = GetWorld2D().DirectSpaceState;
|
//var spaceState = GetWorld2D().DirectSpaceState;
|
||||||
|
|
@ -267,12 +267,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
EmitSignal(nameof(InteractableAreaEntered), interactable);
|
EmitSignal(nameof(InteractableAreaEntered), interactable);
|
||||||
|
|
||||||
if (_selector != null)
|
if (_selector == null) return;
|
||||||
{
|
_selector.Position = interactable.Position;
|
||||||
_selector.Position = interactable.Position;
|
//_selector.Visible = true;
|
||||||
_selector.Visible = true;
|
//_lastInteractable = interactable;
|
||||||
_lastInteractable = interactable;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,6 +281,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
Debug.WriteLine($"Interactable {area.Name} Exited");
|
Debug.WriteLine($"Interactable {area.Name} Exited");
|
||||||
|
|
||||||
EmitSignal(nameof(InteractableAreaExited), interactable);
|
EmitSignal(nameof(InteractableAreaExited), interactable);
|
||||||
|
|
||||||
|
if (_selector == null) return;
|
||||||
|
_selector.RemoveInteractable(interactable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,92 @@ public partial class Selector : Node2D
|
||||||
|
|
||||||
private int _selectedInteractable;
|
private int _selectedInteractable;
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void SelectedItemInteractableChangedEventHandler(Interactable interactable);
|
||||||
|
|
||||||
|
public Interactable SelectedInteractable
|
||||||
|
{
|
||||||
|
get =>
|
||||||
|
_interactables.Count > 0
|
||||||
|
? _selectedInteractable >= _interactables.Count
|
||||||
|
? _interactables[^1]
|
||||||
|
: _interactables[_selectedInteractable]
|
||||||
|
: null;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// Passing null deselects the interactable
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
_selectedInteractable = -1;
|
||||||
|
NotifyChanged(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's already in the list, set the current one to it, otherwise add it
|
||||||
|
if (!_interactables.Contains(value))
|
||||||
|
{
|
||||||
|
AddInteractable(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
_selectedInteractable = _interactables.IndexOf(value);
|
||||||
|
NotifyChanged(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (Input.IsActionPressed("scan"))
|
||||||
|
{
|
||||||
|
_selectedInteractable += 1;
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NotifyChanged(Interactable interactable)
|
||||||
|
{
|
||||||
|
EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddInteractable(Interactable interactable)
|
public void AddInteractable(Interactable interactable)
|
||||||
{
|
{
|
||||||
if (!_interactables.Contains(interactable)) {
|
if (!_interactables.Contains(interactable)) {
|
||||||
_interactables.Add(interactable);
|
_interactables.Add(interactable);
|
||||||
|
|
||||||
|
if (_interactables.Count == 1)
|
||||||
|
{
|
||||||
|
_selectedInteractable = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveInteractable(Interactable interactable)
|
||||||
|
{
|
||||||
|
if (_interactables.Contains(interactable))
|
||||||
|
{
|
||||||
|
_interactables.Remove(interactable);
|
||||||
|
}
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deselect()
|
||||||
|
{
|
||||||
|
_selectedInteractable = -1;
|
||||||
|
this.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePosition()
|
||||||
|
{
|
||||||
|
if (SelectedInteractable != null)
|
||||||
|
{
|
||||||
|
this.Position = SelectedInteractable.Position;
|
||||||
|
this.Visible = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Visible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveInteractable()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue