Submodule for JSON added.

Menu data and menu in their own folder.
This commit is contained in:
Pcornat 2022-01-14 22:06:07 +01:00
parent 27c571a6b9
commit 9142896237
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
12 changed files with 106 additions and 60 deletions

3
.gitmodules vendored
View File

@ -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

View File

@ -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})

1
external/json vendored Submodule

@ -0,0 +1 @@
Subproject commit 4f8fba14066156b73f1189a2b8bd568bde5284c5

View File

@ -2,7 +2,7 @@
#define BILLYSHEET_GUI_HPP
#include <filesystem>
#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;

View File

@ -2,32 +2,28 @@
#define BILLYSHEET_GUI_DATA_HPP
#include "character_sheet.hpp"
#include <filesystem>
#include <spdlog/spdlog.h>
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;
};
}

View File

@ -1,24 +0,0 @@
#ifndef BILLYSHEET_MENU_HPP
#define BILLYSHEET_MENU_HPP
#include <spdlog/spdlog.h>
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

30
include/gui/menu/menu.hpp Normal file
View File

@ -0,0 +1,30 @@
#ifndef BILLYSHEET_MENU_HPP
#define BILLYSHEET_MENU_HPP
#include <spdlog/spdlog.h>
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

View File

@ -0,0 +1,28 @@
#ifndef BILLYSHEET_MENU_DATA_HPP
#define BILLYSHEET_MENU_DATA_HPP
#include <filesystem>
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

View File

@ -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();

View File

@ -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();
}
}

24
src/gui/menu/menu.cpp Normal file
View File

@ -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();
}
}

View File

@ -1,6 +1,7 @@
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#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();