Skip to content

Commit 5d8d4df

Browse files
Add editor shortcuts for Tiles and Objects navigation (#2988)
- Add "Q" to switch between Tiles and Objects; - Add Shift + "Q" to toggle between current and last subgroup inside the same group (Tiles or Objects); - Add Shift + Scroll to open the current menu and select on release; - Add "S" to open a menu of sub-subgroups within each Tiles subgroup; - This uses the divisions previously commented in tiles.strf. Co-authored-by: Afonso Mateus <[email protected]>
1 parent 9ff3bbc commit 5d8d4df

17 files changed

+673
-59
lines changed

data/images/tiles.strf

Lines changed: 151 additions & 25 deletions
Large diffs are not rendered by default.

src/editor/editor.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#endif
2828

2929
#include <fmt/format.h>
30+
#include <SDL.h>
3031

3132
#include "zip_manager.hpp"
3233

@@ -409,10 +410,14 @@ Editor::open_level_directory()
409410
void
410411
Editor::scroll(const Vector& velocity)
411412
{
412-
if (!m_levelloaded) return;
413-
414-
m_sector->get_camera().move(velocity / m_sector->get_camera().get_current_scale());
415-
keep_camera_in_bounds();
413+
const Uint16 mod_state = SDL_GetModState();
414+
const bool shiftPressed = (mod_state & KMOD_SHIFT) != 0;
415+
if (!shiftPressed)
416+
{
417+
if (!m_levelloaded) return;
418+
m_sector->get_camera().move(velocity / m_sector->get_camera().get_current_scale());
419+
keep_camera_in_bounds();
420+
}
416421
}
417422

418423
void
@@ -973,9 +978,9 @@ Editor::sort_layers()
973978
}
974979

975980
void
976-
Editor::select_tilegroup(int id)
981+
Editor::select_tilegroup(int id, bool subgroup)
977982
{
978-
m_toolbox_widget->select_tilegroup(id);
983+
m_toolbox_widget->select_tilegroup(id, subgroup);
979984
}
980985

981986
const std::vector<Tilegroup>&

src/editor/editor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Editor final : public Screen,
137137
void delete_markers();
138138
void sort_layers();
139139

140-
void select_tilegroup(int id);
140+
void select_tilegroup(int id, bool subgroup);
141141
const std::vector<Tilegroup>& get_tilegroups() const;
142142
void change_tileset();
143143

src/editor/overlay_widget.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,14 +1500,29 @@ EditorOverlayWidget::draw(DrawingContext& context)
15001500

15011501
m_object_tip->draw(context, m_mouse_pos);
15021502

1503-
// Draw zoom indicator.
1503+
// Draw zoom indicator and current mode (tiles/objects)
15041504
// The placing on the top-right is temporary, will be moved with the implementation of an editor toolbar.
15051505
const float scale = m_editor.get_sector()->get_camera().get_current_scale();
15061506
const int scale_percentage = static_cast<int>(roundf(scale * 100.f));
1507-
if (scale_percentage != 100)
1508-
context.color().draw_text(Resources::big_font, std::to_string(scale_percentage) + '%',
1509-
Vector(context.get_width() - 140.f, 15.f),
1510-
ALIGN_RIGHT, LAYER_OBJECTS + 1, Color::WHITE);
1507+
std::string mode_text;
1508+
switch (m_editor.get_tileselect_input_type())
1509+
{
1510+
case EditorTilebox::InputType::TILE:
1511+
mode_text = "TILE MODE (Click S to open tiles subgroups)";
1512+
break;
1513+
case EditorTilebox::InputType::OBJECT:
1514+
mode_text = "OBJECT MODE";
1515+
break;
1516+
default:
1517+
mode_text = "NONE";
1518+
break;
1519+
}
1520+
std::string zoom_text = (scale_percentage != 100)
1521+
? std::to_string(scale_percentage) + "% " + mode_text
1522+
: mode_text;
1523+
context.color().draw_text(Resources::normal_font, zoom_text,
1524+
Vector(144, 55),
1525+
ALIGN_LEFT, LAYER_OBJECTS + 1, EditorOverlayWidget::text_autotile_available_color);
15111526

15121527
context.push_transform();
15131528
context.set_translation(m_editor.get_sector()->get_camera().get_translation());

src/editor/tilebox.cpp

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include "util/log.hpp"
3232
#include "video/drawing_context.hpp"
3333

