Always functional.
Design : the controller controls data of the character sheet and also saving and reading data.
This commit is contained in:
parent
84450d25af
commit
b759836989
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,3 +10,6 @@
|
|||||||
[submodule "external/catch2"]
|
[submodule "external/catch2"]
|
||||||
path = external/catch2
|
path = external/catch2
|
||||||
url = https://github.com/catchorg/Catch2.git
|
url = https://github.com/catchorg/Catch2.git
|
||||||
|
[submodule "external/ImFileDialog"]
|
||||||
|
path = external/ImFileDialog
|
||||||
|
url = https://github.com/dfranx/ImFileDialog.git
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
|
||||||
project(BillySheet LANGUAGES CXX C)
|
project(BillySheet LANGUAGES CXX C)
|
||||||
|
|
||||||
|
#set(GLEW_USE_STATIC_LIBS ON)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
|
||||||
set(PRECOMPILE_HEADERS
|
set(PRECOMPILE_HEADERS
|
||||||
include/gui/gui.hpp
|
include/gui/gui.hpp
|
||||||
@ -20,6 +22,8 @@ set(SOURCE_HEADERS
|
|||||||
include/imgui/imstb_rectpack.h
|
include/imgui/imstb_rectpack.h
|
||||||
include/imgui/imstb_textedit.h
|
include/imgui/imstb_textedit.h
|
||||||
include/imgui/imstb_truetype.h
|
include/imgui/imstb_truetype.h
|
||||||
|
include/stb_image.h
|
||||||
|
external/ImFileDialog/ImFileDialog.h
|
||||||
include/gui/gui.hpp
|
include/gui/gui.hpp
|
||||||
include/gui/gui_data.hpp
|
include/gui/gui_data.hpp
|
||||||
include/gui/window.hpp
|
include/gui/window.hpp
|
||||||
@ -42,6 +46,7 @@ set(SOURCE_FILES
|
|||||||
src/imgui/imgui_impl_opengl3.cpp
|
src/imgui/imgui_impl_opengl3.cpp
|
||||||
src/imgui/imgui_tables.cpp
|
src/imgui/imgui_tables.cpp
|
||||||
src/imgui/imgui_widgets.cpp
|
src/imgui/imgui_widgets.cpp
|
||||||
|
external/ImFileDialog/ImFileDialog.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/gui/gui.cpp
|
src/gui/gui.cpp
|
||||||
src/gui/gui_data.cpp
|
src/gui/gui_data.cpp
|
||||||
@ -124,7 +129,7 @@ set(LINKER_FLAGS
|
|||||||
|
|
||||||
add_executable(BillySheet ${SOURCES})
|
add_executable(BillySheet ${SOURCES})
|
||||||
|
|
||||||
target_include_directories(BillySheet PRIVATE include include/imgui)
|
target_include_directories(BillySheet PRIVATE include include/imgui external/ImFileDialog)
|
||||||
|
|
||||||
set_target_properties(BillySheet spdlog PROPERTIES
|
set_target_properties(BillySheet spdlog PROPERTIES
|
||||||
CXX_STANDARD 17
|
CXX_STANDARD 17
|
||||||
@ -157,4 +162,4 @@ target_link_options(BillySheet PRIVATE ${LINKER_OPTIONS})
|
|||||||
|
|
||||||
target_link_libraries(spdlog PRIVATE ${LINKER_FLAGS})
|
target_link_libraries(spdlog PRIVATE ${LINKER_FLAGS})
|
||||||
target_link_libraries(glfw PRIVATE ${LINKER_FLAGS})
|
target_link_libraries(glfw PRIVATE ${LINKER_FLAGS})
|
||||||
target_link_libraries(BillySheet glfw spdlog OpenGL::OpenGL nlohmann_json::nlohmann_json ${LINKER_FLAGS})
|
target_link_libraries(BillySheet glfw spdlog OpenGL::OpenGL GLEW::GLEW nlohmann_json::nlohmann_json ${LINKER_FLAGS})
|
||||||
|
@ -6,6 +6,8 @@ Some dependencies are inside the "external" directory. The followings are inside
|
|||||||
- GLFW: windowing
|
- GLFW: windowing
|
||||||
- Spdlog: logging the app.
|
- Spdlog: logging the app.
|
||||||
- Catch2
|
- Catch2
|
||||||
|
- [ImFileDialog](https://github.com/dfranx/ImFileDialog)
|
||||||
|
- [stb_image.h](https://github.com/nothings/stb/blob/master/stb_image.h)
|
||||||
|
|
||||||
The others are:
|
The others are:
|
||||||
- jemalloc
|
- jemalloc
|
||||||
|
1
external/ImFileDialog
vendored
Submodule
1
external/ImFileDialog
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a4753476b1bdb22566d6913924206326704dc2cf
|
@ -15,6 +15,8 @@ namespace character {
|
|||||||
class CharacterSheet final {
|
class CharacterSheet final {
|
||||||
private:
|
private:
|
||||||
friend gui::Gui;
|
friend gui::Gui;
|
||||||
|
friend class Controller;
|
||||||
|
|
||||||
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
||||||
|
|
||||||
std::string caractere{};
|
std::string caractere{};
|
||||||
@ -62,7 +64,7 @@ namespace character {
|
|||||||
[[nodiscard]] std::uint32_t get_money() const { return money; }
|
[[nodiscard]] std::uint32_t get_money() const { return money; }
|
||||||
|
|
||||||
friend void from_json(const json &j, CharacterSheet &billy) {
|
friend void from_json(const json &j, CharacterSheet &billy) {
|
||||||
j.at("caracters").get_to(billy.caractere);
|
j.at("caractere").get_to(billy.caractere);
|
||||||
j.at("adresse").get_to(billy.adresse);
|
j.at("adresse").get_to(billy.adresse);
|
||||||
j.at("endurance").get_to(billy.endurance);
|
j.at("endurance").get_to(billy.endurance);
|
||||||
j.at("chance").get_to(billy.chance);
|
j.at("chance").get_to(billy.chance);
|
||||||
|
@ -1,9 +1,27 @@
|
|||||||
#ifndef BILLYSHEET_CONTROLLER_HPP
|
#ifndef BILLYSHEET_CONTROLLER_HPP
|
||||||
#define BILLYSHEET_CONTROLLER_HPP
|
#define BILLYSHEET_CONTROLLER_HPP
|
||||||
|
|
||||||
|
namespace character {
|
||||||
|
class CharacterSheet;
|
||||||
|
}
|
||||||
|
|
||||||
class Controller {
|
namespace gui::menu {
|
||||||
|
class MenuData;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Controller final {
|
||||||
|
private:
|
||||||
|
character::CharacterSheet &sheet;
|
||||||
|
const gui::menu::MenuData &menu_data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Controller() = delete;
|
||||||
|
|
||||||
|
explicit Controller(character::CharacterSheet &sheet, const gui::menu::MenuData &menuData) : sheet(sheet), menu_data(menuData) {}
|
||||||
|
|
||||||
|
~Controller() noexcept = default;
|
||||||
|
|
||||||
|
void control() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#ifndef BILLYSHEET_GUI_DATA_HPP
|
#ifndef BILLYSHEET_GUI_DATA_HPP
|
||||||
#define BILLYSHEET_GUI_DATA_HPP
|
#define BILLYSHEET_GUI_DATA_HPP
|
||||||
|
|
||||||
#include "character_sheet.hpp"
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
namespace character {
|
||||||
|
class CharacterSheet;
|
||||||
|
}
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Window;
|
class Window;
|
||||||
|
|
||||||
@ -13,13 +16,12 @@ namespace gui {
|
|||||||
|
|
||||||
Window &window;
|
Window &window;
|
||||||
|
|
||||||
character::CharacterSheet billy;
|
character::CharacterSheet &billy;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuiData() = delete;
|
GuiData() = delete;
|
||||||
|
|
||||||
explicit GuiData(Window &wwindow) : window(wwindow) { SPDLOG_DEBUG("Creating GUI Data"); }
|
explicit GuiData(Window &wwindow, character::CharacterSheet &billy) : window(wwindow), billy(billy) { SPDLOG_DEBUG("Creating GUI Data"); }
|
||||||
|
|
||||||
~GuiData() noexcept = default;
|
~GuiData() noexcept = default;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ namespace gui {
|
|||||||
public:
|
public:
|
||||||
Menu() noexcept = delete;
|
Menu() noexcept = delete;
|
||||||
|
|
||||||
explicit Menu(MenuData &data) noexcept: data(data) { SPDLOG_DEBUG("Creating Menu"); }
|
explicit Menu(MenuData &data) noexcept;
|
||||||
|
|
||||||
~Menu() noexcept = default;
|
~Menu() noexcept = default;
|
||||||
|
|
||||||
|
@ -5,18 +5,26 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
namespace character {
|
||||||
|
class CharacterSheet;
|
||||||
|
}
|
||||||
|
|
||||||
namespace gui::menu {
|
namespace gui::menu {
|
||||||
class MenuData final {
|
class MenuData final {
|
||||||
private:
|
private:
|
||||||
friend class Menu;
|
friend class Menu;
|
||||||
|
|
||||||
|
const character::CharacterSheet &character_sheet;
|
||||||
|
|
||||||
fs::path save_path{ "./" };
|
fs::path save_path{ "./" };
|
||||||
|
|
||||||
std::string filename{ "character_sheet.json" };
|
std::string filename{ "character_sheet.json" };
|
||||||
|
|
||||||
bool edit_mode{ true };
|
bool edit_mode{ true };
|
||||||
public:
|
public:
|
||||||
MenuData() noexcept = default;
|
MenuData() noexcept = delete;
|
||||||
|
|
||||||
|
explicit MenuData(const character::CharacterSheet &characterSheet) noexcept: character_sheet(characterSheet) {}
|
||||||
|
|
||||||
~MenuData() noexcept = default;
|
~MenuData() noexcept = default;
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef BILLYSHEET_WINDOW_HPP
|
#ifndef BILLYSHEET_WINDOW_HPP
|
||||||
#define BILLYSHEET_WINDOW_HPP
|
#define BILLYSHEET_WINDOW_HPP
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "imgui_impl_opengl3_loader.h"
|
|
||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Window final {
|
class Window final {
|
||||||
|
7897
include/stb_image.h
Normal file
7897
include/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1 +1,10 @@
|
|||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
|
#include "gui/menu/menu_data.hpp"
|
||||||
|
|
||||||
|
void Controller::control() noexcept {
|
||||||
|
if (menu_data.is_edit_mode()) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "gui/gui.hpp"
|
#include "gui/gui.hpp"
|
||||||
#include "gui/gui_data.hpp"
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_stdlib.h"
|
#include "imgui_stdlib.h"
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
#include "imgui_impl_opengl3_loader.h"
|
|
||||||
#include "gui/window.hpp"
|
#include "gui/window.hpp"
|
||||||
|
#include "gui/gui_data.hpp"
|
||||||
|
#include "character_sheet.hpp"
|
||||||
|
|
||||||
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||||
SPDLOG_DEBUG("Creating GUI");
|
SPDLOG_DEBUG("Creating GUI");
|
||||||
@ -13,7 +13,7 @@ gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuDa
|
|||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
|
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
|
||||||
(void) ImGui_ImplGlfw_InitForOpenGL(data.get_window().get_window().get(), true);
|
(void) ImGui_ImplGlfw_InitForOpenGL(data.get_window().get_window().get(), true);
|
||||||
initialized = ImGui_ImplOpenGL3_Init();
|
initialized = ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
SPDLOG_DEBUG("Initialized: {}", initialized);
|
SPDLOG_DEBUG("Initialized: {}", initialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,52 @@
|
|||||||
#include "gui/menu/menu.hpp"
|
#include "gui/menu/menu.hpp"
|
||||||
#include "imgui.h"
|
#include <GL/glew.h>
|
||||||
#include "gui/menu/menu_data.hpp"
|
#include <GL/gl.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "gui/menu/menu_data.hpp"
|
||||||
|
#include "character_sheet.hpp"
|
||||||
|
#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;
|
||||||
|
|
||||||
|
glGenTextures(1, &tex);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
|
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);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
return (void *) tex;
|
||||||
|
};
|
||||||
|
|
||||||
|
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void {
|
||||||
|
auto texID = (GLuint) ((std::uintptr_t) tex);
|
||||||
|
glDeleteTextures(1, &texID);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void gui::menu::Menu::gui() const noexcept {
|
void gui::menu::Menu::gui() const noexcept {
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
if (ImGui::MenuItem("Open file")) {
|
if (ImGui::MenuItem("Open file")) {
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save")) {
|
if (ImGui::MenuItem("Save")) {
|
||||||
std::ofstream file{ data.save_path / data.filename };
|
std::ofstream file{ data.save_path / data.filename };
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
j.emplace("character_sheet", data)
|
j.emplace("character_sheet", data.character_sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save as...")) {
|
if (ImGui::MenuItem("Save as...")) {
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "gui/window.hpp"
|
#include "gui/window.hpp"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "spdlog/spdlog.h"
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
static void glfwErrorCallback(int error, const char *message) {
|
static void glfwErrorCallback(int error, const char *message) {
|
||||||
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
||||||
@ -27,6 +27,13 @@ gui::Window::Window() {
|
|||||||
throw std::runtime_error("GLFW failed. See log.");
|
throw std::runtime_error("GLFW failed. See log.");
|
||||||
}
|
}
|
||||||
glfwMakeContextCurrent(wwindow.get());
|
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.");
|
||||||
|
}
|
||||||
glfwSwapInterval(1); // VSync on
|
glfwSwapInterval(1); // VSync on
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "gui/menu/menu_data.hpp"
|
#include "gui/menu/menu_data.hpp"
|
||||||
#include "gui/gui_data.hpp"
|
#include "gui/gui_data.hpp"
|
||||||
#include "gui/gui.hpp"
|
#include "gui/gui.hpp"
|
||||||
|
#include "controller.hpp"
|
||||||
|
#include "character_sheet.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
@ -11,12 +13,15 @@ int main() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
gui::Window window;
|
gui::Window window;
|
||||||
gui::GuiData gui_data(window);
|
character::CharacterSheet billy;
|
||||||
gui::menu::MenuData menu_data;
|
gui::GuiData gui_data(window, billy);
|
||||||
|
gui::menu::MenuData menu_data(billy);
|
||||||
|
Controller controller(billy, menu_data);
|
||||||
gui::Gui gui(gui_data, menu_data);
|
gui::Gui gui(gui_data, menu_data);
|
||||||
|
|
||||||
while (!window.should_close()) {
|
while (!window.should_close()) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
controller.control();
|
||||||
|
|
||||||
gui.render_gui();
|
gui.render_gui();
|
||||||
gui.render_gpu();
|
gui.render_gpu();
|
||||||
|
Loading…
Reference in New Issue
Block a user