add inBounds() method to GuiBase
This commit is contained in:
@@ -25,28 +25,28 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
public void initGui() {
|
public void initGui() {
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
init(getRelativeX(), getRelativeY());
|
init(guiLeft, guiTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen() {
|
public void updateScreen() {
|
||||||
super.updateScreen();
|
super.updateScreen();
|
||||||
|
|
||||||
update(getRelativeX(), getRelativeY());
|
update(guiLeft, guiTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
|
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
drawBackground(getRelativeX(), getRelativeY(), mouseX, mouseY);
|
drawBackground(guiLeft, guiTop, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
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);
|
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);
|
public abstract void drawForeground(int mouseX, int mouseY);
|
||||||
|
|
||||||
private int getRelativeX() {
|
protected boolean inBounds(int x, int y, int w, int h, int ox, int oy) {
|
||||||
return (width - xSize) / 2;
|
return ox >= x && ox <= x + w && oy >= y && oy <= y + h;
|
||||||
}
|
|
||||||
|
|
||||||
private int getRelativeY() {
|
|
||||||
return (height - ySize) / 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindTexture(String file) {
|
protected void bindTexture(String file) {
|
||||||
@@ -73,7 +69,6 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
mc.getTextureManager().bindTexture(new ResourceLocation(base, "textures/" + file));
|
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) {
|
protected void drawItem(int x, int y, ItemStack stack) {
|
||||||
drawItem(x, y, stack, false);
|
drawItem(x, y, stack, false);
|
||||||
}
|
}
|
||||||
@@ -110,6 +105,7 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
fontRendererObj.drawString(message, x, y, color);
|
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) {
|
protected void drawTooltip(int x, int y, String message) {
|
||||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class GuiGrid extends GuiMachine {
|
|||||||
drawItem(x, y, grid.getController().getItems().get(slot).toItemStack(), true);
|
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;
|
hoveringSlot = slot;
|
||||||
|
|
||||||
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
|
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
|
||||||
@@ -133,7 +133,7 @@ public class GuiGrid extends GuiMachine {
|
|||||||
for (int i = 0; i < container.inventorySlots.size(); ++i) {
|
for (int i = 0; i < container.inventorySlots.size(); ++i) {
|
||||||
Slot slot = (Slot) container.inventorySlots.get(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)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
|
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public abstract class GuiMachine extends GuiBase {
|
|||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY) {
|
||||||
drawItem(redstoneModeX + 2, redstoneModeY + 1, REDSTONE_MODE_ITEM);
|
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));
|
drawTooltip(mouseX, mouseY, t("misc.storagecraft:redstoneMode." + machine.getRedstoneMode().id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user