package mcjty.rftools.blocks.screens.modulesclient;
import mcjty.lib.gui.widgets.Panel;
import mcjty.lib.varia.Coordinate;
import mcjty.rftools.blocks.screens.ModuleGuiChanged;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class EnergyBarClientScreenModule implements ClientScreenModule {
private String line = "";
private int color = 0xffffff;
private int rfcolor = 0xffffff;
private int rfcolorNeg = 0xffffff;
protected int dim = 0;
private boolean hidebar = false;
private boolean hidetext = false;
private boolean showdiff = false;
private boolean showpct = false;
private FormatStyle format = FormatStyle.MODE_FULL;
protected Coordinate coordinate = Coordinate.INVALID;
@Override
public TransformMode getTransformMode() {
return TransformMode.TEXT;
}
@Override
public int getHeight() {
return 10;
}
@Override
public void render(FontRenderer fontRenderer, int currenty, Object[] screenData, float factor) {
GL11.glDisable(GL11.GL_LIGHTING);
int xoffset;
if (!line.isEmpty()) {
fontRenderer.drawString(line, 7, currenty, color);
xoffset = 7 + 40;
} else {
xoffset = 7;
}
if (coordinate.isValid()) {
ClientScreenModuleHelper.renderLevel(fontRenderer, xoffset, currenty, screenData, "RF", hidebar, hidetext, showpct, showdiff, rfcolor, rfcolorNeg, 0xffff0000, 0xff333300, format);
} else {
fontRenderer.drawString("<invalid>", xoffset, currenty, 0xff0000);
}
}
@Override
public void mouseClick(World world, int x, int y, boolean clicked) {
}
@Override
public Panel createGui(Minecraft mc, Gui gui, final NBTTagCompound currentData, final ModuleGuiChanged moduleGuiChanged) {
return new ScreenModuleGuiBuilder(mc, gui, currentData, moduleGuiChanged).
label("Label:").text("text", "Label text").color("color", "Color for the label").nl().
label("RF+:").color("rfcolor", "Color for the RF text").label("RF-:").color("rfcolor_neg", "Color for the negative", "RF/tick ratio").nl().
toggleNegative("hidebar", "Bar", "Toggle visibility of the", "energy bar").mode("RF").format().nl().
label("Block:").monitor().nl().
build();
}
@Override
public void setupFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
if (tagCompound != null) {
line = tagCompound.getString("text");
if (tagCompound.hasKey("color")) {
color = tagCompound.getInteger("color");
} else {
color = 0xffffff;
}
if (tagCompound.hasKey("rfcolor")) {
rfcolor = tagCompound.getInteger("rfcolor");
} else {
rfcolor = 0xffffff;
}
if (tagCompound.hasKey("rfcolor_neg")) {
rfcolorNeg = tagCompound.getInteger("rfcolor_neg");
} else {
rfcolorNeg = 0xffffff;
}
hidebar = tagCompound.getBoolean("hidebar");
hidetext = tagCompound.getBoolean("hidetext");
showdiff = tagCompound.getBoolean("showdiff");
showpct = tagCompound.getBoolean("showpct");
format = FormatStyle.values()[tagCompound.getInteger("format")];
setupCoordinateFromNBT(tagCompound, dim, x, y, z);
}
}
protected void setupCoordinateFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
coordinate = Coordinate.INVALID;
if (tagCompound.hasKey("monitorx")) {
this.dim = tagCompound.getInteger("dim");
if (dim == this.dim) {
Coordinate c = new Coordinate(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
int dx = Math.abs(c.getX() - x);
int dy = Math.abs(c.getY() - y);
int dz = Math.abs(c.getZ() - z);
if (dx <= 64 && dy <= 64 && dz <= 64) {
coordinate = c;
}
}
}
}
@Override
public boolean needsServerData() {
return true;
}
}