mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Started work on IO config GUI for machines.
This commit is contained in:
1 parent
926104ba56
commit
758921d10a
10 files changed
+618
-23
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.util.IIcon;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
|
||||
public interface IGuiOverlay {
|
||||
|
||||
void init(IGuiScreen screen);
|
||||
|
||||
IIcon getIcon();
|
||||
|
||||
Rectangle getBounds();
|
||||
|
||||
void draw(int mouseX, int mouseY, float partialTick);
|
||||
|
||||
// //consume event?
|
||||
// boolean mouseClicked(int par1, int par2, int par3);
|
||||
//
|
||||
// boolean mouseClickMove(int par1, int par2, int par3, long p_146273_4_);
|
||||
//
|
||||
// boolean mouseMovedOrUp(int par1, int par2, int par3);
|
||||
|
||||
void setVisible(boolean visible);
|
||||
|
||||
boolean isVisible();
|
||||
|
||||
boolean handleMouseInput(int x, int y, int b);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.teleport.TravelController;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.vecmath.Camera;
|
||||
import crazypants.vecmath.Matrix4d;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class IoConfigRenderer {
|
||||
|
||||
protected static final RenderBlocks RB = new RenderBlocks();
|
||||
|
||||
//private int range;
|
||||
private boolean dragging = false;
|
||||
private float pitch = -45;
|
||||
private float yaw = 45;
|
||||
private double distance;
|
||||
private long initTime;
|
||||
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private World world = mc.thePlayer.worldObj;
|
||||
|
||||
private final Vector3d origin = new Vector3d();
|
||||
private final Vector3d eye = new Vector3d();
|
||||
private final Camera camera = new Camera();
|
||||
private final Matrix4d pitchRot = new Matrix4d();
|
||||
private final Matrix4d yawRot = new Matrix4d();
|
||||
|
||||
public BlockCoord originBC;
|
||||
public IIoConfigurable configuarble;
|
||||
|
||||
public IoConfigRenderer(IIoConfigurable configuarble) {
|
||||
this.configuarble = configuarble;
|
||||
originBC = configuarble.getLocation();
|
||||
origin.set(originBC.x + 0.5, originBC.y+ 0.5, originBC.z+ 0.5);
|
||||
pitchRot.setIdentity();
|
||||
yawRot.setIdentity();
|
||||
distance = 4;
|
||||
|
||||
// blocks.add(new ViewableBlocks(ioX, ioY, ioZ, EnderIO.blockEnderIo));
|
||||
//
|
||||
// for (int x = ioX - range; x <= ioX + range; x++) {
|
||||
// for (int y = ioY - range; y <= ioY + range; y++) {
|
||||
// for (int z = ioZ - range; z <= ioZ + range; z++) {
|
||||
// Block block = world.getBlock(x, y, z);
|
||||
// blocks.add(new ViewableBlocks(x, y, z, block));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void init() {
|
||||
world = mc.thePlayer.worldObj;
|
||||
initTime = world.getTotalWorldTime();
|
||||
RB.blockAccess = world;
|
||||
}
|
||||
|
||||
public void handleMouseInput() {
|
||||
|
||||
if(Mouse.getEventButton() == 0) {
|
||||
dragging = Mouse.getEventButtonState();
|
||||
}
|
||||
|
||||
if(dragging) {
|
||||
|
||||
double dx = (Mouse.getEventDX() / (double) mc.displayWidth);
|
||||
double dy = (Mouse.getEventDY() / (double) mc.displayHeight);
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
distance -= dy * 15;
|
||||
} else {
|
||||
yaw -= 4 * dx * 180;
|
||||
pitch += 2* dy * 180;
|
||||
pitch = (float) VecmathUtil.clamp(pitch, -80, 80);
|
||||
}
|
||||
}
|
||||
|
||||
distance -= Mouse.getDWheel() * 0.01;
|
||||
distance = VecmathUtil.clamp(distance, 0.1, 20);
|
||||
|
||||
long elapsed = world.getTotalWorldTime() - initTime;
|
||||
|
||||
if(Mouse.getEventButton() == 1 && !Mouse.getEventButtonState() && camera.isValid() && elapsed > 10) {
|
||||
int x = Mouse.getEventX();
|
||||
int y = Mouse.getEventY();
|
||||
Vector3d start = new Vector3d();
|
||||
Vector3d end = new Vector3d();
|
||||
if(camera.getRayForPixel(x, y, start, end)) {
|
||||
end.scale(distance * 2);
|
||||
end.add(start);
|
||||
doSelection(start, end);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void doSelection(Vector3d start, Vector3d end) {
|
||||
start.add(origin);
|
||||
end.add(origin);
|
||||
List<MovingObjectPosition> hits = new ArrayList<MovingObjectPosition>();
|
||||
|
||||
Block block = world.getBlock(originBC.x, originBC.y, originBC.z);
|
||||
if(block != null) {
|
||||
MovingObjectPosition hit = block.collisionRayTrace(world, originBC.x, originBC.y, originBC.z, Vec3.createVectorHelper(start.x, start.y, start.z),
|
||||
Vec3.createVectorHelper(end.x, end.y, end.z));
|
||||
if(hit != null) {
|
||||
block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
|
||||
configuarble.toggleIoModeForFace(ForgeDirection.getOrientation(hit.sideHit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MovingObjectPosition getClosestHit(Vec3 origin, Collection<MovingObjectPosition> candidates) {
|
||||
double minLengthSquared = Double.POSITIVE_INFINITY;
|
||||
MovingObjectPosition closest = null;
|
||||
|
||||
for (MovingObjectPosition hit : candidates) {
|
||||
if(hit != null) {
|
||||
double lengthSquared = hit.hitVec.squareDistanceTo(origin);
|
||||
if(lengthSquared < minLengthSquared) {
|
||||
minLengthSquared = lengthSquared;
|
||||
closest = hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float partialTick, Rectangle vp) {
|
||||
//TODO: Need to depth sort transparent passes
|
||||
if(!updateCamera(partialTick,vp.x,vp.y,vp.width,vp.height)) {
|
||||
return;
|
||||
}
|
||||
applyCamera(partialTick);
|
||||
|
||||
TravelController.instance.setSelectionEnabled(false);
|
||||
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
mc.entityRenderer.enableLightmap(0);
|
||||
RenderUtil.bindBlockTexture();
|
||||
|
||||
Vector3d trans = new Vector3d((-origin.x) + eye.x, (-origin.y) + eye.y, (-origin.z) + eye.z);
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
|
||||
ForgeHooksClient.setRenderPass(pass);
|
||||
setGlStateForPass(pass);
|
||||
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
Tessellator.instance.setTranslation(trans.x, trans.y, trans.z);
|
||||
|
||||
Block block = world.getBlock(originBC.x, originBC.y, originBC.z);
|
||||
if(block != null) {
|
||||
if(block.canRenderInPass(pass)) {
|
||||
BlockCoord bc = originBC;
|
||||
RB.setRenderBounds(0, 0, 0, 1, 1, 1);
|
||||
RB.renderBlockByRenderType(block, bc.x, bc.y, bc.z);
|
||||
}
|
||||
}
|
||||
|
||||
// for (ViewableBlocks ug : blocks) {
|
||||
// if(ug.block.canRenderInPass(pass)) {
|
||||
// RB.setRenderBounds(0, 0, 0, 1, 1, 1);
|
||||
// RB.renderBlockByRenderType(ug.block, ug.bc.x, ug.bc.y, ug.bc.z);
|
||||
// }
|
||||
// }
|
||||
Tessellator.instance.draw();
|
||||
Tessellator.instance.setTranslation(0, 0, 0);
|
||||
}
|
||||
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
|
||||
TileEntityRendererDispatcher.instance.field_147558_l = origin.x - eye.x;
|
||||
TileEntityRendererDispatcher.instance.field_147560_j = origin.y - eye.y;
|
||||
TileEntityRendererDispatcher.instance.field_147561_k = origin.z - eye.z;
|
||||
|
||||
TileEntityRendererDispatcher.staticPlayerX = origin.x - eye.x;
|
||||
TileEntityRendererDispatcher.staticPlayerY = origin.y - eye.y;
|
||||
TileEntityRendererDispatcher.staticPlayerZ = origin.z - eye.z;
|
||||
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
|
||||
ForgeHooksClient.setRenderPass(pass);
|
||||
setGlStateForPass(pass);
|
||||
|
||||
// for (ViewableBlocks ug : blocks) {
|
||||
// TileEntity tile = world.getTileEntity(ug.bc.x, ug.bc.y, ug.bc.z);
|
||||
// if(tile != null) {
|
||||
// Vector3d at = new Vector3d(eye.x - 0.5, eye.y - 0.5, eye.z - 0.5);
|
||||
// at.x += ug.bc.x - ioX;
|
||||
// at.y += ug.bc.y - ioY;
|
||||
// at.z += ug.bc.z - ioZ;
|
||||
// TileEntityRendererDispatcher.instance.renderTileEntityAt(tile, at.x, at.y, at.z, 0);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
ForgeHooksClient.setRenderPass(-1);
|
||||
setGlStateForPass(0);
|
||||
TravelController.instance.setSelectionEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
private void setGlStateForPass(int pass) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if(pass == 0) {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glDepthMask(true);
|
||||
} else {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDepthMask(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean updateCamera(float partialTick, int vpx, int vpy, int vpw, int vph) {
|
||||
if(vpw <= 0 || vph <= 0) {
|
||||
return false;
|
||||
}
|
||||
camera.setViewport(vpx, vpy, vpw, vph);
|
||||
camera.setProjectionMatrixAsPerspective(30, 0.05, 50, vpw, vph);
|
||||
eye.set(0, 0, distance);
|
||||
pitchRot.makeRotationX(Math.toRadians(pitch));
|
||||
yawRot.makeRotationY(Math.toRadians(yaw));
|
||||
pitchRot.transform(eye);
|
||||
yawRot.transform(eye);
|
||||
camera.setViewMatrixAsLookAt(eye, RenderUtil.ZERO_V, RenderUtil.UP_V);
|
||||
return camera.isValid();
|
||||
}
|
||||
|
||||
private void applyCamera(float partialTick) {
|
||||
Rectangle vp = camera.getViewport();
|
||||
GL11.glViewport(vp.x, vp.y, vp.width, vp.height);
|
||||
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
RenderUtil.loadMatrix(camera.getTransposeProjectionMatrix());
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
RenderUtil.loadMatrix(camera.getTransposeViewMatrix());
|
||||
GL11.glTranslatef(-(float) eye.x, -(float) eye.y, -(float) eye.z);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import crazypants.util.InventoryWrapper;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public abstract class AbstractMachineEntity extends TileEntityEio implements ISidedInventory, IInternalPowerReceptor, IMachine, IRedstoneModeControlable {
|
||||
public abstract class AbstractMachineEntity extends TileEntityEio implements ISidedInventory, IInternalPowerReceptor, IMachine, IRedstoneModeControlable, IIoConfigurable {
|
||||
|
||||
public short facing;
|
||||
|
||||
@@ -108,6 +108,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCoord getLocation() {
|
||||
return new BlockCoord(this);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import net.minecraft.inventory.Container;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
@@ -22,11 +24,16 @@ public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
protected static final int BOTTOM_POWER_Y = POWER_Y + POWER_HEIGHT;
|
||||
|
||||
public static final int BUTTON_SIZE = 16;
|
||||
private static final int CONFIG_ID = 8962349;
|
||||
|
||||
private AbstractMachineEntity tileEntity;
|
||||
|
||||
private RedstoneModeButton redstoneButton;
|
||||
|
||||
private GuiOverlayIoConfig configOverlay;
|
||||
|
||||
private IconButtonEIO configB;
|
||||
|
||||
public GuiMachineBase(AbstractMachineEntity machine, Container container) {
|
||||
super(container);
|
||||
tileEntity = machine;
|
||||
@@ -43,6 +50,12 @@ public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
int x = xSize - 5 - BUTTON_SIZE;
|
||||
int y = 5;
|
||||
redstoneButton = new RedstoneModeButton(this, -1, x, y, tileEntity, new BlockCoord(tileEntity));
|
||||
|
||||
y += 20;
|
||||
configB = new IconButtonEIO(this, CONFIG_ID, x, y, IconEIO.BUTTON_DOWN);
|
||||
|
||||
configOverlay = new GuiOverlayIoConfig(machine);
|
||||
addOverlay(configOverlay);
|
||||
}
|
||||
|
||||
protected int getPowerX() {
|
||||
@@ -61,10 +74,25 @@ public abstract class GuiMachineBase extends GuiContainerBase {
|
||||
return POWER_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
System.out.println("GuiMachineBase.actionPerformed: ");
|
||||
if(b.id == CONFIG_ID) {
|
||||
System.out.println("GuiMachineBase.actionPerformed: 2");
|
||||
configOverlay.setVisible(!configOverlay.isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
redstoneButton.onGuiInit();
|
||||
configB.onGuiInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.util.IIcon;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.enderio.gui.IoConfigRenderer;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class GuiOverlayIoConfig implements IGuiOverlay {
|
||||
|
||||
private boolean visible = false;
|
||||
|
||||
private IGuiScreen screen;
|
||||
|
||||
private Rectangle bounds;
|
||||
int height = 80;
|
||||
|
||||
private IoConfigRenderer renderer;
|
||||
|
||||
private IIoConfigurable ioConf;
|
||||
|
||||
|
||||
public GuiOverlayIoConfig(IIoConfigurable ioConf) {
|
||||
this.ioConf = ioConf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon() {
|
||||
return EnderIOTab.tabEnderIO.getIconItemStack().getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IGuiScreen screen) {
|
||||
this.screen = screen;
|
||||
renderer = new IoConfigRenderer(ioConf);
|
||||
renderer.init();
|
||||
bounds = new Rectangle(5, screen.getYSize() - height -5, screen.getXSize() - 10, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTick) {
|
||||
|
||||
RenderUtil.renderQuad2D(bounds.x, bounds.y, 0, bounds.width, bounds.height, ColorUtil.getRGB(Color.lightGray));
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledresolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
int vpx = ( (screen.getGuiLeft() + bounds.x)* scaledresolution.getScaleFactor());
|
||||
int vpy = (screen.getGuiTop())* scaledresolution.getScaleFactor();
|
||||
int w = bounds.width * scaledresolution.getScaleFactor();
|
||||
int h = bounds.height * scaledresolution.getScaleFactor();
|
||||
|
||||
renderer.drawScreen(mouseX, mouseY, partialTick, new Rectangle(vpx,vpy,w,h));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMouseInput(int x, int y, int b) {
|
||||
if(!mouseInBounds(x, y)) {
|
||||
renderer.handleMouseInput();
|
||||
return false;
|
||||
}
|
||||
|
||||
renderer.handleMouseInput();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean mouseInBounds(int mouseX, int mouseY) {
|
||||
int x = mouseX - screen.getGuiLeft();
|
||||
int y = mouseY - screen.getGuiTop();
|
||||
if(bounds.contains(x,y)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public interface IIoConfigurable {
|
||||
|
||||
public IoMode toggleIoModeForFace(ForgeDirection faceHit);
|
||||
|
||||
public boolean supportsMode(ForgeDirection faceHit, IoMode mode);
|
||||
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode);
|
||||
|
||||
public IoMode getIoMode(ForgeDirection face) ;
|
||||
|
||||
BlockCoord getLocation();
|
||||
|
||||
}
|
||||
@@ -1,34 +1,120 @@
|
||||
package crazypants.gui;
|
||||
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
|
||||
public abstract class GuiContainerBase extends GuiContainer implements ToolTipRenderer, IGuiScreen {
|
||||
|
||||
protected ToolTipManager ttMan = new ToolTipManager();
|
||||
protected List<IGuiOverlay> overlays = new ArrayList<IGuiOverlay>();
|
||||
|
||||
protected GuiContainerBase(Container par1Container) {
|
||||
super(par1Container);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
for(IGuiOverlay overlay : overlays) {
|
||||
overlay.init(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
if (par2 == 1 || par2 == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
//this.mc.thePlayer.closeScreen();
|
||||
for(IGuiOverlay overlay : overlays) {
|
||||
if(overlay.isVisible()) {
|
||||
overlay.setVisible(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.keyTyped(par1, par2);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addToolTip(GuiToolTip toolTip) {
|
||||
ttMan.addToolTip(toolTip);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void mouseClicked(int par1, int par2, int par3) {
|
||||
// for(IGuiOverlay overlay : overlays) {
|
||||
// if(overlay != null && overlay.isVisible() && overlay.mouseClicked(par1, par2, par3)) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// super.mouseClicked(par1, par2, par3);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void mouseClickMove(int par1, int par2, int par3, long par4) {
|
||||
// for(IGuiOverlay overlay : overlays) {
|
||||
// if(overlay != null && overlay.isVisible() && overlay.mouseClickMove(par1, par2, par3, par4)) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// super.mouseClickMove(par1, par2, par3, par4);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void mouseMovedOrUp(int par1, int par2, int par3) {
|
||||
// for(IGuiOverlay overlay : overlays) {
|
||||
// if(overlay != null && overlay.isVisible() && overlay.mouseMovedOrUp(par1, par2, par3)) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// super.mouseMovedOrUp(par1, par2, par3);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void removeToolTip(GuiToolTip toolTip) {
|
||||
ttMan.removeToolTip(toolTip);
|
||||
public void handleMouseInput() {
|
||||
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
int b = Mouse.getEventButton();
|
||||
for(IGuiOverlay overlay : overlays) {
|
||||
if(overlay != null && overlay.isVisible() && overlay.handleMouseInput(x, y, b)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.handleMouseInput();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleKeyboardInput() {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleKeyboardInput();
|
||||
}
|
||||
|
||||
|
||||
public void addOverlay(IGuiOverlay overlay) {
|
||||
overlays.add(overlay);
|
||||
}
|
||||
|
||||
public void removeOverlay(IGuiOverlay overlay) {
|
||||
overlays.remove(overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +123,48 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
ttMan.drawTooltips(this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
|
||||
int mx = par1;
|
||||
int my = par2;
|
||||
for(IGuiOverlay overlay : overlays) {
|
||||
if(overlay != null && overlay.isVisible() && isMouseInOverlay(par1, par2, overlay)) {
|
||||
mx = -1;
|
||||
my = -1;
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mx, my, par3);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
for(IGuiOverlay overlay : overlays) {
|
||||
if(overlay != null && overlay.isVisible()) {
|
||||
overlay.draw(par1, par2, par3);
|
||||
}
|
||||
}
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private boolean isMouseInOverlay(int mouseX, int mouseY, IGuiOverlay overlay) {
|
||||
int x = mouseX - getGuiLeft();
|
||||
int y = mouseY - getGuiTop();
|
||||
if(overlay.getBounds().contains(x,y)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeToolTip(GuiToolTip toolTip) {
|
||||
ttMan.removeToolTip(toolTip);
|
||||
}
|
||||
|
||||
protected void drawForegroundImpl(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
@@ -144,6 +272,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYSize() {
|
||||
return ySize;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package crazypants.gui;
|
||||
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
|
||||
public abstract class GuiScreenBase extends GuiScreen implements ToolTipRenderer, IGuiScreen {
|
||||
|
||||
@@ -198,6 +200,11 @@ public abstract class GuiScreenBase extends GuiScreen implements ToolTipRenderer
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontRenderer getFontRenderer() {
|
||||
return Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
@@ -6,16 +6,22 @@ public interface IGuiScreen {
|
||||
|
||||
void addToolTip(GuiToolTip toolTip);
|
||||
|
||||
public int getGuiLeft();
|
||||
|
||||
public int getGuiTop();
|
||||
|
||||
public int getXSize();
|
||||
|
||||
public void addButton(GuiButton button);
|
||||
|
||||
public void removeButton(GuiButton button);
|
||||
|
||||
void removeToolTip(GuiToolTip toolTip);
|
||||
|
||||
int getGuiLeft();
|
||||
|
||||
int getGuiTop();
|
||||
|
||||
int getXSize();
|
||||
|
||||
int getYSize();
|
||||
|
||||
void addButton(GuiButton button);
|
||||
|
||||
void removeButton(GuiButton button);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
@@ -177,6 +176,8 @@ public class RenderUtil {
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* left, bottom, right, top
|
||||
*
|
||||
@@ -426,12 +427,12 @@ public class RenderUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void renderGuiTank(FluidTank tank, double x, double y, double zLevel, double width, double height) {
|
||||
renderGuiTank(tank.getFluid(),tank.getCapacity(),tank.getFluidAmount(), x, y, zLevel, width, height);
|
||||
}
|
||||
|
||||
public static void renderGuiTank(FluidStack fluid, int capacity, int amount, double x, double y, double zLevel, double width, double height) {
|
||||
|
||||
public static void renderGuiTank(FluidStack fluid, int capacity, int amount, double x, double y, double zLevel, double width, double height) {
|
||||
if(fluid == null || fluid.getFluid() == null || fluid.amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user