add inBounds() method to GuiBase

This commit is contained in:
Raoul Van den Berge
2015-12-20 12:46:21 +01:00
parent e27e4c326d
commit 69b1d47861
3 changed files with 10 additions and 14 deletions

View File

@@ -25,28 +25,28 @@ public abstract class GuiBase extends GuiContainer {
public void initGui() {
super.initGui();
init(getRelativeX(), getRelativeY());
init(guiLeft, guiTop);
}
@Override
public void updateScreen() {
super.updateScreen();
update(getRelativeX(), getRelativeY());
update(guiLeft, guiTop);
}
@Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawBackground(getRelativeX(), getRelativeY(), mouseX, mouseY);
drawBackground(guiLeft, guiTop, mouseX, mouseY);
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawForeground(mouseX - ((this.width - xSize) / 2), mouseY - ((this.height - ySize) / 2));
drawForeground(mouseX - guiLeft, mouseY - guiTop);
}
public abstract void init(int x, int y);
@@ -57,12 +57,8 @@ public abstract class GuiBase extends GuiContainer {
public abstract void drawForeground(int mouseX, int mouseY);
private int getRelativeX() {
return (width - xSize) / 2;
}
private int getRelativeY() {
return (height - ySize) / 2;
protected boolean inBounds(int x, int y, int w, int h, int ox, int oy) {
return ox >= x && ox <= x + w && oy >= y && oy <= y + h;
}
protected void bindTexture(String file) {
@@ -73,7 +69,6 @@ public abstract class GuiBase extends GuiContainer {
mc.getTextureManager().bindTexture(new ResourceLocation(base, "textures/" + file));
}
// @TODO: inBounds(x, y, width, height, ox, oy)
protected void drawItem(int x, int y, ItemStack stack) {
drawItem(x, y, stack, false);
}
@@ -110,6 +105,7 @@ public abstract class GuiBase extends GuiContainer {
fontRendererObj.drawString(message, x, y, color);
}
// https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/master/src/main/java/appeng/client/gui/AEBaseGui.java
protected void drawTooltip(int x, int y, String message) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

View File

@@ -93,7 +93,7 @@ public class GuiGrid extends GuiMachine {
drawItem(x, y, grid.getController().getItems().get(slot).toItemStack(), true);
}
if ((mouseX >= x && mouseX <= x + 16 && mouseY >= y && mouseY <= y + 16) || !grid.isConnected()) {
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
hoveringSlot = slot;
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
@@ -133,7 +133,7 @@ public class GuiGrid extends GuiMachine {
for (int i = 0; i < container.inventorySlots.size(); ++i) {
Slot slot = (Slot) container.inventorySlots.get(i);
if (func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) {
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
}

View File

@@ -38,7 +38,7 @@ public abstract class GuiMachine extends GuiBase {
public void drawForeground(int mouseX, int mouseY) {
drawItem(redstoneModeX + 2, redstoneModeY + 1, REDSTONE_MODE_ITEM);
if (mouseX >= redstoneModeX && mouseX <= redstoneModeX + redstoneModeWidth && mouseY >= redstoneModeY && mouseY <= redstoneModeY + redstoneModeHeight) {
if (inBounds(redstoneModeX, redstoneModeY, redstoneModeWidth, redstoneModeHeight, mouseX, mouseY)) {
drawTooltip(mouseX, mouseY, t("misc.storagecraft:redstoneMode." + machine.getRedstoneMode().id));
}
}