2025-05-04 20:27:55 +02:00
|
|
|
package client.gui.element;
|
2025-03-11 14:09:49 +01:00
|
|
|
|
2025-05-04 20:27:55 +02:00
|
|
|
import client.gui.Formatter;
|
|
|
|
import client.renderer.Drawing;
|
|
|
|
import client.window.Button;
|
2025-03-28 01:01:16 +01:00
|
|
|
import game.util.Util;
|
2025-03-11 14:09:49 +01:00
|
|
|
|
|
|
|
public class Toggle extends Element {
|
|
|
|
public static interface Callback {
|
|
|
|
void use(Toggle elem, boolean value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Callback func;
|
|
|
|
private final boolean def;
|
|
|
|
|
|
|
|
private boolean value;
|
|
|
|
|
|
|
|
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter<Toggle> formatter) {
|
|
|
|
super(x, y, w, h, formatter);
|
|
|
|
this.func = callback;
|
|
|
|
this.def = def;
|
|
|
|
this.value = init;
|
|
|
|
this.formatText();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, final String text) {
|
|
|
|
this(x, y, w, h, def, init, callback, new Formatter<Toggle>() {
|
|
|
|
public String use(Toggle elem) {
|
|
|
|
return String.format("%s: %s", text, elem.value ? "An" : "Aus");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
|
|
|
boolean prev = this.value;
|
|
|
|
if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) {
|
|
|
|
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
|
|
|
|
// gui_update_style(this, 1);
|
2025-03-20 01:14:54 +01:00
|
|
|
// this.r_dirty = true;
|
2025-03-11 14:09:49 +01:00
|
|
|
this.func.use(this, this.value);
|
|
|
|
this.formatText();
|
2025-03-18 13:07:23 +01:00
|
|
|
this.playSound();
|
2025-03-11 14:09:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void drawBackground() {
|
2025-03-28 01:01:16 +01:00
|
|
|
if(this.value) {
|
|
|
|
if(this.enabled)
|
|
|
|
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, 0xff000000, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
|
|
|
else
|
|
|
|
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, Util.mulColor(this.gm.style.fill_btm, 0.5f), Util.mulColor(this.gm.style.fill_top, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f));
|
|
|
|
}
|
2025-03-11 14:09:49 +01:00
|
|
|
else
|
|
|
|
super.drawBackground();
|
|
|
|
}
|
|
|
|
}
|