diff --git a/mod/src/main/java/basemod/ModRadioButtonGroup.java b/mod/src/main/java/basemod/ModRadioButtonGroup.java new file mode 100644 index 00000000..baf5c251 --- /dev/null +++ b/mod/src/main/java/basemod/ModRadioButtonGroup.java @@ -0,0 +1,43 @@ +package basemod; + +import java.util.ArrayList; +import java.util.List; + +public class ModRadioButtonGroup { + private List buttons; + private ModToggleButton selected; + + public ModRadioButtonGroup(){ + this.buttons = new ArrayList(); + } + + public ModRadioButtonGroup(ModToggleButton... buttons){ + for(ModToggleButton b : buttons){ + addButton(b); + } + } + + public boolean addButton(ModToggleButton b){ + b.addConsumer( + button -> + { + selectButton(button); + }); + return buttons.add(b); + } + + public boolean removeButton(ModToggleButton b){ + return buttons.remove(b); + } + + public void selectButton(ModToggleButton b){ + this.selected=b; + updateButtons(); + } + + public void updateButtons(){ + for(ModToggleButton b : buttons){ + b.enabled = selected.equals(b); + } + } +} \ No newline at end of file diff --git a/mod/src/main/java/basemod/ModToggleButton.java b/mod/src/main/java/basemod/ModToggleButton.java index 4ec5b8cd..8e4d6783 100644 --- a/mod/src/main/java/basemod/ModToggleButton.java +++ b/mod/src/main/java/basemod/ModToggleButton.java @@ -11,13 +11,16 @@ import com.megacrit.cardcrawl.helpers.ImageMaster; import com.megacrit.cardcrawl.helpers.input.InputHelper; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; public class ModToggleButton implements IUIElement { private static final float TOGGLE_Y_DELTA = 0f; private static final float TOGGLE_X_EXTEND = 12.0f; private static final float HB_WIDTH_EXTENDED = 200.0f; - + + private List> consumers = new ArrayList>(); private Consumer toggle; Hitbox hb; private float x; @@ -97,6 +100,9 @@ public void update() { private void onToggle() { this.enabled = !enabled; toggle.accept(this); + for(Consumer c : consumers){ + c.accept(this); + } } public void toggle() { @@ -144,4 +150,8 @@ public float getX() { public float getY() { return y/Settings.scale; } + + public void addConsumer(Consumer c){ + consumers.add(c); + } }