gui and text drawing, gui misc

This commit is contained in:
Sen 2025-03-19 21:54:09 +01:00
parent c906760bd4
commit 4ec8affe85
37 changed files with 799 additions and 646 deletions

View file

@ -735,7 +735,7 @@ public class Game implements IThreadListener {
Drawing.drawTextbox(String.format(TextColor.GREEN + "%d " + TextColor.GRAY + "/ " + TextColor.NEON + "%d", value, max), x, y, 0x3f000000); Drawing.drawTextbox(String.format(TextColor.GREEN + "%d " + TextColor.GRAY + "/ " + TextColor.NEON + "%d", value, max), x, y, 0x3f000000);
// Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000); // Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000);
Drawing.drawRect2GradBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f); Drawing.drawRect2GradBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
Drawing.drawGradient(x + 2 + 246 - w, y + 20 + 2, w, 6, color | 0xff000000, Drawing.mixColor(color | 0xff000000, 0xff000000)); Drawing.drawGradient(x + 2 + 246 - w, y + 20 + 2, w, 6, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000));
return y + 40; return y + 40;
} }
@ -744,7 +744,7 @@ public class Game implements IThreadListener {
// Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000); // Drawing.drawRectColor(x, y + 20, 250, 10, 0xff000000);
// Drawing.drawRectColor(x, y + 20, (int)(250.0f * fill), 10, color | 0xff000000); // Drawing.drawRectColor(x, y + 20, (int)(250.0f * fill), 10, color | 0xff000000);
Drawing.drawRect2GradBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f); Drawing.drawRect2GradBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
Drawing.drawGradient(x + 2, y + 20 + 2, (int)(246.0f * fill), 6, color | 0xff000000, Drawing.mixColor(color | 0xff000000, 0xff000000)); Drawing.drawGradient(x + 2, y + 20 + 2, (int)(246.0f * fill), 6, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000));
return y + 40; return y + 40;
} }
@ -755,10 +755,8 @@ public class Game implements IThreadListener {
this.renderWorldDirections((float)Timing.tick_fraction); this.renderWorldDirections((float)Timing.tick_fraction);
} }
else { else {
Drawing.drawRectColor(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32, Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf);
this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf); Drawing.drawRect(this.fb_x / 2 - 16, this.fb_y / 2 - 1, 32, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf);
Drawing.drawRectColor(this.fb_x / 2 - 16, this.fb_y / 2 - 1, 32, 2,
this.pointed != null && this.pointed.type != ObjectType.MISS ? 0xffffffff : 0xffcfcfcf);
} }
} }
if(this.theWorld != null && this.open == null) { if(this.theWorld != null && this.open == null) {
@ -775,7 +773,7 @@ public class Game implements IThreadListener {
ItemStack itemstack = this.thePlayer != null ? this.thePlayer.inventory.getCurrentItem() : null; ItemStack itemstack = this.thePlayer != null ? this.thePlayer.inventory.getCurrentItem() : null;
String current = itemstack != null ? itemstack.getItem().getHotbarText(this.thePlayer, itemstack) : ""; String current = itemstack != null ? itemstack.getItem().getHotbarText(this.thePlayer, itemstack) : "";
if(!current.isEmpty()) if(!current.isEmpty())
Drawing.drawTextUpward(current, this.fb_x / 2, this.fb_y - 80, 0xffffffff); Drawing.drawTextUpward(current, this.fb_x / 2, this.fb_y - 60, 0xffffffff);
} }
if(this.theWorld != null && !(this.open instanceof GuiConsole)) { if(this.theWorld != null && !(this.open instanceof GuiConsole)) {
int x = this.fb_x / 2; int x = this.fb_x / 2;
@ -793,8 +791,7 @@ public class Game implements IThreadListener {
entity.getMaxHealth() + TextColor.GRAY + "]"; entity.getMaxHealth() + TextColor.GRAY + "]";
Drawing.drawTextboxCentered(s, x, y, 0x3f000000); Drawing.drawTextboxCentered(s, x, y, 0x3f000000);
Drawing.drawRect2GradBorder(x - 200, y + 20, 400, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f); Drawing.drawRect2GradBorder(x - 200, y + 20, 400, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
Drawing.drawGradient(x - 200 + 2, y + 20 + 2, (int)(396.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 6, entity.getColor() | 0xff000000, Drawing.drawGradient(x - 200 + 2, y + 20 + 2, (int)(396.0f * ((float)entity.getHealth() / (float)entity.getMaxHealth())), 6, entity.getColor() | 0xff000000, Util.mixColor(entity.getColor() | 0xff000000, 0xff000000));
Drawing.mixColor(entity.getColor() | 0xff000000, 0xff000000));
// Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000); // Drawing.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000);
// Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | ); // Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | );
y += 40; y += 40;
@ -813,9 +810,9 @@ public class Game implements IThreadListener {
String name = (potion.isBadEffect() ? TextColor.ORANGE : TextColor.ACID) + potion.getDisplay() + PotionHelper.getPotionPotency(effect.getAmplifier()); String name = (potion.isBadEffect() ? TextColor.ORANGE : TextColor.ACID) + potion.getDisplay() + PotionHelper.getPotionPotency(effect.getAmplifier());
String desc = TextColor.NEON + Potion.getDurationString(effect); String desc = TextColor.NEON + Potion.getDurationString(effect);
// Drawing.drawRectColor(x, y, 250, Font.DEFAULT.yglyph + 2, color | 0xff000000); // Drawing.drawRectColor(x, y, 250, Font.DEFAULT.yglyph + 2, color | 0xff000000);
Drawing.drawGradient2GradBorder(x, y, 250, Font.YGLYPH + 4, color | 0xff000000, Drawing.mixColor(color | 0xff000000, 0xff000000), 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f); Drawing.drawGradient2GradBorder(x, y, 250, Font.YGLYPH + 4, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000), 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
Drawing.drawText(name, x + 2 + 2, y + 2, 0xffffffff); Drawing.drawText(name, x + 4, y + 2, 0xffffffff);
Drawing.drawTextRight(desc, x + 250 - 2, y + 2, 0xffffffff); Drawing.drawTextRight(desc, x + 250 - 4, y + 2, 0xffffffff);
y += 24; y += 24;
} }
} }
@ -950,11 +947,7 @@ public class Game implements IThreadListener {
this.renderStats(); this.renderStats();
} }
else { else {
String str = String.format("%s%.2f", framecode(), Timing.framerate); Drawing.drawText(String.format("%s%.2f", framecode(), Timing.framerate), 0, 0, 0xffffffff);
Drawing.txt_draw(0, 0,
0, 0,
this.fb_x, this.fb_y,
0xffffffff, str);
} }
} }
GlState.enableBlend(); GlState.enableBlend();
@ -994,10 +987,7 @@ public class Game implements IThreadListener {
// if(str) // if(str)
// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str); // (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str);
// gui_render_text(elem, 0, 0, sys.style.text_label, sys.work_buf); // gui_render_text(elem, 0, 0, sys.style.text_label, sys.work_buf);
Drawing.txt_draw(0, 0, Drawing.drawText(draw, 0, 0, 0xffffffff);
0, 0,
this.fb_x, this.fb_y,
0xffffffff, draw);
str = this.getRight(false); str = this.getRight(false);
// str = jstr ? (*jsys.env)->GetStringUTFChars(jsys.env, jstr, NULL) : NULL; // str = jstr ? (*jsys.env)->GetStringUTFChars(jsys.env, jstr, NULL) : NULL;
@ -1008,8 +998,7 @@ public class Game implements IThreadListener {
sb.append('\n'); sb.append('\n');
sb.append(perf.getName()); sb.append(perf.getName());
} }
Drawing.txt_draw(x1 + 0, y1, x1 + 0, y1, x1 + 120, y2, Drawing.drawText(sb.toString(), x1 + 0, y1, 0xffffffff);
this.style.text_label, sb.toString());
// pos = 0; // pos = 0;
sb.setLength(0); sb.setLength(0);
for(PerfSection perf : PerfSection.values()) { for(PerfSection perf : PerfSection.values()) {
@ -1017,8 +1006,7 @@ public class Game implements IThreadListener {
sb.append('\n'); sb.append('\n');
sb.append(String.format("%.3f ms", (float)perf.getLast() / 1000.0f)); sb.append(String.format("%.3f ms", (float)perf.getLast() / 1000.0f));
} }
Drawing.txt_draw(x1 + 120, y1, x1 + 120, y1, x1 + 240, y2, Drawing.drawText(sb.toString(), x1 + 120, y1, 0xffffffff);
this.style.text_label, sb.toString());
// pos = 0; // pos = 0;
sb.setLength(0); sb.setLength(0);
long total = PerfSection.getTotal(true); long total = PerfSection.getTotal(true);
@ -1027,12 +1015,10 @@ public class Game implements IThreadListener {
sb.append('\n'); sb.append('\n');
sb.append(String.format("%.2f %%", ((float)perf.getLast() / (float)total) * 100.0f)); sb.append(String.format("%.2f %%", ((float)perf.getLast() / (float)total) * 100.0f));
} }
Drawing.txt_draw(x1 + 240, y1, x1 + 240, y1, x1 + 320, y2, Drawing.drawText(sb.toString(), x1 + 240, y1, 0xffffffff);
this.style.text_label, sb.toString());
if(str != null) { if(str != null) {
y1 = Font.YGLYPH * 10; y1 = Font.YGLYPH * 10;
Drawing.txt_draw(x1, y1, x1, y1, x1 + 320, y1 + Font.YGLYPH * 12, Drawing.drawText(str, x1, y1, 0xffffffff);
this.style.text_label, str);
// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str); // (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str);
} }
} }
@ -2992,7 +2978,7 @@ public class Game implements IThreadListener {
int y = 10 + by * Font.YGLYPH; int y = 10 + by * Font.YGLYPH;
Drawing.drawGradient(x, y, 300, Font.YGLYPH, 0x7f404040, 0x7f000000); Drawing.drawGradient(x, y, 300, Font.YGLYPH, 0x7f404040, 0x7f000000);
Drawing.drawText(elem.getKey(), x + 4, y, 0xffffffff); Drawing.drawText(elem.getKey(), x + 4, y, 0xffffffff);
Drawing.drawTextRight(formatPing(elem.getValue()), x + 299, y, 0xffffffff); Drawing.drawTextRight(formatPing(elem.getValue()), x + 300 - 4, y, 0xffffffff);
if(++bx >= w) { if(++bx >= w) {
bx = 0; bx = 0;
++by; ++by;

View file

@ -2,6 +2,8 @@ package game.color;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import game.util.Util;
public enum TextColor { public enum TextColor {
NULL(0x00), NULL(0x00),
RESET(0x01), RESET(0x01),
@ -48,13 +50,15 @@ public enum TextColor {
private static final Pattern STRIP_PATTERN = Pattern.compile("[\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000b\u000c\r\u000e\u000f" private static final Pattern STRIP_PATTERN = Pattern.compile("[\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000b\u000c\r\u000e\u000f"
+ "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f]"); + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f]");
private static final int[] COLORS = new int[32]; private static final int[] COLORS = new int[32];
private static final int[] SHADOW = new int[32];
private final String format; private final String format;
public final char code; public final char code;
public final int color; public final int color;
public final int shadow;
public static String stripCodes(String text) { public static String stripCodes(String text) {
return text == null ? null : STRIP_PATTERN.matcher(text).replaceAll(""); return text == null ? null : STRIP_PATTERN.matcher(text).replaceAll("");
} }
@ -62,6 +66,10 @@ public enum TextColor {
public static int getColor(char code) { public static int getColor(char code) {
return code < COLORS.length ? COLORS[code] : 0x000000; return code < COLORS.length ? COLORS[code] : 0x000000;
} }
public static int getShadow(char code) {
return code < SHADOW.length ? SHADOW[code] : 0x000000;
}
private TextColor(int code) { private TextColor(int code) {
this(code, 0x000000); this(code, 0x000000);
@ -70,6 +78,7 @@ public enum TextColor {
private TextColor(int code, int color) { private TextColor(int code, int color) {
this.format = Character.toString(this.code = (char)code); this.format = Character.toString(this.code = (char)code);
this.color = color; this.color = color;
this.shadow = Util.mixColor(Util.mixColor(this.color, 0x000000), 0x000000);
} }
public String toString() { public String toString() {
@ -78,8 +87,10 @@ public enum TextColor {
static { static {
for(TextColor color : values()) { for(TextColor color : values()) {
if(color.code < COLORS.length) if(color.code < COLORS.length) {
COLORS[color.code] = color.color; COLORS[color.code] = color.color;
SHADOW[color.code] = color.shadow;
}
} }
} }
} }

View file

@ -0,0 +1,7 @@
package game.command;
public interface ArgCombiner<T> {
Object combine(T[] values);
Class<?> getTypeClass();
Class<T> getInputClass();
}

View file

@ -86,6 +86,7 @@ public abstract class ArgumentParser {
public abstract Object parse(ScriptEnvironment env, String input); public abstract Object parse(ScriptEnvironment env, String input);
public abstract Object getDefault(ScriptEnvironment env); public abstract Object getDefault(ScriptEnvironment env);
public abstract String[] getCompletions(ScriptEnvironment env); public abstract String[] getCompletions(ScriptEnvironment env);
public abstract Class<?> getTypeClass();
public final String getName() { public final String getName() {
return this.name; return this.name;

View file

@ -1,7 +1,11 @@
package game.command; package game.command;
public class BooleanParser extends EnumParser { public class BooleanParser extends EnumParser<Boolean> {
public BooleanParser(String name, Boolean def) { public BooleanParser(String name, Boolean def) {
super(name, def, true, false); super(name, Boolean.class, def, true, false);
}
public Class<?> getTypeClass() {
return this.hasDefault() ? boolean.class : Boolean.class;
} }
} }

View file

@ -1,5 +1,6 @@
package game.command; package game.command;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -11,12 +12,14 @@ public class CachedExecutable {
private final String name; private final String name;
private final Map<String, Parameter> parameters; private final Map<String, Parameter> parameters;
private final List<Parameter> positionals; private final List<Parameter> positionals;
private final Method method;
protected CachedExecutable(Executable executable, Map<String, Parameter> parameters, List<Parameter> positionals) { protected CachedExecutable(Executable executable, Map<String, Parameter> parameters, List<Parameter> positionals, Method method) {
this.executable = executable; this.executable = executable;
this.parameters = parameters; this.parameters = parameters;
this.positionals = positionals; this.positionals = positionals;
this.name = executable.getName(); this.name = executable.getName();
this.method = method;
} }
public static CachedExecutable cacheExecutable(Executable executable) { public static CachedExecutable cacheExecutable(Executable executable) {
@ -39,13 +42,39 @@ public class CachedExecutable {
throw new NullPointerException("positions[" + z + "]"); throw new NullPointerException("positions[" + z + "]");
positionals.add(positions[z]); positionals.add(positions[z]);
} }
return new CachedExecutable(executable, parameters, positionals); List<Class<?>> classes = Lists.newArrayList(ScriptEnvironment.class, ScriptExecutor.class);
for(Parameter param : executable.getParamList()) {
ArgCombiner<?> combiner = param.getCombiner();
if(combiner != null) {
classes.add(combiner.getTypeClass());
continue;
}
if(param.getParsers().isEmpty()) {
classes.add(boolean.class);
continue;
}
for(ArgumentParser parser : param.getParsers()) {
classes.add(parser.getTypeClass());
}
}
Method method;
try {
method = executable.getClass().getDeclaredMethod("exec", classes.toArray(new Class<?>[classes.size()]));
}
catch(NoSuchMethodException e) {
throw new RuntimeException(e);
}
return new CachedExecutable(executable, parameters, positionals, method);
} }
public Executable getExecutable() { public Executable getExecutable() {
return this.executable; return this.executable;
} }
public Method getMethod() {
return this.method;
}
public Map<String, Parameter> getParameters() { public Map<String, Parameter> getParameters() {
return this.parameters; return this.parameters;
} }

View file

@ -11,4 +11,8 @@ public abstract class DefaultingParser extends CompletingParser {
public Object getDefault(ScriptEnvironment env) { public Object getDefault(ScriptEnvironment env) {
return this.def; return this.def;
} }
protected final boolean hasDefault() {
return this.def != null;
}
} }

View file

@ -40,4 +40,8 @@ public class DimensionParser extends CompletingParser {
public String[] getCompletions(ScriptEnvironment env) { public String[] getCompletions(ScriptEnvironment env) {
return UniverseRegistry.getWorldNames().toArray(new String[UniverseRegistry.getWorldNames().size()]); return UniverseRegistry.getWorldNames().toArray(new String[UniverseRegistry.getWorldNames().size()]);
} }
public Class<?> getTypeClass() {
return Dimension.class;
}
} }

View file

@ -62,4 +62,8 @@ public class DoubleParser extends DefaultingParser {
} }
return (Double)super.getDefault(env); return (Double)super.getDefault(env);
} }
public Class<?> getTypeClass() {
return this.hasDefault() ? double.class : Double.class;
}
} }

View file

@ -4,9 +4,10 @@ import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
public class EnumParser extends DefaultingParser { public class EnumParser<T> extends DefaultingParser {
private final Map<String, Object> lookup = Maps.newHashMap(); private final Class<T> clazz;
private final Object[] selections; private final Map<String, T> lookup = Maps.newHashMap();
private final T[] selections;
private static <T> String joinArgs(T[] iter) { private static <T> String joinArgs(T[] iter) {
StringBuilder sb = new StringBuilder("'"); StringBuilder sb = new StringBuilder("'");
@ -18,16 +19,17 @@ public class EnumParser extends DefaultingParser {
return sb.append("'").toString(); return sb.append("'").toString();
} }
public EnumParser(String name, Object def, Object ... selections) { public EnumParser(String name, Class<T> clazz, T def, T ... selections) {
super(name, def, selections); super(name, def, selections);
this.clazz = clazz;
this.selections = selections; this.selections = selections;
for(Object o : selections) { for(T o : selections) {
this.lookup.put(o.toString().toLowerCase(), o); this.lookup.put(o.toString().toLowerCase(), o);
} }
} }
public Object parse(ScriptEnvironment env, String input) { public T parse(ScriptEnvironment env, String input) {
Object value = this.lookup.get(input.toLowerCase()); T value = this.lookup.get(input.toLowerCase());
if(value != null) if(value != null)
return value; return value;
int id = -1; int id = -1;
@ -41,4 +43,8 @@ public class EnumParser extends DefaultingParser {
joinArgs(this.selections)); joinArgs(this.selections));
return this.selections[id]; return this.selections[id];
} }
public Class<?> getTypeClass() {
return this.clazz;
}
} }

View file

@ -1,9 +1,11 @@
package game.command; package game.command;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface Executable { public interface Executable {
Object exec(ScriptEnvironment env, ScriptArgs args); // Object exec(ScriptEnvironment env, ScriptArgs args);
Map<String, Parameter> getParameters(); Map<String, Parameter> getParameters();
List<Parameter> getParamList();
String getName(); String getName();
} }

View file

@ -32,4 +32,8 @@ public class IntParser extends DefaultingParser {
throw new ScriptException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value); throw new ScriptException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value);
return value; return value;
} }
public Class<?> getTypeClass() {
return this.hasDefault() ? int.class : Integer.class;
}
} }

View file

@ -30,4 +30,8 @@ public class LongParser extends DefaultingParser {
throw new ScriptException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value); throw new ScriptException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value);
return value; return value;
} }
public Class<?> getTypeClass() {
return this.hasDefault() ? long.class : Long.class;
}
} }

