Merge pull request #65370 from SaracenOne/tileset_editor_visibility_fixes

Fix contextual visibility of tileset and tilemap editors (again)
This commit is contained in:
Rémi Verschelde 2023-01-13 18:02:12 +01:00
commit 44f7392883
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 22 additions and 7 deletions

View File

@ -185,26 +185,34 @@ void TilesEditorPlugin::_notification(int p_what) {
}
void TilesEditorPlugin::make_visible(bool p_visible) {
is_visible = p_visible;
if (is_visible) {
if (p_visible || is_tile_map_selected()) {
// Disable and hide invalid editors.
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
tileset_editor_button->set_visible(tile_set.is_valid());
tilemap_editor_button->set_visible(tile_map);
if (tile_map && !is_editing_tile_set) {
if (tile_map && (!is_editing_tile_set || !p_visible)) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(tilemap_editor);
} else {
EditorNode::get_singleton()->make_bottom_panel_item_visible(tileset_editor);
}
is_visible = true;
} else {
tileset_editor_button->hide();
tilemap_editor_button->hide();
EditorNode::get_singleton()->hide_bottom_panel();
is_visible = false;
}
}
bool TilesEditorPlugin::is_tile_map_selected() {
TypedArray<Node> selection = get_editor_interface()->get_selection()->get_selected_nodes();
if (selection.size() == 1 && Object::cast_to<TileMap>(selection[0])) {
return true;
}
return false;
}
void TilesEditorPlugin::queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback) {
ERR_FAIL_COND(!p_tile_set.is_valid());
ERR_FAIL_COND(!p_pattern.is_valid());
@ -362,19 +370,24 @@ void TilesEditorPlugin::edit(Object *p_object) {
} else if (p_object->is_class("TileSet")) {
tile_set = Ref<TileSet>(p_object);
if (tile_map) {
if (tile_map->get_tileset() != tile_set || !tile_map->is_inside_tree()) {
if (tile_map->get_tileset() != tile_set || !tile_map->is_inside_tree() || !is_tile_map_selected()) {
tile_map = nullptr;
tile_map_id = ObjectID();
}
}
is_editing_tile_set = true;
EditorNode::get_singleton()->make_bottom_panel_item_visible(tileset_editor);
}
}
// Update the editors.
_update_editors();
// If the tileset is being edited, the visibility function must be called
// here after _update_editors has been called.
if (is_editing_tile_set) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(tileset_editor);
}
// Add change listener.
if (tile_map) {
tile_map->connect("changed", callable_mp(this, &TilesEditorPlugin::_tile_map_changed));

View File

@ -110,6 +110,8 @@ public:
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return tilemap_editor->forward_canvas_gui_input(p_event); }
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { tilemap_editor->forward_canvas_draw_over_viewport(p_overlay); }
bool is_tile_map_selected();
// Pattern preview API.
void queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback);