split text fields

This commit is contained in:
Sen 2025-05-18 14:30:35 +02:00
parent 9077451c08
commit 2ea3267e3a
48 changed files with 709 additions and 571 deletions

View file

@ -50,7 +50,7 @@ import client.gui.Style;
import client.gui.character.GuiChar; import client.gui.character.GuiChar;
import client.gui.container.GuiContainer; import client.gui.container.GuiContainer;
import client.gui.container.GuiInventory; import client.gui.container.GuiInventory;
import client.gui.element.Textbox; import client.gui.element.Area;
import client.gui.ingame.GuiGameOver; import client.gui.ingame.GuiGameOver;
import client.network.ClientLoginHandler; import client.network.ClientLoginHandler;
import client.network.ClientPlayer; import client.network.ClientPlayer;
@ -1011,7 +1011,7 @@ public class Client implements IThreadListener {
this.open.render(); this.open.render();
else if(this.world == null || this.world.hasNoChunks() || this.charEditor) else if(this.world == null || this.world.hasNoChunks() || this.charEditor)
Drawing.drawScaled(this, Gui.DIRT_BACKGROUND); Drawing.drawScaled(this, Gui.DIRT_BACKGROUND);
if(Bind.INFO.isDown() && (this.open == null || !(this.open.selected instanceof Textbox))) if(Bind.INFO.isDown() && (this.open == null || !(this.open.selected instanceof client.gui.element.Field || this.open.selected instanceof Area)))
this.drawInfo(); this.drawInfo();
if(this.hudOverlay && !(this.open instanceof GuiConsole)) { if(this.hudOverlay && !(this.open instanceof GuiConsole)) {
this.drawOverlay(this.feed, this.feedSize, false, 1, 0, 0); this.drawOverlay(this.feed, this.feedSize, false, 1, 0, 0);

View file

@ -2,6 +2,7 @@ package client.audio;
import client.Client; import client.Client;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.SliderCallback;
import client.vars.CVar; import client.vars.CVar;
import client.vars.CVarCategory; import client.vars.CVarCategory;
import common.color.TextColor; import common.color.TextColor;
@ -96,7 +97,7 @@ public enum Volume implements CVar {
} }
public Slider selector(int x, int y, int w, int h) { public Slider selector(int x, int y, int w, int h) {
return new Slider(x, y, w, h, 0, 0, 100, 100, this.value, new Slider.Callback() { return new Slider(x, y, w, h, 0, 0, 100, 100, this.value, new SliderCallback() {
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
Volume.this.value = value; Volume.this.value = value;
Volume.this.apply(); Volume.this.apply();

View file

@ -1,11 +1,12 @@
package client.gui; package client.gui;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.TransparentBox; import client.gui.element.PressType;
import client.gui.element.TransparentArea;
public class GuiConfirm extends Gui implements ActButton.Callback { public class GuiConfirm extends Gui implements ButtonCallback {
public static interface Callback { public static interface Callback {
void confirm(boolean confirmed); void confirm(boolean confirmed);
} }
@ -28,7 +29,7 @@ public class GuiConfirm extends Gui implements ActButton.Callback {
public void init(int width, int height) { public void init(int width, int height) {
this.add(new Label(0, 0, 500, 24, this.messageLine1, true)); this.add(new Label(0, 0, 500, 24, this.messageLine1, true));
this.add(new TransparentBox(0, 80, 500, 300, this.messageLine2, this.gm.world != null && !this.gm.charEditor)); this.add(new TransparentArea(0, 80, 500, 300, this.messageLine2, this.gm.world != null && !this.gm.charEditor));
this.confirmBtn = this.add(new ActButton(48, 500, 200, 24, this, this.confirmButtonText)); this.confirmBtn = this.add(new ActButton(48, 500, 200, 24, this, this.confirmButtonText));
this.cancelBtn = this.add(new ActButton(252, 500, 200, 24, this, this.cancelButtonText)); this.cancelBtn = this.add(new ActButton(252, 500, 200, 24, this, this.cancelButtonText));
this.shift(); this.shift();
@ -38,7 +39,7 @@ public class GuiConfirm extends Gui implements ActButton.Callback {
return "Aktion bestätigen"; return "Aktion bestätigen";
} }
public void use(ActButton btn, Mode mode) { public void use(ActButton btn, PressType mode) {
this.callback.confirm(btn == this.confirmBtn); this.callback.confirm(btn == this.confirmBtn);
} }
} }

View file

@ -6,10 +6,11 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.GuiList; import client.gui.element.GuiList;
import client.gui.element.ListEntry; import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PressType;
import client.renderer.Drawing; import client.renderer.Drawing;
import common.color.TextColor; import common.color.TextColor;
import common.init.Config; import common.init.Config;
@ -19,7 +20,7 @@ import common.util.FileUtils;
import common.util.Tuple; import common.util.Tuple;
import common.util.Util; import common.util.Util;
public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ActButton.Callback { public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ButtonCallback {
public class ServerInfo implements Comparable<ServerInfo>, ListEntry { public class ServerInfo implements Comparable<ServerInfo>, ListEntry {
private String name; private String name;
private String address; private String address;
@ -91,7 +92,7 @@ public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ActBut
GuiConnect.this.copyButton.enabled = true; GuiConnect.this.copyButton.enabled = true;
if(isDoubleClick) { if(isDoubleClick) {
GuiConnect.this.use(GuiConnect.this.selectButton, Mode.PRIMARY); GuiConnect.this.use(GuiConnect.this.selectButton, PressType.PRIMARY);
} }
} }
@ -233,7 +234,7 @@ public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ActBut
return 56; return 56;
} }
public void use(ActButton button, Mode mode) { public void use(ActButton button, PressType mode) {
if(button == this.deleteButton) { if(button == this.deleteButton) {
if(this.selectedElement >= 0) { if(this.selectedElement >= 0) {
this.elements.remove(this.selectedElement); this.elements.remove(this.selectedElement);

View file

@ -4,13 +4,16 @@ import java.util.List;
import client.Client; import client.Client;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ButtonCallback;
import client.gui.element.Fill; import client.gui.element.Fill;
import client.gui.element.Textbox; import client.gui.element.PressType;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.network.ClientPlayer; import client.network.ClientPlayer;
import client.vars.BoolVar; import client.vars.BoolVar;
import client.vars.CVar; import client.vars.CVar;
import client.gui.element.TransparentBox; import client.gui.element.TransparentArea;
import client.window.Keysym; import client.window.Keysym;
import common.collect.Lists; import common.collect.Lists;
import common.color.TextColor; import common.color.TextColor;
@ -20,7 +23,7 @@ import common.util.BlockPos;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.HitPosition; import common.util.HitPosition;
public class GuiConsole extends Gui implements Textbox.Callback { public class GuiConsole extends Gui implements FieldCallback {
public static final GuiConsole INSTANCE = new GuiConsole(); public static final GuiConsole INSTANCE = new GuiConsole();
private final List<String> sentMessages = Lists.<String>newArrayList(); private final List<String> sentMessages = Lists.<String>newArrayList();
@ -35,8 +38,8 @@ public class GuiConsole extends Gui implements Textbox.Callback {
private String prefixFirst; private String prefixFirst;
private int autocompleteIndex; private int autocompleteIndex;
private List<String> foundPlayerNames = Lists.<String>newArrayList(); private List<String> foundPlayerNames = Lists.<String>newArrayList();
private Textbox inputField; private Field inputField;
private TransparentBox logBox; private TransparentArea logBox;
public GuiConsole setFull(boolean full) { public GuiConsole setFull(boolean full) {
this.full = full; this.full = full;
@ -48,17 +51,17 @@ public class GuiConsole extends Gui implements Textbox.Callback {
this.addSelector("con_autoclose", 0, 0, 160, 24); this.addSelector("con_autoclose", 0, 0, 160, 24);
this.addSelector("con_timestamps", 160, 0, 160, 24); this.addSelector("con_timestamps", 160, 0, 160, 24);
this.addSelector("con_loglevel", 320, 0, 160, 24); this.addSelector("con_loglevel", 320, 0, 160, 24);
this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() { this.add(new ActButton(480, 0, 160, 24, new ButtonCallback() {
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, PressType action) {
GuiConsole.this.reset(); GuiConsole.this.reset();
GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer()); GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer());
} }
}, "Löschen")); }, "Löschen"));
} }
this.logBox = this.add(new TransparentBox(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor)); this.logBox = this.add(new TransparentArea(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor));
if(this.full) if(this.full)
this.add(new Fill(640, 0, width - 640, 24)); this.add(new Fill(640, 0, width - 640, 24));
this.inputField = this.add(new Textbox(0, height - 24, width, 24, IPlayer.MAX_CMD_LENGTH, true, this, "")); this.inputField = this.add(new Field(0, height - 24, width, 24, IPlayer.MAX_CMD_LENGTH, this, ""));
this.inputField.setSelected(); this.inputField.setSelected();
this.sentHistoryCursor = this.sentMessages.size(); this.sentHistoryCursor = this.sentMessages.size();
} }
@ -90,13 +93,13 @@ public class GuiConsole extends Gui implements Textbox.Callback {
this.playerNamesFound = false; this.playerNamesFound = false;
} }
public void use(Textbox elem, Action value) public void use(Field elem, FieldAction value)
{ {
this.waitingOnAutocomplete = false; this.waitingOnAutocomplete = false;
if (value == Action.FORWARD || value == Action.BACKWARD) if (value == FieldAction.FORWARD || value == FieldAction.BACKWARD)
{ {
this.reverse = value == Action.BACKWARD; this.reverse = value == FieldAction.BACKWARD;
this.autocompletePlayerNames(); this.autocompletePlayerNames();
} }
else else
@ -104,11 +107,11 @@ public class GuiConsole extends Gui implements Textbox.Callback {
this.playerNamesFound = false; this.playerNamesFound = false;
} }
if(value == Action.PREVIOUS) if(value == FieldAction.PREVIOUS)
this.getSentHistory(-1); this.getSentHistory(-1);
else if (value == Action.NEXT) else if (value == FieldAction.NEXT)
this.getSentHistory(1); this.getSentHistory(1);
if(value == Action.SEND) if(value == FieldAction.SEND)
{ {
String s = this.inputField.getText().trim(); String s = this.inputField.getText().trim();
@ -154,7 +157,7 @@ public class GuiConsole extends Gui implements Textbox.Callback {
{ {
if (this.playerNamesFound) if (this.playerNamesFound)
{ {
this.inputField.deleteFromCursor(); this.inputField.deleteSpaceToCur();
if (this.autocompleteIndex >= this.foundPlayerNames.size()) if (this.autocompleteIndex >= this.foundPlayerNames.size())
{ {
@ -167,11 +170,11 @@ public class GuiConsole extends Gui implements Textbox.Callback {
} }
else else
{ {
int i = this.inputField.getNthCharFromPos(); int i = this.inputField.getSpaceBeforeCur();
this.foundPlayerNames.clear(); this.foundPlayerNames.clear();
this.autocompleteIndex = 0; this.autocompleteIndex = 0;
// String s = this.inputField.getText().substring(i).toLowerCase(); // String s = this.inputField.getText().substring(i).toLowerCase();
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition()); String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPos());
String[] localMatches = this.sendAutocompleteRequest(s1); String[] localMatches = this.sendAutocompleteRequest(s1);
if(localMatches != null) { if(localMatches != null) {
this.onAutocompleteResponse(localMatches); this.onAutocompleteResponse(localMatches);
@ -184,7 +187,7 @@ public class GuiConsole extends Gui implements Textbox.Callback {
} }
this.playerNamesFound = true; this.playerNamesFound = true;
this.inputField.deleteFromCursor(); this.inputField.deleteSpaceToCur();
} }
if (this.foundPlayerNames.size() > 1) if (this.foundPlayerNames.size() > 1)
@ -314,12 +317,12 @@ public class GuiConsole extends Gui implements Textbox.Callback {
} }
} }
String s1 = this.inputField.getText().substring(this.inputField.getNthCharFromPos()); String s1 = this.inputField.getText().substring(this.inputField.getSpaceBeforeCur());
String s2 = getCommonPrefix(choices); String s2 = getCommonPrefix(choices);
if (s2.length() > 0 && !s1.equalsIgnoreCase(s2)) if (s2.length() > 0 && !s1.equalsIgnoreCase(s2))
{ {
this.inputField.deleteFromCursor(); this.inputField.deleteSpaceToCur();
this.inputField.insertText(s2); this.inputField.insertText(s2);
} }
else if (this.foundPlayerNames.size() > 0) else if (this.foundPlayerNames.size() > 0)

View file

@ -1,7 +1,7 @@
package client.gui; package client.gui;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.TransparentBox; import client.gui.element.TransparentArea;
import common.color.TextColor; import common.color.TextColor;
import common.init.Config; import common.init.Config;
import common.log.Log; import common.log.Log;
@ -125,7 +125,7 @@ public class GuiInfo extends Gui {
} }
public void init(int width, int height) { public void init(int width, int height) {
this.add(new TransparentBox(10, 10, width - 20, height - 44, this.info, this.gm.world != null && !this.gm.charEditor)); this.add(new TransparentArea(10, 10, width - 20, height - 44, this.info, this.gm.world != null && !this.gm.charEditor));
this.add(new NavButton(0, height - 24, width, 24, GuiMenu.INSTANCE, "Zurück")); this.add(new NavButton(0, height - 24, width, 24, GuiMenu.INSTANCE, "Zurück"));
} }

View file

@ -4,10 +4,10 @@ import client.Timing;
import client.gui.character.GuiChar; import client.gui.character.GuiChar;
import client.gui.character.GuiCharacters; import client.gui.character.GuiCharacters;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.Textbox; import client.gui.element.PressType;
import client.gui.options.GuiOptions; import client.gui.options.GuiOptions;
import client.renderer.Drawing; import client.renderer.Drawing;
import client.window.Keysym; import client.window.Keysym;
@ -52,8 +52,8 @@ public class GuiMenu extends Gui {
this.ticks = 0; this.ticks = 0;
this.hacked = 0; this.hacked = 0;
this.resetAnimation(); this.resetAnimation();
this.add(new ActButton(0, -28, 400, 24, new ActButton.Callback() { this.add(new ActButton(0, -28, 400, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(GuiMenu.this.hacked == 9) { if(GuiMenu.this.hacked == 9) {
GuiMenu.this.hacked++; GuiMenu.this.hacked++;
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!"); GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
@ -64,16 +64,16 @@ public class GuiMenu extends Gui {
} }
}, "Server beitreten")); }, "Server beitreten"));
this.add(new NavButton(0, 0, 400, 24, GuiServer.INSTANCE, "Schnellverbindung")); this.add(new NavButton(0, 0, 400, 24, GuiServer.INSTANCE, "Schnellverbindung"));
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() { this.add(new ActButton(0, 28, 400, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(GuiMenu.this.hacked == 8) if(GuiMenu.this.hacked == 8)
GuiMenu.this.hacked++; GuiMenu.this.hacked++;
else else
GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage()); GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage());
} }
}, "Einstellungen")); }, "Einstellungen"));
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() { this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE); GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
} }
}, "Info / Über / Mitwirkende") { }, "Info / Über / Mitwirkende") {
@ -95,8 +95,8 @@ public class GuiMenu extends Gui {
} }
} }
}); });
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() { this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() {
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, PressType action) {
GuiMenu.this.gm.interrupted = true; GuiMenu.this.gm.interrupted = true;
} }
}, "Client schließen")); }, "Client schließen"));
@ -110,8 +110,8 @@ public class GuiMenu extends Gui {
this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen")); this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen"));
if(!this.gm.charEditor) if(!this.gm.charEditor)
this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter")); this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter"));
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() { this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() {
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, PressType action) {
GuiMenu.this.gm.unload(true); GuiMenu.this.gm.unload(true);
// GuiMenu.this.gm.displayGuiScreen(INSTANCE); // GuiMenu.this.gm.displayGuiScreen(INSTANCE);
} }
@ -226,7 +226,7 @@ public class GuiMenu extends Gui {
public void updateScreen() { public void updateScreen() {
if(this.gm.world == null) { if(this.gm.world == null) {
this.ticks++; this.ticks++;
if(this.gm.shift() && !(this.selected instanceof Textbox)) if(this.gm.shift())
this.pickSplash(); this.pickSplash();
this.updateAnimation(); this.updateAnimation();
} }

View file

@ -2,27 +2,30 @@ package client.gui;
import client.gui.GuiConnect.ServerInfo; import client.gui.GuiConnect.ServerInfo;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ButtonCallback;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.Textbox; import client.gui.element.PressType;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.vars.CVarCategory; import client.vars.CVarCategory;
import client.vars.Variable; import client.vars.Variable;
import common.color.TextColor; import common.color.TextColor;
import common.init.Config; import common.init.Config;
import common.network.IPlayer; import common.network.IPlayer;
public class GuiServer extends Gui implements Textbox.Callback { public class GuiServer extends Gui implements FieldCallback {
public static final GuiServer INSTANCE = new GuiServer(null); public static final GuiServer INSTANCE = new GuiServer(null);
private final ServerInfo server; private final ServerInfo server;
private Textbox nameBox; private Field nameBox;
private Textbox addrBox; private Field addrBox;
private Textbox portBox; private Field portBox;
private Textbox userBox; private Field userBox;
private Textbox passBox; private Field passBox;
private Textbox accBox; private Field accBox;
private Label nameLabel; private Label nameLabel;
private Label addrLabel; private Label addrLabel;
private Label portLabel; private Label portLabel;
@ -47,14 +50,14 @@ public class GuiServer extends Gui implements Textbox.Callback {
public void init(int width, int height) { public void init(int width, int height) {
if(this.server != null) if(this.server != null)
this.nameBox = this.add(new Textbox(0, -50, 400, 24, 128, true, this, this.server.getName())); this.nameBox = this.add(new Field(0, -50, 400, 24, 128, this, this.server.getName()));
this.addrBox = this.add(new Textbox(0, 20, 400, 24, 128, true, this, this.server == null ? this.lastAddr : this.server.getAddress())); this.addrBox = this.add(new Field(0, 20, 400, 24, 128, this, this.server == null ? this.lastAddr : this.server.getAddress()));
this.portBox = this.add(new Textbox(404, 20, 76, 24, 5, true, this, "" + (this.server == null ? this.lastPort : this.server.getPort()))); this.portBox = this.add(new Field(404, 20, 76, 24, 5, this, "" + (this.server == null ? this.lastPort : this.server.getPort())));
this.userBox = this.add(new Textbox(0, 70, 220, 24, IPlayer.MAX_USER_LENGTH, true, this, IPlayer.VALID_USER, this.server == null ? this.lastUser : this.server.getUser())); this.userBox = this.add(new Field(0, 70, 220, 24, IPlayer.MAX_USER_LENGTH, this, IPlayer.VALID_USER, this.server == null ? this.lastUser : this.server.getUser()));
this.passBox = this.add(new Textbox(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastPass : this.server.getPassword())); this.passBox = this.add(new Field(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, this, this.server == null ? this.lastPass : this.server.getPassword()));
this.accBox = this.add(new Textbox(0, 170, 480, 24, IPlayer.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastAcc : this.server.getAccess())); this.accBox = this.add(new Field(0, 170, 480, 24, IPlayer.MAX_PASS_LENGTH, this, this.server == null ? this.lastAcc : this.server.getAccess()));
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() { this.add(new ActButton(0, 220, 480, 24, new ButtonCallback() {
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, PressType action) {
GuiServer.this.connect(); GuiServer.this.connect();
} }
}, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen"))); }, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen")));
@ -127,12 +130,12 @@ public class GuiServer extends Gui implements Textbox.Callback {
} }
} }
public void use(Textbox elem, Action value) { public void use(Field elem, FieldAction value) {
if(value == Action.SEND) { if(value == FieldAction.SEND) {
elem.setDeselected(); elem.setDeselected();
this.connect(); this.connect();
} }
else if(value == Action.FOCUS) { else if(value == FieldAction.FOCUS) {
if(elem == this.addrBox) if(elem == this.addrBox)
this.addrLabel.setText("Adresse"); this.addrLabel.setText("Adresse");
else if(elem == this.portBox) else if(elem == this.portBox)

View file

@ -20,16 +20,20 @@ import client.SkinConverter;
import client.gui.FileCallback; import client.gui.FileCallback;
import client.gui.GuiLoading; import client.gui.GuiLoading;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.Element; import client.gui.element.Element;
import client.gui.element.GuiList; import client.gui.element.GuiList;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.ListEntry; import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PressType;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.Textbox; import client.gui.element.SliderCallback;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import client.gui.element.TransparentBox; import client.gui.element.Area;
import client.gui.element.ButtonCallback;
import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.gui.element.TransparentArea;
import client.renderer.Drawing; import client.renderer.Drawing;
import client.renderer.GlState; import client.renderer.GlState;
import client.renderer.ItemRenderer; import client.renderer.ItemRenderer;
@ -248,7 +252,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
private ActButton templateButton; private ActButton templateButton;
private DragAdjust adjust; private DragAdjust adjust;
private ActButton dimButton; private ActButton dimButton;
private TransparentBox descLines; private TransparentArea descLines;
private float yaw = -15.0f; private float yaw = -15.0f;
private float pitch = -15.0f; private float pitch = -15.0f;
private boolean waiting = true; private boolean waiting = true;
@ -273,8 +277,8 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
} }
this.currentSkin = this.gm.player != null && !EntityTexManager.hasCustomSkin(this.gm.player.getId()) ? this.gm.player.getChar() : null; this.currentSkin = this.gm.player != null && !EntityTexManager.hasCustomSkin(this.gm.player.getId()) ? this.gm.player.getChar() : null;
this.load(this.gm.player == null ? ModelType.HUMANOID : this.gm.player.getModel(), this.gm.player != null ? this.gm.player.getSpecies() : SpeciesRegistry.CLASSES.get(EntityHuman.class)); this.load(this.gm.player == null ? ModelType.HUMANOID : this.gm.player.getModel(), this.gm.player != null ? this.gm.player.getSpecies() : SpeciesRegistry.CLASSES.get(EntityHuman.class));
this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() { this.add(new ActButton(4, 4, 194, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", TEXTURE_FOLDER, new FileCallback() { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", TEXTURE_FOLDER, new FileCallback() {
public void selected(File file) { public void selected(File file) {
if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, false)) if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, false))
@ -283,8 +287,8 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
}); });
} }
}, "Importieren: Standard")); }, "Importieren: Standard"));
this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() { this.add(new ActButton(202, 4, 194, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", TEXTURE_FOLDER, new FileCallback() { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", TEXTURE_FOLDER, new FileCallback() {
public void selected(File file) { public void selected(File file) {
if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, true)) if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, true))
@ -294,13 +298,13 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
} }
}, "Importieren: Schlank")); }, "Importieren: Schlank"));
this.addSelector("char_filter_species", 400, 4, 300, 24); this.addSelector("char_filter_species", 400, 4, 300, 24);
this.add(new ActButton(4, height - 28, 194, 24, new ActButton.Callback() { this.add(new ActButton(4, height - 28, 194, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiChar.this.gm.displayGuiScreen(GuiChar.this); GuiChar.this.gm.displayGuiScreen(GuiChar.this);
} }
}, "Neu laden")); }, "Neu laden"));
this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ActButton.Callback() { this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
SkinEntry skin = GuiChar.this.getSelected(); SkinEntry skin = GuiChar.this.getSelected();
if(skin != null && skin.getLocation() != null) { if(skin != null && skin.getLocation() != null) {
String loc = skin.getLocation(); String loc = skin.getLocation();
@ -346,8 +350,8 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
for (int z = 0; z < Alignment.values().length; z++) for (int z = 0; z < Alignment.values().length; z++)
{ {
final Alignment align = Alignment.values()[z]; final Alignment align = Alignment.values()[z];
alignBtns[z] = this.add(new ActButton(width - 396 + (z % 3) * 132, height - 32 - 28 * 3 + 28 * (z / 3), 128, 24, new ActButton.Callback() { alignBtns[z] = this.add(new ActButton(width - 396 + (z % 3) * 132, height - 32 - 28 * 3 + 28 * (z / 3), 128, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(GuiChar.this.gm.player != null) { if(GuiChar.this.gm.player != null) {
GuiChar.this.waiting = false; GuiChar.this.waiting = false;
GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal())); GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal()));
@ -359,7 +363,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
}, align.color + align.display)); }, align.color + align.display));
alignBtns[z].enabled = this.gm.player == null || this.gm.player.getAlignment() != align; alignBtns[z].enabled = this.gm.player == null || this.gm.player.getAlignment() != align;
} }
this.add(new Slider(width / 2 - 200, height - 28, 400, 24, 1, this.gm.player == null ? 120 : this.gm.player.getMinSize(), this.gm.player == null ? 320 : this.gm.player.getMaxSize(), this.gm.player == null ? 180 : this.gm.player.getDefaultSize(), this.gm.player == null ? 180 : this.gm.player.getCurrentSize(), new Slider.Callback() { this.add(new Slider(width / 2 - 200, height - 28, 400, 24, 1, this.gm.player == null ? 120 : this.gm.player.getMinSize(), this.gm.player == null ? 320 : this.gm.player.getMaxSize(), this.gm.player == null ? 180 : this.gm.player.getDefaultSize(), this.gm.player == null ? 180 : this.gm.player.getCurrentSize(), new SliderCallback() {
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
if(GuiChar.this.gm.player != null) { if(GuiChar.this.gm.player != null) {
GuiChar.this.waiting = false; GuiChar.this.waiting = false;
@ -369,12 +373,9 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
}, "Spieler-Größe", "cm")).enabled = this.gm.player == null || this.gm.player.getMinSize() != this.gm.player.getMaxSize(); }, "Spieler-Größe", "cm")).enabled = this.gm.player == null || this.gm.player.getMinSize() != this.gm.player.getMaxSize();
this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true)); this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true));
this.add(new Label(width - 396, height - 384, 392, 20, "Beschreibung", true)); this.add(new Label(width - 396, height - 384, 392, 20, "Beschreibung", true));
final Textbox descField = this.add(new Textbox(width - 396, height - 364, 392, 130, IPlayer.MAX_INFO_LENGTH, new Textbox.Callback() { final Area descField = this.add(new Area(width - 396, height - 364, 392, 130, IPlayer.MAX_INFO_LENGTH, ""));
public void use(Textbox elem, Action value) { this.add(new ActButton(width - 198, height - 28, 194, 24, new ButtonCallback() {
} public void use(ActButton elem, PressType action) {
}, ""));
this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(GuiChar.this.gm.player != null) { if(GuiChar.this.gm.player != null) {
GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ...")); GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ..."));
Dimension dim = UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension); Dimension dim = UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension);
@ -383,9 +384,9 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
} }
} }
}, "Charakter erstellen")); }, "Charakter erstellen"));
this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, true, new Textbox.Callback() { this.add(new Field(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, new FieldCallback() {
public void use(Textbox elem, Action value) { public void use(Field elem, FieldAction value) {
if(value == Action.SEND || value == Action.UNFOCUS) { if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) {
String name = elem.getText(); String name = elem.getText();
if(name.isEmpty()) if(name.isEmpty())
elem.setText(GuiChar.this.gm.player == null ? "..." : GuiChar.this.gm.player.getCustomNameTag()); elem.setText(GuiChar.this.gm.player == null ? "..." : GuiChar.this.gm.player.getCustomNameTag());
@ -410,12 +411,12 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
} }
} }
} }
this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ActButton.Callback() { this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ButtonCallback() {
public void use(ActButton elem, Mode mode) { public void use(ActButton elem, PressType mode) {
if(mode == Mode.TERTIARY) { if(mode == PressType.TERTIARY) {
GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size());
} }
else if(mode == Mode.SECONDARY) { else if(mode == PressType.SECONDARY) {
if(--GuiChar.this.dimension < 0) if(--GuiChar.this.dimension < 0)
GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1; GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1;
} }
@ -426,7 +427,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
GuiChar.this.setDimButton(); GuiChar.this.setDimButton();
} }
}, "")); }, ""));
this.descLines = this.add(new TransparentBox(width - 396, height - 220 + 24, 392, 66, "", false)); this.descLines = this.add(new TransparentArea(width - 396, height - 220 + 24, 392, 66, "", false));
this.setDimButton(); this.setDimButton();
} }

