From bdcb33d99248cca77133272f22d85bfef4d9f815 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 10 Mar 2016 12:46:06 +0100 Subject: [PATCH] Mouse always unlocked on game start and on disconnecting (i.e when menu shows). --- include/Game/Systems/SpectatorCameraSystem.h | 3 +++ resources/DefaultInput.ini | 4 +++- src/Engine/Editor/EditorSystem.cpp | 1 + src/Engine/Network/Client.cpp | 7 ++++++- src/Game/Systems/SpectatorCameraSystem.cpp | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/Game/Systems/SpectatorCameraSystem.h b/include/Game/Systems/SpectatorCameraSystem.h index 5a00279b..bc7aa860 100644 --- a/include/Game/Systems/SpectatorCameraSystem.h +++ b/include/Game/Systems/SpectatorCameraSystem.h @@ -3,6 +3,7 @@ #include "Core/System.h" #include "Input/EInputCommand.h" +#include "Network/EPlayerDisconnected.h" class SpectatorCameraSystem : public ImpureSystem { @@ -17,6 +18,8 @@ private: EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); + EventRelay m_EDisconnect; + bool OnDisconnect(const Events::PlayerDisconnected& e); }; #endif \ No newline at end of file diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 18fb943f..840e5cd0 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -29,4 +29,6 @@ K=TakeDamage,1500 F2=PerformanceTimingResetAllTimers F3=PerformanceTimingCreateExcelData Comma=SwapToClassPick -Period=SwapToTeamPick \ No newline at end of file +Period=SwapToTeamPick +Enter=PickClass,1 +F5=DisconnectFromServer \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 5e0d02fd..89f6ef5c 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -47,6 +47,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame Enable(); } else { Disable(); + m_EventBroker->Publish(Events::UnlockMouse()); } } diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index b4eafbcb..02ffc78a 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -1,4 +1,5 @@ #include "Network/Client.h" +#include "Network/EPlayerDisconnected.h" using namespace boost::asio::ip; Client::Client(World* world, EventBroker* eventBroker) @@ -224,7 +225,7 @@ void Client::parseServerlist(Packet& packet) void Client::parseKick() { LOG_WARNING("You have been kicked from the server."); - m_IsConnected = false; + disconnect(); } void Client::parseSpawnEvents() @@ -464,6 +465,10 @@ void Client::disconnect() Packet packet(MessageType::Disconnect, m_SendPacketID); m_Reliable.Send(packet); m_Reliable.Disconnect(); + Events::PlayerDisconnected e; + e.Entity = m_LocalPlayer.ID; + e.PlayerID = -1; + m_EventBroker->Publish(e); createMainMenu(); } diff --git a/src/Game/Systems/SpectatorCameraSystem.cpp b/src/Game/Systems/SpectatorCameraSystem.cpp index d1f2f1ce..23dfb164 100644 --- a/src/Game/Systems/SpectatorCameraSystem.cpp +++ b/src/Game/Systems/SpectatorCameraSystem.cpp @@ -8,6 +8,7 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params) , m_PickedTeam(-1) { EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand); + EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect); } void SpectatorCameraSystem::Update(double dt) @@ -87,4 +88,17 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) } return true; -} \ No newline at end of file +} + +bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e) +{ + // If local player gets disconnected, they should be set to + // the spectator camera next time a map loads that has one. + if (e.Entity == LocalPlayer.ID) { + m_CamSetToTeamPick = false; + // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); + } + return true; +}