From e3dc285866822947a1a6710eb721d99922a4d8af Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 31 Dec 2022 02:11:58 +0100 Subject: Added Pause --- kurator/CMakeLists.txt | 1 + kurator/src/Battle.cpp | 5 ++++- kurator/src/Pause.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ kurator/src/Pause.h | 28 +++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 kurator/src/Pause.cpp create mode 100644 kurator/src/Pause.h 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(session, session->current())); battle->update(dt * time_factor); auto& registry = battle->registry(); auto timers = registry.view(); 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 +#include + +#include +#include + +#include "Scene.h" +#include "Session.h" + + +namespace kurator +{ + + +Pause::Pause(std::shared_ptr _session, std::shared_ptr _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 + +#include "Scene.h" +#include "SceneFrame.h" +#include "Session.h" + + +namespace kurator +{ + + +class Pause : public Scene +{ +public: + Pause(std::shared_ptr _session, std::shared_ptr _scene); + void update(float dt) override; + void draw() const override; + void stop() const; +private: + std::shared_ptr session; + std::shared_ptr scene; + SceneFrame frame; +}; + + +} // namespace kurator -- cgit v1.1