Unlocks mouse when changing to SpectatorCamera and locking when respawning.
This commit is contained in:
@@ -25,6 +25,7 @@ private:
|
||||
EventRelay<PlayerDeathSystem, Events::EntityDeleted> m_EEntityDeleted;
|
||||
bool OnEntityDeleted(Events::EntityDeleted& e);
|
||||
|
||||
void setSpectatorCamera();
|
||||
void createDeathEffect(EntityWrapper player);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Systems/PlayerDeathSystem.h"
|
||||
#include "Core/ELockMouse.h"
|
||||
|
||||
PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
|
||||
: System(params)
|
||||
@@ -33,10 +34,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
|
||||
//components that we need from player
|
||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
if (!playerModel.Valid()) {
|
||||
return;
|
||||
}
|
||||
if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
|
||||
if (!playerModel.Valid() || !playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
|
||||
if (player == LocalPlayer) {
|
||||
setSpectatorCamera();
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto playerEntityModel = playerModel["Model"];
|
||||
@@ -46,9 +47,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
playerEntityModel.Copy(deathEffectEW["Model"]);
|
||||
playerEntityAnimation.Copy(deathEffectEW["Animation"]);
|
||||
//freeze the animation
|
||||
deathEffectEW["Animation"]["Speed1"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed2"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed3"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed"] = 0.0;
|
||||
|
||||
//copy the models position,orientation
|
||||
deathEffectEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
@@ -73,13 +72,20 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
setSpectatorCamera();
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerDeathSystem::setSpectatorCamera()
|
||||
{
|
||||
// Look for the spectator camera entity in the level.
|
||||
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
|
||||
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
return true;
|
||||
Events::UnlockMouse unlock;
|
||||
m_EventBroker->Publish(unlock);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Systems/PlayerSpawnSystem.h"
|
||||
#include "Core/ELockMouse.h"
|
||||
|
||||
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
||||
: System(params)
|
||||
@@ -100,6 +101,8 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
e.Player = player;
|
||||
e.Spawner = spawner;
|
||||
m_EventBroker->Publish(e);
|
||||
Events::LockMouse lock;
|
||||
m_EventBroker->Publish(lock);
|
||||
++numSpawnedPlayers;
|
||||
it = m_SpawnRequests.erase(it);
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Systems/SpectatorCameraSystem.h"
|
||||
#include "Rendering/ESetCamera.h"
|
||||
#include "Core/ELockMouse.h"
|
||||
|
||||
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
|
||||
: System(params)
|
||||
@@ -19,6 +20,8 @@ void SpectatorCameraSystem::Update(double dt)
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
Events::UnlockMouse unlock;
|
||||
m_EventBroker->Publish(unlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +63,8 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
Events::UnlockMouse unlock;
|
||||
m_EventBroker->Publish(unlock);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user