summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-23 17:22:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-23 17:22:32 +0100
commitecacc4e197eb8da6c311dad6e37330bcbbfef86e (patch)
tree4e9d6f70b93d2e53aa948eac6cd0aceff11f1fc5 /editor
parent25e36ab269096f11ebb2a1c9f6cc3ab93f830b44 (diff)
wip
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp1
-rw-r--r--editor/imgui.cpp19
-rw-r--r--editor/inspect-types.cpp46
-rw-r--r--editor/inspect.cpp22
-rw-r--r--editor/inspect.hpp8
5 files changed, 84 insertions, 12 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index 9385c2a9..f6a2e842 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -94,6 +94,7 @@ private:
void draw_collision_boxes();
void draw_editor_pane(float main_menu_height);
+ void draw_inspector();
void draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr<tile_atlas>& atlas);
void draw_editor_scenery_pane(scenery_editor& ed);
void set_cursor_from_imgui();
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 69037861..c26e9987 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -2,6 +2,9 @@
#include "floormat/main.hpp"
#include "compat/format.hpp"
#include "imgui-raii.hpp"
+#include "world.hpp"
+#include "scenery.hpp"
+#include "inspect.hpp"
#include <Magnum/Math/Color.h>
namespace floormat {
@@ -109,6 +112,7 @@ void app::draw_ui()
draw_editor_pane(main_menu_height);
draw_fps();
draw_tile_under_cursor();
+ draw_inspector();
ImGui::EndFrame();
}
@@ -144,6 +148,21 @@ void app::draw_tile_under_cursor()
{window_size[0]*.5f - size.x/2, 3*dpi[1]}, (unsigned)-1, buf);
}
+void app::draw_inspector()
+{
+ auto& w = M->world();
+ if (cursor.tile)
+ {
+ auto [c, t] = w[*cursor.tile];
+ if (auto s = t.scenery())
+ {
+ ImGui::SetNextWindowSize({400, 0});
+ auto b = begin_window("inspector"_s);
+ entities::inspect_type(s);
+ }
+ }
+}
+
void app::draw_editor_pane(float main_menu_height)
{
auto* ed = _editor.current_tile_editor();
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
new file mode 100644
index 00000000..27d61f97
--- /dev/null
+++ b/editor/inspect-types.cpp
@@ -0,0 +1,46 @@
+#include "entity/metadata.hpp"
+#include "entity/accessor.hpp"
+#include "src/scenery.hpp"
+#include "src/anim-atlas.hpp"
+#include "src/tile-defs.hpp"
+#include "entity/types.hpp"
+#include "inspect.hpp"
+
+namespace floormat::entities {
+
+template<> struct entity_accessors<scenery_ref> {
+ static constexpr auto accessors()
+ {
+ using entity = Entity<scenery_ref>;
+ using frame_t = scenery::frame_t;
+ constexpr auto tuple = std::make_tuple(
+ entity::type<scenery::frame_t>::field{"frame"_s,
+ [](const scenery_ref& x) { return x.frame.frame; },
+ [](scenery_ref& x, frame_t value) { x.frame.frame = value; },
+ [](const scenery_ref& x) { return constraints::range<frame_t>{0, !x.atlas ? frame_t(0) : frame_t(x.atlas->info().nframes)}; }
+ },
+ entity::type<Vector2b>::field{"offset"_s,
+ [](const scenery_ref& x) { return x.frame.offset; },
+ [](scenery_ref& x, Vector2b value) { x.frame.offset = value; },
+ constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)})
+ },
+ // todo pass_mode enum
+ entity::type<bool>::field{"interactive"_s,
+ [](const scenery_ref& x) { return x.frame.interactive; },
+ [](scenery_ref& x, bool value) { x.frame.interactive = value; }
+ }
+ );
+ return tuple;
+ }
+};
+
+template<>
+void inspect_type<scenery_ref>(scenery_ref& x)
+{
+ visit_tuple([&](const auto& field) {
+ using type = typename std::decay_t<decltype(field)>::FieldType;
+ inspect_field<type>(&x, field.erased());
+ }, entity_metadata<scenery_ref>::accessors);
+}
+
+} // namespace floormat::entities
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index 48e4c708..ef06671a 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -11,11 +11,11 @@
#include <Magnum/Math/Vector4.h>
#include <algorithm>
-namespace floormat {
+namespace floormat::entities {
namespace {
-using entities::erased_constraints::is_magnum_vector;
+using erased_constraints::is_magnum_vector;
String label_left(StringView label)
{
@@ -46,7 +46,8 @@ template<typename T, std::size_t N> constexpr bool eqv(const Math::Vector<N, T>&
template<typename T> void do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr)
{
- fm_assert(accessor.check_field_name<T>());
+ fm_assert(accessor.check_field_type<T>());
+
bool should_disable;
switch (accessor.is_enabled(datum))
@@ -64,7 +65,9 @@ template<typename T> void do_inspect_field(void* datum, const erased_accessor& a
accessor.read_fun(datum, accessor.reader, &value);
auto orig = value;
- if constexpr (!is_magnum_vector<T>)
+ if constexpr(std::is_same_v<T, bool>)
+ ret = ImGui::Checkbox(label.data(), &value);
+ else if constexpr (!is_magnum_vector<T>)
{
auto [min, max] = accessor.get_range(datum).convert<T>();
constexpr auto igdt = IGDT<T>;
@@ -105,13 +108,15 @@ template<typename T> void do_inspect_field(void* datum, const erased_accessor& a
} // namespace
-#define MAKE_SPEC(type, repr) \
- template<> void inspect_field<type>(void* datum, const erased_accessor& accessor) { \
+#define MAKE_SPEC(type, repr) \
+ template<> \
+ void inspect_field<type>(void* datum, const erased_accessor& accessor) { \
do_inspect_field<type>(datum, accessor, (repr)); \
}
#define MAKE_SPEC2(type, repr) \
- template<> void inspect_field<field_repr_<type, field_repr, repr>>(void* datum, const erased_accessor& accessor) { \
+ template<> \
+ void inspect_field<field_repr_<type, field_repr, repr>>(void* datum, const erased_accessor& accessor) { \
do_inspect_field<type>(datum, accessor, (repr)); \
}
@@ -134,5 +139,6 @@ MAKE_SPEC_REPRS2(std::int16_t)
MAKE_SPEC_REPRS2(std::uint32_t)
MAKE_SPEC_REPRS2(std::int32_t)
MAKE_SPEC_REPRS2(float)
+MAKE_SPEC(bool, field_repr::input)
-} // namespace floormat
+} // namespace floormat::entities
diff --git a/editor/inspect.hpp b/editor/inspect.hpp
index d2824f2c..5cb71303 100644
--- a/editor/inspect.hpp
+++ b/editor/inspect.hpp
@@ -1,8 +1,7 @@
#pragma once
-//#include "entity/accessor.hpp"
-namespace floormat::entities { struct erased_accessor; }
+namespace floormat::entities {
-namespace floormat {
+struct erased_accessor;
template<typename T, typename Enum, Enum As>
struct field_repr_ final {
@@ -26,5 +25,6 @@ template<typename T> using field_repr_slider = field_repr_<T, field_repr, field_
template<typename T> using field_repr_drag = field_repr_<T, field_repr, field_repr::drag>;
template<typename T> void inspect_field(void* datum, const entities::erased_accessor& accessor);
+template<typename T> void inspect_type(T& x);
-} // namespace floormat
+} // namespace floormat::entities