diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index 7b4b95b..f0f4260 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -64,15 +64,9 @@ namespace character { static std::string_view billy_object_to_string(const billyObject &object) noexcept; - void push_object(const billyObject &object, CharacterSheet &sheet) noexcept; + void add_object(const billyObject &object, 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; + void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; private: container objects; @@ -80,8 +74,8 @@ namespace character { std::minus minus; std::uint8_t end_object{ 0 }; - static void change_carac_weapon(const weapons &arg, - CharacterSheet &sheet, + static void change_carac_weapon(CharacterSheet &sheet, + const weapons &arg, characteristic::Characteristic &localHabilete, characteristic::Characteristic &localAdresse, characteristic::Characteristic &localEndurance, diff --git a/include/gui/gui.hpp b/include/gui/gui.hpp index 60f8284..e2d718e 100644 --- a/include/gui/gui.hpp +++ b/include/gui/gui.hpp @@ -8,10 +8,6 @@ namespace fs = std::filesystem; class Controller; -namespace character::characteristic { - class Characteristic; -} - namespace gui { class GuiData; @@ -56,8 +52,6 @@ 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/billy_objects.cpp b/src/billy_objects.cpp index dd69c23..914c380 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -8,10 +8,9 @@ namespace character { using characteristic::Characteristic; - void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept { + void BillyObjects::add_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); @@ -21,7 +20,7 @@ namespace character { std::visit(overloaded{ [&](const weapons &arg) { ++sheet.nb_weapons; - change_carac_weapon(arg, sheet, local_habilete, local_adresse, local_endurance, plus); + change_carac_weapon(sheet, arg, local_habilete, local_adresse, local_endurance, plus); }, [&](const equipments &arg) { ++sheet.nb_equipments; @@ -48,46 +47,6 @@ 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, @@ -142,8 +101,8 @@ namespace character { } } - void BillyObjects::change_carac_weapon(const weapons &arg, - CharacterSheet &sheet, + void BillyObjects::change_carac_weapon(CharacterSheet &sheet, + const weapons &arg, Characteristic &localHabilete, Characteristic &localAdresse, Characteristic &localEndurance, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 62a65ae..000df05 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7,10 +7,6 @@ #include "gui/gui_data.hpp" #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") { @@ -115,106 +111,116 @@ 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::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::Text("Habileté"); - characteristic_gui(static_cast(data.billy.get_habilete())); + 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; ImGui::EndChild(); } void gui::Gui::adresse_menu() noexcept { - ImGui::BeginChild("adresse", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), - ImGuiChildFlags_Border); + ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::Text("Adresse"); - characteristic_gui(static_cast(data.billy.get_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; ImGui::EndChild(); } void gui::Gui::endurance_menu() noexcept { - ImGui::BeginChild("endurance", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), - ImGuiChildFlags_Border); + ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::Text("Endurance"); - characteristic_gui(static_cast(data.billy.get_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; ImGui::EndChild(); } void gui::Gui::chance_menu() noexcept { - ImGui::BeginChild("chance", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), - ImGuiChildFlags_Border); + ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::Text("Chance"); - characteristic_gui(static_cast(data.billy.get_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; ImGui::EndChild(); } void gui::Gui::stat_second_menu() noexcept { - ImGui::BeginChild("stats secondaire", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), - ImGuiChildFlags_Border); + ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true); ImGui::Text("STAT. SECONDAIRES"); ImGui::EndChild(); } void gui::Gui::materiel_menu() noexcept { - ImGui::BeginChild("materiel", - ImVec2(ImGui::GetWindowWidth() / 3, 0), - ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY); + ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); 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(); } void gui::Gui::gloire_menu() noexcept { - ImGui::BeginChild("gloire", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), - ImGuiChildFlags_Border); + ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); ImGui::Text("Gloire"); ImGui::EndChild(); } void gui::Gui::richesse_menu() noexcept { - ImGui::BeginChild("richesse", - ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), - ImGuiChildFlags_Border); + ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); ImGui::Text("Richesse"); ImGui::EndChild(); }