141 lines
4.4 KiB
C++
141 lines
4.4 KiB
C++
#ifndef LEARNGTK4_APP_WIN_2_BACK_HPP
|
|
#define LEARNGTK4_APP_WIN_2_BACK_HPP
|
|
|
|
#include <array>
|
|
|
|
#include <glibmm/refptr.h>
|
|
#include <gtkmm/application.h>
|
|
#include <gtkmm/builder.h>
|
|
#include <gtkmm/checkbutton.h>
|
|
|
|
#include <billy_objects.hpp>
|
|
#include <character_sheet.hpp>
|
|
|
|
namespace learn_gtkmm4 {
|
|
class HelloWorld;
|
|
}
|
|
|
|
namespace Gtk {
|
|
class Label;
|
|
class Button;
|
|
}
|
|
|
|
namespace gui_to_app {
|
|
template<typename T>
|
|
struct CaracInterface final {
|
|
T *base{ nullptr };
|
|
T *carac{ nullptr };
|
|
T *mat{ nullptr };
|
|
T *total{ nullptr };
|
|
|
|
CaracInterface() = default;
|
|
|
|
explicit CaracInterface(const std::array<std::string_view, 4> &list,
|
|
const Glib::RefPtr<Gtk::Builder> &builder) :
|
|
base(builder->get_widget<T>(list[0].data())),
|
|
carac(builder->get_widget<T>(list[1].data())),
|
|
mat(builder->get_widget<T>(list[2].data())),
|
|
total(builder->get_widget<T>(list[3].data())) {}
|
|
};
|
|
|
|
class AppWin2Back final : public Gtk::Application {
|
|
public:
|
|
~AppWin2Back() noexcept final = default;
|
|
|
|
static Glib::RefPtr<AppWin2Back> create();
|
|
|
|
protected:
|
|
AppWin2Back();
|
|
|
|
void on_startup() final;
|
|
|
|
void on_activate() final;
|
|
|
|
private:
|
|
using selection_button = Gtk::CheckButton;
|
|
using buttons_obj_container = std::unordered_set<selection_button *>;
|
|
|
|
|
|
struct SwitchSignalHelper {
|
|
AppWin2Back &app;
|
|
const character::billyEnums obj;
|
|
selection_button *switch_{ nullptr };
|
|
bool on_stack{ false };
|
|
|
|
void signal_handler() noexcept;
|
|
};
|
|
|
|
friend struct SwitchSignalHelper;
|
|
|
|
/*!
|
|
*
|
|
* @return true: failed, false: success
|
|
*/
|
|
bool switches_procedure();
|
|
|
|
void on_quit() noexcept;
|
|
|
|
void debug_button_clicked() const noexcept;
|
|
|
|
void update_labels() const noexcept;
|
|
|
|
bool insert_obj(const character::billyEnums &obj) noexcept;
|
|
|
|
bool erase_obj(const character::billyEnums &obj) noexcept;
|
|
|
|
Glib::RefPtr<Gtk::Builder> app_builder;
|
|
learn_gtkmm4::HelloWorld *main_window{ nullptr };
|
|
selection_button *sword_switch{ nullptr };
|
|
selection_button *lance_switch{ nullptr };
|
|
selection_button *morgen_switch{ nullptr };
|
|
selection_button *bow_switch{ nullptr };
|
|
|
|
selection_button *chainmail_switch{ nullptr };
|
|
selection_button *cookpot_switch{ nullptr };
|
|
selection_button *pamphlet_switch{ nullptr };
|
|
selection_button *medkit_switch{ nullptr };
|
|
|
|
selection_button *fourche_switch{ nullptr };
|
|
selection_button *dagger_switch{ nullptr };
|
|
selection_button *rock_kit_switch{ nullptr };
|
|
selection_button *sack_switch{ nullptr };
|
|
|
|
CaracInterface<Gtk::Label> hab_labels;
|
|
|
|
CaracInterface<Gtk::Label> endu_labels;
|
|
|
|
CaracInterface<Gtk::Label> addr_labels;
|
|
|
|
CaracInterface<Gtk::Label> luck_labels;
|
|
|
|
Gtk::Label *damage_label{ nullptr };
|
|
Gtk::Label *armor_label{ nullptr };
|
|
Gtk::Label *critic_label{ nullptr };
|
|
|
|
Gtk::Button *debug_button{ nullptr };
|
|
|
|
std::array<SwitchSignalHelper, 12> signal_handlers{
|
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Sword },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Lance },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Morgenstern },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::weapons::Bow },
|
|
|
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::Chainmail },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::CookingPot },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::PamphletTourist },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::equipments::MedicKit },
|
|
|
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::Fourche },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::Dagger },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::RockClimbingKit },
|
|
SwitchSignalHelper{ .app = *this, .obj = character::tools::SackOfGrain },
|
|
};
|
|
|
|
buttons_obj_container selection_buttons;
|
|
|
|
character::BillyObjects gestionnaire{};
|
|
character::CharacterSheet sheet{};
|
|
};
|
|
} // gui_to_app
|
|
|
|
#endif //LEARNGTK4_APP_WIN_2_BACK_HPP
|