diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index dcdb5ce..0ad2952 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -50,8 +50,6 @@ namespace gui_to_app { if (!app.insert_obj(obj)) { on_stack = true; switch_->set_active(false); - } else { - app.update_labels(); } } else { if (!app.erase_obj(obj)) { @@ -61,8 +59,6 @@ namespace gui_to_app { "Erasing object {} was not successful", character::BillyObjects::billy_object_to_string(obj).data() ); - } else { - app.update_labels(); } } } @@ -169,24 +165,10 @@ namespace gui_to_app { return; } debug_button = app_builder->get_widget("debug_button"); - hab_labels = CaracInterface{ - { - "habilete_label_base", - "habilete_label_carac", - "habilete_label_materiel", - "habilete_label_total" - }, - app_builder - }; - endu_labels = CaracInterface{ - { - "endurance_label_base", - "endurance_label_carac", - "endurance_label_materiel", - "endurance_label_total" - }, - app_builder - }; + hab_base = app_builder->get_widget("habilete_label_base"); + hab_carac = app_builder->get_widget("habilete_label_carac"); + hab_mat = app_builder->get_widget("habilete_label_materiel"); + hab_total = app_builder->get_widget("habilete_label_total"); debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false); } @@ -200,52 +182,17 @@ namespace gui_to_app { quit(); } + bool AppWin2Back::switch_signal_handler(const bool flag, const character::billyEnums &obj) noexcept { + return flag ? gestionnaire.insert_object(sheet, obj) : !gestionnaire.erase_object(sheet, obj); + } + void AppWin2Back::debug_button_clicked() const noexcept { - const json j{ { "character_sheet", sheet } }; - spdlog::info("Character sheet in json: \n{}", j.dump(4, ' ', true)); - } - - static void convert_to_label(std::array &convert, - const std::string_view &err_msg, - const uint32_t data, - Gtk::Label *const __restrict label) noexcept { - if (const auto [ptr, ec] = std::to_chars(convert.data(), convert.data() + convert.size(), data); - ec != std::errc()) { - spdlog::error("An error occurred while converting {} value: {}", - err_msg, - std::make_error_code(ec).message()); - } else { - const Glib::ustring converted{ - convert.data(), static_cast(ptr - convert.data()) - }; - label->set_label(converted); + spdlog::info("Display objects"); + for (const auto &obj: sheet.get_objects() | views::values) { + spdlog::info("Object: {}", obj->to_string()); } } - static void update_in_labels(const character::characteristic::Characteristic &charac, - const std::string_view short_name, - const CaracInterface &labels) noexcept { - std::array convert{}; - convert_to_label(convert, std::format("base {}", short_name), charac.get_base(), labels.base); - convert_to_label(convert, - std::format("carac {}", short_name), - charac.get_carac(), - labels.carac); - convert_to_label(convert, - std::format("materiel {}", short_name), - charac.get_materiel(), - labels.mat); - convert_to_label(convert, - std::format("total {}", short_name), - charac.get_total(), - labels.total); - } - - void AppWin2Back::update_labels() const noexcept { - update_in_labels(sheet.get_habilete(), "hab", hab_labels); - update_in_labels(sheet.get_endurance(), "endu", endu_labels); - } - bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept { return gestionnaire.insert_object(sheet, obj); } diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index 2238ccf..b0f30d5 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -16,28 +15,12 @@ namespace learn_gtkmm4 { } namespace Gtk { + class Builder; class Label; class Button; } namespace gui_to_app { - template - struct CaracInterface final { - T *base{ nullptr }; - T *carac{ nullptr }; - T *mat{ nullptr }; - T *total{ nullptr }; - - CaracInterface() = default; - - explicit CaracInterface(const std::array &list, - const Glib::RefPtr &builder) : - base(builder->get_widget(list[0].data())), - carac(builder->get_widget(list[1].data())), - mat(builder->get_widget(list[2].data())), - total(builder->get_widget(list[3].data())) {} - }; - class AppWin2Back final : public Gtk::Application { public: ~AppWin2Back() noexcept final = default; @@ -75,9 +58,9 @@ namespace gui_to_app { void on_quit() noexcept; - void debug_button_clicked() const noexcept; + bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept; - void update_labels() const noexcept; + void debug_button_clicked() const noexcept; bool insert_obj(const character::billyEnums &obj) noexcept; @@ -100,9 +83,10 @@ namespace gui_to_app { selection_button *rock_kit_switch{ nullptr }; selection_button *sack_switch{ nullptr }; - CaracInterface hab_labels; - - CaracInterface endu_labels; + Gtk::Label *hab_base{ nullptr }; + Gtk::Label *hab_carac{ nullptr }; + Gtk::Label *hab_mat{ nullptr }; + Gtk::Label *hab_total{ nullptr }; Gtk::Button *debug_button{ nullptr }; diff --git a/window_ui.ui b/window_ui.ui index a9d7e38..c6cf1fd 100644 --- a/window_ui.ui +++ b/window_ui.ui @@ -30,7 +30,6 @@ - True start @@ -44,8 +43,7 @@ - center - True + end 1 0 @@ -64,7 +62,7 @@ - center + end 1 1 @@ -83,7 +81,7 @@ - center + end 1 2 @@ -107,9 +105,6 @@ - center - True - center 2 0 @@ -138,11 +133,8 @@ - True - True - True start @@ -156,8 +148,7 @@ - center - True + end 1 0 @@ -176,7 +167,7 @@ - center + end 1 1 @@ -195,7 +186,7 @@ - center + end 1 2 @@ -219,8 +210,6 @@ - center - True 2 0