Updating hab labels

This commit is contained in:
Pcornat 2026-03-16 16:23:26 +01:00
commit 53a70aefa5
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
2 changed files with 44 additions and 16 deletions

View file

@ -50,6 +50,8 @@ namespace gui_to_app {
if (!app.insert_obj(obj)) { if (!app.insert_obj(obj)) {
on_stack = true; on_stack = true;
switch_->set_active(false); switch_->set_active(false);
} else {
app.update_hab_labels();
} }
} else { } else {
if (!app.erase_obj(obj)) { if (!app.erase_obj(obj)) {
@ -59,6 +61,8 @@ namespace gui_to_app {
"Erasing object {} was not successful", "Erasing object {} was not successful",
character::BillyObjects::billy_object_to_string(obj).data() character::BillyObjects::billy_object_to_string(obj).data()
); );
} else {
app.update_hab_labels();
} }
} }
} }
@ -165,10 +169,10 @@ namespace gui_to_app {
return; return;
} }
debug_button = app_builder->get_widget<Gtk::Button>("debug_button"); debug_button = app_builder->get_widget<Gtk::Button>("debug_button");
hab_base = app_builder->get_widget<Gtk::Label>("habilete_label_base"); hab_labels.base = app_builder->get_widget<Gtk::Label>("habilete_label_base");
hab_carac = app_builder->get_widget<Gtk::Label>("habilete_label_carac"); hab_labels.carac = app_builder->get_widget<Gtk::Label>("habilete_label_carac");
hab_mat = app_builder->get_widget<Gtk::Label>("habilete_label_materiel"); hab_labels.mat = app_builder->get_widget<Gtk::Label>("habilete_label_materiel");
hab_total = app_builder->get_widget<Gtk::Label>("habilete_label_total"); hab_labels.total = app_builder->get_widget<Gtk::Label>("habilete_label_total");
debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false); debug_button->signal_clicked().connect(sigc::mem_fun(*this, &AppWin2Back::debug_button_clicked), false);
} }
@ -182,17 +186,36 @@ namespace gui_to_app {
quit(); quit();
} }
bool AppWin2Back::switch_signal_handler(const bool flag, const character::billyEnums &obj) noexcept { void AppWin2Back::debug_button_clicked() const noexcept {
return flag ? gestionnaire.insert_object(sheet, obj) : !gestionnaire.erase_object(sheet, obj); const json j{ { "character_sheet", sheet } };
spdlog::info("Character sheet in json: \n{}", j.dump(4, ' ', true));
} }
void AppWin2Back::debug_button_clicked() const noexcept { static void convert_to_label(std::array<char, 10> &convert,
spdlog::info("Display objects"); const char *err_msg,
for (const auto &obj: sheet.get_objects() | views::values) { const uint32_t data,
spdlog::info("Object: {}", obj->to_string()); Gtk::Label *const __restrict label) noexcept {
if (const auto [ptr, ec] = std::to_chars(convert.data(), convert.data() + convert.size(), data);
ec != std::errc()) {
spdlog::error("An error occurred while converting {} value: {}",
err_msg,
std::make_error_code(ec).message());
} else {
const Glib::ustring converted{
convert.data(), static_cast<std::string::size_type>(ptr - convert.data())
};
label->set_label(converted);
} }
} }
void AppWin2Back::update_hab_labels() const noexcept {
std::array<char, 10> convert{};
convert_to_label(convert, "base hab", sheet.get_habilete().get_base(), hab_labels.base);
convert_to_label(convert, "carac hab", sheet.get_habilete().get_carac(), hab_labels.carac);
convert_to_label(convert, "materiel hab", sheet.get_habilete().get_materiel(), hab_labels.mat);
convert_to_label(convert, "total hab", sheet.get_habilete().get_total(), hab_labels.total);
}
bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept { bool AppWin2Back::insert_obj(const character::billyEnums &obj) noexcept {
return gestionnaire.insert_object(sheet, obj); return gestionnaire.insert_object(sheet, obj);
} }

View file

@ -21,6 +21,14 @@ namespace Gtk {
} }
namespace gui_to_app { namespace gui_to_app {
template<typename T>
struct CaracInterface {
T *base{ nullptr };
T *carac{ nullptr };
T *mat{ nullptr };
T *total{ nullptr };
};
class AppWin2Back final : public Gtk::Application { class AppWin2Back final : public Gtk::Application {
public: public:
~AppWin2Back() noexcept final = default; ~AppWin2Back() noexcept final = default;
@ -58,10 +66,10 @@ namespace gui_to_app {
void on_quit() noexcept; void on_quit() noexcept;
bool switch_signal_handler(bool flag, const character::billyEnums &obj) noexcept;
void debug_button_clicked() const noexcept; void debug_button_clicked() const noexcept;
void update_hab_labels() const noexcept;
bool insert_obj(const character::billyEnums &obj) noexcept; bool insert_obj(const character::billyEnums &obj) noexcept;
bool erase_obj(const character::billyEnums &obj) noexcept; bool erase_obj(const character::billyEnums &obj) noexcept;
@ -83,10 +91,7 @@ namespace gui_to_app {
selection_button *rock_kit_switch{ nullptr }; selection_button *rock_kit_switch{ nullptr };
selection_button *sack_switch{ nullptr }; selection_button *sack_switch{ nullptr };
Gtk::Label *hab_base{ nullptr }; CaracInterface<Gtk::Label> hab_labels;
Gtk::Label *hab_carac{ nullptr };
Gtk::Label *hab_mat{ nullptr };
Gtk::Label *hab_total{ nullptr };
Gtk::Button *debug_button{ nullptr }; Gtk::Button *debug_button{ nullptr };