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+
3441EditorTilebox::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+
5679void
5780EditorTilebox::draw (DrawingContext& context)
5881{
@@ -100,20 +123,57 @@ void
100123EditorTilebox::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
372432void
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
380451void
381452EditorTilebox::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+
425525void
426526EditorTilebox::reset_scrollbar ()
427527{
0 commit comments