summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp4
-rw-r--r--editor/draw.cpp47
-rw-r--r--editor/editor.cpp11
-rw-r--r--editor/editor.hpp2
-rw-r--r--editor/events.cpp24
-rw-r--r--editor/imgui.cpp6
-rw-r--r--editor/update.cpp14
7 files changed, 61 insertions, 47 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index de7ffc14..cfea9c12 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -41,6 +41,7 @@ struct app final : floormat_app
enum class key : int {
camera_up, camera_left, camera_right, camera_down, camera_reset,
rotate_tile, quicksave, quickload,
+ mode_select, mode_floor, mode_walls,
quit,
MAX = quit, COUNT, NO_REPEAT = rotate_tile,
};
@@ -82,10 +83,7 @@ struct app final : floormat_app
void reset_camera_offset();
void update_cursor_tile(const std::optional<Vector2i>& pixel);
-
void draw_cursor_tile();
- void draw_wireframe_quad(global_coords pt);
- void draw_wireframe_box(global_coords pt);
void init_imgui(Vector2i size);
void draw_ui();
diff --git a/editor/draw.cpp b/editor/draw.cpp
index b94d8ec2..4000689b 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -7,38 +7,35 @@
namespace floormat {
-void app::draw_wireframe_quad(global_coords pos)
+void app::draw_cursor_tile()
{
constexpr float LINE_WIDTH = 2;
- const auto pt = pos.to_signed();
- auto& shader = M->shader();
+ if (cursor.tile && !cursor.in_imgui)
{
- const Vector3 center{Vector3i(pt[0], pt[1], 0) * iTILE_SIZE};
- shader.set_tint({1, 0, 0, 1});
- _wireframe_quad.draw(shader, {center, TILE_SIZE2, LINE_WIDTH});
- //_wireframe_wall_n.draw(shader, {center, TILE_SIZE, LINE_WIDTH});
- //_wireframe_wall_w.draw(shader, {center, TILE_SIZE, LINE_WIDTH});
+ const auto pos = *cursor.tile;
+
+ const auto draw = [&](auto& mesh, const auto& size) {
+ const auto pt = pos.to_signed();
+ const Vector3 center{Vector3i(pt[0], pt[1], 0) * iTILE_SIZE};
+ auto& shader = M->shader();
+ shader.set_tint({1, 0, 0, 1});
+ mesh.draw(shader, {center, size, LINE_WIDTH});
+ };
+
+ if (const auto* ed = _editor.current(); ed && ed->mode() == editor_mode::walls)
+ {
+ switch (ed->rotation())
+ {
+ case editor_wall_rotation::N: draw(_wireframe_wall_n, TILE_SIZE); break;
+ case editor_wall_rotation::W: draw(_wireframe_wall_w, TILE_SIZE); break;
+ }
+ }
+ else
+ draw(_wireframe_quad, TILE_SIZE2);
}
}
-void app::draw_wireframe_box(global_coords pos)
-{
- constexpr float LINE_WIDTH = 1.5;
- auto& shader = M->shader();
-
- const auto pt = pos.to_signed();
- const auto center = Vector3((float)pt[0], (float)pt[1], 0) * TILE_SIZE;
- shader.set_tint({0, 1, 0, 1});
- _wireframe_box.draw(shader, {center, TILE_SIZE, LINE_WIDTH});
-}
-
-void app::draw_cursor_tile()
-{
- if (cursor.tile && !cursor.in_imgui)
- draw_wireframe_quad(*cursor.tile);
-}
-
void app::draw_msaa()
{
draw_cursor_tile();
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 5419b653..2bfd481f 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -161,10 +161,15 @@ void tile_editor::place_tile(world& world, global_coords pos, tile_image& img)
case editor_mode::select:
break;
case editor_mode::floor:
- t.ground = {atlas, variant };
+ t.ground = { atlas, variant };
break;
case editor_mode::walls:
- break; // todo
+ switch (tile_image x = { atlas, variant }; _rotation)
+ {
+ case editor_wall_rotation::N: t.wall_north = x; break;
+ case editor_wall_rotation::W: t.wall_west = x; break;
+ }
+ break;
}
}
@@ -210,7 +215,7 @@ const tile_editor* editor::current() const noexcept
case editor_mode::floor:
return &_floor;
case editor_mode::walls:
- return nullptr; // todo
+ return &_wall; // todo
default:
fm_warn_once("invalid editor mode '%u'", (unsigned)_mode);
return nullptr;
diff --git a/editor/editor.hpp b/editor/editor.hpp
index 201f6468..dfd2207d 100644
--- a/editor/editor.hpp
+++ b/editor/editor.hpp
@@ -38,7 +38,7 @@ private:
std::tuple<std::shared_ptr<tile_atlas>, std::vector<decltype(tile_image::variant)>> _permutation;
selection_mode _selection_mode = sel_none;
editor_mode _mode;
- editor_wall_rotation _rotation = editor_wall_rotation::N;
+ editor_wall_rotation _rotation = editor_wall_rotation::W;
void load_atlases();
tile_image get_selected_perm();
diff --git a/editor/events.cpp b/editor/events.cpp
index 2ba2437b..42420686 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -77,16 +77,20 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept
{
// todo put it into a separate function
const key x = fm_begin(switch (event.key) {
- default: return key::COUNT;
- case SDLK_w: return key::camera_up;
- case SDLK_a: return key::camera_left;
- case SDLK_s: return key::camera_down;
- case SDLK_d: return key::camera_right;
- case SDLK_HOME: return key::camera_reset;
- case SDLK_r: return key::rotate_tile;
- case SDLK_F5: return key::quicksave;
- case SDLK_F9: return key::quickload;
- case SDLK_ESCAPE: return key::quit; });
+ default: return key::COUNT;
+ case SDLK_w: return key::camera_up;
+ case SDLK_a: return key::camera_left;
+ case SDLK_s: return key::camera_down;
+ case SDLK_d: return key::camera_right;
+ case SDLK_HOME: return key::camera_reset;
+ case SDLK_r: return key::rotate_tile;
+ case SDLK_1: return key::mode_select;
+ case SDLK_2: return key::mode_floor;
+ case SDLK_3: return key::mode_walls;
+ case SDLK_F5: return key::quicksave;
+ case SDLK_F9: return key::quickload;
+ case SDLK_ESCAPE: return key::quit;
+ });
if (x != key::COUNT)
{
keys[x] = is_down;
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 3b2af522..83824967 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -45,9 +45,9 @@ float app::draw_main_menu()
}
if (auto b = begin_menu("Mode"))
{
- ImGui::MenuItem("Select", "F1", _editor.mode() == editor_mode::select);
- ImGui::MenuItem("Floor", "F2", _editor.mode() == editor_mode::floor);
- ImGui::MenuItem("Walls", "F3", _editor.mode() == editor_mode::walls);
+ ImGui::MenuItem("Select", "1", _editor.mode() == editor_mode::select);
+ ImGui::MenuItem("Floor", "2", _editor.mode() == editor_mode::floor);
+ ImGui::MenuItem("Walls", "3", _editor.mode() == editor_mode::walls);
}
main_menu_height = ImGui::GetContentRegionMax().y;
diff --git a/editor/update.cpp b/editor/update.cpp
index 468f89b1..8ff4246b 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -84,8 +84,18 @@ void app::do_keys()
do_quicksave();
if (k[key::quickload])
do_quickload();
- if (auto* ed = _editor.current(); ed && k[key::rotate_tile])
- ed->toggle_rotation();
+ if (k[key::mode_select])
+ _editor.set_mode(editor_mode::select);
+ if (k[key::mode_floor])
+ _editor.set_mode(editor_mode::floor);
+ if (k[key::mode_walls])
+ _editor.set_mode(editor_mode::walls);
+
+ if (auto* ed = _editor.current(); ed)
+ {
+ if (k[key::rotate_tile])
+ ed->toggle_rotation();
+ }
}
void app::update(float dt)