View file

@ -3,17 +3,18 @@ package client.gui.character;
import client.gui.GuiConfirm; import client.gui.GuiConfirm;
import client.gui.GuiMenu; import client.gui.GuiMenu;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.GuiList; import client.gui.element.GuiList;
import client.gui.element.ListEntry; import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.TransparentBox; import client.gui.element.PressType;
import client.gui.element.TransparentArea;
import client.renderer.Drawing; import client.renderer.Drawing;
import common.color.TextColor; import common.color.TextColor;
import common.entity.npc.PlayerCharacter; import common.entity.npc.PlayerCharacter;
import common.packet.CPacketAction; import common.packet.CPacketAction;
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ActButton.Callback public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ButtonCallback
{ {
protected class CharacterEntry implements ListEntry protected class CharacterEntry implements ListEntry
{ {
@ -43,14 +44,14 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
public void select(boolean dclick, int mx, int my) public void select(boolean dclick, int mx, int my)
{ {
if(dclick) if(dclick)
GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY); GuiCharacters.this.use(GuiCharacters.this.actionButtom, PressType.PRIMARY);
GuiCharacters.this.updateButtons(); GuiCharacters.this.updateButtons();
} }
} }
public static final GuiCharacters INSTANCE = new GuiCharacters(); public static final GuiCharacters INSTANCE = new GuiCharacters();
private TransparentBox descField; private TransparentArea descField;
private ActButton actionButtom; private ActButton actionButtom;
private ActButton deleteButtom; private ActButton deleteButtom;
@ -78,7 +79,7 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
this.elements.add(new CharacterEntry(null, false)); this.elements.add(new CharacterEntry(null, false));
this.setSelected(initialSelection); this.setSelected(initialSelection);
} }
this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false)); this.descField = this.add(new TransparentArea(width - 390, 62, 380, height - 124, "", false));
this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen")); this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen"));
this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, "")); this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, ""));
this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen")); this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen"));
@ -99,7 +100,7 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
return 36 + 4; return 36 + 4;
} }
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
CharacterEntry entry = GuiCharacters.this.getSelected(); CharacterEntry entry = GuiCharacters.this.getSelected();
if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) { if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) {
if(elem == this.actionButtom) { if(elem == this.actionButtom) {

View file

@ -1,14 +1,15 @@
package client.gui.character; package client.gui.character;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.GuiList; import client.gui.element.GuiList;
import client.gui.element.ListEntry; import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PressType;
import client.renderer.Drawing; import client.renderer.Drawing;
import common.packet.CPacketAction; import common.packet.CPacketAction;
public class GuiClass extends GuiList<GuiClass.ClassEntry> implements ActButton.Callback public class GuiClass extends GuiList<GuiClass.ClassEntry> implements ButtonCallback
{ {
protected class ClassEntry implements ListEntry protected class ClassEntry implements ListEntry
{ {
@ -29,7 +30,7 @@ public class GuiClass extends GuiList<GuiClass.ClassEntry> implements ActButton.
public void select(boolean dclick, int mx, int my) public void select(boolean dclick, int mx, int my)
{ {
if((GuiClass.this.selectButton.enabled = GuiClass.this.gm.player == null || this.clazz != GuiClass.this.gm.player.getNpcClass()) && dclick) if((GuiClass.this.selectButton.enabled = GuiClass.this.gm.player == null || this.clazz != GuiClass.this.gm.player.getNpcClass()) && dclick)
GuiClass.this.use(GuiClass.this.selectButton, Mode.PRIMARY); GuiClass.this.use(GuiClass.this.selectButton, PressType.PRIMARY);
} }
} }
@ -67,7 +68,7 @@ public class GuiClass extends GuiList<GuiClass.ClassEntry> implements ActButton.
return 44 + 4; return 44 + 4;
} }
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
ClassEntry entry = this.getSelected(); ClassEntry entry = this.getSelected();
if(entry != null && GuiClass.this.gm.player != null) { if(entry != null && GuiClass.this.gm.player != null) {
GuiClass.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_CLASS, entry.clazz.ordinal())); GuiClass.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_CLASS, entry.clazz.ordinal()));

View file

@ -1,17 +1,18 @@
package client.gui.character; package client.gui.character;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.GuiList; import client.gui.element.GuiList;
import client.gui.element.ListEntry; import client.gui.element.ListEntry;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PressType;
import client.renderer.Drawing; import client.renderer.Drawing;
import common.entity.npc.SpeciesInfo; import common.entity.npc.SpeciesInfo;
import common.init.EntityRegistry; import common.init.EntityRegistry;
import common.init.SpeciesRegistry; import common.init.SpeciesRegistry;
import common.packet.CPacketAction; import common.packet.CPacketAction;
public class GuiSpecies extends GuiList<GuiSpecies.SpeciesEntry> implements ActButton.Callback public class GuiSpecies extends GuiList<GuiSpecies.SpeciesEntry> implements ButtonCallback
{ {
protected class SpeciesEntry implements ListEntry protected class SpeciesEntry implements ListEntry
{ {
@ -34,7 +35,7 @@ public class GuiSpecies extends GuiList<GuiSpecies.SpeciesEntry> implements ActB
public void select(boolean dclick, int mx, int my) public void select(boolean dclick, int mx, int my)
{ {
if((GuiSpecies.this.selectButton.enabled = GuiSpecies.this.gm.player == null || this.species != GuiSpecies.this.gm.player.getSpecies()) && dclick) if((GuiSpecies.this.selectButton.enabled = GuiSpecies.this.gm.player == null || this.species != GuiSpecies.this.gm.player.getSpecies()) && dclick)
GuiSpecies.this.use(GuiSpecies.this.selectButton, Mode.PRIMARY); GuiSpecies.this.use(GuiSpecies.this.selectButton, PressType.PRIMARY);
} }
} }
@ -71,7 +72,7 @@ public class GuiSpecies extends GuiList<GuiSpecies.SpeciesEntry> implements ActB
return 44 + 4; return 44 + 4;
} }
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
SpeciesEntry entry = this.getSelected(); SpeciesEntry entry = this.getSelected();
if(entry != null && GuiSpecies.this.gm.player != null) if(entry != null && GuiSpecies.this.gm.player != null)
GuiSpecies.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(entry.species.clazz))); GuiSpecies.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(entry.species.clazz)));

