From ee16de583fef6673937bba3cd51cbf16cf5527ea Mon Sep 17 00:00:00 2001 From: Micky Date: Sat, 13 Aug 2022 13:37:10 +0200 Subject: [PATCH] Reverse Camera2D.`rotating` to `ignore_rotation` `rotating` is misleading, as Camera2D is affected by `rotation` and `global_rotation` like any other Node2D Updates description in the docs, as well. --- doc/classes/Camera2D.xml | 6 ++--- editor/project_converter_3_to_4.cpp | 39 +++++++++++++++++++++++++++++ scene/2d/camera_2d.cpp | 18 ++++++------- scene/2d/camera_2d.h | 6 ++--- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/doc/classes/Camera2D.xml b/doc/classes/Camera2D.xml index bb78d537ad6..a1d24f778d0 100644 --- a/doc/classes/Camera2D.xml +++ b/doc/classes/Camera2D.xml @@ -124,6 +124,9 @@ If [code]true[/code], draws the camera's screen rectangle in the editor. + + If [code]true[/code], the camera's rendered view is not affected by its [member Node2D.rotation] and [member Node2D.global_rotation]. + Bottom scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit. @@ -147,9 +150,6 @@ The camera's process callback. See [enum Camera2DProcessCallback]. - - If [code]true[/code], the camera view rotates with the target. - If [code]true[/code], the camera smoothly moves towards the target at [member smoothing_speed]. diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp index 8df59c286ca..0bd3ec09251 100644 --- a/editor/project_converter_3_to_4.cpp +++ b/editor/project_converter_3_to_4.cpp @@ -419,6 +419,7 @@ static const char *gdscript_function_renames[][2] = { { "is_normalmap", "is_normal_map" }, // NoiseTexture { "is_refusing_new_network_connections", "is_refusing_new_connections" }, // Multiplayer API { "is_region", "is_region_enabled" }, // Sprite2D + { "is_rotating", "is_ignoring_rotation" }, // Camera2D { "is_scancode_unicode", "is_keycode_unicode" }, // OS { "is_selectable_when_hidden", "_is_selectable_when_hidden" }, // EditorNode3DGizmoPlugin { "is_set_as_toplevel", "is_set_as_top_level" }, // CanvasItem @@ -841,6 +842,7 @@ static const char *csharp_function_renames[][2] = { { "IsNormalmap", "IsNormalMap" }, // NoiseTexture { "IsRefusingNewNetworkConnections", "IsRefusingNewConnections" }, // Multiplayer API { "IsRegion", "IsRegionEnabled" }, // Sprite2D + { "IsRotating", "IsIgnoringRotation" }, // Camera2D { "IsScancodeUnicode", "IsKeycodeUnicode" }, // OS { "IsSelectableWhenHidden", "_IsSelectableWhenHidden" }, // EditorNode3DGizmoPlugin { "IsSetAsToplevel", "IsSetAsTopLevel" }, // CanvasItem @@ -3492,6 +3494,20 @@ void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContai } } } + + // set_rotating(true) -> set_ignore_rotation(false) + if (line.contains("set_rotating(")) { + int start = line.find("set_rotating("); + int end = get_end_parenthesis(line.substr(start)) + 1; + if (end > -1) { + Vector parts = parse_arguments(line.substr(start, end)); + if (parts.size() == 1) { + String opposite = parts[0] == "true" ? "false" : "true"; + line = line.substr(0, start) + "set_ignore_rotation(" + opposite + ")"; + } + } + } + // OS.get_window_safe_area() -> DisplayServer.get_display_safe_area() if (line.contains("OS.get_window_safe_area(")) { int start = line.find("OS.get_window_safe_area("); @@ -3539,6 +3555,29 @@ void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContai } } + // rotating = true -> ignore_rotation = false # reversed "rotating" for Camera2D + if (line.contains("rotating")) { + int start = line.find("rotating"); + bool foundNextEqual = false; + String line_to_check = line.substr(start + String("rotating").length()); + String assigned_value; + for (int current_index = 0; line_to_check.length() > current_index; current_index++) { + char32_t chr = line_to_check.get(current_index); + if (chr == '\t' || chr == ' ') { + continue; + } else if (chr == '=') { + foundNextEqual = true; + assigned_value = line.right(current_index).strip_edges(); + assigned_value = assigned_value == "true" ? "false" : "true"; + } else { + break; + } + } + if (foundNextEqual) { + line = line.substr(0, start) + "ignore_rotation =" + assigned_value + " # reversed \"rotating\" for Camera2D"; + } + } + // OS -> Time functions if (line.contains("OS.get_ticks_msec")) { line = line.replace("OS.get_ticks_msec", "Time.get_ticks_msec"); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index a11b2b66bf2..e120aa871b4 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -172,7 +172,7 @@ Transform2D Camera2D::get_camera_transform() { Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom_scale) : Point2()); real_t angle = get_global_rotation(); - if (rotating) { + if (!ignore_rotation) { screen_offset = screen_offset.rotated(angle); } @@ -204,7 +204,7 @@ Transform2D Camera2D::get_camera_transform() { Transform2D xform; xform.scale_basis(zoom_scale); - if (rotating) { + if (!ignore_rotation) { xform.set_rotation(angle); } xform.set_origin(screen_rect.position); @@ -363,15 +363,15 @@ Camera2D::AnchorMode Camera2D::get_anchor_mode() const { return anchor_mode; } -void Camera2D::set_rotating(bool p_rotating) { - rotating = p_rotating; +void Camera2D::set_ignore_rotation(bool p_ignore) { + ignore_rotation = p_ignore; Point2 old_smoothed_camera_pos = smoothed_camera_pos; _update_scroll(); smoothed_camera_pos = old_smoothed_camera_pos; } -bool Camera2D::is_rotating() const { - return rotating; +bool Camera2D::is_ignoring_rotation() const { + return ignore_rotation; } void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) { @@ -668,8 +668,8 @@ void Camera2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_anchor_mode", "anchor_mode"), &Camera2D::set_anchor_mode); ClassDB::bind_method(D_METHOD("get_anchor_mode"), &Camera2D::get_anchor_mode); - ClassDB::bind_method(D_METHOD("set_rotating", "rotating"), &Camera2D::set_rotating); - ClassDB::bind_method(D_METHOD("is_rotating"), &Camera2D::is_rotating); + ClassDB::bind_method(D_METHOD("set_ignore_rotation", "ignore"), &Camera2D::set_ignore_rotation); + ClassDB::bind_method(D_METHOD("is_ignoring_rotation"), &Camera2D::is_ignoring_rotation); ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll); @@ -733,7 +733,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_mode", PROPERTY_HINT_ENUM, "Fixed TopLeft,Drag Center"), "set_anchor_mode", "get_anchor_mode"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rotating"), "set_rotating", "is_rotating"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_rotation"), "set_ignore_rotation", "is_ignoring_rotation"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom", PROPERTY_HINT_LINK), "set_zoom", "get_zoom"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", PROPERTY_USAGE_NONE), "set_custom_viewport", "get_custom_viewport"); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 78654ee6061..1ce622388cd 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -63,7 +63,7 @@ protected: Vector2 zoom = Vector2(1, 1); Vector2 zoom_scale = Vector2(1, 1); AnchorMode anchor_mode = ANCHOR_MODE_DRAG_CENTER; - bool rotating = false; + bool ignore_rotation = true; bool current = false; real_t smoothing = 5.0; bool smoothing_enabled = false; @@ -109,8 +109,8 @@ public: void set_anchor_mode(AnchorMode p_anchor_mode); AnchorMode get_anchor_mode() const; - void set_rotating(bool p_rotating); - bool is_rotating() const; + void set_ignore_rotation(bool p_ignore); + bool is_ignoring_rotation() const; void set_limit(Side p_side, int p_limit); int get_limit(Side p_side) const;