Undo support for locking and grouping for both 2D and 3D
This commit is contained in:
parent
260530f01c
commit
d1fa546dc9
5 changed files with 93 additions and 31 deletions
|
@ -1059,6 +1059,10 @@ Variant Object::get_meta(const String &p_name) const {
|
|||
return metadata[p_name];
|
||||
}
|
||||
|
||||
void Object::remove_meta(const String &p_name) {
|
||||
metadata.erase(p_name);
|
||||
}
|
||||
|
||||
Array Object::_get_property_list_bind() const {
|
||||
|
||||
List<PropertyInfo> lpi;
|
||||
|
@ -1691,6 +1695,7 @@ void Object::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_script"), &Object::get_script);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_meta", "name", "value"), &Object::set_meta);
|
||||
ClassDB::bind_method(D_METHOD("remove_meta", "name"), &Object::remove_meta);
|
||||
ClassDB::bind_method(D_METHOD("get_meta", "name"), &Object::get_meta);
|
||||
ClassDB::bind_method(D_METHOD("has_meta", "name"), &Object::has_meta);
|
||||
ClassDB::bind_method(D_METHOD("get_meta_list"), &Object::_get_meta_list_bind);
|
||||
|
|
|
@ -673,6 +673,7 @@ public:
|
|||
|
||||
bool has_meta(const String &p_name) const;
|
||||
void set_meta(const String &p_name, const Variant &p_value);
|
||||
void remove_meta(const String &p_name);
|
||||
Variant get_meta(const String &p_name) const;
|
||||
void get_meta_list(List<String> *p_list) const;
|
||||
|
||||
|
|
|
@ -3916,6 +3916,8 @@ void CanvasItemEditor::_popup_callback(int p_op) {
|
|||
viewport->update();
|
||||
} break;
|
||||
case LOCK_SELECTED: {
|
||||
undo_redo->create_action(TTR("Lock Selected"));
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
||||
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
||||
|
@ -3924,12 +3926,18 @@ void CanvasItemEditor::_popup_callback(int p_op) {
|
|||
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
canvas_item->set_meta("_edit_lock_", true);
|
||||
emit_signal("item_lock_status_changed");
|
||||
undo_redo->add_do_method(canvas_item, "set_meta", "_edit_lock_", true);
|
||||
undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_lock_");
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_lock_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_lock_status_changed");
|
||||
}
|
||||
viewport->update();
|
||||
undo_redo->add_do_method(viewport, "update", Variant());
|
||||
undo_redo->add_undo_method(viewport, "update", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case UNLOCK_SELECTED: {
|
||||
undo_redo->create_action(TTR("Unlock Selected"));
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
||||
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
||||
|
@ -3938,12 +3946,18 @@ void CanvasItemEditor::_popup_callback(int p_op) {
|
|||
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
canvas_item->set_meta("_edit_lock_", Variant());
|
||||
emit_signal("item_lock_status_changed");
|
||||
undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_lock_");
|
||||
undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_lock_", true);
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_lock_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_lock_status_changed");
|
||||
}
|
||||
viewport->update();
|
||||
undo_redo->add_do_method(viewport, "update", Variant());
|
||||
undo_redo->add_undo_method(viewport, "update", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case GROUP_SELECTED: {
|
||||
undo_redo->create_action(TTR("Group Selected"));
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
||||
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
||||
|
@ -3952,12 +3966,18 @@ void CanvasItemEditor::_popup_callback(int p_op) {
|
|||
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
canvas_item->set_meta("_edit_group_", true);
|
||||
emit_signal("item_group_status_changed");
|
||||
undo_redo->add_do_method(canvas_item, "set_meta", "_edit_group_", true);
|
||||
undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_group_");
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_group_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_group_status_changed");
|
||||
}
|
||||
viewport->update();
|
||||
undo_redo->add_do_method(viewport, "update", Variant());
|
||||
undo_redo->add_undo_method(viewport, "update", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case UNGROUP_SELECTED: {
|
||||
undo_redo->create_action(TTR("Ungroup Selected"));
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
||||
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
||||
|
@ -3966,10 +3986,14 @@ void CanvasItemEditor::_popup_callback(int p_op) {
|
|||
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
canvas_item->set_meta("_edit_group_", Variant());
|
||||
emit_signal("item_group_status_changed");
|
||||
undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_group_");
|
||||
undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_group_", true);
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_group_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_group_status_changed");
|
||||
}
|
||||
viewport->update();
|
||||
undo_redo->add_do_method(viewport, "update", Variant());
|
||||
undo_redo->add_undo_method(viewport, "update", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case ANCHORS_AND_MARGINS_PRESET_TOP_LEFT: {
|
||||
_set_anchors_and_margins_preset(PRESET_TOP_LEFT);
|
||||
|
|
|
@ -4515,6 +4515,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
|
|||
snap_selected_nodes_to_floor();
|
||||
} break;
|
||||
case MENU_LOCK_SELECTED: {
|
||||
undo_redo->create_action(TTR("Lock Selected"));
|
||||
|
||||
List<Node *> &selection = editor_selection->get_selected_node_list();
|
||||
|
||||
|
@ -4527,13 +4528,18 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
|
|||
if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
spatial->set_meta("_edit_lock_", true);
|
||||
emit_signal("item_lock_status_changed");
|
||||
undo_redo->add_do_method(spatial, "set_meta", "_edit_lock_", true);
|
||||
undo_redo->add_undo_method(spatial, "remove_meta", "_edit_lock_");
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_lock_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_lock_status_changed");
|
||||
}
|
||||
|
||||
_refresh_menu_icons();
|
||||
undo_redo->add_do_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->add_undo_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case MENU_UNLOCK_SELECTED: {
|
||||
undo_redo->create_action(TTR("Unlock Selected"));
|
||||
|
||||
List<Node *> &selection = editor_selection->get_selected_node_list();
|
||||
|
||||
|
@ -4546,13 +4552,18 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
|
|||
if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
spatial->set_meta("_edit_lock_", Variant());
|
||||
emit_signal("item_lock_status_changed");
|
||||
undo_redo->add_do_method(spatial, "remove_meta", "_edit_lock_");
|
||||
undo_redo->add_undo_method(spatial, "set_meta", "_edit_lock_", true);
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_lock_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_lock_status_changed");
|
||||
}
|
||||
|
||||
_refresh_menu_icons();
|
||||
undo_redo->add_do_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->add_undo_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case MENU_GROUP_SELECTED: {
|
||||
undo_redo->create_action(TTR("Group Selected"));
|
||||
|
||||
List<Node *> &selection = editor_selection->get_selected_node_list();
|
||||
|
||||
|
@ -4565,14 +4576,18 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
|
|||
if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
spatial->set_meta("_edit_group_", true);
|
||||
emit_signal("item_group_status_changed");
|
||||
undo_redo->add_do_method(spatial, "set_meta", "_edit_group_", true);
|
||||
undo_redo->add_undo_method(spatial, "remove_meta", "_edit_group_");
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_group_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_group_status_changed");
|
||||
}
|
||||
|
||||
_refresh_menu_icons();
|
||||
undo_redo->add_do_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->add_undo_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case MENU_UNGROUP_SELECTED: {
|
||||
|
||||
undo_redo->create_action(TTR("Ungroup Selected"));
|
||||
List<Node *> &selection = editor_selection->get_selected_node_list();
|
||||
|
||||
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
||||
|
@ -4584,11 +4599,15 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
|
|||
if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
||||
continue;
|
||||
|
||||
spatial->set_meta("_edit_group_", Variant());
|
||||
emit_signal("item_group_status_changed");
|
||||
undo_redo->add_do_method(spatial, "remove_meta", "_edit_group_");
|
||||
undo_redo->add_undo_method(spatial, "set_meta", "_edit_group_", true);
|
||||
undo_redo->add_do_method(this, "emit_signal", "item_group_status_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "item_group_status_changed");
|
||||
}
|
||||
|
||||
_refresh_menu_icons();
|
||||
undo_redo->add_do_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->add_undo_method(this, "_refresh_menu_icons", Variant());
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,12 +88,18 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
|
|||
}
|
||||
undo_redo->commit_action();
|
||||
} else if (p_id == BUTTON_LOCK) {
|
||||
undo_redo->create_action(TTR("Unlock Node"));
|
||||
|
||||
if (n->is_class("CanvasItem") || n->is_class("Spatial")) {
|
||||
n->set_meta("_edit_lock_", Variant());
|
||||
_update_tree();
|
||||
emit_signal("node_changed");
|
||||
|
||||
undo_redo->add_do_method(n, "remove_meta", "_edit_lock_");
|
||||
undo_redo->add_undo_method(n, "set_meta", "_edit_lock_", true);
|
||||
undo_redo->add_do_method(this, "_update_tree", Variant());
|
||||
undo_redo->add_undo_method(this, "_update_tree", Variant());
|
||||
undo_redo->add_do_method(this, "emit_signal", "node_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "node_changed");
|
||||
}
|
||||
undo_redo->commit_action();
|
||||
} else if (p_id == BUTTON_PIN) {
|
||||
|
||||
if (n->is_class("AnimationPlayer")) {
|
||||
|
@ -102,11 +108,18 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
|
|||
}
|
||||
|
||||
} else if (p_id == BUTTON_GROUP) {
|
||||
undo_redo->create_action(TTR("Button Group"));
|
||||
|
||||
if (n->is_class("CanvasItem") || n->is_class("Spatial")) {
|
||||
n->set_meta("_edit_group_", Variant());
|
||||
_update_tree();
|
||||
emit_signal("node_changed");
|
||||
|
||||
undo_redo->add_do_method(n, "remove_meta", "_edit_group_");
|
||||
undo_redo->add_undo_method(n, "set_meta", "_edit_group_", true);
|
||||
undo_redo->add_do_method(this, "_update_tree", Variant());
|
||||
undo_redo->add_undo_method(this, "_update_tree", Variant());
|
||||
undo_redo->add_do_method(this, "emit_signal", "node_changed");
|
||||
undo_redo->add_undo_method(this, "emit_signal", "node_changed");
|
||||
}
|
||||
undo_redo->commit_action();
|
||||
} else if (p_id == BUTTON_WARNING) {
|
||||
|
||||
String config_err = n->get_configuration_warning();
|
||||
|
|
Loading…
Reference in a new issue