package me.benjozork.onyx.ui;


import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;

import me.benjozork.onyx.ui.object.ActionEvent;

/**
 * Created by Benjozork on 2017-03-24.
 */
public class UIRadioButtonGroup extends UIElement {

    private Array<UIRadioButton> buttons = new Array<UIRadioButton>();
    private int selected;

    public UIRadioButtonGroup() {
        super(0, 0);
    }


    public int getSelected() {
        return selected;
    }

    public void setSelected(int selected) {
        this.selected = selected;
    }

    public Array<UIRadioButton> getButtons() {
        return buttons;
    }

    public void addButton(UIRadioButton b) {
        b.setGroup(this);
        buttons.add(b);
    }

    public void select(UIRadioButton b) {
        triggerEvent(ActionEvent.VALUE_CHANGED);
        selected = buttons.indexOf(b, true);
        b.set(true);
        if (selected == - 1) {
            selected = 0;
            throw new IllegalArgumentException();
        }
        for (UIRadioButton button : buttons) {
            if (buttons.indexOf(button, true) != selected) {
                button.set(false);
            }
        }
    }

    @Override
    public void init() {
        setBounds(new Rectangle(0, 0, 0, 0));
        selected = buttons.size - 1;
    }

    @Override
    public void update() {
        for (UIRadioButton button : buttons) {
            if (selected == buttons.indexOf(button, true)) {
                button.set(true);
            }
        }
    }

    @Override
    public void draw() {

    }

    @Override
    public boolean click(Vector2 localPosition) {
        return false;
    }

    @Override
    public void dispose() {

    }
}

@@ -454,156 +454,487 @@
  %7D%0A%0A
-%0A    public int getSelected() %7B%0A        return selected;%0A    %7D%0A%0A    public void setSelected(int selected) %7B%0A        this.selected = selected;%0A    %7D%0A
+    /**%0A     * The UIRadioBUtton that is currently selected%0A     * @return the button's index%0A     */%0A    public int getSelected() %7B%0A        return selected;%0A    %7D%0A%0A    /**%0A     * Sets the UIRadioButton that is currently selected%0A     * @param selected the button's index%0A     */%0A    public void setSelected(int selected) %7B%0A        this.selected = selected;%0A    %7D%0A%0A    /**%0A     * The list of buttons that the UIRadioButtonGroup contains%0A     * @return the list of buttons%0A     */
 %0A   
@@ -1000,32 +1000,108 @@
 buttons;%0A    %7D%0A%0A
+    /**%0A     * Adds a button to the list%0A     * @param b the button%0A     */%0A
     public void 
@@ -1182,24 +1182,145 @@
 (b);%0A    %7D%0A%0A
+    /**%0A     * Selects a button from the list%0A     * @param b the button%0A     * @throws IllegalArgumentException%0A     */%0A
     public v
@@ -1338,32 +1338,64 @@
 UIRadioButton b)
+ throws IllegalArgumentException
  %7B%0A        trigg

add UIRadioButtonGroup javadocs