Unlocks mouse when changing to SpectatorCamera and locking when respawning.

This commit is contained in:
William Moberg
2016-03-04 09:49:27 +01:00
parent 7a2f1ac9fd
commit 0dfe00b406
4 changed files with 24 additions and 9 deletions
+1
View File
@@ -25,6 +25,7 @@ private:
EventRelay<PlayerDeathSystem, Events::EntityDeleted> m_EEntityDeleted; EventRelay<PlayerDeathSystem, Events::EntityDeleted> m_EEntityDeleted;
bool OnEntityDeleted(Events::EntityDeleted& e); bool OnEntityDeleted(Events::EntityDeleted& e);
void setSpectatorCamera();
void createDeathEffect(EntityWrapper player); void createDeathEffect(EntityWrapper player);
}; };
+15 -9
View File
@@ -1,4 +1,5 @@
#include "Systems/PlayerDeathSystem.h" #include "Systems/PlayerDeathSystem.h"
#include "Core/ELockMouse.h"
PlayerDeathSystem::PlayerDeathSystem(SystemParams params) PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
: System(params) : System(params)
@@ -33,10 +34,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
//components that we need from player //components that we need from player
auto playerModel = player.FirstChildByName("PlayerModel"); auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid()) { if (!playerModel.Valid() || !playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
return; if (player == LocalPlayer) {
} setSpectatorCamera();
if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) { }
return; return;
} }
auto playerEntityModel = playerModel["Model"]; auto playerEntityModel = playerModel["Model"];
@@ -46,9 +47,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
playerEntityModel.Copy(deathEffectEW["Model"]); playerEntityModel.Copy(deathEffectEW["Model"]);
playerEntityAnimation.Copy(deathEffectEW["Animation"]); playerEntityAnimation.Copy(deathEffectEW["Animation"]);
//freeze the animation //freeze the animation
deathEffectEW["Animation"]["Speed1"] = 0.0; deathEffectEW["Animation"]["Speed"] = 0.0;
deathEffectEW["Animation"]["Speed2"] = 0.0;
deathEffectEW["Animation"]["Speed3"] = 0.0;
//copy the models position,orientation //copy the models position,orientation
deathEffectEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; deathEffectEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
@@ -73,13 +72,20 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
return false; return false;
} }
setSpectatorCamera();
return true;
}
void PlayerDeathSystem::setSpectatorCamera()
{
// Look for the spectator camera entity in the level. // Look for the spectator camera entity in the level.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) { if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
return false; return;
} }
Events::SetCamera eSetCamera; Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam; eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera); m_EventBroker->Publish(eSetCamera);
return true; Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
} }
+3
View File
@@ -1,4 +1,5 @@
#include "Systems/PlayerSpawnSystem.h" #include "Systems/PlayerSpawnSystem.h"
#include "Core/ELockMouse.h"
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params) PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
: System(params) : System(params)
@@ -100,6 +101,8 @@ void PlayerSpawnSystem::Update(double dt)
e.Player = player; e.Player = player;
e.Spawner = spawner; e.Spawner = spawner;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
Events::LockMouse lock;
m_EventBroker->Publish(lock);
++numSpawnedPlayers; ++numSpawnedPlayers;
it = m_SpawnRequests.erase(it); it = m_SpawnRequests.erase(it);
break; break;
@@ -1,5 +1,6 @@
#include "Systems/SpectatorCameraSystem.h" #include "Systems/SpectatorCameraSystem.h"
#include "Rendering/ESetCamera.h" #include "Rendering/ESetCamera.h"
#include "Core/ELockMouse.h"
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params) SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
: System(params) : System(params)
@@ -19,6 +20,8 @@ void SpectatorCameraSystem::Update(double dt)
Events::SetCamera eSetCamera; Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam; eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera); 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; Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam; eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera); m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
} }
return true; return true;