Repository: godotengine/godot
File: editor/plugins/cast_2d_editor_plugin.cpp (C++)

Code before:

bool Cast2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
	if (!node || !node->is_visible_in_tree()) {
		return false;
	}

	Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();

	Ref<InputEventMouseButton> mb = p_event;
	if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
		Vector2 target_position = node->get("target_position");

		if (mb->is_pressed()) {
			if (xform.xform(target_position).distance_to(mb->get_position()) < 8) {
				pressed = true;
				original_target_position = target_position;

				return true;
			} else {
				pressed = false;

				return false;
			}
		} else if (pressed) {
			EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
			undo_redo->create_action(TTR("Set target_position"));
			undo_redo->add_do_property(node, "target_position", target_position);
			undo_redo->add_do_method(canvas_item_editor, "update_viewport");
			undo_redo->add_undo_property(node, "target_position", original_target_position);
			undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
			undo_redo->commit_action();

			pressed = false;

			return true;
		}
	}

	Ref<InputEventMouseMotion> mm = p_event;
	if (mm.is_valid() && pressed) {
		Vector2 point = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position()));
		point = node->get_global_transform().affine_inverse().xform(point);

		node->set("target_position", point);
		canvas_item_editor->update_viewport();
		node->notify_property_list_changed();

		return true;
	}

	return false;

Review comment (suggestion):
Don't we write undoredo messages in natural language normally? If so this could be "Set Target Position".

Code after:

bool Cast2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
	if (!node || !node->is_visible_in_tree()) {
		return false;
	}

	Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();

	Ref<InputEventMouseButton> mb = p_event;
	if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
		Vector2 target_position = node->get("target_position");

		if (mb->is_pressed()) {
			if (xform.xform(target_position).distance_to(mb->get_position()) < 8) {
				pressed = true;
				original_target_position = target_position;

				return true;
			} else {
				pressed = false;

				return false;
			}
		} else if (pressed) {
			EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
			undo_redo->create_action(TTR("Set Target Position"));
			undo_redo->add_do_property(node, "target_position", target_position);
			undo_redo->add_do_method(canvas_item_editor, "update_viewport");
			undo_redo->add_undo_property(node, "target_position", original_target_position);
			undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
			undo_redo->commit_action();

			pressed = false;

			return true;
		}
	}

	Ref<InputEventMouseMotion> mm = p_event;
	if (mm.is_valid() && pressed) {
		Vector2 point = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position()));
		point = node->get_global_transform().affine_inverse().xform(point);

		node->set("target_position", point);
		canvas_item_editor->update_viewport();
		node->notify_property_list_changed();

		return true;
	}

	return false;