View file

@ -4,30 +4,22 @@ import client.gui.Formatter;
import client.window.Button; import client.window.Button;
public class ActButton extends Element { public class ActButton extends Element {
public static enum Mode { private final ButtonCallback func;
PRIMARY, SECONDARY, TERTIARY;
}
public static interface Callback { public ActButton(int x, int y, int w, int h, ButtonCallback callback, Formatter<ActButton> formatter) {
void use(ActButton elem, Mode action);
}
private final Callback func;
public ActButton(int x, int y, int w, int h, Callback callback, Formatter<ActButton> formatter) {
super(x, y, w, h, formatter); super(x, y, w, h, formatter);
this.func = callback; this.func = callback;
this.formatText(); this.formatText();
} }
public ActButton(int x, int y, int w, int h, Callback callback, String text) { public ActButton(int x, int y, int w, int h, ButtonCallback callback, String text) {
super(x, y, w, h, null); super(x, y, w, h, null);
this.func = callback; this.func = callback;
this.setText(text); this.setText(text);
} }
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
this.func.use(this, (ctrl || (btn == Button.MOUSE_MIDDLE)) ? Mode.TERTIARY : ((shift || (btn == Button.MOUSE_RIGHT)) ? Mode.SECONDARY : Mode.PRIMARY)); this.func.use(this, (ctrl || (btn == Button.MOUSE_MIDDLE)) ? PressType.TERTIARY : ((shift || (btn == Button.MOUSE_RIGHT)) ? PressType.SECONDARY : PressType.PRIMARY));
this.formatText(); this.formatText();
this.playSound(); this.playSound();
} }

View file

@ -0,0 +1,159 @@
package client.gui.element;
import client.gui.Font;
import client.renderer.Drawing;
import client.renderer.Drawing.Offset;
import client.renderer.Drawing.Vec2i;
import common.util.CharValidator;
import common.util.ExtMath;
import common.util.Util;
public class Area extends Textbox {
private int textHeight;
private int scrollPos;
private int cursorX;
private int cursorY;
private Area(int x, int y, int w, int h, int cap, boolean editable, CharValidator validator, String text) {
super(x, y, w, h, cap, editable, null, validator);
this.setText(text);
}
public Area(int x, int y, int w, int h, int cap, CharValidator validator, String text) {
this(x, y, w, h, cap, true, validator, text);
}
public Area(int x, int y, int w, int h, int cap, String text) {
this(x, y, w, h, cap, true, null, text);
}
public Area(int x, int y, int w, int h, String text) {
this(x, y, w, h, Integer.MAX_VALUE, false, null, text);
}
public void updateText() {
this.textHeight = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2)), Integer.MAX_VALUE, this.text).ypos;
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
if(scr_y != 0) {
int limit = Font.YGLYPH + this.textHeight - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_y;
this.text_y += (scr_y < 0 ? -1 : 1) * (ctrl ? 1 : Font.YGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
if(this.sel_start >= 0)
this.cursorY += (this.text_y - prev);
}
}
public void mouserel() {
this.scrollPos = 0;
}
public void onReturn(boolean shift) {
insertText("\n");
}
public void onSelection(boolean up) {
if(!up && this.sel_start != this.sel_end) {
this.sel_start = this.sel_drag = this.sel_end;
}
else if(up && this.sel_start != this.sel_end) {
this.sel_end = this.sel_drag = this.sel_start;
}
if(!up && this.sel_start >= 0) {
if(this.sel_end < this.text.length()) {
int nl = this.text.indexOf('\n', this.sel_end);
this.sel_end = nl >= 0 ? nl + 1 : this.text.length();
this.sel_start = this.sel_drag = this.sel_end;
}
else {
this.sel_end = this.sel_drag = this.sel_start;
}
gui_text_update_cur(this.sel_end, true);
}
else if(up && this.sel_start >= 0) {
if(this.sel_start > 0) {
int nl = this.text.lastIndexOf('\n', this.sel_start);
this.sel_start = nl >= 0 ? nl : 0;
}
this.sel_end = this.sel_drag = this.sel_start;
gui_text_update_cur(this.sel_end, true);
}
}
public void update() {
if(this.scrollPos != 0) {
int n = this.updateScroll(this.scrollPos);
this.text_y += n;
if(n != 0)
gui_text_clamp_scroll();
}
}
public void shift(int shift_x, int shift_y) {
super.shift(shift_x, shift_y);
this.cursorX += shift_x;
this.cursorY += shift_y;
}
protected void gui_text_clamp_scroll() {
int limit = Font.YGLYPH + this.textHeight - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
}
protected void updateCursor(int offset, boolean shift, int x1, int y1, int x2, int y2) {
Vec2i coord = Drawing.txt_coord(offset, x1, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, this.pos_x + x2, 0x7fffffff, this.text);
this.cursorX = coord.xpos;
this.cursorY = coord.ypos;
if(shift) {
if(this.cursorY < y1)
this.text_y += y1 - this.cursorY;
else if((this.cursorY + Font.YGLYPH) >= (y1 + y2))
this.text_y -= (this.cursorY + Font.YGLYPH) - (y1 + y2);
gui_text_update_cur(offset, false);
}
}
protected int onCursorOffset(int x, int y, int x1, int y1, int x2, int y2) {
Offset off = Drawing.txt_offset(x, y, x1, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, this.pos_x + x2, 0x7fffffff, this.text);
if(off != null) {
this.cursorX = off.xpos;
this.cursorY = off.ypos;
}
int offset = off == null ? 0 : off.offset;
if(y < y1)
this.scrollPos = y1 - y;
else if(y >= (y1 + y2))
this.scrollPos = -(y - (y1 + y2));
return offset;
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.pos_x + x2, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text);
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
Drawing.txt_overlay(this.sel_start, this.sel_end, x1, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.pos_x + x2, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text);
}
protected char getNewline() {
return '\n';
}
protected int getCursorX(int x1, int x2) {
return this.cursorX;
}
protected int getCursorY(int y1, int y2) {
return this.cursorY;
}
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface ButtonCallback {
void use(ActButton elem, PressType action);
}

View file

@ -64,18 +64,14 @@ public class Dropdown<T> extends Element {
} }
} }
public static interface Callback<T> { private final DropdownCallback<T> func;
void use(Dropdown<T> elem, T value);
}
private final Callback<T> func;
private final T[] values; private final T[] values;
private final Handle handle; private final Handle handle;
private final int def; private final int def;
private int value; private int value;
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback<T> callback, Formatter<Dropdown<T>> formatter) { public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback<T> callback, Formatter<Dropdown<T>> formatter) {
super(x, y, w, h, formatter); super(x, y, w, h, formatter);
this.func = callback; this.func = callback;
this.values = values; this.values = values;
@ -85,7 +81,7 @@ public class Dropdown<T> extends Element {
this.formatText(); this.formatText();
} }
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback<T> callback, final String text) { public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback<T> callback, final String text) {
this(x, y, w, h, up, values, def, init, callback, new Formatter<Dropdown<T>>() { this(x, y, w, h, up, values, def, init, callback, new Formatter<Dropdown<T>>() {
public String use(Dropdown<T> elem) { public String use(Dropdown<T> elem) {
T value = elem.getValue(); T value = elem.getValue();

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface DropdownCallback<T> {
void use(Dropdown<T> elem, T value);
}

View file

@ -0,0 +1,194 @@
package client.gui.element;
import client.gui.Font;
import client.renderer.Drawing;
import client.renderer.Drawing.Offset;
import client.renderer.Drawing.Vec2i;
import common.util.CharValidator;
import common.util.ExtMath;
import common.util.Util;
public class Field extends Textbox {
private int textWidth;
private int scrollPos;
private int cursorPos;
private Field(int x, int y, int w, int h, int cap, boolean editable, FieldCallback callback, CharValidator validator, String text) {
super(x, y, w, h, cap, editable, callback, validator);
this.text_y = (this.size_y - (this.margin_y1 + this.margin_y2 + Font.YGLYPH)) / 2;
this.setText(text);
}
public Field(int x, int y, int w, int h, int cap, FieldCallback callback, CharValidator validator, String text) {
this(x, y, w, h, cap, true, callback, validator, text);
}
public Field(int x, int y, int w, int h, int cap, FieldCallback callback, String text) {
this(x, y, w, h, cap, true, callback, null, text);
}
public Field(int x, int y, int w, int h, String text) {
this(x, y, w, h, Integer.MAX_VALUE, false, null, null, text);
}
public void updateText() {
this.textWidth = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
Integer.MAX_VALUE, Integer.MAX_VALUE, this.text).xpos;
}
public void mouserel() {
this.scrollPos = 0;
}
public void onReturn(boolean shift) {
if(this.func != null) {
this.func.use(this, shift ? FieldAction.LINE : FieldAction.SEND);
}
}
public void onSelection(boolean up) {
if(this.func != null) {
this.func.use(this, up ? FieldAction.PREVIOUS : FieldAction.NEXT);
}
}
public void update() {
if(this.scrollPos != 0) {
int n = this.updateScroll(this.scrollPos);
this.text_x += n;
if(n != 0)
gui_text_clamp_scroll();
}
}
public void shift(int shift_x, int shift_y) {
super.shift(shift_x, shift_y);
this.cursorPos += shift_x;
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
if(scr_y != 0 || scr_x != 0) {
int limit = Font.XGLYPH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_x;
this.text_x += ((scr_y != 0 ? scr_y : (-scr_x)) < 0 ? -1 : 1) * (ctrl ? 1 : Font.XGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
if(this.sel_start >= 0)
this.cursorPos += (this.text_x - prev);
}
}
protected int getCursorX(int x1, int x2) {
return this.cursorPos;
}
protected int getCursorY(int y1, int y2) {
return y1 + (y2 - Font.YGLYPH) / 2;
}
protected void gui_text_clamp_scroll() {
int limit = Font.XGLYPH + this.textWidth - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
}
protected void updateCursor(int offset, boolean shift, int x1, int y1, int x2, int y2) {
Vec2i coord = Drawing.txt_coord(offset, x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.text);
this.cursorPos = coord.xpos;
if(shift) {
if(this.cursorPos < x1)
this.text_x += x1 - this.cursorPos;
else if((this.cursorPos + Font.XGLYPH) >= (x1 + x2))
this.text_x -= (this.cursorPos + Font.XGLYPH) - (x1 + x2);
gui_text_update_cur(offset, false);
}
}
protected int onCursorOffset(int x, int y, int x1, int y1, int x2, int y2) {
Offset off = Drawing.txt_offset(x, y, x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, 0x7fffffff, 0x7fffffff, this.text);
if(off != null) {
this.cursorPos = off.xpos;
}
int offset = off == null ? 0 : off.offset;
if(x < x1)
this.scrollPos = x1 - x;
else if(x >= (x1 + x2))
this.scrollPos = -(x - (x1 + x2));
return offset;
}
protected void drawBackground() {
if(this.enabled)
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.field_top, this.gm.style.field_btm, 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.field_top, 0.5f), Util.mulColor(this.gm.style.field_btm, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f));
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text);
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text);
}
protected char getNewline() {
return ' ';
}
public void deleteSpaceToCur() {
int num = this.getSpaceBeforeCur() - this.sel_start;
if(this.text.length() != 0) {
if(this.sel_start != this.sel_end) {
this.insertText("");
}
else {
// boolean flag = num < 0;
int i = this.sel_start + num; // flag ? this.sel_start + num : this.sel_start;
int j = this.sel_start; // flag ? this.sel_start : this.sel_start + num;
String s = "";
if(i >= 0) {
s = this.text.substring(0, i);
}
if(j < this.text.length()) {
s = s + this.text.substring(j);
}
// this.setText(s);
this.text = s;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = i;
gui_text_update_cur(this.sel_start, true);
//
// if(flag) {
// this.moveCursorBy(num);
// }
}
}
}
public int getSpaceBeforeCur() {
int i = this.sel_start;
while(i > 0 && this.text.charAt(i - 1) != ' ') {
--i;
}
return i;
}
public int getCursorPos() {
return this.sel_start == this.sel_end ? this.sel_start : -1;
}
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
public enum FieldAction {
FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD;
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface FieldCallback extends TextCallback<Field> {
void use(Field elem, FieldAction value);
}

View file

@ -9,8 +9,8 @@ public class NavButton extends ActButton {
private final Gui navGui; private final Gui navGui;
public NavButton(int x, int y, int w, int h, Gui gui, String text) { public NavButton(int x, int y, int w, int h, Gui gui, String text) {
super(x, y, w, h, new Callback() { super(x, y, w, h, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
Client.CLIENT.displayGuiScreen(gui); Client.CLIENT.displayGuiScreen(gui);
} }
}, text); }, text);

View file

@ -1,27 +0,0 @@
package client.gui.element;
import client.gui.Font;
import client.renderer.Drawing;
import common.util.Util;
public class PasswordBox extends Textbox {
public PasswordBox(int x, int y, int w, int h, int cap, Callback callback, String text) {
super(x, y, w, h, cap, true, callback, text);
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text.isEmpty() ? "" : "****");
}
public void drawOverlay() {
if(Util.ftime() % 1.0f < 0.5f) {
int x1 = this.pos_x + this.margin_x1;
int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
Drawing.drawRect(x1, y1 + (y2 - Font.YGLYPH) / 2, 1, Font.YGLYPH, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm)));
}
}
}

View file

@ -0,0 +1,20 @@
package client.gui.element;
import client.renderer.Drawing;
import common.util.Util;
public class PasswordField extends Field {
public PasswordField(int x, int y, int w, int h, int cap, FieldCallback callback, String text) {
super(x, y, w, h, cap, callback, text);
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1 + this.text_x, y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text.isEmpty() ? "" : "****");
}
protected int getCursorX(int x1, int x2) {
return x1;
}
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
public enum PressType {
PRIMARY, SECONDARY, TERTIARY;
}

View file

@ -6,7 +6,7 @@ import common.util.Util;
public class SelectableButton extends ActButton { public class SelectableButton extends ActButton {
private boolean selected; private boolean selected;
public SelectableButton(int x, int y, int w, int h, Callback callback, String text, boolean selected) { public SelectableButton(int x, int y, int w, int h, ButtonCallback callback, String text, boolean selected) {
super(x, y, w, h, callback, text); super(x, y, w, h, callback, text);
this.selected = selected; this.selected = selected;
} }

View file

@ -7,17 +7,9 @@ import common.util.ExtMath;
import common.util.Util; import common.util.Util;
public class Slider extends Element { public class Slider extends Element {
public static interface Callback {
void use(Slider elem, int value);
}
public static interface FloatCallback {
void use(Slider elem, float value);
}
private static final int SLIDER_WIDTH = 10; private static final int SLIDER_WIDTH = 10;
private final Callback func; private final SliderCallback func;
private final int def; private final int def;
private final int min; private final int min;
private final int max; private final int max;
@ -27,7 +19,7 @@ public class Slider extends Element {
private int value; private int value;
private int position; private int position;
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, Formatter<Slider> formatter) { public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, Formatter<Slider> formatter) {
super(x, y, w, h, formatter); super(x, y, w, h, formatter);
this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1; this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1;
this.func = callback; this.func = callback;
@ -40,7 +32,7 @@ public class Slider extends Element {
this.formatText(); this.formatText();
} }
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, final String text) { public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, final String text) {
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() { this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
public String use(Slider elem) { public String use(Slider elem) {
return String.format("%s: %d", text, elem.value); return String.format("%s: %d", text, elem.value);
@ -48,7 +40,7 @@ public class Slider extends Element {
}); });
} }
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, final String text, final String unit) { public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, final String text, final String unit) {
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() { this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
private final String format = unit.isEmpty() ? "%s: %d" : "%s: %d %s"; private final String format = unit.isEmpty() ? "%s: %d" : "%s: %d %s";
@ -58,15 +50,15 @@ public class Slider extends Element {
}); });
} }
public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final FloatCallback callback, Formatter<Slider> formatter) { public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final SliderFloatCallback callback, Formatter<Slider> formatter) {
this(x, y, w, h, prec, (int)(min * 1000.0f), (int)(max * 1000.0f), (int)(def * 1000.0f), (int)(init * 1000.0f), new Callback() { this(x, y, w, h, prec, (int)(min * 1000.0f), (int)(max * 1000.0f), (int)(def * 1000.0f), (int)(init * 1000.0f), new SliderCallback() {
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
callback.use(elem, (float)value / 1000.0f); callback.use(elem, (float)value / 1000.0f);
} }
}, formatter); }, formatter);
} }
public Slider(int x, int y, int w, int h, final int prec, float min, float max, float def, float init, FloatCallback callback, final String text, final String unit) { public Slider(int x, int y, int w, int h, final int prec, float min, float max, float def, float init, SliderFloatCallback callback, final String text, final String unit) {
this(x, y, w, h, prec < 0 ? 0 : prec, min, max, def, init, callback, new Formatter<Slider>() { this(x, y, w, h, prec < 0 ? 0 : prec, min, max, def, init, callback, new Formatter<Slider>() {
private final String format = "%s: " + (prec <= 0 ? "%d" : ("%." + prec + "f")) + (unit.isEmpty() ? "" : " %s"); private final String format = "%s: " + (prec <= 0 ? "%d" : ("%." + prec + "f")) + (unit.isEmpty() ? "" : " %s");

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface SliderCallback {
void use(Slider elem, int value);
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface SliderFloatCallback {
void use(Slider elem, float value);
}

View file

@ -6,17 +6,13 @@ import common.util.Displayable;
import common.util.Util; import common.util.Util;
public class Switch<T> extends Element { public class Switch<T> extends Element {
public static interface Callback<T> { private final SwitchCallback<T> func;
void use(Switch<T> elem, T value);
}
private final Callback<T> func;
private final T[] values; private final T[] values;
private final int def; private final int def;
private int value; private int value;
public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback<T> callback, Formatter<Switch<T>> formatter) { public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback<T> callback, Formatter<Switch<T>> formatter) {
super(x, y, w, h, formatter); super(x, y, w, h, formatter);
this.func = callback; this.func = callback;
this.values = values; this.values = values;
@ -25,7 +21,7 @@ public class Switch<T> extends Element {
this.formatText(); this.formatText();
} }
public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback<T> callback, final String text) { public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback<T> callback, final String text) {
this(x, y, w, h, values, def, init, callback, new Formatter<Switch<T>>() { this(x, y, w, h, values, def, init, callback, new Formatter<Switch<T>>() {
public String use(Switch<T> elem) { public String use(Switch<T> elem) {
T value = elem.getValue(); T value = elem.getValue();

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface SwitchCallback<T> {
void use(Switch<T> elem, T value);
}

View file

@ -0,0 +1,5 @@
package client.gui.element;
interface TextCallback<T extends Textbox> {
void use(T elem, FieldAction value);
}

View file

@ -5,97 +5,44 @@ import org.lwjgl.opengl.GL11;
import client.Timing; import client.Timing;
import client.gui.Font; import client.gui.Font;
import client.renderer.Drawing; import client.renderer.Drawing;
import client.renderer.Drawing.Offset;
import client.renderer.Drawing.Vec2i;
import client.window.Button; import client.window.Button;
import client.window.Keysym; import client.window.Keysym;
import client.window.Window; import client.window.Window;
import common.util.CharValidator; import common.util.CharValidator;
import common.util.ExtMath;
import common.util.Util; import common.util.Util;
public class Textbox extends Element { abstract class Textbox extends Element {
public static enum Action { protected final TextCallback func;
FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD; protected final CharValidator validator;
} protected final int capacity;
protected final boolean editable;
public static interface Callback { protected long tmr_scroll;
void use(Textbox elem, Action value); protected long tmr_leftmb;
} protected int sel_start = -1;
protected int sel_end = -1;
protected int sel_drag = -1;
private final Callback func; protected Textbox(int x, int y, int w, int h, int cap, boolean editable, TextCallback callback, CharValidator validator) {
private final CharValidator validator;
private final int capacity;
private final boolean xbreak;
private final boolean editable;
private long tmr_scroll;
private long tmr_leftmb;
private int scrollx;
private int scrolly;
private int sel_start = -1;
private int sel_end = -1;
private int sel_drag = -1;
private int cursorX = 0;
private int cursorY = 0;
private int tsize_x = 0;
private int tsize_y = 0;
private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) {
super(x, y, w, h, null); super(x, y, w, h, null);
this.func = callback; this.func = callback;
this.validator = validator; this.validator = validator;
this.capacity = cap; this.capacity = cap;
this.xbreak = !line;
this.editable = editable; this.editable = editable;
if(line)
this.text_y = (this.size_y - (this.margin_y1 + this.margin_y2 + Font.YGLYPH)) / 2;
this.setText(text);
} }
public Textbox(int x, int y, int w, int h, int cap, boolean line, Callback callback, String text) { public abstract void updateText();
this(x, y, w, h, cap, line, true, callback, null, text); protected abstract void onReturn(boolean shift);
} protected abstract void onSelection(boolean up);
public abstract void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift);
public Textbox(int x, int y, int w, int h, int cap, boolean line, Callback callback, CharValidator validator, String text) { public abstract void update();
this(x, y, w, h, cap, line, true, callback, validator, text); protected abstract void gui_text_clamp_scroll();
} protected abstract void updateCursor(int offset, boolean shift, int x1, int y1, int x2, int y2);
protected abstract char getNewline();
public Textbox(int x, int y, int w, int h, int cap, Callback callback, String text) { protected abstract int getCursorX(int x1, int x2);
this(x, y, w, h, cap, false, true, callback, null, text); protected abstract int getCursorY(int y1, int y2);
} protected abstract int onCursorOffset(int x, int y, int x1, int y1, int x2, int y2);
protected abstract void drawForeground(int x1, int y1, int x2, int y2);
public Textbox(int x, int y, int w, int h, String text) {
this(x, y, w, h, Integer.MAX_VALUE, false, false, null, null, text);
}
public Textbox(int x, int y, int w, int h, boolean line, String text) {
this(x, y, w, h, Integer.MAX_VALUE, line, false, null, null, text);
}
// public void setEditable(boolean editable) {
// this.editable = editable;
// }
// protected boolean isTextCenteredX() {
// return false;
// }
//
// protected boolean isTextCenteredY() {
// return false;
// }
// protected boolean hasLinebreak() {
// return this.xbreak;
// }
public void updateText() {
Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.xbreak ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text);
this.tsize_x = size.xpos;
this.tsize_y = size.ypos;
}
public boolean canHover() { public boolean canHover() {
return false; return false;
@ -114,35 +61,11 @@ public class Textbox extends Element {
gui_text_update_cur(this.sel_start, true); gui_text_update_cur(this.sel_start, true);
} }
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
if(scr_y != 0 && this.xbreak) {
int limit = Font.YGLYPH + this.tsize_y - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_y;
this.text_y += (scr_y < 0 ? -1 : 1) * (ctrl ? 1 : Font.YGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
if(this.sel_start >= 0)
this.cursorY += (this.text_y - prev);
// this.r_dirty = true;
}
else if(scr_y != 0 || scr_x != 0) {
int limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_x;
this.text_x += ((scr_y != 0 ? scr_y : (-scr_x)) < 0 ? -1 : 1) * (ctrl ? 1 : Font.XGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
if(this.sel_start >= 0)
this.cursorX += (this.text_x - prev);
// this.r_dirty = true;
}
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
if(btn == Button.MOUSE_LEFT) { if(btn == Button.MOUSE_LEFT) {
if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) {
this.sel_start = this.sel_drag = 0; this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length(); this.sel_end = this.text.length();
// this.r_dirty = true;
} }
else { else {
gui_text_select(x, y, shift); gui_text_select(x, y, shift);
@ -150,41 +73,28 @@ public class Textbox extends Element {
this.tmr_leftmb = Timing.tmr_current; this.tmr_leftmb = Timing.tmr_current;
} }
else if((btn == Button.MOUSE_MIDDLE) && this.func != null) { else if((btn == Button.MOUSE_MIDDLE) && this.func != null) {
this.func.use(this, Action.FUNCTION); this.func.use(this, FieldAction.FUNCTION);
} }
} }
public void mouserel() {
this.scrollx = this.scrolly = 0;
}
public void drag(int x, int y) { public void drag(int x, int y) {
gui_text_select(x, y, true); gui_text_select(x, y, true);
} }
public void character(char code) { public void character(char code) {
if(this.editable) { if(this.editable)
// int pos = 0;
// char chr[8];
// utf_rwriten(chr, &pos, 8, code);
// chr[pos] = 0;
insertText(Character.toString(code)); insertText(Character.toString(code));
}
} }
public void key(Keysym key, boolean ctrl, boolean shift) { public void key(Keysym key, boolean ctrl, boolean shift) {
if(ctrl && key == Keysym.A) { if(ctrl && key == Keysym.A) {
this.sel_start = this.sel_drag = 0; this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length(); this.sel_end = this.text.length();
// this.r_dirty = true;
} }
else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) { else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) {
if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty
// char end = this.text[this.sel_end];
// this.text[this.sel_end] = 0;
String str = Util.strip(this.text, this.sel_start, this.sel_end - this.sel_start, '\n', (char)0, '?'); String str = Util.strip(this.text, this.sel_start, this.sel_end - this.sel_start, '\n', (char)0, '?');
Window.setClipboard(str); Window.setClipboard(str);
// this.text[this.sel_end] = end;
if(key == Keysym.X) if(key == Keysym.X)
insertText(""); insertText("");
} }
@ -193,12 +103,7 @@ public class Textbox extends Element {
insertText(Window.getClipboard()); insertText(Window.getClipboard());
} }
else if(this.editable && !ctrl && key == Keysym.RETURN) { else if(this.editable && !ctrl && key == Keysym.RETURN) {
if(this.xbreak) { this.onReturn(shift);
insertText("\n");
}
else if(this.func != null) {
this.func.use(this, shift ? Action.LINE : Action.SEND);
}
} }
else if(this.editable && (!ctrl) && (key == Keysym.BACKSPACE || key == Keysym.DELETE)) { else if(this.editable && (!ctrl) && (key == Keysym.BACKSPACE || key == Keysym.DELETE)) {
if(this.sel_start != this.sel_end) { if(this.sel_start != this.sel_end) {
@ -242,150 +147,60 @@ public class Textbox extends Element {
} }
} }
else if(!ctrl && (key == Keysym.DOWN || key == Keysym.UP)) { else if(!ctrl && (key == Keysym.DOWN || key == Keysym.UP)) {
if(this.xbreak) { this.onSelection(key == Keysym.UP);
if(key == Keysym.DOWN && this.sel_start != this.sel_end) {
this.sel_start = this.sel_drag = this.sel_end;
}
else if(key == Keysym.UP && this.sel_start != this.sel_end) {
this.sel_end = this.sel_drag = this.sel_start;
}
if(key == Keysym.DOWN && this.sel_start >= 0) {
if(this.sel_end < this.text.length()) {
// char ch = this.text.charAt(this.sel_end);
// this.sel_end += 1;
int nl = this.text.indexOf('\n', this.sel_end);
// while(ch && ch != '\n') {
// ch = utf_readn(this.text, &this.sel_end);
// }
this.sel_end = nl >= 0 ? nl + 1 : this.text.length();
// else
// this.sel_end -= 1;
this.sel_start = this.sel_drag = this.sel_end;
}
else {
this.sel_end = this.sel_drag = this.sel_start;
}
gui_text_update_cur(this.sel_end, true);
}
else if(key == Keysym.UP && this.sel_start >= 0) {
// uint ch;
if(this.sel_start > 0) {
int nl = this.text.lastIndexOf('\n', this.sel_start);
this.sel_start = nl >= 0 ? nl : 0;
// do {
// ch = utf_rreadn(this.text, &this.sel_start);
// }
// while(ch && ch != '\n');
}
this.sel_end = this.sel_drag = this.sel_start;
gui_text_update_cur(this.sel_end, true);
}
}
else if(this.func != null) {
this.func.use(this, (key == Keysym.DOWN) ? Action.NEXT : Action.PREVIOUS);
}
} }
else if((!ctrl) && key == Keysym.TAB) { else if((!ctrl) && key == Keysym.TAB) {
if(this.func != null) { if(this.func != null) {
this.func.use(this, shift ? Action.BACKWARD : Action.FORWARD); this.func.use(this, shift ? FieldAction.BACKWARD : FieldAction.FORWARD);
} }
} }
} }
public void select() { public void select() {
if(this.func != null) { if(this.func != null) {
this.func.use(this, Action.FOCUS); this.func.use(this, FieldAction.FOCUS);
} }
} }
public void deselect() { public void deselect() {
this.sel_start = this.sel_end = this.sel_drag = -1; this.sel_start = this.sel_end = this.sel_drag = -1;
this.tmr_leftmb = 0L; this.tmr_leftmb = 0L;
// this.r_dirty = true;
if(this.func != null) { if(this.func != null) {
this.func.use(this, Action.UNFOCUS); this.func.use(this, FieldAction.UNFOCUS);
} }
} }
public void update() { protected int updateScroll(int value) {
if((this.scrollx != 0 && !(this.xbreak)) || (this.scrolly != 0 && this.xbreak)) { if(value != 0) {
int n; int n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)value));
if(!this.xbreak)
this.text_x += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrollx)));
else
this.text_y += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrolly)));
if(n != 0) {
gui_text_clamp_scroll();
// this.r_dirty = true;
}
if((((long)n) * 1000000L) <= this.tmr_scroll) if((((long)n) * 1000000L) <= this.tmr_scroll)
this.tmr_scroll -= ((long)n) * 1000000L; this.tmr_scroll -= ((long)n) * 1000000L;
else else
this.tmr_scroll = 0L; this.tmr_scroll = 0L;
this.tmr_scroll += Timing.tmr_delta; this.tmr_scroll += Timing.tmr_delta;
return n;
} }
return 0;
} }
public void shift(int shift_x, int shift_y) { protected void gui_text_update_cur(int offset, boolean shift) {
super.shift(shift_x, shift_y);
this.cursorX += shift_x;
this.cursorY += shift_y;
}
private void gui_text_clamp_scroll() {
int limit;
if(this.xbreak) {
limit = Font.YGLYPH + this.tsize_y - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
}
else {
limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
}
}
private void gui_text_update_cur(int offset, boolean shift) {
int x1 = this.pos_x + this.margin_x1; int x1 = this.pos_x + this.margin_x1;
int y1 = this.pos_y + this.margin_y1; int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2); int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
gui_text_clamp_scroll(); gui_text_clamp_scroll();
Vec2i coord = Drawing.txt_coord(offset, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y, this.updateCursor(offset, shift, x1, y1, x2, y2);
x1 + this.text_x, y1 + this.text_y, this.xbreak ? (this.pos_x + x2) : 0x7fffffff, 0x7fffffff, this.text);
this.cursorX = coord.xpos;
this.cursorY = coord.ypos;
if(shift) {
if(this.xbreak && this.cursorY < y1)
this.text_y += y1 - this.cursorY;
else if(this.xbreak && (this.cursorY + Font.YGLYPH) >= (y1 + y2))
this.text_y -= (this.cursorY + Font.YGLYPH) - (y1 + y2);
if(!(this.xbreak) && this.cursorX < x1)
this.text_x += x1 - this.cursorX;
else if(!(this.xbreak) && (this.cursorX + Font.XGLYPH) >= (x1 + x2))
this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2);
gui_text_update_cur(offset, false);
}
// else {
// this.r_dirty = true;
// }
} }
public void insertText(String str) { public void insertText(String str) {
if(str == null || (this.sel_start == -1)) if(str == null || (this.sel_start == -1))
return; return;
str = Util.strip(str, 0, str.length(), this.xbreak ? '\n' : ' ', ' ', (char)0); str = Util.strip(str, 0, str.length(), this.getNewline(), ' ', (char)0);
if(this.validator != null) if(this.validator != null)
str = this.validator.filter(str); str = this.validator.filter(str);
// plen = strlen(&sys.work_buf[1 + olen - this.sel_end]);
// logd("t", "%d %d %d", olen, slen, plen);
if((str.length() + this.text.length() - (this.sel_end - this.sel_start)) > this.capacity) if((str.length() + this.text.length() - (this.sel_end - this.sel_start)) > this.capacity)
return; return;
this.text = this.text.substring(0, this.sel_start) + str + this.text.substring(this.sel_end); this.text = this.text.substring(0, this.sel_start) + str + this.text.substring(this.sel_end);
// memcpy(sys.work_buf, &this.text[this.sel_end], 1 + this.text.length() - this.sel_end);
// memcpy(&this.text[this.sel_start], &sys.work_buf[1 + this.text.length() - this.sel_end], str.length());
// memcpy(&this.text[this.sel_start + str.length()], sys.work_buf, 1 + this.text.length() - this.sel_end);
this.sel_start += str.length(); this.sel_start += str.length();
this.sel_end = this.sel_drag = this.sel_start; this.sel_end = this.sel_drag = this.sel_start;
this.updateText(); this.updateText();
@ -397,15 +212,7 @@ public class Textbox extends Element {
int y1 = this.pos_y + this.margin_y1; int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2); int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
Offset off = Drawing.txt_offset(x, y, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y, int offset = this.onCursorOffset(x, y, x1, y1, x2, y2);
x1 + this.text_x, y1 + this.text_y, this.xbreak ? (this.pos_x + x2) : 0x7fffffff, 0x7fffffff, this.text);
if(off != null) {
this.cursorX = off.xpos;
this.cursorY = off.ypos;
}
int offset = off == null ? 0 : off.offset;
// logd("tst", "@A %d %d -. %d %d", x1, y1, x2, y2);
// logd("tst", "@C %d %d -. %d, %d %d", x, y, offset, this.min, this.max);
if(!drag) { if(!drag) {
this.sel_drag = this.sel_start = this.sel_end = offset; this.sel_drag = this.sel_start = this.sel_end = offset;
} }
@ -417,16 +224,6 @@ public class Textbox extends Element {
this.sel_start = offset; this.sel_start = offset;
this.sel_end = this.sel_drag; this.sel_end = this.sel_drag;
} }
// logd("tst", "@S %d . %d . %d", this.sel_start, this.sel_drag, this.sel_end);
// this.r_dirty = true;
if(x < x1)
this.scrollx = x1 - x;
else if(x >= (x1 + x2))
this.scrollx = -(x - (x1 + x2));
if(y < y1)
this.scrolly = y1 - y;
else if(y >= (y1 + y2))
this.scrolly = -(y - (y1 + y2));
} }
protected void drawBackground() { protected void drawBackground() {
@ -436,16 +233,6 @@ public class Textbox extends Element {
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, Util.mulColor(this.gm.style.field_top, 0.5f), Util.mulColor(this.gm.style.field_btm, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f)); Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, Util.mulColor(this.gm.style.field_top, 0.5f), Util.mulColor(this.gm.style.field_btm, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f));
} }
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text);
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text);
}
public void drawOverlay() { public void drawOverlay() {
if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && Util.ftime() % 1.0f < 0.5f) { if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && Util.ftime() % 1.0f < 0.5f) {
int x1 = this.pos_x + this.margin_x1; int x1 = this.pos_x + this.margin_x1;
@ -454,61 +241,8 @@ public class Textbox extends Element {
int y2 = this.size_y - (this.margin_y1 + this.margin_y2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glEnable(GL11.GL_SCISSOR_TEST);
Drawing.drawRect(this.cursorX, this.cursorY, 1, Font.YGLYPH, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm))); Drawing.drawRect(this.getCursorX(x1, x2), this.getCursorY(y1, y2), 1, Font.YGLYPH, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm)));
GL11.glDisable(GL11.GL_SCISSOR_TEST); GL11.glDisable(GL11.GL_SCISSOR_TEST);
} }
} }
public void deleteFromCursor() {
int num = this.getNthCharFromPos() - this.sel_start;
if(this.text.length() != 0) {
if(this.sel_start != this.sel_end) {
this.insertText("");
}
else {
// boolean flag = num < 0;
int i = this.sel_start + num; // flag ? this.sel_start + num : this.sel_start;
int j = this.sel_start; // flag ? this.sel_start : this.sel_start + num;
String s = "";
if(i >= 0) {
s = this.text.substring(0, i);
}
if(j < this.text.length()) {
s = s + this.text.substring(j);
}
// this.setText(s);
this.text = s;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = i;
gui_text_update_cur(this.sel_start, true);
//
// if(flag) {
// this.moveCursorBy(num);
// }
}
}
}
public int getNthCharFromPos() {
int i = this.sel_start;
while(i > 0 && this.text.charAt(i - 1) != ' ') {
--i;
}
return i;
}
public int getCursorPosition() {
return this.sel_start == this.sel_end ? this.sel_start : -1;
}
} }

