add scrollbar to builder, improve GUI rendering

This commit is contained in:
Adrian 2015-05-07 05:56:31 +02:00
parent 4599abd240
commit d732d4ee11
5 changed files with 110 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View file

@ -16,3 +16,5 @@ Bugs fixed:
* [#2684] Force robot only seems to look at first parameter (asie)
* Add-assembly-recipe IMC not working (asie)
* Crash with Transport and no Silicon (asie)
* Incorrect orientation/position in inventory rendering (asie)
* Laser table textures broken when anisotropic filtering on (asie)

View file

@ -8,10 +8,8 @@
*/
package buildcraft.builders;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.*;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -620,7 +618,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
return getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint;
}
public Collection<ItemStack> getNeededItems() {
public List<ItemStack> getNeededItems() {
return requiredToBuild;
}

View file

@ -9,6 +9,8 @@
package buildcraft.builders.gui;
import java.util.Collection;
import java.util.List;
import org.lwjgl.opengl.GL11;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
@ -27,17 +29,19 @@ import buildcraft.core.lib.network.command.PacketCommand;
import buildcraft.core.lib.utils.StringUtils;
public class GuiBuilder extends GuiAdvancedInterface {
private static final ResourceLocation REGULAR_TEXTURE = new ResourceLocation("buildcraftbuilders:textures/gui/builder.png");
private static final ResourceLocation BLUEPRINT_TEXTURE = new ResourceLocation("buildcraftbuilders:textures/gui/builder_blueprint.png");
private static final ResourceLocation FOREGROUND_TEXTURE = new ResourceLocation("buildcraftbuilders:textures/gui/builder_foreground.png");
private IInventory playerInventory;
private TileBuilder builder;
private GuiButton selectedButton;
private int sbPosition, sbLength;
private boolean sbInside;
public GuiBuilder(IInventory playerInventory, TileBuilder builder) {
super(new ContainerBuilder(playerInventory, builder), builder, BLUEPRINT_TEXTURE);
this.playerInventory = playerInventory;
this.builder = builder;
xSize = 176;
xSize = 256;
ySize = 225;
resetNullSlots(6 * 4);
@ -54,10 +58,12 @@ public class GuiBuilder extends GuiAdvancedInterface {
super.drawGuiContainerForegroundLayer(par1, par2);
drawCenteredString(StringUtils.localize("tile.builderBlock.name"), 178 / 2, 16, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.building.resources"), 8, 60, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.needed"), 178, 7, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.building.fluids"), 178, 133, 0x404040);
if (builder.getStackInSlot(0) != null) {
fontRendererObj.drawString(StringUtils.localize("gui.building.resources"), 8, 60, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.needed"), 178, 7, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.building.fluids"), 178, 133, 0x404040);
}
drawTooltipForSlotAt(par1, par2);
}
@ -65,38 +71,67 @@ public class GuiBuilder extends GuiAdvancedInterface {
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
boolean isBlueprint = builder.getStackInSlot(0) != null;
mc.renderEngine.bindTexture(REGULAR_TEXTURE);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, 176, ySize);
mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, 256, ySize);
for (AdvancedSlot s : slots) {
((ItemSlot) s).stack = null;
if (isBlueprint) {
drawTexturedModalRect(guiLeft + 169, guiTop, 169, 0, 256 - 169, ySize);
}
Collection<ItemStack> needs = builder.getNeededItems();
List<ItemStack> needs = builder.getNeededItems();
if (needs != null) {
int s = 0;
for (ItemStack stack : needs) {
if (s >= slots.size()) {
break;
if (needs.size() > slots.size()) {
sbLength = (needs.size() - slots.size() + 3) / 4;
if (sbPosition >= sbLength) {
sbPosition = sbLength;
}
((ItemSlot) slots.get(s)).stack = stack.copy();
s++;
// render scrollbar
drawTexturedModalRect(guiLeft + 172, guiTop + 17, 18, 0, 6, 108);
int sbPixelPosition = (sbPosition * (108 - 13) / sbLength);
drawTexturedModalRect(guiLeft + 172, guiTop + 17 + sbPixelPosition, 24, 0, 6, 14);
} else {
sbPosition = 0;
sbLength = 0;
}
int offset = sbPosition * 4;
for (int s = 0; s < slots.size(); s++) {
int ts = offset + s;
if (ts >= needs.size()) {
((ItemSlot) slots.get(s)).stack = null;
} else {
((ItemSlot) slots.get(s)).stack = needs.get(ts).copy();
}
}
for (GuiButton b : (List<GuiButton>) buttonList) {
b.visible = true;
}
} else {
sbPosition = 0;
sbLength = 0;
for (int s = 0; s < slots.size(); s++) {
((ItemSlot) slots.get(s)).stack = null;
}
for (GuiButton b : (List<GuiButton>) buttonList) {
b.visible = false;
}
}
drawBackgroundSlots();
if (isBlueprint) {
drawBackgroundSlots();
for (int i = 0; i < builder.fluidTanks.length; i++) {
Tank tank = builder.fluidTanks[i];
drawFluid(tank.getFluid(), guiLeft + 179 + 18 * i, guiTop + 145, 16, 47, tank.getCapacity());
}
mc.renderEngine.bindTexture(FOREGROUND_TEXTURE);
for (int i = 0; i < builder.fluidTanks.length; i++) {
drawTexturedModalRect(guiLeft + 179 + 18 * i, guiTop + 145, 0, 54, 16, 47);
for (int i = 0; i < builder.fluidTanks.length; i++) {
Tank tank = builder.fluidTanks[i];
if (tank.getFluid() != null && tank.getFluid().amount > 0) {
drawFluid(tank.getFluid(), guiLeft + 179 + 18 * i, guiTop + 145, 16, 47, tank.getCapacity());
drawTexturedModalRect(guiLeft + 179 + 18 * i, guiTop + 145, 0, 54, 16, 47);
}
}
}
}
@ -108,9 +143,49 @@ public class GuiBuilder extends GuiAdvancedInterface {
}
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
int guiX = mouseX - guiLeft;
int guiY = mouseY - guiTop;
if (sbLength > 0 && button == 0) {
if (guiX >= 172 && guiX < 178 && guiY >= 17 && guiY < 125) {
sbInside = true;
updateToSbHeight(guiY - 17);
}
}
super.mouseClicked(mouseX, mouseY, button);
}
private void updateToSbHeight(int h) {
int hFrac = (h * sbLength + 54) / 108;
sbPosition = hFrac;
}
@Override
protected void mouseClickMove(int x, int y, int button, long time) {
super.mouseClickMove(x, y, button, time);
if (sbInside && button == 0) {
int guiY = y - guiTop;
if (sbLength > 0) {
if (guiY >= 17 && guiY < 125) {
updateToSbHeight(guiY - 17);
}
}
}
}
@Override
protected void mouseMovedOrUp(int mouseX, int mouseY, int eventType) {
super.mouseMovedOrUp(mouseX, mouseY, eventType);
if (sbInside && eventType == 0) {
int guiY = mouseY - guiTop;
if (sbLength > 0) {
if (guiY >= 17 && guiY < 125) {
updateToSbHeight(guiY - 17);
sbInside = false;
}
}
}
if (this.selectedButton != null && eventType == 0) {
this.selectedButton.mouseReleased(mouseX, mouseY);
@ -149,10 +224,13 @@ public class GuiBuilder extends GuiAdvancedInterface {
@Override
public void drawButton(Minecraft mc, int x, int y) {
if (!visible) {
return;
}
// hovered
this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height;
mc.renderEngine.bindTexture(FOREGROUND_TEXTURE);
mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE);
drawTexturedModalRect(xPosition, yPosition, 0, (clicked ? 1 : this.field_146123_n ? 2 : 0) * 18, 18, 18);
mouseDragged(mc, x, y);
}