Skip to content

Commit adecef8

Browse files
sofi004Filipe2004
andcommitted
Fixes #517 - Add a button with the ability to hide/single layers
The Supertux level editor did not have a button to hide individual layers. Now this button is at the end of each layer menu. The button does not appear on the selected layer, as it does not make sense to hide the selected layer. When someone decides to hide a layer other than the selected one and then switches to it, that layer is shown again. In addition, after hiding a layer, if the hidden layer menu is opened again, instead of the hide layer button, a show layer button appears. The default opacity of 0.5 was kept as the default, so that users do not find it strange or have to press this implemented button. Closes #517 Co-authored-by: Filipe Oleacu <[email protected]>
1 parent c210829 commit adecef8

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/editor/editor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Editor final : public Screen,
5151
{
5252
public:
5353
static bool is_active();
54+
inline EditorLayersWidget* get_layers_widget() const { return m_layers_widget; }
5455

5556
private:
5657
static bool is_autosave_file(const std::string& filename) {

src/editor/layers_widget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,14 @@ EditorLayersWidget::set_selected_tilemap(TileMap* tilemap)
495495
{
496496
TileMap* selected_tilemap = get_selected_tilemap();
497497
if (selected_tilemap)
498+
{
498499
selected_tilemap->m_editor_active = false;
500+
selected_tilemap->set_alpha(0.5f);
501+
}
499502

500503
m_selected_tilemap = tilemap->get_uid();
501504
tilemap->m_editor_active = true;
505+
tilemap->set_alpha(1.0f);
502506
}
503507

504508
Vector

src/editor/object_menu.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ ObjectMenu::refresh()
5454
}
5555
}
5656

57+
TileMap* selected_tilemap = m_editor.get_layers_widget()->get_selected_tilemap();
58+
if (m_object != selected_tilemap)
59+
{
60+
float current_alpha = static_cast<TileMap*>(m_object)->get_alpha();
61+
if (current_alpha > 0.0f)
62+
{
63+
add_entry(MNID_HIDE_LAYER, _("Hide Layer"));
64+
}
65+
else
66+
{
67+
add_entry(MNID_HIDE_LAYER, _("Show Layer"));
68+
}
69+
}
70+
5771
if (!m_object->is_up_to_date())
5872
{
5973
add_hl();
@@ -86,6 +100,25 @@ ObjectMenu::menu_action(MenuItem& item)
86100
refresh();
87101
});
88102
break;
103+
104+
case MNID_HIDE_LAYER:
105+
if (m_object)
106+
{
107+
TileMap* tilemap = static_cast<TileMap*>(m_object);
108+
float current_alpha = tilemap->get_alpha();
109+
if (current_alpha > 0.0f)
110+
{
111+
tilemap->set_alpha(0.0f);
112+
}
113+
else
114+
{
115+
tilemap->set_alpha(1.0f);
116+
}
117+
m_editor.m_reactivate_request = true;
118+
refresh();
119+
}
120+
MenuManager::instance().pop_menu();
121+
break;
89122

90123
case MNID_PATCH_NOTES:
91124
{

src/editor/object_menu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ObjectMenu final : public Menu
2929
public:
3030
enum {
3131
MNID_UPDATE,
32+
MNID_HIDE_LAYER,
3233
MNID_PATCH_NOTES,
3334
MNID_REMOVE,
3435
MNID_REMOVEFUNCTION,

0 commit comments

Comments
 (0)