summaryrefslogtreecommitdiff
path: root/src/port/ui/SceneExplorer.cpp
blob: 68c670b97847d37b9ae047f9c79ab70c50c6dc12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "SceneExplorer.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "ship/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>

#include "engine/editor/Editor.h"
#include "port/Game.h"

extern "C" {
#include "racing/actors.h"
}

namespace TrackEditor {

    SceneExplorerWindow::~SceneExplorerWindow() {
        SPDLOG_TRACE("destruct scene explorer window");
    }

    void SceneExplorerWindow::DrawElement() {
        ImGui::Text("Scene");

        size_t id = 0; // id for now because we don't have unique names atm

        for (const auto& actor : GetWorld()->Actors) {
            std::string name;
            if (nullptr != actor->Name && actor->Name[0] != '\0') {
                name = std::string(actor->Name);
            } else {
                if (!actor->IsMod()) {
                    name = std::string(get_actor_display_name(actor->Type));
                } else {
                    name = "Unk Actor";
                }
            }

            // Ensure unique label using index
            std::string label = fmt::format("{}##{}", name, id);

            if (ImGui::Button(label.c_str())) {
                gEditor.SelectObjectFromSceneExplorer(actor.get());
            }

            id += 1;
        }

        for (const auto& object : GetWorld()->Objects) {
            std::string name;
            if (nullptr != object->Name && object->Name[0] != '\0') {
                name = std::string(object->Name);
            } else {
                name = "Unk Object";
            }

            // Ensure unique label using index
            std::string label = fmt::format("{}##{}", name, id);

            if (ImGui::Button(label.c_str())) {
                gEditor.SelectObjectFromSceneExplorer(object.get());
            }
            id += 1;
        }

        for (auto& object : gEditor.eGameObjects) {
            std::string name;
            if (nullptr != object->Name && object->Name[0] != '\0') {
                name = std::string(object->Name);
            } else {
                name = "Unk Editor Obj";
            }

            // Ensure unique label using index
            std::string label = fmt::format("{}##{}", name, id);

            if (ImGui::Button(label.c_str())) {
                gEditor.SelectObjectFromSceneExplorer(object.get());
            }
            id += 1;
        }
    }
}