From 60957902cbf84ae4ea1e6f7bd1b064ba8a5262c2 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 17:51:20 +0100 Subject: [PATCH 1/5] Modern border flag for child in GUI. --- src/gui/gui.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 000df05..4c7a8d8 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -112,7 +112,9 @@ void gui::Gui::render_gpu() const { } void gui::Gui::habilete_menu() noexcept { - ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); + ImGui::BeginChild("habilete", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), + ImGuiChildFlags_Border); ImGui::Text("Habileté"); data.base.second = data.billy.get_habilete().get_base(); data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Habilete @@ -134,7 +136,9 @@ void gui::Gui::habilete_menu() noexcept { } void gui::Gui::adresse_menu() noexcept { - ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); + ImGui::BeginChild("adresse", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), + ImGuiChildFlags_Border); ImGui::Text("Adresse"); data.base.second = data.billy.get_adresse().get_base(); data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Adresse @@ -156,7 +160,9 @@ void gui::Gui::adresse_menu() noexcept { } void gui::Gui::endurance_menu() noexcept { - ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); + ImGui::BeginChild("endurance", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), + ImGuiChildFlags_Border); ImGui::Text("Endurance"); data.base.second = data.billy.get_endurance().get_base(); @@ -180,7 +186,9 @@ void gui::Gui::endurance_menu() noexcept { } void gui::Gui::chance_menu() noexcept { - ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); + ImGui::BeginChild("chance", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), + ImGuiChildFlags_Border); ImGui::Text("Chance"); data.base.second = data.billy.get_chance().get_base(); data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Chance @@ -202,25 +210,33 @@ void gui::Gui::chance_menu() noexcept { } void gui::Gui::stat_second_menu() noexcept { - ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true); + ImGui::BeginChild("stats secondaire", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), + ImGuiChildFlags_Border); ImGui::Text("STAT. SECONDAIRES"); ImGui::EndChild(); } void gui::Gui::materiel_menu() noexcept { - ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); + ImGui::BeginChild("materiel", + ImVec2(ImGui::GetWindowWidth() / 3, 0), + ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); ImGui::Text("Matériel"); ImGui::EndChild(); } void gui::Gui::gloire_menu() noexcept { - ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); + ImGui::BeginChild("gloire", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), + ImGuiChildFlags_Border); ImGui::Text("Gloire"); ImGui::EndChild(); } void gui::Gui::richesse_menu() noexcept { - ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); + ImGui::BeginChild("richesse", + ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), + ImGuiChildFlags_Border); ImGui::Text("Richesse"); ImGui::EndChild(); } From 7d4981e02c92cf4c9771da74b0173b2c5a519db7 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 17:51:43 +0100 Subject: [PATCH 2/5] Displaying available objects in GUI. --- src/gui/gui.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4c7a8d8..69745ca 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7,6 +7,7 @@ #include "gui/gui_data.hpp" #include "character_sheet.hpp" #include "controller.hpp" +#include "billy_objects.hpp" gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") { @@ -222,6 +223,28 @@ void gui::Gui::materiel_menu() noexcept { ImVec2(ImGui::GetWindowWidth() / 3, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); ImGui::Text("Matériel"); + + ImGui::BeginChild("weapons", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); + ImGui::Text(character::BillyObjects::sword.data()); + ImGui::Text(character::BillyObjects::lance.data()); + ImGui::Text(character::BillyObjects::morgenstern.data()); + ImGui::Text(character::BillyObjects::bow.data()); + ImGui::EndChild(); + + ImGui::BeginChild("equipments", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); + ImGui::Text(character::BillyObjects::chainmail.data()); + ImGui::Text(character::BillyObjects::cooking_pot.data()); + ImGui::Text(character::BillyObjects::pamphlet_tourist.data()); + ImGui::Text(character::BillyObjects::medic_kit.data()); + ImGui::EndChild(); + + ImGui::BeginChild("tools", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); + ImGui::Text(character::BillyObjects::fourche.data()); + ImGui::Text(character::BillyObjects::dagger.data()); + ImGui::Text(character::BillyObjects::rock_climbing_kit.data()); + ImGui::Text(character::BillyObjects::sack_of_grain.data()); + ImGui::EndChild(); + ImGui::EndChild(); } From 1d609f12d5abd7197ad96c83186327b1ee4dc20e Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 23:40:46 +0100 Subject: [PATCH 3/5] Better displaying characteristics --- include/gui/gui.hpp | 6 ++++ src/gui/gui.cpp | 87 +++++++++++---------------------------------- 2 files changed, 27 insertions(+), 66 deletions(-) diff --git a/include/gui/gui.hpp b/include/gui/gui.hpp index e2d718e..60f8284 100644 --- a/include/gui/gui.hpp +++ b/include/gui/gui.hpp @@ -8,6 +8,10 @@ namespace fs = std::filesystem; class Controller; +namespace character::characteristic { + class Characteristic; +} + namespace gui { class GuiData; @@ -52,6 +56,8 @@ namespace gui { void render_gui(const Controller &controller); void render_gpu() const; + + static void characteristic_gui(const character::characteristic::Characteristic &characteristic) noexcept; }; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 69745ca..62a65ae 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -8,6 +8,9 @@ #include "character_sheet.hpp" #include "controller.hpp" #include "billy_objects.hpp" +#include "characteristic/characteristic.hpp" + +using character::characteristic::Characteristic; gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") { @@ -112,27 +115,26 @@ void gui::Gui::render_gpu() const { } } +void gui::Gui::characteristic_gui(const Characteristic &characteristic) noexcept { + int base = static_cast(characteristic.get_base()); + (void) ImGui::InputInt("Base", &base, 1, 100, ImGuiInputTextFlags_ReadOnly); + + int carac = static_cast(characteristic.get_carac()); + (void) ImGui::InputInt("Carac", &carac, 1, 100, ImGuiInputTextFlags_ReadOnly); + + int materiel = static_cast(characteristic.get_materiel()); + (void) ImGui::InputInt("Matériel", &materiel, 1, 100, ImGuiInputTextFlags_ReadOnly); + + int additional = static_cast(characteristic.get_additional()); + (void) ImGui::InputInt("Additionnel", &additional, 1, 100, ImGuiInputTextFlags_ReadOnly); +} + void gui::Gui::habilete_menu() noexcept { ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), ImGuiChildFlags_Border); ImGui::Text("Habileté"); - data.base.second = data.billy.get_habilete().get_base(); - data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Habilete - : characChanged::None; - - data.carac.second = data.billy.get_habilete().get_carac(); - data.carac.first = ImGui::InputInt("Carac", reinterpret_cast(&data.carac.second)) ? characChanged::Habilete - : characChanged::None; - - data.materiel.second = data.billy.get_habilete().get_materiel(); - data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast(&data.materiel.second)) - ? characChanged::Habilete : characChanged::None; - - data.additional.second = data.billy.get_habilete().get_additional(); - data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast(&data.additional.second)) ? - characChanged::Habilete : - characChanged::None; + characteristic_gui(static_cast(data.billy.get_habilete())); ImGui::EndChild(); } @@ -141,22 +143,7 @@ void gui::Gui::adresse_menu() noexcept { ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), ImGuiChildFlags_Border); ImGui::Text("Adresse"); - data.base.second = data.billy.get_adresse().get_base(); - data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Adresse - : characChanged::None; - - data.carac.second = data.billy.get_adresse().get_carac(); - data.carac.first = ImGui::InputInt("Carac", reinterpret_cast(&data.carac.second)) ? characChanged::Adresse - : characChanged::None; - - data.materiel.second = data.billy.get_adresse().get_materiel(); - data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast(&data.materiel.second)) - ? characChanged::Adresse : characChanged::None; - - data.additional.second = data.billy.get_adresse().get_additional(); - data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast(&data.additional.second)) ? - characChanged::Adresse : - characChanged::None; + characteristic_gui(static_cast(data.billy.get_adresse())); ImGui::EndChild(); } @@ -165,24 +152,7 @@ void gui::Gui::endurance_menu() noexcept { ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), ImGuiChildFlags_Border); ImGui::Text("Endurance"); - - data.base.second = data.billy.get_endurance().get_base(); - data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Endurance - : characChanged::None; - - data.carac.second = data.billy.get_endurance().get_carac(); - data.carac.first = ImGui::InputInt("Carac", reinterpret_cast(&data.carac.second)) ? characChanged::Endurance - : characChanged::None; - - data.materiel.second = data.billy.get_endurance().get_materiel(); - data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast(&data.materiel.second)) ? - characChanged::Endurance : - characChanged::None; - - data.additional.second = data.billy.get_endurance().get_additional(); - data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast(&data.additional.second)) ? - characChanged::Endurance : - characChanged::None; + characteristic_gui(static_cast(data.billy.get_endurance())); ImGui::EndChild(); } @@ -191,22 +161,7 @@ void gui::Gui::chance_menu() noexcept { ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), ImGuiChildFlags_Border); ImGui::Text("Chance"); - data.base.second = data.billy.get_chance().get_base(); - data.base.first = ImGui::InputInt("Base", reinterpret_cast(&data.base.second)) ? characChanged::Chance - : characChanged::None; - - data.carac.second = data.billy.get_chance().get_carac(); - data.carac.first = ImGui::InputInt("Carac", reinterpret_cast(&data.carac.second)) ? characChanged::Chance - : characChanged::None; - - data.materiel.second = data.billy.get_chance().get_materiel(); - data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast(&data.materiel.second)) - ? characChanged::Chance : characChanged::None; - - data.additional.second = data.billy.get_chance().get_additional(); - data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast(&data.additional.second)) ? - characChanged::Chance : - characChanged::None; + characteristic_gui(static_cast(data.billy.get_chance())); ImGui::EndChild(); } From fd230e87e93c79f23debd24f79023d15c1d48e41 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 23:51:09 +0100 Subject: [PATCH 4/5] Correctly adding (pushing_back) objects. --- include/billy_objects.hpp | 6 +++--- src/billy_objects.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index f0f4260..6759631 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -64,7 +64,7 @@ namespace character { static std::string_view billy_object_to_string(const billyObject &object) noexcept; - void add_object(const billyObject &object, CharacterSheet &sheet) noexcept; + void push_object(const billyObject &object, CharacterSheet &sheet) noexcept; void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; @@ -74,8 +74,8 @@ namespace character { std::minus minus; std::uint8_t end_object{ 0 }; - static void change_carac_weapon(CharacterSheet &sheet, - const weapons &arg, + static void change_carac_weapon(const weapons &arg, + CharacterSheet &sheet, characteristic::Characteristic &localHabilete, characteristic::Characteristic &localAdresse, characteristic::Characteristic &localEndurance, diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 914c380..0610c12 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -8,9 +8,10 @@ namespace character { using characteristic::Characteristic; - void BillyObjects::add_object(const billyObject &object, CharacterSheet &sheet) noexcept { + void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept { if (end_object < 3) { objects.at(end_object) = object; + ++end_object; auto &local_habilete = static_cast(sheet.habilete); auto &local_adresse = static_cast(sheet.adresse); @@ -20,7 +21,7 @@ namespace character { std::visit(overloaded{ [&](const weapons &arg) { ++sheet.nb_weapons; - change_carac_weapon(sheet, arg, local_habilete, local_adresse, local_endurance, plus); + change_carac_weapon(arg, sheet, local_habilete, local_adresse, local_endurance, plus); }, [&](const equipments &arg) { ++sheet.nb_equipments; @@ -101,8 +102,8 @@ namespace character { } } - void BillyObjects::change_carac_weapon(CharacterSheet &sheet, - const weapons &arg, + void BillyObjects::change_carac_weapon(const weapons &arg, + CharacterSheet &sheet, Characteristic &localHabilete, Characteristic &localAdresse, Characteristic &localEndurance, From 9d5971e23a57fdb8b95b8a06b35ef667395a8c09 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 23:53:18 +0100 Subject: [PATCH 5/5] Now popping objects too. --- include/billy_objects.hpp | 8 +++++++- src/billy_objects.cpp | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index 6759631..7b4b95b 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -66,7 +66,13 @@ namespace character { void push_object(const billyObject &object, CharacterSheet &sheet) noexcept; - void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; + void pop_object(CharacterSheet &sheet) noexcept; + + [[nodiscard]] std::pair get_objects() const noexcept { + return { objects, end_object }; + } + +// void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; private: container objects; diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 0610c12..dd69c23 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -48,6 +48,46 @@ namespace character { } } + void BillyObjects::pop_object(CharacterSheet &sheet) noexcept { + if (end_object > 0) { + const auto &obj = objects.at(end_object - 1); + --end_object; + + auto &local_habilete = static_cast(sheet.habilete); + auto &local_adresse = static_cast(sheet.adresse); + auto &local_endurance = static_cast(sheet.endurance); + auto &local_chance = static_cast(sheet.chance); + + std::visit(overloaded{ + [&](const weapons &arg) { + --sheet.nb_weapons; + change_carac_weapon(arg, sheet, local_habilete, local_adresse, local_endurance, minus); + }, + [&](const equipments &arg) { + --sheet.nb_equipments; + change_carac_equipment(arg, + sheet, + local_habilete, + local_adresse, + local_endurance, + local_chance, + minus, + plus); + }, + [&](const tools &arg) { + --sheet.nb_tools; + change_carac_tools(arg, + sheet, + local_habilete, + local_adresse, + local_endurance, + local_chance, + minus); + } + }, obj); + } + } + void BillyObjects::change_carac_tools(const tools &arg, CharacterSheet &sheet, Characteristic &localHabilete,