summaryrefslogtreecommitdiff
path: root/src/port/ui
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-12-15 12:29:58 -0700
committerGitHub <noreply@github.com>2025-12-15 12:29:58 -0700
commiteb11374093b07bd968ccb955eecd06133db0ab74 (patch)
tree8e584cd21b9ea22403c903621d300d8223a62c86 /src/port/ui
parent2995361eb152a5c0c8add52c590e30ec916b81ec (diff)
Edit TrackInfo Properties (#594)
* Fix finishline for toads turnpike in extra * Fixed trash bin in extra * Refactor fov * Update scene.json * Allow setting fog * impl fog save & load * Fix modifying resourceName and rename editor namespace to trackeditor * small change
Diffstat (limited to 'src/port/ui')
-rw-r--r--src/port/ui/ContentBrowser.cpp2
-rw-r--r--src/port/ui/ContentBrowser.h2
-rw-r--r--src/port/ui/ImguiUI.cpp10
-rw-r--r--src/port/ui/Properties.cpp2
-rw-r--r--src/port/ui/Properties.h2
-rw-r--r--src/port/ui/SceneExplorer.cpp2
-rw-r--r--src/port/ui/SceneExplorer.h2
-rw-r--r--src/port/ui/Tools.cpp7
-rw-r--r--src/port/ui/Tools.h2
-rw-r--r--src/port/ui/TrackProperties.cpp113
-rw-r--r--src/port/ui/TrackProperties.h3
11 files changed, 122 insertions, 25 deletions
diff --git a/src/port/ui/ContentBrowser.cpp b/src/port/ui/ContentBrowser.cpp
index c6a3c2551..a5ef9baa3 100644
--- a/src/port/ui/ContentBrowser.cpp
+++ b/src/port/ui/ContentBrowser.cpp
@@ -29,7 +29,7 @@ extern "C" {
#include "collision.h"
}
-namespace Editor {
+namespace TrackEditor {
bool bIsTrainWindowOpen = false; // Global because member variables do not work in lambdas
ContentBrowserWindow::~ContentBrowserWindow() {
diff --git a/src/port/ui/ContentBrowser.h b/src/port/ui/ContentBrowser.h
index b259e0b78..5d4e4c338 100644
--- a/src/port/ui/ContentBrowser.h
+++ b/src/port/ui/ContentBrowser.h
@@ -4,7 +4,7 @@
#include "engine/tracks/Track.h"
#include "AllActors.h"
-namespace Editor {
+namespace TrackEditor {
class ContentBrowserWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp
index ddfde0781..7ee262cb4 100644
--- a/src/port/ui/ImguiUI.cpp
+++ b/src/port/ui/ImguiUI.cpp
@@ -69,21 +69,21 @@ void SetupGuiElements() {
SPDLOG_ERROR("Could not find input GfxDebuggerWindow");
}
- mToolsWindow = std::make_shared<Editor::ToolsWindow>("gEditorEnabled", "Tools", ImVec2(100, 100),
+ mToolsWindow = std::make_shared<TrackEditor::ToolsWindow>("gEditorEnabled", "Tools", ImVec2(100, 100),
(ImGuiWindowFlags_NoTitleBar));
gui->AddGuiWindow(mToolsWindow);
- mSceneExplorerWindow = std::make_shared<Editor::SceneExplorerWindow>("gEditorEnabled", "Scene Explorer");
+ mSceneExplorerWindow = std::make_shared<TrackEditor::SceneExplorerWindow>("gEditorEnabled", "Scene Explorer");
gui->AddGuiWindow(mSceneExplorerWindow);
- mPropertiesWindow = std::make_shared<Editor::PropertiesWindow>("gEditorEnabled", "Properties");
+ mPropertiesWindow = std::make_shared<TrackEditor::PropertiesWindow>("gEditorEnabled", "Properties");
gui->AddGuiWindow(mPropertiesWindow);
- mTrackPropertiesWindow = std::make_shared<Editor::TrackPropertiesWindow>("gEditorEnabled", "Track Properties");
+ mTrackPropertiesWindow = std::make_shared<TrackEditor::TrackPropertiesWindow>("gEditorEnabled", "Track Properties");
gui->AddGuiWindow(mTrackPropertiesWindow);
mContentBrowserWindow =
- std::make_shared<Editor::ContentBrowserWindow>("gEditorEnabled", "Content Browser");
+ std::make_shared<TrackEditor::ContentBrowserWindow>("gEditorEnabled", "Content Browser");
gui->AddGuiWindow(mContentBrowserWindow);
}
diff --git a/src/port/ui/Properties.cpp b/src/port/ui/Properties.cpp
index 216efa2c1..fc3eb2d1e 100644
--- a/src/port/ui/Properties.cpp
+++ b/src/port/ui/Properties.cpp
@@ -23,7 +23,7 @@ extern "C" {
#include "actors.h"
}
-namespace Editor {
+namespace TrackEditor {
PropertiesWindow::~PropertiesWindow() {
SPDLOG_TRACE("destruct properties window");
diff --git a/src/port/ui/Properties.h b/src/port/ui/Properties.h
index 64af1b4f8..2330a1f0c 100644
--- a/src/port/ui/Properties.h
+++ b/src/port/ui/Properties.h
@@ -3,7 +3,7 @@
#include <libultraship/libultraship.h>
#include "port/Game.h"
-namespace Editor {
+namespace TrackEditor {
class PropertiesWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
diff --git a/src/port/ui/SceneExplorer.cpp b/src/port/ui/SceneExplorer.cpp
index 11affa50e..a6526ca22 100644
--- a/src/port/ui/SceneExplorer.cpp
+++ b/src/port/ui/SceneExplorer.cpp
@@ -18,7 +18,7 @@ extern "C" {
#include "actors.h"
}
-namespace Editor {
+namespace TrackEditor {
SceneExplorerWindow::~SceneExplorerWindow() {
SPDLOG_TRACE("destruct scene explorer window");
diff --git a/src/port/ui/SceneExplorer.h b/src/port/ui/SceneExplorer.h
index f9e926148..69ee476e7 100644
--- a/src/port/ui/SceneExplorer.h
+++ b/src/port/ui/SceneExplorer.h
@@ -4,7 +4,7 @@
#include "port/Game.h"
-namespace Editor {
+namespace TrackEditor {
class SceneExplorerWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
diff --git a/src/port/ui/Tools.cpp b/src/port/ui/Tools.cpp
index 75dd3ac10..531a1c773 100644
--- a/src/port/ui/Tools.cpp
+++ b/src/port/ui/Tools.cpp
@@ -12,13 +12,14 @@
#include <defines.h>
#include "port/Game.h"
#include "engine/editor/SceneManager.h"
+#include "engine/TrackBrowser.h"
extern "C" {
#include "code_800029B0.h"
#include "code_80057C60.h"
}
-namespace Editor {
+namespace TrackEditor {
ToolsWindow::~ToolsWindow() {
SPDLOG_TRACE("destruct tools window");
@@ -37,6 +38,7 @@ namespace Editor {
if (ImGui::Button(ICON_FA_FLOPPY_O, ImVec2(50, 25))) {
if (gEditor.IsPaused()) {
SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
+ TrackBrowser::Instance->Refresh(gTrackRegistry);
} else {
printf("[Editor] Cannot save during simulation\n Please switch back to edit mode!\n\n");
}
@@ -140,7 +142,8 @@ namespace Editor {
ImGui::PushStyleColor(ImGuiCol_Button, defaultColor);
if (ImGui::Button(gEditor.IsPaused() ? ICON_FA_PLAY : ICON_FA_STOP, ImVec2(50, 25))) {
if (gEditor.IsPaused()) {
- SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
+ SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
+ TrackBrowser::Instance->Refresh(gTrackRegistry);
CVarSetInteger("gFreecam", false);
CM_SetFreeCamera(false);
} else {
diff --git a/src/port/ui/Tools.h b/src/port/ui/Tools.h
index 7ef3450a7..12bd58adc 100644
--- a/src/port/ui/Tools.h
+++ b/src/port/ui/Tools.h
@@ -2,7 +2,7 @@
#include <libultraship/libultraship.h>
-namespace Editor {
+namespace TrackEditor {
class ToolsWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
diff --git a/src/port/ui/TrackProperties.cpp b/src/port/ui/TrackProperties.cpp
index 3f95de411..d3ef44ad4 100644
--- a/src/port/ui/TrackProperties.cpp
+++ b/src/port/ui/TrackProperties.cpp
@@ -14,6 +14,9 @@
#include "port/Game.h"
#include "engine/cameras/TourCamera.h"
+#include "engine/TrackBrowser.h"
+#include "engine/editor/SceneManager.h"
+#include "engine/Registry.h"
extern "C" {
#include "code_800029B0.h"
@@ -23,26 +26,23 @@ extern "C" {
#include "render_objects.h"
}
-namespace Editor {
+namespace TrackEditor {
TrackPropertiesWindow::~TrackPropertiesWindow() {
SPDLOG_TRACE("destruct track properties window");
}
void TrackPropertiesWindow::DrawElement() {
- static char idBuffer[256] = "mk:mario_raceway";
- static char nameBuffer[256] = "Mario Raceway";
- static char debugNameBuffer[256] = "m circuit";
- static char lengthBuffer[256] = "567m";
-
if (nullptr == GetWorld()->GetTrack()) {
return;
}
- ImGui::InputText("ID", idBuffer, IM_ARRAYSIZE(idBuffer));
- ImGui::InputText("Name", GetWorld()->GetTrack()->Props.Name, IM_ARRAYSIZE(nameBuffer));
- ImGui::InputText("Debug Name", GetWorld()->GetTrack()->Props.DebugName, IM_ARRAYSIZE(debugNameBuffer));
- ImGui::InputText("Track Length", GetWorld()->GetTrack()->Props.TrackLength, IM_ARRAYSIZE(lengthBuffer));
+ if (ImGui::Button("Edit TrackInfo")) {
+ ImGui::OpenPopup("Edit TrackInfo");
+ }
+
+ DrawResourceNameEdit();
+
ImGui::InputFloat("Water Level", &GetWorld()->GetTrack()->Props.WaterLevel);
if (ImGui::CollapsingHeader("Camera")) {
@@ -175,6 +175,99 @@ namespace Editor {
TrackPropertiesWindow::DrawTourCamera();
}
+ void TrackPropertiesWindow::DrawResourceNameEdit() {
+ Track* track = GetWorld()->GetTrack();
+ if (!track) {
+ return;
+ }
+
+ static char resourceNameBuffer[128] = {};
+ static char nameBuffer[128] = "blank_track";
+ static char debugNameBuffer[128] = "blanktrack";
+ static char lengthBuffer[128] = "100m";
+ static bool initialized = false;
+ static std::string oldResourceName = track->ResourceName;
+
+ // Auto-sizing fills the height of the screen for a single frame.
+ // Because there's no content in the window in the first frame.
+ // This forces the window size to prevent that
+ ImGui::SetNextWindowSize(ImVec2(400, 275), ImGuiCond_Always);
+ if (ImGui::BeginPopupModal("Edit TrackInfo", nullptr,
+ ImGuiWindowFlags_AlwaysAutoResize)) {
+
+ // Initialize once per popup open
+ if (!initialized) {
+ strncpy(resourceNameBuffer, track->ResourceName.c_str(), sizeof(resourceNameBuffer));
+ resourceNameBuffer[sizeof(resourceNameBuffer) - 1] = '\0';
+ oldResourceName = track->ResourceName;
+ initialized = true;
+ }
+
+ ImGui::TextWrapped(
+ "Changing these fields will:\n"
+ "- Save the current track\n"
+ "- Reload the track\n"
+ "- Update the registry\n\n"
+ );
+
+ gEditor.Pause();
+
+ ImGui::Spacing();
+ ImGui::Separator();
+ ImGui::Spacing();
+
+ ImGui::InputText("ResourceName", resourceNameBuffer, IM_ARRAYSIZE(resourceNameBuffer));
+ ImGui::InputText("Name", GetWorld()->GetTrack()->Props.Name, IM_ARRAYSIZE(nameBuffer));
+ ImGui::InputText("Debug Name", GetWorld()->GetTrack()->Props.DebugName, IM_ARRAYSIZE(debugNameBuffer));
+ ImGui::InputText("Track Length", GetWorld()->GetTrack()->Props.TrackLength, IM_ARRAYSIZE(lengthBuffer));
+
+ ImGui::Spacing();
+ ImGui::Separator();
+ ImGui::Spacing();
+
+ bool cancel = ImGui::Button("Cancel", ImVec2(120, 0));
+
+ ImGui::SameLine();
+
+ bool confirm = ImGui::Button("Confirm", ImVec2(120, 0));
+
+ if (confirm) {
+ if (oldResourceName != resourceNameBuffer) {
+ track->ResourceName = resourceNameBuffer;
+ const TrackInfo* oldInfo = gTrackRegistry.GetInfo(oldResourceName);
+ TrackInfo info;
+ info.ResourceName = track->ResourceName;
+ info.Name = track->Props.Name;
+ info.DebugName = track->Props.DebugName;
+ info.Path = oldInfo->Path;
+
+ TrackEditor::SaveLevel(track, static_cast<const TrackInfo*>(&info));
+ auto archive = track->Archive;
+ gTrackRegistry.Remove(oldResourceName);
+ gTrackRegistry.Add(info, [info, archive]() {
+ auto track = std::make_unique<Track>();
+ track->Archive = archive;
+ track->ResourceName = info.ResourceName;
+ GetWorld()->SetCurrentTrack(std::move(track));
+ });
+ TrackBrowser::Instance->Refresh(gTrackRegistry);
+ gGotoMode = RACING;
+
+ }
+ initialized = false;
+
+ ImGui::CloseCurrentPopup();
+ }
+
+ if (cancel) {
+ initialized = false;
+ ImGui::CloseCurrentPopup();
+ }
+
+ ImGui::EndPopup();
+ }
+ }
+
void TrackPropertiesWindow::DrawMusic() {
const char* items[] = {
"None", "Title Screen", "Main Menu", "Wario Stadium", "Moo Moo Farm",
diff --git a/src/port/ui/TrackProperties.h b/src/port/ui/TrackProperties.h
index a3c151b32..d08560bf9 100644
--- a/src/port/ui/TrackProperties.h
+++ b/src/port/ui/TrackProperties.h
@@ -6,7 +6,7 @@ extern "C" {
#include "sounds.h"
}
-namespace Editor {
+namespace TrackEditor {
class TrackPropertiesWindow : public Ship::GuiWindow {
public:
using Ship::GuiWindow::GuiWindow;
@@ -15,6 +15,7 @@ public:
protected:
void InitElement() override {};
void DrawElement() override;
+ void DrawResourceNameEdit();
void DrawMusic();
void DrawFog();
void DrawLight();