From 9142896237e85652debd9fe9ca4db642a32dc86f Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 14 Jan 2022 22:06:07 +0100 Subject: [PATCH] Submodule for JSON added. Menu data and menu in their own folder. --- .gitmodules | 3 +++ CMakeLists.txt | 11 +++++++---- external/json | 1 + include/gui/gui.hpp | 8 +++++--- include/gui/gui_data.hpp | 12 ++++-------- include/gui/menu.hpp | 24 ------------------------ include/gui/menu/menu.hpp | 30 ++++++++++++++++++++++++++++++ include/gui/menu/menu_data.hpp | 28 ++++++++++++++++++++++++++++ src/gui/gui.cpp | 2 +- src/gui/menu.cpp | 19 ------------------- src/gui/menu/menu.cpp | 24 ++++++++++++++++++++++++ src/main.cpp | 4 +++- 12 files changed, 106 insertions(+), 60 deletions(-) create mode 160000 external/json delete mode 100644 include/gui/menu.hpp create mode 100644 include/gui/menu/menu.hpp create mode 100644 include/gui/menu/menu_data.hpp delete mode 100644 src/gui/menu.cpp create mode 100644 src/gui/menu/menu.cpp diff --git a/.gitmodules b/.gitmodules index 9c51ba7..2ded04f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "external/glfw"] path = external/glfw url = https://github.com/glfw/glfw.git +[submodule "external/json"] + path = external/json + url = https://github.com/nlohmann/json.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a2bbd96..e012e0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ set(SOURCE_HEADERS include/characteristic/adresse.hpp include/characteristic/endurance.hpp include/characteristic/chance.hpp - include/gui/menu.hpp - ) + include/gui/menu/menu.hpp + include/gui/menu/menu_data.hpp) set(SOURCE_FILES src/imgui/imgui.cpp @@ -45,7 +45,7 @@ set(SOURCE_FILES src/characteristic/adresse.cpp src/characteristic/endurance.cpp src/characteristic/chance.cpp - src/gui/menu.cpp + src/gui/menu/menu.cpp ) set(SOURCES @@ -79,6 +79,9 @@ option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" ON) option(SPDLOG_NO_ATOMIC_LEVELS "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" ON) add_subdirectory(external/spdlog) +set(JSON_BuildTests OFF CACHE INTERNAL "") +add_subdirectory(external/json) + set(COMPILE_FLAGS -pipe -march=skylake # change to native or your architecture. @@ -142,4 +145,4 @@ target_link_options(BillySheet PRIVATE ${LINKER_OPTIONS}) target_link_libraries(spdlog PRIVATE ${LINKER_FLAGS}) target_link_libraries(glfw PRIVATE ${LINKER_FLAGS}) -target_link_libraries(BillySheet glfw spdlog OpenGL::OpenGL ${LINKER_FLAGS}) +target_link_libraries(BillySheet glfw spdlog OpenGL::OpenGL nlohmann_json::nlohmann_json ${LINKER_FLAGS}) diff --git a/external/json b/external/json new file mode 160000 index 0000000..4f8fba1 --- /dev/null +++ b/external/json @@ -0,0 +1 @@ +Subproject commit 4f8fba14066156b73f1189a2b8bd568bde5284c5 diff --git a/include/gui/gui.hpp b/include/gui/gui.hpp index 0202b8f..cfff485 100644 --- a/include/gui/gui.hpp +++ b/include/gui/gui.hpp @@ -2,7 +2,7 @@ #define BILLYSHEET_GUI_HPP #include -#include "menu.hpp" +#include "gui/menu/menu.hpp" namespace fs = std::filesystem; @@ -10,11 +10,13 @@ namespace gui { class GuiData; + namespace menu { class MenuData; } + class Gui final { private: GuiData &data; - Menu menu; + menu::Menu menu; fs::path font; @@ -22,7 +24,7 @@ namespace gui { public: Gui() = delete; - explicit Gui(GuiData &data); + explicit Gui(GuiData &data, menu::MenuData &menuData); ~Gui() noexcept; diff --git a/include/gui/gui_data.hpp b/include/gui/gui_data.hpp index a509d37..373eabf 100644 --- a/include/gui/gui_data.hpp +++ b/include/gui/gui_data.hpp @@ -2,32 +2,28 @@ #define BILLYSHEET_GUI_DATA_HPP #include "character_sheet.hpp" -#include #include -namespace fs = std::filesystem; - namespace gui { class Window; class GuiData final { private: + friend class Gui; + Window &window; character::CharacterSheet billy; - // Is it the right place here for both ? Not sure. - fs::path save_path{ "./" }; - std::string filename{ "character_sheet.json" }; public: GuiData() = delete; explicit GuiData(Window &wwindow) : window(wwindow) { SPDLOG_DEBUG("Creating GUI Data"); } - [[nodiscard]] Window &get_window() const; - ~GuiData() noexcept = default; + + [[nodiscard]] Window &get_window() const; }; } diff --git a/include/gui/menu.hpp b/include/gui/menu.hpp deleted file mode 100644 index 5c89c93..0000000 --- a/include/gui/menu.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BILLYSHEET_MENU_HPP -#define BILLYSHEET_MENU_HPP - -#include - -namespace gui { - class GuiData; - - class Menu final { - private: - GuiData &data; - public: - Menu() noexcept = delete; - - explicit Menu(GuiData &data) noexcept: data(data) { SPDLOG_DEBUG("Creating Menu"); } - - ~Menu() noexcept = default; - - void gui() const noexcept; - }; -} - - -#endif //BILLYSHEET_MENU_HPP diff --git a/include/gui/menu/menu.hpp b/include/gui/menu/menu.hpp new file mode 100644 index 0000000..0d69053 --- /dev/null +++ b/include/gui/menu/menu.hpp @@ -0,0 +1,30 @@ +#ifndef BILLYSHEET_MENU_HPP +#define BILLYSHEET_MENU_HPP + +#include + +namespace gui { + class GuiData; + + namespace menu { + class MenuData; + + class Menu final { + private: + MenuData &data; + public: + Menu() noexcept = delete; + + explicit Menu(MenuData &data) noexcept: data(data) { SPDLOG_DEBUG("Creating Menu"); } + + ~Menu() noexcept = default; + + void gui() const noexcept; + + [[nodiscard]] const MenuData &get_data() const { return data; } + }; + } +} + + +#endif //BILLYSHEET_MENU_HPP diff --git a/include/gui/menu/menu_data.hpp b/include/gui/menu/menu_data.hpp new file mode 100644 index 0000000..f68157c --- /dev/null +++ b/include/gui/menu/menu_data.hpp @@ -0,0 +1,28 @@ +#ifndef BILLYSHEET_MENU_DATA_HPP +#define BILLYSHEET_MENU_DATA_HPP + +#include + +namespace fs = std::filesystem; + +namespace gui::menu { + class MenuData final { + private: + friend class Menu; + + fs::path save_path{ "./" }; + + std::string filename{ "character_sheet.json" }; + + bool edit_mode{ true }; + public: + MenuData() noexcept = default; + + ~MenuData() noexcept = default; + + [[nodiscard]] bool is_edit_mode() const { return edit_mode; } + }; +} + + +#endif //BILLYSHEET_MENU_DATA_HPP diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index db02c4d..87517af 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6,7 +6,7 @@ #include "imgui_impl_opengl3_loader.h" #include "gui/window.hpp" -gui::Gui::Gui(gui::GuiData &data) : data(data), menu(data), font("font/DejaVuSans.ttf") { +gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") { SPDLOG_DEBUG("Creating GUI"); (void) ImGui::CreateContext(); ImGui::StyleColorsDark(); diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp deleted file mode 100644 index 68976fb..0000000 --- a/src/gui/menu.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "gui/menu.hpp" -#include "imgui.h" - -void gui::Menu::gui() const noexcept { - if (ImGui::BeginMenuBar()) { - if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Save")) { - - } - - if (ImGui::MenuItem("Save as...")) { - - } - - ImGui::EndMenu(); - } - ImGui::EndMenuBar(); - } -} diff --git a/src/gui/menu/menu.cpp b/src/gui/menu/menu.cpp new file mode 100644 index 0000000..be50335 --- /dev/null +++ b/src/gui/menu/menu.cpp @@ -0,0 +1,24 @@ +#include "gui/menu/menu.hpp" +#include "imgui.h" +#include "gui/menu/menu_data.hpp" + +void gui::menu::Menu::gui() const noexcept { + if (ImGui::BeginMenuBar()) { + if (ImGui::BeginMenu("File")) { + if (ImGui::MenuItem("Save")) { + + } + + if (ImGui::MenuItem("Save as...")) { + + } + + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Editor")) { + ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode); + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } +} diff --git a/src/main.cpp b/src/main.cpp index e841c6f..37de4d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include "gui/window.hpp" +#include "gui/menu/menu_data.hpp" #include "gui/gui_data.hpp" #include "gui/gui.hpp" @@ -11,7 +12,8 @@ int main() { try { gui::Window window; gui::GuiData gui_data(window); - gui::Gui gui(gui_data); + gui::menu::MenuData menu_data; + gui::Gui gui(gui_data, menu_data); while (!window.should_close()) { glfwPollEvents();