From 91180411ab4c59f89dfcba8f249b0b89524f6cbc Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 20:23:15 +0100 Subject: [PATCH] =?UTF-8?q?Adding=20switches=20for=20mat=C3=A9riels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_win_2_back.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ app_win_2_back.hpp | 18 ++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 664d573..e42fc17 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -2,6 +2,7 @@ #include "hello_world.hpp" #include #include +#include namespace gui_to_app { AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { @@ -56,6 +57,52 @@ namespace gui_to_app { main_window->set_visible(true); } else { on_quit(); + return; + } + sword_switch = app_builder->get_widget("sword_switch"); + lance_switch = app_builder->get_widget("lance_switch"); + morgen_switch = app_builder->get_widget("morgenstern_switch"); + bow_switch = app_builder->get_widget("arc_switch"); + chainmail_switch = app_builder->get_widget("chainmail_switch"); + cookpot_switch = app_builder->get_widget("cookingpot_switch"); + pamphlet_switch = app_builder->get_widget("pamphlet_tourist_switch"); + medkit_switch = app_builder->get_widget("medkit_switch"); + fourche_switch = app_builder->get_widget("fourche_switch"); + dagger_switch = app_builder->get_widget("dagger_switch"); + rock_kit_switch = app_builder->get_widget("rock_kit_switch"); + sack_switch = app_builder->get_widget("sack_switch"); + + const auto test_result = [this]() -> std::vector { + const std::array test_ptrs{ + std::pair{ "sword_switch", sword_switch == nullptr }, + std::pair{ "lance_switch", lance_switch == nullptr }, + std::pair{ "morgen_switch", morgen_switch == nullptr }, + std::pair{ "bow_switch", bow_switch == nullptr }, + std::pair{ "chainmail_switch", chainmail_switch == nullptr }, + std::pair{ "cookpot_switch", cookpot_switch == nullptr }, + std::pair{ "pamphlet_switch", pamphlet_switch == nullptr }, + std::pair{ "medkit_switch", medkit_switch == nullptr }, + std::pair{ "fourche_switch", fourche_switch == nullptr }, + std::pair{ "dagger_switch", dagger_switch == nullptr }, + std::pair{ "rock_kit_switch", rock_kit_switch == nullptr }, + std::pair{ "sack_switch", sack_switch == nullptr }, + }; + std::vector test_result; + test_result.reserve(test_ptrs.size()); + std::for_each(test_ptrs.cbegin(), test_ptrs.cend(), [&test_result](const auto &a) { + if (a.second) { + test_result.emplace_back(a.first); + } + }); + return test_result; + }(); + if (!test_result.empty()) { + std::cerr << "Error occurred, at least one switch is not available:\n"; + for (const auto result: test_result) { + std::cerr << result << '\n'; + } + on_quit(); + return; } } diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index fbc2d67..4f2d1e2 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -8,6 +8,10 @@ namespace learn_gtkmm4 { class HelloWorld; } +namespace Gtk { + class Switch; +} + namespace gui_to_app { class AppWin2Back final : public Gtk::Application { @@ -27,6 +31,20 @@ namespace gui_to_app { void on_quit(); learn_gtkmm4::HelloWorld *main_window{ nullptr }; + Gtk::Switch *sword_switch{ nullptr }; + Gtk::Switch *lance_switch{ nullptr }; + Gtk::Switch *morgen_switch{ nullptr }; + Gtk::Switch *bow_switch{ nullptr }; + + Gtk::Switch *chainmail_switch{ nullptr }; + Gtk::Switch *cookpot_switch{ nullptr }; + Gtk::Switch *pamphlet_switch{ nullptr }; + Gtk::Switch *medkit_switch{ nullptr }; + + Gtk::Switch *fourche_switch{ nullptr }; + Gtk::Switch *dagger_switch{ nullptr }; + Gtk::Switch *rock_kit_switch{ nullptr }; + Gtk::Switch *sack_switch{ nullptr }; }; } // gui_to_app