Added Wellbehaviour and fixed door interaction to offer outlines
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
@@ -6,6 +7,7 @@ public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
[Export] private Area2D _area;
|
||||
[Export] private Label _label;
|
||||
[Export] private bool _active = true;
|
||||
[Export] private bool _useOutline = true;
|
||||
[Export] private ShaderMaterial _outlineMaterial;
|
||||
[Export] private bool _useSprite = true;
|
||||
@@ -17,17 +19,32 @@ public partial class InteractionArea2D : Node2D
|
||||
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
||||
[Signal] public delegate void InteractedEventHandler();
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
public bool IsActive
|
||||
{
|
||||
get => _active;
|
||||
set => _active = value;
|
||||
}
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if(_useSprite && _useOutline)
|
||||
_backupMaterial = _spriteToOutline.Material;
|
||||
if (_useSprite && _useOutline)
|
||||
{
|
||||
try
|
||||
{
|
||||
_backupMaterial = _spriteToOutline.Material;
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
GD.PrintErr($"No sprite to outline found on: {GetParent().Name}" + exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnPlayerEntered(Node2D player)
|
||||
{
|
||||
if (!IsActive)
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
if(_showLabel)
|
||||
@@ -41,7 +58,7 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
public void OnPlayerExited(Node2D player)
|
||||
{
|
||||
if (!IsActive)
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
_label.Hide();
|
||||
@@ -54,31 +71,34 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (!IsActive)
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
||||
if (@event.IsAction("interact") && @event.IsPressed())
|
||||
{
|
||||
_label.Hide();
|
||||
if (_area.HasOverlappingBodies())
|
||||
{
|
||||
_label.Hide();
|
||||
|
||||
if (_useSprite && _useOutline)
|
||||
_spriteToOutline.Material = _backupMaterial;
|
||||
if (_useSprite && _useOutline)
|
||||
_spriteToOutline.Material = _backupMaterial;
|
||||
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
||||
{
|
||||
GD.PrintErr("SetSpriteActiveState is being called.");
|
||||
if(!IsActive)
|
||||
if(!_active)
|
||||
return;
|
||||
}
|
||||
|
||||
public void ToggleActive()
|
||||
{
|
||||
IsActive = !IsActive;
|
||||
_active = !_active;
|
||||
_label.Hide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cqtlic8xxtvkc
|
||||
@@ -0,0 +1 @@
|
||||
uid://dw5dl5yscbyaw
|
||||
@@ -23,6 +23,10 @@ public static class WateringCanState
|
||||
/// Triggers animations and ui.
|
||||
/// </summary>
|
||||
public static bool Active = false;
|
||||
|
||||
public delegate void WateringCanDelegate(bool state);
|
||||
public static event WateringCanDelegate WateringCanActiveStateChanged;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -65,6 +69,8 @@ public static class WateringCanState
|
||||
/// <param name="active"></param>
|
||||
public static void SetActive(bool active)
|
||||
{
|
||||
if(active != Active)
|
||||
WateringCanActiveStateChanged?.Invoke(active);
|
||||
Active = active;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class WellBehaviour : Node2D
|
||||
{
|
||||
[Export] private InteractionArea2D _interactionArea;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
WateringCanState.WateringCanActiveStateChanged += OnWateringCanStateChanged;
|
||||
}
|
||||
|
||||
private void OnWateringCanStateChanged(bool state)
|
||||
{
|
||||
_interactionArea.IsActive = state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://boehox1ydbcnx
|
||||
@@ -0,0 +1 @@
|
||||
uid://cnggo5jyimosu
|
||||
Reference in New Issue
Block a user