Skip to content

Commit

Permalink
[editor] moved default world selection window into EditorWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Oct 29, 2024
1 parent e7fbea1 commit 37a4de0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 90 deletions.
6 changes: 3 additions & 3 deletions editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ void Editor::Tick()
// engine
Spartan::Engine::Tick();

EditorWindow::Tick();

// editor
if (render_editor)
{
Expand All @@ -160,8 +158,10 @@ void Editor::Tick()
widget->Tick();
}


ImGui::End();

// various windows that don't belnog to a certain widget
EditorWindow::Tick();
}
}

Expand Down
85 changes: 85 additions & 0 deletions editor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "Settings.h"
#include "Widgets/Viewport.h"
#include "Input/Input.h"
#include "Game/Game.h"
//===============================

//= NAMESPACES =====
Expand Down Expand Up @@ -415,6 +416,84 @@ namespace
ImGui::End();
}
}

namespace default_worlds
{
static const char* worlds[] =
{
"1. Objects",
"2. Car",
"3. Doom",
"4. Minecraft",
"5. Living Room",
"6. Subway",
"7. Sponza - stress: low",
"8. Bistro - stress: medium",
"9. Forest - stress: high",
};

bool downloaded = false;
bool window_visible_download = !downloaded;
bool visible = downloaded;

void world_on_download_finished()
{
Spartan::ProgressTracker::SetLoadingStateGlobal(false);
visible = true;
}

void window()
{
if (window_visible_download)
{
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(300, 150), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Default worlds", &window_visible_download, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("No default worlds are present. Would you like to download them?");
ImGui::Separator();

if (ImGui::Button("Yes"))
{
Spartan::FileSystem::Command("python download_assets.py", world_on_download_finished, false);
Spartan::ProgressTracker::SetLoadingStateGlobal(true);
window_visible_download = false;
}
ImGui::SameLine();
if (ImGui::Button("No"))
{
window_visible_download = false;
visible = false;
}
}
ImGui::End();
}

if (visible)
{
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
if (ImGui::Begin("World selection", &visible, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Select the world you would like to load and click \"Ok\"");

// list
static int item_index = 0;
static int item_count = IM_ARRAYSIZE(worlds);
ImGui::PushItemWidth(500.0f * Spartan::Window::GetDpiScale());
ImGui::ListBox("##list_box", &item_index, worlds, item_count, item_count);
ImGui::PopItemWidth();

// button
if (ImGuiSp::button_centered_on_line("Ok"))
{
Spartan::Game::Load(static_cast<Spartan::DefaultWorld>(item_index));
visible = false;
}
}
ImGui::End();
}
}
}
}

void EditorWindow::Initialize(Editor* editor_in)
Expand All @@ -423,6 +502,10 @@ void EditorWindow::Initialize(Editor* editor_in)

// the sponsor window only shows up if the editor.ini file doesn't exist, which means that this is the first ever run
sponsor::visible = !Spartan::FileSystem::Exists(ImGui::GetIO().IniFilename);

default_worlds::downloaded = !Spartan::FileSystem::IsDirectoryEmpty(Spartan::ResourceCache::GetProjectDirectory());
default_worlds::window_visible_download = !default_worlds::downloaded;
default_worlds::visible = default_worlds::downloaded;
}

void EditorWindow::Tick()
Expand All @@ -443,6 +526,8 @@ void EditorWindow::Tick()
{
shortcuts::window();
}

default_worlds::window();
}

// shortcuts
Expand Down
89 changes: 2 additions & 87 deletions editor/Widgets/WorldViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,95 +55,12 @@ namespace
ImGuiSp::DragDropPayload g_payload;
bool popup_rename_entity = false;
Spartan::Entity* entity_copied = nullptr;

namespace default_worlds
{
static bool downloaded = false;
static bool window_visible_download = !downloaded;
static bool window_visible_list = downloaded;

void world_on_download_finished()
{
Spartan::ProgressTracker::SetLoadingStateGlobal(false);
window_visible_list = true;
}

void window_list(Editor* editor)
{
if (window_visible_download)
{
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(300, 150), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Default worlds", &window_visible_download, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("No default worlds are present. Would you like to download them?");
ImGui::Separator();

if (ImGui::Button("Yes"))
{
Spartan::FileSystem::Command("python download_assets.py", world_on_download_finished, false);
Spartan::ProgressTracker::SetLoadingStateGlobal(true);
window_visible_download = false;
}
ImGui::SameLine();
if (ImGui::Button("No"))
{
window_visible_download = false;
window_visible_list = false;
}
}
ImGui::End();
}

if (window_visible_list)
{
ImGui::SetNextWindowPos(editor->GetWidget<Viewport>()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
if (ImGui::Begin("World selection", &window_visible_list, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Select the world you would like to load and click \"Ok\"");

// list
static int item_index = 0;
{
static const char* items[] =
{
"1. Objects",
"2. Car",
"3. Doom",
"4. Minecraft",
"5. Living Room",
"6. Subway",
"7. Sponza - stress: low",
"8. Bistro - stress: medium",
"9. Forest - stress: high",
};
static int item_count = IM_ARRAYSIZE(items);

ImGui::PushItemWidth(500.0f * Spartan::Window::GetDpiScale());
ImGui::ListBox("##list_box", &item_index, items, item_count, item_count);
ImGui::PopItemWidth();
}

// button
if (ImGuiSp::button_centered_on_line("Ok"))
{
Spartan::Game::Load(static_cast<Spartan::DefaultWorld>(item_index));
window_visible_list = false;
}
}
ImGui::End();
}
}
}
}

WorldViewer::WorldViewer(Editor* editor) : Widget(editor)
{
m_title = "World";
m_flags |= ImGuiWindowFlags_HorizontalScrollbar;
default_worlds::downloaded = !Spartan::FileSystem::IsDirectoryEmpty(Spartan::ResourceCache::GetProjectDirectory());
default_worlds::window_visible_download = !default_worlds::downloaded;
default_worlds::window_visible_list = default_worlds::downloaded;
m_title = "World";
m_flags |= ImGuiWindowFlags_HorizontalScrollbar;
}

void WorldViewer::OnTickVisible()
Expand All @@ -167,8 +84,6 @@ void WorldViewer::OnTickVisible()
}
}
}

default_worlds::window_list(m_editor);
}

void WorldViewer::TreeShow()
Expand Down

0 comments on commit 37a4de0

Please sign in to comment.