Reformat.
This commit is contained in:
parent
7d1a0473ff
commit
2755f4827e
24 changed files with 6140 additions and 5829 deletions
|
@ -1,5 +1,5 @@
|
|||
#include "characteristic/endurance.hpp"
|
||||
|
||||
std::uint32_t character::characteristic::Endurance::get_max_lp() const noexcept {
|
||||
return (base + carac + materiel + additional) * 3;
|
||||
return (base + carac + materiel + additional) * 3;
|
||||
}
|
||||
|
|
|
@ -7,56 +7,56 @@
|
|||
#include "character_sheet.hpp"
|
||||
|
||||
void Controller::control_menu() const noexcept {
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path opening: {}", str.string());
|
||||
const auto filename = str.filename();
|
||||
const auto save_path = str.remove_filename();
|
||||
menu_data.set_filename(*this, filename);
|
||||
menu_data.set_save_path(*this, save_path);
|
||||
std::ifstream file{ save_path / filename };
|
||||
json j = json::parse(file);
|
||||
file.close();
|
||||
sheet = j.at("character_sheet").get<character::CharacterSheet>();
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path saving: {}", str.string());
|
||||
const auto filename = str.filename();
|
||||
const auto save_path = str.remove_filename();
|
||||
menu_data.set_filename(*this, filename);
|
||||
menu_data.set_save_path(*this, save_path);
|
||||
std::ofstream file{ save_path / filename };
|
||||
json j;
|
||||
j.emplace("character_sheet", sheet);
|
||||
file << j.dump(4);
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path opening: {}", str.string());
|
||||
const auto filename = str.filename();
|
||||
const auto save_path = str.remove_filename();
|
||||
menu_data.set_filename(*this, filename);
|
||||
menu_data.set_save_path(*this, save_path);
|
||||
std::ifstream file{ save_path / filename };
|
||||
json j = json::parse(file);
|
||||
file.close();
|
||||
sheet = j.at("character_sheet").get<character::CharacterSheet>();
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path saving: {}", str.string());
|
||||
const auto filename = str.filename();
|
||||
const auto save_path = str.remove_filename();
|
||||
menu_data.set_filename(*this, filename);
|
||||
menu_data.set_save_path(*this, save_path);
|
||||
std::ofstream file{ save_path / filename };
|
||||
json j;
|
||||
j.emplace("character_sheet", sheet);
|
||||
file << j.dump(4);
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
290
src/gui/gui.cpp
290
src/gui/gui.cpp
|
@ -8,209 +8,221 @@
|
|||
#include "character_sheet.hpp"
|
||||
#include "controller.hpp"
|
||||
|
||||
gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||
SPDLOG_DEBUG("Creating GUI");
|
||||
(void) ImGui::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
|
||||
(void) ImGui_ImplGlfw_InitForOpenGL(window.get_window().get(), true);
|
||||
initialized = ImGui_ImplOpenGL3_Init("#version 130");
|
||||
SPDLOG_DEBUG("Initialized: {}", initialized);
|
||||
gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) :
|
||||
data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||
SPDLOG_DEBUG("Creating GUI");
|
||||
(void) ImGui::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
|
||||
(void) ImGui_ImplGlfw_InitForOpenGL(window.get_window().get(), true);
|
||||
initialized = ImGui_ImplOpenGL3_Init("#version 130");
|
||||
SPDLOG_DEBUG("Initialized: {}", initialized);
|
||||
}
|
||||
|
||||
gui::Gui::~Gui() noexcept {
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void gui::Gui::render_gui(const Controller &controller) {
|
||||
if (initialized) {
|
||||
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoTitleBar;
|
||||
if (initialized) {
|
||||
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoTitleBar;
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
//TODO GUI
|
||||
{
|
||||
const ImGuiViewport &viewport = *ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport.Pos);
|
||||
ImGui::SetNextWindowSize(viewport.Size);
|
||||
}
|
||||
//TODO GUI
|
||||
{
|
||||
const ImGuiViewport &viewport = *ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport.Pos);
|
||||
ImGui::SetNextWindowSize(viewport.Size);
|
||||
}
|
||||
|
||||
// Never collapsed.
|
||||
(void) ImGui::Begin("Billy", nullptr, flags);
|
||||
menu.gui();
|
||||
// Never collapsed.
|
||||
(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 (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();
|
||||
}
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Caractère");
|
||||
// Remove label
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
{
|
||||
ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Caractère");
|
||||
// Remove label
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
ImGui::BeginGroup();
|
||||
habilete_menu();
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginGroup();
|
||||
habilete_menu();
|
||||
ImGui::SameLine();
|
||||
|
||||
adresse_menu();
|
||||
adresse_menu();
|
||||
|
||||
endurance_menu();
|
||||
ImGui::SameLine();
|
||||
endurance_menu();
|
||||
ImGui::SameLine();
|
||||
|
||||
chance_menu();
|
||||
ImGui::EndGroup();
|
||||
chance_menu();
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine();
|
||||
|
||||
stat_second_menu();
|
||||
stat_second_menu();
|
||||
|
||||
materiel_menu();
|
||||
materiel_menu();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginGroup();
|
||||
gloire_menu();
|
||||
ImGui::BeginGroup();
|
||||
gloire_menu();
|
||||
|
||||
richesse_menu();
|
||||
ImGui::EndGroup();
|
||||
richesse_menu();
|
||||
ImGui::EndGroup();
|
||||
|
||||
|
||||
ImGui::End();
|
||||
ImGui::End();
|
||||
|
||||
controller.control_menu();
|
||||
controller.control_menu();
|
||||
|
||||
ImGui::Render();
|
||||
}
|
||||
ImGui::Render();
|
||||
}
|
||||
}
|
||||
|
||||
void gui::Gui::render_gpu() const {
|
||||
if (initialized) {
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
if (initialized) {
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
}
|
||||
|
||||
void gui::Gui::habilete_menu() noexcept {
|
||||
ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Habileté");
|
||||
data.base.second = data.billy.get_habilete().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Habilete : characChanged::None;
|
||||
ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Habileté");
|
||||
data.base.second = data.billy.get_habilete().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Habilete
|
||||
: characChanged::None;
|
||||
|
||||
data.carac.second = data.billy.get_habilete().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Habilete : characChanged::None;
|
||||
data.carac.second = data.billy.get_habilete().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Habilete
|
||||
: characChanged::None;
|
||||
|
||||
data.materiel.second = data.billy.get_habilete().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Habilete : characChanged::None;
|
||||
data.materiel.second = data.billy.get_habilete().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
|
||||
? characChanged::Habilete : characChanged::None;
|
||||
|
||||
data.additional.second = data.billy.get_habilete().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Habilete :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
data.additional.second = data.billy.get_habilete().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Habilete :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::adresse_menu() noexcept {
|
||||
ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Adresse");
|
||||
data.base.second = data.billy.get_adresse().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Adresse : characChanged::None;
|
||||
ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Adresse");
|
||||
data.base.second = data.billy.get_adresse().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Adresse
|
||||
: characChanged::None;
|
||||
|
||||
data.carac.second = data.billy.get_adresse().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Adresse : characChanged::None;
|
||||
data.carac.second = data.billy.get_adresse().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Adresse
|
||||
: characChanged::None;
|
||||
|
||||
data.materiel.second = data.billy.get_adresse().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Adresse : characChanged::None;
|
||||
data.materiel.second = data.billy.get_adresse().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
|
||||
? characChanged::Adresse : characChanged::None;
|
||||
|
||||
data.additional.second = data.billy.get_adresse().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Adresse :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
data.additional.second = data.billy.get_adresse().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Adresse :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::endurance_menu() noexcept {
|
||||
ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Endurance");
|
||||
ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Endurance");
|
||||
|
||||
data.base.second = data.billy.get_endurance().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Endurance : characChanged::None;
|
||||
data.base.second = data.billy.get_endurance().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Endurance
|
||||
: characChanged::None;
|
||||
|
||||
data.carac.second = data.billy.get_endurance().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Endurance : characChanged::None;
|
||||
data.carac.second = data.billy.get_endurance().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Endurance
|
||||
: characChanged::None;
|
||||
|
||||
data.materiel.second = data.billy.get_endurance().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ?
|
||||
characChanged::Endurance :
|
||||
characChanged::None;
|
||||
data.materiel.second = data.billy.get_endurance().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ?
|
||||
characChanged::Endurance :
|
||||
characChanged::None;
|
||||
|
||||
data.additional.second = data.billy.get_endurance().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Endurance :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
data.additional.second = data.billy.get_endurance().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Endurance :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::chance_menu() noexcept {
|
||||
ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Chance");
|
||||
data.base.second = data.billy.get_chance().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Chance : characChanged::None;
|
||||
ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Chance");
|
||||
data.base.second = data.billy.get_chance().get_base();
|
||||
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Chance
|
||||
: characChanged::None;
|
||||
|
||||
data.carac.second = data.billy.get_chance().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Chance : characChanged::None;
|
||||
data.carac.second = data.billy.get_chance().get_carac();
|
||||
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Chance
|
||||
: characChanged::None;
|
||||
|
||||
data.materiel.second = data.billy.get_chance().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Chance : characChanged::None;
|
||||
data.materiel.second = data.billy.get_chance().get_materiel();
|
||||
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
|
||||
? characChanged::Chance : characChanged::None;
|
||||
|
||||
data.additional.second = data.billy.get_chance().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Chance :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
data.additional.second = data.billy.get_chance().get_additional();
|
||||
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
|
||||
characChanged::Chance :
|
||||
characChanged::None;
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::stat_second_menu() noexcept {
|
||||
ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true);
|
||||
ImGui::Text("STAT. SECONDAIRES");
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true);
|
||||
ImGui::Text("STAT. SECONDAIRES");
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::materiel_menu() noexcept {
|
||||
ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Matériel");
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
|
||||
ImGui::Text("Matériel");
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::gloire_menu() noexcept {
|
||||
ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
|
||||
ImGui::Text("Gloire");
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
|
||||
ImGui::Text("Gloire");
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void gui::Gui::richesse_menu() noexcept {
|
||||
ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
|
||||
ImGui::Text("Richesse");
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
|
||||
ImGui::Text("Richesse");
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
|
|
@ -9,61 +9,65 @@
|
|||
#include "ImFileDialog.h"
|
||||
|
||||
gui::menu::Menu::Menu(gui::menu::MenuData &data) noexcept: data(data) {
|
||||
SPDLOG_DEBUG("Creating Menu");
|
||||
ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * {
|
||||
GLuint tex;
|
||||
SPDLOG_DEBUG("Inside CreateTexture for file dialog.");
|
||||
glGenTextures(1, &tex);
|
||||
SPDLOG_DEBUG("texture generated");
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
SPDLOG_DEBUG("Texture binded");
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
SPDLOG_DEBUG("Before mipmap");
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
SPDLOG_DEBUG("Creating Menu");
|
||||
ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * {
|
||||
GLuint tex;
|
||||
SPDLOG_DEBUG("Inside CreateTexture for file dialog.");
|
||||
glGenTextures(1, &tex);
|
||||
SPDLOG_DEBUG("texture generated");
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
SPDLOG_DEBUG("Texture binded");
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
SPDLOG_DEBUG("Before mipmap");
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return (void *) tex;
|
||||
};
|
||||
return (void *) tex;
|
||||
};
|
||||
|
||||
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void {
|
||||
auto texID = (GLuint) ((std::uintptr_t) tex);
|
||||
glDeleteTextures(1, &texID);
|
||||
};
|
||||
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void {
|
||||
auto texID = (GLuint) ((std::uintptr_t) tex);
|
||||
glDeleteTextures(1, &texID);
|
||||
};
|
||||
}
|
||||
|
||||
void gui::menu::Menu::gui() const noexcept {
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open file")) {
|
||||
SPDLOG_DEBUG("Opening file");
|
||||
ifd::FileDialog::Instance().Open(data.open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*");
|
||||
SPDLOG_DEBUG("File opened");
|
||||
}
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open file")) {
|
||||
SPDLOG_DEBUG("Opening file");
|
||||
ifd::FileDialog::Instance().Open(data.open_character_key,
|
||||
"Open a character sheet",
|
||||
"Character sheet (*.json){.json},.*");
|
||||
SPDLOG_DEBUG("File opened");
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save")) {
|
||||
SPDLOG_DEBUG("Saving file with know path");
|
||||
std::ofstream file{ data.save_path / data.filename };
|
||||
nlohmann::json j;
|
||||
j.emplace("character_sheet", data.character_sheet);
|
||||
file << j.dump(4);
|
||||
}
|
||||
if (ImGui::MenuItem("Save")) {
|
||||
SPDLOG_DEBUG("Saving file with know path");
|
||||
std::ofstream file{ data.save_path / data.filename };
|
||||
nlohmann::json j;
|
||||
j.emplace("character_sheet", data.character_sheet);
|
||||
file << j.dump(4);
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save as...")) {
|
||||
SPDLOG_DEBUG("Saving with file dialog");
|
||||
ifd::FileDialog::Instance().Save(data.save_character_key, "Save character sheet as...", "*.json {.json}");
|
||||
SPDLOG_DEBUG("File saved with dialog");
|
||||
}
|
||||
if (ImGui::MenuItem("Save as...")) {
|
||||
SPDLOG_DEBUG("Saving with file dialog");
|
||||
ifd::FileDialog::Instance().Save(data.save_character_key,
|
||||
"Save character sheet as...",
|
||||
"*.json {.json}");
|
||||
SPDLOG_DEBUG("File saved with dialog");
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Editor")) {
|
||||
ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Editor")) {
|
||||
ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,47 +3,51 @@
|
|||
#include <spdlog/spdlog.h>
|
||||
|
||||
static void glfwErrorCallback(int error, const char *message) {
|
||||
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
||||
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
||||
}
|
||||
|
||||
static void framebufferCallback([[maybe_unused]] GLFWwindow *glfWwindow, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glViewport(0, 0, width, height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
gui::Window::Window() {
|
||||
SPDLOG_DEBUG("Creating Window");
|
||||
glfwSetErrorCallback(glfwErrorCallback);
|
||||
if (glfwInit() == GLFW_FALSE) {
|
||||
SPDLOG_CRITICAL("GLFW init failed.");
|
||||
throw std::runtime_error("GLFW init failed.");
|
||||
}
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(720, 1280, "Billy Sheet tracker", nullptr, nullptr),
|
||||
delete_glfw_window);
|
||||
if (!wwindow) {
|
||||
glfwTerminate();
|
||||
SPDLOG_CRITICAL("No GLFW window created, nullptr.");
|
||||
throw std::runtime_error("GLFW failed. See log.");
|
||||
}
|
||||
glfwMakeContextCurrent(wwindow.get());
|
||||
glewExperimental = true;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
wwindow.reset(nullptr);
|
||||
glfwTerminate();
|
||||
SPDLOG_CRITICAL("GLEW loader failed.");
|
||||
throw std::runtime_error("GLEW failed. See log.");
|
||||
}
|
||||
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
||||
SPDLOG_DEBUG("Creating Window");
|
||||
glfwSetErrorCallback(glfwErrorCallback);
|
||||
if (glfwInit() == GLFW_FALSE) {
|
||||
SPDLOG_CRITICAL("GLFW init failed.");
|
||||
throw std::runtime_error("GLFW init failed.");
|
||||
}
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(720,
|
||||
1280,
|
||||
"Billy Sheet tracker",
|
||||
nullptr,
|
||||
nullptr),
|
||||
delete_glfw_window);
|
||||
if (!wwindow) {
|
||||
glfwTerminate();
|
||||
SPDLOG_CRITICAL("No GLFW window created, nullptr.");
|
||||
throw std::runtime_error("GLFW failed. See log.");
|
||||
}
|
||||
glfwMakeContextCurrent(wwindow.get());
|
||||
glewExperimental = true;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
wwindow.reset(nullptr);
|
||||
glfwTerminate();
|
||||
SPDLOG_CRITICAL("GLEW loader failed.");
|
||||
throw std::runtime_error("GLEW failed. See log.");
|
||||
}
|
||||
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
||||
|
||||
glfwSwapInterval(1); // VSync on
|
||||
glfwSwapInterval(1); // VSync on
|
||||
}
|
||||
|
||||
bool gui::Window::should_close() const noexcept {
|
||||
return glfwWindowShouldClose(wwindow.get());
|
||||
return glfwWindowShouldClose(wwindow.get());
|
||||
}
|
||||
|
||||
void gui::Window::swap_buffers() const noexcept {
|
||||
glfwSwapBuffers(wwindow.get());
|
||||
glfwSwapBuffers(wwindow.get());
|
||||
}
|
42
src/main.cpp
42
src/main.cpp
|
@ -8,29 +8,29 @@
|
|||
#include "character_sheet.hpp"
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
spdlog::set_default_logger(spdlog::stdout_color_st("BillySheet"));
|
||||
std::ios::sync_with_stdio(false);
|
||||
spdlog::set_default_logger(spdlog::stdout_color_st("BillySheet"));
|
||||
|
||||
try {
|
||||
gui::Window window;
|
||||
character::CharacterSheet billy;
|
||||
gui::GuiData gui_data(billy);
|
||||
gui::menu::MenuData menu_data(billy);
|
||||
Controller controller(billy, menu_data);
|
||||
gui::Gui gui(window, gui_data, menu_data);
|
||||
try {
|
||||
gui::Window window;
|
||||
character::CharacterSheet billy;
|
||||
gui::GuiData gui_data(billy);
|
||||
gui::menu::MenuData menu_data(billy);
|
||||
Controller controller(billy, menu_data);
|
||||
gui::Gui gui(window, gui_data, menu_data);
|
||||
|
||||
while (!window.should_close()) {
|
||||
glfwPollEvents();
|
||||
controller.control_sheet();
|
||||
while (!window.should_close()) {
|
||||
glfwPollEvents();
|
||||
controller.control_sheet();
|
||||
|
||||
gui.render_gui(controller);
|
||||
gui.render_gpu();
|
||||
gui.render_gui(controller);
|
||||
gui.render_gpu();
|
||||
|
||||
window.swap_buffers();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
SPDLOG_CRITICAL(e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
window.swap_buffers();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
SPDLOG_CRITICAL(e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue