瀏覽代碼

Added button/shortcut for removing all guides

Added undo/redo


Correctly added has_meta
shaderbeast 6 年之前
父節點
當前提交
c6fb6a6a21
共有 2 個文件被更改,包括 23 次插入0 次删除
  1. 22 0
      editor/plugins/canvas_item_editor_plugin.cpp
  2. 1 0
      editor/plugins/canvas_item_editor_plugin.h

+ 22 - 0
editor/plugins/canvas_item_editor_plugin.cpp

@@ -4348,6 +4348,27 @@ void CanvasItemEditor::_popup_callback(int p_op) {
 				}
 			}
 
+		} break;
+		case CLEAR_GUIDES: {
+
+			if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_") || EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
+				undo_redo->create_action(TTR("Clear Guides"));
+				if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
+					Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
+
+					undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", Array());
+					undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
+				}
+				if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
+					Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
+
+					undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", Array());
+					undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
+				}
+				undo_redo->add_undo_method(viewport, "update");
+				undo_redo->commit_action();
+			}
+
 		} break;
 		case VIEW_CENTER_TO_SELECTION:
 		case VIEW_FRAME_TO_SELECTION: {
@@ -5077,6 +5098,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
 	p->add_separator();
 	p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION);
 	p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION);
+	p->add_shortcut(ED_SHORTCUT("canvas_item_editor/clear_guides", TTR("Clear Guides")), CLEAR_GUIDES);
 	p->add_separator();
 	p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE);
 

+ 1 - 0
editor/plugins/canvas_item_editor_plugin.h

@@ -170,6 +170,7 @@ private:
 		ANIM_COPY_POSE,
 		ANIM_PASTE_POSE,
 		ANIM_CLEAR_POSE,
+		CLEAR_GUIDES,
 		VIEW_CENTER_TO_SELECTION,
 		VIEW_FRAME_TO_SELECTION,
 		PREVIEW_CANVAS_SCALE,