From 9c9bd7d75cccc84d2a07117e8529aaee5f3180f8 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Sun, 1 Aug 2021 16:50:24 +0200 Subject: [PATCH] [#26]: Disable Play/Save buttons, when there's no active Level --- editor/GUI/EditorGUI.cpp | 7 ++++++- engine/FileManager/FileManager.cpp | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/editor/GUI/EditorGUI.cpp b/editor/GUI/EditorGUI.cpp index 3d2a6e7f..6a7b6fa1 100644 --- a/editor/GUI/EditorGUI.cpp +++ b/editor/GUI/EditorGUI.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace dgame { @@ -158,7 +159,9 @@ EditorGUI::Render() ImGui::SetNextWindowPos({0, 0}); ImGui::SetNextWindowSize(ImVec2(m_windowWidth, toolsWindowHeight)); ImGui::Begin("Tools"); - ImGui::PushStyleColor(ImGuiCol_Button, {0.45f, 0.0f, 0.2f, 0.8f}); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.45f, 0.0f, 0.2f, 0.8f}); + ImGui::PushDisabled(m_currentLevel == nullptr); + if (ImGui::Button("Play")) { m_parent.PlayLevel(); @@ -174,6 +177,8 @@ EditorGUI::Render() m_parent.SaveLevel(levelName); } } + ImGui::PopDisabled(); + ImGui::SameLine(); if (ImGui::Button("Load")) { diff --git a/engine/FileManager/FileManager.cpp b/engine/FileManager/FileManager.cpp index 331a2fa8..efbb3495 100644 --- a/engine/FileManager/FileManager.cpp +++ b/engine/FileManager/FileManager.cpp @@ -241,11 +241,15 @@ FileManager::FileDialog(const std::vector< std::pair< std::string, std::string > assert(output); std::string buffer(FILE_DIALOG_MAX_BUFFER, 0); - fgets(buffer.data(), FILE_DIALOG_MAX_BUFFER, output); - - // fgets includes \n character at the end, remove it - // buffer.back() = '\0'; - buffer[strcspn(buffer.c_str(), "\n")] = 0; + if (fgets(buffer.data(), FILE_DIALOG_MAX_BUFFER, output)) + { + // fgets includes \n character at the end, remove it + buffer[strcspn(buffer.c_str(), "\n")] = 0; + } + else + { + buffer = ""; + } pclose(output);