Working with file dialog, yay ! :D
This commit is contained in:
parent
1266628646
commit
546c935cf2
8 changed files with 25 additions and 31 deletions
|
@ -3,27 +3,24 @@
|
|||
#include "ImFileDialog.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
void Controller::control() noexcept {
|
||||
SPDLOG_DEBUG("Check \"open character\" task");
|
||||
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::open_character_key)) {
|
||||
SPDLOG_DEBUG("Task done");
|
||||
void Controller::control_menu() const noexcept {
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
SPDLOG_DEBUG("Has Result");
|
||||
fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path opening: {}", str.string());
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
SPDLOG_DEBUG("Check \"saving character\" task");
|
||||
if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::save_character_key)) {
|
||||
SPDLOG_DEBUG("Task done");
|
||||
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
|
||||
if (ifd::FileDialog::Instance().HasResult()) {
|
||||
SPDLOG_DEBUG("Has Result");
|
||||
const fs::path str = ifd::FileDialog::Instance().GetResult();
|
||||
SPDLOG_DEBUG("path saving: {}", str.string());
|
||||
}
|
||||
ifd::FileDialog::Instance().Close();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::control_sheet() const noexcept {
|
||||
if (menu_data.is_edit_mode()) {
|
||||
// TODO
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gui/window.hpp"
|
||||
#include "gui/gui_data.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
#include "controller.hpp"
|
||||
|
||||
gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") {
|
||||
SPDLOG_DEBUG("Creating GUI");
|
||||
|
@ -23,7 +24,7 @@ gui::Gui::~Gui() noexcept {
|
|||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void gui::Gui::render_gui() {
|
||||
void gui::Gui::render_gui(const Controller &controller) {
|
||||
if (initialized) {
|
||||
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoMove |
|
||||
|
@ -88,6 +89,8 @@ void gui::Gui::render_gui() {
|
|||
|
||||
ImGui::End();
|
||||
|
||||
controller.control_menu();
|
||||
|
||||
ImGui::Render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ void gui::menu::Menu::gui() const noexcept {
|
|||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open file")) {
|
||||
SPDLOG_DEBUG("Opening file");
|
||||
ifd::FileDialog::Instance().Open(MenuData::open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*");
|
||||
ifd::FileDialog::Instance().Open(data.open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*");
|
||||
SPDLOG_DEBUG("File opened");
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,12 @@ void gui::menu::Menu::gui() const noexcept {
|
|||
std::ofstream file{ data.save_path / data.filename };
|
||||
nlohmann::json j;
|
||||
j.emplace("character_sheet", data.character_sheet);
|
||||
file << j;
|
||||
file << j.dump(4);
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save as...")) {
|
||||
SPDLOG_DEBUG("Saving with file dialog");
|
||||
ifd::FileDialog::Instance().Save(MenuData::save_character_key, "Save character sheet as...", "*.json {.json}");
|
||||
ifd::FileDialog::Instance().Save(data.save_character_key, "Save character sheet as...", "*.json {.json}");
|
||||
SPDLOG_DEBUG("File saved with dialog");
|
||||
}
|
||||
|
||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -1,4 +1,3 @@
|
|||
#include <boost/stacktrace.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include "gui/window.hpp"
|
||||
|
@ -8,15 +7,7 @@
|
|||
#include "controller.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
|
||||
void myTerminateHandler() {
|
||||
try {
|
||||
SPDLOG_CRITICAL(to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {}
|
||||
std::abort();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::set_terminate(myTerminateHandler);
|
||||
std::ios::sync_with_stdio(false);
|
||||
spdlog::set_default_logger(spdlog::stdout_color_st("console"));
|
||||
|
||||
|
@ -30,9 +21,9 @@ int main() {
|
|||
|
||||
while (!window.should_close()) {
|
||||
glfwPollEvents();
|
||||
controller.control();
|
||||
// controller.control();
|
||||
|
||||
gui.render_gui();
|
||||
gui.render_gui(controller);
|
||||
gui.render_gpu();
|
||||
|
||||
window.swap_buffers();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue