Skip to content

Commit

Permalink
Display a 4-columns GUI if the smeltery has >16 blocks per layer
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 11, 2014
1 parent 24e0e9f commit 711fe0d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 34 deletions.
76 changes: 53 additions & 23 deletions src/main/java/tconstruct/smeltery/gui/SmelteryGui.java
Expand Up @@ -18,20 +18,23 @@
public class SmelteryGui extends NewContainerGui
{
public SmelteryLogic logic;
String username;
boolean isScrolling = false;
boolean wasClicking;
float currentScroll = 0.0F;
int slotPos = 0;
int prevSlotPos = 0;
private boolean isScrolling = false;
private boolean wasClicking;
private float currentScroll = 0.0F;
private int slotPos = 0;
private int prevSlotPos = 0;

private final int columns;
public static final int maxRows = 8;

public SmelteryGui(InventoryPlayer inventoryplayer, SmelteryLogic smeltery, World world, int x, int y, int z)
{
super((ActiveContainer) smeltery.getGuiContainer(inventoryplayer, world, x, y, z));
logic = smeltery;
username = inventoryplayer.player.getDisplayName();
xSize = 248;
smeltery.updateFuelDisplay();

columns = ((SmelteryContainer)this.container).columns;
}

@Override
Expand All @@ -52,7 +55,7 @@ public void drawScreen (int mouseX, int mouseY, float par3)

protected void updateScrollbar (int mouseX, int mouseY, float par3)
{
if (logic.getBlockCapacity() > 18)
if (logic.getBlockCapacity() > columns*maxRows)
{
boolean mouseDown = Mouse.isButtonDown(0);
int lefto = this.guiLeft;
Expand Down Expand Up @@ -220,49 +223,76 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY)
drawTexturedModalRect(cornerX + 54, cornerY + 16, 176, 76, 52, 52);

// Side inventory
int xleft = 46;
xleft += 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns
int h = logic.getBlockCapacity()/columns;
if(logic.getBlockCapacity()%columns != 0)
h++;

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(backgroundSide);
if (logic.getBlockCapacity() > 0)
{
int h = logic.getBlockCapacity()/3;
if(logic.getBlockCapacity()%3 != 0)
h++;

if(h >= 8)
{
drawTexturedModalRect(cornerX - 46, cornerY, 0, 0, 97, ySize - 8);
// standard 3 slots
drawTexturedModalRect(cornerX - xleft, cornerY, 0, 0, 72, ySize - 8);
// additional slots
for(int i = 0; i < columns-3; i++)
drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY, 50, 0, 22, ySize - 8);
// right end
drawTexturedModalRect(cornerX - 46 + 72, cornerY, 72, 0, 25, ySize - 8);

// scroll bar
drawTexturedModalRect(cornerX + 32, (int) (cornerY + 8 + 127 * currentScroll), 98, 0, 12, 15);
}
else
{
int yd = 43 + 18*(h-3);
drawTexturedModalRect(cornerX - 46, cornerY, 0, 0, 97, yd);
drawTexturedModalRect(cornerX - 46, cornerY + yd, 0, 133, 97, 25);
// slots
// standard 3 slots
drawTexturedModalRect(cornerX - xleft, cornerY, 0, 0, 72, yd);
// additional slots
for(int i = 0; i < columns-3; i++)
drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY, 50, 0, 22, yd);
// right end
drawTexturedModalRect(cornerX - 46 + 72, cornerY, 72, 0, 25, yd);



// bottom end
drawTexturedModalRect(cornerX - xleft, cornerY + yd, 0, 133, 72, 25);
for(int i = 0; i < columns-3; i++)
drawTexturedModalRect(cornerX - xleft + 72 + i*22, cornerY + yd, 50, 133, 22, 25);
drawTexturedModalRect(cornerX - 46 + 72, cornerY + yd, 72, 133, 25, 25);

// grayed out scroll bar
drawTexturedModalRect(cornerX + 32, (int) (cornerY + 8 + 127 * currentScroll), 110, 0, 12, 15);
}
}

