Adding switches for matériels

This commit is contained in:
Pcornat 2024-10-29 20:23:15 +01:00
parent ae3c7d496a
commit 91180411ab
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
2 changed files with 65 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "hello_world.hpp" #include "hello_world.hpp"
#include <iostream> #include <iostream>
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include <gtkmm/switch.h>
namespace gui_to_app { namespace gui_to_app {
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { 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); main_window->set_visible(true);
} else { } else {
on_quit(); on_quit();
return;
}
sword_switch = app_builder->get_widget<Gtk::Switch>("sword_switch");
lance_switch = app_builder->get_widget<Gtk::Switch>("lance_switch");
morgen_switch = app_builder->get_widget<Gtk::Switch>("morgenstern_switch");
bow_switch = app_builder->get_widget<Gtk::Switch>("arc_switch");
chainmail_switch = app_builder->get_widget<Gtk::Switch>("chainmail_switch");
cookpot_switch = app_builder->get_widget<Gtk::Switch>("cookingpot_switch");
pamphlet_switch = app_builder->get_widget<Gtk::Switch>("pamphlet_tourist_switch");
medkit_switch = app_builder->get_widget<Gtk::Switch>("medkit_switch");
fourche_switch = app_builder->get_widget<Gtk::Switch>("fourche_switch");
dagger_switch = app_builder->get_widget<Gtk::Switch>("dagger_switch");
rock_kit_switch = app_builder->get_widget<Gtk::Switch>("rock_kit_switch");
sack_switch = app_builder->get_widget<Gtk::Switch>("sack_switch");
const auto test_result = [this]() -> std::vector<const char *> {
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<const char *> 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;
} }
} }

View File

@ -8,6 +8,10 @@ namespace learn_gtkmm4 {
class HelloWorld; class HelloWorld;
} }
namespace Gtk {
class Switch;
}
namespace gui_to_app { namespace gui_to_app {
class AppWin2Back final : public Gtk::Application { class AppWin2Back final : public Gtk::Application {
@ -27,6 +31,20 @@ namespace gui_to_app {
void on_quit(); void on_quit();
learn_gtkmm4::HelloWorld *main_window{ nullptr }; 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 } // gui_to_app