mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-06 10:21:19 +00:00
Add read-only mode to AnimationTreeEditor plugins
This commit is contained in:
@@ -60,11 +60,29 @@ void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) {
|
||||
blend_space->disconnect("triangles_updated", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_changed));
|
||||
}
|
||||
blend_space = p_node;
|
||||
read_only = false;
|
||||
|
||||
if (!blend_space.is_null()) {
|
||||
read_only = EditorNode::get_singleton()->is_resource_read_only(blend_space);
|
||||
|
||||
blend_space->connect("triangles_updated", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_changed));
|
||||
_update_space();
|
||||
}
|
||||
|
||||
tool_create->set_disabled(read_only);
|
||||
interpolation->set_disabled(read_only);
|
||||
max_x_value->set_editable(!read_only);
|
||||
min_x_value->set_editable(!read_only);
|
||||
max_y_value->set_editable(!read_only);
|
||||
min_y_value->set_editable(!read_only);
|
||||
label_x->set_editable(!read_only);
|
||||
label_y->set_editable(!read_only);
|
||||
edit_x->set_editable(!read_only);
|
||||
edit_y->set_editable(!read_only);
|
||||
tool_triangle->set_disabled(read_only);
|
||||
auto_triangles->set_disabled(read_only);
|
||||
sync->set_disabled(read_only);
|
||||
interpolation->set_disabled(read_only);
|
||||
}
|
||||
|
||||
StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const {
|
||||
@@ -76,7 +94,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
Ref<InputEventKey> k = p_event;
|
||||
if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) {
|
||||
if (selected_point != -1 || selected_triangle != -1) {
|
||||
_erase_selected();
|
||||
if (!read_only) {
|
||||
_erase_selected();
|
||||
}
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
@@ -84,57 +104,59 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
Ref<InputEventMouseButton> mb = p_event;
|
||||
|
||||
if (mb.is_valid() && mb->is_pressed() && ((tool_select->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) || (mb->get_button_index() == MouseButton::LEFT && tool_create->is_pressed()))) {
|
||||
menu->clear();
|
||||
animations_menu->clear();
|
||||
animations_to_add.clear();
|
||||
List<StringName> classes;
|
||||
classes.sort_custom<StringName::AlphCompare>();
|
||||
if (!read_only) {
|
||||
menu->clear();
|
||||
animations_menu->clear();
|
||||
animations_to_add.clear();
|
||||
List<StringName> classes;
|
||||
classes.sort_custom<StringName::AlphCompare>();
|
||||
|
||||
ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
|
||||
menu->add_submenu_item(TTR("Add Animation"), "animations");
|
||||
ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
|
||||
menu->add_submenu_item(TTR("Add Animation"), "animations");
|
||||
|
||||
AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree();
|
||||
ERR_FAIL_COND(!gp);
|
||||
if (gp && gp->has_node(gp->get_animation_player())) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
|
||||
if (ap) {
|
||||
List<StringName> names;
|
||||
ap->get_animation_list(&names);
|
||||
for (const StringName &E : names) {
|
||||
animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E);
|
||||
animations_to_add.push_back(E);
|
||||
AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree();
|
||||
ERR_FAIL_COND(!gp);
|
||||
if (gp && gp->has_node(gp->get_animation_player())) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
|
||||
if (ap) {
|
||||
List<StringName> names;
|
||||
ap->get_animation_list(&names);
|
||||
for (const StringName &E : names) {
|
||||
animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E);
|
||||
animations_to_add.push_back(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const StringName &E : classes) {
|
||||
String name = String(E).replace_first("AnimationNode", "");
|
||||
if (name == "Animation" || name == "StartState" || name == "EndState") {
|
||||
continue; // nope
|
||||
for (const StringName &E : classes) {
|
||||
String name = String(E).replace_first("AnimationNode", "");
|
||||
if (name == "Animation" || name == "StartState" || name == "EndState") {
|
||||
continue; // nope
|
||||
}
|
||||
int idx = menu->get_item_count();
|
||||
menu->add_item(vformat(TTR("Add %s"), name), idx);
|
||||
menu->set_item_metadata(idx, E);
|
||||
}
|
||||
int idx = menu->get_item_count();
|
||||
menu->add_item(vformat(TTR("Add %s"), name), idx);
|
||||
menu->set_item_metadata(idx, E);
|
||||
}
|
||||
|
||||
Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
|
||||
if (clipb.is_valid()) {
|
||||
Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
|
||||
if (clipb.is_valid()) {
|
||||
menu->add_separator();
|
||||
menu->add_item(TTR("Paste"), MENU_PASTE);
|
||||
}
|
||||
menu->add_separator();
|
||||
menu->add_item(TTR("Paste"), MENU_PASTE);
|
||||
}
|
||||
menu->add_separator();
|
||||
menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
|
||||
menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
|
||||
|
||||
menu->set_position(blend_space_draw->get_screen_position() + mb->get_position());
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
add_point_pos = (mb->get_position() / blend_space_draw->get_size());
|
||||
add_point_pos.y = 1.0 - add_point_pos.y;
|
||||
add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
|
||||
add_point_pos += blend_space->get_min_space();
|
||||
menu->set_position(blend_space_draw->get_screen_position() + mb->get_position());
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
add_point_pos = (mb->get_position() / blend_space_draw->get_size());
|
||||
add_point_pos.y = 1.0 - add_point_pos.y;
|
||||
add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
|
||||
add_point_pos += blend_space->get_min_space();
|
||||
|
||||
if (snap->is_pressed()) {
|
||||
add_point_pos = add_point_pos.snapped(blend_space->get_snap());
|
||||
if (snap->is_pressed()) {
|
||||
add_point_pos = add_point_pos.snapped(blend_space->get_snap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,17 +244,19 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
point = point.snapped(blend_space->get_snap());
|
||||
}
|
||||
|
||||
updating = true;
|
||||
undo_redo->create_action(TTR("Move Node Point"));
|
||||
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
|
||||
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
|
||||
undo_redo->add_do_method(this, "_update_space");
|
||||
undo_redo->add_undo_method(this, "_update_space");
|
||||
undo_redo->add_do_method(this, "_update_edited_point_pos");
|
||||
undo_redo->add_undo_method(this, "_update_edited_point_pos");
|
||||
undo_redo->commit_action();
|
||||
updating = false;
|
||||
_update_edited_point_pos();
|
||||
if (!read_only) {
|
||||
updating = true;
|
||||
undo_redo->create_action(TTR("Move Node Point"));
|
||||
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
|
||||
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
|
||||
undo_redo->add_do_method(this, "_update_space");
|
||||
undo_redo->add_undo_method(this, "_update_space");
|
||||
undo_redo->add_do_method(this, "_update_edited_point_pos");
|
||||
undo_redo->add_undo_method(this, "_update_edited_point_pos");
|
||||
undo_redo->commit_action();
|
||||
updating = false;
|
||||
_update_edited_point_pos();
|
||||
}
|
||||
}
|
||||
dragging_selected_attempt = false;
|
||||
dragging_selected = false;
|
||||
@@ -259,7 +283,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
|
||||
if (mm.is_valid() && dragging_selected_attempt) {
|
||||
dragging_selected = true;
|
||||
drag_ofs = ((mm->get_position() - drag_from) / blend_space_draw->get_size()) * (blend_space->get_max_space() - blend_space->get_min_space()) * Vector2(1, -1);
|
||||
if (!read_only) {
|
||||
drag_ofs = ((mm->get_position() - drag_from) / blend_space_draw->get_size()) * (blend_space->get_max_space() - blend_space->get_min_space()) * Vector2(1, -1);
|
||||
}
|
||||
blend_space_draw->update();
|
||||
_update_edited_point_pos();
|
||||
}
|
||||
@@ -355,7 +381,10 @@ void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) {
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2DEditor::_update_tool_erase() {
|
||||
tool_erase->set_disabled(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count()));
|
||||
tool_erase->set_disabled(
|
||||
(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count())) ||
|
||||
read_only);
|
||||
|
||||
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
|
||||
Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
|
||||
if (AnimationTreeEditor::get_singleton()->can_edit(an)) {
|
||||
@@ -363,7 +392,11 @@ void AnimationNodeBlendSpace2DEditor::_update_tool_erase() {
|
||||
} else {
|
||||
open_editor->hide();
|
||||
}
|
||||
edit_hb->show();
|
||||
if (!read_only) {
|
||||
edit_hb->show();
|
||||
} else {
|
||||
edit_hb->hide();
|
||||
}
|
||||
} else {
|
||||
edit_hb->hide();
|
||||
}
|
||||
@@ -503,10 +536,12 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
|
||||
points.clear();
|
||||
for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
|
||||
Vector2 point = blend_space->get_blend_point_position(i);
|
||||
if (dragging_selected && selected_point == i) {
|
||||
point += drag_ofs;
|
||||
if (snap->is_pressed()) {
|
||||
point = point.snapped(blend_space->get_snap());
|
||||
if (!read_only) {
|
||||
if (dragging_selected && selected_point == i) {
|
||||
point += drag_ofs;
|
||||
if (snap->is_pressed()) {
|
||||
point = point.snapped(blend_space->get_snap());
|
||||
}
|
||||
}
|
||||
}
|
||||
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
|
||||
|
||||
Reference in New Issue
Block a user