Setup imgui layout for editor

This commit is contained in:
MegaMech
2025-03-07 14:52:36 -07:00
parent 8f1458902a
commit 55b905f377
12 changed files with 179 additions and 110 deletions
+4 -2
View File
@@ -23,10 +23,12 @@ FVector ScreenRayTrace() {
Camera* camera = &cameras[0];
Ship::Coords mouse = wnd->GetMousePos();
mouse.x -= gfx_current_game_window_viewport.x;
mouse.y -= gfx_current_game_window_viewport.y;
// Get screen dimensions
uint32_t width = wnd->GetWidth();
uint32_t height = wnd->GetHeight();
uint32_t width = OTRGetGameRenderWidth();
uint32_t height = OTRGetGameRenderHeight();
// Convert mouse to NDS screen coordinates
float x = (2.0f * mouse.x) / width - 1.0f; // Normalized X: -1 to 1
+5
View File
@@ -21,6 +21,7 @@ extern "C" {
#include "math_util_2.h"
#include "camera.h"
#include "courses/harbour/ship_model.h"
#include "src/racing/collision.h"
}
Gizmo::Gizmo() {
@@ -93,6 +94,10 @@ void Gizmo::Translate() {
break;
}
if (CVarGetInteger("gEditorSnapToGround", false) == true) {
_selected->Pos->y = spawn_actor_on_surface(_selected->Pos->x, 2000.0f, _selected->Pos->z);
}
Pos = FVector(
_selected->Pos->x,
_selected->Pos->y,
+26
View File
@@ -0,0 +1,26 @@
#include "ContentBrowser.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <map>
#include <libultraship/libultraship.h>
#include <spdlog/fmt/fmt.h>
#include "spdlog/formatter.h"
#include <common_structs.h>
#include <defines.h>
namespace Editor {
ContentBrowserWindow::~ContentBrowserWindow() {
SPDLOG_TRACE("destruct editor window");
}
void ContentBrowserWindow::DrawElement() {
ImGui::Text("This is your Content browser Lab editor window!");
if (ImGui::Button("Click Me")) {
// Handle button click (example)
}
}
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <libultraship/libultraship.h>
namespace Editor {
class ContentBrowserWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
~ContentBrowserWindow();
protected:
void InitElement() override {};
void DrawElement() override;
void UpdateElement() override {};
};
}
-106
View File
@@ -1,106 +0,0 @@
#include "EditorWindow.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <map>
#include <libultraship/libultraship.h>
#include <spdlog/fmt/fmt.h>
#include "spdlog/formatter.h"
#include <common_structs.h>
#include <defines.h>
namespace GameUI {
extern std::shared_ptr<PortMenu> mPortMenu;
void RegisterEditorWidgets() {
mPortMenu->AddSidebarEntry("Enhancements", "HM64 Lab", 4);
WidgetPath path = { "Enhancements", "HM64 Lab", SECTION_COLUMN_1 };
mPortMenu->AddWidget(path, "Enable HM64 Labs", WIDGET_CVAR_CHECKBOX)
.CVar("gEditor")
.Options(UIWidgets::CheckboxOptions({{ .tooltip = "Edit the universe!"}}));
}
static RegisterMenuInitFunc initFunc(RegisterEditorWidgets);
} // namespace GameUI
namespace EditorWin {
EditorWindow::~EditorWindow() {
SPDLOG_TRACE("destruct editor window");
}
void EditorWindow::DrawElement() {
auto viewport = ImGui::GetMainViewport();
ImGuiID mainDock = ImGui::GetID("main_dock");
EditorWindow::SetupLayout();
EditorWindow::DrawContentBrowser(viewport, mainDock);
EditorWindow::DrawSceneExplorer(viewport, mainDock);
}
void EditorWindow::SetupLayout() {
}
void EditorWindow::DrawContentBrowser(ImGuiViewport* viewport, ImGuiID mainDock) {
ImGuiID bottomId = 0;
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) {
if (!ImGui::DockBuilderGetNode(mainDock)) {
bottomId = ImGui::DockBuilderSplitNode(mainDock, ImGuiDir_Down, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x * 0.2f, viewport->Size.y));
ImGui::DockBuilderDockWindow("Content Browser", bottomId);
ImGui::DockBuilderFinish(mainDock);
}
}
if (ImGui::Begin("Content Browser", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove)) {
ImGui::Text("This is your Content browser Lab editor window!");
if (ImGui::Button("Click Me")) {
// Handle button click (example)
}
ImGui::End();
}
}
void EditorWindow::DrawSceneExplorer(ImGuiViewport* viewport, ImGuiID mainDock) {
ImGuiID rightId = 0;
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) {
if (!ImGui::DockBuilderGetNode(mainDock)) {
rightId = ImGui::DockBuilderSplitNode(mainDock, ImGuiDir_Right, 0.25f, nullptr, nullptr);
ImGui::DockBuilderSetNodeSize(rightId, ImVec2(viewport->Size.x * 0.2f, viewport->Size.y));
ImGui::DockBuilderDockWindow("HM64 Lab", rightId);
ImGui::DockBuilderFinish(mainDock);
}
}
if (ImGui::Begin("HM64 Lab", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove)) {
ImGui::Text("This is your HM64 Lab editor window!");
if (ImGui::Button("Click Me")) {
// Handle button click (example)
}
ImGui::End();
}
}
}
+18
View File
@@ -4,6 +4,9 @@
#include "GameInfoWindow.h"
#include "MultiplayerWindow.h"
#include "FreecamWindow.h"
#include "Tools.h"
#include "SceneExplorer.h"
#include "ContentBrowser.h"
#include <spdlog/spdlog.h>
#include <imgui.h>
@@ -32,6 +35,9 @@ std::shared_ptr<Ship::GuiWindow> mInputEditorWindow;
std::shared_ptr<Ship::GuiWindow> mGfxDebuggerWindow;
std::shared_ptr<Ship::GuiWindow> mGameInfoWindow;
std::shared_ptr<Ship::GuiWindow> mMultiplayerWindow;
std::shared_ptr<Ship::GuiWindow> mToolsWindow;
std::shared_ptr<Ship::GuiWindow> mSceneExplorerWindow;
std::shared_ptr<Ship::GuiWindow> mContentBrowserWindow;
void SetupGuiElements() {
auto gui = Ship::Context::GetInstance()->GetWindow()->GetGui();
@@ -73,6 +79,15 @@ void SetupGuiElements() {
SPDLOG_ERROR("Could not find input GfxDebuggerWindow");
}
mToolsWindow = std::make_shared<Editor::ToolsWindow>("gEditorEnabled", true, "Tools", ImVec2(100, 100), (ImGuiWindowFlags_NoTitleBar));
gui->AddGuiWindow(mToolsWindow);
mSceneExplorerWindow = std::make_shared<Editor::SceneExplorerWindow>("gEditorEnabled", "Scene Explorer");
gui->AddGuiWindow(mSceneExplorerWindow);
mContentBrowserWindow = std::make_shared<Editor::ContentBrowserWindow>("gEditorEnabled", "Content Browser");
gui->AddGuiWindow(mContentBrowserWindow);
mGameInfoWindow = std::make_shared<GameInfo::GameInfoWindow>("gGameInfoEnabled", "Game Info");
gui->AddGuiWindow(mGameInfoWindow);
}
@@ -82,6 +97,9 @@ void Destroy() {
mConsoleWindow = nullptr;
mStatsWindow = nullptr;
mInputEditorWindow = nullptr;
mToolsWindow = nullptr;
mSceneExplorerWindow = nullptr;
mContentBrowserWindow = nullptr;
}
std::string GetWindowButtonText(const char* text, bool menuOpen) {
+2
View File
@@ -7,6 +7,8 @@
typedef enum {
DISABLE_FOR_FREE_CAM_ON,
DISABLE_FOR_FREE_CAM_OFF,
DISABLE_FOR_EDITOR_ON,
DISABLE_FOR_EDITOR_OFF,
DISABLE_FOR_DEBUG_MODE_OFF,
DISABLE_FOR_NO_VSYNC,
DISABLE_FOR_NO_WINDOWED_FULLSCREEN,
+17 -2
View File
@@ -360,6 +360,17 @@ void PortMenu::AddEnhancements() {
.CVar("gMinHeight")
.Options(FloatSliderOptions().Min(-50.0f).Max(50.0f).DefaultValue(0.0f)
.Tooltip("When Disable Wall Collision are enable what is the minimal height you can get."));
path = { "Enhancements", "HM64 Lab", SECTION_COLUMN_1 };
AddSidebarEntry("Enhancements", "HM64 Lab", 4);
AddWidget(path, "Enable HM64 Labs", WIDGET_CVAR_CHECKBOX)
.CVar("gEditorEnabled")
.Callback([](WidgetInfo& info) {
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Tools")->ToggleVisibility();
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Scene Explorer")->ToggleVisibility();
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Content Browser")->ToggleVisibility();
})
.Options(UIWidgets::CheckboxOptions({{ .tooltip = "Edit the universe!"}}));
}
void PortMenu::AddDevTools() {
@@ -432,9 +443,13 @@ void PortMenu::InitElement() {
disabledMap = {
{ DISABLE_FOR_FREE_CAM_ON,
{ [](disabledInfo& info) -> bool { return CVarGetInteger("gFreecam", 0); }, "Free Cam is Enabled" } },
{ [](disabledInfo& info) -> bool { return CVarGetInteger("gFreecam", 0); }, "Freecam is Enabled" } },
{ DISABLE_FOR_FREE_CAM_OFF,
{ [](disabledInfo& info) -> bool { return !CVarGetInteger("gFreecam", 0); }, "Free Cam is Disabled" } },
{ [](disabledInfo& info) -> bool { return !CVarGetInteger("gFreecam", 0); }, "Freecam is Disabled" } },
{ DISABLE_FOR_EDITOR_ON,
{ [](disabledInfo& info) -> bool { return CVarGetInteger("gEditorEnabled", 0); }, "Editor is Enabled" } },
{ DISABLE_FOR_EDITOR_OFF,
{ [](disabledInfo& info) -> bool { return !CVarGetInteger("gEditorEnabled", 0); }, "Editor is Disabled" } },
{ DISABLE_FOR_DEBUG_MODE_OFF,
{ [](disabledInfo& info) -> bool { return !CVarGetInteger("gEnableDebugMode", 0); },
"Debug Mode is Disabled" } },
+27
View File
@@ -0,0 +1,27 @@
#include "SceneExplorer.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <map>
#include <libultraship/libultraship.h>
#include <spdlog/fmt/fmt.h>
#include "spdlog/formatter.h"
#include <common_structs.h>
#include <defines.h>
namespace Editor {
SceneExplorerWindow::~SceneExplorerWindow() {
SPDLOG_TRACE("destruct editor window");
}
void SceneExplorerWindow::DrawElement() {
ImGui::Text("This is your Scene Explorer window!");
if (ImGui::Button("Click Me")) {
// Handle button click (example)
}
ImGui::End();
}
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <libultraship/libultraship.h>
namespace Editor {
class SceneExplorerWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
~SceneExplorerWindow();
protected:
void InitElement() override {};
void DrawElement() override;
void UpdateElement() override {};
};
}
+34
View File
@@ -0,0 +1,34 @@
#include "Tools.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <map>
#include <libultraship/libultraship.h>
#include <spdlog/fmt/fmt.h>
#include "spdlog/formatter.h"
#include <common_structs.h>
#include <defines.h>
namespace Editor {
ToolsWindow::~ToolsWindow() {
SPDLOG_TRACE("destruct editor window");
}
void ToolsWindow::InitElement() {
}
void ToolsWindow::DrawElement() {
static bool toggleState = false;
ImGui::PushStyleColor(ImGuiCol_Button, toggleState ? ImVec4(0.2f, 0.8f, 0.2f, 1.0f) : ImVec4(0.8f, 0.2f, 0.2f, 1.0f));
if (ImGui::Button(toggleState ? "v" : "v", ImVec2(50, 25))) {
toggleState = !toggleState;
CVarSetInteger("gEditorSnapToGround", toggleState);
}
ImGui::PopStyleColor();
}
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <libultraship/libultraship.h>
namespace Editor {
class ToolsWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
~ToolsWindow();
protected:
void InitElement() override;
void DrawElement() override;
void UpdateElement() override {};
};
}