First try to interact with buttons and CharacterSheet
This commit is contained in:
parent
f687b2f325
commit
f4cbc2558b
3 changed files with 193 additions and 117 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#include <billy_objects.hpp>
|
||||
|
||||
#include <glibmm/miscutils.h>
|
||||
#include <gtkmm/switch.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <ranges>
|
||||
|
|
@ -15,6 +15,7 @@ namespace gui_to_app {
|
|||
|
||||
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) {
|
||||
Glib::set_application_name("Billy's character sheet");
|
||||
selection_buttons.reserve(signal_handlers.size());
|
||||
}
|
||||
|
||||
void AppWin2Back::on_startup() {
|
||||
|
|
@ -41,6 +42,107 @@ namespace gui_to_app {
|
|||
return Glib::make_refptr_for_instance(new AppWin2Back());
|
||||
}
|
||||
|
||||
void AppWin2Back::SwitchSignalHelper::signal_handler() noexcept {
|
||||
if (switch_ != nullptr && !on_stack) {
|
||||
if (!switch_->get_inconsistent()) {
|
||||
if (switch_->get_active()) {
|
||||
if (!app.insert_obj(obj)) {
|
||||
on_stack = true;
|
||||
switch_->set_active(false);
|
||||
ranges::for_each(
|
||||
app.selection_buttons | views::filter([](const buttons_obj_container::value_type a) {
|
||||
return !a->get_active() && !a->get_inconsistent();
|
||||
}),
|
||||
[](const buttons_obj_container::value_type a) { a->set_inconsistent(); });
|
||||
}
|
||||
} else {
|
||||
const bool was_full = character::BillyObjects::is_full(app.sheet);
|
||||
if (!app.erase_obj(obj)) {
|
||||
on_stack = true;
|
||||
switch_->set_active(true);
|
||||
} else if (!character::BillyObjects::is_full(app.sheet) && was_full) {
|
||||
ranges::for_each(
|
||||
app.selection_buttons | views::filter([](const buttons_obj_container::value_type a) {
|
||||
return a->get_inconsistent();
|
||||
}),
|
||||
[](const buttons_obj_container::value_type a) { a->set_inconsistent(false); });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (on_stack) {
|
||||
on_stack = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AppWin2Back::switches_procedure() {
|
||||
sword_switch = app_builder->get_widget<selection_button>("sword_button");
|
||||
lance_switch = app_builder->get_widget<selection_button>("lance_button");
|
||||
morgen_switch = app_builder->get_widget<selection_button>("morgenstern_button");
|
||||
bow_switch = app_builder->get_widget<selection_button>("arc_button");
|
||||
chainmail_switch = app_builder->get_widget<selection_button>("chainmail_button");
|
||||
cookpot_switch = app_builder->get_widget<selection_button>("cookingpot_button");
|
||||
pamphlet_switch = app_builder->get_widget<selection_button>("pamphlet_tourist_button");
|
||||
medkit_switch = app_builder->get_widget<selection_button>("medkit_button");
|
||||
fourche_switch = app_builder->get_widget<selection_button>("fourche_button");
|
||||
dagger_switch = app_builder->get_widget<selection_button>("dagger_button");
|
||||
rock_kit_switch = app_builder->get_widget<selection_button>("rock_kit_button");
|
||||
sack_switch = app_builder->get_widget<selection_button>("sack_button");
|
||||
|
||||
const auto test_result = ranges::to<std::vector<const char *> >(
|
||||
std::array{
|
||||
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 },
|
||||
}
|
||||
| views::filter([](const auto &a) { return a.second; })
|
||||
| views::keys
|
||||
);
|
||||
|
||||
if (!test_result.empty()) {
|
||||
spdlog::critical("Error occurred, at least one switch is not available. See logs below");
|
||||
for (const auto result: test_result) {
|
||||
spdlog::critical(result);
|
||||
}
|
||||
on_quit();
|
||||
return true;
|
||||
}
|
||||
// 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),
|
||||
[this](const std::tuple<selection_button *, SwitchSignalHelper &> &vals) {
|
||||
const auto &[switch_val, signal_handle] = vals;
|
||||
signal_handle.switch_ = switch_val;
|
||||
selection_buttons.emplace(switch_val);
|
||||
switch_val->signal_toggled().connect(
|
||||
sigc::mem_fun(signal_handle, &SwitchSignalHelper::signal_handler),
|
||||
false);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppWin2Back::on_activate() {
|
||||
Application::on_activate();
|
||||
|
||||
|
|
@ -67,69 +169,13 @@ namespace gui_to_app {
|
|||
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 = ranges::to<std::vector<const char *> >(
|
||||
std::array{
|
||||
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 },
|
||||
}
|
||||
| views::filter([](const auto &a) { return a.second; })
|
||||
| views::keys
|
||||
);
|
||||
|
||||
if (!test_result.empty()) {
|
||||
spdlog::critical("Error occurred, at least one switch is not available. See logs below");
|
||||
for (const auto result: test_result) {
|
||||
spdlog::critical(result);
|
||||
}
|
||||
on_quit();
|
||||
if (switches_procedure()) {
|
||||
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<Gtk::Switch *, SwitchSignalHelper &> &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);
|
||||
});
|
||||
hab_base = app_builder->get_widget<Gtk::Label>("habilete_label_base");
|
||||
hab_carac = app_builder->get_widget<Gtk::Label>("habilete_label_carac");
|
||||
hab_mat = app_builder->get_widget<Gtk::Label>("habilete_label_materiel");
|
||||
hab_total = app_builder->get_widget<Gtk::Label>("habilete_label_total");
|
||||
}
|
||||
|
||||
void AppWin2Back::on_quit() noexcept {
|
||||
|
|
@ -144,4 +190,12 @@ namespace gui_to_app {
|
|||
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);
|
||||
}
|
||||
|
||||
bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept {
|
||||
return gestionnaire.insert_object(sheet, obj);
|
||||
}
|
||||
|
||||
bool AppWin2Back::erase_obj(const character::billyEnums &obj) noexcept {
|
||||
return gestionnaire.erase_object(sheet, obj);
|
||||
}
|
||||
} // gui_to_app
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue