Merge pull request #24341 from YeldhamDev/buttongroup_expose_get_buttons

Expose ButtonGroup's "get_buttons()" to GDScript
This commit is contained in:
Rémi Verschelde 2018-12-14 09:04:58 +01:00 committed by GitHub
commit fc2038e128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -12,11 +12,18 @@
<demos>
</demos>
<methods>
<method name="get_buttons">
<return type="Array">
</return>
<description>
Returns an [Array] of [Button]s who have this as their [code]ButtonGroup[/code] (see [member BaseButton.group]).
</description>
</method>
<method name="get_pressed_button">
<return type="BaseButton">
</return>
<description>
Return the pressed button.
Returns the current pressed button.
</description>
</method>
</methods>

View file

@ -595,6 +595,16 @@ void ButtonGroup::get_buttons(List<BaseButton *> *r_buttons) {
}
}
Array ButtonGroup::_get_buttons() {
Array btns;
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
btns.push_back(E->get());
}
return btns;
}
BaseButton *ButtonGroup::get_pressed_button() {
for (Set<BaseButton *>::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() {

View file

@ -143,6 +143,7 @@ protected:
public:
BaseButton *get_pressed_button();
void get_buttons(List<BaseButton *> *r_buttons);
Array _get_buttons();
ButtonGroup();
};