From 48e564a32c266c8d4649c6f50bf4eac56f771c0d Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Fri, 2 Jul 2021 12:26:39 +0500 Subject: Added Respawn screen --- cwd/assets/altcraft/scripts/init.lua | 1 + cwd/assets/altcraft/ui/respawn-styles.rcss | 24 ++++++++++++++++++++++++ cwd/assets/altcraft/ui/respawn.rml | 12 ++++++++++++ src/Game.hpp | 1 + src/GameState.cpp | 12 ++++++++---- src/GameState.hpp | 4 ++++ src/Plugin.cpp | 3 ++- src/Render.cpp | 4 ++++ 8 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 cwd/assets/altcraft/ui/respawn-styles.rcss create mode 100644 cwd/assets/altcraft/ui/respawn.rml diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index ffd74b7..e13fc81 100644 --- a/cwd/assets/altcraft/scripts/init.lua +++ b/cwd/assets/altcraft/scripts/init.lua @@ -16,6 +16,7 @@ function plugin.onLoad () con:LoadDocument("altcraft/ui/pause") con:LoadDocument("altcraft/ui/options") con:LoadDocument("altcraft/ui/loading") + con:LoadDocument("altcraft/ui/respawn") uiMainMenu:Show() AC.Settings.Load() diff --git a/cwd/assets/altcraft/ui/respawn-styles.rcss b/cwd/assets/altcraft/ui/respawn-styles.rcss new file mode 100644 index 0000000..c6bbd7a --- /dev/null +++ b/cwd/assets/altcraft/ui/respawn-styles.rcss @@ -0,0 +1,24 @@ +.body-respawn { + background-color: #800000AA; +} + +#died { + font-size: 10vh; + margin: 30% auto auto; +} + +#respawn { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 10% auto auto; +} + +#disconnect { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 20% auto auto; +} diff --git a/cwd/assets/altcraft/ui/respawn.rml b/cwd/assets/altcraft/ui/respawn.rml new file mode 100644 index 0000000..093a169 --- /dev/null +++ b/cwd/assets/altcraft/ui/respawn.rml @@ -0,0 +1,12 @@ + + + + + NeedRespawn + + + You died! + + + + diff --git a/src/Game.hpp b/src/Game.hpp index f7efd11..74eeea9 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -13,6 +13,7 @@ enum class State { Paused, Inventory, Chat, + NeedRespawn, }; void RunGame(); diff --git a/src/GameState.cpp b/src/GameState.cpp index bb93c45..50a9004 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -456,9 +456,8 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { auto packet = std::static_pointer_cast(ptr); playerStatus.health = packet->Health; if (playerStatus.health <= 0) { - LOG(INFO) << "Player is dead. Respawning..."; - auto packetPerformRespawn = std::make_shared(0); - PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); + LOG(INFO) << "Player is dead. Need respawn..."; + SetState(State::NeedRespawn); } break; } @@ -681,4 +680,9 @@ void GameState::PlaceBlock() { auto packet = std::static_pointer_cast(packetPlace); PUSH_EVENT("SendPacket", packet); -} \ No newline at end of file +} + +void GameState::PerformRespawn() { + auto packetPerformRespawn = std::make_shared(0); + PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); +} diff --git a/src/GameState.hpp b/src/GameState.hpp index 0ca858f..ca2ea81 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -75,6 +75,8 @@ class GameState { bool receivedFirstPlayerPosAndLook = false; + std::shared_ptr packetRespawn; + public: void Update(double deltaTime); @@ -89,6 +91,8 @@ public: void PlaceBlock(); + void PerformRespawn(); + enum MoveType { FORWARD, BACKWARD, LEFT, RIGHT, JUMP }; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f759d5f..64fc00b 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -174,7 +174,8 @@ void PluginSystem::Init() { "GetGameStatus", &GameState::GetGameStatus, "GetPlayerStatus", &GameState::GetPlayerStatus, "GetSelectionStatus", &GameState::GetSelectionStatus, - "GetInventory", &GameState::GetInventory); + "GetInventory", &GameState::GetInventory, + "PerformRespawn", &GameState::PerformRespawn); lua.new_usertype("TimeStatus", "interpolatedTimeOfDay", &TimeStatus::interpolatedTimeOfDay, diff --git a/src/Render.cpp b/src/Render.cpp index bee8ffb..6aecd88 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -498,6 +498,10 @@ void Render::InitEvents() { PluginSystem::CallOnChangeState("Chat"); SetMouseCapture(false); break; + case State::NeedRespawn: + PluginSystem::CallOnChangeState("NeedRespawn"); + SetMouseCapture(false); + break; } }); -- cgit v1.2.3