xleft -= 8;
// Temperature
int slotSize = logic.getBlockCapacity();
if (slotSize > 24)
slotSize = 24;
if (slotSize > columns*maxRows)
slotSize = columns*maxRows;
int iter;
for (iter = 0; iter < slotSize && iter + slotPos*3 < logic.getBlockCapacity(); iter++)
for (iter = 0; iter < slotSize && iter + slotPos*columns < logic.getBlockCapacity(); iter++)
{
int slotTemp = logic.getTempForSlot(iter + slotPos * 3) - 20;
int maxTemp = logic.getMeltingPointForSlot(iter + slotPos * 3) - 20;
int slotTemp = logic.getTempForSlot(iter + slotPos * columns) - 20;
int maxTemp = logic.getMeltingPointForSlot(iter + slotPos * columns) - 20;
if (slotTemp > 0 && maxTemp > 0)
{
int size = 16 * slotTemp / maxTemp + 1;
drawTexturedModalRect(cornerX - 38 + (iter % 3 * 22), cornerY + 8 + (iter / 3 * 18) + 16 - size, 98, 15 + 16 - size, 5, size);
drawTexturedModalRect(cornerX - xleft + (iter % columns * 22), cornerY + 8 + (iter / columns * 18) + 16 - size, 98, 15 + 16 - size, 5, size);
}
}

// hide nonexistant slots
for (; iter < slotSize; iter++)
int maxSlots = Math.min(maxRows, h) * columns;
for (; iter < maxSlots; iter++)
{
drawTexturedModalRect(cornerX - 38 + (iter % 3 * 22)-1, cornerY + 8 + (iter / 3 * 18)-1, 98, 47, 22, 18);
drawTexturedModalRect(cornerX - xleft + (iter % columns * 22)-1, cornerY + 8 + (iter / columns * 18)-1, 98, 47, 22, 18);
}
}

Expand Down
32 changes: 21 additions & 11 deletions src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java
Expand Up @@ -5,32 +5,38 @@
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.smeltery.gui.SmelteryGui;
import tconstruct.smeltery.logic.SmelteryLogic;

public class SmelteryContainer extends ActiveContainer
{
public SmelteryLogic logic;
public InventoryPlayer playerInv;
public int fuel = 0;
int slotRow;
private int slotRow;
public int columns;

public SmelteryContainer(InventoryPlayer inventoryplayer, SmelteryLogic smeltery)
{
logic = smeltery;
playerInv = inventoryplayer;
slotRow = 0;
columns = smeltery.getBlocksPerLayer() >= 16 ? 4 : 3;

/* Smeltery inventory */

// new rectangular smeltery
int totalSlots = smeltery.getBlockCapacity();
int y = 0;

int xleft = 2;
xleft -= 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns

for(int i = 0; i < totalSlots; i++)
{
int x = i%3;
this.addDualSlotToContainer(new ActiveSlot(smeltery, x + y * 3, 2 + x * 22, 8 + y * 18, y < 8));
if(x == 2)
int x = i%columns;
this.addDualSlotToContainer(new ActiveSlot(smeltery, x + y * columns, xleft + x * 22, 8 + y * 18, y < 8));
if(x == columns-1)
y++;
}

Expand All @@ -55,21 +61,24 @@ public int updateRows (int invRow)
{
slotRow = invRow;
// TConstruct.logger.info(invRow);
int basePos = invRow * 3;
int basePos = invRow * columns;
for (int iter = 0; iter < activeInventorySlots.size(); iter++)
{
ActiveSlot slot = (ActiveSlot) activeInventorySlots.get(iter);
if (slot.activeSlotNumber >= basePos && slot.activeSlotNumber < basePos + 24)
if (slot.activeSlotNumber >= basePos && slot.activeSlotNumber < basePos + columns*SmelteryGui.maxRows)
{
slot.setActive(true);
}
else
{
slot.setActive(false);
}
int xPos = (iter - basePos) % 3;
int yPos = (iter - basePos) / 3;
slot.xDisplayPosition = 2 + 22 * xPos;
int xleft = 2;
xleft -= 22 * (columns-3); // we have to shift the whole thing to the left if we have more than 3 columns

int xPos = (iter - basePos) % columns;
int yPos = (iter - basePos) / columns;
slot.xDisplayPosition = xleft + 22 * xPos;
slot.yDisplayPosition = 8 + 18 * yPos;
}
return slotRow;
Expand All @@ -79,8 +88,9 @@ public int updateRows (int invRow)

public int scrollTo (float scrollPos)
{
float total = (logic.getSizeInventory() - 24) / 3;
if((logic.getSizeInventory() - 24)%3 != 0)
int slots = SmelteryGui.maxRows*columns;
float total = (logic.getSizeInventory() - slots) / columns;
if((logic.getSizeInventory() - slots)%columns != 0)
total++;
int rowPos = Math.round(total * scrollPos);
return updateRows(rowPos);
Expand Down

0 comments on commit 711fe0d

Please sign in to comment.