BillySheet/src/gui/gui.cpp

227 lines
9.2 KiB
C++

#include "gui/gui.hpp"
#include "imgui.h"
#include "imgui_stdlib.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "gui/window.hpp"
#include "gui/gui_data.hpp"
#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() noexcept {
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;
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
//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();
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 (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::BeginGroup();
habilete_menu();
ImGui::SameLine();
adresse_menu();
endurance_menu();
ImGui::SameLine();
chance_menu();
ImGui::EndGroup();
ImGui::SameLine();
stat_second_menu();
materiel_menu();
ImGui::SameLine();
ImGui::BeginGroup();
gloire_menu();
richesse_menu();
ImGui::EndGroup();
ImGui::End();
controller.control_menu();
ImGui::Render();
}
}
void gui::Gui::render_gpu() const {
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;
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.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;
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.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");
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.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();
}
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;
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.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();
}
void gui::Gui::materiel_menu() noexcept {
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();
}
void gui::Gui::richesse_menu() noexcept {
ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
ImGui::Text("Richesse");
ImGui::EndChild();
}