View file

@ -8,13 +8,15 @@ public class Parameter {
private final boolean required; private final boolean required;
private final int position; private final int position;
private final List<ArgumentParser> parsers; private final List<ArgumentParser> parsers;
private final ArgCombiner<?> combiner;
public Parameter(String name, char shortName, int position, boolean required, List<ArgumentParser> parsers) { public Parameter(String name, char shortName, int position, boolean required, List<ArgumentParser> parsers, ArgCombiner<?> combiner) {
this.name = name; this.name = name;
this.shortName = shortName; this.shortName = shortName;
this.position = position; this.position = position;
this.required = required; this.required = required;
this.parsers = parsers; this.parsers = parsers;
this.combiner = combiner;
} }
public boolean isPositional() { public boolean isPositional() {
@ -29,6 +31,10 @@ public class Parameter {
return this.parsers; return this.parsers;
} }
public ArgCombiner<?> getCombiner() {
return this.combiner;
}
public boolean isRequired() { public boolean isRequired() {
return this.required; return this.required;
} }

View file

@ -8,19 +8,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import game.block.Block;
import game.entity.Entity;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.item.Item;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.world.BlockPos;
import game.world.State;
import game.world.Vec3;
import game.world.WorldPos;
import game.world.WorldServer;
public class ScriptArgs { public class ScriptArgs {
private final String command; private final String command;
private final Map<String, ScriptArg> arguments; private final Map<String, ScriptArg> arguments;
@ -126,6 +113,9 @@ public class ScriptArgs {
throw new ScriptException("Argument '%s' muss angegeben werden", param.getName()); throw new ScriptException("Argument '%s' muss angegeben werden", param.getName());
} }
} }
else if(param.getParsers().isEmpty()) {
continue;
}
Map<String, Object> params = Maps.newHashMapWithExpectedSize(param.getParsers().size()); Map<String, Object> params = Maps.newHashMapWithExpectedSize(param.getParsers().size());
for(ArgumentParser parser : param.getParsers()) { for(ArgumentParser parser : param.getParsers()) {
params.put(parser.getName(), parser.getDefault(env)); params.put(parser.getName(), parser.getDefault(env));
@ -200,212 +190,222 @@ public class ScriptArgs {
return null; return null;
} }
public static String[] parseComplete(ScriptEnvironment env, String[] argv, CachedExecutable cached) { public static String[] parseComplete(ScriptEnvironment env, String[] argv, CachedExecutable cached, String last) {
String[] comp = getParam(env, argv, cached); String[] comp = getParam(env, argv, cached);
if(comp == null || comp.length == 0) { if(comp == null || comp.length == 0) {
Set<String> params = Sets.newTreeSet(); Set<String> params = Sets.newTreeSet();
boolean all = last.startsWith("--");
for(String param : cached.getParameters().keySet()) { for(String param : cached.getParameters().keySet()) {
params.add(param.length() == 1 ? "-" + param : ("--" + param)); if(all || param.length() == 1)
params.add(param.length() == 1 ? "-" + param : ("--" + param));
} }
comp = params.toArray(new String[params.size()]); comp = params.toArray(new String[params.size()]);
} }
return comp; return comp;
} }
public ScriptArg getArg(String name) { // public ScriptArg getArg(String name) {
return this.arguments.get(name); // return this.arguments.get(name);
} // }
public boolean hasArg(String name) { public boolean hasArg(String name) {
return this.arguments.containsKey(name); return this.arguments.containsKey(name);
} }
public boolean has(String name, String par) { // public boolean has(String name, String par) {
return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par); // return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
} // }
public boolean has(String name) { // public boolean has(String name) {
return this.has(name, name); // return this.has(name, name);
} // }
public <T> T getDefault(String name, String par, T def) { // public <T> T getDefault(String name, String par, T def) {
// ScriptArg arg = this.arguments.get(name);
// if(arg == null)
// return def;
// Object value = arg.getValues().get(par);
// return value == null ? def : (T)value;
// }
//
// public <T> T getDefault(String name, T def) {
// return this.getDefault(name, name, def);
// }
//
// public <T> T getUnchecked(String name, String par) {
// return this.getDefault(name, par, null);
// }
public <T> T getUnchecked(String name, String par) {
ScriptArg arg = this.arguments.get(name); ScriptArg arg = this.arguments.get(name);
if(arg == null) if(arg == null)
return def; return null;
Object value = arg.getValues().get(par); Object value = arg.getValues().get(par);
return value == null ? def : (T)value; return value == null ? null : (T)value;
} }
public <T> T getDefault(String name, T def) { // public <T> T getUnchecked(String name) {
return this.getDefault(name, name, def); // return this.getDefault(name, null);
} // }
//
public <T> T getUnchecked(String name, String par) { // public boolean getBool(String name, boolean def) {
return this.getDefault(name, par, null); // return this.getDefault(name, def);
} // }
//
public <T> T getUnchecked(String name) { // public boolean getBool(String name) {
return this.getDefault(name, null); // return this.getUnchecked(name);
} // }
//
public boolean getBool(String name, boolean def) { // public <T extends Enum<?>> T getEnum(String name, T def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public boolean getBool(String name) { // public <T extends Enum<?>> T getEnum(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public <T extends Enum<?>> T getEnum(String name, T def) { // public int getInt(String name, int def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public <T extends Enum<?>> T getEnum(String name) { // public int getInt(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public int getInt(String name, int def) { // public long getLong(String name, long def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public int getInt(String name) { // public long getLong(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public long getLong(String name, long def) { // public double getDouble(String name, double def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public long getLong(String name) { // public double getDouble(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public double getDouble(String name, double def) { // public String getString(String name, String def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public double getDouble(String name) { // public String getString(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public String getString(String name, String def) { // public String[] getStrings(String name, String[] def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public String getString(String name) { // public String[] getStrings(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public String[] getStrings(String name, String[] def) { // public Entity getEntity(String name, Entity def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public String[] getStrings(String name) { // public Entity getEntity(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public Entity getEntity(String name, Entity def) { // public EntityLiving getLiving(String name, EntityLiving def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public Entity getEntity(String name) { // public EntityLiving getLiving(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public EntityLiving getLiving(String name, EntityLiving def) { // public EntityNPC getNpc(String name, EntityNPC def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public EntityLiving getLiving(String name) { // public EntityNPC getNpc(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public EntityNPC getNpc(String name, EntityNPC def) { // public Block getBlock(String name, Block def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public EntityNPC getNpc(String name) { // public Block getBlock(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public Block getBlock(String name, Block def) { // public State getState(String name, State def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public Block getBlock(String name) { // public State getState(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public State getState(String name, State def) { // public Item getItem(String name, Item def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public State getState(String name) { // public Item getItem(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public Item getItem(String name, Item def) { // public ItemStack getStack(String name, ItemStack def) {
return this.getDefault(name, def); // return this.getDefault(name, def);
} // }
//
public Item getItem(String name) { // public ItemStack getStack(String name) {
return this.getUnchecked(name); // return this.getUnchecked(name);
} // }
//
public ItemStack getStack(String name, ItemStack def) { // public BlockPos getColumnPos(String name, BlockPos def) {
return this.getDefault(name, def); // return this.hasArg(name) ? this.getColumnPos(name) : def;
} // }
//
public ItemStack getStack(String name) { // public BlockPos getColumnPos(String name) {
return this.getUnchecked(name); // return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
} // }
//
public BlockPos getColumnPos(String name, BlockPos def) { // public BlockPos getBlockPos(String name, BlockPos def) {
return this.hasArg(name) ? this.getColumnPos(name) : def; // return this.hasArg(name) ? this.getBlockPos(name) : def;
} // }
//
public BlockPos getColumnPos(String name) { // public BlockPos getBlockPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z")); // return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
} // }
//
public BlockPos getBlockPos(String name, BlockPos def) { // public WorldPos getWorldPos(String name, WorldPos def) {
return this.hasArg(name) ? this.getBlockPos(name) : def; // return this.hasArg(name) ? this.getWorldPos(name) : def;
} // }
//
public BlockPos getBlockPos(String name) { // public WorldPos getWorldPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z")); // return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
} // this.getUnchecked(name, "dim"));
// }
public WorldPos getWorldPos(String name, WorldPos def) { //
return this.hasArg(name) ? this.getWorldPos(name) : def; // public Vec3 getVector2D(String name, Vec3 def) {
} // return this.hasArg(name) ? this.getVector2D(name) : def;
// }
public WorldPos getWorldPos(String name) { //
return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"), // public Vec3 getVector2D(String name) {
this.getUnchecked(name, "dim")); // return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
} // }
//
public Vec3 getVector2D(String name, Vec3 def) { // public Vec3 getVector(String name, Vec3 def) {
return this.hasArg(name) ? this.getVector2D(name) : def; // return this.hasArg(name) ? this.getVector(name) : def;
} // }
//
public Vec3 getVector2D(String name) { // public Vec3 getVector(String name) {
return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z")); // return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
} // }
//
public Vec3 getVector(String name, Vec3 def) { // public WorldServer getWorld(String name) {
return this.hasArg(name) ? this.getVector(name) : def; // return this.getUnchecked(name);
} // }
//
public Vec3 getVector(String name) { // public NBTTagCompound getTag(String name) {
return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z")); // return this.getUnchecked(name);
} // }
public WorldServer getWorld(String name) {
return this.getUnchecked(name);
}
public NBTTagCompound getTag(String name) {
return this.getUnchecked(name);
}
} }

