diff --git a/CMakeLists.txt b/CMakeLists.txt index 735fca4..18870ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,6 @@ set_target_properties(LearnGtk4 spdlog_header_only PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON ) -target_compile_definitions(LearnGtk4 PUBLIC $<$:_GLIBCXX_DEBUG>) target_compile_options(LearnGtk4 PUBLIC ${COMPILE_FLAGS}) target_link_options(LearnGtk4 PUBLIC ${LINKER_OPTIONS}) target_link_libraries(LearnGtk4 PkgConfig::GTKMM4 spdlog_header_only BillySheet) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 5f5fab4..7d80cae 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -1,6 +1,8 @@ #include "app_win_2_back.hpp" #include "hello_world.hpp" +#include + #include #include #include @@ -107,6 +109,28 @@ namespace gui_to_app { return; } // TODO: interaction avec la CharacterSheet + ranges::for_each(views::zip(std::array{ + sword_switch, + lance_switch, + morgen_switch, + bow_switch, + chainmail_switch, + cookpot_switch, + pamphlet_switch, + medkit_switch, + fourche_switch, + dagger_switch, + rock_kit_switch, + sack_switch, + }, + signal_handlers), + [](const std::tuple &vals) { + const auto &[switch_val, signal_handle] = vals; + signal_handle.switch_ = switch_val; + switch_val->signal_state_set().connect( + sigc::mem_fun(signal_handle, &SwitchSignalHelper::signal_handler), + false); + }); } void AppWin2Back::on_quit() noexcept { @@ -117,4 +141,8 @@ 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); + } } // gui_to_app diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index fdb5d21..7f950dd 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -1,8 +1,14 @@ #ifndef LEARNGTK4_APP_WIN_2_BACK_HPP #define LEARNGTK4_APP_WIN_2_BACK_HPP -#include +#include + #include +#include + +#include +#include +#include namespace learn_gtkmm4 { class HelloWorld; @@ -28,8 +34,23 @@ namespace gui_to_app { void on_activate() final; private: + struct SwitchSignalHelper { + AppWin2Back &app; + const character::billyEnums obj; + Gtk::Switch *switch_{ nullptr }; + + [[nodiscard]] bool signal_handler(const bool flag) const noexcept { + switch_->set_state(app.switch_signal_handler(flag, obj)); + return true; + } + }; + + friend struct SwitchSignalHelper; + void on_quit() noexcept; + bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept; + Glib::RefPtr app_builder; learn_gtkmm4::HelloWorld *main_window{ nullptr }; Gtk::Switch *sword_switch{ nullptr }; @@ -46,6 +67,26 @@ namespace gui_to_app { Gtk::Switch *dagger_switch{ nullptr }; Gtk::Switch *rock_kit_switch{ nullptr }; Gtk::Switch *sack_switch{ nullptr }; + + std::array signal_handlers{ + SwitchSignalHelper{ .app = *this, .obj = character::weapons::Sword }, + SwitchSignalHelper{ .app = *this, .obj = character::weapons::Lance }, + SwitchSignalHelper{ .app = *this, .obj = character::weapons::Morgenstern }, + SwitchSignalHelper{ .app = *this, .obj = character::weapons::Bow }, + + SwitchSignalHelper{ .app = *this, .obj = character::equipments::Chainmail }, + SwitchSignalHelper{ .app = *this, .obj = character::equipments::CookingPot }, + SwitchSignalHelper{ .app = *this, .obj = character::equipments::PamphletTourist }, + SwitchSignalHelper{ .app = *this, .obj = character::equipments::MedicKit }, + + SwitchSignalHelper{ .app = *this, .obj = character::tools::Fourche }, + SwitchSignalHelper{ .app = *this, .obj = character::tools::Dagger }, + SwitchSignalHelper{ .app = *this, .obj = character::tools::RockClimbingKit }, + SwitchSignalHelper{ .app = *this, .obj = character::tools::SackOfGrain }, + }; + + character::BillyObjects gestionnaire{}; + character::CharacterSheet sheet{}; }; } // gui_to_app