From c2fe5c04684105fdfedbc6679f17acec12b3382c Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Fri, 14 Dec 2018 03:39:31 -0200 Subject: [PATCH] Expose ButtonGroup's "get_buttons()" to GDScript --- doc/classes/ButtonGroup.xml | 9 ++++++++- scene/gui/base_button.cpp | 11 +++++++++++ scene/gui/base_button.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/classes/ButtonGroup.xml b/doc/classes/ButtonGroup.xml index 0f5ea8e6bfc..6273c8f83f2 100644 --- a/doc/classes/ButtonGroup.xml +++ b/doc/classes/ButtonGroup.xml @@ -12,11 +12,18 @@ + + + + + Returns an [Array] of [Button]s who have this as their [code]ButtonGroup[/code] (see [member BaseButton.group]). + + - Return the pressed button. + Returns the current pressed button. diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 1ac19774f7c..dc85c8e641e 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -595,6 +595,16 @@ void ButtonGroup::get_buttons(List *r_buttons) { } } +Array ButtonGroup::_get_buttons() { + + Array btns; + for (Set::Element *E = buttons.front(); E; E = E->next()) { + btns.push_back(E->get()); + } + + return btns; +} + BaseButton *ButtonGroup::get_pressed_button() { for (Set::Element *E = buttons.front(); E; E = E->next()) { @@ -608,6 +618,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); } ButtonGroup::ButtonGroup() { diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index a131e719adc..272c07f68aa 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -143,6 +143,7 @@ protected: public: BaseButton *get_pressed_button(); void get_buttons(List *r_buttons); + Array _get_buttons(); ButtonGroup(); };