View file

@ -1,5 +1,7 @@
package game.command; package game.command;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -10,6 +12,7 @@ import com.google.common.collect.Maps;
import game.Server; import game.Server;
import game.color.TextColor; import game.color.TextColor;
import game.command.commands.CommandSpawn; import game.command.commands.CommandSpawn;
import game.log.Log;
public class ScriptEnvironment { public class ScriptEnvironment {
private final Server server; private final Server server;
@ -80,7 +83,36 @@ public class ScriptEnvironment {
if(cached == null) if(cached == null)
throw new ScriptException("Skript '%s' existiert nicht", argv[0]); throw new ScriptException("Skript '%s' existiert nicht", argv[0]);
ScriptArgs args = ScriptArgs.parseArgs(this, cmd, argv, cached); ScriptArgs args = ScriptArgs.parseArgs(this, cmd, argv, cached);
o = cached.getExecutable().exec(this, args); List<Object> params = Lists.newArrayList(this, this.currentExecutor);
for(Parameter param : cached.getExecutable().getParamList()) {
ArgCombiner combiner = param.getCombiner();
if(combiner != null) {
Object[] data = (Object[])Array.newInstance(combiner.getInputClass(), param.getParsers().size());
for(int z = 0; z < data.length; z++) {
data[z] = args.getUnchecked(param.getName(), param.getParsers().get(z).getName());
if(data[z] == null) {
data = null;
break;
}
}
params.add(data == null ? null : combiner.combine(data));
continue;
}
if(param.getParsers().isEmpty()) {
params.add(args.hasArg(param.getName()));
continue;
}
for(ArgumentParser parser : param.getParsers()) {
params.add(args.getUnchecked(param.getName(), parser.getName()));
}
}
try {
o = cached.getMethod().invoke(cached.getExecutable(), params.toArray(new Object[params.size()]));
}
catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e);
}
// o = cached.getExecutable().exec(this, args);
if(setPrev) if(setPrev)
this.previousOutput = o; this.previousOutput = o;
} }
@ -102,6 +134,7 @@ public class ScriptEnvironment {
} }
catch(Throwable t) { catch(Throwable t) {
exec.logConsole(TextColor.RED + "Fehler: %s", t.getMessage()); exec.logConsole(TextColor.RED + "Fehler: %s", t.getMessage());
Log.CONSOLE.error(t, "Fehler beim Ausführen von Befehl '%s'", cmd);
} }
finally { finally {
this.currentExecutor = null; this.currentExecutor = null;
@ -118,17 +151,17 @@ public class ScriptEnvironment {
String[] argv = cmds[cmds.length - 1]; String[] argv = cmds[cmds.length - 1];
if(argv.length == 0) if(argv.length == 0)
return list; return list;
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
String[] comp; String[] comp;
if(argv.length > 1) { if(argv.length > 1) {
CachedExecutable cached = this.executables.get(argv[0]); CachedExecutable cached = this.executables.get(argv[0]);
if(cached == null) if(cached == null)
return list; return list;
comp = ScriptArgs.parseComplete(this, argv, cached); comp = ScriptArgs.parseComplete(this, argv, cached, param);
} }
else { else {
comp = this.executables.keySet().toArray(new String[this.executables.keySet().size()]); comp = this.executables.keySet().toArray(new String[this.executables.keySet().size()]);
} }
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
for(String cmp : comp) { for(String cmp : comp) {
if(cmp.regionMatches(true, 0, param, 0, param.length())) if(cmp.regionMatches(true, 0, param, 0, param.length()))
list.add(cmp); list.add(cmp);

View file

@ -1,17 +1,21 @@
package game.command; package game.command;
import java.lang.reflect.Array;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import game.command.DoubleParser.DefType; import game.command.DoubleParser.DefType;
import game.world.Vec3;
import game.world.World; import game.world.World;
public abstract class ScriptExecutable implements Executable { public abstract class ScriptExecutable implements Executable {
private final String name; private final String name;
private final Map<String, Parameter> parameters = Maps.newHashMap(); private final Map<String, Parameter> parameters = Maps.newHashMap();
private final List<Parameter> argList = Lists.newArrayList();
private int parPos = 0; private int parPos = 0;
private boolean parReq = true; private boolean parReq = true;
@ -25,16 +29,28 @@ public abstract class ScriptExecutable implements Executable {
return this; return this;
} }
protected ScriptExecutable addParameter(String name, ArgumentParser ... parsers) { protected ScriptExecutable addParameter(String name, ArgCombiner<?> combiner, ArgumentParser ... parsers) {
this.parameters.put(name, new Parameter(name, (char)0, this.parPos++, this.parReq, Lists.newArrayList(parsers))); Parameter param = new Parameter(name, (char)0, this.parPos++, this.parReq, Lists.newArrayList(parsers), combiner);
this.parameters.put(name, param);
this.argList.add(param);
return this; return this;
} }
protected ScriptExecutable addParameter(String name, char shortName, ArgumentParser ... parsers) { protected ScriptExecutable addParameter(String name, char shortName, ArgCombiner<?> combiner, ArgumentParser ... parsers) {
this.parameters.put(name, new Parameter(name, shortName, -1, false, Lists.newArrayList(parsers))); Parameter param = new Parameter(name, shortName, -1, false, Lists.newArrayList(parsers), combiner);
this.parameters.put(name, param);
this.argList.add(param);
return this; return this;
} }
protected ScriptExecutable addParameter(String name, ArgumentParser ... parsers) {
return this.addParameter(name, null, parsers);
}
protected ScriptExecutable addParameter(String name, char shortName, ArgumentParser ... parsers) {
return this.addParameter(name, shortName, null, parsers);
}
protected ScriptExecutable addParameter(ArgumentParser parser) { protected ScriptExecutable addParameter(ArgumentParser parser) {
return this.addParameter(parser.getName(), parser); return this.addParameter(parser.getName(), parser);
} }
@ -44,7 +60,22 @@ public abstract class ScriptExecutable implements Executable {
} }
protected ScriptExecutable addVector(String name, boolean defaulted) { protected ScriptExecutable addVector(String name, boolean defaulted) {
return this.addParameter(name, new DoubleParser("x", defaulted ? DefType.X : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE), new DoubleParser("y", defaulted ? DefType.Y : null, 0.0, (double)World.HEIGHT), new DoubleParser("z", defaulted ? DefType.Z : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE)); return this.addParameter(name, new ArgCombiner<Double>() {
public Vec3 combine(Double[] values) {
return new Vec3(values[0], values[1], values[2]);
}
public Class<?> getTypeClass() {
return Vec3.class;
}
public Class<Double> getInputClass() {
return Double.class;
}
},
new DoubleParser("x", defaulted ? DefType.X : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE),
new DoubleParser("y", defaulted ? DefType.Y : null, 0.0, (double)World.HEIGHT),
new DoubleParser("z", defaulted ? DefType.Z : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE));
} }
protected ScriptExecutable addWorld(String name, boolean defaulted) { protected ScriptExecutable addWorld(String name, boolean defaulted) {
@ -63,24 +94,24 @@ public abstract class ScriptExecutable implements Executable {
return this.addParameter(name, shortName); return this.addParameter(name, shortName);
} }
protected ScriptExecutable addFlag(String name) { // protected ScriptExecutable addFlag(String name) {
return this.addParameter(name, name.charAt(0)); // return this.addParameter(name, name.charAt(0));
// }
protected <T> ScriptExecutable addEnum(String name, T def, Class<T> clazz, T ... values) {
return this.addParameter(new EnumParser<T>(name, clazz, def, values));
} }
protected ScriptExecutable addEnum(String name, Object ... values) { protected <T> ScriptExecutable addEnum(String name, Class<T> clazz, T ... values) {
return this.addParameter(new EnumParser(name, null, values)); return this.addEnum(name, null, clazz, values);
} }
protected ScriptExecutable addEnumDef(String name, Object def, Object ... values) { protected <T> ScriptExecutable addEnum(String name, T def, Class<T> clazz, Collection<T> values) {
return this.addParameter(new EnumParser(name, null, values)); return this.addEnum(name, def, clazz, values.toArray((T[])Array.newInstance(clazz, values.size())));
} }
protected ScriptExecutable addEnum(String name, Collection<?> values) { protected <T> ScriptExecutable addEnum(String name, Class<T> clazz, Collection<T> values) {
return this.addEnum(name, (Object[])values.toArray(new String[values.size()])); return this.addEnum(name, null, clazz, values);
}
protected ScriptExecutable addEnumDef(String name, Object def, Collection<?> values) {
return this.addEnumDef(name, def, (Object[])values.toArray(new String[values.size()]));
} }
protected ScriptExecutable addTag(String name) { protected ScriptExecutable addTag(String name) {
@ -91,14 +122,19 @@ public abstract class ScriptExecutable implements Executable {
return this.addParameter(shortName, new TagParser(name, null)); return this.addParameter(shortName, new TagParser(name, null));
} }
public Object exec(ScriptEnvironment env, ScriptArgs args) { // public Object exec(ScriptEnvironment env, ScriptArgs args) {
return null; // this.getClass().getDeclaredMethod(name, null)
} // return null;
// }
public Map<String, Parameter> getParameters() { public Map<String, Parameter> getParameters() {
return this.parameters; return this.parameters;
} }
public List<Parameter> getParamList() {
return this.argList;
}
public String getName() { public String getName() {
return this.name; return this.name;
} }

View file

@ -1,14 +1,14 @@
package game.command; package game.command;
import com.google.common.base.Predicate; import game.util.CharValidator;
public class StringParser extends DefaultingParser { public class StringParser extends DefaultingParser {
private final boolean allowEmpty; private final boolean allowEmpty;
private final Integer minLength; private final Integer minLength;
private final Integer maxLength; private final Integer maxLength;
private final Predicate<Character> validator; private final CharValidator validator;
public StringParser(String name, String def, boolean allowEmpty, Integer minLength, Integer maxLength, Predicate<Character> validator, public StringParser(String name, String def, boolean allowEmpty, Integer minLength, Integer maxLength, CharValidator validator,
Object ... completions) { Object ... completions) {
super(name, def, completions); super(name, def, completions);
this.allowEmpty = allowEmpty; this.allowEmpty = allowEmpty;
@ -34,6 +34,12 @@ public class StringParser extends DefaultingParser {
else else
throw new ScriptException("Die Zeichenkette darf höchstens %d Zeichen lang sein, habe %d ('%s')", throw new ScriptException("Die Zeichenkette darf höchstens %d Zeichen lang sein, habe %d ('%s')",
this.maxLength, input.length(), input); this.maxLength, input.length(), input);
if(this.validator != null && !this.validator.valid(input))
throw new ScriptException("Die Zeichenkette '%s' enthält ungültige Zeichen", input);
return input; return input;
} }
public Class<?> getTypeClass() {
return String.class;
}
} }

View file

@ -19,4 +19,8 @@ public class TagParser extends DefaultingParser {
} }
return value; return value;
} }
public Class<?> getTypeClass() {
return NBTTagCompound.class;
}
} }

View file

@ -41,4 +41,8 @@ public class WorldParser extends DimensionParser {
} }
return super.getCompletions(env); return super.getCompletions(env);
} }
public Class<?> getTypeClass() {
return WorldServer.class;
}
} }

View file

@ -4,10 +4,10 @@ import java.util.Set;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import game.command.ScriptArgs;
import game.command.ScriptEnvironment; import game.command.ScriptEnvironment;
import game.command.ScriptException; import game.command.ScriptException;
import game.command.ScriptExecutable; import game.command.ScriptExecutable;
import game.command.ScriptExecutor;
import game.entity.Entity; import game.entity.Entity;
import game.entity.types.EntityLiving; import game.entity.types.EntityLiving;
import game.init.EntityRegistry; import game.init.EntityRegistry;
@ -18,28 +18,23 @@ import game.world.WorldServer;
public class CommandSpawn extends ScriptExecutable { public class CommandSpawn extends ScriptExecutable {
public CommandSpawn() { public CommandSpawn() {
super("spawn"); super("spawn");
Set<String> names = Sets.newTreeSet(); Set<String> names = Sets.newTreeSet();
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) { for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
names.add(EntityRegistry.getEntityString(clazz)); names.add(EntityRegistry.getEntityString(clazz));
} }
this.addEnum("type", names); this.addEnum("type", String.class, names);
this.setParamsOptional(); this.setParamsOptional();
this.addVector("position", true); this.addVector("position", true);
this.addWorld("dim", true); this.addWorld("dim", true);
this.addTag("tag"); this.addTag("tag");
this.addFlag("noinit");
this.addFlag("noinit", 'n');
this.addInt("count", 'c', 1, 1024, 1); this.addInt("count", 'c', 1, 1024, 1);
this.addTag("postTag", 'p'); this.addTag("postTag", 'p');
} }
public Object exec(ScriptEnvironment env, ScriptArgs args) { public Object exec(ScriptEnvironment env, ScriptExecutor exec, String type, Vec3 pos, WorldServer world, NBTTagCompound tag, boolean noinit, int count, NBTTagCompound postTag) {
String type = args.getString("type");
WorldServer world = args.getWorld("dim");
Vec3 pos = args.getVector("position");
int count = args.getInt("count");
boolean init = !args.has("noinit");
NBTTagCompound tag = args.getTag("tag");
NBTTagCompound postTag = args.getTag("postTag");
for(int z = 0; z < count; z++) { for(int z = 0; z < count; z++) {
Entity entity = EntityRegistry.createEntityByName(type, world); Entity entity = EntityRegistry.createEntityByName(type, world);
if(entity == null) if(entity == null)
@ -51,7 +46,7 @@ public class CommandSpawn extends ScriptExecutable {
ent.merge(tag); ent.merge(tag);
entity.readFromNBT(ent); entity.readFromNBT(ent);
} }
if(init && (entity instanceof EntityLiving)) if(!noinit && (entity instanceof EntityLiving))
((EntityLiving)entity).onInitialSpawn(null); ((EntityLiving)entity).onInitialSpawn(null);
world.spawnEntityInWorld(entity); world.spawnEntityInWorld(entity);
if(postTag != null) { if(postTag != null) {
@ -61,7 +56,7 @@ public class CommandSpawn extends ScriptExecutable {
entity.readFromNBT(ent); entity.readFromNBT(ent);
} }
} }
env.getExecutor().logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); exec.logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
return null; return null;
} }
} }

