add new files
This commit is contained in:
parent
4e90a93d68
commit
8038516a66
65 changed files with 7996 additions and 0 deletions
106
java/src/game/gui/Font.java
Normal file
106
java/src/game/gui/Font.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package game.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import game.log.Log;
|
||||
import game.renderer.GlState;
|
||||
import game.renderer.texture.TextureUtil;
|
||||
import game.util.FileUtils;
|
||||
import game.window.WCF;
|
||||
|
||||
public class Font {
|
||||
public static final FontChar[] SIZES = new FontChar[256];
|
||||
public static final int XGLYPH = 12;
|
||||
public static final int YGLYPH = 18;
|
||||
|
||||
private static int texture;
|
||||
|
||||
public static void bindTexture() {
|
||||
GlState.bindTexture(texture);
|
||||
}
|
||||
|
||||
private static int stride(int width, int height, int x, int y, int c) {
|
||||
return ((c & 15) * width + x) + (((c >> 4) & 15) * height + y) * (width << 4); // << 2;
|
||||
}
|
||||
|
||||
private static byte specialChar(int width, int ch) {
|
||||
return (byte)((ch == Log.CHR_UNK) ? width : ((ch == Log.CHR_SPC) ? (width / 6) : 127));
|
||||
}
|
||||
|
||||
private static void calculate(int[] data, FontChar[] glyphs, int width, int height, int page) {
|
||||
int off;
|
||||
for(int z = 0; z < 256; z++) {
|
||||
byte s, t, u, v;
|
||||
if((u = specialChar(width, (page << 8) + z)) != 127) {
|
||||
s = t = 0;
|
||||
v = (byte)(((int)u) * height / width);
|
||||
if(((page << 8) + z) != Log.CHR_UNK) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int y = 0; y < height; y++) {
|
||||
off = stride(width, height, x, y, z);
|
||||
data[off/*+3*/] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
glyphs[z] = new FontChar(s, t, u, v);
|
||||
continue;
|
||||
}
|
||||
s = t = 127;
|
||||
u = v = 0;
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int y = 0; y < height; y++) {
|
||||
off = stride(width, height, x, y, z);
|
||||
if((data[off/*+3*/] & 0xff000000) != 0) {
|
||||
s = x < s ? (byte)x : s;
|
||||
t = y < t ? (byte)y : t;
|
||||
u = x > u ? (byte)x : u;
|
||||
v = y > v ? (byte)y : v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(s == 127 && t == 127 && u == 0 && v == 0) {
|
||||
s = t = 0;
|
||||
}
|
||||
else {
|
||||
u += 1;
|
||||
v += 1;
|
||||
}
|
||||
glyphs[z] = new FontChar(s, t, u, v);
|
||||
}
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
BufferedImage img = null;
|
||||
try {
|
||||
img = TextureUtil.readImage(FileUtils.getResource("textures/font.png"));
|
||||
}
|
||||
catch(FileNotFoundException e) {
|
||||
Log.IO.error("Konnte Font-Textur nicht laden: Datei nicht vorhanden");
|
||||
}
|
||||
catch(IOException e) {
|
||||
Log.IO.error(e, "Konnte Font-Textur nicht laden");
|
||||
}
|
||||
if(img != null && (img.getWidth() != XGLYPH * 16 || img.getHeight() != YGLYPH * 16)) {
|
||||
Log.IO.error("Konnte Font-Textur nicht laden: Größe ist nicht %dx%d", XGLYPH * 16, YGLYPH * 16);
|
||||
img = null;
|
||||
}
|
||||
if(img == null)
|
||||
throw new IllegalStateException("Konnte erforderliche Schriftart nicht laden");
|
||||
int[] data = new int[XGLYPH * 16 * YGLYPH * 16];
|
||||
img.getRGB(0, 0, XGLYPH * 16, YGLYPH * 16, data, 0, XGLYPH * 16);
|
||||
calculate(data, SIZES, XGLYPH, YGLYPH, 0);
|
||||
texture = WCF.glGenTextures();
|
||||
TextureUtil.uploadImage(texture, img);
|
||||
Log.RENDER.debug("Font-Textur wurde mit ID #%d geladen", texture);
|
||||
}
|
||||
|
||||
public static void unload() {
|
||||
if(texture != 0) {
|
||||
WCF.glDeleteTextures(texture);
|
||||
Log.RENDER.debug("Font-Textur mit ID #%d wurde gelöscht", texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
}
|
15
java/src/game/gui/FontChar.java
Normal file
15
java/src/game/gui/FontChar.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package game.gui;
|
||||
|
||||
public class FontChar {
|
||||
public final byte s;
|
||||
public final byte t;
|
||||
public final byte u;
|
||||
public final byte v;
|
||||
|
||||
public FontChar(byte s, byte t, byte u, byte v) {
|
||||
this.s = s;
|
||||
this.t = t;
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
}
|
||||
}
|
362
java/src/game/gui/Gui.java
Normal file
362
java/src/game/gui/Gui.java
Normal file
|
@ -0,0 +1,362 @@
|
|||
package game.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.Game;
|
||||
import game.collect.Lists;
|
||||
import game.gui.element.Dropdown;
|
||||
import game.gui.element.Element;
|
||||
import game.gui.element.Dropdown.Handle;
|
||||
import game.renderer.DefaultVertexFormats;
|
||||
import game.renderer.Drawing;
|
||||
import game.renderer.GlState;
|
||||
import game.renderer.RenderBuffer;
|
||||
import game.renderer.Tessellator;
|
||||
import game.vars.CVar;
|
||||
import game.vars.ColorVar;
|
||||
import game.window.Bind;
|
||||
import game.window.Button;
|
||||
import game.window.Keysym;
|
||||
import game.window.WCF;
|
||||
|
||||
public abstract class Gui {
|
||||
public static final String DIRT_BACKGROUND = "textures/background.png";
|
||||
|
||||
protected final Game gm = Game.getGame();
|
||||
|
||||
public Element selected;
|
||||
private int min_x;
|
||||
private int min_y;
|
||||
private int max_x;
|
||||
private int max_y;
|
||||
public final List<Element> elems = Lists.newArrayList();
|
||||
|
||||
public abstract void init(int width, int height);
|
||||
public abstract String getTitle();
|
||||
|
||||
public void updateScreen() {
|
||||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
}
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
}
|
||||
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
}
|
||||
|
||||
public void drawPost() {
|
||||
}
|
||||
|
||||
public void drawGuiContainerForegroundLayer() {
|
||||
}
|
||||
|
||||
public void drawGuiContainerBackgroundLayer() {
|
||||
}
|
||||
|
||||
public void drawOverlays() {
|
||||
}
|
||||
|
||||
public void useHotbar(int slot) {
|
||||
}
|
||||
|
||||
public void dropItem() {
|
||||
}
|
||||
|
||||
public void drawBackground() {
|
||||
|
||||
}
|
||||
|
||||
public Element clicked(int x, int y) {
|
||||
if(this.selected != null && this.selected.visible && (this.selected instanceof Handle) && this.selected.inside(x, y))
|
||||
return this.selected; // fix (?)
|
||||
for(Element elem : this.elems) {
|
||||
if(elem.visible && elem.enabled && elem.inside(x, y))
|
||||
return elem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void reformat() {
|
||||
for(Element elem : this.elems) {
|
||||
elem.reformat();
|
||||
}
|
||||
}
|
||||
|
||||
public void deselect() {
|
||||
if(this.selected != null && !(this.selected instanceof Handle)) {
|
||||
this.selected.deselect();
|
||||
this.selected = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void select(Element elem) {
|
||||
if(this.selected != elem && !(this.selected instanceof Handle) && !(elem instanceof Handle)) {
|
||||
if(this.selected != null)
|
||||
this.selected.deselect();
|
||||
if(elem != null)
|
||||
elem.select();
|
||||
this.selected = elem;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
int prev;
|
||||
Element elem = this.clicked(x, y);
|
||||
if(this.selected != null && this.selected != elem && this.selected instanceof Handle) {
|
||||
this.selected.deselect();
|
||||
return;
|
||||
}
|
||||
else if(this.selected != elem) {
|
||||
if(this.selected != null)
|
||||
this.selected.deselect();
|
||||
if(elem != null)
|
||||
elem.select();
|
||||
this.selected = elem;
|
||||
}
|
||||
if(elem != null)
|
||||
elem.mouse(btn, x, y, ctrl, shift);
|
||||
}
|
||||
|
||||
public void mouserel(Button btn, int x, int y) {
|
||||
if(this.selected != null)
|
||||
this.selected.mouserel();
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
if(this.selected != null && (Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown()))
|
||||
this.selected.drag(x, y);
|
||||
}
|
||||
|
||||
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
|
||||
Element elem = this.clicked(x, y);
|
||||
if(elem != null)
|
||||
elem.scroll(scr_x, scr_y, x, y, ctrl, shift);
|
||||
}
|
||||
|
||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||
if(this.selected != null)
|
||||
this.selected.key(key, ctrl, shift);
|
||||
}
|
||||
|
||||
public void character(char code) {
|
||||
if(this.selected != null)
|
||||
this.selected.character(code);
|
||||
}
|
||||
|
||||
protected void shift() {
|
||||
if(this.gm.fb_x != 0 && this.gm.fb_y != 0) {
|
||||
int shift_x = (this.gm.fb_x - (this.max_x - this.min_x)) / 2 - this.min_x;
|
||||
int shift_y = (this.gm.fb_y - (this.max_y - this.min_y)) / 2 - this.min_y;
|
||||
for(Element elem : this.elems) {
|
||||
elem.shift(shift_x, shift_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.selected = null;
|
||||
this.min_x = this.min_y = Integer.MAX_VALUE;
|
||||
this.max_x = this.max_y = Integer.MIN_VALUE;
|
||||
this.elems.clear();
|
||||
this.init(this.gm.fb_x, this.gm.fb_y);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(this.selected != null)
|
||||
this.selected.update();
|
||||
}
|
||||
|
||||
protected <T extends Element> T add(T elem) {
|
||||
this.elems.add(elem);
|
||||
elem.setGui(this);
|
||||
this.min_x = Math.min(this.min_x, elem.getX());
|
||||
this.min_y = Math.min(this.min_y, elem.getY());
|
||||
this.max_x = Math.max(this.max_x, elem.getX() + elem.getWidth());
|
||||
this.max_y = Math.max(this.max_y, elem.getY() + elem.getHeight());
|
||||
if(elem instanceof Dropdown)
|
||||
this.add(((Dropdown)elem).getHandle());
|
||||
return elem;
|
||||
}
|
||||
|
||||
protected Element addSelector(String cvar, int x, int y, int w, int h) {
|
||||
CVar cv = this.gm.getVar(cvar);
|
||||
if(cv instanceof ColorVar) {
|
||||
ColorVar color = (ColorVar)cv;
|
||||
if(!color.getDisplay().isEmpty())
|
||||
this.add(color.label(x, y - 20, w, 20));
|
||||
return this.add(color.editor(x, y, w, h));
|
||||
}
|
||||
return this.add(cv.selector(x, y, w, h));
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if(this.selected != null && /* this.selected.r_dirty && */ this.selected instanceof Handle && !this.selected.visible) {
|
||||
this.selected = null;
|
||||
}
|
||||
for(Element elem : this.elems) {
|
||||
if(/* this.selected != e || */ !(elem instanceof Handle)) // || !e.visible)
|
||||
elem.draw();
|
||||
}
|
||||
if(this.selected != null && /* elem.r_dirty && */ this.selected instanceof Handle && this.selected.visible) {
|
||||
this.selected.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public void drawOverlay() {
|
||||
Element elem = this.selected;
|
||||
if(Button.isMouseDown() && elem != null && elem.enabled && elem.visible && elem.canClick()) {
|
||||
elem.drawPress();
|
||||
return;
|
||||
}
|
||||
if(elem != null && elem.enabled && elem.visible)
|
||||
elem.drawOverlay();
|
||||
elem = this.clicked(this.gm.mouse_x, this.gm.mouse_y);
|
||||
if(elem != null && elem.enabled && elem.visible && elem.canHover())
|
||||
elem.drawHover();
|
||||
}
|
||||
|
||||
public static void drawRect(int left, int top, int right, int bottom, int color)
|
||||
{
|
||||
if (left < right)
|
||||
{
|
||||
int i = left;
|
||||
left = right;
|
||||
right = i;
|
||||
}
|
||||
|
||||
if (top < bottom)
|
||||
{
|
||||
int j = top;
|
||||
top = bottom;
|
||||
bottom = j;
|
||||
}
|
||||
|
||||
float f3 = (float)(color >> 24 & 255) / 255.0F;
|
||||
float f = (float)(color >> 16 & 255) / 255.0F;
|
||||
float f1 = (float)(color >> 8 & 255) / 255.0F;
|
||||
float f2 = (float)(color & 255) / 255.0F;
|
||||
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
||||
GlState.enableBlend();
|
||||
GlState.disableTexture2D();
|
||||
GlState.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlState.color(f, f1, f2, f3);
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION);
|
||||
worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex();
|
||||
worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex();
|
||||
worldrenderer.pos((double)right, (double)top, 0.0D).endVertex();
|
||||
worldrenderer.pos((double)left, (double)top, 0.0D).endVertex();
|
||||
Tessellator.draw();
|
||||
GlState.enableTexture2D();
|
||||
GlState.disableBlend();
|
||||
}
|
||||
|
||||
public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
|
||||
{
|
||||
float f = 0.00390625F;
|
||||
float f1 = 0.00390625F;
|
||||
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
worldrenderer.pos((double)(x + 0), (double)(y + height), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + height) * f1)).endVertex();
|
||||
worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + height) * f1)).endVertex();
|
||||
worldrenderer.pos((double)(x + width), (double)(y + 0), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + 0) * f1)).endVertex();
|
||||
worldrenderer.pos((double)(x + 0), (double)(y + 0), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)
|
||||
{
|
||||
float f = 1.0F / tileWidth;
|
||||
float f1 = 1.0F / tileHeight;
|
||||
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex();
|
||||
worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex();
|
||||
worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex();
|
||||
worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
|
||||
{
|
||||
float f = (float)(startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float)(startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float)(startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float)(startColor & 255) / 255.0F;
|
||||
float f4 = (float)(endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float)(endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float)(endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float)(endColor & 255) / 255.0F;
|
||||
GlState.disableTexture2D();
|
||||
GlState.enableBlend();
|
||||
GlState.disableAlpha();
|
||||
GlState.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlState.shadeModel(7425);
|
||||
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
worldrenderer.pos((double)right, (double)top, 0.0).color(f1, f2, f3, f).endVertex();
|
||||
worldrenderer.pos((double)left, (double)top, 0.0).color(f1, f2, f3, f).endVertex();
|
||||
worldrenderer.pos((double)left, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex();
|
||||
worldrenderer.pos((double)right, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex();
|
||||
Tessellator.draw();
|
||||
GlState.shadeModel(7424);
|
||||
GlState.disableBlend();
|
||||
GlState.enableAlpha();
|
||||
GlState.enableTexture2D();
|
||||
}
|
||||
|
||||
public void drawMainBackground() {
|
||||
if(this.gm.theWorld != null) {
|
||||
// Drawing.drawGradient(0, 0, this.fb_x, this.fb_y, this.theWorld == null ? this.style.bg_top : 0x3f202020,
|
||||
// this.theWorld == null ? this.style.bg_btm : 0x3f000000);
|
||||
Drawing.drawGradient(0, 0, this.gm.fb_x, this.gm.fb_y, 0xc0101010, 0xd0101010);
|
||||
}
|
||||
else {
|
||||
this.drawDirtBackground(0, 0, this.gm.fb_x, this.gm.fb_y);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawDirtBackground(double x, double y, double width, double height) {
|
||||
GlState.enableTexture2D();
|
||||
GlState.disableLighting();
|
||||
GlState.disableFog();
|
||||
RenderBuffer buf = Tessellator.getBuffer();
|
||||
this.gm.getTextureManager().bindTexture(DIRT_BACKGROUND);
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
double scale = 32.0;
|
||||
buf.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
buf.pos(x, y + height, 0.0D).tex(0.0D, height / scale)
|
||||
.color(64, 64, 64, 255).endVertex();
|
||||
buf.pos(x + width, y + height, 0.0D)
|
||||
.tex(width / scale, height / scale)
|
||||
.color(64, 64, 64, 255).endVertex();
|
||||
buf.pos(x + width, y, 0.0D).tex(width / scale, 0.0)
|
||||
.color(64, 64, 64, 255).endVertex();
|
||||
buf.pos(x, y, 0.0D).tex(0.0D, 0.0)
|
||||
.color(64, 64, 64, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
GlState.disableTexture2D();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
this.drawMainBackground();
|
||||
this.drawBackground();
|
||||
if(this.gm.fb_x != 0 && this.gm.fb_y != 0)
|
||||
this.draw();
|
||||
this.drawGuiContainerBackgroundLayer();
|
||||
this.drawGuiContainerForegroundLayer();
|
||||
GlState.bindTexture(0);
|
||||
GlState.setActiveTexture(WCF.GL_TEXTURE0);
|
||||
GlState.enableTexture2D();
|
||||
GlState.disableDepth();
|
||||
this.drawPost();
|
||||
GlState.disableDepth();
|
||||
this.drawOverlays();
|
||||
if(Bind.isWindowActive())
|
||||
this.drawOverlay();
|
||||
}
|
||||
}
|
74
java/src/game/gui/GuiBinds.java
Normal file
74
java/src/game/gui/GuiBinds.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.util.Formatter;
|
||||
import game.window.Bind;
|
||||
|
||||
public class GuiBinds extends GuiOptions {
|
||||
protected GuiBinds() {
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
for(Bind bind : Bind.values()) {
|
||||
this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay()));
|
||||
this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(action == Mode.SECONDARY) {
|
||||
if(!bind.isDefault()) {
|
||||
bind.setDefault();
|
||||
GuiBinds.this.gm.setDirty();
|
||||
GuiBinds.this.reformat();
|
||||
}
|
||||
}
|
||||
else if(action == Mode.TERTIARY) {
|
||||
if(bind.getInput() != null) {
|
||||
bind.setInput(null);
|
||||
GuiBinds.this.gm.setDirty();
|
||||
GuiBinds.this.reformat();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Bind.disableInput(bind);
|
||||
}
|
||||
}
|
||||
}, new Formatter<ActButton>() {
|
||||
public String use(ActButton elem) {
|
||||
if(bind == Bind.getWaiting())
|
||||
return /* TextColor.BLINK + "" + */ TextColor.BLUE + "***";
|
||||
else
|
||||
return (bind.isDupe() ? TextColor.RED : TextColor.YELLOW) + (bind.getInput() == null ? "---" : bind.getInput().getDisplay());
|
||||
}
|
||||
}));
|
||||
if(++x == 5) {
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
y += x != 0 ? 1 : 0;
|
||||
this.add(new ActButton(200, 100 + y * 50, 560, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
boolean flag = false;
|
||||
for(Bind bind : Bind.values()) {
|
||||
flag |= !bind.isDefault();
|
||||
bind.setDefault();
|
||||
}
|
||||
if(flag) {
|
||||
GuiBinds.this.gm.setDirty();
|
||||
GuiBinds.this.reformat();
|
||||
}
|
||||
}
|
||||
}, "Zurücksetzen"));
|
||||
this.addSelector("phy_sensitivity", 30, 160 + y * 50, 440, 24);
|
||||
this.addSelector("gui_dclick_delay", 490, 160 + y * 50, 440, 24);
|
||||
super.init(width, height);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Tastenbelegung und Maus";
|
||||
}
|
||||
}
|
106
java/src/game/gui/GuiConnect.java
Normal file
106
java/src/game/gui/GuiConnect.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.network.NetHandlerPlayServer;
|
||||
|
||||
public class GuiConnect extends Gui implements Textbox.Callback {
|
||||
public static final GuiConnect INSTANCE = new GuiConnect();
|
||||
|
||||
private GuiConnect() {
|
||||
}
|
||||
|
||||
private Textbox addrBox;
|
||||
private Textbox portBox;
|
||||
private Textbox userBox;
|
||||
private Textbox passBox;
|
||||
private Textbox accBox;
|
||||
private Label addrLabel;
|
||||
private Label portLabel;
|
||||
private Label userLabel;
|
||||
private Label passLabel;
|
||||
private Label accLabel;
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.addrBox = this.add(new Textbox(0, 20, 410, 24, 128, true, this, ""));
|
||||
this.portBox = this.add(new Textbox(414, 20, 66, 24, 5, true, this, ""));
|
||||
this.userBox = this.add(new Textbox(0, 70, 220, 24, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, ""));
|
||||
this.passBox = this.add(new Textbox(0, 120, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, ""));
|
||||
this.accBox = this.add(new Textbox(0, 170, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, ""));
|
||||
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiConnect.this.connect();
|
||||
}
|
||||
}, "Verbinden"));
|
||||
this.add(new ActButton(0, 250, 480, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiConnect.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
}, "Zurück"));
|
||||
this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true));
|
||||
this.portLabel = this.add(new Label(414, 0, 66, 20, "Port", true));
|
||||
this.userLabel = this.add(new Label(0, 50, 220, 20, "Nutzer", true));
|
||||
this.passLabel = this.add(new Label(0, 100, 480, 20, "Passwort", true));
|
||||
this.accLabel = this.add(new Label(0, 150, 480, 20, "Zugang", true));
|
||||
this.shift();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Mit Server verbinden";
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
if(this.gm.theWorld != null)
|
||||
return;
|
||||
String addr = this.addrBox.getText();
|
||||
if(addr.isEmpty()) {
|
||||
this.addrLabel.setText(TextColor.RED + "Adresse");
|
||||
return;
|
||||
}
|
||||
int port = -1;
|
||||
if(this.portBox.getText().isEmpty()) {
|
||||
port = 26666;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
port = Integer.parseInt(this.portBox.getText());
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(port < 0 || port > 65535) {
|
||||
this.portLabel.setText(TextColor.RED + "Port");
|
||||
return;
|
||||
}
|
||||
}
|
||||
String user = this.userBox.getText();
|
||||
if(user.isEmpty()) {
|
||||
this.userLabel.setText(TextColor.RED + "Nutzer");
|
||||
return;
|
||||
}
|
||||
String pass = this.passBox.getText();
|
||||
String acc = this.accBox.getText();
|
||||
this.gm.connect(addr, port, user, pass, acc);
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND) {
|
||||
elem.setDeselected();
|
||||
this.connect();
|
||||
}
|
||||
else if(value == Action.FOCUS) {
|
||||
if(elem == this.addrBox)
|
||||
this.addrLabel.setText("Adresse");
|
||||
else if(elem == this.portBox)
|
||||
this.portLabel.setText("Port");
|
||||
else if(elem == this.userBox)
|
||||
this.userLabel.setText("Nutzer");
|
||||
}
|
||||
}
|
||||
|
||||
// public void updateScreen() {
|
||||
//
|
||||
// }
|
||||
}
|
311
java/src/game/gui/GuiConsole.java
Normal file
311
java/src/game/gui/GuiConsole.java
Normal file
|
@ -0,0 +1,311 @@
|
|||
package game.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Fill;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.TransparentBox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.log.Log;
|
||||
import game.network.NetHandlerPlayServer;
|
||||
import game.packet.CPacketComplete;
|
||||
import game.util.ExtMath;
|
||||
import game.window.Keysym;
|
||||
|
||||
public class GuiConsole extends Gui implements Textbox.Callback {
|
||||
public static final GuiConsole INSTANCE = new GuiConsole();
|
||||
|
||||
private final List<String> sentMessages = Lists.<String>newArrayList();
|
||||
|
||||
private String historyBuffer = "";
|
||||
private int sentHistoryCursor = -1;
|
||||
private boolean playerNamesFound;
|
||||
private boolean waitingOnAutocomplete;
|
||||
private int autocompleteIndex;
|
||||
private List<String> foundPlayerNames = Lists.<String>newArrayList();
|
||||
private Textbox inputField;
|
||||
private TransparentBox logBox;
|
||||
|
||||
public void init(int width, int height) {
|
||||
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) {
|
||||
GuiConsole.this.reset();
|
||||
GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer());
|
||||
}
|
||||
}, "Löschen"));
|
||||
this.logBox = this.add(new TransparentBox(0, 24, width, height - 48, this.gm.getBuffer()));
|
||||
this.add(new Fill(640, 0, width - 640, 24));
|
||||
this.inputField = this.add(new Textbox(0, height - 24, width, 24, NetHandlerPlayServer.MAX_CMD_LENGTH, true, this, ""));
|
||||
this.inputField.setSelected();
|
||||
this.sentHistoryCursor = this.sentMessages.size();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Konsole / Chat";
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.gm.reset();
|
||||
this.sentMessages.clear();
|
||||
this.sentHistoryCursor = -1;
|
||||
}
|
||||
|
||||
public void setLog(String buffer) {
|
||||
if(this.logBox != null)
|
||||
this.logBox.setText(buffer);
|
||||
}
|
||||
|
||||
public void drawMainBackground() {
|
||||
if(this.gm.theWorld == null)
|
||||
super.drawMainBackground();
|
||||
}
|
||||
|
||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||
super.key(key, ctrl, shift);
|
||||
// this.waitingOnAutocomplete = false;
|
||||
if(key != Keysym.TAB)
|
||||
this.playerNamesFound = false;
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value)
|
||||
{
|
||||
this.waitingOnAutocomplete = false;
|
||||
|
||||
if ((value == Action.FORWARD || value == Action.BACKWARD) && this.gm.thePlayer != null)
|
||||
{
|
||||
this.autocompletePlayerNames();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.playerNamesFound = false;
|
||||
}
|
||||
|
||||
if(value == Action.PREVIOUS)
|
||||
this.getSentHistory(-1);
|
||||
else if (value == Action.NEXT)
|
||||
this.getSentHistory(1);
|
||||
if(value == Action.SEND)
|
||||
{
|
||||
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.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.gm.theWorld != null)
|
||||
this.gm.displayGuiScreen(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setText(String newChatText, boolean shouldOverwrite)
|
||||
{
|
||||
if (shouldOverwrite)
|
||||
{
|
||||
this.inputField.setText(newChatText);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inputField.insertText(newChatText);
|
||||
}
|
||||
}
|
||||
|
||||
public void autocompletePlayerNames()
|
||||
{
|
||||
if (this.playerNamesFound)
|
||||
{
|
||||
this.inputField.deleteFromCursor();
|
||||
|
||||
if (this.autocompleteIndex >= this.foundPlayerNames.size())
|
||||
{
|
||||
this.autocompleteIndex = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = this.inputField.getNthCharFromPos();
|
||||
this.foundPlayerNames.clear();
|
||||
this.autocompleteIndex = 0;
|
||||
String s = this.inputField.getText().substring(i).toLowerCase();
|
||||
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition());
|
||||
this.sendAutocompleteRequest(s1, s);
|
||||
|
||||
if (this.foundPlayerNames.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.playerNamesFound = true;
|
||||
this.inputField.deleteFromCursor();
|
||||
}
|
||||
|
||||
if (this.foundPlayerNames.size() > 1)
|
||||
{
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
for (String s2 : this.foundPlayerNames)
|
||||
{
|
||||
if (stringbuilder.length() > 0)
|
||||
{
|
||||
stringbuilder.append(", ");
|
||||
}
|
||||
|
||||
stringbuilder.append(s2);
|
||||
}
|
||||
|
||||
Log.CONSOLE.user(stringbuilder.toString());
|
||||
}
|
||||
|
||||
this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex++));
|
||||
}
|
||||
|
||||
private void sendAutocompleteRequest(String currentText, String newText)
|
||||
{
|
||||
if (currentText.length() >= 1)
|
||||
{
|
||||
// BlockPos blockpos = null;
|
||||
// int eid = -1;
|
||||
//
|
||||
// if (this.gm.pointed != null && this.gm.pointed.type == HitPosition.ObjectType.BLOCK)
|
||||
// {
|
||||
// blockpos = this.gm.pointed.block;
|
||||
// }
|
||||
// else if (this.gm.pointed != null && this.gm.pointed.type == HitPosition.ObjectType.ENTITY)
|
||||
// {
|
||||
// eid = this.gm.pointed.entity.getId();
|
||||
// }
|
||||
|
||||
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText));
|
||||
this.waitingOnAutocomplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void getSentHistory(int msgPos)
|
||||
{
|
||||
int i = this.sentHistoryCursor + msgPos;
|
||||
int j = this.sentMessages.size();
|
||||
i = ExtMath.clampi(i, 0, j);
|
||||
|
||||
if (i != this.sentHistoryCursor)
|
||||
{
|
||||
if (i == j)
|
||||
{
|
||||
this.sentHistoryCursor = j;
|
||||
this.inputField.setText(this.historyBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.sentHistoryCursor == j)
|
||||
{
|
||||
this.historyBuffer = this.inputField.getText();
|
||||
}
|
||||
|
||||
this.inputField.setText(this.sentMessages.get(i));
|
||||
this.sentHistoryCursor = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAutocompleteResponse(String[] choices)
|
||||
{
|
||||
if (this.waitingOnAutocomplete)
|
||||
{
|
||||
this.playerNamesFound = false;
|
||||
this.foundPlayerNames.clear();
|
||||
|
||||
for (String s : choices)
|
||||
{
|
||||
if (s.length() > 0)
|
||||
{
|
||||
this.foundPlayerNames.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
String s1 = this.inputField.getText().substring(this.inputField.getNthCharFromPos());
|
||||
String s2 = getCommonPrefix(choices);
|
||||
|
||||
if (s2.length() > 0 && !s1.equalsIgnoreCase(s2))
|
||||
{
|
||||
this.inputField.deleteFromCursor();
|
||||
this.inputField.insertText(s2);
|
||||
}
|
||||
else if (this.foundPlayerNames.size() > 0)
|
||||
{
|
||||
this.playerNamesFound = true;
|
||||
this.autocompletePlayerNames();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCommonPrefix(String[] strs) {
|
||||
if (strs != null && strs.length != 0) {
|
||||
int smallestIndexOfDiff = indexOfDifference(strs);
|
||||
if (smallestIndexOfDiff == -1) {
|
||||
return strs[0] == null ? "" : strs[0];
|
||||
} else {
|
||||
return smallestIndexOfDiff == 0 ? "" : strs[0].substring(0, smallestIndexOfDiff);
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static int indexOfDifference(CharSequence[] css) {
|
||||
if (css != null && css.length > 1) {
|
||||
boolean anyStringNull = false;
|
||||
boolean allStringsNull = true;
|
||||
int arrayLen = css.length;
|
||||
int shortestStrLen = Integer.MAX_VALUE;
|
||||
int longestStrLen = 0;
|
||||
|
||||
int firstDiff;
|
||||
for (firstDiff = 0; firstDiff < arrayLen; ++firstDiff) {
|
||||
if (css[firstDiff] == null) {
|
||||
anyStringNull = true;
|
||||
shortestStrLen = 0;
|
||||
} else {
|
||||
allStringsNull = false;
|
||||
shortestStrLen = Math.min(css[firstDiff].length(), shortestStrLen);
|
||||
longestStrLen = Math.max(css[firstDiff].length(), longestStrLen);
|
||||
}
|
||||
}
|
||||
|
||||
if (allStringsNull || longestStrLen == 0 && !anyStringNull) {
|
||||
return -1;
|
||||
} else if (shortestStrLen == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
firstDiff = -1;
|
||||
|
||||
for (int stringPos = 0; stringPos < shortestStrLen; ++stringPos) {
|
||||
char comparisonChar = css[0].charAt(stringPos);
|
||||
|
||||
for (int arrayPos = 1; arrayPos < arrayLen; ++arrayPos) {
|
||||
if (css[arrayPos].charAt(stringPos) != comparisonChar) {
|
||||
firstDiff = stringPos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstDiff != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return firstDiff == -1 && shortestStrLen != longestStrLen ? shortestStrLen : firstDiff;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
70
java/src/game/gui/GuiDisplay.java
Normal file
70
java/src/game/gui/GuiDisplay.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.Dropdown;
|
||||
import game.gui.element.Fill;
|
||||
import game.gui.element.Slider;
|
||||
import game.util.Formatter;
|
||||
import game.window.DisplayMode;
|
||||
import game.window.WCF;
|
||||
|
||||
public class GuiDisplay extends GuiOptions {
|
||||
protected GuiDisplay() {
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
DisplayMode[] dmodes = WCF.getDisplayModes();
|
||||
if(dmodes != null && dmodes.length > 0) {
|
||||
int offset = 0;
|
||||
int pos = 0;
|
||||
int num = dmodes.length;
|
||||
if(dmodes.length > DisplayMode.VID_MODES) {
|
||||
offset = dmodes.length - DisplayMode.VID_MODES;
|
||||
num = DisplayMode.VID_MODES;
|
||||
}
|
||||
DisplayMode[] modes = new DisplayMode[num];
|
||||
DisplayMode selected = dmodes[num + offset - 1];
|
||||
for(int z = 0; z < num; z++) {
|
||||
modes[z] = dmodes[z + offset];
|
||||
if(modes[z].equals(this.gm.vidMode))
|
||||
selected = modes[z];
|
||||
}
|
||||
this.add(new Dropdown<DisplayMode>(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new Dropdown.Callback<DisplayMode>() {
|
||||
public void use(Dropdown<DisplayMode> elem, DisplayMode value) {
|
||||
GuiDisplay.this.gm.vidMode = value;
|
||||
}
|
||||
}, "Auflösung"));
|
||||
}
|
||||
else {
|
||||
this.add(new Fill(30, 80, 440, 24, TextColor.RED + "Auflösung: <XRandR kaputt :)>"));
|
||||
}
|
||||
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
}, new Formatter<Slider>() {
|
||||
public String use(Slider elem) {
|
||||
int value = elem.getValue();
|
||||
return "Max. Bildrate: " + (value > 0 && value < (360 - 8) ? (value + 9) + " FPS" : (value != 0 ? "Unbegrenzt" : "VSync"));
|
||||
}
|
||||
}));
|
||||
this.addSelector("gl_vsync_flush", 490, 120, 440, 24);
|
||||
|
||||
this.addSelector("con_overlay", 30, 200, 440, 24);
|
||||
this.addSelector("con_opacity", 490, 200, 440, 24);
|
||||
this.addSelector("con_size", 30, 240, 440, 24);
|
||||
this.addSelector("con_fadeout", 490, 240, 440, 24);
|
||||
this.addSelector("con_position", 30, 280, 440, 24);
|
||||
|
||||
this.addSelector("gl_fov", 30, 360, 440, 24);
|
||||
this.addSelector("chunk_view_distance", 30, 400, 440, 24);
|
||||
this.addSelector("chunk_build_time", 490, 400, 440, 24);
|
||||
super.init(width, height);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Grafik und Anzeige";
|
||||
}
|
||||
}
|
55
java/src/game/gui/GuiInfo.java
Normal file
55
java/src/game/gui/GuiInfo.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.TransparentBox;
|
||||
import game.init.Config;
|
||||
|
||||
public class GuiInfo extends Gui {
|
||||
private static final String INFO =
|
||||
TextColor.GREEN + "" + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG + " " + TextColor.VIOLET + "" + Config.VERSION + "" +
|
||||
TextColor.GREEN + " " + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG + "\n" +
|
||||
"\n" +
|
||||
TextColor.LGRAY + "Ein kleine Anwendung zur Simulation, zum Testen, für Spiele, Musik und vieles" + "\n" +
|
||||
"mehr. Optimiert für Geschwindigkeit, Stabilität und" + TextColor.UNKNOWN + "" + TextColor.UNKNOWN + " [Speicherzugriffsfehler]" + "\n" +
|
||||
"\n" +
|
||||
TextColor.CYAN + "Geschrieben von Sen dem \"kleinen\" Dämonen " + TextColor.CRIMSON + TextColor.DEMON + TextColor.BLACK + TextColor.BLKHEART + "\n" +
|
||||
"\n" +
|
||||
TextColor.YELLOW + "Verwendete Programmbibliotheken:" + "\n" +
|
||||
TextColor.LGRAY + " -> " + TextColor.NEON + "axe_ork (Modifiziert: GLFW 3.3.8)" + "\n" +
|
||||
TextColor.LGRAY + " -> " + TextColor.NEON + "opl3 (Modifiziert: Nuked-OPL3 f2c9873)" + "\n" +
|
||||
TextColor.LGRAY + " -> " + TextColor.NEON + "nionet (Modifiziert: Netty 4.0.23-Final)" + "\n" +
|
||||
TextColor.LGRAY + " -> " + TextColor.NEON + "collectutil + futureutil (Modifiziert: Guava 17.0)" + "\n" +
|
||||
TextColor.LGRAY + " -> " + TextColor.NEON + "tjglu (Modifiziert: LWJGL 2.9.4-nightly-20150209)" + "\n" +
|
||||
// "\n" +
|
||||
// TextColor.YELLOW + "Verwendeter Compiler: " + "\n" +
|
||||
// TextColor.LGRAY + " -> " + TextColor.NEON + BUILD_COMP + "\n" +
|
||||
// "\n" +
|
||||
// TextColor.YELLOW + "Kompiliert auf System: " + "\n" +
|
||||
// TextColor.LGRAY + " -> " + TextColor.NEON + BUILD_SYS + "\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
TextColor.BLACK + "#0 " + TextColor.DGRAY + "#1 " + TextColor.GRAY + "#2 " + TextColor.LGRAY + "#3 " + TextColor.WHITE + "#4 " + TextColor.RED + "#5 " + TextColor.GREEN + "#6 " +
|
||||
TextColor.BLUE + "#7 " + TextColor.YELLOW + "#8 " + TextColor.MAGENTA + "#9 " + TextColor.CYAN + "#A " + TextColor.VIOLET + "#B " + TextColor.ORANGE + "#C " + TextColor.CRIMSON + "#D " +
|
||||
TextColor.MIDNIGHT + "#E " + TextColor.NEON + "#F " + TextColor.BROWN + "#G " + TextColor.DBROWN + "#H " + TextColor.DGREEN + "#I " + TextColor.DRED + "#J " + TextColor.DMAGENTA + "#K " +
|
||||
TextColor.DVIOLET + "#L " + TextColor.ORK + "#M " + TextColor.ACID + "#N ";
|
||||
|
||||
public static final GuiInfo INSTANCE = new GuiInfo("Über dieses Programm", INFO);
|
||||
|
||||
private final String header;
|
||||
private final String info;
|
||||
|
||||
public GuiInfo(String header, String info) {
|
||||
this.header = header;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.add(new TransparentBox(0, 0, width, height - 24, this.info));
|
||||
this.add(new ActButton(0, height - 24, width, 24, GuiMenu.INSTANCE, "Zurück"));
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.header;
|
||||
}
|
||||
}
|
280
java/src/game/gui/GuiMenu.java
Normal file
280
java/src/game/gui/GuiMenu.java
Normal file
|
@ -0,0 +1,280 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.gui.world.GuiWorlds;
|
||||
import game.init.Config;
|
||||
import game.renderer.Drawing;
|
||||
import game.rng.Random;
|
||||
import game.util.Splashes;
|
||||
import game.util.Timing;
|
||||
import game.window.Keysym;
|
||||
|
||||
public class GuiMenu extends Gui {
|
||||
public static final GuiMenu INSTANCE = new GuiMenu();
|
||||
|
||||
private GuiMenu() {
|
||||
}
|
||||
|
||||
public void drawMainBackground() {
|
||||
if(this.gm.theWorld != null)
|
||||
super.drawMainBackground();
|
||||
else
|
||||
this.gm.renderGlobal.renderStarField(this.gm.fb_x, this.gm.fb_y, 0x000000, 0xffffff, (float)this.ticks + (float)Timing.tick_fraction, this.rand);
|
||||
}
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
private Label splashLabel;
|
||||
|
||||
private int ticks;
|
||||
private int hacked;
|
||||
|
||||
private int animWidth = 32;
|
||||
private int animGrowth = 10;
|
||||
private int[] animGrow = new int[this.animWidth];
|
||||
private String animStr = "";
|
||||
private String animBack = "";
|
||||
private int animPos;
|
||||
private int animLen;
|
||||
private int animDir;
|
||||
private boolean animStep;
|
||||
|
||||
public void init(int width, int height) {
|
||||
if(this.gm.theWorld == null) {
|
||||
this.ticks = 0;
|
||||
this.hacked = 0;
|
||||
this.resetAnimation();
|
||||
this.add(new ActButton(0, 0, 400, 24, (Gui)GuiWorlds.INSTANCE, "Einzelspieler"));
|
||||
this.add(new ActButton(0, 28, 400, 24, (Gui)GuiConnect.INSTANCE, "Mehrspieler"));
|
||||
this.add(new ActButton(0, 56, 400, 24, GuiInfo.INSTANCE, "Info / Über / Mitwirkende"));
|
||||
this.add(new ActButton(0, 102, 196, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
this.add(new ActButton(204, 102, 196, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.interrupted = true;
|
||||
}
|
||||
}, "Spiel beenden"));
|
||||
this.shift();
|
||||
this.add(new Label(4, /* this.gm.fb_y - 2 */ 0, 200, 20, TextColor.VIOLET + Config.VERSION, true));
|
||||
this.splashLabel = this.add(new Label(0, 160, width, 24, ""));
|
||||
this.pickSplash();
|
||||
}
|
||||
else {
|
||||
this.add(new ActButton(0, 0, 400, 24, (Gui)null, "Zurück zum Spiel"));
|
||||
this.add(new ActButton(0, 28, 400, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
if(!this.gm.isRemote() && !this.gm.debugWorld) {
|
||||
this.add(new Textbox(0, 56, 96, 24, 5, true, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND || value == Action.UNFOCUS) {
|
||||
int port = -1;
|
||||
try {
|
||||
port = Integer.parseInt(elem.getText());
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(port < 0 || port > 65535)
|
||||
elem.setText("" + GuiMenu.this.gm.port);
|
||||
else
|
||||
GuiMenu.this.gm.port = port;
|
||||
}
|
||||
}
|
||||
}, "" + this.gm.port)); // "srv_port"
|
||||
this.add(new ActButton(100, 56, 300, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.bind(GuiMenu.this.gm.bind = (GuiMenu.this.gm.bind != -1 ? -1 : GuiMenu.this.gm.port));
|
||||
elem.setText(GuiMenu.this.gm.bind != -1 ? "LAN-Welt schließen" : "LAN-Welt öffnen");
|
||||
}
|
||||
}, this.gm.bind != -1 ? "LAN-Welt schließen" : "LAN-Welt öffnen"));
|
||||
}
|
||||
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.unload();
|
||||
GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
||||
}
|
||||
}, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen"));
|
||||
this.shift();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.gm.theWorld == null ? "Hauptmenü" : "Menü";
|
||||
}
|
||||
|
||||
private void pickSplash() {
|
||||
this.splashLabel.setText(TextColor.VIOLET + this.rand.pick(Splashes.SPLASHES));
|
||||
}
|
||||
|
||||
private void resetAnimation() {
|
||||
this.animStr = "";
|
||||
this.animBack = "";
|
||||
this.animPos = 0;
|
||||
this.animLen = 0;
|
||||
this.animDir = 0;
|
||||
this.animStep = false;
|
||||
this.animWidth = Math.max(5, (this.gm.fb_x - 5) / 10);
|
||||
this.animGrowth = this.animWidth / 15;
|
||||
this.animGrow = new int[this.animWidth];
|
||||
}
|
||||
|
||||
private void updateAnimation() {
|
||||
if(this.animLen == 0) {
|
||||
this.animDir = this.rand.zrange(3) - 1;
|
||||
this.animLen = this.animDir == 0 ? (2 + this.rand.zrange(2)) : (8 + this.rand.zrange(96));
|
||||
}
|
||||
else {
|
||||
this.animPos += this.animDir;
|
||||
if(this.animPos == -1) {
|
||||
this.animPos = 0;
|
||||
this.animDir = 1;
|
||||
}
|
||||
else if(this.animPos == this.animWidth - 3) {
|
||||
this.animPos = this.animWidth - 4;
|
||||
this.animDir = -1;
|
||||
}
|
||||
this.animLen--;
|
||||
}
|
||||
this.animStep = !this.animStep;
|
||||
StringBuilder sb = new StringBuilder(11);
|
||||
sb.append(TextColor.GRAY);
|
||||
sb.append("[");
|
||||
sb.append(TextColor.YELLOW);
|
||||
switch(this.animDir) {
|
||||
case -1:
|
||||
sb.append((this.animStep ? '>' : '-') + "' ");
|
||||
break;
|
||||
case 0:
|
||||
sb.append("`" + (this.animStep ? 'O' : 'o') + "'");
|
||||
break;
|
||||
case 1:
|
||||
sb.append(" `" + (this.animStep ? '<' : '-'));
|
||||
break;
|
||||
}
|
||||
sb.append(TextColor.GRAY);
|
||||
sb.append("]");
|
||||
this.animStr = sb.toString();
|
||||
for(int z = this.animPos; z < this.animPos + 4; z++) {
|
||||
this.animGrow[z] = 0;
|
||||
}
|
||||
for(int z = 0; z < this.animGrowth; z++) {
|
||||
this.animGrow[this.rand.zrange(this.animWidth)] += 1;
|
||||
}
|
||||
sb = new StringBuilder(this.animWidth + 2);
|
||||
sb.append(TextColor.DGREEN);
|
||||
for(int z = 0; z < this.animWidth; z++) {
|
||||
switch(this.animGrow[z] / 5) {
|
||||
case 0:
|
||||
sb.append(TextColor.BLACK);
|
||||
break;
|
||||
case 1:
|
||||
sb.append(TextColor.GRAY);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
sb.append(TextColor.LGRAY);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
sb.append(TextColor.WHITE);
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
sb.append(TextColor.MAGENTA);
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
sb.append(TextColor.DVIOLET);
|
||||
break;
|
||||
default:
|
||||
sb.append(TextColor.VIOLET);
|
||||
break;
|
||||
}
|
||||
sb.append(",.");
|
||||
}
|
||||
this.animBack = sb.toString();
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
if(this.gm.theWorld == null) {
|
||||
this.ticks++;
|
||||
if(this.gm.shift() && !(this.selected instanceof Textbox))
|
||||
this.pickSplash();
|
||||
this.updateAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||
super.key(key, ctrl, shift);
|
||||
if(this.gm.theWorld == null) {
|
||||
if((key == Keysym.UP || key == Keysym.W) && (this.hacked == 0 || this.hacked == 1))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.DOWN || key == Keysym.S) && (this.hacked == 2 || this.hacked == 3))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.LEFT || key == Keysym.A) && (this.hacked == 4 || this.hacked == 6))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.RIGHT || key == Keysym.D) && (this.hacked == 5 || this.hacked == 7))
|
||||
this.hacked++;
|
||||
else
|
||||
this.hacked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
protected void actionPerformed(Button button) throws IOException {
|
||||
if(button.id == 2 && this.hacked == 8) {
|
||||
this.hacked++;
|
||||
return;
|
||||
}
|
||||
else if(button.id == 1 && this.hacked == 9) {
|
||||
this.hacked++;
|
||||
return;
|
||||
}
|
||||
if(button.id != 3 || this.hacked != 10)
|
||||
this.hacked = 0;
|
||||
switch(button.id) {
|
||||
case 0:
|
||||
this.gm.displayGuiScreen(new GuiOptions(this));
|
||||
break;
|
||||
case 1:
|
||||
this.gm.displayGuiScreen(new GuiWorlds(this));
|
||||
break;
|
||||
case 2:
|
||||
this.gm.displayGuiScreen(new GuiMultiplayer(this));
|
||||
break;
|
||||
case 3:
|
||||
if(this.hacked == 10)
|
||||
Log.info("Hax!");
|
||||
this.gm.displayGuiScreen(new GuiCredits(this.hacked == 10));
|
||||
this.hacked = 0;
|
||||
break;
|
||||
// case 4:
|
||||
// this.gm.displayGuiScreen(new GuiLanguage());
|
||||
// break;
|
||||
case 4:
|
||||
this.gm.shutdown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void drawOverlays() {
|
||||
super.drawOverlays();
|
||||
if(this.gm.theWorld == null) {
|
||||
int y = 164;
|
||||
int h = 16;
|
||||
int n = Drawing.getWidth(this.splashLabel.getText());
|
||||
Drawing.drawRectColor(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff);
|
||||
Drawing.drawRectColor(this.gm.fb_x / 2 + n / 2 + 10, y, this.gm.fb_x - (this.gm.fb_x / 2 + n / 2 + 10), h, 0x7f7f00ff);
|
||||
Drawing.drawText(this.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack) - 2, this.gm.fb_y - 18, 0xffffffff);
|
||||
Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
|
||||
}
|
||||
}
|
||||
}
|
30
java/src/game/gui/GuiOptions.java
Normal file
30
java/src/game/gui/GuiOptions.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package game.gui;
|
||||
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.SelectedButton;
|
||||
|
||||
public abstract class GuiOptions extends Gui {
|
||||
private static final GuiOptions[] PAGES = {lastPage = new GuiBinds(), new GuiStyle(), new GuiDisplay(), new GuiSound()};
|
||||
|
||||
private static GuiOptions lastPage;
|
||||
|
||||
public static GuiOptions getPage() {
|
||||
return lastPage;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
lastPage = this;
|
||||
this.shift();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for(GuiOptions gui : PAGES) {
|
||||
this.add(gui == this ? new SelectedButton(240 * x, 24 * y, 240, 24, gui, gui.getTitle()) :
|
||||
new ActButton(240 * x, 24 * y, 240, 24, gui, gui.getTitle()));
|
||||
if(++x == 4) {
|
||||
x = 0;
|
||||
++y;
|
||||
}
|
||||
}
|
||||
this.add(new ActButton(width - 240, 0, 240, 24, GuiMenu.INSTANCE, "Zurück"));
|
||||
}
|
||||
}
|
48
java/src/game/gui/GuiSign.java
Normal file
48
java/src/game/gui/GuiSign.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package game.gui;
|
||||
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.network.NetHandlerPlayClient;
|
||||
import game.packet.CPacketSign;
|
||||
import game.world.BlockPos;
|
||||
|
||||
public class GuiSign extends Gui implements Textbox.Callback {
|
||||
private final BlockPos position;
|
||||
private final Textbox[] lines = new Textbox[4];
|
||||
private final String[] tempLines = new String[this.lines.length];
|
||||
|
||||
|
||||
public void init(int width, int height) {
|
||||
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.add(new ActButton(0, 40 * (this.lines.length + 1), 300, 24, (Gui)null, "Fertig"));
|
||||
this.shift();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Schild bearbeiten";
|
||||
}
|
||||
|
||||
|
||||
public void onGuiClosed() {
|
||||
NetHandlerPlayClient nethandler = this.gm.getNetHandler();
|
||||
if(nethandler != null) {
|
||||
for(int z = 0; z < this.lines.length; z++) {
|
||||
this.tempLines[z] = this.lines[z].getText();
|
||||
}
|
||||
nethandler.addToSendQueue(new CPacketSign(this.position, this.tempLines));
|
||||
}
|
||||
}
|
||||
|
||||
public GuiSign(BlockPos sign, String[] lines) {
|
||||
this.position = sign;
|
||||
System.arraycopy(lines, 0, this.tempLines, 0, this.lines.length);
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND)
|
||||
this.gm.displayGuiScreen(null);
|
||||
}
|
||||
}
|
75
java/src/game/gui/GuiSound.java
Normal file
75
java/src/game/gui/GuiSound.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package game.gui;
|
||||
|
||||
import game.audio.Volume;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
|
||||
public class GuiSound extends GuiOptions {
|
||||
protected GuiSound() {
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
// this.addSelector("mid_visualizer", 30, 80, 440, 24); // "Visualisation"
|
||||
// this.addSelector("mid_opl_bank", 490, 80, 440, 24);
|
||||
// this.addSelector("mid_play_unknown", 30, 120, 440, 24);
|
||||
// this.addSelector("mid_keep_notes", 490, 120, 440, 24);
|
||||
// this.addSelector("mid_dont_fade", 30, 160, 440, 24);
|
||||
// this.addSelector("mid_debug_events", 490, 160, 440, 24);
|
||||
// this.addSelector("mid_velocity_func", 30, 200, 440, 24);
|
||||
// this.addSelector("mid_opl_voices", 490, 200, 440, 24);
|
||||
|
||||
// gui_add_custom(win, 30, 240, 128, 128, gui_render_velocity);
|
||||
|
||||
this.addSelector("snd_device_type", 490, 260, 440, 24);
|
||||
|
||||
// this.addSelector("snd_sample_rate", 30, 380, 440, 24);
|
||||
// this.addSelector("snd_sample_format", 490, 380, 440, 24);
|
||||
|
||||
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) {
|
||||
GuiSound.this.gm.restartSound(false);
|
||||
}
|
||||
}, "Übernehmen und Audio-Thread neu starten"));
|
||||
|
||||
int x = 30;
|
||||
int y = 540;
|
||||
for(Volume volume : Volume.values()) {
|
||||
this.addSelector(volume.getCVarName(), x, y, 440, 24);
|
||||
x = (x == 30) ? 490 : 30;
|
||||
if(x == 30)
|
||||
y += 40;
|
||||
}
|
||||
super.init(width, height);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Audio und Ton";
|
||||
}
|
||||
|
||||
// void gui_fmt_velofunc(gui_t *elem, int value) {
|
||||
// snprintf(elem->text, elem->capacity, "%s %d: %s", elem->format_text, value, (value ? (value == -128 ? "Vollklang [1]" : (value < 0 ? "Log. Gedämpft [nlog(x)]" : "Log.+Minimum [m+nlog(x)]")) : "Linear [x]"));
|
||||
// }
|
||||
|
||||
// int gui_rect(gui_t *elem, int x, int y, int w, int h, uint color) {
|
||||
// gfx_draw_rect(elem->pos_x + x, elem->pos_y + y, w, h, 0, 0, 0xff000000 | color, 0xff000000 | color, 0, 0);
|
||||
// return h;
|
||||
// }
|
||||
//
|
||||
// // uint bank_getlevel(char function, byte velocity, byte volume, char pan);
|
||||
//
|
||||
// void gui_render_velocity(gui_t *elem, int value) {
|
||||
// elem->r_dirty = 1;
|
||||
// if(!value)
|
||||
// gui_rect(elem, 0, 0, elem->size_x, elem->size_y, 0x202020);
|
||||
// else
|
||||
// return;
|
||||
// int y;
|
||||
// for(int x = 0; x < 128; x++) {
|
||||
// y = x; // bank_getlevel(snd.mid_velo, x, 127, 0) / 512;
|
||||
// gui_rect(elem, x, 128 - 1 - y, 1, y, 0x2fbf2f);
|
||||
// }
|
||||
// }
|
||||
}
|
106
java/src/game/gui/GuiStyle.java
Normal file
106
java/src/game/gui/GuiStyle.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package game.gui;
|
||||
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Dropdown;
|
||||
import game.gui.element.SelectedButton;
|
||||
import game.gui.element.Slider;
|
||||
import game.gui.element.Switch;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Toggle;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.gui.element.Textbox.Action;
|
||||
|
||||
public class GuiStyle extends GuiOptions implements Dropdown.Callback<String>, ActButton.Callback, Toggle.Callback, Switch.Callback<String>, Slider.Callback, Textbox.Callback {
|
||||
private static final String[] STYLE_CVARS = {
|
||||
"color_hover",
|
||||
"color_background_t",
|
||||
"color_button_top",
|
||||
"color_textbox_top",
|
||||
"color_border_top",
|
||||
|
||||
"color_press",
|
||||
"color_background_b",
|
||||
"color_button_btm",
|
||||
"color_textbox_btm",
|
||||
"color_border_btm",
|
||||
|
||||
"color_select",
|
||||
"color_label_text",
|
||||
"color_button_text",
|
||||
"color_textbox_text",
|
||||
"color_cursor"
|
||||
};
|
||||
|
||||
protected GuiStyle() {
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
int z;
|
||||
for(z = 0; z < STYLE_CVARS.length; z++) {
|
||||
this.addSelector(STYLE_CVARS[z], 10 + (z % 5) * 190, 100 + z / 5 * 50, 180, 24);
|
||||
}
|
||||
z = 0;
|
||||
for(Style theme : Style.values()) {
|
||||
ActButton.Callback callback = new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiStyle.this.gm.style != theme) {
|
||||
GuiStyle.this.gm.style = theme;
|
||||
GuiStyle.this.gm.setDirty();
|
||||
GuiStyle.this.gm.displayGuiScreen(GuiStyle.this);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.add(theme == this.gm.style ? new SelectedButton(10 + (z % 3) * 320, 360 + (z / 3) * 40, 300, 24, callback, theme.name) :
|
||||
new ActButton(10 + (z % 3) * 320, 360 + (z / 3) * 40, 300, 24, callback, theme.name));
|
||||
z++;
|
||||
}
|
||||
|
||||
String[] values = new String[] {"VALUE 1", "VALUE 2"};
|
||||
this.add(new Dropdown(10, height - 74, 300, 24, false, values, values[1], values[0], this, "DROPDOWN"));
|
||||
this.add(new ActButton(330, height - 74, 300, 24, (ActButton.Callback)this, "BUTTON"));
|
||||
this.add(new Toggle(650, height - 74, 140, 24, false, true, this, "TOGGLE"));
|
||||
this.add(new Toggle(810, height - 74, 140, 24, true, false, this, "TOGGLE"));
|
||||
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 ActButton(200, 100 + 3 * 50, 560, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiStyle.this.gm.style != Style.CUSTOM) {
|
||||
GuiStyle.this.gm.style = Style.CUSTOM;
|
||||
GuiStyle.this.gm.setDirty();
|
||||
}
|
||||
GuiStyle.this.gm.displayGuiScreen(GuiStyle.this);
|
||||
}
|
||||
}, "Übernehmen"));
|
||||
this.add(new ActButton(200, 140 + 3 * 50, 560, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
GuiStyle.this.gm.style = Style.CUSTOM;
|
||||
for(String cvar : STYLE_CVARS) {
|
||||
GuiStyle.this.gm.getVar(cvar).setDefault();
|
||||
}
|
||||
GuiStyle.this.gm.setDirty();
|
||||
GuiStyle.this.gm.displayGuiScreen(GuiStyle.this);
|
||||
}
|
||||
}, "Zurücksetzen"));
|
||||
super.init(width, height);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Benutzeroberfläche";
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
}
|
||||
public void use(Slider elem, int value) {
|
||||
}
|
||||
public void use(Switch<String> elem, String value) {
|
||||
}
|
||||
public void use(Toggle elem, boolean value) {
|
||||
}
|
||||
public void use(ActButton elem, Mode action) {
|
||||
}
|
||||
public void use(Dropdown<String> elem, String value) {
|
||||
}
|
||||
}
|
127
java/src/game/gui/Style.java
Normal file
127
java/src/game/gui/Style.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package game.gui;
|
||||
|
||||
import game.properties.IStringSerializable;
|
||||
import game.util.Displayable;
|
||||
import game.vars.CVarCategory;
|
||||
import game.vars.Variable;
|
||||
import game.vars.Variable.IntType;
|
||||
|
||||
public enum Style implements IStringSerializable, Displayable {
|
||||
DEFAULT("default", "Glänzend (Standard)"), GRAY("gray", "Grau"), BLUE("blue", "Blau"), CUSTOM("custom", "Angepasst");
|
||||
|
||||
public final String id;
|
||||
public final String name;
|
||||
|
||||
private Style(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Variable(type = IntType.COLOR, name = "color_border_top", category = CVarCategory.STYLE, display = "Umrahmung")
|
||||
public int brdr_top;
|
||||
@Variable(type = IntType.COLOR, name = "color_border_btm", category = CVarCategory.STYLE)
|
||||
public int brdr_btm;
|
||||
|
||||
@Variable(type = IntType.COLOR, name = "color_button_top", category = CVarCategory.STYLE, display = "Knopf")
|
||||
public int fill_top;
|
||||
@Variable(type = IntType.COLOR, name = "color_button_btm", category = CVarCategory.STYLE)
|
||||
public int fill_btm;
|
||||
@Variable(type = IntType.COLOR, name = "color_textbox_top", category = CVarCategory.STYLE, display = "Textfeld")
|
||||
public int field_top;
|
||||
@Variable(type = IntType.COLOR, name = "color_textbox_btm", category = CVarCategory.STYLE)
|
||||
public int field_btm;
|
||||
|
||||
@Variable(type = IntType.COLOR, name = "color_label_text", category = CVarCategory.STYLE, display = "Beschriftung")
|
||||
public int text_label;
|
||||
@Variable(type = IntType.COLOR, name = "color_button_text", category = CVarCategory.STYLE, display = "Text Knopf")
|
||||
public int text_base;
|
||||
@Variable(type = IntType.COLOR, name = "color_textbox_text", category = CVarCategory.STYLE, display = "Textfeld Text")
|
||||
public int text_field;
|
||||
|
||||
@Variable(type = IntType.COLOR, name = "color_background_t", category = CVarCategory.STYLE, display = "Hintergrund")
|
||||
public int bg_top;
|
||||
@Variable(type = IntType.COLOR, name = "color_background_b", category = CVarCategory.STYLE)
|
||||
public int bg_btm;
|
||||
|
||||
@Variable(type = IntType.ALPHA, name = "color_press", category = CVarCategory.STYLE, display = "Gedrückt")
|
||||
public int press;
|
||||
@Variable(type = IntType.ALPHA, name = "color_hover", category = CVarCategory.STYLE, display = "Gewählt")
|
||||
public int hover;
|
||||
@Variable(type = IntType.ALPHA, name = "color_select", category = CVarCategory.STYLE, display = "Textauswahl")
|
||||
public int select;
|
||||
@Variable(type = IntType.ALPHA, name = "color_cursor", category = CVarCategory.STYLE, display = "Textmarke")
|
||||
public int cursor;
|
||||
|
||||
static {
|
||||
DEFAULT
|
||||
.border(0xffffff, 0x3f3f3f)
|
||||
.background(0x000000, 0x000000)
|
||||
.base(0x404040, 0x000000, 0xffffff, 0xefefef)
|
||||
.field(0x000000, 0x202020, 0xdfdfdf)
|
||||
.select(0x30ffffff, 0x28ffffff, 0x60dfdfdf, 0xffffffff);
|
||||
|
||||
GRAY
|
||||
.border(0x000000, 0x202020)
|
||||
.background(0x404040, 0x0a0a0a)
|
||||
.base(0x808080, 0x000000, 0xffffff, 0xffffff)
|
||||
.field(0x404040, 0x808080, 0xffffff)
|
||||
.select(0x18ffffff, 0x288080ff, 0x808080ff, 0xff000000);
|
||||
|
||||
BLUE
|
||||
.border(0x0000df, 0x300020)
|
||||
.background(0x20208f, 0x0a0a2d)
|
||||
.base(0x2020a0, 0x000020, 0x8fffaf, 0x00cfaf)
|
||||
.field(0x505090, 0x406060, 0xcfdfff)
|
||||
.select(0x288f00ff, 0x28c080ff, 0x604020ff, 0xff2fff6f);
|
||||
|
||||
CUSTOM
|
||||
.border(0x000000, 0x000000)
|
||||
.background(0x404040, 0x404040)
|
||||
.base(0x808080, 0x808080, 0xffffff, 0xffffff)
|
||||
.field(0x808080, 0x808080, 0xffffff)
|
||||
.select(0x18ffffff, 0x288080ff, 0x808080ff, 0xff000000);
|
||||
}
|
||||
|
||||
private Style border(int top, int btm) {
|
||||
this.brdr_top = top | 0xff000000;
|
||||
this.brdr_btm = btm | 0xff000000;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Style background(int top, int btm) {
|
||||
this.bg_top = top | 0xff000000;
|
||||
this.bg_btm = btm | 0xff000000;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Style base(int top, int btm, int text, int label) {
|
||||
this.fill_top = top | 0xff000000;
|
||||
this.fill_btm = btm | 0xff000000;
|
||||
this.text_base = text | 0xff000000;
|
||||
this.text_label = label | 0xff000000;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Style field(int top, int btm, int text) {
|
||||
this.field_top = top | 0xff000000;
|
||||
this.field_btm = btm | 0xff000000;
|
||||
this.text_field = text | 0xff000000;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Style select(int prs, int hov, int sel, int cur) {
|
||||
this.press = prs;
|
||||
this.hover = hov;
|
||||
this.select = sel;
|
||||
this.cursor = cur;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
44
java/src/game/gui/element/ActButton.java
Normal file
44
java/src/game/gui/element/ActButton.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.Game;
|
||||
import game.gui.Gui;
|
||||
import game.util.Formatter;
|
||||
import game.window.Button;
|
||||
|
||||
public class ActButton extends Element {
|
||||
public static enum Mode {
|
||||
PRIMARY, SECONDARY, TERTIARY;
|
||||
}
|
||||
|
||||
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<ActButton> 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) {
|
||||
super(x, y, w, h, null);
|
||||
this.func = callback;
|
||||
this.setText(text);
|
||||
}
|
||||
|
||||
public ActButton(int x, int y, int w, int h, Gui gui, String text) {
|
||||
this(x, y, w, h, new Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
Game.getGame().displayGuiScreen(gui);
|
||||
}
|
||||
}, 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.formatText();
|
||||
}
|
||||
}
|
126
java/src/game/gui/element/Dropdown.java
Normal file
126
java/src/game/gui/element/Dropdown.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.gui.Font;
|
||||
import game.renderer.Drawing;
|
||||
import game.util.Displayable;
|
||||
import game.util.ExtMath;
|
||||
import game.util.Formatter;
|
||||
import game.util.Util;
|
||||
import game.window.Button;
|
||||
|
||||
public class Dropdown<T> extends Element {
|
||||
public class Handle extends Element {
|
||||
private Handle(boolean up) {
|
||||
super(Dropdown.this.pos_x, Dropdown.this.pos_y + (up ? -(Font.YGLYPH * Dropdown.this.values.length + 2) : Dropdown.this.size_y), Dropdown.this.size_x, Font.YGLYPH * Dropdown.this.values.length + 2, null);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(T value : Dropdown.this.values) {
|
||||
if(sb.length() > 0)
|
||||
sb.append('\n');
|
||||
sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
}
|
||||
this.setText(sb.toString());
|
||||
this.visible = this.r_dirty = false;
|
||||
}
|
||||
|
||||
public void updateText() {
|
||||
this.r_dirty = true;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredX() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredY() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canClick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deselect() {
|
||||
this.visible = false;
|
||||
this.r_dirty = true;
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
Dropdown drop = Dropdown.this;
|
||||
int prev = drop.value;
|
||||
drop.value = (y - (this.pos_y + this.margin_y1)) * drop.values.length / (this.size_y - (this.margin_y1 + this.margin_y2));
|
||||
drop.value = ExtMath.clampi(drop.value, 0, drop.values.length - 1);
|
||||
if(drop.value != prev) {
|
||||
drop.func.use(drop, drop.getValue());
|
||||
drop.formatText();
|
||||
}
|
||||
this.visible = false;
|
||||
this.r_dirty = true;
|
||||
}
|
||||
|
||||
public void drawHover() {
|
||||
int m = ((this.gm.mouse_y - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2)));
|
||||
// if((sys.mouse_y - this.pos_y) < (this.size_y - this.margin_y2))
|
||||
Drawing.drawRectColor(this.pos_x + this.margin_x1,
|
||||
this.pos_y + this.margin_y1 + ExtMath.clampi(m, 0, Dropdown.this.values.length - 1) * ((this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length),
|
||||
this.size_x - (this.margin_x1 + this.margin_x2),
|
||||
(this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length, this.gm.style.hover);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Callback<T> {
|
||||
void use(Dropdown<T> elem, T value);
|
||||
}
|
||||
|
||||
private final Callback<T> 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<T> callback, Formatter<Dropdown<T>> formatter) {
|
||||
super(x, y, w, h, formatter);
|
||||
this.func = callback;
|
||||
this.values = values;
|
||||
this.def = Util.indexOfChecked(this.values, def);
|
||||
this.value = Util.indexOfChecked(this.values, init);
|
||||
this.handle = new Handle(up);
|
||||
this.formatText();
|
||||
}
|
||||
|
||||
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback<T> callback, final String text) {
|
||||
this(x, y, w, h, up, values, def, init, callback, new Formatter<Dropdown<T>>() {
|
||||
public String use(Dropdown<T> elem) {
|
||||
T value = elem.getValue();
|
||||
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return this.values[this.value];
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = Util.indexOfChecked(this.values, value);
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
int prev = this.value;
|
||||
if(ctrl || (btn == Button.MOUSE_MIDDLE)) {
|
||||
if((this.value = this.def) != prev) {
|
||||
this.func.use(this, this.getValue());
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
else if(this.gui != null) {
|
||||
Handle drop = this.handle;
|
||||
drop.visible = true;
|
||||
drop.r_dirty = true;
|
||||
this.gui.selected = drop;
|
||||
}
|
||||
}
|
||||
|
||||
public Handle getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
}
|
278
java/src/game/gui/element/Element.java
Normal file
278
java/src/game/gui/element/Element.java
Normal file
|
@ -0,0 +1,278 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.Game;
|
||||
import game.gui.Font;
|
||||
import game.gui.Gui;
|
||||
import game.gui.element.Dropdown.Handle;
|
||||
import game.renderer.Drawing;
|
||||
import game.renderer.Drawing.Vec2i;
|
||||
import game.util.Formatter;
|
||||
import game.window.Button;
|
||||
import game.window.Keysym;
|
||||
import game.window.WCF;
|
||||
|
||||
public abstract class Element {
|
||||
protected final Game gm = Game.getGame();
|
||||
|
||||
protected Gui gui;
|
||||
protected Formatter format;
|
||||
protected String text = "";
|
||||
|
||||
// String format_text;
|
||||
// Object aux_data;
|
||||
// String[] format_data;
|
||||
// CVar cv_data;
|
||||
|
||||
protected int pos_x;
|
||||
protected int pos_y;
|
||||
protected int size_x;
|
||||
protected int size_y;
|
||||
protected int text_x = 0;
|
||||
protected int text_y = 0;
|
||||
protected int tsize_x = 0;
|
||||
protected int tsize_y = 0;
|
||||
|
||||
protected final int margin_x1 = this.getMargin();
|
||||
protected final int margin_y1 = this.getMargin();
|
||||
protected final int margin_x2 = this.getMargin();
|
||||
protected final int margin_y2 = this.getMargin();
|
||||
|
||||
public boolean visible = true;
|
||||
public boolean enabled = true;
|
||||
public boolean r_dirty = true;
|
||||
|
||||
|
||||
public Element(int x, int y, int w, int h, Formatter formatter) {
|
||||
this.pos_x = x;
|
||||
this.pos_y = y;
|
||||
this.size_x = w;
|
||||
this.size_y = h;
|
||||
this.format = formatter;
|
||||
// gui_update_style(this, 1);
|
||||
// if(type != ElemType.SLIDER) {
|
||||
// this.margin_x1 = this.margin_x2 = (type == ElemType.FIELD || type == ElemType.DROPDOWN_HANDLE) ? this.border : 0;
|
||||
// this.margin_y1 = this.margin_y2 = (type == ElemType.FIELD || type == ElemType.DROPDOWN_HANDLE) ? this.border : 0;
|
||||
// }
|
||||
}
|
||||
|
||||
public void setGui(Gui gui) {
|
||||
if(gui == null)
|
||||
throw new NullPointerException("gui");
|
||||
if(this.gui != null)
|
||||
throw new IllegalStateException("GUI bereits gesetzt");
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
protected int getMargin() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public final int getX() {
|
||||
return this.pos_x;
|
||||
}
|
||||
|
||||
public final int getY() {
|
||||
return this.pos_y;
|
||||
}
|
||||
|
||||
public final int getWidth() {
|
||||
return this.size_x;
|
||||
}
|
||||
|
||||
public final int getHeight() {
|
||||
return this.size_y;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredX() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredY() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean hasLinebreak() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canHover() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canClick() {
|
||||
return this.canHover();
|
||||
}
|
||||
|
||||
public boolean inside(int x, int y) {
|
||||
return (x >= this.pos_x) && (x < (this.pos_x + this.size_x)) && (y >= this.pos_y) && (y < (this.pos_y + this.size_y));
|
||||
}
|
||||
|
||||
public boolean intersects(Element elem) {
|
||||
return (elem.pos_y + elem.size_y) > this.pos_y && elem.pos_y < (this.pos_y + this.size_y) && (elem.pos_x + elem.size_x) > this.pos_x && elem.pos_x < (this.pos_x + this.size_x);
|
||||
}
|
||||
|
||||
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.hasLinebreak() ? (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;
|
||||
// if(this.type != ElemType.FIELD) {
|
||||
if(this.isTextCenteredX())
|
||||
this.text_x = (this.size_x - this.tsize_x) / 2;
|
||||
if(this.isTextCenteredY())
|
||||
this.text_y = (this.size_y - this.tsize_y - Font.YGLYPH) / 2;
|
||||
// }
|
||||
// logd("DBG", "s = %d %d; o = %d %d", this.tsize_x, this.tsize_y, this.text_x, this.text_y);
|
||||
// gui_update_dropdown();
|
||||
if(this.gui != null && this.gui.selected instanceof Handle && this.gui.selected.visible)
|
||||
this.gui.selected.r_dirty = true;
|
||||
this.r_dirty = true;
|
||||
}
|
||||
|
||||
public void setText(String str) {
|
||||
this.text = str;
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
protected void formatText() {
|
||||
if(this.format != null) {
|
||||
this.text = this.format.use(this);
|
||||
this.updateText();
|
||||
}
|
||||
}
|
||||
|
||||
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
|
||||
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
|
||||
}
|
||||
|
||||
public void mouserel() {
|
||||
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
public void character(char code) {
|
||||
|
||||
}
|
||||
|
||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||
|
||||
}
|
||||
|
||||
public void select() {
|
||||
|
||||
}
|
||||
|
||||
public void deselect() {
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void setSelected() {
|
||||
if(this.gui != null)
|
||||
this.gui.select(this);
|
||||
}
|
||||
|
||||
public void setDeselected() {
|
||||
if(this.gui != null && this.gui.selected == this)
|
||||
this.gui.deselect();
|
||||
}
|
||||
|
||||
public void shift(int shift_x, int shift_y) {
|
||||
this.pos_x += shift_x;
|
||||
this.pos_y += shift_y;
|
||||
}
|
||||
|
||||
public void reformat() {
|
||||
if(this.format != null) {
|
||||
// boolean flag = this.r_dirty;
|
||||
this.formatText();
|
||||
// if(!flag && !this.visible)
|
||||
// this.r_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_top, this.gm.style.fill_btm, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
// Drawing.drawGradient2GradBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_top, this.gm.style.fill_btm, 0xff000000,
|
||||
// this.gm.style.brdr_top, Drawing.mixColor(this.gm.style.brdr_top, this.gm.style.brdr_btm), Drawing.mixColor(this.gm.style.brdr_top, this.gm.style.brdr_btm), this.gm.style.brdr_btm);
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_base);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
// if(this.r_dirty) {
|
||||
if(this.visible) {
|
||||
// WCF.glScissor(this.pos_x, (this.gm.fb_y - (this.pos_y + this.size_y)) < 0 ? 0 : (this.gm.fb_y - (this.pos_y + this.size_y)), this.size_x, this.size_y);
|
||||
// WCF.glEnable(WCF.GL_SCISSOR_TEST);
|
||||
// WCF.glClear(WCF.GL_COLOR_BUFFER_BIT);
|
||||
// WCF.glDisable(WCF.GL_SCISSOR_TEST);
|
||||
this.drawBackground();
|
||||
// if(this.selected == this && this.type == ElemType.DROPDOWN_HANDLE)
|
||||
// continue;
|
||||
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);
|
||||
// if(elem.type == ElemType.FIELD) {
|
||||
WCF.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);
|
||||
WCF.glEnable(WCF.GL_SCISSOR_TEST);
|
||||
// }
|
||||
// if(this.type == ElemType.CUSTOM)
|
||||
// this.func(this, 1);
|
||||
// else
|
||||
this.drawForeground(x1, y1, x2, y2);
|
||||
// logd("DBG", "%d @ %d %d -> %d %d", elem.id, x1, y1, elem.pos_x + x2, elem.pos_y + y2);
|
||||
// if(elem.type == ElemType.FIELD) {
|
||||
WCF.glDisable(WCF.GL_SCISSOR_TEST);
|
||||
// glScissor(0, 0, sys.fb_x, sys.fb_y);
|
||||
// }
|
||||
}
|
||||
// else {
|
||||
// WCF.glScissor(this.pos_x, (this.gm.fb_y - (this.pos_y + this.size_y)) < 0 ? 0 : (this.gm.fb_y - (this.pos_y + this.size_y)), this.size_x, this.size_y);
|
||||
// // logd("DBG", "%d @ %d %d -> %d %d", elem.id, elem.pos_x, elem.pos_y, elem.pos_x + elem.size_x, elem.pos_y + elem.size_y);
|
||||
// WCF.glEnable(WCF.GL_SCISSOR_TEST);
|
||||
//// if(this.type == ElemType.CUSTOM)
|
||||
//// this.func(this, 0);
|
||||
//// else
|
||||
// WCF.glClear(WCF.GL_COLOR_BUFFER_BIT);
|
||||
// WCF.glDisable(WCF.GL_SCISSOR_TEST);
|
||||
// this.r_dirty = false;
|
||||
// }
|
||||
// this.r_dirty = this.visible;
|
||||
// logd("DBG", "@ r");
|
||||
// if(this.visible) {
|
||||
// }
|
||||
// else {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void drawOverlay() {
|
||||
|
||||
}
|
||||
|
||||
public void drawHover() {
|
||||
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.hover);
|
||||
}
|
||||
|
||||
public void drawPress() {
|
||||
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.press);
|
||||
}
|
||||
}
|
46
java/src/game/gui/element/Fill.java
Normal file
46
java/src/game/gui/element/Fill.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package game.gui.element;
|
||||
|
||||
public class Fill extends Element {
|
||||
private final boolean left;
|
||||
private final boolean top;
|
||||
|
||||
public Fill(int x, int y, int w, int h, String text, boolean top, boolean left) {
|
||||
super(x, y, w, h, null);
|
||||
this.top = top;
|
||||
this.left = left;
|
||||
this.setText(text);
|
||||
}
|
||||
|
||||
public Fill(int x, int y, int w, int h, String text, boolean left) {
|
||||
this(x, y, w, h, text, false, left);
|
||||
}
|
||||
|
||||
public Fill(int x, int y, int w, int h, String text) {
|
||||
this(x, y, w, h, text, false, false);
|
||||
}
|
||||
|
||||
public Fill(int x, int y, int w, int h, boolean top, boolean left) {
|
||||
this(x, y, w, h, "", top, left);
|
||||
}
|
||||
|
||||
public Fill(int x, int y, int w, int h, boolean left) {
|
||||
this(x, y, w, h, "", false, left);
|
||||
}
|
||||
|
||||
public Fill(int x, int y, int w, int h) {
|
||||
this(x, y, w, h, "", false, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean canHover() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredX() {
|
||||
return !this.left;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredY() {
|
||||
return !this.top;
|
||||
}
|
||||
}
|
407
java/src/game/gui/element/GuiList.java
Executable file
407
java/src/game/gui/element/GuiList.java
Executable file
|
@ -0,0 +1,407 @@
|
|||
package game.gui.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.gui.Gui;
|
||||
import game.renderer.DefaultVertexFormats;
|
||||
import game.renderer.Drawing;
|
||||
import game.renderer.GlState;
|
||||
import game.renderer.Tessellator;
|
||||
import game.util.ExtMath;
|
||||
import game.window.Button;
|
||||
import game.renderer.RenderBuffer;
|
||||
|
||||
public abstract class GuiList<T extends ListEntry> extends Gui
|
||||
{
|
||||
protected final List<T> elements = Lists.newArrayList();
|
||||
|
||||
protected int width;
|
||||
protected int height;
|
||||
|
||||
protected int top;
|
||||
protected int bottom;
|
||||
protected int right;
|
||||
protected int left;
|
||||
protected int mouseX;
|
||||
protected int mouseY;
|
||||
protected int initialClickY = -2;
|
||||
protected float scrollMultiplier;
|
||||
protected float amountScrolled;
|
||||
protected int selectedElement = -1;
|
||||
protected long lastClicked;
|
||||
|
||||
public abstract int getListWidth(); // 220
|
||||
|
||||
public abstract int getSlotHeight();
|
||||
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setDimensions(int widthIn, int heightIn, int topIn, int bottomIn)
|
||||
{
|
||||
this.width = widthIn;
|
||||
this.height = heightIn;
|
||||
this.top = topIn;
|
||||
this.bottom = bottomIn;
|
||||
this.left = 0;
|
||||
this.right = widthIn;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
|
||||
this.selectedElement = -1;
|
||||
}
|
||||
|
||||
public void setSlotXBoundsFromLeft(int leftIn)
|
||||
{
|
||||
this.left = leftIn;
|
||||
this.right = leftIn + this.width;
|
||||
}
|
||||
|
||||
public final T getListEntry(int index) {
|
||||
return this.elements.get(index);
|
||||
}
|
||||
|
||||
public final T getSelected() {
|
||||
return this.selectedElement < 0 ? null : this.elements.get(this.selectedElement);
|
||||
}
|
||||
|
||||
public final int getSize() {
|
||||
return this.elements.size();
|
||||
}
|
||||
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return this.getSize() * this.getSlotHeight();
|
||||
}
|
||||
|
||||
public int getSlotIndexFromScreenCoords(int x, int y)
|
||||
{
|
||||
int i = this.left + this.width / 2 - this.getListWidth() / 2;
|
||||
int j = this.left + this.width / 2 + this.getListWidth() / 2;
|
||||
int k = y - this.top + (int)this.amountScrolled - 4;
|
||||
int l = k / this.getSlotHeight();
|
||||
return this.isInList(x, y) && x >= i && x <= j && l >= 0 && k >= 0 && l < this.getSize() ? l : -1;
|
||||
}
|
||||
|
||||
protected boolean isInList(int x, int y)
|
||||
{
|
||||
return x >= this.getScrollBarX() + 6; // x < this.getScrollBarX();
|
||||
}
|
||||
|
||||
protected final boolean isSelected(int slotIndex)
|
||||
{
|
||||
return slotIndex == this.selectedElement;
|
||||
}
|
||||
|
||||
protected void bindAmountScrolled()
|
||||
{
|
||||
this.amountScrolled = ExtMath.clampf(this.amountScrolled, 0.0F, (float)this.getMaxScroll());
|
||||
}
|
||||
|
||||
public int getMaxScroll()
|
||||
{
|
||||
return Math.max(0, this.getContentHeight() - (this.bottom - this.top - 4));
|
||||
}
|
||||
|
||||
public int getAmountScrolled()
|
||||
{
|
||||
return (int)this.amountScrolled;
|
||||
}
|
||||
|
||||
public boolean isMouseYWithinSlotBounds(int p_148141_1_)
|
||||
{
|
||||
return p_148141_1_ >= this.top && p_148141_1_ <= this.bottom && this.mouseX >= this.left && this.mouseX <= this.right;
|
||||
}
|
||||
|
||||
public void scrollBy(int amount)
|
||||
{
|
||||
this.amountScrolled += (float)amount;
|
||||
this.bindAmountScrolled();
|
||||
this.initialClickY = -2;
|
||||
}
|
||||
|
||||
// public void actionPerformed(Button button)
|
||||
// {
|
||||
// if (button.enabled)
|
||||
// {
|
||||
// if (button.id == this.scrollUpButtonID)
|
||||
// {
|
||||
// this.amountScrolled -= (float)(this.slotHeight * 2 / 3);
|
||||
// this.initialClickY = -2;
|
||||
// this.bindAmountScrolled();
|
||||
// }
|
||||
// else if (button.id == this.scrollDownButtonID)
|
||||
// {
|
||||
// this.amountScrolled += (float)(this.slotHeight * 2 / 3);
|
||||
// this.initialClickY = -2;
|
||||
// this.bindAmountScrolled();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void draw()
|
||||
{
|
||||
int mouseXIn = this.gm.mouse_x;
|
||||
int mouseYIn = this.gm.mouse_y;
|
||||
this.mouseX = mouseXIn;
|
||||
this.mouseY = mouseYIn;
|
||||
this.drawBackground();
|
||||
int i = this.getScrollBarX();
|
||||
int j = i + 6;
|
||||
this.bindAmountScrolled();
|
||||
GlState.disableLighting();
|
||||
GlState.disableFog();
|
||||
GlState.enableTexture2D();
|
||||
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
||||
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
float f = 32.0F;
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)this.left, (double)this.bottom, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)this.bottom, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)this.top, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
|
||||
worldrenderer.pos((double)this.left, (double)this.top, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
|
||||
int x = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
|
||||
int y = this.top + 4 - (int)this.amountScrolled;
|
||||
|
||||
this.drawSelectionBox(x, y, mouseXIn, mouseYIn);
|
||||
GlState.disableDepth();
|
||||
|
||||
this.overlayBackground(0, this.top, 255, 255);
|
||||
this.overlayBackground(this.bottom, this.height, 255, 255);
|
||||
|
||||
GlState.enableBlend();
|
||||
GlState.tryBlendFuncSeparate(770, 771, 0, 1);
|
||||
GlState.disableAlpha();
|
||||
GlState.shadeModel(7425);
|
||||
GlState.disableTexture2D();
|
||||
|
||||
int i1 = 4;
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)this.left, (double)(this.top + i1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)(this.top + i1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)this.right, (double)(this.bottom - i1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
|
||||
worldrenderer.pos((double)this.left, (double)(this.bottom - i1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
|
||||
Tessellator.draw();
|
||||
|
||||
int j1 = this.getMaxScroll();
|
||||
|
||||
if (j1 > 0)
|
||||
{
|
||||
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
|
||||
k1 = ExtMath.clampi(k1, 32, this.bottom - this.top - 8);
|
||||
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
|
||||
|
||||
if (l1 < this.top)
|
||||
{
|
||||
l1 = this.top;
|
||||
}
|
||||
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
worldrenderer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||
worldrenderer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||
worldrenderer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldrenderer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
|
||||
worldrenderer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
|
||||
worldrenderer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
|
||||
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
|
||||
GlState.enableTexture2D();
|
||||
GlState.shadeModel(7424);
|
||||
GlState.enableAlpha();
|
||||
GlState.disableBlend();
|
||||
|
||||
super.draw();
|
||||
}
|
||||
|
||||
public void handleMouseInput()
|
||||
{
|
||||
if (this.isMouseYWithinSlotBounds(this.mouseY))
|
||||
{
|
||||
// if (Button.MOUSE_LEFT.isDown() && this.getEnabled())
|
||||
// {
|
||||
if (this.initialClickY == -1)
|
||||
{
|
||||
boolean flag1 = true;
|
||||
|
||||
if (this.mouseY >= this.top && this.mouseY <= this.bottom)
|
||||
{
|
||||
int j2 = (this.width - this.getListWidth()) / 2;
|
||||
int k2 = (this.width + this.getListWidth()) / 2;
|
||||
int l2 = this.mouseY - this.top + (int)this.amountScrolled - 4;
|
||||
int i1 = l2 / this.getSlotHeight();
|
||||
|
||||
if (i1 < this.getSize() && this.mouseX >= j2 && this.mouseX <= k2 && i1 >= 0 && l2 >= 0)
|
||||
{
|
||||
}
|
||||
else if (this.mouseX >= j2 && this.mouseX <= k2 && l2 < 0)
|
||||
{
|
||||
flag1 = false;
|
||||
}
|
||||
|
||||
int i3 = this.getScrollBarX();
|
||||
int j1 = i3 + 6;
|
||||
|
||||
if (this.mouseX >= i3 && this.mouseX <= j1)
|
||||
{
|
||||
this.scrollMultiplier = -1.0F;
|
||||
int k1 = this.getMaxScroll();
|
||||
|
||||
if (k1 < 1)
|
||||
{
|
||||
k1 = 1;
|
||||
}
|
||||
|
||||
int l1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
|
||||
l1 = ExtMath.clampi(l1, 32, this.bottom - this.top - 8);
|
||||
this.scrollMultiplier /= (float)(this.bottom - this.top - l1) / (float)k1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollMultiplier = 1.0F;
|
||||
}
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
this.initialClickY = this.mouseY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialClickY = -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialClickY = -2;
|
||||
}
|
||||
}
|
||||
else if (this.initialClickY >= 0)
|
||||
{
|
||||
this.amountScrolled -= (float)(this.mouseY - this.initialClickY) * this.scrollMultiplier;
|
||||
this.initialClickY = this.mouseY;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.initialClickY = -1;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawSelectionBox(int x, int y, int mouseXIn, int mouseYIn)
|
||||
{
|
||||
int size = this.getSize();
|
||||
RenderBuffer rb = Tessellator.getBuffer();
|
||||
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
int y1 = y + z * this.getSlotHeight();
|
||||
int h = this.getSlotHeight() - 4;
|
||||
|
||||
if (this.isSelected(z))
|
||||
{
|
||||
int x1 = this.left + (this.width / 2 - this.getListWidth() / 2);
|
||||
int x2 = this.left + this.width / 2 + this.getListWidth() / 2;
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlState.disableTexture2D();
|
||||
rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
rb.pos((double)x1, (double)(y1 + h + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||
rb.pos((double)x2, (double)(y1 + h + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||
rb.pos((double)x2, (double)(y1 - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||
rb.pos((double)x1, (double)(y1 - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||
rb.pos((double)(x1 + 1), (double)(y1 + h + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
rb.pos((double)(x2 - 1), (double)(y1 + h + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||
rb.pos((double)(x2 - 1), (double)(y1 - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
rb.pos((double)(x1 + 1), (double)(y1 - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||
Tessellator.draw();
|
||||
GlState.enableTexture2D();
|
||||
}
|
||||
|
||||
boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z;
|
||||
this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover);
|
||||
if(hover)
|
||||
Drawing.drawRectColor(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), this.gm.style.hover);
|
||||
}
|
||||
}
|
||||
|
||||
protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha)
|
||||
{
|
||||
RenderBuffer rb = Tessellator.getBuffer();
|
||||
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
float f = 32.0F;
|
||||
rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
rb.pos((double)this.left, (double)endY, 0.0D).tex(0.0D, (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
|
||||
rb.pos((double)(this.left + this.width), (double)endY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
|
||||
rb.pos((double)(this.left + this.width), (double)startY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
|
||||
rb.pos((double)this.left, (double)startY, 0.0D).tex(0.0D, (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift)
|
||||
{
|
||||
super.mouse(btn, x, y, ctrl, shift);
|
||||
if (this.isMouseYWithinSlotBounds(y))
|
||||
{
|
||||
int i = this.getSlotIndexFromScreenCoords(x, y);
|
||||
|
||||
if (i >= 0)
|
||||
{
|
||||
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
|
||||
int k = this.top + 4 - this.getAmountScrolled() + i * this.getSlotHeight();
|
||||
int l = x - j;
|
||||
int i1 = y - k;
|
||||
|
||||
boolean flag = i == this.selectedElement && System.currentTimeMillis() - this.lastClicked < (long)this.gm.dclickDelay;
|
||||
this.selectedElement = i;
|
||||
this.lastClicked = System.currentTimeMillis();
|
||||
|
||||
this.getListEntry(i).select(flag, l, i1);
|
||||
}
|
||||
}
|
||||
if(btn == Button.MOUSE_LEFT && this.clicked(x, y) == null)
|
||||
this.handleMouseInput();
|
||||
}
|
||||
|
||||
public void mouserel(Button btn, int x, int y) {
|
||||
super.mouserel(btn, x, y);
|
||||
if(btn == Button.MOUSE_LEFT)
|
||||
this.initialClickY = -1;
|
||||
}
|
||||
|
||||
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
|
||||
super.scroll(scr_x, scr_y, x, y, ctrl, shift);
|
||||
if(scr_y != 0 && this.clicked(x, y) == null)
|
||||
this.amountScrolled -= (float)(ExtMath.clampi(scr_y, -1, 1) * this.getSlotHeight() / 2);
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
super.drag(x, y);
|
||||
if(this.selected == null && Button.MOUSE_LEFT.isDown())
|
||||
this.handleMouseInput();
|
||||
}
|
||||
}
|
17
java/src/game/gui/element/InventoryButton.java
Normal file
17
java/src/game/gui/element/InventoryButton.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
|
||||
public class InventoryButton extends Element {
|
||||
public InventoryButton(int x, int y, int w, int h) {
|
||||
super(x, y, w, h, null);
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
// Drawing.drawRect2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xffafafaf);
|
||||
Drawing.drawRect2GradBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xff000000, 0xffafafaf, 0xff7f7f7f, 0xff7f7f7f, 0xff4f4f4f);
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
}
|
||||
}
|
28
java/src/game/gui/element/Label.java
Normal file
28
java/src/game/gui/element/Label.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
|
||||
public class Label extends Fill {
|
||||
public Label(int x, int y, int w, int h, String text, boolean top, boolean left) {
|
||||
super(x, y, w, h, text, top, left);
|
||||
}
|
||||
|
||||
public Label(int x, int y, int w, int h, String text, boolean left) {
|
||||
super(x, y, w, h, text, left);
|
||||
}
|
||||
|
||||
public Label(int x, int y, int w, int h, String text) {
|
||||
super(x, y, w, h, text);
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label);
|
||||
}
|
||||
|
||||
protected int getMargin() {
|
||||
return 0;
|
||||
}
|
||||
}
|
7
java/src/game/gui/element/ListEntry.java
Normal file
7
java/src/game/gui/element/ListEntry.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package game.gui.element;
|
||||
|
||||
public interface ListEntry
|
||||
{
|
||||
void draw(int x, int y, int mouseX, int mouseY, boolean hovered);
|
||||
void select(boolean dclick, int mx, int my);
|
||||
}
|
18
java/src/game/gui/element/SelectedButton.java
Normal file
18
java/src/game/gui/element/SelectedButton.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.gui.Gui;
|
||||
import game.renderer.Drawing;
|
||||
|
||||
public class SelectedButton extends ActButton {
|
||||
public SelectedButton(int x, int y, int w, int h, Callback callback, String text) {
|
||||
super(x, y, w, h, callback, text);
|
||||
}
|
||||
|
||||
public SelectedButton(int x, int y, int w, int h, Gui gui, String text) {
|
||||
super(x, y, w, h, gui, text);
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
}
|
||||
}
|
165
java/src/game/gui/element/Slider.java
Normal file
165
java/src/game/gui/element/Slider.java
Normal file
|
@ -0,0 +1,165 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
import game.util.ExtMath;
|
||||
import game.util.Formatter;
|
||||
import game.window.Button;
|
||||
|
||||
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 int def;
|
||||
private final int min;
|
||||
private final int max;
|
||||
private final int precision;
|
||||
private final int handle;
|
||||
|
||||
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<Slider> formatter) {
|
||||
super(x, y, w, h, formatter);
|
||||
this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1;
|
||||
this.func = callback;
|
||||
this.precision = prec;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.def = def;
|
||||
this.value = init;
|
||||
this.position = gui_slider_pixel();
|
||||
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) {
|
||||
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
|
||||
public String use(Slider elem) {
|
||||
return String.format("%s: %d", text, elem.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
|
||||
private final String format = unit.isEmpty() ? "%s: %d" : "%s: %d %s";
|
||||
|
||||
public String use(Slider elem) {
|
||||
return String.format(this.format, text, elem.value, unit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final FloatCallback callback, Formatter<Slider> formatter) {
|
||||
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 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) {
|
||||
this(x, y, w, h, prec < 0 ? 0 : prec, min, max, def, init, callback, new Formatter<Slider>() {
|
||||
private final String format = "%s: " + (prec <= 0 ? "%d" : ("%." + prec + "f")) + (unit.isEmpty() ? "" : " %s");
|
||||
|
||||
public String use(Slider elem) {
|
||||
return prec <= 0 ? String.format(this.format, text, prec < 0 ? (int)((float)elem.value / 10.0f) : (elem.value / 1000), unit)
|
||||
: String.format(this.format, text, (float)elem.value / 1000.0f, unit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
|
||||
if(scr_y != 0) {
|
||||
int prev = this.value;
|
||||
this.value += (scr_y < 0 ? -1 : 1) * (ctrl ? (this.precision != 0 ? 1 : 10) : ((this.precision >= 2) ? 10 : (this.precision != 0 ? 100 : 1))) * (shift ? (this.precision != 0 ? 50 : 5) : 1);
|
||||
this.value = ExtMath.clampi(this.value, this.min, this.max);
|
||||
this.position = gui_slider_pixel();
|
||||
if(this.value != prev) {
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
int prev = this.value;
|
||||
if(ctrl || (btn == Button.MOUSE_MIDDLE)) {
|
||||
this.value = this.def;
|
||||
this.position = gui_slider_pixel();
|
||||
if(this.value != prev) {
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.position = x - this.pos_x;
|
||||
this.value = gui_slider_value();
|
||||
this.position = gui_slider_pixel();
|
||||
if(this.value != prev) {
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
x = (x < this.pos_x) ? this.pos_x : ((x >= (this.pos_x + this.size_x)) ? (this.pos_x - 1 + this.size_x) : x);
|
||||
int prev = this.value;
|
||||
this.position = x - this.pos_x;
|
||||
this.value = gui_slider_value();
|
||||
this.value = ExtMath.clampi(this.value, this.min, this.max);
|
||||
this.position = gui_slider_pixel();
|
||||
if(this.value != prev) {
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
|
||||
public void reformat() {
|
||||
this.position = gui_slider_pixel();
|
||||
if(this.visible)
|
||||
this.r_dirty = true;
|
||||
super.reformat();
|
||||
}
|
||||
|
||||
private int gui_slider_value() {
|
||||
int r = this.min + (int)(((float)(int)(this.position - (this.handle / 2))) * ((float)(int)(this.max - this.min)) / ((float)(int)(this.size_x + 1 - this.handle)));
|
||||
return ExtMath.clampi(r, this.min, this.max);
|
||||
}
|
||||
|
||||
private int gui_slider_pixel() {
|
||||
int r = ((int)(float)(((float)(int)(this.value - this.min)) * ((float)(int)(this.size_x + 1 - this.handle)) / ((float)(int)(this.max - this.min)))) + (this.handle / 2);
|
||||
return ExtMath.clampi(r, this.handle / 2, this.size_x - (this.handle / 2));
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = ExtMath.clampi(value, this.min, this.max);
|
||||
this.position = gui_slider_pixel();
|
||||
this.formatText();
|
||||
}
|
||||
|
||||
public void setFloatValue(float value) {
|
||||
this.setValue((int)(value * 1000.0f));
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
return (float)this.value / 1000.0f;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
Drawing.drawGradient2Border(this.pos_x + this.position - (this.handle / 2), this.pos_y, this.handle, this.size_y, this.gm.style.fill_top, this.gm.style.fill_btm, this.gm.style.brdr_btm, this.gm.style.brdr_top);
|
||||
}
|
||||
}
|
54
java/src/game/gui/element/Switch.java
Normal file
54
java/src/game/gui/element/Switch.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.util.Displayable;
|
||||
import game.util.Formatter;
|
||||
import game.util.Util;
|
||||
import game.window.Button;
|
||||
|
||||
public class Switch<T> extends Element {
|
||||
public static interface Callback<T> {
|
||||
void use(Switch<T> elem, T value);
|
||||
}
|
||||
|
||||
private final Callback<T> 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<T> callback, Formatter<Switch<T>> formatter) {
|
||||
super(x, y, w, h, formatter);
|
||||
this.func = callback;
|
||||
this.values = values;
|
||||
this.def = Util.indexOfChecked(this.values, def);
|
||||
this.value = Util.indexOfChecked(this.values, init);
|
||||
this.formatText();
|
||||
}
|
||||
|
||||
public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback<T> callback, final String text) {
|
||||
this(x, y, w, h, values, def, init, callback, new Formatter<Switch<T>>() {
|
||||
public String use(Switch<T> elem) {
|
||||
T value = elem.getValue();
|
||||
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return this.values[this.value];
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = Util.indexOfChecked(this.values, value);
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
int prev = this.value;
|
||||
this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : (this.value + ((shift || (btn == Button.MOUSE_RIGHT)) ? -1 : 1));
|
||||
this.value = (this.value == this.values.length) ? 0 : ((this.value == -1) ? (this.values.length - 1) : this.value);
|
||||
if(this.value != prev) {
|
||||
this.func.use(this, this.getValue());
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
}
|
488
java/src/game/gui/element/Textbox.java
Normal file
488
java/src/game/gui/element/Textbox.java
Normal file
|
@ -0,0 +1,488 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.gui.Font;
|
||||
import game.renderer.Drawing;
|
||||
import game.renderer.Drawing.Offset;
|
||||
import game.renderer.Drawing.Vec2i;
|
||||
import game.util.CharValidator;
|
||||
import game.util.ExtMath;
|
||||
import game.util.Timing;
|
||||
import game.util.Util;
|
||||
import game.window.Button;
|
||||
import game.window.Keysym;
|
||||
import game.window.WCF;
|
||||
|
||||
public class Textbox extends Element {
|
||||
public static enum Action {
|
||||
FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD;
|
||||
}
|
||||
|
||||
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 Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) {
|
||||
super(x, y, w, h, null);
|
||||
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 void setEditable(boolean editable) {
|
||||
// this.editable = editable;
|
||||
// }
|
||||
|
||||
protected boolean isTextCenteredX() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isTextCenteredY() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean hasLinebreak() {
|
||||
return this.xbreak;
|
||||
}
|
||||
|
||||
public boolean canHover() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setText(String str) {
|
||||
if(this.validator != null)
|
||||
str = this.validator.filter(str);
|
||||
this.text = str.length() > this.capacity ? str.substring(0, this.capacity) : str;
|
||||
this.updateText();
|
||||
this.sel_start = this.sel_end = this.sel_drag = this.text.length();
|
||||
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);
|
||||
}
|
||||
this.tmr_leftmb = Timing.tmr_current;
|
||||
}
|
||||
else if((btn == Button.MOUSE_MIDDLE) && this.func != null) {
|
||||
this.func.use(this, Action.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;
|
||||
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, '?');
|
||||
WCF.setClipboard(str);
|
||||
// this.text[this.sel_end] = end;
|
||||
if(key == Keysym.X)
|
||||
insertText("");
|
||||
}
|
||||
}
|
||||
else if(this.editable && ctrl && key == Keysym.V) {
|
||||
insertText(WCF.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);
|
||||
}
|
||||
}
|
||||
else if(this.editable && (!ctrl) && (key == Keysym.BACKSPACE || key == Keysym.DELETE)) {
|
||||
if(this.sel_start != this.sel_end) {
|
||||
insertText("");
|
||||
}
|
||||
else if(key == Keysym.DELETE && this.sel_start >= 0) {
|
||||
if(this.sel_end < this.text.length()) {
|
||||
this.sel_end += 1;
|
||||
insertText("");
|
||||
}
|
||||
else {
|
||||
this.sel_end = this.sel_start;
|
||||
}
|
||||
}
|
||||
else if(key == Keysym.BACKSPACE && this.sel_start > 0) {
|
||||
this.sel_start -= 1;
|
||||
insertText("");
|
||||
}
|
||||
}
|
||||
else if(!ctrl && (key == Keysym.RIGHT || key == Keysym.LEFT)) {
|
||||
if(key == Keysym.RIGHT && this.sel_start != this.sel_end) {
|
||||
this.sel_start = this.sel_drag = this.sel_end;
|
||||
}
|
||||
else if(key == Keysym.LEFT && this.sel_start != this.sel_end) {
|
||||
this.sel_end = this.sel_drag = this.sel_start;
|
||||
}
|
||||
if(key == Keysym.RIGHT && this.sel_start >= 0) {
|
||||
if(this.sel_end < this.text.length()) {
|
||||
this.sel_start = this.sel_drag = this.sel_end += 1;
|
||||
}
|
||||
else {
|
||||
this.sel_end = this.sel_drag = this.sel_start;
|
||||
}
|
||||
gui_text_update_cur(this.sel_end, true);
|
||||
}
|
||||
else if(key == Keysym.LEFT && this.sel_start >= 0) {
|
||||
if(this.sel_start > 0)
|
||||
this.sel_start -= 1;
|
||||
this.sel_end = this.sel_drag = this.sel_start;
|
||||
gui_text_update_cur(this.sel_end, true);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
else if((!ctrl) && key == Keysym.TAB) {
|
||||
if(this.func != null) {
|
||||
this.func.use(this, shift ? Action.BACKWARD : Action.FORWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void select() {
|
||||
if(this.func != null) {
|
||||
this.func.use(this, Action.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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if((((long)n) * 1000000L) <= this.tmr_scroll)
|
||||
this.tmr_scroll -= ((long)n) * 1000000L;
|
||||
else
|
||||
this.tmr_scroll = 0L;
|
||||
this.tmr_scroll += Timing.tmr_delta;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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();
|
||||
gui_text_update_cur(this.sel_end, true);
|
||||
}
|
||||
|
||||
private void gui_text_select(int x, int y, boolean drag) {
|
||||
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);
|
||||
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);
|
||||
if(!drag) {
|
||||
this.sel_drag = this.sel_start = this.sel_end = offset;
|
||||
}
|
||||
else if(drag && this.sel_drag >= 0 && offset >= this.sel_drag) {
|
||||
this.sel_start = this.sel_drag;
|
||||
this.sel_end = offset;
|
||||
}
|
||||
else if(drag && this.sel_drag >= 0 && offset < this.sel_drag) {
|
||||
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() {
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.field_top, this.gm.style.field_btm, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
}
|
||||
|
||||
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.gm.style.text_field, this.text);
|
||||
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
|
||||
Drawing.txt_draw_range(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.gm.style.select, this.text);
|
||||
}
|
||||
|
||||
public void drawOverlay() {
|
||||
if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && this.gm.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);
|
||||
WCF.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);
|
||||
WCF.glEnable(WCF.GL_SCISSOR_TEST);
|
||||
Drawing.drawRectColor(this.cursorX, this.cursorY, 1, Font.YGLYPH, this.gm.style.cursor);
|
||||
WCF.glDisable(WCF.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;
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
51
java/src/game/gui/element/Toggle.java
Normal file
51
java/src/game/gui/element/Toggle.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
import game.util.Formatter;
|
||||
import game.window.Button;
|
||||
|
||||
public class Toggle extends Element {
|
||||
public static interface Callback {
|
||||
void use(Toggle elem, boolean value);
|
||||
}
|
||||
|
||||
private final Callback func;
|
||||
private final boolean def;
|
||||
|
||||
private boolean value;
|
||||
|
||||
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter<Toggle> formatter) {
|
||||
super(x, y, w, h, formatter);
|
||||
this.func = callback;
|
||||
this.def = def;
|
||||
this.value = init;
|
||||
this.formatText();
|
||||
}
|
||||
|
||||
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, final String text) {
|
||||
this(x, y, w, h, def, init, callback, new Formatter<Toggle>() {
|
||||
public String use(Toggle elem) {
|
||||
return String.format("%s: %s", text, elem.value ? "An" : "Aus");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
boolean prev = this.value;
|
||||
if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) {
|
||||
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
|
||||
// gui_update_style(this, 1);
|
||||
this.r_dirty = true;
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
if(this.value)
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
else
|
||||
super.drawBackground();
|
||||
}
|
||||
}
|
12
java/src/game/gui/element/TransparentBox.java
Normal file
12
java/src/game/gui/element/TransparentBox.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package game.gui.element;
|
||||
|
||||
public class TransparentBox extends Textbox {
|
||||
public TransparentBox(int x, int y, int w, int h, String text) {
|
||||
super(x, y, w, h, text);
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
// Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y,
|
||||
// this.gm.style.field_top & 0x80ffffff, this.gm.style.field_btm & 0x80ffffff, this.gm.style.brdr_top & 0x80ffffff, this.gm.style.brdr_btm & 0x80ffffff);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue