summaryrefslogtreecommitdiffhomepage
path: root/editor/inspect-draw.cpp
blob: f3b4982f3076bc24486e1349f565dd6c2c7d7cf5 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "app.hpp"
#include "compat/array-size.hpp"
#include "compat/format.hpp"
#include "inspect.hpp"
#include "floormat/main.hpp"
#include "src/world.hpp"
#include "src/object.hpp"
#include "src/scenery.hpp"
#include "src/critter.hpp"
#include "src/light.hpp"
#include "src/anim-atlas.hpp"
#include "imgui-raii.hpp"
#include "loader/loader.hpp"

namespace floormat {

using namespace floormat::imgui;

void app::draw_inspector()
{
    auto b = push_id("inspector");

    const auto dpi = M->dpi_scale();
    auto& w = M->world();

    for (auto i = (int)(inspectors.size()-1); i >= 0; i--)
    {
        auto [id, target] = inspectors[i];
        auto= w.find_object(id);
        if (!)
        {
            erase_inspector((unsigned)i);
            continue;
        }
        auto& e = *;

        char buf[256], buf2[32], buf3[128];
        ImGui::SetNextWindowSize({375*dpi[0], 0});
#if 0
        auto name = loader.strip_prefix(e.atlas->name());
        chunk_coords ch = e.coord.chunk();
        local_coords pos = e.coord.local();
auto z = e.coord.z();
        if (z == 0)
            snformat(buf, "{} ({}x{} -> {}x{})###inspector-{:08x}"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y, e.id);
        else
            snformat(buf, "{} ({}x{}:{} -> {}x{})###inspector-{:08x}"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y, e.id);
#else
        entity_inspector_name(buf2, sizeof buf2, e.id);
        entity_friendly_name(buf3, sizeof buf3, e);
        std::snprintf(buf, array_size(buf), "%s###%s", buf3, buf2);
#endif

        bool is_open = true;
        if (auto b2 = begin_window(buf, &is_open))
        {
            bool ret = entities::inspect_object_subtype(e);
            (void)ret;
        }
        if (!is_open)
            erase_inspector((unsigned)i);
    }
}

void app::entity_inspector_name(char* buf, size_t len, object_id id)
{
    constexpr auto min_len = sizeof "inspector-" + 8;
    fm_debug_assert(len >= min_len);
    auto result = fmt::format_to_n(buf, len, "inspector-{:08x}"_cf, id);
    fm_assert(result.size < len);
    buf[result.size] = '\0';
}

void app::entity_friendly_name(char* buf, size_t len, const object& obj)
{
    switch (obj.type())
    {
    case object_type::none:
    case object_type::COUNT:
        break;
    case object_type::hole:
        std::snprintf(buf, len, "%s", "hole");
        return;
    case object_type::critter: {
        const auto& c = static_cast<const critter&>(obj);
        std::snprintf(buf, len, "critter %s", c.name.data());
        return;
    }
    case object_type::light: {
        const auto& L = static_cast<const light&>(obj);
        const char* type = "(unknown?)";
        switch (L.falloff)
        {
        case light_falloff::COUNT: break;
        case light_falloff::constant: type = "constant"; break;
        case light_falloff::linear: type = "linear"; break;
        case light_falloff::quadratic: type = "quadratic"; break;
        }
        std::snprintf(buf, len, "light #%hhx%hhx%hhx%hhx %s:%.2f",
                      L.color.r(), L.color.g(), L.color.b(), L.color.a(),
                      type,
                      L.falloff == light_falloff::constant ? 0. : (double)L.max_distance);
        return;
    }
    case object_type::scenery: {
        const auto& sc = static_cast<const scenery&>(obj);
        switch (sc.scenery_type())
        {
        case scenery_type::none:
        case scenery_type::COUNT:
            break;
        case scenery_type::door:
            std::snprintf(buf, len, "door");
            return;
        case scenery_type::generic:
            std::snprintf(buf, len, "scenery %s", sc.atlas->name().data());
            return;
        }
        std::snprintf(buf, len, "(scenery?)");
        return;
    }
    }
    std::snprintf(buf, len, "(unknown?)");
}

} // namespace floormat