View file

@ -222,94 +222,94 @@ public abstract class Gui {
elem.drawHover(); elem.drawHover();
} }
public static void drawRect(int left, int top, int right, int bottom, int color) // public static void drawRect(int left, int top, int right, int bottom, int color)
{ // {
if (left < right) // if (left < right)
{ // {
int i = left; // int i = left;
left = right; // left = right;
right = i; // right = i;
} // }
//
if (top < bottom) // if (top < bottom)
{ // {
int j = top; // int j = top;
top = bottom; // top = bottom;
bottom = j; // bottom = j;
} // }
//
float f3 = (float)(color >> 24 & 255) / 255.0F; // float f3 = (float)(color >> 24 & 255) / 255.0F;
float f = (float)(color >> 16 & 255) / 255.0F; // float f = (float)(color >> 16 & 255) / 255.0F;
float f1 = (float)(color >> 8 & 255) / 255.0F; // float f1 = (float)(color >> 8 & 255) / 255.0F;
float f2 = (float)(color & 255) / 255.0F; // float f2 = (float)(color & 255) / 255.0F;
RenderBuffer worldrenderer = Tessellator.getBuffer(); // RenderBuffer worldrenderer = Tessellator.getBuffer();
GlState.enableBlend(); // GlState.enableBlend();
GlState.disableTexture2D(); // GlState.disableTexture2D();
GlState.tryBlendFuncSeparate(770, 771, 1, 0); // GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.color(f, f1, f2, f3); // GlState.color(f, f1, f2, f3);
worldrenderer.begin(7, DefaultVertexFormats.POSITION); // worldrenderer.begin(7, DefaultVertexFormats.POSITION);
worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex(); // worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex();
worldrenderer.pos((double)right, (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)right, (double)top, 0.0D).endVertex();
worldrenderer.pos((double)left, (double)top, 0.0D).endVertex(); // worldrenderer.pos((double)left, (double)top, 0.0D).endVertex();
Tessellator.draw(); // Tessellator.draw();
GlState.enableTexture2D(); // GlState.enableTexture2D();
GlState.disableBlend(); // GlState.disableBlend();
} // }
public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) // public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
{ // {
float f = 0.00390625F; // float f = 0.00390625F;
float f1 = 0.00390625F; // float f1 = 0.00390625F;
RenderBuffer worldrenderer = Tessellator.getBuffer(); // RenderBuffer worldrenderer = Tessellator.getBuffer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); // 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 + 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 + 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 + 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(); // worldrenderer.pos((double)(x + 0), (double)(y + 0), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex();
Tessellator.draw(); // 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) // 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 f = 1.0F / tileWidth;
float f1 = 1.0F / tileHeight; // float f1 = 1.0F / tileHeight;
RenderBuffer worldrenderer = Tessellator.getBuffer(); // RenderBuffer worldrenderer = Tessellator.getBuffer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); // 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, (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 + 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 + 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(); // worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
Tessellator.draw(); // Tessellator.draw();
} // }
//
public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) // 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 f = (float)(startColor >> 24 & 255) / 255.0F;
float f1 = (float)(startColor >> 16 & 255) / 255.0F; // float f1 = (float)(startColor >> 16 & 255) / 255.0F;
float f2 = (float)(startColor >> 8 & 255) / 255.0F; // float f2 = (float)(startColor >> 8 & 255) / 255.0F;
float f3 = (float)(startColor & 255) / 255.0F; // float f3 = (float)(startColor & 255) / 255.0F;
float f4 = (float)(endColor >> 24 & 255) / 255.0F; // float f4 = (float)(endColor >> 24 & 255) / 255.0F;
float f5 = (float)(endColor >> 16 & 255) / 255.0F; // float f5 = (float)(endColor >> 16 & 255) / 255.0F;
float f6 = (float)(endColor >> 8 & 255) / 255.0F; // float f6 = (float)(endColor >> 8 & 255) / 255.0F;
float f7 = (float)(endColor & 255) / 255.0F; // float f7 = (float)(endColor & 255) / 255.0F;
GlState.disableTexture2D(); // GlState.disableTexture2D();
GlState.enableBlend(); // GlState.enableBlend();
GlState.disableAlpha(); // GlState.disableAlpha();
GlState.tryBlendFuncSeparate(770, 771, 1, 0); // GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425); // GlState.shadeModel(7425);
RenderBuffer worldrenderer = Tessellator.getBuffer(); // RenderBuffer worldrenderer = Tessellator.getBuffer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); // worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos((double)right, (double)top, 0.0).color(f1, f2, f3, f).endVertex(); // 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)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)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(); // worldrenderer.pos((double)right, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex();
Tessellator.draw(); // Tessellator.draw();
GlState.shadeModel(7424); // GlState.shadeModel(7424);
GlState.disableBlend(); // GlState.disableBlend();
GlState.enableAlpha(); // GlState.enableAlpha();
GlState.enableTexture2D(); // GlState.enableTexture2D();
} // }
public void drawMainBackground() { public void drawMainBackground() {
if(this.gm.theWorld != null) { if(this.gm.theWorld != null) {

View file

@ -77,7 +77,7 @@ public class GuiMenu extends Gui {
}, "Info / Über / Mitwirkende") { }, "Info / Über / Mitwirkende") {
public void drawHover() { public void drawHover() {
if(GuiMenu.this.hacked == 10) { if(GuiMenu.this.hacked == 10) {
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, (this.gm.style.hover & 0xff000000) | 0x7f00ff); Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, (this.gm.style.hover & 0xff000000) | 0x7f00ff);
GuiMenu.this.rand.setSeed(((long)this.gm.mouse_x * 7652657L) ^ ((long)this.gm.mouse_y * 87262826276L)); GuiMenu.this.rand.setSeed(((long)this.gm.mouse_x * 7652657L) ^ ((long)this.gm.mouse_y * 87262826276L));
int width = Drawing.getWidth("Hax!"); int width = Drawing.getWidth("Hax!");
for(int z = 0; z < 64; z++) { for(int z = 0; z < 64; z++) {
@ -314,10 +314,10 @@ public class GuiMenu extends Gui {
int y = 164; int y = 164;
int h = 16; int h = 16;
int n = Drawing.getWidth(this.splashLabel.getText()); int n = Drawing.getWidth(this.splashLabel.getText());
Drawing.drawRectColor(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff); Drawing.drawRect(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.drawRect(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.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack), 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); Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - 3 - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
} }
} }
} }

View file

@ -118,7 +118,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
if (/* this.gm.touchscreen || */ hovered) if (/* this.gm.touchscreen || */ hovered)
{ {
// GuiSkin.this.gm.getTextureManager().bindTexture(SKINS_BUTTONS); // GuiSkin.this.gm.getTextureManager().bindTexture(SKINS_BUTTONS);
Drawing.drawRectColor(x, y, 64, 64, -1601138544); Drawing.drawRect(x, y, 64, 64, -1601138544);
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); // GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// int k1 = mouseX - x; // int k1 = mouseX - x;
// int l1 = mouseY - y; // int l1 = mouseY - y;
@ -248,7 +248,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
// if(this.dragging) { // if(this.dragging) {
// //
// } // }
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x20ffffff); Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x20ffffff);
} }
protected void drawForeground(int x1, int y1, int x2, int y2) { protected void drawForeground(int x1, int y1, int x2, int y2) {

View file

@ -120,16 +120,15 @@ public abstract class GuiContainer extends Gui
public void drawString(String text, int x, int y) { public void drawString(String text, int x, int y) {
x = x * 2 + this.container_x; x = x * 2 + this.container_x;
y = y * 2 + this.container_y; y = y * 2 + this.container_y;
Drawing.txt_draw(x, y, x, y, x + 440, y + 260, 0xffffffff, text); Drawing.drawText(text, x, y, 0xffffffff);
} }
public int getStringWidth(String text) { public int getStringWidth(String text) {
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, text); return Drawing.getSize(text).xpos / 2;
return size.xpos / 2;
} }
public void rect(int x, int y, int width, int height, int color) { public void rect(int x, int y, int width, int height, int color) {
Drawing.drawRectColor(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | color); Drawing.drawRect(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | color);
} }
public InventoryButton button(int x, int y, int w, int h) { public InventoryButton button(int x, int y, int w, int h) {
@ -1087,12 +1086,12 @@ public abstract class GuiContainer extends Gui
s = TextColor.RED + ItemStack.formatAmount(stack.stackSize); s = TextColor.RED + ItemStack.formatAmount(stack.stackSize);
} }
// this.drawString(s, , ); // this.drawString(s, , );
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s); // Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s);
int x = xPosition + 34 - size.xpos; // this.getStringWidth(s); // int x = - size.xpos; // this.getStringWidth(s);
int y = yPosition + 17; // int y = ;
// x = x * 2 + this.container_x; // x = x * 2 + this.container_x;
// y = y * 2 + this.container_y; // y = y * 2 + this.container_y;
Drawing.txt_draw(x, y, x, y, x + 440, y + 260, 0xffffffff, s); Drawing.drawTextRight(s, xPosition + 32, yPosition + 17, 0xffffffff);
} }
if (stack.isItemDamaged()) if (stack.isItemDamaged())
@ -1109,7 +1108,7 @@ public abstract class GuiContainer extends Gui
private static void draw(int x, int y, int width, int height, int red, int green, int blue) private static void draw(int x, int y, int width, int height, int red, int green, int blue)
{ {
// Drawing.gfx_draw_rect_color(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | (red << 16) | (green << 8) | blue); // Drawing.gfx_draw_rect_color(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | (red << 16) | (green << 8) | blue);
Drawing.drawRectColor(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue); Drawing.drawRect(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue);
} }
public void drawBackground() { public void drawBackground() {

View file

@ -2,6 +2,7 @@ package game.gui.element;
import game.renderer.Drawing; import game.renderer.Drawing;
import game.util.ExtMath; import game.util.ExtMath;
import game.util.Util;
public class Bar extends Fill { public class Bar extends Fill {
private int color = 0x00ff00; private int color = 0x00ff00;
@ -25,7 +26,7 @@ public class Bar extends Fill {
protected void drawBackground() { 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.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);
if(this.progress > 0) if(this.progress > 0)
Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.progress, this.size_y - 4, this.color | 0xff000000, Drawing.mixColor(this.color | 0xff000000, 0xff000000)); Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.progress, this.size_y - 4, this.color | 0xff000000, Util.mixColor(this.color | 0xff000000, 0xff000000));
} }
protected void drawForeground(int x1, int y1, int x2, int y2) { protected void drawForeground(int x1, int y1, int x2, int y2) {

View file

@ -23,16 +23,15 @@ public class Dropdown<T> extends Element {
} }
public void updateText() { public void updateText() {
this.r_dirty = true;
} }
protected boolean isTextCenteredX() { // protected boolean isTextCenteredX() {
return false; // return false;
} // }
//
protected boolean isTextCenteredY() { // protected boolean isTextCenteredY() {
return false; // return false;
} // }
public boolean canClick() { public boolean canClick() {
return false; return false;
@ -60,10 +59,7 @@ public class Dropdown<T> extends Element {
public void drawHover() { 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))); 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)) // if((sys.mouse_y - this.pos_y) < (this.size_y - this.margin_y2))
Drawing.drawRectColor(this.pos_x + this.margin_x1, Drawing.drawRect(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);
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);
} }
} }