View file

@ -6,16 +6,12 @@ import client.window.Button;
import common.util.Util; import common.util.Util;
public class Toggle extends Element { public class Toggle extends Element {
public static interface Callback { private final ToggleCallback func;
void use(Toggle elem, boolean value);
}
private final Callback func;
private final boolean def; private final boolean def;
private boolean value; private boolean value;
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter<Toggle> formatter) { public Toggle(int x, int y, int w, int h, boolean def, boolean init, ToggleCallback callback, Formatter<Toggle> formatter) {
super(x, y, w, h, formatter); super(x, y, w, h, formatter);
this.func = callback; this.func = callback;
this.def = def; this.def = def;
@ -23,7 +19,7 @@ public class Toggle extends Element {
this.formatText(); this.formatText();
} }
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, final String text) { public Toggle(int x, int y, int w, int h, boolean def, boolean init, ToggleCallback callback, final String text) {
this(x, y, w, h, def, init, callback, new Formatter<Toggle>() { this(x, y, w, h, def, init, callback, new Formatter<Toggle>() {
public String use(Toggle elem) { public String use(Toggle elem) {
return String.format("%s: %s", text, elem.value ? "An" : "Aus"); return String.format("%s: %s", text, elem.value ? "An" : "Aus");

View file

@ -0,0 +1,5 @@
package client.gui.element;
public interface ToggleCallback {
void use(Toggle elem, boolean value);
}

View file

@ -2,10 +2,10 @@ package client.gui.element;
import client.renderer.Drawing; import client.renderer.Drawing;
public class TransparentBox extends Textbox { public class TransparentArea extends Area {
private final boolean background; private final boolean background;
public TransparentBox(int x, int y, int w, int h, String text, boolean background) { public TransparentArea(int x, int y, int w, int h, String text, boolean background) {
super(x, y, w, h, text); super(x, y, w, h, text);
this.background = background; this.background = background;
} }

View file

@ -2,22 +2,26 @@ package client.gui.ingame;
import client.gui.Gui; import client.gui.Gui;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.Element; import client.gui.element.Element;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.PasswordBox; import client.gui.element.PasswordField;
import client.gui.element.PressType;
import client.gui.element.Switch; import client.gui.element.Switch;
import client.gui.element.Textbox; import client.gui.element.SwitchCallback;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.gui.element.Toggle; import client.gui.element.Toggle;
import client.gui.element.ToggleCallback;
import client.network.ClientPlayer; import client.network.ClientPlayer;
import common.color.TextColor; import common.color.TextColor;
import common.packet.CPacketForm; import common.packet.CPacketForm;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Triplet; import common.util.Triplet;
public class GuiForm extends Gui implements ActButton.Callback { public class GuiForm extends Gui implements ButtonCallback {
private final int id; private final int id;
private final String title; private final String title;
private final Element[] inputs; private final Element[] inputs;
@ -35,7 +39,7 @@ public class GuiForm extends Gui implements ActButton.Callback {
Object obj = this.inputData[z].second; Object obj = this.inputData[z].second;
int param = this.inputData[z].third; int param = this.inputData[z].third;
if(obj instanceof Boolean) { if(obj instanceof Boolean) {
this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 24, (Boolean)obj, (Boolean)obj, new Toggle.Callback() { this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 24, (Boolean)obj, (Boolean)obj, new ToggleCallback() {
public void use(Toggle elem, boolean value) { public void use(Toggle elem, boolean value) {
GuiForm.this.outputData[index] = value; GuiForm.this.outputData[index] = value;
} }
@ -44,7 +48,7 @@ public class GuiForm extends Gui implements ActButton.Callback {
else if(obj instanceof String[]) { else if(obj instanceof String[]) {
final String[] strs = (String[])obj; final String[] strs = (String[])obj;
param = ExtMath.clampi(param, 0, strs.length - 1); param = ExtMath.clampi(param, 0, strs.length - 1);
this.inputs[z] = this.add(new Switch<String>(0, 50 * z, 300, 24, strs, strs[param], strs[param], new Switch.Callback<String>() { this.inputs[z] = this.add(new Switch<String>(0, 50 * z, 300, 24, strs, strs[param], strs[param], new SwitchCallback<String>() {
public void use(Switch<String> elem, String value) { public void use(Switch<String> elem, String value) {
for(int n = 0; n < strs.length; n++) { for(int n = 0; n < strs.length; n++) {
if(value == strs[n]) { if(value == strs[n]) {
@ -57,14 +61,14 @@ public class GuiForm extends Gui implements ActButton.Callback {
} }
else { else {
this.labels[z] = this.add(new Label(0, 50 * z - 20, 300, 20, name, true)); this.labels[z] = this.add(new Label(0, 50 * z - 20, 300, 20, name, true));
Textbox.Callback callback = new Textbox.Callback() { FieldCallback callback = new FieldCallback() {
public void use(Textbox elem, Action value) { public void use(Field elem, FieldAction value) {
if(value == Action.FOCUS) if(value == FieldAction.FOCUS)
GuiForm.this.labels[index].setText(name); GuiForm.this.labels[index].setText(name);
} }
}; };
this.inputs[z] = this.add((param & 0x80000000) != 0 ? new PasswordBox(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), callback, (String)obj) : this.inputs[z] = this.add((param & 0x80000000) != 0 ? new PasswordField(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), callback, (String)obj) :
new Textbox(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), true, callback, (String)obj)); new Field(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), callback, (String)obj));
} }
} }
this.add(new NavButton(0, 50 * (this.inputs.length + 1), 148, 24, null, "Abbrechen")); this.add(new NavButton(0, 50 * (this.inputs.length + 1), 148, 24, null, "Abbrechen"));
@ -98,9 +102,9 @@ public class GuiForm extends Gui implements ActButton.Callback {
} }
} }
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
for(int z = 0; z < this.inputs.length; z++) { for(int z = 0; z < this.inputs.length; z++) {
if(this.inputs[z] instanceof Textbox) { if(this.inputs[z] instanceof Field) {
int min = (this.inputData[z].third & 0x7fffffff) >> 16; int min = (this.inputData[z].third & 0x7fffffff) >> 16;
String text = this.inputs[z].getText(); String text = this.inputs[z].getText();
if(text.length() < min) { if(text.length() < min) {

View file

@ -2,9 +2,10 @@ package client.gui.ingame;
import client.gui.Gui; import client.gui.Gui;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import common.color.TextColor; import common.color.TextColor;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.PressType;
public class GuiGameOver extends Gui { public class GuiGameOver extends Gui {
public static final GuiGameOver INSTANCE = new GuiGameOver(); public static final GuiGameOver INSTANCE = new GuiGameOver();
@ -19,8 +20,8 @@ public class GuiGameOver extends Gui {
this.timer = 0; this.timer = 0;
this.add(new Label(0, 0, 200, 20, "Du bist gestorben!")); this.add(new Label(0, 0, 200, 20, "Du bist gestorben!"));
this.add(new Label(0, 32, 200, 20, "Punktestand: " + TextColor.YELLOW + this.gm.player.experienceLevel)); this.add(new Label(0, 32, 200, 20, "Punktestand: " + TextColor.YELLOW + this.gm.player.experienceLevel));
this.button = this.add(new ActButton(0, 100, 200, 24, new ActButton.Callback() { this.button = this.add(new ActButton(0, 100, 200, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiGameOver.this.gm.player.respawnPlayer(); GuiGameOver.this.gm.player.respawnPlayer();
GuiGameOver.this.gm.displayGuiScreen(null); GuiGameOver.this.gm.displayGuiScreen(null);
} }

View file

@ -3,24 +3,24 @@ package client.gui.ingame;
import client.gui.Gui; import client.gui.Gui;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.NavButton; import client.gui.element.NavButton;
import client.gui.element.Textbox; import client.gui.element.FieldAction;
import client.gui.element.Textbox.Action; import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.network.ClientPlayer; import client.network.ClientPlayer;
import common.packet.CPacketSign; import common.packet.CPacketSign;
import common.util.BlockPos; import common.util.BlockPos;
public class GuiSign extends Gui implements Textbox.Callback { public class GuiSign extends Gui implements FieldCallback {
private final BlockPos position; private final BlockPos position;
private final Textbox[] lines; private final Field[] lines;
private final String[] tempLines; private final String[] tempLines;
public void init(int width, int height) { public void init(int width, int height) {
this.add(new Label(0, -140, 300, 20, "Bearbeite Schild")); this.add(new Label(0, -140, 300, 20, "Bearbeite Schild"));
this.add(new Label(0, -80, 300, 20, String.format("%d, %d, %d", this.position.getX(), this.position.getY(), this.position.getZ()))); this.add(new Label(0, -80, 300, 20, String.format("%d, %d, %d", this.position.getX(), this.position.getY(), this.position.getZ())));
this.add(new Label(0, -50, 300, 20, this.gm.world == null ? "<?>" : this.gm.world.dimension.getFormattedName(false))); this.add(new Label(0, -50, 300, 20, this.gm.world == null ? "<?>" : this.gm.world.dimension.getFormattedName(false)));
for(int z = 0; z < this.lines.length; z++) { for(int z = 0; z < this.lines.length; z++) {
this.lines[z] = this.add(new Textbox(0, 40 * z, 300, 24, 50, true, this, this.tempLines[z] == null ? "" : this.tempLines[z])); this.lines[z] = this.add(new Field(0, 40 * z, 300, 24, 50, this, this.tempLines[z] == null ? "" : this.tempLines[z]));
} }
this.add(new NavButton(0, 40 * (this.lines.length + 1), 300, 24, null, "Fertig")); this.add(new NavButton(0, 40 * (this.lines.length + 1), 300, 24, null, "Fertig"));
this.shift(); this.shift();
@ -42,13 +42,13 @@ public class GuiSign extends Gui implements Textbox.Callback {
public GuiSign(BlockPos sign, String[] lines) { public GuiSign(BlockPos sign, String[] lines) {
this.position = sign; this.position = sign;
this.lines = new Textbox[lines.length]; this.lines = new Field[lines.length];
this.tempLines = new String[lines.length]; this.tempLines = new String[lines.length];
System.arraycopy(lines, 0, this.tempLines, 0, lines.length); System.arraycopy(lines, 0, this.tempLines, 0, lines.length);
} }
public void use(Textbox elem, Action value) { public void use(Field elem, FieldAction value) {
if(value == Action.SEND) if(value == FieldAction.SEND)
this.gm.displayGuiScreen(null); this.gm.displayGuiScreen(null);
} }
} }

View file

@ -2,8 +2,9 @@ package client.gui.options;
import client.gui.Formatter; import client.gui.Formatter;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.PressType;
import client.window.Bind; import client.window.Bind;
import common.color.TextColor; import common.color.TextColor;
@ -16,16 +17,16 @@ public class GuiBinds extends GuiOptions {
int x = 0; int x = 0;
for(Bind bind : Bind.values()) { for(Bind bind : Bind.values()) {
this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay())); 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() { this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(action == Mode.SECONDARY) { if(action == PressType.SECONDARY) {
if(!bind.isDefault()) { if(!bind.isDefault()) {
bind.setDefault(); bind.setDefault();
GuiBinds.this.gm.setDirty(); GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat(); GuiBinds.this.reformat();
} }
} }
else if(action == Mode.TERTIARY) { else if(action == PressType.TERTIARY) {
if(bind.getInput() != null) { if(bind.getInput() != null) {
bind.setInput(null); bind.setInput(null);
GuiBinds.this.gm.setDirty(); GuiBinds.this.gm.setDirty();
@ -50,8 +51,8 @@ public class GuiBinds extends GuiOptions {
} }
} }
y += x != 0 ? 1 : 0; y += x != 0 ? 1 : 0;
this.add(new ActButton(200, 100 + y * 50, 560, 24, new ActButton.Callback() { this.add(new ActButton(200, 100 + y * 50, 560, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
boolean flag = false; boolean flag = false;
for(Bind bind : Bind.values()) { for(Bind bind : Bind.values()) {
flag |= !bind.isDefault(); flag |= !bind.isDefault();

View file

@ -2,10 +2,13 @@ package client.gui.options;
import client.gui.Formatter; import client.gui.Formatter;
import client.gui.element.Dropdown; import client.gui.element.Dropdown;
import client.gui.element.DropdownCallback;
import client.gui.element.Element; import client.gui.element.Element;
import client.gui.element.Fill; import client.gui.element.Fill;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.SliderCallback;
import client.gui.element.Toggle; import client.gui.element.Toggle;
import client.gui.element.ToggleCallback;
import client.window.Button; import client.window.Button;
import client.window.DisplayMode; import client.window.DisplayMode;
import client.window.Window; import client.window.Window;
@ -36,7 +39,7 @@ public class GuiDisplay extends GuiOptions {
if(modes[z].equals(this.gm.vidMode)) if(modes[z].equals(this.gm.vidMode))
selected = modes[z]; selected = modes[z];
} }
this.add(new Dropdown<DisplayMode>(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new Dropdown.Callback<DisplayMode>() { this.add(new Dropdown<DisplayMode>(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new DropdownCallback<DisplayMode>() {
public void use(Dropdown<DisplayMode> elem, DisplayMode value) { public void use(Dropdown<DisplayMode> elem, DisplayMode value) {
GuiDisplay.this.gm.vidMode = value; GuiDisplay.this.gm.vidMode = value;
GuiDisplay.this.gm.full(true); GuiDisplay.this.gm.full(true);
@ -47,12 +50,12 @@ public class GuiDisplay extends GuiOptions {
this.add(new Fill(30, 80, 440, 24, TextColor.RED + "Auflösung: <?>")); this.add(new Fill(30, 80, 440, 24, TextColor.RED + "Auflösung: <?>"));
} }
this.add(new Toggle(490, 80, 440, 24, false, GuiDisplay.this.gm.fullscreen, new Toggle.Callback() { this.add(new Toggle(490, 80, 440, 24, false, GuiDisplay.this.gm.fullscreen, new ToggleCallback() {
public void use(Toggle elem, boolean value) { public void use(Toggle elem, boolean value) {
GuiDisplay.this.gm.full(value); GuiDisplay.this.gm.full(value);
} }
}, "Vollbild")); }, "Vollbild"));
this.add(new Slider(30, 120, 440, 24, 0, 0, 360 - 8, 0, (this.gm.sync < 0) ? (360 - 8) : (this.gm.sync != 0 ? ((this.gm.sync < 10) ? 1 : (this.gm.sync - 9)) : 0), new Slider.Callback() { this.add(new Slider(30, 120, 440, 24, 0, 0, 360 - 8, 0, (this.gm.sync < 0) ? (360 - 8) : (this.gm.sync != 0 ? ((this.gm.sync < 10) ? 1 : (this.gm.sync - 9)) : 0), new SliderCallback() {
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
GuiDisplay.this.gm.getVar("win_sync").parse("" + ((value > 0 && value < 360 - 8) ? (value + 9) : (value != 0 ? -1 : 0))); GuiDisplay.this.gm.getVar("win_sync").parse("" + ((value > 0 && value < 360 - 8) ? (value + 9) : (value != 0 ? -1 : 0)));
GuiDisplay.this.gm.setDirty(); GuiDisplay.this.gm.setDirty();

View file

@ -2,7 +2,8 @@ package client.gui.options;
import client.audio.Volume; import client.audio.Volume;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.PressType;
public class GuiSound extends GuiOptions { public class GuiSound extends GuiOptions {
protected GuiSound() { protected GuiSound() {
@ -14,8 +15,8 @@ public class GuiSound extends GuiOptions {
this.addSelector("snd_buffer_size", 30, 420, 440, 24); this.addSelector("snd_buffer_size", 30, 420, 440, 24);
this.addSelector("snd_frame_size", 490, 420, 440, 24); this.addSelector("snd_frame_size", 490, 420, 440, 24);
this.add(new ActButton(30, 480, 900, 24, new ActButton.Callback() { this.add(new ActButton(30, 480, 900, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiSound.this.gm.restartSound(false); GuiSound.this.gm.restartSound(false);
} }
}, "Übernehmen und Audio-Thread neu starten")); }, "Übernehmen und Audio-Thread neu starten"));

View file

@ -2,19 +2,25 @@ package client.gui.options;
import client.gui.Style; import client.gui.Style;
import client.gui.element.ActButton; import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode; import client.gui.element.ButtonCallback;
import client.gui.element.Dropdown; import client.gui.element.Dropdown;
import client.gui.element.DropdownCallback;
import client.gui.element.Element; import client.gui.element.Element;
import client.gui.element.SelectableButton; import client.gui.element.SelectableButton;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.SliderCallback;
import client.gui.element.Switch; import client.gui.element.Switch;
import client.gui.element.Textbox; import client.gui.element.SwitchCallback;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import client.gui.element.Field;
import client.gui.element.FieldCallback;
import client.gui.element.PressType;
import client.vars.CVar; import client.vars.CVar;
import client.vars.ColorVar; import client.vars.ColorVar;
import client.gui.element.Toggle; import client.gui.element.Toggle;
import client.gui.element.ToggleCallback;
public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, ActButton.Callback, Toggle.Callback, Switch.Callback<String>, Slider.Callback, Textbox.Callback { public class GuiStyle extends GuiOptions implements DropdownCallback<String>, ButtonCallback, ToggleCallback, SwitchCallback<String>, SliderCallback, FieldCallback {
private static final String[] STYLE_CVARS = { private static final String[] STYLE_CVARS = {
"color_button_top", "color_button_top",
"color_textbox_top", "color_textbox_top",
@ -39,7 +45,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
if(!color.getDisplay().isEmpty()) if(!color.getDisplay().isEmpty())
this.add(color.label(x, y - 20, w, 20)); this.add(color.label(x, y - 20, w, 20));
if(this.gm.style != Style.CUSTOM) if(this.gm.style != Style.CUSTOM)
return this.add(new Textbox(x, y, w, h, true, color.getFieldValue(this.gm.style))); return this.add(new Field(x, y, w, h, color.getFieldValue(this.gm.style)));
else else
return this.add(color.editor(x, y, w, h)); return this.add(color.editor(x, y, w, h));
} }
@ -53,8 +59,8 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
} }
z = 0; z = 0;
for(Style theme : Style.values()) { for(Style theme : Style.values()) {
ActButton.Callback callback = new ActButton.Callback() { ButtonCallback callback = new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(GuiStyle.this.gm.style != theme) { if(GuiStyle.this.gm.style != theme) {
GuiStyle.this.gm.style = theme; GuiStyle.this.gm.style = theme;
GuiStyle.this.gm.setDirty(); GuiStyle.this.gm.setDirty();
@ -75,11 +81,11 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
values = new String[] {"VALUE 1", "VALUE 2", "VALUE 3", "VALUE 4"}; values = new String[] {"VALUE 1", "VALUE 2", "VALUE 3", "VALUE 4"};
this.add(new Switch(10, height - 34, 300, 24, values, values[2], values[0], this, "ENUM")); this.add(new Switch(10, height - 34, 300, 24, values, values[2], values[0], this, "ENUM"));
this.add(new Slider(330, height - 34, 300, 24, 0, -20, 827, 60, 120, this, "SLIDER")); this.add(new Slider(330, height - 34, 300, 24, 0, -20, 827, 60, 120, this, "SLIDER"));
this.add(new Textbox(650, height - 34, 300, 24, 128, true, this, "FIELD")); this.add(new Field(650, height - 34, 300, 24, 128, this, "FIELD"));
if(this.gm.style != Style.CUSTOM) { if(this.gm.style != Style.CUSTOM) {
this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ActButton.Callback() { this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
if(GuiStyle.this.gm.style != Style.CUSTOM) { if(GuiStyle.this.gm.style != Style.CUSTOM) {
GuiStyle.this.gm.style.copyToCustom(); GuiStyle.this.gm.style.copyToCustom();
GuiStyle.this.gm.style = Style.CUSTOM; GuiStyle.this.gm.style = Style.CUSTOM;
@ -90,8 +96,8 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
}, "In angepasstes Design kopieren")); }, "In angepasstes Design kopieren"));
} }
else { else {
this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ActButton.Callback() { this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
GuiStyle.this.gm.style = Style.CUSTOM; GuiStyle.this.gm.style = Style.CUSTOM;
for(String cvar : STYLE_CVARS) { for(String cvar : STYLE_CVARS) {
GuiStyle.this.gm.getVar(cvar).setDefault(); GuiStyle.this.gm.getVar(cvar).setDefault();
@ -108,7 +114,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
return "Benutzeroberfläche"; return "Benutzeroberfläche";
} }
public void use(Textbox elem, Action value) { public void use(Field elem, FieldAction value) {
} }
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
} }
@ -116,7 +122,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, A
} }
public void use(Toggle elem, boolean value) { public void use(Toggle elem, boolean value) {
} }
public void use(ActButton elem, Mode action) { public void use(ActButton elem, PressType action) {
} }
public void use(Dropdown<String> elem, String value) { public void use(Dropdown<String> elem, String value) {
} }

View file

@ -3,6 +3,7 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.element.Toggle; import client.gui.element.Toggle;
import client.gui.element.ToggleCallback;
import common.color.TextColor; import common.color.TextColor;
import common.util.Util; import common.util.Util;
@ -59,7 +60,7 @@ public class BoolVar extends BaseVar {
public Toggle selector(int x, int y, int w, int h) { public Toggle selector(int x, int y, int w, int h) {
try { try {
return new Toggle(x, y, w, h, this.def, this.field.getBoolean(this.object), new Toggle.Callback() { return new Toggle(x, y, w, h, this.def, this.field.getBoolean(this.object), new ToggleCallback() {
public void use(Toggle elem, boolean value) { public void use(Toggle elem, boolean value) {
BoolVar.this.parse("" + value); BoolVar.this.parse("" + value);
} }

View file

@ -3,10 +3,10 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.Style; import client.gui.Style;
import client.gui.element.FieldCallback;
import client.gui.element.Label; import client.gui.element.Label;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.Textbox; import client.gui.element.FieldAction;
import client.gui.element.Textbox.Action;
import common.color.TextColor; import common.color.TextColor;
import common.util.Util; import common.util.Util;
@ -26,6 +26,8 @@ public class ColorVar extends IntVar {
if(str.length() != (this.alpha ? 8 : 6)) if(str.length() != (this.alpha ? 8 : 6))
return null; return null;
Integer value = Util.parseInt(str, -16); Integer value = Util.parseInt(str, -16);
if(value == null)
return null;
return this.alpha || (value & 0xff000000) == 0 ? (this.alpha ? value : (0xff000000 | value)) : null; return this.alpha || (value & 0xff000000) == 0 ? (this.alpha ? value : (0xff000000 | value)) : null;
} }
@ -41,10 +43,10 @@ public class ColorVar extends IntVar {
return new Label(x, y, w, h, this.display); return new Label(x, y, w, h, this.display);
} }
public Textbox editor(int x, int y, int w, int h) { public client.gui.element.Field editor(int x, int y, int w, int h) {
return new Textbox(x, y, w, h, this.alpha ? 8 : 6, true, new Textbox.Callback() { return new client.gui.element.Field(x, y, w, h, this.alpha ? 8 : 6, new FieldCallback() {
public void use(Textbox elem, Textbox.Action value) { public void use(client.gui.element.Field elem, FieldAction value) {
if(value == Action.SEND || value == Action.UNFOCUS) if(value == FieldAction.SEND || value == FieldAction.UNFOCUS)
ColorVar.this.parse(elem.getText()); ColorVar.this.parse(elem.getText());
} }
}, this.format()); }, this.format());

View file

@ -3,8 +3,10 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.element.Dropdown; import client.gui.element.Dropdown;
import client.gui.element.DropdownCallback;
import client.gui.element.Element; import client.gui.element.Element;
import client.gui.element.Switch; import client.gui.element.Switch;
import client.gui.element.SwitchCallback;
import common.color.TextColor; import common.color.TextColor;
import common.util.Identifyable; import common.util.Identifyable;
import common.util.Util; import common.util.Util;
@ -79,7 +81,7 @@ public class EnumVar<T extends Enum> extends BaseVar {
if(this.useSwitch) if(this.useSwitch)
return this.switcher(x, y, w, h); return this.switcher(x, y, w, h);
try { try {
return new Dropdown<T>(x, y, w, h, false, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Dropdown.Callback<T>() { return new Dropdown<T>(x, y, w, h, false, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new DropdownCallback<T>() {
public void use(Dropdown<T> elem, T value) { public void use(Dropdown<T> elem, T value) {
EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString()); EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString());
} }
@ -92,7 +94,7 @@ public class EnumVar<T extends Enum> extends BaseVar {
public Switch switcher(int x, int y, int w, int h) { public Switch switcher(int x, int y, int w, int h) {
try { try {
return new Switch<T>(x, y, w, h, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Switch.Callback<T>() { return new Switch<T>(x, y, w, h, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new SwitchCallback<T>() {
public void use(Switch<T> elem, T value) { public void use(Switch<T> elem, T value) {
EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString()); EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString());
} }

View file

@ -3,6 +3,7 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.SliderFloatCallback;
import common.color.TextColor; import common.color.TextColor;
import common.util.ExtMath; import common.util.ExtMath;
@ -90,7 +91,7 @@ public class FloatVar extends BaseVar {
public Slider selector(int x, int y, int w, int h) { public Slider selector(int x, int y, int w, int h) {
try { try {
return new Slider(x, y, w, h, this.unit.equals("%") ? -1 : this.precision, this.min, this.max, this.def, this.field.getFloat(this.object), new Slider.FloatCallback() { return new Slider(x, y, w, h, this.unit.equals("%") ? -1 : this.precision, this.min, this.max, this.def, this.field.getFloat(this.object), new SliderFloatCallback() {
public void use(Slider elem, float value) { public void use(Slider elem, float value) {
FloatVar.this.parse(String.format(FloatVar.this.format, value)); FloatVar.this.parse(String.format(FloatVar.this.format, value));
} }

View file

@ -3,6 +3,7 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.element.Slider; import client.gui.element.Slider;
import client.gui.element.SliderCallback;
import common.color.TextColor; import common.color.TextColor;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Util; import common.util.Util;
@ -82,7 +83,7 @@ public class IntVar extends BaseVar {
public Slider selector(int x, int y, int w, int h) { public Slider selector(int x, int y, int w, int h) {
try { try {
return new Slider(x, y, w, h, this.precision, this.min, this.max, this.def, this.field.getInt(this.object), new Slider.Callback() { return new Slider(x, y, w, h, this.precision, this.min, this.max, this.def, this.field.getInt(this.object), new SliderCallback() {
public void use(Slider elem, int value) { public void use(Slider elem, int value) {
IntVar.this.parse(IntVar.this.formatValue(value)); IntVar.this.parse(IntVar.this.formatValue(value));
} }

View file

@ -2,8 +2,8 @@ package client.vars;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import client.gui.element.Textbox; import client.gui.element.FieldCallback;
import client.gui.element.Textbox.Action; import client.gui.element.FieldAction;
import common.color.TextColor; import common.color.TextColor;
import common.util.CharValidator; import common.util.CharValidator;
@ -67,10 +67,10 @@ public class StringVar extends BaseVar {
return this.def; return this.def;
} }
public Textbox selector(int x, int y, int w, int h) { public client.gui.element.Field selector(int x, int y, int w, int h) {
return new Textbox(x, y, w, h, this.maxLength, true, new Textbox.Callback() { return new client.gui.element.Field(x, y, w, h, this.maxLength, new FieldCallback() {
public void use(Textbox elem, Textbox.Action value) { public void use(client.gui.element.Field elem, FieldAction value) {
if(value == Action.SEND || value == Action.UNFOCUS) { if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) {
if(!StringVar.this.allowEmpty && elem.getText().isEmpty()) if(!StringVar.this.allowEmpty && elem.getText().isEmpty())
elem.setText(StringVar.this.format()); elem.setText(StringVar.this.format());
else else