summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-15 11:40:19 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-15 11:40:19 +0200
commit4e77740facb23e1c392f180381ccb5446d445724 (patch)
treed629c4d2960546dab2ed759d756674533baac536
parenta99c6ebd1c24e3f645e2c07591cfcfa97a162a6b (diff)
a
-rw-r--r--anim-crop-tool/main.cpp16
-rw-r--r--doc/atlas.json.example3
-rw-r--r--main/app.cpp5
-rw-r--r--main/app.hpp3
-rw-r--r--main/keyboard.cpp2
-rw-r--r--main/menu.cpp59
-rw-r--r--serialize/anim.cpp2
-rw-r--r--serialize/anim.hpp2
8 files changed, 62 insertions, 30 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp
index b268321e..5caa9fe4 100644
--- a/anim-crop-tool/main.cpp
+++ b/anim-crop-tool/main.cpp
@@ -250,9 +250,15 @@ int main(int argc, char** argv)
if (!anim_ok)
return EX_DATAERR;
- if (!check_atlas_name(anim_info.name))
+ if (!check_atlas_name(anim_info.object_name))
{
- Error{} << "error: atlas name" << anim_info.name << "contains invalid characters";
+ Error{} << "error: atlas object name" << anim_info.object_name << "is invalid";
+ return EX_DATAERR;
+ }
+
+ if (!check_atlas_name(anim_info.anim_name))
+ {
+ Error{} << "error: atlas animation name" << anim_info.object_name << "contains invalid characters";
return EX_DATAERR;
}
@@ -281,12 +287,14 @@ int main(int argc, char** argv)
return EX_CANTCREAT;
}
- if (auto pathname = opts.output_dir/(anim_info.name + ".png"); !atlas.dump(pathname)) {
+ const std::string base_name = anim_info.object_name + "_" + anim_info.anim_name;
+
+ if (auto pathname = opts.output_dir/(base_name + ".png"); !atlas.dump(pathname)) {
Error{} << "error: failed writing image to" << pathname << ":"
<< std::strerror(errno); // NOLINT(concurrency-mt-unsafe)
return EX_CANTCREAT;
}
- if (!json_helper::to_json<anim>(anim_info, opts.output_dir/(anim_info.name + ".json")))
+ if (!json_helper::to_json<anim>(anim_info, opts.output_dir/(base_name + ".json")))
return EX_CANTCREAT;
return 0;
diff --git a/doc/atlas.json.example b/doc/atlas.json.example
index bbb2796f..2c9f0f0a 100644
--- a/doc/atlas.json.example
+++ b/doc/atlas.json.example
@@ -1,5 +1,6 @@
{
- "name": "test",
+ "object_name": "test",
+ "anim_name": "walk",
"width": 0, "height": 0,
"nframes": 0, "fps": 24,
"actionframe": 0,
diff --git a/main/app.cpp b/main/app.cpp
index 0c29abf1..33b89231 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -31,8 +31,7 @@ void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
{
update_window_scale(event.windowSize());
GL::defaultFramebuffer.setViewport({{}, event.windowSize()});
- _imgui.relayout(Vector2{event.windowSize()}/event.dpiScaling(),
- event.windowSize(), event.framebufferSize());
+ _imgui.relayout(Vector2{event.windowSize()}, event.windowSize(), event.framebufferSize());
}
@@ -63,7 +62,7 @@ void app::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
{
if (_imgui.handleTextInputEvent(event))
- return event.setAccepted();
+ return keys = {}, event.setAccepted();
}
void app::update(float dt)
diff --git a/main/app.hpp b/main/app.hpp
index 389dbef3..876ad8fe 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -43,7 +43,6 @@ struct app final : Platform::Application
void update_window_scale(Vector2i window_size);
void viewportEvent(ViewportEvent& event) override;
void draw_menu();
- void draw_menu_bar();
void setup_menu();
void display_menu();
void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
@@ -75,7 +74,7 @@ struct app final : Platform::Application
Vector2 camera_offset;
enum_bitset<key> keys;
Magnum::Timeline timeline;
- editor_mode _editor_mode = editor_mode{};
+ editor_state _editor;
};
} // namespace floormat
diff --git a/main/keyboard.cpp b/main/keyboard.cpp
index 041af2c8..66dafa7e 100644
--- a/main/keyboard.cpp
+++ b/main/keyboard.cpp
@@ -42,7 +42,7 @@ void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
{
if (_imgui.handleKeyReleaseEvent(event))
- return event.setAccepted();
+ return keys = {}, event.setAccepted();
do_key(event.key(), event.modifiers(), false, false);
}
diff --git a/main/menu.cpp b/main/menu.cpp
index 07626032..bd107611 100644
--- a/main/menu.cpp
+++ b/main/menu.cpp
@@ -23,27 +23,29 @@ struct raii_wrapper final
constexpr inline const auto* imgui_name = "floormat editor";
-#if 0
-[[nodiscard]] static raii_wrapper gui_begin() {
- using f = ImGuiWindowFlags_;
- int flags = 0;
- //flags |= ImGuiWindowFlags_AlwaysAutoResize;
- flags |= f::ImGuiWindowFlags_NoDecoration;
+[[nodiscard]] static raii_wrapper begin_window(int flags = 0) {
if (ImGui::Begin(imgui_name, nullptr, flags))
- return {&ImGui::End; };
+ return {&ImGui::End};
else
return {};
}
-#endif
+
[[nodiscard]] static raii_wrapper begin_main_menu() {
if (ImGui::BeginMainMenuBar())
- return raii_wrapper{&ImGui::EndMainMenuBar};
+ return {&ImGui::EndMainMenuBar};
else
return {};
}
[[nodiscard]] static raii_wrapper begin_menu(const char* name, bool enabled = true) {
if (ImGui::BeginMenu(name, enabled))
- return raii_wrapper{&ImGui::EndMenu};
+ return {&ImGui::EndMenu};
+ else
+ return {};
+}
+
+[[nodiscard]] static raii_wrapper begin_list_box(const char* name, ImVec2 size = {}) {
+ if (ImGui::BeginListBox(name, size))
+ return {&ImGui::EndListBox};
else
return {};
}
@@ -73,11 +75,8 @@ void app::draw_menu()
else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
stopTextInput();
- draw_menu_bar();
-}
+ ImVec2 main_menu_pos;
-void app::draw_menu_bar()
-{
if (auto b = begin_main_menu())
{
if (auto b = begin_menu("File"))
@@ -92,9 +91,35 @@ void app::draw_menu_bar()
}
if (auto b = begin_menu("Mode"))
{
- ImGui::MenuItem("Select", "F1", _editor_mode == editor_mode::select);
- ImGui::MenuItem("Floors", "F2", _editor_mode == editor_mode::floors);
- ImGui::MenuItem("Walls", "F3", _editor_mode == editor_mode::walls);
+ ImGui::MenuItem("Select", "F1", _editor.mode == editor_mode::select);
+ ImGui::MenuItem("Floors", "F2", _editor.mode == editor_mode::floors);
+ ImGui::MenuItem("Walls", "F3", _editor.mode == editor_mode::walls);
+ }
+ main_menu_pos = ImGui::GetContentRegionMax();
+ }
+ if (main_menu_pos.y > 0)
+ {
+ auto& style = ImGui::GetStyle();
+ ImGui::StyleColorsDark(&style);
+ style.WindowPadding = {8, 8};
+ style.WindowBorderSize = {};
+ style.Colors[ImGuiCol_WindowBg] = {0, 0, 0, .5};
+ style.Colors[ImGuiCol_FrameBg] = {0, 0, 0, 0};
+
+ ImGui::SetNextWindowPos({0, main_menu_pos.y+style.WindowPadding.y});
+ ImGui::SetNextFrameWantCaptureKeyboard(false);
+ if (auto b = begin_window(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings))
+ {
+ ImGui::Text("Items:");
+ //ImGui::SetNextWindowBgAlpha(.2f);
+
+ if (auto b = begin_list_box("##tiles", {-FLT_MIN, 100}))
+ {
+ for (const auto& label : {"foo", "bar", "baz"})
+ {
+ ImGui::Selectable(label);
+ }
+ }
}
}
}
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index 0e3b371f..18bca85a 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -10,7 +10,7 @@ namespace floormat::Serialize {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_frame, ground, offset, size)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground)
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim, name, nframes, actionframe, fps, groups, width, height)
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim, object_name, anim_name, nframes, actionframe, fps, groups, width, height)
} // namespace floormat::Serialize
diff --git a/serialize/anim.hpp b/serialize/anim.hpp
index 244799fb..957e733e 100644
--- a/serialize/anim.hpp
+++ b/serialize/anim.hpp
@@ -34,7 +34,7 @@ struct anim final
{
static constexpr int default_fps = 24;
- std::string name;
+ std::string object_name, anim_name;
std::array<anim_group, (std::size_t)anim_direction::COUNT> groups;
int nframes = 0;
int width = 0, height = 0;