Skip to content

Commit

Permalink
reworked tile list
Browse files Browse the repository at this point in the history
  • Loading branch information
Redcrafter committed Sep 15, 2024
1 parent 5291c9a commit b501ce9
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/imgui
Submodule imgui updated 45 files
+64 −4 .github/workflows/build.yml
+12 −0 .github/workflows/manual.yml
+8 −5 backends/imgui_impl_allegro5.cpp
+51 −15 backends/imgui_impl_glfw.cpp
+3 −0 backends/imgui_impl_glfw.h
+8 −3 backends/imgui_impl_osx.mm
+65 −28 backends/imgui_impl_sdl2.cpp
+97 −39 backends/imgui_impl_sdl3.cpp
+1 −2 backends/imgui_impl_sdl3.h
+2 −0 backends/imgui_impl_sdlrenderer3.cpp
+2 −0 backends/imgui_impl_sdlrenderer3.h
+2 −0 backends/imgui_impl_win32.cpp
+1 −1 docs/BACKENDS.md
+143 −1 docs/CHANGELOG.txt
+9 −8 docs/FAQ.md
+5 −1 docs/FONTS.md
+4 −4 docs/README.md
+1 −2 docs/TODO.txt
+5 −0 examples/example_glfw_opengl2/main.cpp
+5 −0 examples/example_glfw_opengl3/main.cpp
+5 −0 examples/example_glfw_vulkan/main.cpp
+0 −1 examples/example_glfw_wgpu/CMakeLists.txt
+5 −0 examples/example_glfw_wgpu/main.cpp
+1 −1 examples/example_null/Makefile
+5 −0 examples/example_sdl2_directx11/main.cpp
+5 −0 examples/example_sdl2_opengl2/main.cpp
+5 −0 examples/example_sdl2_opengl3/main.cpp
+6 −1 examples/example_sdl2_sdlrenderer2/main.cpp
+5 −0 examples/example_sdl2_vulkan/main.cpp
+3 −3 examples/example_sdl3_opengl3/README.md
+6 −1 examples/example_sdl3_opengl3/main.cpp
+9 −1 examples/example_sdl3_sdlrenderer3/main.cpp
+8 −0 examples/example_win32_opengl3/build_mingw.bat
+5 −0 examples/example_win32_opengl3/main.cpp
+4 −3 examples/libs/emscripten/emscripten_mainloop_stub.h
+1 −1 imconfig.h
+264 −100 imgui.cpp
+100 −64 imgui.h
+65 −36 imgui_demo.cpp
+13 −5 imgui_draw.cpp
+64 −58 imgui_internal.h
+34 −21 imgui_tables.cpp
+315 −236 imgui_widgets.cpp
+63 −35 imstb_textedit.h
+3 −2 misc/freetype/imgui_freetype.cpp
27 changes: 14 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ constexpr auto room_size = glm::ivec2(40, 22);
constexpr const char* modes[] = {"View", "Edit"};
int mouse_mode = 0;
glm::ivec2 mode0_selection = {-1, -1};
MapTile mode1_placing;

// 0 = forground, 1 = background
bool selectLayer = false;
Expand Down Expand Up @@ -1311,8 +1312,6 @@ static void DrawPreviewWindow() {
}

} else if(mouse_mode == 1) {
static MapTile placing;

auto mouse_world_pos = screen_to_world(mousePos);

ImGui::SameLine();
Expand All @@ -1338,15 +1337,15 @@ ctrl + y to redo.");
auto tile = room->tiles[0][tp.y][tp.x];

if(render_data->show_fg && tile.tile_id != 0) {
placing = tile;
mode1_placing = tile;
selectLayer = false;
} else {
tile = room->tiles[1][tp.y][tp.x];
if(render_data->show_bg && tile.tile_id != 0) {
placing = tile;
mode1_placing = tile;
selectLayer = true;
} else {
placing = {};
mode1_placing = {};
}
}
}
Expand All @@ -1356,9 +1355,9 @@ ctrl + y to redo.");
auto tp = glm::ivec2(mouse_world_pos.x % room_size.x, mouse_world_pos.y % room_size.y);
auto tile_layer = room->tiles[selectLayer];
auto tile = tile_layer[tp.y][tp.x];
if(tile != placing) {
if(tile != mode1_placing) {
push_undo(std::make_unique<SingleChange>(glm::ivec3(mouse_world_pos, selectLayer), tile));
tile_layer[tp.y][tp.x] = placing;
tile_layer[tp.y][tp.x] = mode1_placing;
updateRender();
}
}
Expand All @@ -1369,11 +1368,11 @@ ctrl + y to redo.");
selection_handler.change_layer(!selectLayer, selectLayer);
}
ImGui::NewLine();
ImGui::InputScalar("id", ImGuiDataType_U16, &placing.tile_id);
ImGui::InputScalar("param", ImGuiDataType_U8, &placing.param);
ImGui::InputScalar("id", ImGuiDataType_U16, &mode1_placing.tile_id);
ImGui::InputScalar("param", ImGuiDataType_U8, &mode1_placing.param);

if(ImGui::BeginTable("tile_flags_table", 2)) {
int flags = placing.flags;
int flags = mode1_placing.flags;
// clang-format off
ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::CheckboxFlags("Horizontal mirror", &flags, 1);
Expand All @@ -1384,13 +1383,13 @@ ctrl + y to redo.");
ImGui::TableNextColumn(); ImGui::CheckboxFlags("Rotate 180", &flags, 8);
// clang-format on

placing.flags = flags;
mode1_placing.flags = flags;

ImGui::EndTable();
}

ImGui::SeparatorText("preview");
ImGui_draw_tile(placing.tile_id, game_data, 0);
ImGui_draw_tile(mode1_placing.tile_id, game_data, 0);
}

ImGui::End();
Expand Down Expand Up @@ -1655,6 +1654,8 @@ int runViewer() {
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
tile_list.init(); // load settings handler for tiles

ImGuiIO& io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
Expand Down Expand Up @@ -1744,7 +1745,7 @@ int runViewer() {
// center of screen
camera.position = -(pos * 8 + 4);
});
tile_list.draw(game_data, render_data->atlas);
tile_list.draw(game_data, mode1_placing);
tile_viewer.draw(game_data, should_update);
DrawPreviewWindow();

Expand Down
18 changes: 18 additions & 0 deletions src/structures/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ struct SpriteData {

return out;
}

std::pair<glm::ivec2, glm::ivec2> calcBB(int frame) const {
glm::ivec2 min {0, 0};
glm::ivec2 max {0, 0};
for(int i = 0; i < layers.size(); ++i) {
auto subsprite_id = compositions[frame * layers.size() + i];
if(subsprite_id >= sub_sprites.size())
continue;

auto& layer = layers[i];
if(layer.is_normals1 || layer.is_normals2 || !layer.is_visible) continue;

auto& subsprite = sub_sprites[subsprite_id];
min = glm::min(min, glm::ivec2(subsprite.composite_pos));
max = glm::max(max, glm::ivec2(subsprite.composite_pos + subsprite.size));
}
return {min, max};
}
};

struct TileMapping {
Expand Down
Loading

0 comments on commit b501ce9

Please sign in to comment.