Skip to content

Commit

Permalink
Merge pull request #89219 from devloglogan/xr-profile-changed
Browse files Browse the repository at this point in the history
Expose `profile_changed` signal to XRController3D
  • Loading branch information
akien-mga committed Mar 6, 2024
2 parents 7e65fd8 + 1383401 commit 6c9a166
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doc/classes/XRController3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,11 @@
Emitted when a thumbstick or thumbpad on this controller is moved.
</description>
</signal>
<signal name="profile_changed">
<param index="0" name="role" type="String" />
<description>
Emitted when the interaction profile on this controller is changed.
</description>
</signal>
</signals>
</class>
11 changes: 7 additions & 4 deletions scene/3d/xr_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ void XRController3D::_bind_methods() {
ADD_SIGNAL(MethodInfo("button_released", PropertyInfo(Variant::STRING, "name")));
ADD_SIGNAL(MethodInfo("input_float_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "value")));
ADD_SIGNAL(MethodInfo("input_vector2_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::VECTOR2, "value")));
ADD_SIGNAL(MethodInfo("profile_changed", PropertyInfo(Variant::STRING, "role")));
};

void XRController3D::_bind_tracker() {
Expand All @@ -471,6 +472,7 @@ void XRController3D::_bind_tracker() {
tracker->connect("button_released", callable_mp(this, &XRController3D::_button_released));
tracker->connect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed));
tracker->connect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed));
tracker->connect("profile_changed", callable_mp(this, &XRController3D::_profile_changed));
}
}

Expand All @@ -481,31 +483,32 @@ void XRController3D::_unbind_tracker() {
tracker->disconnect("button_released", callable_mp(this, &XRController3D::_button_released));
tracker->disconnect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed));
tracker->disconnect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed));
tracker->disconnect("profile_changed", callable_mp(this, &XRController3D::_profile_changed));
}

XRNode3D::_unbind_tracker();
}

void XRController3D::_button_pressed(const String &p_name) {
// just pass it on...
emit_signal(SNAME("button_pressed"), p_name);
}

void XRController3D::_button_released(const String &p_name) {
// just pass it on...
emit_signal(SNAME("button_released"), p_name);
}

void XRController3D::_input_float_changed(const String &p_name, float p_value) {
// just pass it on...
emit_signal(SNAME("input_float_changed"), p_name, p_value);
}

void XRController3D::_input_vector2_changed(const String &p_name, Vector2 p_value) {
// just pass it on...
emit_signal(SNAME("input_vector2_changed"), p_name, p_value);
}

void XRController3D::_profile_changed(const String &p_role) {
emit_signal(SNAME("profile_changed"), p_role);
}

bool XRController3D::is_button_pressed(const StringName &p_name) const {
if (tracker.is_valid()) {
// Inputs should already be of the correct type, our XR runtime handles conversions between raw input and the desired type
Expand Down
1 change: 1 addition & 0 deletions scene/3d/xr_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class XRController3D : public XRNode3D {
void _button_released(const String &p_name);
void _input_float_changed(const String &p_name, float p_value);
void _input_vector2_changed(const String &p_name, Vector2 p_value);
void _profile_changed(const String &p_role);

public:
bool is_button_pressed(const StringName &p_name) const;
Expand Down

0 comments on commit 6c9a166

Please sign in to comment.