diff --git a/Cirno.sln.DotSettings.user b/Cirno.sln.DotSettings.user index 514ca554..2361dae1 100644 --- a/Cirno.sln.DotSettings.user +++ b/Cirno.sln.DotSettings.user @@ -31,5 +31,6 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs b/Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs index 6ac77773..ab4e9e3a 100644 --- a/Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs +++ b/Scripts/Components/FSM/3DPlayer/IsoActivationProvider.cs @@ -6,9 +6,8 @@ using Godot; namespace Cirno.Scripts.Components.FSM._3DPlayer; -public partial class IsoActivationProvider: Area3D, IModule +public partial class IsoActivationProvider : Area3D, IModule { - private bool _enabled = false; public bool Enabled @@ -20,19 +19,21 @@ public partial class IsoActivationProvider: Area3D, IModule StateMachine { get; private set; } - + private CollisionShape3D _collisionShape; - + public void EnterState(PlayerState state) { Enabled = true; @@ -50,13 +51,15 @@ public partial class IsoActivationProvider: Area3D, IModule machine) { StateMachine = machine; - + _collisionShape = GetNode("CollisionShape"); - + _selectorController.Hide(); - - SpawnSelector(); - + + _selectorController.ShowSelector += ShowSelector; + _selectorController.HideSelector += HideSelector; + _selectorController.ChangeParent3D += OnChangeParent3D; + // if (SelectorScene is not null && _selector is null) // { // _selector = actor.CreateSibling(SelectorScene, this.GlobalPosition); @@ -64,16 +67,57 @@ public partial class IsoActivationProvider: Area3D, IModule(); + //node.AddChild(_selector); + StateMachine.MainObject.GetParent().AddChild(_selector); + //sel.GlobalPosition = StateMachine.MainObject.GlobalPosition; + + _selector.GlobalPosition = node.GlobalPosition; + } + //_selector.Position = Vector3.Zero; + } + + private void ShowSelector() + { + if (IsInstanceValid(_selector)) + { + _selector?.Show(); + } + } + + private void HideSelector() + { + if (IsInstanceValid(_selector)) + { + _selector?.Hide(); + } + } + + + private void SpawnSelector(Node3D parent) { var sel = SelectorScene.Instantiate(); StateMachine.MainObject.GetParent().AddChild(sel); sel.GlobalPosition = StateMachine.MainObject.GlobalPosition; - _selectorController.ShowSelector += () => - { - sel.Show(); - }; + _selectorController.ShowSelector += () => { sel.Show(); }; _selectorController.HideSelector += () => { @@ -103,13 +147,12 @@ public partial class IsoActivationProvider: Area3D, IModule ScanTargets() { var spaceState = GetWorld3D().DirectSpaceState; @@ -182,7 +228,6 @@ public partial class IsoActivationProvider: Area3D, IModule _canSelect; private bool _autoSelect = false; - + private double _cooldownTimer = 0f; - + private Interactable _lastInteractable; private List _interactables = []; @@ -40,6 +40,7 @@ public partial class SelectorController : Node if (value >= _interactables.Count) { _selectedInteractable = 0; + return; } if (value < 0) @@ -49,21 +50,35 @@ public partial class SelectorController : Node // { // _selectedInteractable = 0; // } + return; } + + _selectedInteractable = value; } } + public IInteractable GetSelectedInteractable() + { + return SelectedInteractableIndex < 0 + ? null + : _interactables.Count > 0 + ? SelectedInteractableIndex >= _interactables.Count + ? _interactables[^1] + : _interactables[SelectedInteractableIndex] + : null; + } + public IInteractable SelectedInteractable { // The problem here is that if it's deselected the index is -1 - get => - SelectedInteractableIndex < 0 - ? null - : _interactables.Count > 0 - ? SelectedInteractableIndex >= _interactables.Count - ? _interactables[^1] - : _interactables[SelectedInteractableIndex] - : null; + // get => + // SelectedInteractableIndex < 0 + // ? null + // : _interactables.Count > 0 + // ? SelectedInteractableIndex >= _interactables.Count + // ? _interactables[^1] + // : _interactables[SelectedInteractableIndex] + // : null; set { // Passing null deselects the interactable @@ -128,8 +143,6 @@ public partial class SelectorController : Node { _interactables.Add(interactable); - // Always set the current one to the newest - SelectedInteractable = interactable; // if (_interactables.Count == 1) // { @@ -138,6 +151,9 @@ public partial class SelectorController : Node // } } + // Always set the current one to the newest + SelectedInteractable = interactable; + UpdatePosition(); } @@ -153,7 +169,6 @@ public partial class SelectorController : Node SelectedInteractable = null; //SelectedInteractableIndex = -1; EmitSignalHideSelector(); - } public void DeselectWithCooldown() @@ -165,11 +180,12 @@ public partial class SelectorController : Node public void UpdatePosition() { - if (SelectedInteractable != null) + var selected = GetSelectedInteractable(); + if (selected != null) { - EmitSignalChangePosition(SelectedInteractable.GetScreenPosition()); + EmitSignalChangePosition(selected.GetScreenPosition()); //EmitSignalChangePosition3D(); - EmitSignalChangeParent3D(SelectedInteractable as Node3D); + EmitSignalChangeParent3D(selected as Node3D); EmitSignalShowSelector(); } else