View file

@ -33,8 +33,6 @@ public abstract class Element {
protected int size_y; protected int size_y;
protected int text_x = 0; protected int text_x = 0;
protected int text_y = 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_x1 = this.getMargin();
protected final int margin_y1 = this.getMargin(); protected final int margin_y1 = this.getMargin();
@ -87,17 +85,17 @@ public abstract class Element {
return this.size_y; return this.size_y;
} }
protected boolean isTextCenteredX() { // protected boolean isTextCenteredX() {
return true; // return true;
} // }
//
// protected boolean isTextCenteredY() {
// return true;
// }
protected boolean isTextCenteredY() { // protected boolean hasLinebreak() {
return true; // return false;
} // }
protected boolean hasLinebreak() {
return false;
}
public boolean canHover() { public boolean canHover() {
return true; return true;
@ -116,22 +114,9 @@ public abstract class Element {
} }
public void updateText() { public void updateText() {
Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, Vec2i size = Drawing.getSize(this.text);
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1, this.text_x = (this.size_x - size.xpos) / 2;
this.hasLinebreak() ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text); this.text_y = (this.size_y - size.ypos) / 2;
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) { public void setText(String str) {
@ -273,11 +258,11 @@ public abstract class Element {
} }
public void drawHover() { public void drawHover() {
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.hover); Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.hover);
} }
public void drawPress() { public void drawPress() {
Drawing.drawRectColor(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.press); Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.press);
} }
public void playSound() { public void playSound() {

View file

@ -1,5 +1,8 @@
package game.gui.element; package game.gui.element;
import game.renderer.Drawing;
import game.renderer.Drawing.Vec2i;
public class Fill extends Element { public class Fill extends Element {
private final boolean left; private final boolean left;
private final boolean top; private final boolean top;
@ -36,11 +39,19 @@ public class Fill extends Element {
return false; return false;
} }
protected boolean isTextCenteredX() { // protected boolean isTextCenteredX() {
return !this.left; // return !this.left;
} // }
//
// protected boolean isTextCenteredY() {
// return !this.top;
// }
protected boolean isTextCenteredY() { public void updateText() {
return !this.top; Vec2i size = Drawing.getSize(this.text);
if(!this.left)
this.text_x = (this.size_x - size.xpos) / 2;
if(!this.top)
this.text_y = (this.size_y - size.ypos) / 2;
} }
} }

View file

@ -349,7 +349,7 @@ public abstract class GuiList<T extends ListEntry> extends Gui
boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z; boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z;
this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover); this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover);
if(hover) if(hover)
Drawing.drawRectColor(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), this.gm.style.hover); Drawing.drawRect(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), this.gm.style.hover);
} }
} }

View file

@ -3,6 +3,7 @@ package game.gui.element;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import game.gui.Font; import game.gui.Font;
import game.gui.element.Dropdown.Handle;
import game.renderer.Drawing; import game.renderer.Drawing;
import game.renderer.Drawing.Offset; import game.renderer.Drawing.Offset;
import game.renderer.Drawing.Vec2i; import game.renderer.Drawing.Vec2i;
@ -38,6 +39,8 @@ public class Textbox extends Element {
private int sel_drag = -1; private int sel_drag = -1;
private int cursorX = 0; private int cursorX = 0;
private int cursorY = 0; private int cursorY = 0;
private int tsize_x = 0;
private int tsize_y = 0;
private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) { private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) {
super(x, y, w, h, null); super(x, y, w, h, null);
@ -71,16 +74,24 @@ public class Textbox extends Element {
// this.editable = editable; // this.editable = editable;
// } // }
protected boolean isTextCenteredX() { // protected boolean isTextCenteredX() {
return false; // return false;
} // }
//
// protected boolean isTextCenteredY() {
// return false;
// }
protected boolean isTextCenteredY() { // protected boolean hasLinebreak() {
return false; // return this.xbreak;
} // }
protected boolean hasLinebreak() { public void updateText() {
return this.xbreak; Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.xbreak ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text);
this.tsize_x = size.xpos;
this.tsize_y = size.ypos;
} }
public boolean canHover() { public boolean canHover() {
@ -420,7 +431,7 @@ public class Textbox extends Element {
x1 + 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); 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) 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, Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, 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); this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.gm.style.select, this.text);
} }
@ -433,7 +444,7 @@ public class Textbox extends Element {
int y2 = this.size_y - (this.margin_y1 + this.margin_y2); int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2); GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glEnable(GL11.GL_SCISSOR_TEST);
Drawing.drawRectColor(this.cursorX, this.cursorY, 1, Font.YGLYPH, this.gm.style.cursor); Drawing.drawRect(this.cursorX, this.cursorY, 1, Font.YGLYPH, this.gm.style.cursor);
GL11.glDisable(GL11.GL_SCISSOR_TEST); GL11.glDisable(GL11.GL_SCISSOR_TEST);
} }
} }
@ -466,8 +477,11 @@ public class Textbox extends Element {
s = s + this.text.substring(j); s = s + this.text.substring(j);
} }
this.setText(s); // this.setText(s);
// this.text = s; this.text = s;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = i;
gui_text_update_cur(this.sel_start, true);
// //
// if(flag) { // if(flag) {
// this.moveCursorBy(num); // this.moveCursorBy(num);

View file

