From 2ea3267e3a360cfbee80894a35b6eb44ccc6a3ab Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 18 May 2025 14:30:35 +0200 Subject: [PATCH] split text fields --- client/src/client/Client.java | 4 +- client/src/client/audio/Volume.java | 3 +- client/src/client/gui/GuiConfirm.java | 11 +- client/src/client/gui/GuiConnect.java | 9 +- client/src/client/gui/GuiConsole.java | 47 +-- client/src/client/gui/GuiInfo.java | 4 +- client/src/client/gui/GuiMenu.java | 26 +- client/src/client/gui/GuiServer.java | 43 ++- client/src/client/gui/character/GuiChar.java | 61 +-- .../client/gui/character/GuiCharacters.java | 15 +- client/src/client/gui/character/GuiClass.java | 9 +- .../src/client/gui/character/GuiSpecies.java | 9 +- client/src/client/gui/element/ActButton.java | 16 +- client/src/client/gui/element/Area.java | 159 ++++++++ .../client/gui/element/ButtonCallback.java | 5 + client/src/client/gui/element/Dropdown.java | 10 +- .../client/gui/element/DropdownCallback.java | 5 + client/src/client/gui/element/Field.java | 194 ++++++++++ .../src/client/gui/element/FieldAction.java | 5 + .../src/client/gui/element/FieldCallback.java | 5 + client/src/client/gui/element/NavButton.java | 4 +- .../src/client/gui/element/PasswordBox.java | 27 -- .../src/client/gui/element/PasswordField.java | 20 + client/src/client/gui/element/PressType.java | 5 + .../client/gui/element/SelectableButton.java | 2 +- client/src/client/gui/element/Slider.java | 22 +- .../client/gui/element/SliderCallback.java | 5 + .../gui/element/SliderFloatCallback.java | 5 + client/src/client/gui/element/Switch.java | 10 +- .../client/gui/element/SwitchCallback.java | 5 + .../src/client/gui/element/TextCallback.java | 5 + client/src/client/gui/element/Textbox.java | 348 +++--------------- client/src/client/gui/element/Toggle.java | 10 +- .../client/gui/element/ToggleCallback.java | 5 + ...ansparentBox.java => TransparentArea.java} | 4 +- client/src/client/gui/ingame/GuiForm.java | 32 +- client/src/client/gui/ingame/GuiGameOver.java | 7 +- client/src/client/gui/ingame/GuiSign.java | 18 +- client/src/client/gui/options/GuiBinds.java | 15 +- client/src/client/gui/options/GuiDisplay.java | 9 +- client/src/client/gui/options/GuiSound.java | 7 +- client/src/client/gui/options/GuiStyle.java | 34 +- client/src/client/vars/BoolVar.java | 3 +- client/src/client/vars/ColorVar.java | 14 +- client/src/client/vars/EnumVar.java | 6 +- client/src/client/vars/FloatVar.java | 3 +- client/src/client/vars/IntVar.java | 3 +- client/src/client/vars/StringVar.java | 12 +- 48 files changed, 709 insertions(+), 571 deletions(-) create mode 100644 client/src/client/gui/element/Area.java create mode 100644 client/src/client/gui/element/ButtonCallback.java create mode 100644 client/src/client/gui/element/DropdownCallback.java create mode 100644 client/src/client/gui/element/Field.java create mode 100644 client/src/client/gui/element/FieldAction.java create mode 100644 client/src/client/gui/element/FieldCallback.java delete mode 100644 client/src/client/gui/element/PasswordBox.java create mode 100644 client/src/client/gui/element/PasswordField.java create mode 100644 client/src/client/gui/element/PressType.java create mode 100644 client/src/client/gui/element/SliderCallback.java create mode 100644 client/src/client/gui/element/SliderFloatCallback.java create mode 100644 client/src/client/gui/element/SwitchCallback.java create mode 100644 client/src/client/gui/element/TextCallback.java create mode 100644 client/src/client/gui/element/ToggleCallback.java rename client/src/client/gui/element/{TransparentBox.java => TransparentArea.java} (69%) diff --git a/client/src/client/Client.java b/client/src/client/Client.java index 8535a7d..c2b91ed 100755 --- a/client/src/client/Client.java +++ b/client/src/client/Client.java @@ -50,7 +50,7 @@ import client.gui.Style; import client.gui.character.GuiChar; import client.gui.container.GuiContainer; import client.gui.container.GuiInventory; -import client.gui.element.Textbox; +import client.gui.element.Area; import client.gui.ingame.GuiGameOver; import client.network.ClientLoginHandler; import client.network.ClientPlayer; @@ -1011,7 +1011,7 @@ public class Client implements IThreadListener { this.open.render(); else if(this.world == null || this.world.hasNoChunks() || this.charEditor) 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(); if(this.hudOverlay && !(this.open instanceof GuiConsole)) { this.drawOverlay(this.feed, this.feedSize, false, 1, 0, 0); diff --git a/client/src/client/audio/Volume.java b/client/src/client/audio/Volume.java index f402a3a..5d400b7 100644 --- a/client/src/client/audio/Volume.java +++ b/client/src/client/audio/Volume.java @@ -2,6 +2,7 @@ package client.audio; import client.Client; import client.gui.element.Slider; +import client.gui.element.SliderCallback; import client.vars.CVar; import client.vars.CVarCategory; import common.color.TextColor; @@ -96,7 +97,7 @@ public enum Volume implements CVar { } 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) { Volume.this.value = value; Volume.this.apply(); diff --git a/client/src/client/gui/GuiConfirm.java b/client/src/client/gui/GuiConfirm.java index fb9b117..901117c 100755 --- a/client/src/client/gui/GuiConfirm.java +++ b/client/src/client/gui/GuiConfirm.java @@ -1,11 +1,12 @@ package client.gui; 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.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 { void confirm(boolean confirmed); } @@ -28,7 +29,7 @@ public class GuiConfirm extends Gui implements ActButton.Callback { public void init(int width, int height) { 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.cancelBtn = this.add(new ActButton(252, 500, 200, 24, this, this.cancelButtonText)); this.shift(); @@ -38,7 +39,7 @@ public class GuiConfirm extends Gui implements ActButton.Callback { return "Aktion bestätigen"; } - public void use(ActButton btn, Mode mode) { + public void use(ActButton btn, PressType mode) { this.callback.confirm(btn == this.confirmBtn); } } diff --git a/client/src/client/gui/GuiConnect.java b/client/src/client/gui/GuiConnect.java index 9303c20..789fcf0 100644 --- a/client/src/client/gui/GuiConnect.java +++ b/client/src/client/gui/GuiConnect.java @@ -6,10 +6,11 @@ import java.util.Collections; import java.util.Date; 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.ListEntry; import client.gui.element.NavButton; +import client.gui.element.PressType; import client.renderer.Drawing; import common.color.TextColor; import common.init.Config; @@ -19,7 +20,7 @@ import common.util.FileUtils; import common.util.Tuple; import common.util.Util; -public class GuiConnect extends GuiList implements ActButton.Callback { +public class GuiConnect extends GuiList implements ButtonCallback { public class ServerInfo implements Comparable, ListEntry { private String name; private String address; @@ -91,7 +92,7 @@ public class GuiConnect extends GuiList implements ActBut GuiConnect.this.copyButton.enabled = true; 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 implements ActBut return 56; } - public void use(ActButton button, Mode mode) { + public void use(ActButton button, PressType mode) { if(button == this.deleteButton) { if(this.selectedElement >= 0) { this.elements.remove(this.selectedElement); diff --git a/client/src/client/gui/GuiConsole.java b/client/src/client/gui/GuiConsole.java index 52f1501..d3c6aca 100644 --- a/client/src/client/gui/GuiConsole.java +++ b/client/src/client/gui/GuiConsole.java @@ -4,13 +4,16 @@ import java.util.List; import client.Client; import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; import client.gui.element.Fill; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.PressType; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; import client.network.ClientPlayer; import client.vars.BoolVar; import client.vars.CVar; -import client.gui.element.TransparentBox; +import client.gui.element.TransparentArea; import client.window.Keysym; import common.collect.Lists; import common.color.TextColor; @@ -20,7 +23,7 @@ import common.util.BlockPos; import common.util.ExtMath; 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(); private final List sentMessages = Lists.newArrayList(); @@ -35,8 +38,8 @@ public class GuiConsole extends Gui implements Textbox.Callback { private String prefixFirst; private int autocompleteIndex; private List foundPlayerNames = Lists.newArrayList(); - private Textbox inputField; - private TransparentBox logBox; + private Field inputField; + private TransparentArea logBox; public GuiConsole setFull(boolean 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_timestamps", 160, 0, 160, 24); this.addSelector("con_loglevel", 320, 0, 160, 24); - this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() { - public void use(ActButton elem, ActButton.Mode action) { + this.add(new ActButton(480, 0, 160, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiConsole.this.reset(); GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer()); } }, "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) 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.sentHistoryCursor = this.sentMessages.size(); } @@ -90,13 +93,13 @@ public class GuiConsole extends Gui implements Textbox.Callback { this.playerNamesFound = false; } - public void use(Textbox elem, Action value) + public void use(Field elem, FieldAction value) { 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(); } else @@ -104,11 +107,11 @@ public class GuiConsole extends Gui implements Textbox.Callback { this.playerNamesFound = false; } - if(value == Action.PREVIOUS) + if(value == FieldAction.PREVIOUS) this.getSentHistory(-1); - else if (value == Action.NEXT) + else if (value == FieldAction.NEXT) this.getSentHistory(1); - if(value == Action.SEND) + if(value == FieldAction.SEND) { String s = this.inputField.getText().trim(); @@ -154,7 +157,7 @@ public class GuiConsole extends Gui implements Textbox.Callback { { if (this.playerNamesFound) { - this.inputField.deleteFromCursor(); + this.inputField.deleteSpaceToCur(); if (this.autocompleteIndex >= this.foundPlayerNames.size()) { @@ -167,11 +170,11 @@ public class GuiConsole extends Gui implements Textbox.Callback { } else { - int i = this.inputField.getNthCharFromPos(); + int i = this.inputField.getSpaceBeforeCur(); this.foundPlayerNames.clear(); this.autocompleteIndex = 0; // 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); if(localMatches != null) { this.onAutocompleteResponse(localMatches); @@ -184,7 +187,7 @@ public class GuiConsole extends Gui implements Textbox.Callback { } this.playerNamesFound = true; - this.inputField.deleteFromCursor(); + this.inputField.deleteSpaceToCur(); } 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); if (s2.length() > 0 && !s1.equalsIgnoreCase(s2)) { - this.inputField.deleteFromCursor(); + this.inputField.deleteSpaceToCur(); this.inputField.insertText(s2); } else if (this.foundPlayerNames.size() > 0) diff --git a/client/src/client/gui/GuiInfo.java b/client/src/client/gui/GuiInfo.java index 7d64ac4..5653efb 100644 --- a/client/src/client/gui/GuiInfo.java +++ b/client/src/client/gui/GuiInfo.java @@ -1,7 +1,7 @@ package client.gui; import client.gui.element.NavButton; -import client.gui.element.TransparentBox; +import client.gui.element.TransparentArea; import common.color.TextColor; import common.init.Config; import common.log.Log; @@ -125,7 +125,7 @@ public class GuiInfo extends Gui { } 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")); } diff --git a/client/src/client/gui/GuiMenu.java b/client/src/client/gui/GuiMenu.java index e562003..fd2093b 100644 --- a/client/src/client/gui/GuiMenu.java +++ b/client/src/client/gui/GuiMenu.java @@ -4,10 +4,10 @@ import client.Timing; import client.gui.character.GuiChar; import client.gui.character.GuiCharacters; 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.NavButton; -import client.gui.element.Textbox; +import client.gui.element.PressType; import client.gui.options.GuiOptions; import client.renderer.Drawing; import client.window.Keysym; @@ -52,8 +52,8 @@ public class GuiMenu extends Gui { this.ticks = 0; this.hacked = 0; this.resetAnimation(); - this.add(new ActButton(0, -28, 400, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(0, -28, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { if(GuiMenu.this.hacked == 9) { GuiMenu.this.hacked++; GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!"); @@ -64,16 +64,16 @@ public class GuiMenu extends Gui { } }, "Server beitreten")); this.add(new NavButton(0, 0, 400, 24, GuiServer.INSTANCE, "Schnellverbindung")); - this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(0, 28, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { if(GuiMenu.this.hacked == 8) GuiMenu.this.hacked++; else GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage()); } }, "Einstellungen")); - this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE); } }, "Info / Über / Mitwirkende") { @@ -95,8 +95,8 @@ public class GuiMenu extends Gui { } } }); - this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() { - public void use(ActButton elem, ActButton.Mode action) { + this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiMenu.this.gm.interrupted = true; } }, "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")); if(!this.gm.charEditor) this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter")); - this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() { - public void use(ActButton elem, ActButton.Mode action) { + this.add(new ActButton(0, 102, 400, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiMenu.this.gm.unload(true); // GuiMenu.this.gm.displayGuiScreen(INSTANCE); } @@ -226,7 +226,7 @@ public class GuiMenu extends Gui { public void updateScreen() { if(this.gm.world == null) { this.ticks++; - if(this.gm.shift() && !(this.selected instanceof Textbox)) + if(this.gm.shift()) this.pickSplash(); this.updateAnimation(); } diff --git a/client/src/client/gui/GuiServer.java b/client/src/client/gui/GuiServer.java index 6fc3495..3cb509e 100644 --- a/client/src/client/gui/GuiServer.java +++ b/client/src/client/gui/GuiServer.java @@ -2,27 +2,30 @@ package client.gui; import client.gui.GuiConnect.ServerInfo; import client.gui.element.ActButton; +import client.gui.element.ButtonCallback; import client.gui.element.Label; import client.gui.element.NavButton; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.PressType; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; import client.vars.CVarCategory; import client.vars.Variable; import common.color.TextColor; import common.init.Config; 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); private final ServerInfo server; - private Textbox nameBox; - private Textbox addrBox; - private Textbox portBox; - private Textbox userBox; - private Textbox passBox; - private Textbox accBox; + private Field nameBox; + private Field addrBox; + private Field portBox; + private Field userBox; + private Field passBox; + private Field accBox; private Label nameLabel; private Label addrLabel; private Label portLabel; @@ -47,14 +50,14 @@ public class GuiServer extends Gui implements Textbox.Callback { public void init(int width, int height) { if(this.server != null) - this.nameBox = this.add(new Textbox(0, -50, 400, 24, 128, true, 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.portBox = this.add(new Textbox(404, 20, 76, 24, 5, true, 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.passBox = this.add(new Textbox(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, true, 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.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() { - public void use(ActButton elem, ActButton.Mode action) { + this.nameBox = this.add(new Field(0, -50, 400, 24, 128, this, this.server.getName())); + 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 Field(404, 20, 76, 24, 5, this, "" + (this.server == null ? this.lastPort : this.server.getPort()))); + 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 Field(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, this, this.server == null ? this.lastPass : this.server.getPassword())); + 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 ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiServer.this.connect(); } }, 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) { - if(value == Action.SEND) { + public void use(Field elem, FieldAction value) { + if(value == FieldAction.SEND) { elem.setDeselected(); this.connect(); } - else if(value == Action.FOCUS) { + else if(value == FieldAction.FOCUS) { if(elem == this.addrBox) this.addrLabel.setText("Adresse"); else if(elem == this.portBox) diff --git a/client/src/client/gui/character/GuiChar.java b/client/src/client/gui/character/GuiChar.java index 25c3593..01117c0 100755 --- a/client/src/client/gui/character/GuiChar.java +++ b/client/src/client/gui/character/GuiChar.java @@ -20,16 +20,20 @@ import client.SkinConverter; import client.gui.FileCallback; import client.gui.GuiLoading; import client.gui.element.ActButton; -import client.gui.element.ActButton.Mode; import client.gui.element.Element; import client.gui.element.GuiList; import client.gui.element.Label; import client.gui.element.ListEntry; import client.gui.element.NavButton; +import client.gui.element.PressType; import client.gui.element.Slider; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; -import client.gui.element.TransparentBox; +import client.gui.element.SliderCallback; +import client.gui.element.FieldAction; +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.GlState; import client.renderer.ItemRenderer; @@ -248,7 +252,7 @@ public class GuiChar extends GuiList private ActButton templateButton; private DragAdjust adjust; private ActButton dimButton; - private TransparentBox descLines; + private TransparentArea descLines; private float yaw = -15.0f; private float pitch = -15.0f; private boolean waiting = true; @@ -273,8 +277,8 @@ public class GuiChar extends GuiList } 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.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(4, 4, 194, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", TEXTURE_FOLDER, new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, false)) @@ -283,8 +287,8 @@ public class GuiChar extends GuiList }); } }, "Importieren: Standard")); - this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(202, 4, 194, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", TEXTURE_FOLDER, new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, true)) @@ -294,13 +298,13 @@ public class GuiChar extends GuiList } }, "Importieren: Schlank")); this.addSelector("char_filter_species", 400, 4, 300, 24); - this.add(new ActButton(4, height - 28, 194, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(4, height - 28, 194, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiChar.this.gm.displayGuiScreen(GuiChar.this); } }, "Neu laden")); - this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { SkinEntry skin = GuiChar.this.getSelected(); if(skin != null && skin.getLocation() != null) { String loc = skin.getLocation(); @@ -346,8 +350,8 @@ public class GuiChar extends GuiList for (int z = 0; z < Alignment.values().length; 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() { - public void use(ActButton elem, Mode action) { + 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, PressType action) { if(GuiChar.this.gm.player != null) { GuiChar.this.waiting = false; GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal())); @@ -359,7 +363,7 @@ public class GuiChar extends GuiList }, align.color + align.display)); 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) { if(GuiChar.this.gm.player != null) { GuiChar.this.waiting = false; @@ -369,12 +373,9 @@ public class GuiChar extends GuiList }, "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 - 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() { - public void use(Textbox elem, Action value) { - } - }, "")); - this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + final Area descField = this.add(new Area(width - 396, height - 364, 392, 130, IPlayer.MAX_INFO_LENGTH, "")); + this.add(new ActButton(width - 198, height - 28, 194, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { if(GuiChar.this.gm.player != null) { GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ...")); Dimension dim = UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension); @@ -383,9 +384,9 @@ public class GuiChar extends GuiList } } }, "Charakter erstellen")); - this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, true, new Textbox.Callback() { - public void use(Textbox elem, Action value) { - if(value == Action.SEND || value == Action.UNFOCUS) { + this.add(new Field(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, new FieldCallback() { + public void use(Field elem, FieldAction value) { + if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) { String name = elem.getText(); if(name.isEmpty()) elem.setText(GuiChar.this.gm.player == null ? "..." : GuiChar.this.gm.player.getCustomNameTag()); @@ -410,12 +411,12 @@ public class GuiChar extends GuiList } } } - this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode mode) { - if(mode == Mode.TERTIARY) { + this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ButtonCallback() { + public void use(ActButton elem, PressType mode) { + if(mode == PressType.TERTIARY) { GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); } - else if(mode == Mode.SECONDARY) { + else if(mode == PressType.SECONDARY) { if(--GuiChar.this.dimension < 0) GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1; } @@ -426,7 +427,7 @@ public class GuiChar extends GuiList 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(); } diff --git a/client/src/client/gui/character/GuiCharacters.java b/client/src/client/gui/character/GuiCharacters.java index 159e54f..46e99d8 100644 --- a/client/src/client/gui/character/GuiCharacters.java +++ b/client/src/client/gui/character/GuiCharacters.java @@ -3,17 +3,18 @@ package client.gui.character; import client.gui.GuiConfirm; import client.gui.GuiMenu; 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.ListEntry; 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 common.color.TextColor; import common.entity.npc.PlayerCharacter; import common.packet.CPacketAction; -public class GuiCharacters extends GuiList implements ActButton.Callback +public class GuiCharacters extends GuiList implements ButtonCallback { protected class CharacterEntry implements ListEntry { @@ -43,14 +44,14 @@ public class GuiCharacters extends GuiList impleme public void select(boolean dclick, int mx, int my) { if(dclick) - GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY); + GuiCharacters.this.use(GuiCharacters.this.actionButtom, PressType.PRIMARY); GuiCharacters.this.updateButtons(); } } public static final GuiCharacters INSTANCE = new GuiCharacters(); - private TransparentBox descField; + private TransparentArea descField; private ActButton actionButtom; private ActButton deleteButtom; @@ -78,7 +79,7 @@ public class GuiCharacters extends GuiList impleme this.elements.add(new CharacterEntry(null, false)); 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.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")); @@ -99,7 +100,7 @@ public class GuiCharacters extends GuiList impleme return 36 + 4; } - public void use(ActButton elem, Mode action) { + public void use(ActButton elem, PressType action) { CharacterEntry entry = GuiCharacters.this.getSelected(); if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) { if(elem == this.actionButtom) { diff --git a/client/src/client/gui/character/GuiClass.java b/client/src/client/gui/character/GuiClass.java index e25e5f5..9b83871 100644 --- a/client/src/client/gui/character/GuiClass.java +++ b/client/src/client/gui/character/GuiClass.java @@ -1,14 +1,15 @@ package client.gui.character; 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.ListEntry; import client.gui.element.NavButton; +import client.gui.element.PressType; import client.renderer.Drawing; import common.packet.CPacketAction; -public class GuiClass extends GuiList implements ActButton.Callback +public class GuiClass extends GuiList implements ButtonCallback { protected class ClassEntry implements ListEntry { @@ -29,7 +30,7 @@ public class GuiClass extends GuiList implements ActButton. 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) - 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 implements ActButton. return 44 + 4; } - public void use(ActButton elem, Mode action) { + public void use(ActButton elem, PressType action) { ClassEntry entry = this.getSelected(); if(entry != null && GuiClass.this.gm.player != null) { GuiClass.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_CLASS, entry.clazz.ordinal())); diff --git a/client/src/client/gui/character/GuiSpecies.java b/client/src/client/gui/character/GuiSpecies.java index 47a9ec7..10e8c01 100644 --- a/client/src/client/gui/character/GuiSpecies.java +++ b/client/src/client/gui/character/GuiSpecies.java @@ -1,17 +1,18 @@ package client.gui.character; 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.ListEntry; import client.gui.element.NavButton; +import client.gui.element.PressType; import client.renderer.Drawing; import common.entity.npc.SpeciesInfo; import common.init.EntityRegistry; import common.init.SpeciesRegistry; import common.packet.CPacketAction; -public class GuiSpecies extends GuiList implements ActButton.Callback +public class GuiSpecies extends GuiList implements ButtonCallback { protected class SpeciesEntry implements ListEntry { @@ -34,7 +35,7 @@ public class GuiSpecies extends GuiList implements ActB 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) - 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 implements ActB return 44 + 4; } - public void use(ActButton elem, Mode action) { + public void use(ActButton elem, PressType action) { SpeciesEntry entry = this.getSelected(); 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))); diff --git a/client/src/client/gui/element/ActButton.java b/client/src/client/gui/element/ActButton.java index 72a8d88..d4d32b6 100644 --- a/client/src/client/gui/element/ActButton.java +++ b/client/src/client/gui/element/ActButton.java @@ -4,30 +4,22 @@ import client.gui.Formatter; import client.window.Button; public class ActButton extends Element { - public static enum Mode { - PRIMARY, SECONDARY, TERTIARY; - } + private final ButtonCallback func; - public static interface Callback { - void use(ActButton elem, Mode action); - } - - private final Callback func; - - public ActButton(int x, int y, int w, int h, Callback callback, Formatter formatter) { + public ActButton(int x, int y, int w, int h, ButtonCallback callback, Formatter formatter) { super(x, y, w, h, formatter); this.func = callback; 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); this.func = callback; this.setText(text); } 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.playSound(); } diff --git a/client/src/client/gui/element/Area.java b/client/src/client/gui/element/Area.java new file mode 100644 index 0000000..d93c6b7 --- /dev/null +++ b/client/src/client/gui/element/Area.java @@ -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; + } +} diff --git a/client/src/client/gui/element/ButtonCallback.java b/client/src/client/gui/element/ButtonCallback.java new file mode 100644 index 0000000..b22d24e --- /dev/null +++ b/client/src/client/gui/element/ButtonCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface ButtonCallback { + void use(ActButton elem, PressType action); +} \ No newline at end of file diff --git a/client/src/client/gui/element/Dropdown.java b/client/src/client/gui/element/Dropdown.java index 6ba417f..a49b053 100644 --- a/client/src/client/gui/element/Dropdown.java +++ b/client/src/client/gui/element/Dropdown.java @@ -64,18 +64,14 @@ public class Dropdown extends Element { } } - public static interface Callback { - void use(Dropdown elem, T value); - } - - private final Callback func; + private final DropdownCallback func; private final T[] values; private final Handle handle; private final int def; private int value; - public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback callback, Formatter> formatter) { + public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback callback, Formatter> formatter) { super(x, y, w, h, formatter); this.func = callback; this.values = values; @@ -85,7 +81,7 @@ public class Dropdown extends Element { this.formatText(); } - public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback callback, final String text) { + public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback callback, final String text) { this(x, y, w, h, up, values, def, init, callback, new Formatter>() { public String use(Dropdown elem) { T value = elem.getValue(); diff --git a/client/src/client/gui/element/DropdownCallback.java b/client/src/client/gui/element/DropdownCallback.java new file mode 100644 index 0000000..4161d31 --- /dev/null +++ b/client/src/client/gui/element/DropdownCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface DropdownCallback { + void use(Dropdown elem, T value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/Field.java b/client/src/client/gui/element/Field.java new file mode 100644 index 0000000..bd82813 --- /dev/null +++ b/client/src/client/gui/element/Field.java @@ -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; + } +} diff --git a/client/src/client/gui/element/FieldAction.java b/client/src/client/gui/element/FieldAction.java new file mode 100644 index 0000000..e28413d --- /dev/null +++ b/client/src/client/gui/element/FieldAction.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public enum FieldAction { + FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD; +} \ No newline at end of file diff --git a/client/src/client/gui/element/FieldCallback.java b/client/src/client/gui/element/FieldCallback.java new file mode 100644 index 0000000..09d2ada --- /dev/null +++ b/client/src/client/gui/element/FieldCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface FieldCallback extends TextCallback { + void use(Field elem, FieldAction value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/NavButton.java b/client/src/client/gui/element/NavButton.java index f1722b8..a80d9c4 100644 --- a/client/src/client/gui/element/NavButton.java +++ b/client/src/client/gui/element/NavButton.java @@ -9,8 +9,8 @@ public class NavButton extends ActButton { private final Gui navGui; public NavButton(int x, int y, int w, int h, Gui gui, String text) { - super(x, y, w, h, new Callback() { - public void use(ActButton elem, Mode action) { + super(x, y, w, h, new ButtonCallback() { + public void use(ActButton elem, PressType action) { Client.CLIENT.displayGuiScreen(gui); } }, text); diff --git a/client/src/client/gui/element/PasswordBox.java b/client/src/client/gui/element/PasswordBox.java deleted file mode 100644 index de104bb..0000000 --- a/client/src/client/gui/element/PasswordBox.java +++ /dev/null @@ -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))); - } - } -} diff --git a/client/src/client/gui/element/PasswordField.java b/client/src/client/gui/element/PasswordField.java new file mode 100644 index 0000000..efd3d9a --- /dev/null +++ b/client/src/client/gui/element/PasswordField.java @@ -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; + } +} diff --git a/client/src/client/gui/element/PressType.java b/client/src/client/gui/element/PressType.java new file mode 100644 index 0000000..4424611 --- /dev/null +++ b/client/src/client/gui/element/PressType.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public enum PressType { + PRIMARY, SECONDARY, TERTIARY; +} \ No newline at end of file diff --git a/client/src/client/gui/element/SelectableButton.java b/client/src/client/gui/element/SelectableButton.java index 699121d..b9888a2 100644 --- a/client/src/client/gui/element/SelectableButton.java +++ b/client/src/client/gui/element/SelectableButton.java @@ -6,7 +6,7 @@ import common.util.Util; public class SelectableButton extends ActButton { 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); this.selected = selected; } diff --git a/client/src/client/gui/element/Slider.java b/client/src/client/gui/element/Slider.java index 45bb1e7..347cef9 100644 --- a/client/src/client/gui/element/Slider.java +++ b/client/src/client/gui/element/Slider.java @@ -7,17 +7,9 @@ import common.util.ExtMath; import common.util.Util; 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 final Callback func; + private final SliderCallback func; private final int def; private final int min; private final int max; @@ -27,7 +19,7 @@ public class Slider extends Element { private int value; 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 formatter) { + public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, Formatter formatter) { super(x, y, w, h, formatter); this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1; this.func = callback; @@ -40,7 +32,7 @@ public class Slider extends Element { 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() { public String use(Slider elem) { 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() { 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 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() { + public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final SliderFloatCallback callback, Formatter formatter) { + 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) { callback.use(elem, (float)value / 1000.0f); } }, 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() { private final String format = "%s: " + (prec <= 0 ? "%d" : ("%." + prec + "f")) + (unit.isEmpty() ? "" : " %s"); diff --git a/client/src/client/gui/element/SliderCallback.java b/client/src/client/gui/element/SliderCallback.java new file mode 100644 index 0000000..4ed60b0 --- /dev/null +++ b/client/src/client/gui/element/SliderCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface SliderCallback { + void use(Slider elem, int value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/SliderFloatCallback.java b/client/src/client/gui/element/SliderFloatCallback.java new file mode 100644 index 0000000..ca24df3 --- /dev/null +++ b/client/src/client/gui/element/SliderFloatCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface SliderFloatCallback { + void use(Slider elem, float value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/Switch.java b/client/src/client/gui/element/Switch.java index 6053cd2..878ebcc 100644 --- a/client/src/client/gui/element/Switch.java +++ b/client/src/client/gui/element/Switch.java @@ -6,17 +6,13 @@ import common.util.Displayable; import common.util.Util; public class Switch extends Element { - public static interface Callback { - void use(Switch elem, T value); - } - - private final Callback func; + private final SwitchCallback func; private final T[] values; private final int def; private int value; - public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback callback, Formatter> formatter) { + public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback callback, Formatter> formatter) { super(x, y, w, h, formatter); this.func = callback; this.values = values; @@ -25,7 +21,7 @@ public class Switch extends Element { this.formatText(); } - public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback callback, final String text) { + public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback callback, final String text) { this(x, y, w, h, values, def, init, callback, new Formatter>() { public String use(Switch elem) { T value = elem.getValue(); diff --git a/client/src/client/gui/element/SwitchCallback.java b/client/src/client/gui/element/SwitchCallback.java new file mode 100644 index 0000000..2893e44 --- /dev/null +++ b/client/src/client/gui/element/SwitchCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface SwitchCallback { + void use(Switch elem, T value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/TextCallback.java b/client/src/client/gui/element/TextCallback.java new file mode 100644 index 0000000..c014c89 --- /dev/null +++ b/client/src/client/gui/element/TextCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +interface TextCallback { + void use(T elem, FieldAction value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/Textbox.java b/client/src/client/gui/element/Textbox.java index 533e160..fa82c1a 100644 --- a/client/src/client/gui/element/Textbox.java +++ b/client/src/client/gui/element/Textbox.java @@ -5,97 +5,44 @@ import org.lwjgl.opengl.GL11; import client.Timing; import client.gui.Font; import client.renderer.Drawing; -import client.renderer.Drawing.Offset; -import client.renderer.Drawing.Vec2i; import client.window.Button; import client.window.Keysym; import client.window.Window; import common.util.CharValidator; -import common.util.ExtMath; import common.util.Util; -public class Textbox extends Element { - public static enum Action { - FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD; - } +abstract class Textbox extends Element { + protected final TextCallback func; + protected final CharValidator validator; + protected final int capacity; + protected final boolean editable; - public static interface Callback { - void use(Textbox elem, Action value); - } - - private final Callback func; - 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; + protected long tmr_scroll; + protected long tmr_leftmb; + protected int sel_start = -1; + protected int sel_end = -1; + protected int sel_drag = -1; - private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) { + protected Textbox(int x, int y, int w, int h, int cap, boolean editable, TextCallback callback, CharValidator validator) { super(x, y, w, h, null); this.func = callback; this.validator = validator; this.capacity = cap; - this.xbreak = !line; 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) { - this(x, y, w, h, cap, line, true, callback, null, text); - } - - public Textbox(int x, int y, int w, int h, int cap, boolean line, Callback callback, CharValidator validator, String text) { - this(x, y, w, h, cap, line, true, callback, validator, text); - } - - public Textbox(int x, int y, int w, int h, int cap, Callback callback, String text) { - this(x, y, w, h, cap, false, true, callback, null, text); - } - - 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 abstract void updateText(); + 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 abstract void update(); + 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(); + protected abstract int getCursorX(int x1, int x2); + 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 boolean canHover() { return false; @@ -114,35 +61,11 @@ public class Textbox extends Element { 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) { if(btn == Button.MOUSE_LEFT) { if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { this.sel_start = this.sel_drag = 0; this.sel_end = this.text.length(); -// this.r_dirty = true; } else { gui_text_select(x, y, shift); @@ -150,41 +73,28 @@ public class Textbox extends Element { this.tmr_leftmb = Timing.tmr_current; } 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) { gui_text_select(x, y, true); } public void character(char code) { - if(this.editable) { -// int pos = 0; -// char chr[8]; -// utf_rwriten(chr, &pos, 8, code); -// chr[pos] = 0; + if(this.editable) insertText(Character.toString(code)); - } } public void key(Keysym key, boolean ctrl, boolean shift) { if(ctrl && key == Keysym.A) { this.sel_start = this.sel_drag = 0; this.sel_end = this.text.length(); -// this.r_dirty = true; } else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) { 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, '?'); Window.setClipboard(str); - // this.text[this.sel_end] = end; if(key == Keysym.X) insertText(""); } @@ -193,12 +103,7 @@ public class Textbox extends Element { insertText(Window.getClipboard()); } else if(this.editable && !ctrl && key == Keysym.RETURN) { - if(this.xbreak) { - insertText("\n"); - } - else if(this.func != null) { - this.func.use(this, shift ? Action.LINE : Action.SEND); - } + this.onReturn(shift); } else if(this.editable && (!ctrl) && (key == Keysym.BACKSPACE || key == Keysym.DELETE)) { 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)) { - if(this.xbreak) { - 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); - } + this.onSelection(key == Keysym.UP); } else if((!ctrl) && key == Keysym.TAB) { 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() { if(this.func != null) { - this.func.use(this, Action.FOCUS); + this.func.use(this, FieldAction.FOCUS); } } public void deselect() { this.sel_start = this.sel_end = this.sel_drag = -1; this.tmr_leftmb = 0L; -// this.r_dirty = true; if(this.func != null) { - this.func.use(this, Action.UNFOCUS); + this.func.use(this, FieldAction.UNFOCUS); } } - public void update() { - if((this.scrollx != 0 && !(this.xbreak)) || (this.scrolly != 0 && this.xbreak)) { - int n; - 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; - } + protected int updateScroll(int value) { + if(value != 0) { + int n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)value)); if((((long)n) * 1000000L) <= this.tmr_scroll) this.tmr_scroll -= ((long)n) * 1000000L; else this.tmr_scroll = 0L; this.tmr_scroll += Timing.tmr_delta; + return n; } + return 0; } - public void shift(int shift_x, int shift_y) { - 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) { + protected void gui_text_update_cur(int offset, boolean shift) { 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); gui_text_clamp_scroll(); - Vec2i coord = Drawing.txt_coord(offset, 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) : 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; -// } + this.updateCursor(offset, shift, x1, y1, x2, y2); } public void insertText(String str) { if(str == null || (this.sel_start == -1)) 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) 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) return; 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_end = this.sel_drag = this.sel_start; this.updateText(); @@ -397,15 +212,7 @@ public class Textbox extends Element { 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); - Offset off = Drawing.txt_offset(x, y, 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) : 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); + int offset = this.onCursorOffset(x, y, x1, y1, x2, y2); if(!drag) { this.sel_drag = this.sel_start = this.sel_end = offset; } @@ -417,18 +224,8 @@ public class Textbox extends Element { this.sel_start = offset; 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() { 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); @@ -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)); } - 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() { 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; @@ -454,61 +241,8 @@ public class Textbox extends Element { 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.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); } } - - - - - - - - - - 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; - } } diff --git a/client/src/client/gui/element/Toggle.java b/client/src/client/gui/element/Toggle.java index 5c4be8b..b020dd5 100644 --- a/client/src/client/gui/element/Toggle.java +++ b/client/src/client/gui/element/Toggle.java @@ -6,16 +6,12 @@ import client.window.Button; import common.util.Util; public class Toggle extends Element { - public static interface Callback { - void use(Toggle elem, boolean value); - } - - private final Callback func; + private final ToggleCallback func; private final boolean def; private boolean value; - public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter formatter) { + public Toggle(int x, int y, int w, int h, boolean def, boolean init, ToggleCallback callback, Formatter formatter) { super(x, y, w, h, formatter); this.func = callback; this.def = def; @@ -23,7 +19,7 @@ public class Toggle extends Element { 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() { public String use(Toggle elem) { return String.format("%s: %s", text, elem.value ? "An" : "Aus"); diff --git a/client/src/client/gui/element/ToggleCallback.java b/client/src/client/gui/element/ToggleCallback.java new file mode 100644 index 0000000..8aa374b --- /dev/null +++ b/client/src/client/gui/element/ToggleCallback.java @@ -0,0 +1,5 @@ +package client.gui.element; + +public interface ToggleCallback { + void use(Toggle elem, boolean value); +} \ No newline at end of file diff --git a/client/src/client/gui/element/TransparentBox.java b/client/src/client/gui/element/TransparentArea.java similarity index 69% rename from client/src/client/gui/element/TransparentBox.java rename to client/src/client/gui/element/TransparentArea.java index 04f284d..d9da822 100644 --- a/client/src/client/gui/element/TransparentBox.java +++ b/client/src/client/gui/element/TransparentArea.java @@ -2,10 +2,10 @@ package client.gui.element; import client.renderer.Drawing; -public class TransparentBox extends Textbox { +public class TransparentArea extends Area { 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); this.background = background; } diff --git a/client/src/client/gui/ingame/GuiForm.java b/client/src/client/gui/ingame/GuiForm.java index dc5cce9..3533242 100644 --- a/client/src/client/gui/ingame/GuiForm.java +++ b/client/src/client/gui/ingame/GuiForm.java @@ -2,22 +2,26 @@ package client.gui.ingame; import client.gui.Gui; 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.Label; 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.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.SwitchCallback; +import client.gui.element.FieldAction; +import client.gui.element.Field; +import client.gui.element.FieldCallback; import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; import client.network.ClientPlayer; import common.color.TextColor; import common.packet.CPacketForm; import common.util.ExtMath; 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 String title; private final Element[] inputs; @@ -35,7 +39,7 @@ public class GuiForm extends Gui implements ActButton.Callback { Object obj = this.inputData[z].second; int param = this.inputData[z].third; 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) { GuiForm.this.outputData[index] = value; } @@ -44,7 +48,7 @@ public class GuiForm extends Gui implements ActButton.Callback { else if(obj instanceof String[]) { final String[] strs = (String[])obj; param = ExtMath.clampi(param, 0, strs.length - 1); - this.inputs[z] = this.add(new Switch(0, 50 * z, 300, 24, strs, strs[param], strs[param], new Switch.Callback() { + this.inputs[z] = this.add(new Switch(0, 50 * z, 300, 24, strs, strs[param], strs[param], new SwitchCallback() { public void use(Switch elem, String value) { for(int n = 0; n < strs.length; n++) { if(value == strs[n]) { @@ -57,14 +61,14 @@ public class GuiForm extends Gui implements ActButton.Callback { } else { this.labels[z] = this.add(new Label(0, 50 * z - 20, 300, 20, name, true)); - Textbox.Callback callback = new Textbox.Callback() { - public void use(Textbox elem, Action value) { - if(value == Action.FOCUS) + FieldCallback callback = new FieldCallback() { + public void use(Field elem, FieldAction value) { + if(value == FieldAction.FOCUS) 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) : - new Textbox(0, 50 * z, 300, 24, Math.min(param & 0xffff, 256), true, 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 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")); @@ -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++) { - if(this.inputs[z] instanceof Textbox) { + if(this.inputs[z] instanceof Field) { int min = (this.inputData[z].third & 0x7fffffff) >> 16; String text = this.inputs[z].getText(); if(text.length() < min) { diff --git a/client/src/client/gui/ingame/GuiGameOver.java b/client/src/client/gui/ingame/GuiGameOver.java index d8ad0a9..ce3f7ab 100755 --- a/client/src/client/gui/ingame/GuiGameOver.java +++ b/client/src/client/gui/ingame/GuiGameOver.java @@ -2,9 +2,10 @@ package client.gui.ingame; import client.gui.Gui; import client.gui.element.ActButton; -import client.gui.element.ActButton.Mode; +import client.gui.element.ButtonCallback; import common.color.TextColor; import client.gui.element.Label; +import client.gui.element.PressType; public class GuiGameOver extends Gui { public static final GuiGameOver INSTANCE = new GuiGameOver(); @@ -19,8 +20,8 @@ public class GuiGameOver extends Gui { this.timer = 0; 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.button = this.add(new ActButton(0, 100, 200, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.button = this.add(new ActButton(0, 100, 200, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiGameOver.this.gm.player.respawnPlayer(); GuiGameOver.this.gm.displayGuiScreen(null); } diff --git a/client/src/client/gui/ingame/GuiSign.java b/client/src/client/gui/ingame/GuiSign.java index 65eb72c..c5530fd 100644 --- a/client/src/client/gui/ingame/GuiSign.java +++ b/client/src/client/gui/ingame/GuiSign.java @@ -3,24 +3,24 @@ package client.gui.ingame; import client.gui.Gui; import client.gui.element.Label; import client.gui.element.NavButton; -import client.gui.element.Textbox; -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 common.packet.CPacketSign; 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 Textbox[] lines; + private final Field[] lines; private final String[] tempLines; - public void init(int width, int height) { 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, -50, 300, 20, this.gm.world == null ? "" : this.gm.world.dimension.getFormattedName(false))); 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.shift(); @@ -42,13 +42,13 @@ public class GuiSign extends Gui implements Textbox.Callback { public GuiSign(BlockPos sign, String[] lines) { this.position = sign; - this.lines = new Textbox[lines.length]; + this.lines = new Field[lines.length]; this.tempLines = new String[lines.length]; System.arraycopy(lines, 0, this.tempLines, 0, lines.length); } - public void use(Textbox elem, Action value) { - if(value == Action.SEND) + public void use(Field elem, FieldAction value) { + if(value == FieldAction.SEND) this.gm.displayGuiScreen(null); } } diff --git a/client/src/client/gui/options/GuiBinds.java b/client/src/client/gui/options/GuiBinds.java index 1c1ab7a..ffc6262 100644 --- a/client/src/client/gui/options/GuiBinds.java +++ b/client/src/client/gui/options/GuiBinds.java @@ -2,8 +2,9 @@ package client.gui.options; import client.gui.Formatter; 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.PressType; import client.window.Bind; import common.color.TextColor; @@ -16,16 +17,16 @@ public class GuiBinds extends GuiOptions { int x = 0; for(Bind bind : Bind.values()) { this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay())); - this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { - if(action == Mode.SECONDARY) { + this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { + if(action == PressType.SECONDARY) { if(!bind.isDefault()) { bind.setDefault(); GuiBinds.this.gm.setDirty(); GuiBinds.this.reformat(); } } - else if(action == Mode.TERTIARY) { + else if(action == PressType.TERTIARY) { if(bind.getInput() != null) { bind.setInput(null); GuiBinds.this.gm.setDirty(); @@ -50,8 +51,8 @@ public class GuiBinds extends GuiOptions { } } y += x != 0 ? 1 : 0; - this.add(new ActButton(200, 100 + y * 50, 560, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(200, 100 + y * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { boolean flag = false; for(Bind bind : Bind.values()) { flag |= !bind.isDefault(); diff --git a/client/src/client/gui/options/GuiDisplay.java b/client/src/client/gui/options/GuiDisplay.java index 68febe0..22262d0 100644 --- a/client/src/client/gui/options/GuiDisplay.java +++ b/client/src/client/gui/options/GuiDisplay.java @@ -2,10 +2,13 @@ package client.gui.options; import client.gui.Formatter; import client.gui.element.Dropdown; +import client.gui.element.DropdownCallback; import client.gui.element.Element; import client.gui.element.Fill; import client.gui.element.Slider; +import client.gui.element.SliderCallback; import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; import client.window.Button; import client.window.DisplayMode; import client.window.Window; @@ -36,7 +39,7 @@ public class GuiDisplay extends GuiOptions { if(modes[z].equals(this.gm.vidMode)) selected = modes[z]; } - this.add(new Dropdown(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new Dropdown.Callback() { + this.add(new Dropdown(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new DropdownCallback() { public void use(Dropdown elem, DisplayMode value) { GuiDisplay.this.gm.vidMode = value; 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 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) { GuiDisplay.this.gm.full(value); } }, "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) { GuiDisplay.this.gm.getVar("win_sync").parse("" + ((value > 0 && value < 360 - 8) ? (value + 9) : (value != 0 ? -1 : 0))); GuiDisplay.this.gm.setDirty(); diff --git a/client/src/client/gui/options/GuiSound.java b/client/src/client/gui/options/GuiSound.java index 052c2ab..29a3814 100644 --- a/client/src/client/gui/options/GuiSound.java +++ b/client/src/client/gui/options/GuiSound.java @@ -2,7 +2,8 @@ package client.gui.options; import client.audio.Volume; 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 { protected GuiSound() { @@ -14,8 +15,8 @@ public class GuiSound extends GuiOptions { this.addSelector("snd_buffer_size", 30, 420, 440, 24); this.addSelector("snd_frame_size", 490, 420, 440, 24); - this.add(new ActButton(30, 480, 900, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(30, 480, 900, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiSound.this.gm.restartSound(false); } }, "Übernehmen und Audio-Thread neu starten")); diff --git a/client/src/client/gui/options/GuiStyle.java b/client/src/client/gui/options/GuiStyle.java index 6d374ee..7905591 100644 --- a/client/src/client/gui/options/GuiStyle.java +++ b/client/src/client/gui/options/GuiStyle.java @@ -2,19 +2,25 @@ package client.gui.options; import client.gui.Style; 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.DropdownCallback; import client.gui.element.Element; import client.gui.element.SelectableButton; import client.gui.element.Slider; +import client.gui.element.SliderCallback; import client.gui.element.Switch; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.SwitchCallback; +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.ColorVar; import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; -public class GuiStyle extends GuiOptions implements Dropdown.Callback, ActButton.Callback, Toggle.Callback, Switch.Callback, Slider.Callback, Textbox.Callback { +public class GuiStyle extends GuiOptions implements DropdownCallback, ButtonCallback, ToggleCallback, SwitchCallback, SliderCallback, FieldCallback { private static final String[] STYLE_CVARS = { "color_button_top", "color_textbox_top", @@ -39,7 +45,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A if(!color.getDisplay().isEmpty()) this.add(color.label(x, y - 20, w, 20)); 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 return this.add(color.editor(x, y, w, h)); } @@ -53,8 +59,8 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A } z = 0; for(Style theme : Style.values()) { - ActButton.Callback callback = new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + ButtonCallback callback = new ButtonCallback() { + public void use(ActButton elem, PressType action) { if(GuiStyle.this.gm.style != theme) { GuiStyle.this.gm.style = theme; GuiStyle.this.gm.setDirty(); @@ -75,11 +81,11 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A 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 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) { - this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { if(GuiStyle.this.gm.style != Style.CUSTOM) { GuiStyle.this.gm.style.copyToCustom(); GuiStyle.this.gm.style = Style.CUSTOM; @@ -90,8 +96,8 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A }, "In angepasstes Design kopieren")); } else { - this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ActButton.Callback() { - public void use(ActButton elem, Mode action) { + this.add(new ActButton(200, 100 + 3 * 50, 560, 24, new ButtonCallback() { + public void use(ActButton elem, PressType action) { GuiStyle.this.gm.style = Style.CUSTOM; for(String cvar : STYLE_CVARS) { GuiStyle.this.gm.getVar(cvar).setDefault(); @@ -108,7 +114,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A return "Benutzeroberfläche"; } - public void use(Textbox elem, Action value) { + public void use(Field elem, FieldAction value) { } public void use(Slider elem, int value) { } @@ -116,7 +122,7 @@ public class GuiStyle extends GuiOptions implements Dropdown.Callback, A } 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 elem, String value) { } diff --git a/client/src/client/vars/BoolVar.java b/client/src/client/vars/BoolVar.java index af51d6b..103f1ca 100644 --- a/client/src/client/vars/BoolVar.java +++ b/client/src/client/vars/BoolVar.java @@ -3,6 +3,7 @@ package client.vars; import java.lang.reflect.Field; import client.gui.element.Toggle; +import client.gui.element.ToggleCallback; import common.color.TextColor; import common.util.Util; @@ -59,7 +60,7 @@ public class BoolVar extends BaseVar { public Toggle selector(int x, int y, int w, int h) { 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) { BoolVar.this.parse("" + value); } diff --git a/client/src/client/vars/ColorVar.java b/client/src/client/vars/ColorVar.java index 2a1bfb1..9f72dc6 100644 --- a/client/src/client/vars/ColorVar.java +++ b/client/src/client/vars/ColorVar.java @@ -3,10 +3,10 @@ package client.vars; import java.lang.reflect.Field; import client.gui.Style; +import client.gui.element.FieldCallback; import client.gui.element.Label; import client.gui.element.Slider; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.FieldAction; import common.color.TextColor; import common.util.Util; @@ -26,6 +26,8 @@ public class ColorVar extends IntVar { if(str.length() != (this.alpha ? 8 : 6)) return null; Integer value = Util.parseInt(str, -16); + if(value == null) + return 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); } - public Textbox editor(int x, int y, int w, int h) { - return new Textbox(x, y, w, h, this.alpha ? 8 : 6, true, new Textbox.Callback() { - public void use(Textbox elem, Textbox.Action value) { - if(value == Action.SEND || value == Action.UNFOCUS) + public client.gui.element.Field editor(int x, int y, int w, int h) { + return new client.gui.element.Field(x, y, w, h, this.alpha ? 8 : 6, new FieldCallback() { + public void use(client.gui.element.Field elem, FieldAction value) { + if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) ColorVar.this.parse(elem.getText()); } }, this.format()); diff --git a/client/src/client/vars/EnumVar.java b/client/src/client/vars/EnumVar.java index ed30980..5f8273f 100644 --- a/client/src/client/vars/EnumVar.java +++ b/client/src/client/vars/EnumVar.java @@ -3,8 +3,10 @@ package client.vars; import java.lang.reflect.Field; import client.gui.element.Dropdown; +import client.gui.element.DropdownCallback; import client.gui.element.Element; import client.gui.element.Switch; +import client.gui.element.SwitchCallback; import common.color.TextColor; import common.util.Identifyable; import common.util.Util; @@ -79,7 +81,7 @@ public class EnumVar extends BaseVar { if(this.useSwitch) return this.switcher(x, y, w, h); try { - return new Dropdown(x, y, w, h, false, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Dropdown.Callback() { + return new Dropdown(x, y, w, h, false, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new DropdownCallback() { public void use(Dropdown elem, T value) { EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString()); } @@ -92,7 +94,7 @@ public class EnumVar extends BaseVar { public Switch switcher(int x, int y, int w, int h) { try { - return new Switch(x, y, w, h, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Switch.Callback() { + return new Switch(x, y, w, h, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new SwitchCallback() { public void use(Switch elem, T value) { EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString()); } diff --git a/client/src/client/vars/FloatVar.java b/client/src/client/vars/FloatVar.java index 2343af1..43c6a3f 100644 --- a/client/src/client/vars/FloatVar.java +++ b/client/src/client/vars/FloatVar.java @@ -3,6 +3,7 @@ package client.vars; import java.lang.reflect.Field; import client.gui.element.Slider; +import client.gui.element.SliderFloatCallback; import common.color.TextColor; import common.util.ExtMath; @@ -90,7 +91,7 @@ public class FloatVar extends BaseVar { public Slider selector(int x, int y, int w, int h) { 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) { FloatVar.this.parse(String.format(FloatVar.this.format, value)); } diff --git a/client/src/client/vars/IntVar.java b/client/src/client/vars/IntVar.java index 06282fb..312bd72 100644 --- a/client/src/client/vars/IntVar.java +++ b/client/src/client/vars/IntVar.java @@ -3,6 +3,7 @@ package client.vars; import java.lang.reflect.Field; import client.gui.element.Slider; +import client.gui.element.SliderCallback; import common.color.TextColor; import common.util.ExtMath; import common.util.Util; @@ -82,7 +83,7 @@ public class IntVar extends BaseVar { public Slider selector(int x, int y, int w, int h) { 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) { IntVar.this.parse(IntVar.this.formatValue(value)); } diff --git a/client/src/client/vars/StringVar.java b/client/src/client/vars/StringVar.java index 66dea94..8654948 100644 --- a/client/src/client/vars/StringVar.java +++ b/client/src/client/vars/StringVar.java @@ -2,8 +2,8 @@ package client.vars; import java.lang.reflect.Field; -import client.gui.element.Textbox; -import client.gui.element.Textbox.Action; +import client.gui.element.FieldCallback; +import client.gui.element.FieldAction; import common.color.TextColor; import common.util.CharValidator; @@ -67,10 +67,10 @@ public class StringVar extends BaseVar { return this.def; } - public Textbox selector(int x, int y, int w, int h) { - return new Textbox(x, y, w, h, this.maxLength, true, new Textbox.Callback() { - public void use(Textbox elem, Textbox.Action value) { - if(value == Action.SEND || value == Action.UNFOCUS) { + public client.gui.element.Field selector(int x, int y, int w, int h) { + return new client.gui.element.Field(x, y, w, h, this.maxLength, new FieldCallback() { + public void use(client.gui.element.Field elem, FieldAction value) { + if(value == FieldAction.SEND || value == FieldAction.UNFOCUS) { if(!StringVar.this.allowEmpty && elem.getText().isEmpty()) elem.setText(StringVar.this.format()); else