summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-31 02:11:58 +0100
committerAki <please@ignore.pl>2022-12-31 02:11:58 +0100
commite3dc285866822947a1a6710eb721d99922a4d8af (patch)
tree7a623c5b95b2784fa6e8fb7d21d04df4f1c44c97
parente5fb6a5cd3787d2af830de79cd87e2a0494d908b (diff)
downloadkurator-e3dc285866822947a1a6710eb721d99922a4d8af.zip
kurator-e3dc285866822947a1a6710eb721d99922a4d8af.tar.gz
kurator-e3dc285866822947a1a6710eb721d99922a4d8af.tar.bz2
Added Pause
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp5
-rw-r--r--kurator/src/Pause.cpp60
-rw-r--r--kurator/src/Pause.h28
4 files changed, 93 insertions, 1 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index c91d507..3a7fedc 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -7,6 +7,7 @@ add_executable(
src/colors.cpp
src/ForceBalance.cpp
src/main.cpp
+ src/Pause.cpp
src/ScenarioEditor.cpp
src/SceneBuilder.cpp
src/SceneFrame.cpp
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index f9f402e..52270b3 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -21,8 +21,9 @@
#include "colors.h"
#include "components.h"
-#include "Summary.h"
+#include "Pause.h"
#include "Session.h"
+#include "Summary.h"
namespace kurator
@@ -64,6 +65,8 @@ Battle::~Battle()
void
Battle::update(const float dt)
{
+ if (IsKeyPressed(KEY_ESCAPE))
+ return session->set(std::make_shared<Pause>(session, session->current()));
battle->update(dt * time_factor);
auto& registry = battle->registry();
auto timers = registry.view<Timed>();
diff --git a/kurator/src/Pause.cpp b/kurator/src/Pause.cpp
new file mode 100644
index 0000000..41d6e4b
--- /dev/null
+++ b/kurator/src/Pause.cpp
@@ -0,0 +1,60 @@
+#include "Pause.h"
+
+#include <memory>
+#include <utility>
+
+#include <raylib.h>
+#include <imgui.h>
+
+#include "Scene.h"
+#include "Session.h"
+
+
+namespace kurator
+{
+
+
+Pause::Pause(std::shared_ptr<Session> _session, std::shared_ptr<Scene> _scene) :
+ session {std::move(_session)},
+ scene {std::move(_scene)},
+ frame {scene}
+{
+}
+
+
+void
+Pause::update(float)
+{
+ frame.update();
+ ImGui::SetNextWindowSize({GetScreenWidth()/3.0f, 0.0f}, ImGuiCond_Once);
+ ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()/2.0f}, ImGuiCond_Once, {0.5f, 0.5f});
+ if (ImGui::Begin("Pause", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
+ if (ImGui::Button("Unpause", {-1.0f, 0.0f}))
+ stop();
+ if (ImGui::Button("Exit to Menu", {-1.0f, 0.0f}))
+ session->pop();
+ if (ImGui::Button("Exit to Desktop", {-1.0f, 0.0f}))
+ session->quit();
+ }
+ ImGui::End();
+ if (IsKeyPressed(KEY_SPACE))
+ stop();
+}
+
+
+void
+Pause::draw() const
+{
+ ClearBackground(BLACK);
+ frame.draw();
+}
+
+
+void
+Pause::stop() const
+{
+ session->set(frame.view());
+}
+
+
+} // namespace kurator
diff --git a/kurator/src/Pause.h b/kurator/src/Pause.h
new file mode 100644
index 0000000..b3c4575
--- /dev/null
+++ b/kurator/src/Pause.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <memory>
+
+#include "Scene.h"
+#include "SceneFrame.h"
+#include "Session.h"
+
+
+namespace kurator
+{
+
+
+class Pause : public Scene
+{
+public:
+ Pause(std::shared_ptr<Session> _session, std::shared_ptr<Scene> _scene);
+ void update(float dt) override;
+ void draw() const override;
+ void stop() const;
+private:
+ std::shared_ptr<Session> session;
+ std::shared_ptr<Scene> scene;
+ SceneFrame frame;
+};
+
+
+} // namespace kurator