34+
int current_selected_tilegroup_index = 0;
35+
int previous_tilegroup_index = 0;
36+
int current_selected_objectgroup_index = 0;
37+
int previous_objectgroup_index = 0;
38+
bool tilegroup_selected = false;
39+
bool subgroup_selected = false;
40+
3441
EditorTilebox::EditorTilebox(Editor& editor, const Rectf& rect) :
3542
m_editor(editor),
3643
m_rect(rect),
@@ -53,6 +60,22 @@ EditorTilebox::EditorTilebox(Editor& editor, const Rectf& rect) :
5360
m_scrollbar.reset(new ControlScrollbar(1.f, 1.f, m_scroll_progress, 35.f));
5461
}
5562

63+
64+
int
65+
EditorTilebox::get_parentgroup_size() const
66+
{
67+
int parent_group_size = 0;
68+
std::string parent_group_name = m_active_tilegroup->parent_group;
69+
for (auto& tilegroup :m_editor.get_tileset()->get_tilegroups())
70+
{
71+
if (tilegroup.parent_group == parent_group_name) {
72+
parent_group_size += tilegroup.tiles.size();
73+
}
74+
75+
}
76+
return parent_group_size;
77+
}
78+
5679
void
5780
EditorTilebox::draw(DrawingContext& context)
5881
{
@@ -100,20 +123,57 @@ void
100123
EditorTilebox::draw_tilegroup(DrawingContext& context)
101124
{
102125
int pos = -1;
103-
for (auto& tile_ID : m_active_tilegroup->tiles)
126+
127+
if (!subgroup_selected)
104128
{
105-
pos++;
106-
if (pos / 4 < static_cast<int>(m_scroll_progress / 32.f))
107-
continue;
129+
int id = 0;
130+
// Skip the previous index groups
131+
while (m_editor.get_tileset()->get_tilegroups()[id].parent_group != m_active_tilegroup->parent_group
132+
&& m_active_tilegroup->parent_group != "")
133+
{
134+
id ++;
135+
}
136+
137+
// Treat all same group subgroups
138+
while ((id < m_editor.get_tileset()->get_tilegroups().size()
139+
&& m_editor.get_tileset()->get_tilegroups()[id].parent_group == m_active_tilegroup->parent_group)
140+
&& m_active_tilegroup->parent_group != "") {
141+
for (auto& tile_ID :m_editor.get_tileset()->get_tilegroups()[id].tiles)
142+
{
143+
pos++;
144+
if (pos / 4 < static_cast<int>(m_scroll_progress / 32.f))
145+
continue;
146+
147+
auto position = get_tile_coords(pos, false);
148+
m_editor.get_tileset()->get(tile_ID).draw(context.color(), position, LAYER_GUI - 9);
149+
150+
if (g_config->developer_mode && (m_active_tilegroup->developers_group || g_debug.show_toolbox_tile_ids) && tile_ID != 0)
151+
{
152+
// Display tile ID on top of tile:
153+
context.color().draw_text(Resources::console_font, std::to_string(tile_ID),
154+
position + Vector(16, 16), ALIGN_CENTER, LAYER_GUI - 9, Color::WHITE);
155+
}
156+
}
157+
id ++;
158+
}
159+
}
160+
else
161+
{
162+
for (auto& tile_ID :m_active_tilegroup->tiles)
163+
{
164+
pos++;
165+
if (pos / 4 < static_cast<int>(m_scroll_progress / 32.f))
166+
continue;
108167

109-
auto position = get_tile_coords(pos, false);
110-
m_editor.get_tileset()->get(tile_ID).draw(context.color(), position, LAYER_GUI - 9);
168+
auto position = get_tile_coords(pos, false);
169+
m_editor.get_tileset()->get(tile_ID).draw(context.color(), position, LAYER_GUI - 9);
111170

112-
if (g_config->developer_mode && (m_active_tilegroup->developers_group || g_debug.show_toolbox_tile_ids) && tile_ID != 0)
113-
{
114-
// Display tile ID on top of tile:
115-
context.color().draw_text(Resources::console_font, std::to_string(tile_ID),
116-
position + Vector(16, 16), ALIGN_CENTER, LAYER_GUI - 9, Color::WHITE);
171+
if (g_config->developer_mode && (m_active_tilegroup->developers_group || g_debug.show_toolbox_tile_ids) && tile_ID != 0)
172+
{
173+
// Display tile ID on top of tile:
174+
context.color().draw_text(Resources::console_font, std::to_string(tile_ID),
175+
position + Vector(16, 16), ALIGN_CENTER, LAYER_GUI - 9, Color::WHITE);
176+
}
117177
}
118178
}
119179
}
@@ -370,16 +430,32 @@ EditorTilebox::on_select(const std::function<void(EditorTilebox&)>& callback)
370430
}
371431

372432
void
373-
EditorTilebox::select_tilegroup(int id)
433+
EditorTilebox::select_tilegroup(int id, bool subgroup)
374434
{
435+
if (tilegroup_selected) {
436+
previous_tilegroup_index = current_selected_tilegroup_index;
437+
}
438+
current_selected_tilegroup_index = id;
439+
tilegroup_selected = true;
375440
m_active_tilegroup.reset(new Tilegroup(m_editor.get_tileset()->get_tilegroups()[id]));
376441
m_input_type = InputType::TILE;
377442
reset_scrollbar();
443+
if (subgroup) {
444+
subgroup_selected = true;
445+
}
446+
else {
447+
subgroup_selected = false;
448+
}
378449
}
379450

380451
void
381452
EditorTilebox::select_objectgroup(int id)
382453
{
454+
if (!tilegroup_selected) {
455+
previous_objectgroup_index = current_selected_objectgroup_index;
456+
}
457+
current_selected_objectgroup_index = id;
458+
tilegroup_selected = false;
383459
m_active_objectgroup = &m_object_info->m_groups[id];
384460
m_input_type = InputType::OBJECT;
385461
reset_scrollbar();
@@ -412,7 +488,7 @@ EditorTilebox::get_tiles_height() const
412488
switch (m_input_type)
413489
{
414490
case InputType::TILE:
415-
return ceilf(static_cast<float>(m_active_tilegroup->tiles.size()) / 4.f) * 32.f;
491+
return ceilf(static_cast<float>(get_parentgroup_size()) / 4.f) * 32.f;
416492

417493
case InputType::OBJECT:
418494
return ceilf(static_cast<float>(m_active_objectgroup->get_icons().size()) / 4.f) * 32.f;
@@ -422,6 +498,30 @@ EditorTilebox::get_tiles_height() const
422498
}
423499
}
424500

501+
int
502+
EditorTilebox::get_current_tilegroup_index() const
503+
{
504+
return current_selected_tilegroup_index;
505+
}
506+
507+
int
508+
EditorTilebox::get_previous_tilegroup_index() const
509+
{
510+
return previous_tilegroup_index;
511+
}
512+
513+
int
514+
EditorTilebox::get_current_objectgroup_index() const
515+
{
516+
return current_selected_objectgroup_index;
517+
}
518+
519+
int
520+
EditorTilebox::get_previous_objectgroup_index() const
521+
{
522+
return previous_objectgroup_index;
523+
}
524+
425525
void
426526
EditorTilebox::reset_scrollbar()
427527
{

src/editor/tilebox.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class EditorTilebox final : public Widget
5959
public:
6060
EditorTilebox(Editor& editor, const Rectf& rect);
6161

62+
int get_parentgroup_size() const;
63+
6264
virtual void draw(DrawingContext& context) override;
6365

6466
virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override;
@@ -74,7 +76,7 @@ class EditorTilebox final : public Widget
7476

7577
void on_select(const std::function<void(EditorTilebox&)>& callback);
7678

77-
void select_tilegroup(int id);
79+
void select_tilegroup(int id, bool subgroup);
7880
inline void set_tilegroup(std::unique_ptr<Tilegroup> tilegroup) { m_active_tilegroup = std::move(tilegroup); }
7981
void select_objectgroup(int id);
8082
bool select_layers_objectgroup();
@@ -88,6 +90,10 @@ class EditorTilebox final : public Widget
8890
inline void set_object(const std::string& object) { m_object = object; }
8991

9092
float get_tiles_height() const;
93+
int get_current_tilegroup_index() const;
94+
int get_previous_tilegroup_index() const;
95+
int get_current_objectgroup_index() const;
96+
int get_previous_objectgroup_index() const;
9197

9298
inline bool has_active_object_tip() const { return m_object_tip->get_visible(); }
9399

0 commit comments

Comments
 (0)