satellite projector stuffz

This commit is contained in:
Mister_Nebula 2021-11-03 09:18:52 +00:00
parent a53e599364
commit 838940942f
12 changed files with 222 additions and 6 deletions

View File

@ -89,5 +89,8 @@
public static string QSBDebugEvent = "QSBDebugEvent";
public static string QSBEnterNomaiHeadZone = "QSBEnterNomaiHeadZone";
public static string QSBExitNomaiHeadZone = "QSBExitNomaiHeadZone";
public static string QSBEnterSatelliteCamera = "QSBEnterSatelliteCamera";
public static string QSBExitSatelliteCamera = "QSBExitSatelliteCamera";
public static string QSBSatelliteSnapshot = "QSBSatelliteSnapshot";
}
}

View File

@ -6,6 +6,8 @@
* MISC.
*/
DebugEvent,
SatelliteProjector,
SatelliteProjectorSnapshot,
/*
* SERVER EVENTS

View File

@ -15,6 +15,7 @@ using QSB.Player.Events;
using QSB.ProbeSync.Events;
using QSB.QuantumSync.Events;
using QSB.RoastingSync.Events;
using QSB.SatelliteSync.Events;
using QSB.ShipSync.Events;
using QSB.ShipSync.Events.Component;
using QSB.ShipSync.Events.Hull;
@ -69,6 +70,7 @@ namespace QSB.Events
new ServerStateEvent(),
new ClientStateEvent(),
new DebugEvent(),
new SatelliteProjectorEvent(),
// World Objects
new ElevatorEvent(),
new GeyserEvent(),

View File

@ -16,6 +16,7 @@ using QSB.Player.Patches;
using QSB.PoolSync.Patches;
using QSB.QuantumSync.Patches;
using QSB.RoastingSync.Patches;
using QSB.SatelliteSync.Patches;
using QSB.ShipSync.Patches;
using QSB.StatueSync.Patches;
using QSB.TimeSync.Patches;
@ -67,7 +68,8 @@ namespace QSB.Patches
new MapPatches(),
new RespawnPatches(),
new LauncherPatches(),
new SolanumPatches()
new SolanumPatches(),
new SatelliteProjectorPatches()
};
TypeToInstance = new Dictionary<QSBPatchTypes, Harmony>

View File

@ -200,6 +200,10 @@
<Compile Include="QuantumSync\QuantumManager.cs" />
<Compile Include="QuantumSync\Patches\QuantumVisibilityPatches.cs" />
<Compile Include="QuantumSync\Patches\ServerQuantumPatches.cs" />
<Compile Include="SatelliteSync\Events\SatelliteProjectorEvent.cs" />
<Compile Include="SatelliteSync\Events\SatelliteProjectorSnapshotEvent.cs" />
<Compile Include="SatelliteSync\Patches\SatelliteProjectorPatches.cs" />
<Compile Include="SatelliteSync\SatelliteProjectorManager.cs" />
<Compile Include="SectorSync\TargetType.cs" />
<Compile Include="ClientServerStateSync\Events\ServerStateEvent.cs" />
<Compile Include="ClientServerStateSync\ServerState.cs" />

View File

@ -16,6 +16,7 @@ using QSB.Player;
using QSB.Player.TransformSync;
using QSB.PoolSync;
using QSB.QuantumSync;
using QSB.SatelliteSync;
using QSB.SectorSync;
using QSB.ShipSync;
using QSB.StatueSync;
@ -102,6 +103,7 @@ namespace QSB
gameObject.AddComponent<DebugGUI>();
gameObject.AddComponent<MenuManager>();
gameObject.AddComponent<RespawnManager>();
gameObject.AddComponent<SatelliteProjectorManager>();
// WorldObject managers
gameObject.AddComponent<QuantumManager>();

View File

@ -0,0 +1,42 @@
using QSB.Events;
using QSB.Messaging;
namespace QSB.SatelliteSync.Events
{
class SatelliteProjectorEvent : QSBEvent<BoolMessage>
{
public override EventType Type => EventType.SatelliteProjector;
public override void SetupListener()
{
GlobalMessenger.AddListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.AddListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
public override void CloseListener()
{
GlobalMessenger.RemoveListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.RemoveListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
private void Handler(bool usingProjector) => SendEvent(CreateMessage(usingProjector));
private BoolMessage CreateMessage(bool usingProjector) => new BoolMessage
{
AboutId = LocalPlayerId,
Value = usingProjector
};
public override void OnReceiveRemote(bool isHost, BoolMessage message)
{
if (message.Value)
{
SatelliteProjectorManager.Instance.RemoteEnter();
}
else
{
SatelliteProjectorManager.Instance.RemoteExit();
}
}
}
}

View File

@ -0,0 +1,34 @@
using QSB.Events;
using QSB.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.SatelliteSync.Events
{
class SatelliteProjectorSnapshotEvent : QSBEvent<BoolMessage>
{
public override EventType Type => EventType.SatelliteProjectorSnapshot;
public override void SetupListener()
{
GlobalMessenger<bool>.AddListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward));
}
public override void CloseListener()
{
GlobalMessenger<bool>.RemoveListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward));
}
private void Handler(bool forward) => SendEvent(CreateMessage(forward));
private BoolMessage CreateMessage(bool forward) => new BoolMessage
{
AboutId = LocalPlayerId,
Value = forward
};
public override void OnReceiveRemote(bool isHost, BoolMessage message) => SatelliteProjectorManager.Instance.RemoteTakeSnapshot(message.Value);
}
}

View File

@ -0,0 +1,28 @@
using HarmonyLib;
using QSB.Events;
using QSB.Patches;
namespace QSB.SatelliteSync.Patches
{
[HarmonyPatch]
class SatelliteProjectorPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.OnPressInteract))]
public static bool UseProjector()
{
QSBEventManager.FireEvent(EventNames.QSBEnterSatelliteCamera);
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.TurnOffProjector))]
public static bool LeaveProjector()
{
QSBEventManager.FireEvent(EventNames.QSBExitSatelliteCamera);
return true;
}
}
}

View File

@ -0,0 +1,89 @@
using QSB.Utility;
using System.Linq;
using UnityEngine;
namespace QSB.SatelliteSync
{
class SatelliteProjectorManager : MonoBehaviour
{
public static SatelliteProjectorManager Instance { get; private set; }
public SatelliteSnapshotController Projector { get; private set; }
public void Start()
{
Instance = this;
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
}
public void OnDestroy()
{
QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(OWScene oldScene, OWScene newScene)
{
if (newScene == OWScene.SolarSystem)
{
Projector = Resources.FindObjectsOfTypeAll<SatelliteSnapshotController>().First();
Projector._loopingSource.spatialBlend = 1f;
Projector._oneShotSource.spatialBlend = 1f;
}
}
public void RemoteEnter()
{
DebugLog.DebugWrite($"Remote Enter");
Projector.enabled = true;
Projector._interactVolume.DisableInteraction();
if (Projector._showSplashTexture)
{
Projector._splashObject.SetActive(false);
Projector._diagramObject.SetActive(true);
Projector._projectionScreen.gameObject.SetActive(false);
}
if (Projector._fadeLight != null)
{
Projector._fadeLight.StartFade(0f, 2f, 0f);
}
var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorActivate, 1f);
Projector._loopingSource.FadeIn(audioClip.length, false, false, 1f);
}
public void RemoteExit()
{
DebugLog.DebugWrite($"Remote Exit");
Projector.enabled = false;
Projector._interactVolume.ResetInteraction();
if (Projector._showSplashTexture)
{
Projector._splashObject.SetActive(true);
Projector._diagramObject.SetActive(false);
Projector._projectionScreen.gameObject.SetActive(false);
}
if (Projector._fadeLight != null)
{
Projector._fadeLight.StartFade(Projector._initLightIntensity, 2f, 0f);
}
var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorStop, 1f);
Projector._loopingSource.FadeOut(audioClip.length, OWAudioSource.FadeOutCompleteAction.STOP, 0f);
}
public void RemoteTakeSnapshot(bool forward)
{
Projector._satelliteCamera.transform.localEulerAngles = forward
? Projector._initCamLocalRot
: Projector._initCamLocalRot + new Vector3(0f, 180f, 0f);
Projector.RenderSnapshot();
}
}
}

View File

@ -71,12 +71,20 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
// TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)?
// this would probably be a whole qsb version on it's own
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayRetrievalClip))]
public static void ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f;
public static bool ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayLaunchClip))]
public static void ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f;
public static bool ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
}
}

View File

@ -3,7 +3,7 @@
"settings": {
"defaultServerIP": "localhost",
"port": 7777,
"debugMode": false,
"debugMode": true,
"showLinesInDebug": false
}
}