add clickable commands
This commit is contained in:
parent
dabef4a3fd
commit
73962c7ecd
16 changed files with 147 additions and 133 deletions
|
@ -4,16 +4,17 @@ import java.util.List;
|
|||
|
||||
import client.Client;
|
||||
import client.gui.element.ActButton;
|
||||
import client.gui.element.Area;
|
||||
import client.gui.element.ButtonCallback;
|
||||
import client.gui.element.Element;
|
||||
import client.gui.element.Fill;
|
||||
import client.gui.element.PressType;
|
||||
import client.renderer.Drawing;
|
||||
import client.gui.element.FieldAction;
|
||||
import client.gui.element.Field;
|
||||
import client.gui.element.FieldCallback;
|
||||
import client.vars.BoolVar;
|
||||
import client.vars.CVar;
|
||||
import client.gui.element.TransparentArea;
|
||||
import client.window.Keysym;
|
||||
import common.collect.Lists;
|
||||
import common.color.TextColor;
|
||||
|
@ -24,6 +25,42 @@ import common.util.ExtMath;
|
|||
import common.util.HitPosition;
|
||||
|
||||
public class GuiConsole extends Gui implements FieldCallback {
|
||||
private class ConsoleArea extends Area {
|
||||
private final boolean background;
|
||||
|
||||
public ConsoleArea(int x, int y, int w, int h, String text, boolean background) {
|
||||
super(x, y, w, h, text);
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
if(this.background)
|
||||
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000);
|
||||
}
|
||||
|
||||
protected void onDoubleClick() {
|
||||
if(this.sel_start >= 0 && this.sel_end == this.sel_start) {
|
||||
for(int z = this.sel_start; z >= 0; z--) {
|
||||
char c = this.text.charAt(z);
|
||||
if(c == TextColor.COMMAND.code) {
|
||||
for(int n = z + 1; n < this.text.length(); n++) {
|
||||
c = this.text.charAt(n);
|
||||
if(c < 0x20) {
|
||||
GuiConsole.this.send("/" + this.text.substring(z + 1, n), false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(c < 0x20) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onDoubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
public static final GuiConsole INSTANCE = new GuiConsole();
|
||||
|
||||
private final List<String> sentMessages = Lists.<String>newArrayList();
|
||||
|
@ -39,7 +76,7 @@ public class GuiConsole extends Gui implements FieldCallback {
|
|||
private int autocompleteIndex;
|
||||
private List<String> foundPlayerNames = Lists.<String>newArrayList();
|
||||
private Field inputField;
|
||||
private TransparentArea logBox;
|
||||
private ConsoleArea logBox;
|
||||
|
||||
public GuiConsole setFull(boolean full) {
|
||||
this.full = full;
|
||||
|
@ -58,7 +95,7 @@ public class GuiConsole extends Gui implements FieldCallback {
|
|||
}
|
||||
}, "Löschen"));
|
||||
}
|
||||
this.logBox = this.add(new TransparentArea(0, this.full ? Element.BASE_HEIGHT : 0, width, height - Element.BASE_HEIGHT * (this.full ? 2 : 1), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor));
|
||||
this.logBox = this.add(new ConsoleArea(0, this.full ? Element.BASE_HEIGHT : 0, width, height - Element.BASE_HEIGHT * (this.full ? 2 : 1), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor));
|
||||
if(this.full)
|
||||
this.add(new Fill(640, 0, width - 640, 0));
|
||||
this.inputField = this.add(new Field(0, height - Element.BASE_HEIGHT, width, 0, IPlayer.MAX_CMD_LENGTH, this, ""));
|
||||
|
@ -115,22 +152,24 @@ public class GuiConsole extends Gui implements FieldCallback {
|
|||
{
|
||||
String s = this.inputField.getText().trim();
|
||||
|
||||
if (s.length() > 0)
|
||||
{
|
||||
if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s))
|
||||
this.sentMessages.add(s);
|
||||
this.sentHistoryCursor = this.sentMessages.size();
|
||||
this.gm.exec(s);
|
||||
// if(this.gm.thePlayer != null)
|
||||
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s));
|
||||
}
|
||||
|
||||
this.inputField.setText("");
|
||||
if((this.gm.conAutoclose || !this.full) && this.gm.world != null)
|
||||
this.gm.show(null);
|
||||
this.send(s, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void send(String text, boolean clear) {
|
||||
if(!text.isEmpty()) {
|
||||
if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(text))
|
||||
this.sentMessages.add(text);
|
||||
this.sentHistoryCursor = this.sentMessages.size();
|
||||
this.gm.exec(text);
|
||||
}
|
||||
|
||||
if(clear)
|
||||
this.inputField.setText("");
|
||||
if((this.gm.conAutoclose || !this.full) && this.gm.world != null)
|
||||
this.gm.show(null);
|
||||
}
|
||||
|
||||
protected void setText(String newChatText, boolean shouldOverwrite)
|
||||
{
|
||||
if (shouldOverwrite)
|
||||
|
|
|
@ -84,7 +84,7 @@ public class GuiInfo extends Gui {
|
|||
if(num == 14)
|
||||
sb.append('\n');
|
||||
if((color.code >= Log.CHR_COLORS1 && color.code <= Log.CHR_COLORE1) || (color.code >= Log.CHR_COLORS2 && color.code <= Log.CHR_COLORE2)) {
|
||||
sb.append(color + "#" + (char)(num < 10 ? ('0' + num) : ('A' + (num - 10))) + ' ');
|
||||
sb.append(color + "#" + color.colorId + ' ');
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,11 +67,10 @@ abstract class Textbox extends Element {
|
|||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
if(btn == Button.MOUSE_LEFT) {
|
||||
if(!shift && ((System.currentTimeMillis() - this.tmr_leftmb) <= (long)this.gm.dclickDelay)) {
|
||||
this.sel_start = this.sel_drag = 0;
|
||||
this.sel_end = this.text.length();
|
||||
this.onDoubleClick();
|
||||
}
|
||||
else {
|
||||
gui_text_select(x, y, shift);
|
||||
this.gui_text_select(x, y, shift);
|
||||
}
|
||||
this.tmr_leftmb = System.currentTimeMillis();
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ abstract class Textbox extends Element {
|
|||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
gui_text_select(x, y, true);
|
||||
this.gui_text_select(x, y, true);
|
||||
}
|
||||
|
||||
public void character(char code) {
|
||||
|
@ -248,4 +247,9 @@ abstract class Textbox extends Element {
|
|||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onDoubleClick() {
|
||||
this.sel_start = this.sel_drag = 0;
|
||||
this.sel_end = this.text.length();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package client.gui.element;
|
||||
|
||||
import client.renderer.Drawing;
|
||||
|
||||
public class TransparentArea extends Area {
|
||||
private final 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;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
if(this.background)
|
||||
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue