summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-07-02 09:26:39 +0200
committerLaG1924 <lag1924@gmail.com>2021-07-03 10:36:56 +0200
commit48e564a32c266c8d4649c6f50bf4eac56f771c0d (patch)
tree34fbd849a2b0f1ded8ab8d87c1e4a300107b2e0e
parentAdded Loading screen (diff)
downloadAltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.gz
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.bz2
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.lz
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.xz
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.zst
AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.zip
-rw-r--r--cwd/assets/altcraft/scripts/init.lua1
-rw-r--r--cwd/assets/altcraft/ui/respawn-styles.rcss24
-rw-r--r--cwd/assets/altcraft/ui/respawn.rml12
-rw-r--r--src/Game.hpp1
-rw-r--r--src/GameState.cpp12
-rw-r--r--src/GameState.hpp4
-rw-r--r--src/Plugin.cpp3
-rw-r--r--src/Render.cpp4
8 files changed, 56 insertions, 5 deletions
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 @@
+<rml>
+ <head>
+ <link type="text/rcss" href="mc-styles" />
+ <link type="text/rcss" href="respawn-styles" />
+ <title>NeedRespawn</title>
+ </head>
+ <body class="body-respawn">
+ <strong class="mc-title" id="died">You died!</strong>
+ <button class="mc-button" onclick="AC.GetGameState():PerformRespawn()" id="respawn">Respawn</button>
+ <button class="mc-button" onclick="AC.Disconnect()" id="disconnect">Title screen</button>
+ </body>
+</rml>
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<Packet> ptr) {
auto packet = std::static_pointer_cast<PacketUpdateHealth>(ptr);
playerStatus.health = packet->Health;
if (playerStatus.health <= 0) {
- LOG(INFO) << "Player is dead. Respawning...";
- auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0);
- PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(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<Packet>(packetPlace);
PUSH_EVENT("SendPacket", packet);
-} \ No newline at end of file
+}
+
+void GameState::PerformRespawn() {
+ auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0);
+ PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(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> 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>("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;
}
});