tcr/java/src/game/gui/GuiBinds.java
2025-03-16 17:45:08 +01:00

74 lines
2 KiB
Java

package game.gui;
import game.color.TextColor;
import game.gui.element.ActButton;
import game.gui.element.ActButton.Mode;
import game.gui.element.Label;
import game.util.Formatter;
import game.window.Bind;
public class GuiBinds extends GuiOptions {
protected GuiBinds() {
}
public void init(int width, int height) {
int y = 0;
int x = 0;
for(Bind bind : Bind.values()) {
this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay()));
this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(action == Mode.SECONDARY) {
if(!bind.isDefault()) {
bind.setDefault();
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
else if(action == Mode.TERTIARY) {
if(bind.getInput() != null) {
bind.setInput(null);
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
else {
Bind.disableInput(bind);
}
}
}, new Formatter<ActButton>() {
public String use(ActButton elem) {
if(bind == Bind.getWaiting())
return /* TextColor.BLINK + "" + */ TextColor.BLUE + "***";
else
return (bind.isDupe() ? TextColor.RED : TextColor.YELLOW) + (bind.getInput() == null ? "---" : bind.getInput().getDisplay());
}
}));
if(++x == 5) {
x = 0;
y++;
}
}
y += x != 0 ? 1 : 0;
this.add(new ActButton(200, 100 + y * 50, 560, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
boolean flag = false;
for(Bind bind : Bind.values()) {
flag |= !bind.isDefault();
bind.setDefault();
}
if(flag) {
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
}, "Zurücksetzen"));
this.addSelector("phy_sensitivity", 30, 160 + y * 50, 440, 24);
this.addSelector("gui_dclick_delay", 490, 160 + y * 50, 440, 24);
super.init(width, height);
}
public String getTitle() {
return "Tastenbelegung und Maus";
}
}