From acc2f0ca9dae4b23bee7a3078476683defb399ed Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 25 Jan 2022 19:53:58 +0100 Subject: [PATCH] Working to save and select classes --- .gitignore | 1 + include/character_sheet.hpp | 14 ++++++++++++++ include/gui/gui_data.hpp | 10 ++++++++++ src/controller.cpp | 14 ++++++++++++++ src/gui/gui.cpp | 14 ++++++++++++++ src/main.cpp | 2 +- 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0ad36d2..59919d4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ cmake-* build/ !.idea/cmake.xml .idea/* +*.json imgui.ini \ No newline at end of file diff --git a/include/character_sheet.hpp b/include/character_sheet.hpp index caf686c..9529d8f 100644 --- a/include/character_sheet.hpp +++ b/include/character_sheet.hpp @@ -12,9 +12,17 @@ namespace gui { } namespace character { + enum class classe : std::uint32_t { + Guerrier = 0, + Prudent = 1, + Paysan = 2, + Debrouillard = 3, + }; + class CharacterSheet final { private: friend gui::Gui; + friend class Controller; std::mt19937_64 engine{ std::random_device{ "rdseed" }() }; @@ -29,6 +37,8 @@ namespace character { characteristic::Habilete habilete; + classe current_class{ classe::Guerrier }; + std::uint32_t health_point{ 0 }; std::uint32_t armor{ 0 }; @@ -53,6 +63,8 @@ namespace character { [[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; } + [[nodiscard]] classe get_current_class() const { return current_class; } + [[nodiscard]] std::uint32_t get_health_point() const { return health_point; } [[nodiscard]] std::uint32_t get_armor() const { return armor; } @@ -69,6 +81,7 @@ namespace character { j.at("endurance").get_to(billy.endurance); j.at("chance").get_to(billy.chance); j.at("habilete").get_to(billy.habilete); + j.at("classe").get_to(billy.current_class); j.at("health_point").get_to(billy.health_point); j.at("armor").get_to(billy.armor); j.at("damage").get_to(billy.damage); @@ -83,6 +96,7 @@ namespace character { j["endurance"] = billy.get_endurance(); j["chance"] = billy.get_chance(); j["habilete"] = billy.get_habilete(); + j["classe"] = billy.get_current_class(); j["health_point"] = billy.get_health_point(); j["armor"] = billy.get_armor(); j["damage"] = billy.get_damage(); diff --git a/include/gui/gui_data.hpp b/include/gui/gui_data.hpp index c8403c1..7b1aedc 100644 --- a/include/gui/gui_data.hpp +++ b/include/gui/gui_data.hpp @@ -1,12 +1,15 @@ #ifndef BILLYSHEET_GUI_DATA_HPP #define BILLYSHEET_GUI_DATA_HPP +#include #include namespace character { class CharacterSheet; } +using namespace std::string_view_literals; + namespace gui { class Window; @@ -19,6 +22,13 @@ namespace gui { character::CharacterSheet &billy; public: + static constexpr std::array classes{ + "Guerrier"sv, + "Prudent"sv, + "Paysan"sv, + "Débrouillard"sv + }; + GuiData() = delete; explicit GuiData(Window &wwindow, character::CharacterSheet &billy) : window(wwindow), billy(billy) { SPDLOG_DEBUG("Creating GUI Data"); } diff --git a/src/controller.cpp b/src/controller.cpp index c8cafb7..45bb128 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -42,6 +42,20 @@ void Controller::control_menu() const noexcept { void Controller::control_sheet() const noexcept { if (menu_data.is_edit_mode()) { // TODO + switch (sheet.get_current_class()) { + case character::classe::Prudent: + // TODO + break; + case character::classe::Guerrier: + // TODO + break; + case character::classe::Paysan: + // TODO + break; + case character::classe::Debrouillard: + // TODO + break; + } } else { // TODO } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index d523920..bb09274 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -47,6 +47,20 @@ void gui::Gui::render_gui(const Controller &controller) { (void) ImGui::Begin("Billy", nullptr, flags); menu.gui(); + if (ImGui::BeginCombo("Classe", + GuiData::classes[static_cast(data.billy.get_current_class())].data(), + ImGuiComboFlags_PopupAlignLeft)) { + for (std::size_t i = 0; i < GuiData::classes.size(); ++i) { + const bool is_selected = (data.billy.get_current_class() == static_cast(i)); + if (ImGui::Selectable(GuiData::classes[i].data(), is_selected)) + data.billy.current_class = static_cast(i); + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + { ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true); ImGui::Text("Caractère"); diff --git a/src/main.cpp b/src/main.cpp index 7224f1c..36c9661 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main() { while (!window.should_close()) { glfwPollEvents(); -// controller.control(); + controller.control_sheet(); gui.render_gui(controller); gui.render_gpu();