Got the encoder to scale with the screen resolution

Took a lot of remembering how to do this unity than translating that to
java minecraft. As well to calculate the correct translation base on the
fact that my gui is scaled by .52 of a normal one.
This commit is contained in:
DarkGuardsman 2013-10-24 16:02:48 -04:00
parent 4de3b2ab39
commit 7baf08872d
4 changed files with 73 additions and 52 deletions

View file

@ -10,6 +10,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.client.gui.GuiEncoderCoder;
import dark.assembly.client.gui.GuiEncoderHelp;
import dark.assembly.client.gui.GuiEncoderInventory;
import dark.assembly.client.gui.GuiImprinter;
import dark.assembly.client.gui.GuiProcessor;
@ -81,7 +82,7 @@ public class ClientProxy extends CommonProxy
}
case GUI_ENCODER_HELP:
{
return new GuiEncoderCoder(player, (TileEntityEncoder) tileEntity);
return new GuiEncoderHelp(player, (TileEntityEncoder) tileEntity);
}
case GUI_PROCESSOR:
{

View file

@ -24,7 +24,7 @@ public class GuiEncoderCoder extends GuiEncoderBase
{
if (taskListGui == null)
{
taskListGui = new GuiTaskList((this.width - this.xSize) / 2 + 20, (this.height - this.ySize) / 2 + 40);
taskListGui = new GuiTaskList();
}
super.drawBackgroundLayer(x, y, var1);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_CODE_BACK);
@ -34,7 +34,7 @@ public class GuiEncoderCoder extends GuiEncoderBase
int containerWidth = (this.width - this.xSize) / 2;
int containerHeight = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
taskListGui.drawConsole(this.fontRenderer);
taskListGui.drawConsole(this.mc, (this.width - this.xSize) / 2 + 20, (this.height - this.ySize) / 2 + 40);
}
}

View file

@ -81,7 +81,7 @@ public abstract class GuiEncoderContainer extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
this.fontRenderer.drawString("\u00a77" + "encoder", (int) (this.xSize / 2 - 7 * 2.5), 4, 4210752);
this.fontRenderer.drawString("\u00a77" + "Encoder", (int) (this.xSize / 2 - 7 * 2.5), 4, 4210752);
/** Render Tool Tips */
if (((GuiButtonImage) this.buttonList.get(0)).isIntersect(x, y))

View file

@ -1,7 +1,9 @@
package dark.assembly.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
@ -17,31 +19,32 @@ import dark.assembly.common.armbot.Program;
import dark.assembly.common.armbot.command.TaskGive;
import dark.core.interfaces.IScroll;
/** Not a gui itself but a component used to display task as a box inside of a gui
*
* @author DarkGuardsman */
public class GuiTaskList extends Gui implements IScroll
{
protected IProgram program;
protected int scroll = 0;
/** The x position of this control. */
public int xPosition;
/** The y position of this control. */
public int yPosition;
/** The string displayed on this control. */
public String displayString;
public static final ResourceLocation TEXTURE_PROCESS = new ResourceLocation(AssemblyLine.instance.DOMAIN, AssemblyLine.GUI_DIRECTORY + "PROCESS.png");
public GuiTaskList(int x, int y)
public GuiTaskList()
{
this.xPosition = x;
this.yPosition = y;
program = new Program();
program.setTaskAt(new Vector2(0, 0), new TaskGive());
program.setTaskAt(new Vector2(0, 1), new TaskGive());
program.setTaskAt(new Vector2(0, 2), new TaskGive());
program.setTaskAt(new Vector2(0, 3), new TaskGive());
program.setTaskAt(new Vector2(0, 4), new TaskGive());
program.setTaskAt(new Vector2(0, 5), new TaskGive());
program.setTaskAt(new Vector2(0, 6), new TaskGive());
program.setTaskAt(new Vector2(0, 7), new TaskGive());
program.setTaskAt(new Vector2(0, 8), new TaskGive());
program.setTaskAt(new Vector2(0, 9), new TaskGive());
program.init(null);
}
@ -69,57 +72,74 @@ public class GuiTaskList extends Gui implements IScroll
return this.scroll;
}
public void drawConsole(FontRenderer fontRenderer)
public void drawConsole(Minecraft minecraft, int x, int y)
{
int spacing = 10;
int spacingY = 25;
int spacingX = 25;
int color = 14737632;
GL11.glPushMatrix();
float scale = 0.92f;
//With everything scaled the gui will not align like a normal one so use a scaled distance from the main GUI
float scale = 0.52f;
ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
int scaleH = scaledresolution.getScaledHeight();
int scaleW = scaledresolution.getScaledWidth();
this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, color);
int desiredH = 240;
int desiredW = 427;
float sh = (scaleH / desiredH) / scale;
float sW = (scaleW / desiredW) / scale;
spacingY = (int) (spacingY * sh);
spacingX = (int) (spacingX * sW);
//Start drawing after everying is scaled down
GL11.glScalef(scale, scale, scale);
// Draws each line
for (int i = 0; i < 4; i++)
//TODO add zooming which will involve storing scales with distance translations factors
for (int j = 0; j < 3; j++)
{
int currentLine = i + this.scroll;
if (currentLine < this.program.getSize().intY() && currentLine >= 0)
for (int i = 0; i < 6; i++)
{
ITask task = this.program.getTaskAt(new Vector2(0, currentLine));
int currentLine = i + this.scroll;
if (task != null)
if (currentLine <= this.program.getSize().intY() && currentLine >= 0)
{
if (task instanceof IRedirectTask && !((IRedirectTask) task).render())
ITask task = this.program.getTaskAt(new Vector2(j, currentLine));
if (task != null)
{
continue;
if (task instanceof IRedirectTask && !((IRedirectTask) task).render())
{
continue;
}
int xx = 50;
int yy = 39;
int uu = 0;
int vv = 0;
switch (task.getType())
{
case DATA:
break;
case PROCESS:
break;
case DEFINEDPROCESS:
xx = 50;
yy = 39;
uu = 0;
vv = 39;
break;
case DECISION:
xx = 50;
yy = 50;
uu = 50;
vv = 0;
break;
}
FMLClientHandler.instance().getClient().renderEngine.bindTexture(this.TEXTURE_PROCESS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Vector2 center = new Vector2(x * sW + (spacingX * j), y * sh + (spacingY * i));
this.drawTexturedModalRect(center.intX(), center.intY(), uu, vv, xx, yy);
this.drawCenteredString(minecraft.fontRenderer, task.getMethodName(), center.intX() + (xx / 2), center.intY() + ((yy - 8) / 2), color);
}
int xx = 50;
int yy = 39;
int uu = 0;
int vv = 0;
switch (task.getType())
{
case DATA:
break;
case PROCESS:
break;
case DEFINEDPROCESS:
xx = 50;
yy = 39;
uu = 0;
vv = 39;
break;
case DECISION:
xx = 50;
yy = 50;
uu = 50;
vv = 0;
break;
}
FMLClientHandler.instance().getClient().renderEngine.bindTexture(this.TEXTURE_PROCESS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + xx / 2, this.yPosition + (yy * i), uu, vv, xx, yy);
this.drawCenteredString(fontRenderer, task.getMethodName(), this.xPosition + xx, this.yPosition + (yy * i), -6250336);
}
}