31
31
#include " util/log.hpp"
32
32
#include " video/drawing_context.hpp"
33
33
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
+
34
41
EditorTilebox::EditorTilebox (Editor& editor, const Rectf& rect) :
35
42
m_editor(editor),
36
43
m_rect(rect),
@@ -53,6 +60,22 @@ EditorTilebox::EditorTilebox(Editor& editor, const Rectf& rect) :
53
60
m_scrollbar.reset (new ControlScrollbar (1 .f , 1 .f , m_scroll_progress, 35 .f ));
54
61
}
55
62
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
+
56
79
void
57
80
EditorTilebox::draw (DrawingContext& context)
58
81
{
@@ -100,20 +123,57 @@ void
100
123
EditorTilebox::draw_tilegroup (DrawingContext& context)
101
124
{
102
125
int pos = -1 ;
103
- for (auto & tile_ID : m_active_tilegroup->tiles )
126
+
127
+ if (!subgroup_selected)
104
128
{
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 ;
108
167
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 );
111
170
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
+ }
117
177
}
118
178
}
119
179
}
@@ -370,16 +430,32 @@ EditorTilebox::on_select(const std::function<void(EditorTilebox&)>& callback)
370
430
}
371
431
372
432
void
373
- EditorTilebox::select_tilegroup (int id)
433
+ EditorTilebox::select_tilegroup (int id, bool subgroup )
374
434
{
435
+ if (tilegroup_selected) {
436
+ previous_tilegroup_index = current_selected_tilegroup_index;
437
+ }
438
+ current_selected_tilegroup_index = id;
439
+ tilegroup_selected = true ;
375
440
m_active_tilegroup.reset (new Tilegroup (m_editor.get_tileset ()->get_tilegroups ()[id]));
376
441
m_input_type = InputType::TILE;
377
442
reset_scrollbar ();
443
+ if (subgroup) {
444
+ subgroup_selected = true ;
445
+ }
446
+ else {
447
+ subgroup_selected = false ;
448
+ }
378
449
}
379
450
380
451
void
381
452
EditorTilebox::select_objectgroup (int id)
382
453
{
454
+ if (!tilegroup_selected) {
455
+ previous_objectgroup_index = current_selected_objectgroup_index;
456
+ }
457
+ current_selected_objectgroup_index = id;
458
+ tilegroup_selected = false ;
383
459
m_active_objectgroup = &m_object_info->m_groups [id];
384
460
m_input_type = InputType::OBJECT;
385
461
reset_scrollbar ();
@@ -412,7 +488,7 @@ EditorTilebox::get_tiles_height() const
412
488
switch (m_input_type)
413
489
{
414
490
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 ;
416
492
417
493
case InputType::OBJECT:
418
494
return ceilf (static_cast <float >(m_active_objectgroup->get_icons ().size ()) / 4 .f ) * 32 .f ;
@@ -422,6 +498,30 @@ EditorTilebox::get_tiles_height() const
422
498
}
423
499
}
424
500
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
+
425
525
void
426
526
EditorTilebox::reset_scrollbar ()
427
527
{
0 commit comments