From 472f7e9756796de03c1e9dbc3390bbca4eb020b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilles=20Roudi=C3=A8re?= Date: Thu, 6 May 2021 12:16:27 +0200 Subject: [PATCH] Adds a pressed signal to ButtonGroup (cherry picked from commit 323f1769157cd9e30c504fa6f54e8ba0889cfac3) --- doc/classes/ButtonGroup.xml | 9 +++++++++ scene/gui/base_button.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/doc/classes/ButtonGroup.xml b/doc/classes/ButtonGroup.xml index 4468d5eddb8..87570cd2169 100644 --- a/doc/classes/ButtonGroup.xml +++ b/doc/classes/ButtonGroup.xml @@ -28,6 +28,15 @@ + + + + + + Emitted when one of the buttons of the group is pressed. + + + diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 3802b9ef42b..258d343efed 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -155,6 +155,9 @@ void BaseButton::on_action_event(Ref p_event) { } status.pressed = !status.pressed; _unpress_group(); + if (button_group.is_valid()) { + button_group->emit_signal("pressed", this); + } _toggled(status.pressed); _pressed(); } @@ -220,6 +223,9 @@ void BaseButton::set_pressed(bool p_pressed) { if (p_pressed) { _unpress_group(); + if (button_group.is_valid()) { + button_group->emit_signal("pressed", this); + } } _toggled(status.pressed); @@ -480,6 +486,7 @@ BaseButton *ButtonGroup::get_pressed_button() { void ButtonGroup::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pressed_button"), &ButtonGroup::get_pressed_button); ClassDB::bind_method(D_METHOD("get_buttons"), &ButtonGroup::_get_buttons); + ADD_SIGNAL(MethodInfo("pressed", PropertyInfo(Variant::OBJECT, "button"))); } ButtonGroup::ButtonGroup() {