Working to save and select classes

This commit is contained in:
Pcornat 2022-01-25 19:53:58 +01:00
parent 8e6f0ccc1f
commit acc2f0ca9d
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
6 changed files with 54 additions and 1 deletions

1
.gitignore vendored
View File

@ -2,4 +2,5 @@ cmake-*
build/
!.idea/cmake.xml
.idea/*
*.json
imgui.ini

View File

@ -12,9 +12,17 @@ namespace gui {
}
namespace character {
enum class classe : std::uint32_t {
Guerrier = 0,
Prudent = 1,
Paysan = 2,
Debrouillard = 3,
};
class CharacterSheet final {
private:
friend gui::Gui;
friend class Controller;
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
@ -29,6 +37,8 @@ namespace character {
characteristic::Habilete habilete;
classe current_class{ classe::Guerrier };
std::uint32_t health_point{ 0 };
std::uint32_t armor{ 0 };
@ -53,6 +63,8 @@ namespace character {
[[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; }
[[nodiscard]] classe get_current_class() const { return current_class; }
[[nodiscard]] std::uint32_t get_health_point() const { return health_point; }
[[nodiscard]] std::uint32_t get_armor() const { return armor; }
@ -69,6 +81,7 @@ namespace character {
j.at("endurance").get_to(billy.endurance);
j.at("chance").get_to(billy.chance);
j.at("habilete").get_to(billy.habilete);
j.at("classe").get_to(billy.current_class);
j.at("health_point").get_to(billy.health_point);
j.at("armor").get_to(billy.armor);
j.at("damage").get_to(billy.damage);
@ -83,6 +96,7 @@ namespace character {
j["endurance"] = billy.get_endurance();
j["chance"] = billy.get_chance();
j["habilete"] = billy.get_habilete();
j["classe"] = billy.get_current_class();
j["health_point"] = billy.get_health_point();
j["armor"] = billy.get_armor();
j["damage"] = billy.get_damage();

View File

@ -1,12 +1,15 @@
#ifndef BILLYSHEET_GUI_DATA_HPP
#define BILLYSHEET_GUI_DATA_HPP
#include <string_view>
#include <spdlog/spdlog.h>
namespace character {
class CharacterSheet;
}
using namespace std::string_view_literals;
namespace gui {
class Window;
@ -19,6 +22,13 @@ namespace gui {
character::CharacterSheet &billy;
public:
static constexpr std::array classes{
"Guerrier"sv,
"Prudent"sv,
"Paysan"sv,
"Débrouillard"sv
};
GuiData() = delete;
explicit GuiData(Window &wwindow, character::CharacterSheet &billy) : window(wwindow), billy(billy) { SPDLOG_DEBUG("Creating GUI Data"); }

View File

@ -42,6 +42,20 @@ void Controller::control_menu() const noexcept {
void Controller::control_sheet() const noexcept {
if (menu_data.is_edit_mode()) {
// TODO
switch (sheet.get_current_class()) {
case character::classe::Prudent:
// TODO
break;
case character::classe::Guerrier:
// TODO
break;
case character::classe::Paysan:
// TODO
break;
case character::classe::Debrouillard:
// TODO
break;
}
} else {
// TODO
}

View File

@ -47,6 +47,20 @@ void gui::Gui::render_gui(const Controller &controller) {
(void) ImGui::Begin("Billy", nullptr, flags);
menu.gui();
if (ImGui::BeginCombo("Classe",
GuiData::classes[static_cast<std::uint32_t>(data.billy.get_current_class())].data(),
ImGuiComboFlags_PopupAlignLeft)) {
for (std::size_t i = 0; i < GuiData::classes.size(); ++i) {
const bool is_selected = (data.billy.get_current_class() == static_cast<character::classe>(i));
if (ImGui::Selectable(GuiData::classes[i].data(), is_selected))
data.billy.current_class = static_cast<character::classe>(i);
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
{
ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Caractère");

View File

@ -21,7 +21,7 @@ int main() {
while (!window.should_close()) {
glfwPollEvents();
// controller.control();
controller.control_sheet();
gui.render_gui(controller);
gui.render_gpu();