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.drawRectColor(x, y + 20, 250, 10, 0xff000000);
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;
}
@ -744,7 +744,7 @@ public class Game implements IThreadListener {
// Drawing.drawRectColor(x, y + 20, 250, 10, 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.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;
}
@ -755,10 +755,8 @@ public class Game implements IThreadListener {
this.renderWorldDirections((float)Timing.tick_fraction);
}
else {
Drawing.drawRectColor(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32,
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);
Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - 16, 2, 32, 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);
}
}
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;
String current = itemstack != null ? itemstack.getItem().getHotbarText(this.thePlayer, itemstack) : "";
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)) {
int x = this.fb_x / 2;
@ -793,8 +791,7 @@ public class Game implements IThreadListener {
entity.getMaxHealth() + TextColor.GRAY + "]";
Drawing.drawTextboxCentered(s, x, y, 0x3f000000);
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.mixColor(entity.getColor() | 0xff000000, 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.drawRectColor(x - 200, y + 20, 400, 10, 0xff000000);
// Drawing.drawRectColor(x - 200, y + 20, , 0xff000000 | );
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 desc = TextColor.NEON + Potion.getDurationString(effect);
// 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.drawText(name, x + 2 + 2, y + 2, 0xffffffff);
Drawing.drawTextRight(desc, x + 250 - 2, y + 2, 0xffffffff);
Drawing.drawGradient2GradBorder(x, y, 250, Font.YGLYPH + 4, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000), 0xff202020, 0xffcfcfcf, 0xff9f9f9f, 0xff9f9f9f, 0xff6f6f6f);
Drawing.drawText(name, x + 4, y + 2, 0xffffffff);
Drawing.drawTextRight(desc, x + 250 - 4, y + 2, 0xffffffff);
y += 24;
}
}
@ -950,11 +947,7 @@ public class Game implements IThreadListener {
this.renderStats();
}
else {
String str = String.format("%s%.2f", framecode(), Timing.framerate);
Drawing.txt_draw(0, 0,
0, 0,
this.fb_x, this.fb_y,
0xffffffff, str);
Drawing.drawText(String.format("%s%.2f", framecode(), Timing.framerate), 0, 0, 0xffffffff);
}
}
GlState.enableBlend();
@ -994,10 +987,7 @@ public class Game implements IThreadListener {
// if(str)
// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str);
// gui_render_text(elem, 0, 0, sys.style.text_label, sys.work_buf);
Drawing.txt_draw(0, 0,
0, 0,
this.fb_x, this.fb_y,
0xffffffff, draw);
Drawing.drawText(draw, 0, 0, 0xffffffff);
str = this.getRight(false);
// str = jstr ? (*jsys.env)->GetStringUTFChars(jsys.env, jstr, NULL) : NULL;
@ -1008,8 +998,7 @@ public class Game implements IThreadListener {
sb.append('\n');
sb.append(perf.getName());
}
Drawing.txt_draw(x1 + 0, y1, x1 + 0, y1, x1 + 120, y2,
this.style.text_label, sb.toString());
Drawing.drawText(sb.toString(), x1 + 0, y1, 0xffffffff);
// pos = 0;
sb.setLength(0);
for(PerfSection perf : PerfSection.values()) {
@ -1017,8 +1006,7 @@ public class Game implements IThreadListener {
sb.append('\n');
sb.append(String.format("%.3f ms", (float)perf.getLast() / 1000.0f));
}
Drawing.txt_draw(x1 + 120, y1, x1 + 120, y1, x1 + 240, y2,
this.style.text_label, sb.toString());
Drawing.drawText(sb.toString(), x1 + 120, y1, 0xffffffff);
// pos = 0;
sb.setLength(0);
long total = PerfSection.getTotal(true);
@ -1027,12 +1015,10 @@ public class Game implements IThreadListener {
sb.append('\n');
sb.append(String.format("%.2f %%", ((float)perf.getLast() / (float)total) * 100.0f));
}
Drawing.txt_draw(x1 + 240, y1, x1 + 240, y1, x1 + 320, y2,
this.style.text_label, sb.toString());
Drawing.drawText(sb.toString(), x1 + 240, y1, 0xffffffff);
if(str != null) {
y1 = Font.YGLYPH * 10;
Drawing.txt_draw(x1, y1, x1, y1, x1 + 320, y1 + Font.YGLYPH * 12,
this.style.text_label, str);
Drawing.drawText(str, x1, y1, 0xffffffff);
// (*jsys.env)->ReleaseStringUTFChars(jsys.env, jstr, str);
}
}
@ -2992,7 +2978,7 @@ public class Game implements IThreadListener {
int y = 10 + by * Font.YGLYPH;
Drawing.drawGradient(x, y, 300, Font.YGLYPH, 0x7f404040, 0x7f000000);
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) {
bx = 0;
++by;

View file

@ -2,6 +2,8 @@ package game.color;
import java.util.regex.Pattern;
import game.util.Util;
public enum TextColor {
NULL(0x00),
RESET(0x01),
@ -50,10 +52,12 @@ public enum TextColor {
+ "\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[] SHADOW = new int[32];
private final String format;
public final char code;
public final int color;
public final int shadow;
public static String stripCodes(String text) {
return text == null ? null : STRIP_PATTERN.matcher(text).replaceAll("");
@ -63,6 +67,10 @@ public enum TextColor {
return code < COLORS.length ? COLORS[code] : 0x000000;
}
public static int getShadow(char code) {
return code < SHADOW.length ? SHADOW[code] : 0x000000;
}
private TextColor(int code) {
this(code, 0x000000);
}
@ -70,6 +78,7 @@ public enum TextColor {
private TextColor(int code, int color) {
this.format = Character.toString(this.code = (char)code);
this.color = color;
this.shadow = Util.mixColor(Util.mixColor(this.color, 0x000000), 0x000000);
}
public String toString() {
@ -78,8 +87,10 @@ public enum TextColor {
static {
for(TextColor color : values()) {
if(color.code < COLORS.length)
if(color.code < COLORS.length) {
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 getDefault(ScriptEnvironment env);
public abstract String[] getCompletions(ScriptEnvironment env);
public abstract Class<?> getTypeClass();
public final String getName() {
return this.name;

View file

@ -1,7 +1,11 @@
package game.command;
public class BooleanParser extends EnumParser {
public class BooleanParser extends EnumParser<Boolean> {
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;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
@ -11,12 +12,14 @@ public class CachedExecutable {
private final String name;
private final Map<String, Parameter> parameters;
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.parameters = parameters;
this.positionals = positionals;
this.name = executable.getName();
this.method = method;
}
public static CachedExecutable cacheExecutable(Executable executable) {
@ -39,13 +42,39 @@ public class CachedExecutable {
throw new NullPointerException("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() {
return this.executable;
}
public Method getMethod() {
return this.method;
}
public Map<String, Parameter> getParameters() {
return this.parameters;
}

View file

@ -11,4 +11,8 @@ public abstract class DefaultingParser extends CompletingParser {
public Object getDefault(ScriptEnvironment env) {
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) {
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);
}
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;
public class EnumParser extends DefaultingParser {
private final Map<String, Object> lookup = Maps.newHashMap();
private final Object[] selections;
public class EnumParser<T> extends DefaultingParser {
private final Class<T> clazz;
private final Map<String, T> lookup = Maps.newHashMap();
private final T[] selections;
private static <T> String joinArgs(T[] iter) {
StringBuilder sb = new StringBuilder("'");
@ -18,16 +19,17 @@ public class EnumParser extends DefaultingParser {
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);
this.clazz = clazz;
this.selections = selections;
for(Object o : selections) {
for(T o : selections) {
this.lookup.put(o.toString().toLowerCase(), o);
}
}
public Object parse(ScriptEnvironment env, String input) {
Object value = this.lookup.get(input.toLowerCase());
public T parse(ScriptEnvironment env, String input) {
T value = this.lookup.get(input.toLowerCase());
if(value != null)
return value;
int id = -1;
@ -41,4 +43,8 @@ public class EnumParser extends DefaultingParser {
joinArgs(this.selections));
return this.selections[id];
}
public Class<?> getTypeClass() {
return this.clazz;
}
}

View file

@ -1,9 +1,11 @@
package game.command;
import java.util.List;
import java.util.Map;
public interface Executable {
Object exec(ScriptEnvironment env, ScriptArgs args);
// Object exec(ScriptEnvironment env, ScriptArgs args);
Map<String, Parameter> getParameters();
List<Parameter> getParamList();
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);
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);
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 int position;
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.shortName = shortName;
this.position = position;
this.required = required;
this.parsers = parsers;
this.combiner = combiner;
}
public boolean isPositional() {
@ -29,6 +31,10 @@ public class Parameter {
return this.parsers;
}
public ArgCombiner<?> getCombiner() {
return this.combiner;
}
public boolean isRequired() {
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.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 {
private final String command;
private final Map<String, ScriptArg> arguments;
@ -126,6 +113,9 @@ public class ScriptArgs {
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());
for(ArgumentParser parser : param.getParsers()) {
params.put(parser.getName(), parser.getDefault(env));
@ -200,212 +190,222 @@ public class ScriptArgs {
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);
if(comp == null || comp.length == 0) {
Set<String> params = Sets.newTreeSet();
boolean all = last.startsWith("--");
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()]);
}
return comp;
}
public ScriptArg getArg(String name) {
return this.arguments.get(name);
}
// public ScriptArg getArg(String name) {
// return this.arguments.get(name);
// }
public boolean hasArg(String name) {
return this.arguments.containsKey(name);
}
public boolean has(String name, String par) {
return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
}
// public boolean has(String name, String par) {
// return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
// }
public boolean has(String name) {
return this.has(name, name);
}
// public boolean has(String name) {
// return this.has(name, name);
// }
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 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) {
return this.getDefault(name, par, null);
ScriptArg arg = this.arguments.get(name);
if(arg == null)
return null;
Object value = arg.getValues().get(par);
return value == null ? null : (T)value;
}
public <T> T getUnchecked(String name) {
return this.getDefault(name, null);
}
public boolean getBool(String name, boolean def) {
return this.getDefault(name, def);
}
public boolean getBool(String name) {
return this.getUnchecked(name);
}
public <T extends Enum<?>> T getEnum(String name, T def) {
return this.getDefault(name, def);
}
public <T extends Enum<?>> T getEnum(String name) {
return this.getUnchecked(name);
}
public int getInt(String name, int def) {
return this.getDefault(name, def);
}
public int getInt(String name) {
return this.getUnchecked(name);
}
public long getLong(String name, long def) {
return this.getDefault(name, def);
}
public long getLong(String name) {
return this.getUnchecked(name);
}
public double getDouble(String name, double def) {
return this.getDefault(name, def);
}
public double getDouble(String name) {
return this.getUnchecked(name);
}
public String getString(String name, String def) {
return this.getDefault(name, def);
}
public String getString(String name) {
return this.getUnchecked(name);
}
public String[] getStrings(String name, String[] def) {
return this.getDefault(name, def);
}
public String[] getStrings(String name) {
return this.getUnchecked(name);
}
public Entity getEntity(String name, Entity def) {
return this.getDefault(name, def);
}
public Entity getEntity(String name) {
return this.getUnchecked(name);
}
public EntityLiving getLiving(String name, EntityLiving def) {
return this.getDefault(name, def);
}
public EntityLiving getLiving(String name) {
return this.getUnchecked(name);
}
public EntityNPC getNpc(String name, EntityNPC def) {
return this.getDefault(name, def);
}
public EntityNPC getNpc(String name) {
return this.getUnchecked(name);
}
public Block getBlock(String name, Block def) {
return this.getDefault(name, def);
}
public Block getBlock(String name) {
return this.getUnchecked(name);
}
public State getState(String name, State def) {
return this.getDefault(name, def);
}
public State getState(String name) {
return this.getUnchecked(name);
}
public Item getItem(String name, Item def) {
return this.getDefault(name, def);
}
public Item getItem(String name) {
return this.getUnchecked(name);
}
public ItemStack getStack(String name, ItemStack def) {
return this.getDefault(name, def);
}
public ItemStack getStack(String name) {
return this.getUnchecked(name);
}
public BlockPos getColumnPos(String name, BlockPos def) {
return this.hasArg(name) ? this.getColumnPos(name) : def;
}
public BlockPos getColumnPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
}
public BlockPos getBlockPos(String name, BlockPos def) {
return this.hasArg(name) ? this.getBlockPos(name) : def;
}
public BlockPos getBlockPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
}
public WorldPos getWorldPos(String name, WorldPos def) {
return this.hasArg(name) ? this.getWorldPos(name) : def;
}
public WorldPos getWorldPos(String name) {
return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
this.getUnchecked(name, "dim"));
}
public Vec3 getVector2D(String name, Vec3 def) {
return this.hasArg(name) ? this.getVector2D(name) : def;
}
public Vec3 getVector2D(String name) {
return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
}
public Vec3 getVector(String name, Vec3 def) {
return this.hasArg(name) ? this.getVector(name) : def;
}
public Vec3 getVector(String name) {
return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
}
public WorldServer getWorld(String name) {
return this.getUnchecked(name);
}
public NBTTagCompound getTag(String name) {
return this.getUnchecked(name);
}
// public <T> T getUnchecked(String name) {
// return this.getDefault(name, null);
// }
//
// public boolean getBool(String name, boolean def) {
// return this.getDefault(name, def);
// }
//
// public boolean getBool(String name) {
// return this.getUnchecked(name);
// }
//
// public <T extends Enum<?>> T getEnum(String name, T def) {
// return this.getDefault(name, def);
// }
//
// public <T extends Enum<?>> T getEnum(String name) {
// return this.getUnchecked(name);
// }
//
// public int getInt(String name, int def) {
// return this.getDefault(name, def);
// }
//
// public int getInt(String name) {
// return this.getUnchecked(name);
// }
//
// public long getLong(String name, long def) {
// return this.getDefault(name, def);
// }
//
// public long getLong(String name) {
// return this.getUnchecked(name);
// }
//
// public double getDouble(String name, double def) {
// return this.getDefault(name, def);
// }
//
// public double getDouble(String name) {
// return this.getUnchecked(name);
// }
//
// public String getString(String name, String def) {
// return this.getDefault(name, def);
// }
//
// public String getString(String name) {
// return this.getUnchecked(name);
// }
//
// public String[] getStrings(String name, String[] def) {
// return this.getDefault(name, def);
// }
//
// public String[] getStrings(String name) {
// return this.getUnchecked(name);
// }
//
// public Entity getEntity(String name, Entity def) {
// return this.getDefault(name, def);
// }
//
// public Entity getEntity(String name) {
// return this.getUnchecked(name);
// }
//
// public EntityLiving getLiving(String name, EntityLiving def) {
// return this.getDefault(name, def);
// }
//
// public EntityLiving getLiving(String name) {
// return this.getUnchecked(name);
// }
//
// public EntityNPC getNpc(String name, EntityNPC def) {
// return this.getDefault(name, def);
// }
//
// public EntityNPC getNpc(String name) {
// return this.getUnchecked(name);
// }
//
// public Block getBlock(String name, Block def) {
// return this.getDefault(name, def);
// }
//
// public Block getBlock(String name) {
// return this.getUnchecked(name);
// }
//
// public State getState(String name, State def) {
// return this.getDefault(name, def);
// }
//
// public State getState(String name) {
// return this.getUnchecked(name);
// }
//
// public Item getItem(String name, Item def) {
// return this.getDefault(name, def);
// }
//
// public Item getItem(String name) {
// return this.getUnchecked(name);
// }
//
// public ItemStack getStack(String name, ItemStack def) {
// return this.getDefault(name, def);
// }
//
// public ItemStack getStack(String name) {
// return this.getUnchecked(name);
// }
//
// public BlockPos getColumnPos(String name, BlockPos def) {
// return this.hasArg(name) ? this.getColumnPos(name) : def;
// }
//
// public BlockPos getColumnPos(String name) {
// return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
// }
//
// public BlockPos getBlockPos(String name, BlockPos def) {
// return this.hasArg(name) ? this.getBlockPos(name) : def;
// }
//
// public BlockPos getBlockPos(String name) {
// return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
// }
//
// public WorldPos getWorldPos(String name, WorldPos def) {
// return this.hasArg(name) ? this.getWorldPos(name) : def;
// }
//
// public WorldPos getWorldPos(String name) {
// return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
// this.getUnchecked(name, "dim"));
// }
//
// public Vec3 getVector2D(String name, Vec3 def) {
// return this.hasArg(name) ? this.getVector2D(name) : def;
// }
//
// public Vec3 getVector2D(String name) {
// return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
// }
//
// public Vec3 getVector(String name, Vec3 def) {
// return this.hasArg(name) ? this.getVector(name) : def;
// }
//
// public Vec3 getVector(String name) {
// return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
// }
//
// 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;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@ -10,6 +12,7 @@ import com.google.common.collect.Maps;
import game.Server;
import game.color.TextColor;
import game.command.commands.CommandSpawn;
import game.log.Log;
public class ScriptEnvironment {
private final Server server;
@ -80,7 +83,36 @@ public class ScriptEnvironment {
if(cached == null)
throw new ScriptException("Skript '%s' existiert nicht", argv[0]);
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)
this.previousOutput = o;
}
@ -102,6 +134,7 @@ public class ScriptEnvironment {
}
catch(Throwable t) {
exec.logConsole(TextColor.RED + "Fehler: %s", t.getMessage());
Log.CONSOLE.error(t, "Fehler beim Ausführen von Befehl '%s'", cmd);
}
finally {
this.currentExecutor = null;
@ -118,17 +151,17 @@ public class ScriptEnvironment {
String[] argv = cmds[cmds.length - 1];
if(argv.length == 0)
return list;
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
String[] comp;
if(argv.length > 1) {
CachedExecutable cached = this.executables.get(argv[0]);
if(cached == null)
return list;
comp = ScriptArgs.parseComplete(this, argv, cached);
comp = ScriptArgs.parseComplete(this, argv, cached, param);
}
else {
comp = this.executables.keySet().toArray(new String[this.executables.keySet().size()]);
}
String param = cmd.endsWith(" ") ? "" : argv[argv.length - 1];
for(String cmp : comp) {
if(cmp.regionMatches(true, 0, param, 0, param.length()))
list.add(cmp);

View file

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

View file

@ -1,14 +1,14 @@
package game.command;
import com.google.common.base.Predicate;
import game.util.CharValidator;
public class StringParser extends DefaultingParser {
private final boolean allowEmpty;
private final Integer minLength;
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) {
super(name, def, completions);
this.allowEmpty = allowEmpty;
@ -34,6 +34,12 @@ public class StringParser extends DefaultingParser {
else
throw new ScriptException("Die Zeichenkette darf höchstens %d Zeichen lang sein, habe %d ('%s')",
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;
}
public Class<?> getTypeClass() {
return String.class;
}
}

View file

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

View file

@ -41,4 +41,8 @@ public class WorldParser extends DimensionParser {
}
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 game.command.ScriptArgs;
import game.command.ScriptEnvironment;
import game.command.ScriptException;
import game.command.ScriptExecutable;
import game.command.ScriptExecutor;
import game.entity.Entity;
import game.entity.types.EntityLiving;
import game.init.EntityRegistry;
@ -18,28 +18,23 @@ import game.world.WorldServer;
public class CommandSpawn extends ScriptExecutable {
public CommandSpawn() {
super("spawn");
Set<String> names = Sets.newTreeSet();
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
names.add(EntityRegistry.getEntityString(clazz));
}
this.addEnum("type", names);
this.addEnum("type", String.class, names);
this.setParamsOptional();
this.addVector("position", true);
this.addWorld("dim", true);
this.addTag("tag");
this.addFlag("noinit");
this.addFlag("noinit", 'n');
this.addInt("count", 'c', 1, 1024, 1);
this.addTag("postTag", 'p');
}
public Object exec(ScriptEnvironment env, ScriptArgs args) {
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");
public Object exec(ScriptEnvironment env, ScriptExecutor exec, String type, Vec3 pos, WorldServer world, NBTTagCompound tag, boolean noinit, int count, NBTTagCompound postTag) {
for(int z = 0; z < count; z++) {
Entity entity = EntityRegistry.createEntityByName(type, world);
if(entity == null)
@ -51,7 +46,7 @@ public class CommandSpawn extends ScriptExecutable {
ent.merge(tag);
entity.readFromNBT(ent);
}
if(init && (entity instanceof EntityLiving))
if(!noinit && (entity instanceof EntityLiving))
((EntityLiving)entity).onInitialSpawn(null);
world.spawnEntityInWorld(entity);
if(postTag != null) {
@ -61,7 +56,7 @@ public class CommandSpawn extends ScriptExecutable {
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;
}
}

View file

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

View file

@ -77,7 +77,7 @@ public class GuiMenu extends Gui {
}, "Info / Über / Mitwirkende") {
public void drawHover() {
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));
int width = Drawing.getWidth("Hax!");
for(int z = 0; z < 64; z++) {
@ -314,10 +314,10 @@ public class GuiMenu extends Gui {
int y = 164;
int h = 16;
int n = Drawing.getWidth(this.splashLabel.getText());
Drawing.drawRectColor(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff);
Drawing.drawRectColor(this.gm.fb_x / 2 + n / 2 + 10, y, this.gm.fb_x - (this.gm.fb_x / 2 + n / 2 + 10), h, 0x7f7f00ff);
Drawing.drawText(this.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack) - 2, this.gm.fb_y - 18, 0xffffffff);
Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
Drawing.drawRect(0, y, 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), this.gm.fb_y - 18, 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)
{
// 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);
// int k1 = mouseX - x;
// int l1 = mouseY - y;
@ -248,7 +248,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
// 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) {

View file

@ -120,16 +120,15 @@ public abstract class GuiContainer extends Gui
public void drawString(String text, int x, int y) {
x = x * 2 + this.container_x;
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) {
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, text);
return size.xpos / 2;
return Drawing.getSize(text).xpos / 2;
}
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) {
@ -1087,12 +1086,12 @@ public abstract class GuiContainer extends Gui
s = TextColor.RED + ItemStack.formatAmount(stack.stackSize);
}
// this.drawString(s, , );
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s);
int x = xPosition + 34 - size.xpos; // this.getStringWidth(s);
int y = yPosition + 17;
// Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s);
// int x = - size.xpos; // this.getStringWidth(s);
// int y = ;
// x = x * 2 + this.container_x;
// 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())
@ -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)
{
// 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() {

View file

@ -2,6 +2,7 @@ package game.gui.element;
import game.renderer.Drawing;
import game.util.ExtMath;
import game.util.Util;
public class Bar extends Fill {
private int color = 0x00ff00;
@ -25,7 +26,7 @@ public class Bar extends Fill {
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);
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) {

View file

@ -23,16 +23,15 @@ public class Dropdown<T> extends Element {
}
public void updateText() {
this.r_dirty = true;
}
protected boolean isTextCenteredX() {
return false;
}
protected boolean isTextCenteredY() {
return false;
}
// protected boolean isTextCenteredX() {
// return false;
// }
//
// protected boolean isTextCenteredY() {
// return false;
// }
public boolean canClick() {
return false;
@ -60,10 +59,7 @@ public class Dropdown<T> extends Element {
public void drawHover() {
int m = ((this.gm.mouse_y - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2)));
// if((sys.mouse_y - this.pos_y) < (this.size_y - this.margin_y2))
Drawing.drawRectColor(this.pos_x + this.margin_x1,
this.pos_y + this.margin_y1 + ExtMath.clampi(m, 0, Dropdown.this.values.length - 1) * ((this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length),
this.size_x - (this.margin_x1 + this.margin_x2),
(this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length, this.gm.style.hover);
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);
}
}

View file

@ -33,8 +33,6 @@ public abstract class Element {
protected int size_y;
protected int text_x = 0;
protected int text_y = 0;
protected int tsize_x = 0;
protected int tsize_y = 0;
protected final int margin_x1 = this.getMargin();
protected final int margin_y1 = this.getMargin();
@ -87,17 +85,17 @@ public abstract class Element {
return this.size_y;
}
protected boolean isTextCenteredX() {
return true;
}
// protected boolean isTextCenteredX() {
// return true;
// }
//
// protected boolean isTextCenteredY() {
// return true;
// }
protected boolean isTextCenteredY() {
return true;
}
protected boolean hasLinebreak() {
return false;
}
// protected boolean hasLinebreak() {
// return false;
// }
public boolean canHover() {
return true;
@ -116,22 +114,9 @@ public abstract class Element {
}
public void updateText() {
Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.hasLinebreak() ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text);
this.tsize_x = size.xpos;
this.tsize_y = size.ypos;
// if(this.type != ElemType.FIELD) {
if(this.isTextCenteredX())
this.text_x = (this.size_x - this.tsize_x) / 2;
if(this.isTextCenteredY())
this.text_y = (this.size_y - this.tsize_y - Font.YGLYPH) / 2;
// }
// logd("DBG", "s = %d %d; o = %d %d", this.tsize_x, this.tsize_y, this.text_x, this.text_y);
// gui_update_dropdown();
if(this.gui != null && this.gui.selected instanceof Handle && this.gui.selected.visible)
this.gui.selected.r_dirty = true;
this.r_dirty = true;
Vec2i size = Drawing.getSize(this.text);
this.text_x = (this.size_x - size.xpos) / 2;
this.text_y = (this.size_y - size.ypos) / 2;
}
public void setText(String str) {
@ -273,11 +258,11 @@ public abstract class Element {
}
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() {
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() {

View file

@ -1,5 +1,8 @@
package game.gui.element;
import game.renderer.Drawing;
import game.renderer.Drawing.Vec2i;
public class Fill extends Element {
private final boolean left;
private final boolean top;
@ -36,11 +39,19 @@ public class Fill extends Element {
return false;
}
protected boolean isTextCenteredX() {
return !this.left;
}
// protected boolean isTextCenteredX() {
// return !this.left;
// }
//
// protected boolean isTextCenteredY() {
// return !this.top;
// }
protected boolean isTextCenteredY() {
return !this.top;
public void updateText() {
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;
this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover);
if(hover)
Drawing.drawRectColor(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), this.gm.style.hover);
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 game.gui.Font;
import game.gui.element.Dropdown.Handle;
import game.renderer.Drawing;
import game.renderer.Drawing.Offset;
import game.renderer.Drawing.Vec2i;
@ -38,6 +39,8 @@ public class Textbox extends Element {
private int sel_drag = -1;
private int cursorX = 0;
private int cursorY = 0;
private int tsize_x = 0;
private int tsize_y = 0;
private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) {
super(x, y, w, h, null);
@ -71,16 +74,24 @@ public class Textbox extends Element {
// this.editable = editable;
// }
protected boolean isTextCenteredX() {
return false;
}
// protected boolean isTextCenteredX() {
// return false;
// }
//
// protected boolean isTextCenteredY() {
// return false;
// }
protected boolean isTextCenteredY() {
return false;
}
// protected boolean hasLinebreak() {
// return this.xbreak;
// }
protected boolean hasLinebreak() {
return this.xbreak;
public void updateText() {
Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.xbreak ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text);
this.tsize_x = size.xpos;
this.tsize_y = size.ypos;
}
public boolean canHover() {
@ -420,7 +431,7 @@ public class Textbox extends Element {
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.gm.style.text_field, this.text);
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
Drawing.txt_draw_range(this.sel_start, this.sel_end, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.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);
GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
Drawing.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);
}
}
@ -466,8 +477,11 @@ public class Textbox extends Element {
s = s + this.text.substring(j);
}
this.setText(s);
// this.text = s;
// this.setText(s);
this.text = s;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = i;
gui_text_update_cur(this.sel_start, true);
//
// if(flag) {
// this.moveCursorBy(num);

View file

@ -608,7 +608,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
{
super.drawOverlays();
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 - 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);

View file

@ -5,6 +5,7 @@ import game.color.TextColor;
import game.gui.Font;
import game.gui.FontChar;
import game.log.Log;
import game.util.Util;
public abstract class Drawing {
public static class Vec2i {
@ -26,11 +27,6 @@ public abstract class Drawing {
}
}
// 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)
// {
// float xs = 1.0f / (float)tw; // 0.00390625F;
@ -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 + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).endVertex();
// 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) {
@ -88,7 +55,6 @@ public abstract class Drawing {
FontChar glyph;
char ch;
int ncolor = color;
// color(color);
for(int z = 0; z < str.length(); z++) {
ch = str.charAt(z);
if(ch == Log.CHR_NLN) {
@ -96,19 +62,11 @@ public abstract class Drawing {
y += h;
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)) {
// color(TextColor.getColor(ch) | (color & 0xff000000));
ncolor = TextColor.getColor(ch) | (color & 0xff000000);
continue;
}
// else if(ch == Log.CHR_FRESET) {
// continue;
// }
else if(ch == Log.CHR_CRESET) {
// color(color);
ncolor = color;
continue;
}
@ -128,7 +86,7 @@ public abstract class Drawing {
if(x < x1 || y < y1 || x > x2 || y > y2) {
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;
}
Tessellator.draw();
@ -138,7 +96,7 @@ public abstract class Drawing {
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 tx, ty, u, v;
FontChar glyph;
@ -186,7 +144,7 @@ public abstract class Drawing {
// shd.setVec2("size", (float)u, (float)v);
// shd.setVec4("glyph", (float)glyph.s, 0.0f, (float)glyph.u, (float)h);
// shd.draw();
drawRect(x, y, x + u, y + v, back);
drawRect(x, y, u, v, back);
}
x += u;
}
@ -231,45 +189,6 @@ public abstract class Drawing {
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) {
int h = Font.YGLYPH;
int tx, ty, u, v;
@ -369,42 +288,128 @@ public abstract class Drawing {
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 rt = (float)(ctop >> 16 & 255) / 255.0F;
float gt = (float)(ctop >> 8 & 255) / 255.0F;
float bt = (float)(ctop & 255) / 255.0F;
float ab = (float)(cbottom >> 24 & 255) / 255.0F;
float rb = (float)(cbottom >> 16 & 255) / 255.0F;
float gb = (float)(cbottom >> 8 & 255) / 255.0F;
float bb = (float)(cbottom & 255) / 255.0F;
GlState.disableTexture2D();
float xs = 1.0f / (float)tw;
float ys = 1.0f / (float)th;
rb.pos((double)(x + 0), (double)(y + height), depth).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
rb.pos((double)(x + width), (double)(y + height), depth).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + height) * ys)).color(color).endVertex();
rb.pos((double)(x + width), (double)(y + 0), depth).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
rb.pos((double)(x + 0), (double)(y + 0), depth).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).color(color).endVertex();
}
public static void drawText(String str, int x, int y, int color, boolean shadow) {
GlState.enableTexture2D();
GlState.enableBlend();
GlState.disableAlpha();
GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425);
RenderBuffer buf = Tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_COLOR);
buf.pos((double)right, (double)top, 0.0).color(rt, gt, bt, at).endVertex();
buf.pos((double)left, (double)top, 0.0).color(rt, gt, bt, at).endVertex();
buf.pos((double)left, (double)bottom, 0.0).color(rb, gb, bb, ab).endVertex();
buf.pos((double)right, (double)bottom, 0.0).color(rb, gb, bb, ab).endVertex();
GlState.color(1.0f, 1.0f, 1.0f, 1.0f);
Font.bindTexture();
RenderBuffer rb = Tessellator.getBuffer();
rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
int ox = x;
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();
GlState.shadeModel(7424);
GlState.disableBlend();
GlState.enableAlpha();
GlState.enableTexture2D();
}
}
public static void draw4GradientRect(int left, int top, int right, int bottom, int lopleft, int topright, int btmleft, int btmright)
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 drawGradient(int x, int y, int w, int h, int ctop, int cbottom)
{
GlState.disableTexture2D();
GlState.enableBlend();
@ -413,10 +418,10 @@ public abstract class Drawing {
GlState.shadeModel(7425);
RenderBuffer buf = Tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_COLOR);
buf.pos((double)right, (double)top, 0.0).color(topright).endVertex();
buf.pos((double)left, (double)top, 0.0).color(lopleft).endVertex();
buf.pos((double)left, (double)bottom, 0.0).color(btmleft).endVertex();
buf.pos((double)right, (double)bottom, 0.0).color(btmright).endVertex();
buf.pos((double)(x + w), (double)y, 0.0).color(ctop).endVertex();
buf.pos((double)x, (double)y, 0.0).color(ctop).endVertex();
buf.pos((double)x, (double)(y + h), 0.0).color(cbottom).endVertex();
buf.pos((double)(x + w), (double)(y + h), 0.0).color(cbottom).endVertex();
Tessellator.draw();
GlState.shadeModel(7424);
GlState.disableBlend();
@ -424,38 +429,40 @@ public abstract class Drawing {
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)
{
int i = left;
left = right;
right = i;
}
GlState.disableTexture2D();
GlState.enableBlend();
GlState.disableAlpha();
GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425);
RenderBuffer buf = Tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_COLOR);
buf.pos((double)(x + w), (double)y, 0.0).color(topright).endVertex();
buf.pos((double)x, (double)y, 0.0).color(lopleft).endVertex();
buf.pos((double)x, (double)(y + h), 0.0).color(btmleft).endVertex();
buf.pos((double)(x + w), (double)(y + h), 0.0).color(btmright).endVertex();
Tessellator.draw();
GlState.shadeModel(7424);
GlState.disableBlend();
GlState.enableAlpha();
GlState.enableTexture2D();
}
if (top < bottom)
{
int j = top;
top = bottom;
bottom = j;
}
float f3 = (float)(color >> 24 & 255) / 255.0F;
float f = (float)(color >> 16 & 255) / 255.0F;
float f1 = (float)(color >> 8 & 255) / 255.0F;
float f2 = (float)(color & 255) / 255.0F;
RenderBuffer worldrenderer = Tessellator.getBuffer();
public static void drawRect(int x, int y, int w, int h, int color)
{
RenderBuffer rb = Tessellator.getBuffer();
GlState.enableBlend();
GlState.disableAlpha();
GlState.disableTexture2D();
GlState.tryBlendFuncSeparate(770, 771, 1, 0);
GlState.shadeModel(7425);
GlState.color(f, f1, f2, f3);
worldrenderer.begin(7, DefaultVertexFormats.POSITION);
worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex();
worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex();
worldrenderer.pos((double)right, (double)top, 0.0D).endVertex();
worldrenderer.pos((double)left, (double)top, 0.0D).endVertex();
GlState.color(color);
rb.begin(7, DefaultVertexFormats.POSITION);
rb.pos((double)x, (double)(y + h), 0.0D).endVertex();
rb.pos((double)(x + w), (double)(y + h), 0.0D).endVertex();
rb.pos((double)(x + w), (double)y, 0.0D).endVertex();
rb.pos((double)x, (double)y, 0.0D).endVertex();
Tessellator.draw();
GlState.shadeModel(7424);
GlState.enableTexture2D();
@ -464,76 +471,58 @@ public abstract class Drawing {
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) {
// drawGradientRect(x, y, x + w, y + h, b_top, b_bottom);
// drawGradientRect(x + border, y + border, x + w - border, y + h - border, top, bottom);
// }
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 drawBordered(int x, int y, int w, int h, int color, int border) {
drawRect(x, y, w, h, border);
drawRect(x + 1, y + 1, w - 2, h - 2, 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) {
drawRect(x, y, x + w, y + h, border);
draw4GradientRect(x + 1, y + 1, x + w - 1, y + h - 1, lopleft, topright, btmleft, btmright);
drawRect(x + 2, y + 2, x + w - 2, y + h - 2, color);
drawRect(x, y, w, h, border);
draw4Gradient(x + 1, y + 1, w - 2, h - 2, lopleft, topright, btmleft, btmright);
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) {
drawRect(x, y, x + w, y + h, border);
draw4GradientRect(x + 1, y + 1, x + w - 1, y + h - 1, lopleft, topright, btmleft, btmright);
drawGradientRect(x + 2, y + 2, x + w - 2, y + h - 2, top, bottom);
drawRect(x, y, w, h, border);
draw4Gradient(x + 1, y + 1, w - 2, h - 2, lopleft, topright, btmleft, btmright);
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) {
drawGradientRect(x, y, x + w, y + h, b_top, b_bottom);
drawGradientRect(x + 1, y + 1, x + w - 1, y + h - 1, top, bottom);
drawGradient(x, y, w, h, b_top, b_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) {
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) {
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) {
Vec2i size = txt_box(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, str);
drawRect(x, y, size.xpos + 2, size.ypos, back);
txt_draw(x + 2, y, x + 2, y, Integer.MAX_VALUE, Integer.MAX_VALUE, 0xffffffff, str);
Vec2i size = getSize(str);
drawRect(x, y, size.xpos + 4, size.ypos, back);
drawText(str, x + 2, y, 0xffffffff);
}
public static void drawTextboxRight(String str, int x, int y, int back) {
Vec2i size = getSize(str);
drawTextbox(str, x - (size.xpos + 2), y, back);
drawTextbox(str, x - getBoxWidth(str), y, back);
}
public static void drawTextboxCentered(String str, int x, int y, int back) {
Vec2i size = getSize(str);
drawTextbox(str, x - (size.xpos + 2) / 2, y, back);
drawTextbox(str, x - getBoxWidth(str) / 2, y, back);
}
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) {
@ -551,11 +540,6 @@ public abstract class Drawing {
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) {
drawScaledBackground(gm, texture, 0, 0, gm.fb_x, gm.fb_y);
}

View file

@ -433,6 +433,14 @@ public class GlState
}
}
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()
{
colorState.red = colorState.green = colorState.blue = colorState.alpha = -1.0F;

View file

@ -347,7 +347,7 @@ public abstract class Render<T extends Entity>
// 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;
// GlState.disableTexture2D();
// worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);

View file

@ -104,7 +104,7 @@ public class TileEntitySignRenderer extends TileEntitySpecialRenderer<TileEntity
// {
GL11.glPushMatrix();
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();
// }
}
@ -124,11 +124,11 @@ public class TileEntitySignRenderer extends TileEntitySpecialRenderer<TileEntity
}
private void drawdString(String text, int x, int y) {
Drawing.txt_draw(x, y, x, y, x + 400, y + 200, 0xff000000, text);
} // TODO: signs
private int getdStringWidth(String text) {
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, text);
return size.xpos;
}
// private void drawdString(String text, int x, int y) {
// Drawing.drawText(text, x, y, 0xff000000, false);
// }
// private int getdStringWidth(String text) {
// Vec2i size = Drawing.getTextSize(text);
// return size.xpos;
// }
}

View file

@ -282,4 +282,9 @@ int utf_len(const char *str) {
public static <T> String buildLines(T ... 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);
}
}