@ -608,7 +608,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
{ {
super.drawOverlays(); super.drawOverlays();
if(this.warningMessage != null) { if(this.warningMessage != null) {
Drawing.drawRectBorder(this.gm.fb_x / 2 - 200, this.gm.fb_y - 84, 400, 18, 0xff000000, 0xff808080); Drawing.drawBordered(this.gm.fb_x / 2 - 200, this.gm.fb_y - 84, 400, 18, 0xff000000, 0xff808080);
// drawRect(this.gm.fb_x / 2 - 191, this.gm.fb_y - 82, this.gm.fb_x / 2 + 191, this.gm.fb_y - 66, 0xff808080); // drawRect(this.gm.fb_x / 2 - 191, this.gm.fb_y - 82, this.gm.fb_x / 2 + 191, this.gm.fb_y - 66, 0xff808080);
// drawRect(this.gm.fb_x / 2 - 190, this.gm.fb_y - 81, this.gm.fb_x / 2 + 190, this.gm.fb_y - 67, 0xff000000); // drawRect(this.gm.fb_x / 2 - 190, this.gm.fb_y - 81, this.gm.fb_x / 2 + 190, this.gm.fb_y - 67, 0xff000000);
Drawing.drawTextCentered(this.warningMessage, this.gm.fb_x / 2, this.gm.fb_y - 84, 0xffff0000); Drawing.drawTextCentered(this.warningMessage, this.gm.fb_x / 2, this.gm.fb_y - 84, 0xffff0000);

View file

@ -5,6 +5,7 @@ import game.color.TextColor;
import game.gui.Font; import game.gui.Font;
import game.gui.FontChar; import game.gui.FontChar;
import game.log.Log; import game.log.Log;
import game.util.Util;
public abstract class Drawing { public abstract class Drawing {
public static class Vec2i { public static class Vec2i {
@ -25,11 +26,6 @@ public abstract class Drawing {
this.offset = off; this.offset = off;
} }
} }
// private static final int FLAG_ULINE = 0x01;
// private static final int FLAG_CLINE = 0x02;
// private static final int FLAG_BLINK = 0x04;
// private static final int FLAG_FADE = 0x08;
// public static void drawTexturedModalRect(int tw, int th, int x, int y, int textureX, int textureY, int width, int height) // public static void drawTexturedModalRect(int tw, int th, int x, int y, int textureX, int textureY, int width, int height)
// { // {
@ -42,35 +38,6 @@ public abstract class Drawing {
// rb.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); // rb.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).endVertex();
// rb.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); // rb.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).endVertex();
// Tessellator.draw(); // Tessellator.draw();
// }
public static void drawTexturedModalRect(RenderBuffer rb, int tw, int th, int x, int y, int textureX, int textureY, int width, int height, int color)
{
float xs = 1.0f / (float)tw; // 0.00390625F;
float ys = 1.0f / (float)th; // 0.00390625F;
rb.pos((double)(x + 0), (double)(y + height), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
rb.pos((double)(x + width), (double)(y + height), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
rb.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
rb.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
}
private static void color(int c) {
float a = (float)(c >> 24 & 255) / 255.0F;
float r = (float)(c >> 16 & 255) / 255.0F;
float g = (float)(c >> 8 & 255) / 255.0F;
float b = (float)(c & 255) / 255.0F;
GlState.color(r, g, b, a);
}
// private static void trect(int left, int top, int right, int bottom)
// {
// RenderBuffer worldrenderer = Tessellator.getBuffer();
// 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();
// } // }
public static void txt_draw(int x, int y, int x1, int y1, int x2, int y2, int color, String str) { public static void txt_draw(int x, int y, int x1, int y1, int x2, int y2, int color, String str) {
@ -88,7 +55,6 @@ public abstract class Drawing {
FontChar glyph; FontChar glyph;
char ch; char ch;
int ncolor = color; int ncolor = color;
// color(color);
for(int z = 0; z < str.length(); z++) { for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z); ch = str.charAt(z);
if(ch == Log.CHR_NLN) { if(ch == Log.CHR_NLN) {
@ -96,19 +62,11 @@ public abstract class Drawing {
y += h; y += h;
continue; continue;
} }
// else if(ch >= Log.CHR_ULINE && ch <= Log.CHR_FADE) {
// continue;
// }
else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) { else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) {
// color(TextColor.getColor(ch) | (color & 0xff000000));
ncolor = TextColor.getColor(ch) | (color & 0xff000000); ncolor = TextColor.getColor(ch) | (color & 0xff000000);
continue; continue;
} }
// else if(ch == Log.CHR_FRESET) {
// continue;
// }
else if(ch == Log.CHR_CRESET) { else if(ch == Log.CHR_CRESET) {
// color(color);
ncolor = color; ncolor = color;
continue; continue;
} }
@ -128,7 +86,7 @@ public abstract class Drawing {
if(x < x1 || y < y1 || x > x2 || y > y2) { if(x < x1 || y < y1 || x > x2 || y > y2) {
break; break;
} }
drawTexturedModalRect(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x, y, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, h, ncolor); putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x, y, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, h, ncolor, 0.0);
x += u; x += u;
} }
Tessellator.draw(); Tessellator.draw();
@ -138,7 +96,7 @@ public abstract class Drawing {
GlState.enableTexture2D(); GlState.enableTexture2D();
} }
public static void txt_draw_range(int start, int end, int x, int y, int x1, int y1, int x2, int y2, int back, String str) { public static void txt_overlay(int start, int end, int x, int y, int x1, int y1, int x2, int y2, int back, String str) {
int h = Font.YGLYPH; int h = Font.YGLYPH;
int tx, ty, u, v; int tx, ty, u, v;
FontChar glyph; FontChar glyph;
@ -186,7 +144,7 @@ public abstract class Drawing {
// shd.setVec2("size", (float)u, (float)v); // shd.setVec2("size", (float)u, (float)v);
// shd.setVec4("glyph", (float)glyph.s, 0.0f, (float)glyph.u, (float)h); // shd.setVec4("glyph", (float)glyph.s, 0.0f, (float)glyph.u, (float)h);
// shd.draw(); // shd.draw();
drawRect(x, y, x + u, y + v, back); drawRect(x, y, u, v, back);
} }
x += u; x += u;
} }
@ -231,45 +189,6 @@ public abstract class Drawing {
return new Vec2i(x - ix, y - iy); return new Vec2i(x - ix, y - iy);
} }
public static Vec2i txt_box(int x, int y, int x1, int y1, int x2, int y2, String str) {
int h = Font.YGLYPH;
int ix = x;
// int iy = y;
int tx, ty, u, v;
FontChar glyph;
char ch;
for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z);
if(ch == Log.CHR_NLN) {
x = x1;
y += h;
continue;
}
else if(ch < Log.CHR_SPC) {
continue;
}
if(ch >= 256)
ch = Log.CHR_UNK;
glyph = Font.SIZES[ch];
if(glyph.u == 0 && glyph.v != 0)
continue;
else if(glyph.u == 0)
glyph = Font.SIZES[Log.CHR_UNK];
u = glyph.u + 3 - glyph.s;
v = h;
tx = ((x + u) > x2) ? x1 : x;
ty = ((x + u) > x2) ? y + h : y;
x = tx;
y = ty;
if(x < x1 || y < y1 || x > x2 || y > y2) {
break;
}
x += u;
ix = x > ix ? x : ix;
}
return new Vec2i(ix - 2, y + h);
}
public static Vec2i txt_coord(int offset, int x, int y, int x1, int y1, int x2, int y2, String str) { public static Vec2i txt_coord(int offset, int x, int y, int x1, int y1, int x2, int y2, String str) {
int h = Font.YGLYPH; int h = Font.YGLYPH;
int tx, ty, u, v; int tx, ty, u, v;
@ -368,43 +287,129 @@ public abstract class Drawing {
} }
return new Offset(pos, x, y); return new Offset(pos, x, y);
} }
// public static void gfx_blit(int tex) {
// ShaderContext shd = Shader.BLIT.use();
// GlState.bindTexture(tex);
// shd.draw();
// shd.discard();
// }
public static void drawGradientRect(int left, int top, int right, int bottom, int ctop, int cbottom)
private static void putGlyph(RenderBuffer rb, int tw, int th, int x, int y, int textureX, int textureY, int width, int height, int color, double depth)
{ {
float at = (float)(ctop >> 24 & 255) / 255.0F; float xs = 1.0f / (float)tw;
float rt = (float)(ctop >> 16 & 255) / 255.0F; float ys = 1.0f / (float)th;
float gt = (float)(ctop >> 8 & 255) / 255.0F; rb.pos((double)(x + 0), (double)(y + height), depth).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
float bt = (float)(ctop & 255) / 255.0F; rb.pos((double)(x + width), (double)(y + height), depth).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
float ab = (float)(cbottom >> 24 & 255) / 255.0F; rb.pos((double)(x + width), (double)(y + 0), depth).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
float rb = (float)(cbottom >> 16 & 255) / 255.0F; rb.pos((double)(x + 0), (double)(y + 0), depth).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
float gb = (float)(cbottom >> 8 & 255) / 255.0F; }
float bb = (float)(cbottom & 255) / 255.0F;
GlState.disableTexture2D(); public static void drawText(String str, int x, int y, int color, boolean shadow) {
GlState.enableTexture2D();
GlState.enableBlend(); GlState.enableBlend();
GlState.disableAlpha(); GlState.disableAlpha();
GlState.tryBlendFuncSeparate(770, 771, 1, 0); GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425); GlState.shadeModel(7425);
RenderBuffer buf = Tessellator.getBuffer(); GlState.color(1.0f, 1.0f, 1.0f, 1.0f);
buf.begin(7, DefaultVertexFormats.POSITION_COLOR); Font.bindTexture();
buf.pos((double)right, (double)top, 0.0).color(rt, gt, bt, at).endVertex(); RenderBuffer rb = Tessellator.getBuffer();
buf.pos((double)left, (double)top, 0.0).color(rt, gt, bt, at).endVertex(); rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
buf.pos((double)left, (double)bottom, 0.0).color(rb, gb, bb, ab).endVertex(); int ox = x;
buf.pos((double)right, (double)bottom, 0.0).color(rb, gb, bb, ab).endVertex(); int ncolor = color;
FontChar glyph;
char ch;
if(shadow) {
int oy = y;
int scolor = Util.mixColor(color, color & 0xff000000);
scolor = Util.mixColor(scolor, scolor & 0xff000000);
int bcolor = scolor;
for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z);
if(ch == Log.CHR_NLN) {
x = ox;
y += Font.YGLYPH;
continue;
}
else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) {
bcolor = TextColor.getShadow(ch) | (scolor & 0xff000000);
continue;
}
else if(ch == Log.CHR_CRESET) {
bcolor = scolor;
continue;
}
if(ch >= 256)
ch = Log.CHR_UNK;
glyph = Font.SIZES[ch];
if(glyph.u == 0 && glyph.v != 0)
continue;
else if(glyph.u == 0)
glyph = Font.SIZES[Log.CHR_UNK];
putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x + 1, y + 1, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, Font.YGLYPH, bcolor, -0.01);
x += glyph.u + 3 - glyph.s;
}
x = ox;
y = oy;
}
for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z);
if(ch == Log.CHR_NLN) {
x = ox;
y += Font.YGLYPH;
continue;
}
else if((ch >= Log.CHR_COLORS1 && ch <= Log.CHR_COLORE1) || (ch >= Log.CHR_COLORS2 && ch <= Log.CHR_COLORE2)) {
ncolor = TextColor.getColor(ch) | (color & 0xff000000);
continue;
}
else if(ch == Log.CHR_CRESET) {
ncolor = color;
continue;
}
if(ch >= 256)
ch = Log.CHR_UNK;
glyph = Font.SIZES[ch];
if(glyph.u == 0 && glyph.v != 0)
continue;
else if(glyph.u == 0)
glyph = Font.SIZES[Log.CHR_UNK];
putGlyph(rb, Font.XGLYPH * 16, Font.YGLYPH * 16, x, y, (ch & 0x0f) * Font.XGLYPH + glyph.s, ((ch & 0xf0) >> 4) * Font.YGLYPH, glyph.u, Font.YGLYPH, ncolor, -0.02);
x += glyph.u + 3 - glyph.s;
}
Tessellator.draw(); Tessellator.draw();
GlState.shadeModel(7424); GlState.shadeModel(7424);
GlState.disableBlend(); GlState.disableBlend();
GlState.enableAlpha(); GlState.enableAlpha();
GlState.enableTexture2D(); GlState.enableTexture2D();
} }
public static Vec2i getSize(String str) {
int x = 0;
int y = 0;
int ix = 0;
FontChar glyph;
char ch;
for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z);
if(ch == Log.CHR_NLN) {
ix = x > ix ? x : ix;
x = 0;
y += Font.YGLYPH;
continue;
}
else if(ch < Log.CHR_SPC) {
continue;
}
if(ch >= 256)
ch = Log.CHR_UNK;
glyph = Font.SIZES[ch];
if(glyph.u == 0 && glyph.v != 0)
continue;
else if(glyph.u == 0)
glyph = Font.SIZES[Log.CHR_UNK];
x += glyph.u + 3 - glyph.s;
ix = x > ix ? x : ix;
}
return new Vec2i(ix - 3, y + Font.YGLYPH);
}
public static void draw4GradientRect(int left, int top, int right, int bottom, int lopleft, int topright, int btmleft, int btmright)
public static void drawGradient(int x, int y, int w, int h, int ctop, int cbottom)
{ {
GlState.disableTexture2D(); GlState.disableTexture2D();
GlState.enableBlend(); GlState.enableBlend();
@ -413,10 +418,10 @@ public abstract class Drawing {
GlState.shadeModel(7425); GlState.shadeModel(7425);
RenderBuffer buf = Tessellator.getBuffer(); RenderBuffer buf = Tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_COLOR); buf.begin(7, DefaultVertexFormats.POSITION_COLOR);
buf.pos((double)right, (double)top, 0.0).color(topright).endVertex(); buf.pos((double)(x + w), (double)y, 0.0).color(ctop).endVertex();
buf.pos((double)left, (double)top, 0.0).color(lopleft).endVertex(); buf.pos((double)x, (double)y, 0.0).color(ctop).endVertex();
buf.pos((double)left, (double)bottom, 0.0).color(btmleft).endVertex(); buf.pos((double)x, (double)(y + h), 0.0).color(cbottom).endVertex();
buf.pos((double)right, (double)bottom, 0.0).color(btmright).endVertex(); buf.pos((double)(x + w), (double)(y + h), 0.0).color(cbottom).endVertex();
Tessellator.draw(); Tessellator.draw();
GlState.shadeModel(7424); GlState.shadeModel(7424);
GlState.disableBlend(); GlState.disableBlend();
@ -424,38 +429,40 @@ public abstract class Drawing {
GlState.enableTexture2D(); GlState.enableTexture2D();
} }
public static void drawRect(int left, int top, int right, int bottom, int color) public static void draw4Gradient(int x, int y, int w, int h, int lopleft, int topright, int btmleft, int btmright)
{ {
if (left < right) GlState.disableTexture2D();
{ GlState.enableBlend();
int i = left; GlState.disableAlpha();
left = right; GlState.tryBlendFuncSeparate(770, 771, 1, 0);
right = i; GlState.shadeModel(7425);
} RenderBuffer buf = Tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_COLOR);
if (top < bottom) buf.pos((double)(x + w), (double)y, 0.0).color(topright).endVertex();
{ buf.pos((double)x, (double)y, 0.0).color(lopleft).endVertex();
int j = top; buf.pos((double)x, (double)(y + h), 0.0).color(btmleft).endVertex();
top = bottom; buf.pos((double)(x + w), (double)(y + h), 0.0).color(btmright).endVertex();
bottom = j; Tessellator.draw();
} GlState.shadeModel(7424);
GlState.disableBlend();
float f3 = (float)(color >> 24 & 255) / 255.0F; GlState.enableAlpha();
float f = (float)(color >> 16 & 255) / 255.0F; GlState.enableTexture2D();
float f1 = (float)(color >> 8 & 255) / 255.0F; }
float f2 = (float)(color & 255) / 255.0F;
RenderBuffer worldrenderer = Tessellator.getBuffer(); public static void drawRect(int x, int y, int w, int h, int color)
{
RenderBuffer rb = Tessellator.getBuffer();
GlState.enableBlend(); GlState.enableBlend();
GlState.disableAlpha(); GlState.disableAlpha();
GlState.disableTexture2D(); GlState.disableTexture2D();
GlState.tryBlendFuncSeparate(770, 771, 1, 0); GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425); GlState.shadeModel(7425);
GlState.color(f, f1, f2, f3); GlState.color(color);
worldrenderer.begin(7, DefaultVertexFormats.POSITION); rb.begin(7, DefaultVertexFormats.POSITION);
worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex(); rb.pos((double)x, (double)(y + h), 0.0D).endVertex();
worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex(); rb.pos((double)(x + w), (double)(y + h), 0.0D).endVertex();
worldrenderer.pos((double)right, (double)top, 0.0D).endVertex(); rb.pos((double)(x + w), (double)y, 0.0D).endVertex();
worldrenderer.pos((double)left, (double)top, 0.0D).endVertex(); rb.pos((double)x, (double)y, 0.0D).endVertex();
Tessellator.draw(); Tessellator.draw();
GlState.shadeModel(7424); GlState.shadeModel(7424);
GlState.enableTexture2D(); GlState.enableTexture2D();
@ -463,77 +470,59 @@ public abstract class Drawing {
GlState.enableAlpha(); GlState.enableAlpha();
GlState.color(1.0f, 1.0f, 1.0f, 1.0f); GlState.color(1.0f, 1.0f, 1.0f, 1.0f);
} }
// public static void gfx_draw_rect(int x, int y, int w, int h, int border, int top, int bottom, int b_top, int b_bottom) { public static void drawBordered(int x, int y, int w, int h, int color, int border) {
// drawGradientRect(x, y, x + w, y + h, b_top, b_bottom); drawRect(x, y, w, h, border);
// drawGradientRect(x + border, y + border, x + w - border, y + h - border, top, bottom); drawRect(x + 1, y + 1, w - 2, h - 2, color);
// }
public static void drawRectColor(int x, int y, int w, int h, int color) {
drawRect(x, y, x + w, y + h, color);
} }
public static void drawGradient(int x, int y, int w, int h, int top, int bottom) {
drawGradientRect(x, y, x + w, y + h, top, bottom);
}
public static void drawRectBorder(int x, int y, int w, int h, int color, int border) {
drawRect(x, y, x + w, y + h, border);
drawRect(x + 1, y + 1, x + w - 1, y + h - 1, color);
}
// public static void drawRect2Border(int x, int y, int w, int h, int color, int border) {
// drawRect(x, y, x + w, y + h, border);
// drawRect(x + 2, y + 2, x + w - 2, y + h - 2, color);
// }
public static void drawRect2GradBorder(int x, int y, int w, int h, int color, int border, int lopleft, int topright, int btmleft, int btmright) { public static void drawRect2GradBorder(int x, int y, int w, int h, int color, int border, int lopleft, int topright, int btmleft, int btmright) {
drawRect(x, y, x + w, y + h, border); drawRect(x, y, w, h, border);
draw4GradientRect(x + 1, y + 1, x + w - 1, y + h - 1, lopleft, topright, btmleft, btmright); draw4Gradient(x + 1, y + 1, w - 2, h - 2, lopleft, topright, btmleft, btmright);
drawRect(x + 2, y + 2, x + w - 2, y + h - 2, color); drawRect(x + 2, y + 2, w - 4, h - 4, color);
} }
public static void drawGradient2GradBorder(int x, int y, int w, int h, int top, int bottom, int border, int lopleft, int topright, int btmleft, int btmright) { public static void drawGradient2GradBorder(int x, int y, int w, int h, int top, int bottom, int border, int lopleft, int topright, int btmleft, int btmright) {
drawRect(x, y, x + w, y + h, border); drawRect(x, y, w, h, border);
draw4GradientRect(x + 1, y + 1, x + w - 1, y + h - 1, lopleft, topright, btmleft, btmright); draw4Gradient(x + 1, y + 1, w - 2, h - 2, lopleft, topright, btmleft, btmright);
drawGradientRect(x + 2, y + 2, x + w - 2, y + h - 2, top, bottom); drawGradient(x + 2, y + 2, w - 4, h - 4, top, bottom);
} }
public static void drawGradient2Border(int x, int y, int w, int h, int top, int bottom, int b_top, int b_bottom) { public static void drawGradient2Border(int x, int y, int w, int h, int top, int bottom, int b_top, int b_bottom) {
drawGradientRect(x, y, x + w, y + h, b_top, b_bottom); drawGradient(x, y, w, h, b_top, b_bottom);
drawGradientRect(x + 1, y + 1, x + w - 1, y + h - 1, top, bottom); drawGradient(x + 1, y + 1, w - 2, h - 2, top, bottom);
} }
public static Vec2i getSize(String str) {
return txt_size(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str);
}
public static int getWidth(String str) { public static int getWidth(String str) {
return txt_size(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos; return getSize(str).xpos;
} }
public static int getBoxWidth(String str) { public static int getBoxWidth(String str) {
return txt_box(0, 0, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, str).xpos + 4; return getSize(str).xpos + 4;
} }
public static void drawTextbox(String str, int x, int y, int back) { public static void drawTextbox(String str, int x, int y, int back) {
Vec2i size = txt_box(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, str); Vec2i size = getSize(str);
drawRect(x, y, size.xpos + 2, size.ypos, back); drawRect(x, y, size.xpos + 4, size.ypos, back);
txt_draw(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, 0xffffffff, str); drawText(str, x + 2, y, 0xffffffff);
} }
public static void drawTextboxRight(String str, int x, int y, int back) { public static void drawTextboxRight(String str, int x, int y, int back) {
Vec2i size = getSize(str); drawTextbox(str, x - getBoxWidth(str), y, back);
drawTextbox(str, x - (size.xpos + 2), y, back);
} }
public static void drawTextboxCentered(String str, int x, int y, int back) { public static void drawTextboxCentered(String str, int x, int y, int back) {
Vec2i size = getSize(str); drawTextbox(str, x - getBoxWidth(str) / 2, y, back);
drawTextbox(str, x - (size.xpos + 2) / 2, y, back);
} }
public static void drawText(String str, int x, int y, int color) { public static void drawText(String str, int x, int y, int color) {
txt_draw(x, y, x, y, Integer.MAX_VALUE, Integer.MAX_VALUE, color, str); drawText(str, x, y, color, true);
}
public static void drawTextCenteredN(String str, int x, int y, int color) {
Vec2i size = getSize(str);
drawText(str, x - size.xpos / 2, y, color, false);
} }
public static void drawTextCentered(String str, int x, int y, int color) { public static void drawTextCentered(String str, int x, int y, int color) {
@ -551,11 +540,6 @@ public abstract class Drawing {
drawText(str, x - size.xpos / 2, y - size.ypos, color); drawText(str, x - size.xpos / 2, y - size.ypos, color);
} }
public static int mixColor(int c1, int c2) {
return ((((c1 >> 24 & 255) + (c2 >> 24 & 255)) / 2) << 24) | ((((c1 >> 16 & 255) + (c2 >> 16 & 255)) / 2) << 16) | ((((c1 >> 8 & 255) + (c2 >> 8 & 255)) / 2) << 8) |
(((c1 & 255) + (c2 & 255)) / 2);
}
public static void drawScaledBackground(Game gm, String texture) { public static void drawScaledBackground(Game gm, String texture) {
drawScaledBackground(gm, texture, 0, 0, gm.fb_x, gm.fb_y); drawScaledBackground(gm, texture, 0, 0, gm.fb_x, gm.fb_y);
} }

View file

@ -432,6 +432,14 @@ public class GlState
GL11.glColor4f(colorRed, colorGreen, colorBlue, colorAlpha); GL11.glColor4f(colorRed, colorGreen, colorBlue, colorAlpha);
} }
} }
public static void color(int c) {
float a = (float)(c >> 24 & 255) / 255.0F;
float r = (float)(c >> 16 & 255) / 255.0F;
float g = (float)(c >> 8 & 255) / 255.0F;
float b = (float)(c & 255) / 255.0F;
color(r, g, b, a);
}
public static void resetColor() public static void resetColor()
{ {

View file

@ -347,7 +347,7 @@ public abstract class Render<T extends Entity>
// i = -10; // i = -10;
// } // }
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, str); // Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, str);
// int j = size.xpos / 2; // int j = size.xpos / 2;
// GlState.disableTexture2D(); // GlState.disableTexture2D();
// worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); // worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);

View file

@ -104,7 +104,7 @@ public class TileEntitySignRenderer extends TileEntitySpecialRenderer<TileEntity
// { // {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glScalef(0.75f, 0.75f, 0.75f); GL11.glScalef(0.75f, 0.75f, 0.75f);
this.drawdString(s, -this.getdStringWidth(s) / 2, j * (Font.YGLYPH - 3) - 32); Drawing.drawTextCenteredN(s, 0, j * (Font.YGLYPH - 3) - 32, 0xff000000);
GL11.glPopMatrix(); GL11.glPopMatrix();
// } // }
} }
@ -124,11 +124,11 @@ public class TileEntitySignRenderer extends TileEntitySpecialRenderer<TileEntity
} }
private void drawdString(String text, int x, int y) { // private void drawdString(String text, int x, int y) {
Drawing.txt_draw(x, y, x, y, x + 400, y + 200, 0xff000000, text); // Drawing.drawText(text, x, y, 0xff000000, false);
} // TODO: signs // }
private int getdStringWidth(String text) { // private int getdStringWidth(String text) {
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, text); // Vec2i size = Drawing.getTextSize(text);
return size.xpos; // return size.xpos;
} // }
} }

View file

@ -282,4 +282,9 @@ int utf_len(const char *str) {
public static <T> String buildLines(T ... elems) { public static <T> String buildLines(T ... elems) {
return buildLines("\n", elems); return buildLines("\n", elems);
} }
public static int mixColor(int c1, int c2) {
return ((((c1 >> 24 & 255) + (c2 >> 24 & 255)) / 2) << 24) | ((((c1 >> 16 & 255) + (c2 >> 16 & 255)) / 2) << 16) | ((((c1 >> 8 & 255) + (c2 >> 8 & 255)) / 2) << 8) |
(((c1 & 255) + (c2 & 255)) / 2);
}
} }