Skip to content

Commit

Permalink
Add read only mode to SpriteFrames editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaracenOne committed Sep 6, 2022
1 parent b8977ca commit 15e2ddb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,17 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}

void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
if (frames == p_frames) {
bool new_read_only_state = false;
if (p_frames) {
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_frames);
}

if (frames == p_frames && new_read_only_state == read_only) {
return;
}

frames = p_frames;
read_only = new_read_only_state;

if (p_frames) {
if (!p_frames->has_animation(edited_anim)) {
Expand All @@ -1009,13 +1015,31 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
} else {
hide();
}

new_anim->set_disabled(read_only);
remove_anim->set_disabled(read_only);
anim_speed->set_editable(!read_only);
anim_loop->set_disabled(read_only);
load->set_disabled(read_only);
load_sheet->set_disabled(read_only);
copy->set_disabled(read_only);
paste->set_disabled(read_only);
empty->set_disabled(read_only);
empty2->set_disabled(read_only);
move_up->set_disabled(read_only);
move_down->set_disabled(read_only);
_delete->set_disabled(read_only);
}

void SpriteFramesEditor::set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo) {
undo_redo = p_undo_redo;
}

Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (read_only) {
return false;
}

if (!frames->has_animation(edited_anim)) {
return false;
}
Expand All @@ -1038,6 +1062,10 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
}

bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (read_only) {
return false;
}

Dictionary d = p_data;

if (!d.has("type")) {
Expand Down Expand Up @@ -1169,6 +1197,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
remove_anim->set_flat(true);
remove_anim->set_tooltip_text(TTR("Remove Animation"));
hbc_animlist->add_child(remove_anim);
remove_anim->set_disabled(true);
remove_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_remove));

anim_search_box = memnew(LineEdit);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/sprite_frames_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class SpriteFramesEditor : public HSplitContainer {
};
int dominant_param = PARAM_FRAME_COUNT;

bool read_only = false;

Button *load = nullptr;
Button *load_sheet = nullptr;
Button *_delete = nullptr;
Expand Down

0 comments on commit 15e2ddb

Please sign in to comment.