2022-08-16 22:18:44 +01:00
|
|
|
|
using QSB.Localization;
|
|
|
|
|
using UnityEngine;
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.ShipSync;
|
|
|
|
|
|
|
|
|
|
public class ShipCustomAttach : MonoBehaviour
|
2022-01-31 16:33:11 -08:00
|
|
|
|
{
|
2022-08-16 16:22:22 -07:00
|
|
|
|
private readonly ScreenPrompt _attachPrompt = new(
|
2022-08-16 22:18:44 +01:00
|
|
|
|
InputLibrary.interactSecondary,
|
|
|
|
|
InputLibrary.interact,
|
|
|
|
|
QSBLocalization.Current.AttachToShip + " <CMD>",
|
2022-08-16 16:22:22 -07:00
|
|
|
|
ScreenPrompt.MultiCommandType.HOLD_ONE_AND_PRESS_2ND
|
|
|
|
|
);
|
2022-08-16 22:18:44 +01:00
|
|
|
|
|
2022-08-16 16:22:22 -07:00
|
|
|
|
private readonly ScreenPrompt _detachPrompt = new(
|
2022-08-16 22:18:44 +01:00
|
|
|
|
InputLibrary.cancel,
|
2022-08-16 16:22:22 -07:00
|
|
|
|
QSBLocalization.Current.DetachFromShip + " <CMD>"
|
|
|
|
|
);
|
2022-08-16 22:18:44 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private PlayerAttachPoint _playerAttachPoint;
|
|
|
|
|
|
2022-09-10 17:23:26 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// uses a static field instead of a persistent condition cuz those are synced
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static bool _tutorialPrompt = true;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private void Awake()
|
2022-01-31 16:33:11 -08:00
|
|
|
|
{
|
2022-09-10 17:23:26 -07:00
|
|
|
|
Locator.GetPromptManager().AddScreenPrompt(_attachPrompt, _tutorialPrompt ? PromptPosition.Center : PromptPosition.UpperRight);
|
2022-03-29 11:16:43 -07:00
|
|
|
|
Locator.GetPromptManager().AddScreenPrompt(_detachPrompt, PromptPosition.UpperRight);
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
_playerAttachPoint = gameObject.AddComponent<PlayerAttachPoint>();
|
|
|
|
|
_playerAttachPoint._lockPlayerTurning = false;
|
|
|
|
|
_playerAttachPoint._matchRotation = false;
|
|
|
|
|
_playerAttachPoint._centerCamera = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
if (Locator.GetPromptManager())
|
2022-01-31 16:33:11 -08:00
|
|
|
|
{
|
2022-09-10 17:23:26 -07:00
|
|
|
|
Locator.GetPromptManager().RemoveScreenPrompt(_attachPrompt);
|
|
|
|
|
Locator.GetPromptManager().RemoveScreenPrompt(_detachPrompt);
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
_attachPrompt.SetVisibility(false);
|
|
|
|
|
_detachPrompt.SetVisibility(false);
|
2022-09-10 17:10:35 -07:00
|
|
|
|
// dont show prompt if paused or something
|
|
|
|
|
if (!OWInput.IsInputMode(InputMode.Character))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
var attachedToUs = _playerAttachPoint.enabled;
|
|
|
|
|
_detachPrompt.SetVisibility(attachedToUs);
|
|
|
|
|
if (attachedToUs && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.Character))
|
2022-01-31 17:26:35 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
_playerAttachPoint.DetachPlayer();
|
|
|
|
|
ShipManager.Instance.CockpitController._shipAudioController.PlayUnbuckle();
|
2022-01-31 17:26:35 -08:00
|
|
|
|
}
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-07-16 10:58:50 -07:00
|
|
|
|
if (!PlayerState.IsInsideShip())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (!attachedToUs)
|
2022-01-31 16:33:11 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (PlayerState.IsAttached())
|
2022-01-31 16:33:11 -08:00
|
|
|
|
{
|
2022-02-27 04:40:44 -08:00
|
|
|
|
return;
|
2022-01-31 16:33:11 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (Locator.GetPlayerController() && !Locator.GetPlayerController().IsGrounded())
|
2022-02-07 20:48:17 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return;
|
2022-01-31 16:33:11 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2022-01-31 16:33:11 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
_attachPrompt.SetVisibility(!attachedToUs);
|
|
|
|
|
if (!attachedToUs &&
|
2022-07-16 10:58:50 -07:00
|
|
|
|
OWInput.IsPressed(InputLibrary.interactSecondary, InputMode.Character) &&
|
|
|
|
|
OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.Character))
|
2022-03-02 19:46:33 -08:00
|
|
|
|
{
|
|
|
|
|
transform.position = Locator.GetPlayerTransform().position;
|
|
|
|
|
_playerAttachPoint.AttachPlayer();
|
|
|
|
|
ShipManager.Instance.CockpitController._shipAudioController.PlayBuckle();
|
2022-09-10 17:23:26 -07:00
|
|
|
|
|
|
|
|
|
if (_tutorialPrompt)
|
|
|
|
|
{
|
|
|
|
|
_tutorialPrompt = false;
|
|
|
|
|
Locator.GetPromptManager().RemoveScreenPrompt(_attachPrompt);
|
|
|
|
|
Locator.GetPromptManager().AddScreenPrompt(_attachPrompt, PromptPosition.UpperRight);
|
|
|
|
|
}
|
2022-01-31 16:33:11 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-16 10:58:50 -07:00
|
|
|
|
}
|