Merge pull request #65419 from SaracenOne/tileset_read_only
Add read-only mode to tileset editor
This commit is contained in:
commit
cb6dea8513
@ -266,7 +266,7 @@ void TileMapEditorTilesPlugin::_patterns_item_list_gui_input(const Ref<InputEven
|
||||
}
|
||||
|
||||
Ref<TileSet> tile_set = tile_map->get_tileset();
|
||||
if (!tile_set.is_valid()) {
|
||||
if (!tile_set.is_valid() || EditorNode::get_singleton()->is_resource_read_only(tile_set)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1277,13 +1277,15 @@ void TileMapEditorTilesPlugin::_stop_dragging() {
|
||||
tile_map->set_cell(tile_map_layer, kv.key, kv.value.source_id, kv.value.get_atlas_coords(), kv.value.alternative_tile);
|
||||
}
|
||||
|
||||
// Creating a pattern in the pattern list.
|
||||
select_last_pattern = true;
|
||||
int new_pattern_index = tile_set->get_patterns_count();
|
||||
undo_redo->create_action(TTR("Add TileSet pattern"));
|
||||
undo_redo->add_do_method(*tile_set, "add_pattern", selection_pattern, new_pattern_index);
|
||||
undo_redo->add_undo_method(*tile_set, "remove_pattern", new_pattern_index);
|
||||
undo_redo->commit_action();
|
||||
if (EditorNode::get_singleton()->is_resource_read_only(tile_set)) {
|
||||
// Creating a pattern in the pattern list.
|
||||
select_last_pattern = true;
|
||||
int new_pattern_index = tile_set->get_patterns_count();
|
||||
undo_redo->create_action(TTR("Add TileSet pattern"));
|
||||
undo_redo->add_do_method(*tile_set, "add_pattern", selection_pattern, new_pattern_index);
|
||||
undo_redo->add_undo_method(*tile_set, "remove_pattern", new_pattern_index);
|
||||
undo_redo->commit_action();
|
||||
}
|
||||
} else {
|
||||
// Get the top-left cell.
|
||||
Vector2i top_left;
|
||||
@ -1989,6 +1991,15 @@ TypedArray<Vector2i> TileMapEditorTilesPlugin::_get_tile_map_selection() const {
|
||||
void TileMapEditorTilesPlugin::edit(ObjectID p_tile_map_id, int p_tile_map_layer) {
|
||||
_stop_dragging(); // Avoids staying in a wrong drag state.
|
||||
|
||||
// Disable sort button if the tileset is read-only
|
||||
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
|
||||
if (tile_map) {
|
||||
Ref<TileSet> tile_set = tile_map->get_tileset();
|
||||
if (tile_set.is_valid()) {
|
||||
source_sort_button->set_disabled(EditorNode::get_singleton()->is_resource_read_only(tile_set));
|
||||
}
|
||||
}
|
||||
|
||||
if (tile_map_id != p_tile_map_id) {
|
||||
tile_map_id = p_tile_map_id;
|
||||
|
||||
|
@ -585,6 +585,7 @@ void TileSetAtlasSourceEditor::_update_atlas_source_inspector() {
|
||||
// Update visibility.
|
||||
bool inspector_visible = tools_button_group->get_pressed_button() == tool_setup_atlas_source_button;
|
||||
atlas_source_inspector->set_visible(inspector_visible);
|
||||
atlas_source_inspector->set_read_only(read_only);
|
||||
}
|
||||
|
||||
void TileSetAtlasSourceEditor::_update_tile_inspector() {
|
||||
@ -599,6 +600,7 @@ void TileSetAtlasSourceEditor::_update_tile_inspector() {
|
||||
tile_inspector->hide();
|
||||
tile_inspector_no_tile_selected_label->hide();
|
||||
}
|
||||
tile_inspector->set_read_only(read_only);
|
||||
}
|
||||
|
||||
void TileSetAtlasSourceEditor::_update_tile_data_editors() {
|
||||
@ -970,19 +972,19 @@ void TileSetAtlasSourceEditor::_update_toolbar() {
|
||||
current_tile_data_editor_toolbar->hide();
|
||||
}
|
||||
tools_settings_erase_button->show();
|
||||
tool_advanced_menu_buttom->show();
|
||||
tool_advanced_menu_button->show();
|
||||
} else if (tools_button_group->get_pressed_button() == tool_select_button) {
|
||||
if (current_tile_data_editor_toolbar) {
|
||||
current_tile_data_editor_toolbar->hide();
|
||||
}
|
||||
tools_settings_erase_button->hide();
|
||||
tool_advanced_menu_buttom->hide();
|
||||
tool_advanced_menu_button->hide();
|
||||
} else if (tools_button_group->get_pressed_button() == tool_paint_button) {
|
||||
if (current_tile_data_editor_toolbar) {
|
||||
current_tile_data_editor_toolbar->show();
|
||||
}
|
||||
tools_settings_erase_button->hide();
|
||||
tool_advanced_menu_buttom->hide();
|
||||
tool_advanced_menu_button->hide();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2188,7 +2190,12 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
|
||||
ERR_FAIL_COND(p_source_id < 0);
|
||||
ERR_FAIL_COND(p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source);
|
||||
|
||||
if (p_tile_set == tile_set && p_tile_set_atlas_source == tile_set_atlas_source && p_source_id == tile_set_atlas_source_id) {
|
||||
bool new_read_only_state = false;
|
||||
if (p_tile_set.is_valid()) {
|
||||
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_tile_set);
|
||||
}
|
||||
|
||||
if (p_tile_set == tile_set && p_tile_set_atlas_source == tile_set_atlas_source && p_source_id == tile_set_atlas_source_id && new_read_only_state == read_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2205,11 +2212,23 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
|
||||
tile_set_atlas_source = p_tile_set_atlas_source;
|
||||
tile_set_atlas_source_id = p_source_id;
|
||||
|
||||
// Add the listener again.
|
||||
// Read-only is off by default.
|
||||
read_only = new_read_only_state;
|
||||
|
||||
if (tile_set.is_valid()) {
|
||||
tile_set->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_changed));
|
||||
}
|
||||
|
||||
if (read_only && tools_button_group->get_pressed_button() == tool_paint_button) {
|
||||
tool_paint_button->set_pressed(false);
|
||||
tool_setup_atlas_source_button->set_pressed(true);
|
||||
}
|
||||
|
||||
// Disable buttons in read-only mode.
|
||||
tool_paint_button->set_disabled(read_only);
|
||||
tools_settings_erase_button->set_disabled(read_only);
|
||||
tool_advanced_menu_button->set_disabled(read_only);
|
||||
|
||||
// Update everything.
|
||||
_update_source_inspector();
|
||||
|
||||
@ -2344,7 +2363,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
|
||||
|
||||
tools_settings_erase_button->set_icon(get_theme_icon(SNAME("Eraser"), SNAME("EditorIcons")));
|
||||
|
||||
tool_advanced_menu_buttom->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
|
||||
tool_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
|
||||
|
||||
resize_handle = get_theme_icon(SNAME("EditorHandle"), SNAME("EditorIcons"));
|
||||
resize_handle_disabled = get_theme_icon(SNAME("EditorHandleDisabled"), SNAME("EditorIcons"));
|
||||
@ -2352,6 +2371,18 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
if (tile_set_changed_needs_update) {
|
||||
// Read-only is off by default
|
||||
read_only = false;
|
||||
// Add the listener again and check for read-only status.
|
||||
if (tile_set.is_valid()) {
|
||||
read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
|
||||
}
|
||||
|
||||
// Disable buttons in read-only mode.
|
||||
tool_paint_button->set_disabled(read_only);
|
||||
tools_settings_erase_button->set_disabled(read_only);
|
||||
tool_advanced_menu_button->set_disabled(read_only);
|
||||
|
||||
// Update everything.
|
||||
_update_source_inspector();
|
||||
|
||||
@ -2516,12 +2547,12 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
|
||||
tools_settings_erase_button->set_shortcut_context(this);
|
||||
tool_settings->add_child(tools_settings_erase_button);
|
||||
|
||||
tool_advanced_menu_buttom = memnew(MenuButton);
|
||||
tool_advanced_menu_buttom->set_flat(true);
|
||||
tool_advanced_menu_buttom->get_popup()->add_item(TTR("Create Tiles in Non-Transparent Texture Regions"), ADVANCED_AUTO_CREATE_TILES);
|
||||
tool_advanced_menu_buttom->get_popup()->add_item(TTR("Remove Tiles in Fully Transparent Texture Regions"), ADVANCED_AUTO_REMOVE_TILES);
|
||||
tool_advanced_menu_buttom->get_popup()->connect("id_pressed", callable_mp(this, &TileSetAtlasSourceEditor::_menu_option));
|
||||
tool_settings->add_child(tool_advanced_menu_buttom);
|
||||
tool_advanced_menu_button = memnew(MenuButton);
|
||||
tool_advanced_menu_button->set_flat(true);
|
||||
tool_advanced_menu_button->get_popup()->add_item(TTR("Create Tiles in Non-Transparent Texture Regions"), ADVANCED_AUTO_CREATE_TILES);
|
||||
tool_advanced_menu_button->get_popup()->add_item(TTR("Remove Tiles in Fully Transparent Texture Regions"), ADVANCED_AUTO_REMOVE_TILES);
|
||||
tool_advanced_menu_button->get_popup()->connect("id_pressed", callable_mp(this, &TileSetAtlasSourceEditor::_menu_option));
|
||||
tool_settings->add_child(tool_advanced_menu_button);
|
||||
|
||||
_update_toolbar();
|
||||
|
||||
|
@ -113,6 +113,8 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
bool read_only = false;
|
||||
|
||||
Ref<TileSet> tile_set;
|
||||
TileSetAtlasSource *tile_set_atlas_source = nullptr;
|
||||
int tile_set_atlas_source_id = TileSet::INVALID_SOURCE;
|
||||
@ -209,7 +211,7 @@ private:
|
||||
HBoxContainer *tool_settings = nullptr;
|
||||
HBoxContainer *tool_settings_tile_data_toolbar_container = nullptr;
|
||||
Button *tools_settings_erase_button = nullptr;
|
||||
MenuButton *tool_advanced_menu_buttom = nullptr;
|
||||
MenuButton *tool_advanced_menu_button = nullptr;
|
||||
|
||||
// Selection.
|
||||
RBSet<TileSelection> selection;
|
||||
|
@ -89,6 +89,10 @@ void TileSetEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data,
|
||||
bool TileSetEditor::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
||||
ERR_FAIL_COND_V(!tile_set.is_valid(), false);
|
||||
|
||||
if (read_only) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p_from == sources_list) {
|
||||
Dictionary d = p_data;
|
||||
|
||||
@ -223,7 +227,7 @@ void TileSetEditor::_source_selected(int p_source_index) {
|
||||
ERR_FAIL_COND(!tile_set.is_valid());
|
||||
|
||||
// Update the selected source.
|
||||
sources_delete_button->set_disabled(p_source_index < 0);
|
||||
sources_delete_button->set_disabled(p_source_index < 0 || read_only);
|
||||
|
||||
if (p_source_index >= 0) {
|
||||
int source_id = sources_list->get_item_metadata(p_source_index);
|
||||
@ -356,8 +360,19 @@ void TileSetEditor::_notification(int p_what) {
|
||||
if (tile_set.is_valid()) {
|
||||
tile_set->set_edited(true);
|
||||
}
|
||||
|
||||
read_only = false;
|
||||
if (tile_set.is_valid()) {
|
||||
read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
|
||||
}
|
||||
|
||||
_update_sources_list();
|
||||
_update_patterns_list();
|
||||
|
||||
sources_add_button->set_disabled(read_only);
|
||||
sources_advanced_menu_button->set_disabled(read_only);
|
||||
source_sort_button->set_disabled(read_only);
|
||||
|
||||
tile_set_changed_needs_update = false;
|
||||
}
|
||||
} break;
|
||||
@ -367,6 +382,10 @@ void TileSetEditor::_notification(int p_what) {
|
||||
void TileSetEditor::_patterns_item_list_gui_input(const Ref<InputEvent> &p_event) {
|
||||
ERR_FAIL_COND(!tile_set.is_valid());
|
||||
|
||||
if (EditorNode::get_singleton()->is_resource_read_only(tile_set)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
|
||||
Vector<int> selected = patterns_item_list->get_selected_items();
|
||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||
@ -667,7 +686,12 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p
|
||||
}
|
||||
|
||||
void TileSetEditor::edit(Ref<TileSet> p_tile_set) {
|
||||
if (p_tile_set == tile_set) {
|
||||
bool new_read_only_state = false;
|
||||
if (tile_set.is_valid()) {
|
||||
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_tile_set);
|
||||
}
|
||||
|
||||
if (p_tile_set == tile_set && new_read_only_state == read_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -679,8 +703,15 @@ void TileSetEditor::edit(Ref<TileSet> p_tile_set) {
|
||||
// Change the edited object.
|
||||
tile_set = p_tile_set;
|
||||
|
||||
// Add the listener again.
|
||||
// Read-only status is false by default
|
||||
read_only = new_read_only_state;
|
||||
|
||||
// Add the listener again and check for read-only status.
|
||||
if (tile_set.is_valid()) {
|
||||
sources_add_button->set_disabled(read_only);
|
||||
sources_advanced_menu_button->set_disabled(read_only);
|
||||
source_sort_button->set_disabled(read_only);
|
||||
|
||||
tile_set->connect("changed", callable_mp(this, &TileSetEditor::_tile_set_changed));
|
||||
if (first_edit) {
|
||||
first_edit = false;
|
||||
@ -690,10 +721,6 @@ void TileSetEditor::edit(Ref<TileSet> p_tile_set) {
|
||||
}
|
||||
_update_patterns_list();
|
||||
}
|
||||
|
||||
tile_set_atlas_source_editor->hide();
|
||||
tile_set_scenes_collection_source_editor->hide();
|
||||
no_source_selected_label->show();
|
||||
}
|
||||
|
||||
TileSetEditor::TileSetEditor() {
|
||||
|
@ -45,6 +45,8 @@ class TileSetEditor : public VBoxContainer {
|
||||
static TileSetEditor *singleton;
|
||||
|
||||
private:
|
||||
bool read_only = false;
|
||||
|
||||
Ref<TileSet> tile_set;
|
||||
bool tile_set_changed_needs_update = false;
|
||||
HSplitContainer *split_container = nullptr;
|
||||
|
@ -284,7 +284,7 @@ void TileSetScenesCollectionSourceEditor::_update_tile_inspector() {
|
||||
|
||||
void TileSetScenesCollectionSourceEditor::_update_action_buttons() {
|
||||
Vector<int> selected_indices = scene_tiles_list->get_selected_items();
|
||||
scene_tile_delete_button->set_disabled(selected_indices.size() <= 0);
|
||||
scene_tile_delete_button->set_disabled(selected_indices.size() <= 0 || read_only);
|
||||
}
|
||||
|
||||
void TileSetScenesCollectionSourceEditor::_update_scenes_list() {
|
||||
@ -342,6 +342,12 @@ void TileSetScenesCollectionSourceEditor::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
if (tile_set_scenes_collection_source_changed_needs_update) {
|
||||
read_only = false;
|
||||
// Add the listener again and check for read-only status.
|
||||
if (tile_set.is_valid()) {
|
||||
read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
|
||||
}
|
||||
|
||||
// Update everything.
|
||||
_update_source_inspector();
|
||||
_update_scenes_list();
|
||||
@ -365,7 +371,12 @@ void TileSetScenesCollectionSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetS
|
||||
ERR_FAIL_COND(p_source_id < 0);
|
||||
ERR_FAIL_COND(p_tile_set->get_source(p_source_id) != p_tile_set_scenes_collection_source);
|
||||
|
||||
if (p_tile_set == tile_set && p_tile_set_scenes_collection_source == tile_set_scenes_collection_source && p_source_id == tile_set_source_id) {
|
||||
bool new_read_only_state = false;
|
||||
if (p_tile_set.is_valid()) {
|
||||
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_tile_set);
|
||||
}
|
||||
|
||||
if (p_tile_set == tile_set && p_tile_set_scenes_collection_source == tile_set_scenes_collection_source && p_source_id == tile_set_source_id && new_read_only_state == read_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,6 +390,16 @@ void TileSetScenesCollectionSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetS
|
||||
tile_set_scenes_collection_source = p_tile_set_scenes_collection_source;
|
||||
tile_set_source_id = p_source_id;
|
||||
|
||||
// Read-only status is false by default
|
||||
read_only = new_read_only_state;
|
||||
|
||||
if (tile_set.is_valid()) {
|
||||
scenes_collection_source_inspector->set_read_only(read_only);
|
||||
tile_inspector->set_read_only(read_only);
|
||||
|
||||
scene_tile_add_button->set_disabled(read_only);
|
||||
}
|
||||
|
||||
// Add the listener again.
|
||||
if (tile_set_scenes_collection_source) {
|
||||
tile_set_scenes_collection_source->connect("changed", callable_mp(this, &TileSetScenesCollectionSourceEditor::_tile_set_scenes_collection_source_changed));
|
||||
|
@ -91,6 +91,8 @@ private:
|
||||
};
|
||||
|
||||
private:
|
||||
bool read_only = false;
|
||||
|
||||
Ref<TileSet> tile_set;
|
||||
TileSetScenesCollectionSource *tile_set_scenes_collection_source = nullptr;
|
||||
int tile_set_source_id = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user