summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-09-21 11:06:41 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-21 11:06:41 +0200
commit7bf61e391289d2ada058140ebff0a7eeb2db0da9 (patch)
tree8442949125456ef7169996e30fc08a7c63a4b405
parente9ad0fd1909bfeec20fccf9cd23bcbac09539427 (diff)
parentee16de583fef6673937bba3cd51cbf16cf5527ea (diff)
Merge pull request #64359 from Mickeon/rename-camera-rotating
Reverse Camera2D.`rotating` to `ignore_rotation`
-rw-r--r--doc/classes/Camera2D.xml6
-rw-r--r--editor/project_converter_3_to_4.cpp39
-rw-r--r--scene/2d/camera_2d.cpp18
-rw-r--r--scene/2d/camera_2d.h6
4 files changed, 54 insertions, 15 deletions
diff --git a/doc/classes/Camera2D.xml b/doc/classes/Camera2D.xml
index bb78d537ad..a1d24f778d 100644
--- a/doc/classes/Camera2D.xml
+++ b/doc/classes/Camera2D.xml
@@ -124,6 +124,9 @@
<member name="editor_draw_screen" type="bool" setter="set_screen_drawing_enabled" getter="is_screen_drawing_enabled" default="true">
If [code]true[/code], draws the camera's screen rectangle in the editor.
</member>
+ <member name="ignore_rotation" type="bool" setter="set_ignore_rotation" getter="is_ignoring_rotation" default="true">
+ If [code]true[/code], the camera's rendered view is not affected by its [member Node2D.rotation] and [member Node2D.global_rotation].
+ </member>
<member name="limit_bottom" type="int" setter="set_limit" getter="get_limit" default="10000000">
Bottom scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit.
</member>
@@ -147,9 +150,6 @@
<member name="process_callback" type="int" setter="set_process_callback" getter="get_process_callback" enum="Camera2D.Camera2DProcessCallback" default="1">
The camera's process callback. See [enum Camera2DProcessCallback].
</member>
- <member name="rotating" type="bool" setter="set_rotating" getter="is_rotating" default="false">
- If [code]true[/code], the camera view rotates with the target.
- </member>
<member name="smoothing_enabled" type="bool" setter="set_enable_follow_smoothing" getter="is_follow_smoothing_enabled" default="false">
If [code]true[/code], the camera smoothly moves towards the target at [member smoothing_speed].
</member>
diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp
index 8df59c286c..0bd3ec0925 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<String> 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 a11b2b66bf..e120aa871b 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 78654ee606..1ce622388c 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;