mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-21 03:03:47 +00:00
Automatic box deselection
This commit is contained in:
parent
cc5376e94e
commit
ad985ce1ac
6 changed files with 73 additions and 19 deletions
|
|
@ -36,8 +36,13 @@ public partial class Interactable : Area2D
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Activate()
|
public virtual bool Activate()
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool CanActivate()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_elja3")
|
"texture": SubResource("AtlasTexture_elja3")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"Closed",
|
"name": &"Closed",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -47,7 +47,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_f10r8")
|
"texture": SubResource("AtlasTexture_f10r8")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"Closing",
|
"name": &"Closing",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -55,7 +55,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_faho7")
|
"texture": SubResource("AtlasTexture_faho7")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"Open",
|
"name": &"Open",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -66,7 +66,7 @@ animations = [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_x1bfm")
|
"texture": SubResource("AtlasTexture_x1bfm")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": &"Opening",
|
"name": &"Opening",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}]
|
}]
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,45 @@ public partial class Chest : Interactable
|
||||||
|
|
||||||
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
||||||
|
|
||||||
public override void Activate()
|
[Export] public ChestState State = ChestState.Closed;
|
||||||
|
|
||||||
|
private AnimatedSprite2D _sprite;
|
||||||
|
|
||||||
|
public override bool Activate()
|
||||||
{
|
{
|
||||||
if (!MeetsRequirements()) return;
|
GD.Print("Attempting to open chest");
|
||||||
|
if (State != ChestState.Closed) return false;
|
||||||
|
if (!MeetsRequirements()) return false;
|
||||||
foreach (var item in LootTable)
|
foreach (var item in LootTable)
|
||||||
{
|
{
|
||||||
_inventoryManager.AddItem(item.Item, item.Amount);
|
_inventoryManager.AddItem(item.Item, item.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sprite.Play("Opening");
|
||||||
|
State = ChestState.Open;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
|
|
||||||
|
_sprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanActivate()
|
||||||
|
{
|
||||||
|
return State == ChestState.Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ChestState
|
||||||
|
{
|
||||||
|
Closed,
|
||||||
|
Open,
|
||||||
|
Destroyed
|
||||||
|
}
|
||||||
|
|
@ -6,11 +6,14 @@ public partial class Switch : Interactable
|
||||||
{
|
{
|
||||||
[Export] public Activable Target { get; set; }
|
[Export] public Activable Target { get; set; }
|
||||||
|
|
||||||
public override void Activate()
|
public override bool Activate()
|
||||||
{
|
{
|
||||||
if (MeetsRequirements())
|
if (MeetsRequirements())
|
||||||
{
|
{
|
||||||
Target?.Activate();
|
Target?.Activate();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,9 +121,15 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
private void FindInteractable()
|
private void FindInteractable()
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("Use") && _selector.SelectedInteractable != null)
|
if (!Input.IsActionJustPressed("Use") || _selector.SelectedInteractable == null) return;
|
||||||
|
if (!_selector.SelectedInteractable.CanActivate()) return;
|
||||||
|
bool success = _selector.SelectedInteractable.Activate();
|
||||||
|
|
||||||
|
if (success)
|
||||||
{
|
{
|
||||||
_selector.SelectedInteractable.Activate();
|
// Deselect and scan for next
|
||||||
|
_selector.SelectedInteractable = null;
|
||||||
|
_selector.SelectNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
//var spaceState = GetWorld2D().DirectSpaceState;
|
//var spaceState = GetWorld2D().DirectSpaceState;
|
||||||
|
|
@ -261,7 +267,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
private void _on_interaction_controller_area_entered(Area2D area)
|
private void _on_interaction_controller_area_entered(Area2D area)
|
||||||
{
|
{
|
||||||
// Replace with function body.
|
// Replace with function body.
|
||||||
if (area.IsInGroup("Interactable") && area is Interactable interactable)
|
if (area.IsInGroup("Interactable") && area is Interactable interactable && interactable.CanActivate())
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Interactable {area.Name} Entered");
|
Debug.WriteLine($"Interactable {area.Name} Entered");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,31 @@ public partial class Selector : Node2D
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("scan"))
|
if (Input.IsActionJustPressed("scan"))
|
||||||
{
|
{
|
||||||
_selectedInteractable += 1;
|
SelectNext();
|
||||||
if (_selectedInteractable >= _interactables.Count)
|
|
||||||
{
|
|
||||||
_selectedInteractable = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SelectedInteractable = _interactables[_selectedInteractable];
|
|
||||||
UpdatePosition();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SelectNext()
|
||||||
|
{
|
||||||
|
_selectedInteractable += 1;
|
||||||
|
if (_selectedInteractable >= _interactables.Count)
|
||||||
|
{
|
||||||
|
_selectedInteractable = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_interactables.Count > 0)
|
||||||
|
{
|
||||||
|
SelectedInteractable = _interactables[_selectedInteractable];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_selectedInteractable = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
private void NotifyChanged(Interactable interactable)
|
private void NotifyChanged(Interactable interactable)
|
||||||
{
|
{
|
||||||
EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
|
EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue