Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit TileSet source on double click #80037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {
sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_fix_selected_and_hovered).unbind(1));
sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_source_display).unbind(1));
sources_list->connect("item_selected", callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::set_sources_lists_current));
sources_list->connect("item_activated", callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::display_tile_set_editor_panel).unbind(1));
sources_list->connect("visibility_changed", callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::synchronize_sources_list).bind(sources_list, source_sort_button));
sources_list->add_user_signal(MethodInfo("sort_request"));
sources_list->connect("sort_request", callable_mp(this, &TileMapEditorTilesPlugin::_update_tile_set_sources_list));
Expand Down
27 changes: 22 additions & 5 deletions editor/plugins/tiles/tiles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
#include "scene/resources/tile_set.h"

TilesEditorUtils *TilesEditorUtils::singleton = nullptr;
TileMapEditorPlugin *local_singleton = nullptr;
TileMapEditorPlugin *tile_map_plugin_singleton = nullptr;
TileSetEditorPlugin *tile_set_plugin_singleton = nullptr;

void TilesEditorUtils::_preview_frame_started() {
RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<TilesEditorUtils *>(this), &TilesEditorUtils::_pattern_preview_done));
Expand Down Expand Up @@ -283,6 +284,11 @@ bool TilesEditorUtils::SourceNameComparator::operator()(const int &p_a, const in
return NaturalNoCaseComparator()(name_a, name_b);
}

void TilesEditorUtils::display_tile_set_editor_panel() {
tile_map_plugin_singleton->hide_editor();
tile_set_plugin_singleton->make_visible(true);
}

void TilesEditorUtils::draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color) {
real_t scale = p_ci->get_global_transform().get_scale().x * 0.5;
p_ci->draw_set_transform(p_rect.position, 0, Vector2(1, 1) / scale);
Expand Down Expand Up @@ -373,13 +379,19 @@ void TileMapEditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay)
editor->forward_canvas_draw_over_viewport(p_overlay);
}

void TileMapEditorPlugin::hide_editor() {
if (editor->is_visible_in_tree()) {
EditorNode::get_singleton()->hide_bottom_panel();
}
}

bool TileMapEditorPlugin::is_editor_visible() const {
return editor->is_visible_in_tree();
}

TileMapEditorPlugin::TileMapEditorPlugin() {
memnew(TilesEditorUtils);
local_singleton = this;
tile_map_plugin_singleton = this;

editor = memnew(TileMapEditor);
editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
Expand All @@ -392,7 +404,7 @@ TileMapEditorPlugin::TileMapEditorPlugin() {
}

TileMapEditorPlugin::~TileMapEditorPlugin() {
local_singleton = nullptr;
tile_map_plugin_singleton = nullptr;
}

void TileSetEditorPlugin::edit(Object *p_object) {
Expand All @@ -406,7 +418,7 @@ bool TileSetEditorPlugin::handles(Object *p_object) const {
void TileSetEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
button->show();
if (!local_singleton->is_editor_visible()) {
if (!tile_map_plugin_singleton->is_editor_visible()) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(editor);
}
} else {
Expand All @@ -418,7 +430,8 @@ void TileSetEditorPlugin::make_visible(bool p_visible) {
}

TileSetEditorPlugin::TileSetEditorPlugin() {
DEV_ASSERT(local_singleton);
DEV_ASSERT(tile_map_plugin_singleton);
tile_set_plugin_singleton = this;

editor = memnew(TileSetEditor);
editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
Expand All @@ -429,3 +442,7 @@ TileSetEditorPlugin::TileSetEditorPlugin() {
button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("TileSet"), editor);
button->hide();
}

TileSetEditorPlugin::~TileSetEditorPlugin() {
tile_set_plugin_singleton = nullptr;
}
5 changes: 5 additions & 0 deletions editor/plugins/tiles/tiles_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class TilesEditorUtils : public Object {
void set_sorting_option(int p_option);
List<int> get_sorted_sources(const Ref<TileSet> p_tile_set) const;

// Misc.
void display_tile_set_editor_panel();

static void draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color = Color(1.0, 1.0, 1.0));

TilesEditorUtils();
Expand Down Expand Up @@ -129,6 +132,7 @@ class TileMapEditorPlugin : public EditorPlugin {
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override;
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override;

void hide_editor();
bool is_editor_visible() const;

TileMapEditorPlugin();
Expand All @@ -147,6 +151,7 @@ class TileSetEditorPlugin : public EditorPlugin {
virtual void make_visible(bool p_visible) override;

TileSetEditorPlugin();
~TileSetEditorPlugin();
};

#endif // TILES_EDITOR_PLUGIN_H