🐛 Rebase fixing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
|
||||
@@ -11,19 +12,21 @@ public partial class InteractionArea2D : Node2D
|
||||
[Export] private bool _active = true;
|
||||
[Export] private bool _useOutline = true;
|
||||
[Export] private ShaderMaterial _outlineMaterial;
|
||||
[Export] private bool _useSprite = true;
|
||||
[Export] private CanvasItem _spriteToOutline;
|
||||
[Export] private CanvasItem? _spriteToOutline; // keep to not break old usages. TODO: remove later
|
||||
[Export] private CanvasItem[] _spritesToOutline;
|
||||
[Export] private bool _showLabel = true;
|
||||
[Export] private int _id = -1; // TODO: remove
|
||||
|
||||
private Material _backupMaterial;
|
||||
private Material[] _backupMaterials;
|
||||
|
||||
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
||||
|
||||
[Signal] public delegate void InteractedEventHandler();
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get => _active;
|
||||
set => _active = value;
|
||||
set => _active = value;
|
||||
}
|
||||
|
||||
public void SetActiveInverse(bool active)
|
||||
@@ -33,52 +36,66 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_useSprite && _useOutline)
|
||||
if (_useOutline)
|
||||
{
|
||||
try
|
||||
{
|
||||
_backupMaterial = _spriteToOutline.Material;
|
||||
// support old implementations of the script. If the sprite to outline is set, add it to the array
|
||||
if (_spriteToOutline != null)
|
||||
{
|
||||
Array.Resize(ref _spritesToOutline, _spritesToOutline.Length + 1);
|
||||
_spritesToOutline[^1] = _spriteToOutline;
|
||||
}
|
||||
|
||||
_backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray();
|
||||
}
|
||||
catch(Exception exception)
|
||||
catch (Exception exception)
|
||||
{
|
||||
GD.PrintErr($"No sprite to outline found on: {GetParent().Name}" + exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnPlayerEntered(Node2D player)
|
||||
{
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
return;
|
||||
|
||||
if(_showLabel)
|
||||
|
||||
if (_showLabel)
|
||||
_label.Show();
|
||||
|
||||
if (!_useSprite || !_useOutline)
|
||||
|
||||
if (!_useOutline)
|
||||
return;
|
||||
|
||||
_spriteToOutline.Material = _outlineMaterial;
|
||||
|
||||
foreach (var sprite in _spritesToOutline)
|
||||
{
|
||||
sprite.Material = _outlineMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerExited(Node2D player)
|
||||
{
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
|
||||
_label.Hide();
|
||||
|
||||
if (!_useSprite || !_useOutline)
|
||||
if (!_useOutline)
|
||||
return;
|
||||
|
||||
_spriteToOutline.Material = _backupMaterial;
|
||||
|
||||
for (var i = 0; i < _spritesToOutline.Length; i++)
|
||||
{
|
||||
var sprite = _spritesToOutline[i];
|
||||
sprite.Material = _backupMaterials[i];
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
return;
|
||||
|
||||
|
||||
if (@event.IsAction("interact") && @event.IsPressed())
|
||||
{
|
||||
TryInteract();
|
||||
@@ -95,10 +112,16 @@ public partial class InteractionArea2D : Node2D
|
||||
if (_area.HasOverlappingAreas())
|
||||
{
|
||||
_label.Hide();
|
||||
|
||||
if (_useSprite && _useOutline)
|
||||
_spriteToOutline.Material = _backupMaterial;
|
||||
|
||||
|
||||
if (_useOutline)
|
||||
{
|
||||
for (var i = 0; i < _spritesToOutline.Length; i++)
|
||||
{
|
||||
var sprite = _spritesToOutline[i];
|
||||
sprite.Material = _backupMaterials[i];
|
||||
}
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
@@ -107,7 +130,7 @@ public partial class InteractionArea2D : Node2D
|
||||
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
||||
{
|
||||
GD.PrintErr("SetSpriteActiveState is being called.");
|
||||
if(!_active)
|
||||
if (!_active)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user