Adding objects correctly

This commit is contained in:
Pcornat 2026-02-06 19:17:23 +01:00
commit e8933c5029
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
2 changed files with 15 additions and 26 deletions

View file

@ -44,29 +44,19 @@ namespace gui_to_app {
void AppWin2Back::SwitchSignalHelper::signal_handler() noexcept { void AppWin2Back::SwitchSignalHelper::signal_handler() noexcept {
if (switch_ != nullptr && !on_stack) { if (switch_ != nullptr && !on_stack) {
if (!switch_->get_inconsistent()) { if (switch_->get_active()) {
if (switch_->get_active()) { if (!app.insert_obj(obj)) {
if (!app.insert_obj(obj)) { on_stack = true;
on_stack = true; switch_->set_active(false);
switch_->set_active(false); }
ranges::for_each( } else {
app.selection_buttons | views::filter([](const buttons_obj_container::value_type a) { if (!app.erase_obj(obj)) {
return !a->get_active() && !a->get_inconsistent(); on_stack = true;
}), switch_->set_active(true);
[](const buttons_obj_container::value_type a) { a->set_inconsistent(); }); spdlog::warn(
} "Erasing object {} was not successful",
} else { character::BillyObjects::billy_object_to_string(obj).data()
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); });
}
} }
} }
} }
@ -116,7 +106,7 @@ namespace gui_to_app {
on_quit(); on_quit();
return true; return true;
} }
// TODO: interaction avec la CharacterSheet
ranges::for_each(views::zip(std::array{ ranges::for_each(views::zip(std::array{
sword_switch, sword_switch,
lance_switch, lance_switch,

View file

@ -5,11 +5,10 @@
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <gtkmm/application.h> #include <gtkmm/application.h>
#include <gtkmm/checkbutton.h>
#include <billy_objects.hpp> #include <billy_objects.hpp>
#include <character_sheet.hpp> #include <character_sheet.hpp>
// #include <gtkmm/label.h>
#include <gtkmm/checkbutton.h>
namespace learn_gtkmm4 { namespace learn_gtkmm4 {
class HelloWorld; class HelloWorld;