aboutsummaryrefslogtreecommitdiff
path: root/source/EditorCorePrivate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/EditorCorePrivate.cpp')
-rw-r--r--source/EditorCorePrivate.cpp169
1 files changed, 134 insertions, 35 deletions
diff --git a/source/EditorCorePrivate.cpp b/source/EditorCorePrivate.cpp
index 4b578dd..9fd6087 100644
--- a/source/EditorCorePrivate.cpp
+++ b/source/EditorCorePrivate.cpp
@@ -8,7 +8,6 @@
#include "EditorNotification.hpp"
#include "EditorUtils.hpp"
#include "GameObject.hpp"
-#include "Level.hpp"
#include "Macros.hpp"
#include "Mesh.hpp"
#include "Player.hpp"
@@ -37,6 +36,54 @@
using namespace std::literals;
+namespace ProjectBrussel_UNITY_ID {
+// TODO handle internal state internally and move this to EditorUtils.hpp
+enum RenamableSelectableAction {
+ RSA_None,
+ RSA_Selected,
+ RSA_RenameCommitted,
+ RSA_RenameCancelled,
+};
+RenamableSelectableAction RenamableSelectable(const char* displayName, bool selected, bool& renaming, std::string& renamingScratchBuffer) //
+{
+ RenamableSelectableAction result = RSA_None;
+
+ ImGuiSelectableFlags flags = 0;
+ // When renaming, disable all other entries that is not the one being renamed
+ if (renaming && !selected) {
+ flags |= ImGuiSelectableFlags_Disabled;
+ }
+
+ if (renaming && selected) {
+ // State: being renamed
+
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 0, 0 });
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
+ ImGui::SetKeyboardFocusHere();
+ if (ImGui::InputText("##Rename", &renamingScratchBuffer, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) {
+ // Confirm
+ renaming = false;
+ result = RSA_RenameCommitted;
+ }
+ ImGui::PopStyleVar(2);
+
+ if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
+ // Cancel
+ renaming = false;
+ result = RSA_RenameCancelled;
+ }
+ } else {
+ // State: normal
+
+ if (ImGui::Selectable(displayName, selected, flags)) {
+ result = RSA_Selected;
+ }
+ }
+
+ return result;
+}
+} // namespace ProjectBrussel_UNITY_ID
+
void EditorInspector::SelectTarget(TargetType type, void* object) {
selectedItt = type;
selectedItPtr = object;
@@ -52,6 +99,8 @@ EditorContentBrowser::~EditorContentBrowser() {
}
void EditorContentBrowser::Show(bool* open) {
+ using namespace ProjectBrussel_UNITY_ID;
+
ImGuiWindowFlags windowFlags;
if (mDocked) {
// Center window horizontally, align bottom vertically
@@ -74,11 +123,16 @@ void EditorContentBrowser::Show(bool* open) {
if (ImGui::Selectable("Ires", mPane == P_Ires)) {
mPane = P_Ires;
}
+ if (ImGui::Selectable("Levels", mPane == P_Level)) {
+ mPane = P_Level;
+ }
}
ImGui::EndChild();
ImGui::SameLine(0.0f, kPadding + kSplitterThickness + kPadding);
ImGui::BeginChild("RightPane"); // Fill remaining space
+ auto origItt = mInspector->selectedItt;
+ auto origItPtr = mInspector->selectedItPtr;
switch (mPane) {
case P_Settings: {
ImGui::Checkbox("Docked", &mDocked);
@@ -86,9 +140,7 @@ void EditorContentBrowser::Show(bool* open) {
} break;
case P_Ires: {
- auto itt = mInspector->selectedItt;
- auto itPtr = mInspector->selectedItPtr;
- bool isIttIres = itt == EditorInspector::ITT_Ires;
+ bool isIttIres = origItt == EditorInspector::ITT_Ires;
if (ImGui::Button("New")) {
ImGui::OpenPopup("New Ires");
@@ -116,13 +168,13 @@ void EditorContentBrowser::Show(bool* open) {
ImGui::SameLine();
if (ImGui::Button("Save", !isIttIres)) {
- auto ires = static_cast<IresObject*>(itPtr);
+ auto ires = static_cast<IresObject*>(origItPtr);
IresManager::instance->Save(ires);
}
ImGui::SameLine();
if (ImGui::Button("Reload", !isIttIres)) {
- auto ires = static_cast<IresObject*>(itPtr);
+ auto ires = static_cast<IresObject*>(origItPtr);
IresManager::instance->Reload(ires);
}
@@ -130,7 +182,7 @@ void EditorContentBrowser::Show(bool* open) {
if (ImGui::Button("Rename", !isIttIres) ||
(isIttIres && ImGui::IsKeyPressed(ImGuiKey_F2, false)))
{
- auto ires = static_cast<IresObject*>(itPtr);
+ auto ires = static_cast<IresObject*>(origItPtr);
mInspector->renaming = true;
mInspector->renamingScratchBuffer = ires->GetName();
}
@@ -144,7 +196,7 @@ void EditorContentBrowser::Show(bool* open) {
bool openedDummy = true;
if (ImGui::BeginPopupModal("Delete Ires", &openedDummy, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize)) {
if (ImGui::Button("Confirm")) {
- auto ires = static_cast<IresObject*>(itPtr);
+ auto ires = static_cast<IresObject*>(origItPtr);
IresManager::instance->Delete(ires);
}
ImGui::SameLine();
@@ -159,37 +211,22 @@ void EditorContentBrowser::Show(bool* open) {
auto ires = it->second.Get();
auto& name = ires->GetName();
- bool selected = itPtr == ires;
-
- ImGuiSelectableFlags flags = 0;
- // When renaming, disable all other entries
- if (mInspector->renaming && !selected) {
- flags |= ImGuiSelectableFlags_Disabled;
- }
+ bool selected = origItPtr == ires;
- if (mInspector->renaming && selected) {
- // State: being renamed
+ switch (RenamableSelectable(name.c_str(), selected, mInspector->renaming, mInspector->renamingScratchBuffer)) {
+ case RSA_Selected: {
+ mInspector->SelectTarget(EditorInspector::ITT_Ires, ires);
+ } break;
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 0, 0 });
- ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
- ImGui::SetKeyboardFocusHere();
- if (ImGui::InputText("##Rename", &mInspector->renamingScratchBuffer, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) {
- // Confirm
+ case RSA_RenameCommitted: {
ires->SetName(std::move(mInspector->renamingScratchBuffer));
- mInspector->renaming = false;
- }
- ImGui::PopStyleVar(2);
+ } break;
- if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
- // Cancel
- mInspector->renaming = false;
- }
- } else {
- // State: normal
-
- if (ImGui::Selectable(name.c_str(), selected, flags)) {
- mInspector->SelectTarget(EditorInspector::ITT_Ires, ires);
- }
+ // Do nothing
+ case RSA_RenameCancelled:
+ case RSA_None: break;
+ }
+ if (!mInspector->renaming) {
if (ImGui::BeginDragDropSource()) {
auto kindName = IresObject::ToString(ires->GetKind());
// Reason: intentionally using pointer as payload
@@ -200,6 +237,53 @@ void EditorContentBrowser::Show(bool* open) {
}
}
} break;
+
+ case P_Level: {
+ bool isIttLevel = origItt == EditorInspector::ITT_Level;
+
+ if (ImGui::Button("New")) {
+ auto uid = Uid::Create();
+ auto& ldObj = LevelManager::instance->AddLevel(uid);
+ mInspector->SelectTarget(EditorInspector::ITT_Level, &ldObj);
+ mInspector->renaming = true;
+ mInspector->renamingScratchBuffer = ldObj.name;
+ }
+
+ auto& objects = LevelManager::instance->mObjByUid;
+ for (auto it = objects.begin(); it != objects.end(); ++it) {
+ auto& uid = it->first;
+ auto& ldObj = it->second;
+ auto* level = ldObj.level.Get();
+ bool selected = origItPtr == &ldObj;
+ const char* displayName = ldObj.name.c_str();
+ if (strcmp(displayName, "") == 0) {
+ displayName = "<unnamed level>";
+ }
+
+ switch (RenamableSelectable(displayName, selected, mInspector->renaming, mInspector->renamingScratchBuffer)) {
+ case RSA_Selected: {
+ mInspector->SelectTarget(EditorInspector::ITT_Level, &ldObj);
+ } break;
+
+ case RSA_RenameCommitted: {
+ ldObj.name = std::move(mInspector->renamingScratchBuffer);
+ } break;
+
+ // Do nothing
+ case RSA_RenameCancelled:
+ case RSA_None: break;
+ }
+ if (!mInspector->renaming) {
+ if (ImGui::BeginDragDropSource()) {
+ // Reason: intentionally using pointer as payload
+ ImGui::SetDragDropPayload(BRUSSEL_TAG_Level, &ldObj, sizeof(ldObj)); // NOLINT(bugprone-sizeof-expression)
+ ImGui::Text(BRUSSEL_Uid_FORMAT_STR, BRUSSEL_Uid_FORMAT_EXPAND(uid));
+ ImGui::TextUnformatted(ldObj.name.c_str());
+ ImGui::EndDragDropSource();
+ }
+ }
+ }
+ } break;
}
ImGui::EndChild();
@@ -504,6 +588,11 @@ void EditorInstance::Show() {
ShowInspector(ires);
} break;
+ case EditorInspector::ITT_Level: {
+ auto ldObj = static_cast<LevelManager::LoadableObject*>(mEdInspector.selectedItPtr);
+ ShowInspector(ldObj);
+ } break;
+
case EditorInspector::ITT_None: break;
}
ImGui::End();
@@ -683,6 +772,16 @@ void EditorInstance::ShowInspector(IresObject* ires) {
ires->ShowEditor(*this);
}
+void EditorInstance::ShowInspector(LevelManager::LoadableObject* ldObj) {
+ using namespace Tags;
+ using namespace ProjectBrussel_UNITY_ID;
+
+ ImGui::InputText("Name", &ldObj->name);
+ ImGui::InputTextMultiline("Desciption", &ldObj->description);
+
+ // TODO level object explorer
+}
+
void EditorInstance::ShowInspector(GameObject* object) {
using namespace Tags;
using namespace ProjectBrussel_UNITY_ID;