mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-21 04:32:18 +00:00
added GUI texts and tooltips, improve slot and item moving behavior
This commit is contained in:
1 parent
c28dc83c79
commit
f26b0ba3df
4 files changed
+169
-46
No files matched your search
@@ -1,7 +1,10 @@
|
||||
package crazypants.enderio.machine.gui;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -21,7 +24,13 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
protected Map<Slot, Point> playerSlotLocations = new HashMap<Slot, Point>();
|
||||
|
||||
protected Slot upgradeSlot;
|
||||
|
||||
protected final int startPlayerSlot;
|
||||
protected final int endPlayerSlot;
|
||||
protected final int startHotBarSlot;
|
||||
protected final int endHotBarSlot;
|
||||
|
||||
@SuppressWarnings("OverridableMethodCallInConstructor")
|
||||
public AbstractMachineContainer(InventoryPlayer playerInv, AbstractMachineEntity te) {
|
||||
this.tileEntity = te;
|
||||
|
||||
@@ -47,6 +56,7 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
int y = getPlayerInventoryOffset().y;
|
||||
|
||||
// add players inventory
|
||||
startPlayerSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
Point loc = new Point(x + j * 18, y + i * 18);
|
||||
@@ -55,13 +65,16 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
}
|
||||
|
||||
endPlayerSlot = inventorySlots.size();
|
||||
|
||||
startHotBarSlot = inventorySlots.size();
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
Point loc = new Point(x + i * 18, y + 58);
|
||||
Slot slot = new Slot(playerInv, i, loc.x, loc.y);
|
||||
addSlotToContainer(slot);
|
||||
playerSlotLocations.put(slot, loc);
|
||||
}
|
||||
endHotBarSlot = inventorySlots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,51 +102,28 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
|
||||
int startPlayerSlot = getIndexOfFirstPlayerInvSlot(slotDef);
|
||||
int endPlayerSlot = startPlayerSlot + 26;
|
||||
int startHotBarSlot = endPlayerSlot + 1;
|
||||
int endHotBarSlot = startHotBarSlot + 9;
|
||||
|
||||
ItemStack copystack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
if(slot != null && slot.getHasStack()) {
|
||||
|
||||
ItemStack origStack = slot.getStack();
|
||||
copystack = origStack.copy();
|
||||
|
||||
if(slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) {
|
||||
// merge from machine input slots to inventory
|
||||
if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) {
|
||||
return null;
|
||||
boolean merged = false;
|
||||
for(SlotRange range : getTargetSlotsForTransfer(slotIndex, slot)) {
|
||||
if(mergeItemStack(origStack, range.start, range.end, range.reverse)) {
|
||||
merged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if(slotDef.isOutputSlot(slotIndex)) {
|
||||
// merge result
|
||||
if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, true)) {
|
||||
return null;
|
||||
}
|
||||
if(!merged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(slotDef.isOutputSlot(slotIndex)) {
|
||||
slot.onSlotChange(origStack, copystack);
|
||||
|
||||
} else {
|
||||
//Check from inv->input then inv->upgrade then inv->hotbar or hotbar->inv
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
if(slotDef.getNumInputSlots() <= 0 || !mergeItemStack(origStack, slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1, false)) {
|
||||
if(slotDef.getNumUpgradeSlots() <= 0 || !mergeItemStack(origStack, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false)) {
|
||||
if(slotIndex <= endPlayerSlot) {
|
||||
if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) {
|
||||
if(!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(origStack.stackSize == 0) {
|
||||
@@ -142,8 +132,6 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
slot.onSlotChanged();
|
||||
|
||||
if(origStack.stackSize == copystack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
@@ -158,6 +146,59 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
return slotDef.getNumSlots();
|
||||
}
|
||||
|
||||
protected SlotRange getPlayerInventorySlotRange(boolean reverse) {
|
||||
return new SlotRange(startPlayerSlot, endHotBarSlot, reverse);
|
||||
}
|
||||
|
||||
protected SlotRange getPlayerInventoryWithoutHotbarSlotRange() {
|
||||
return new SlotRange(startPlayerSlot, endPlayerSlot, false);
|
||||
}
|
||||
|
||||
protected SlotRange getPlayerHotbarSlotRange() {
|
||||
return new SlotRange(startHotBarSlot, endHotBarSlot, false);
|
||||
}
|
||||
|
||||
protected void addInputSlotRanges(List<SlotRange> res) {
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
if(slotDef.getNumInputSlots() > 0) {
|
||||
res.add(new SlotRange(slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1, false));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addUpgradeSlotRanges(List<SlotRange> res) {
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
if(slotDef.getNumUpgradeSlots() > 0) {
|
||||
res.add(new SlotRange(slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addPlayerSlotRanges(List<SlotRange> res, int slotIndex) {
|
||||
if(slotIndex <= endPlayerSlot) {
|
||||
res.add(getPlayerHotbarSlotRange());
|
||||
}
|
||||
if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) {
|
||||
res.add(getPlayerInventoryWithoutHotbarSlotRange());
|
||||
}
|
||||
}
|
||||
|
||||
protected List<SlotRange> getTargetSlotsForTransfer(int slotIndex, Slot slot) {
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
if(slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(false));
|
||||
}
|
||||
if(slotDef.isOutputSlot(slotIndex)) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(true));
|
||||
}
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
ArrayList<SlotRange> res = new ArrayList<SlotRange>();
|
||||
addInputSlotRanges(res);
|
||||
addUpgradeSlotRanges(res);
|
||||
addPlayerSlotRanges(res, slotIndex);
|
||||
return res;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*/
|
||||
@@ -251,4 +292,16 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class SlotRange {
|
||||
final int start;
|
||||
final int end;
|
||||
final boolean reverse;
|
||||
|
||||
public SlotRange(int start, int end, boolean reverse) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.reverse = reverse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,15 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.TextFieldEIO;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.gui.GuiMachineBase;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GhostSlot;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -40,6 +44,13 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
private int scrollMax;
|
||||
private long scrollLastTime;
|
||||
|
||||
private final String headerCrafting;
|
||||
private final String headerReturn;
|
||||
private final String headerInventory;
|
||||
private final String infoTextFilter;
|
||||
|
||||
private final GuiToolTip tooltipReturn;
|
||||
|
||||
public GuiInventoryPanel(TileInventoryPanel te, Container container) {
|
||||
super(te, container);
|
||||
redstoneButton.visible = false;
|
||||
@@ -54,16 +65,27 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
tfFilter = new TextFieldEIO(fr, 109, 9, 106, 12);
|
||||
tfFilter = new TextFieldEIO(fr, 109, 10, 106, 10);
|
||||
tfFilter.setEnableBackgroundDrawing(false);
|
||||
btnSort = new IconButtonEIO(this, ID_SORT, 216, 7, getSortOrderIcon());
|
||||
|
||||
textFields.add(tfFilter);
|
||||
|
||||
headerCrafting = Lang.localize("gui.inventorypanel.header.crafting");
|
||||
headerReturn = Lang.localize("gui.inventorypanel.header.return");
|
||||
headerInventory = Lang.localize("container.inventory", false);
|
||||
infoTextFilter = Lang.localize("gui.inventorypanel.info.filter");
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.return.line");
|
||||
tooltipReturn = new GuiToolTip(new Rectangle(6, 72, 5*18, 8), list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
btnSort.onGuiInit();
|
||||
addToolTip(tooltipReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,7 +136,17 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
updateGhostSlots();
|
||||
}
|
||||
|
||||
int headerColor = 0x404040;
|
||||
FontRenderer fr = getFontRenderer();
|
||||
fr.drawString(headerCrafting, sx+7, sy+6, headerColor);
|
||||
fr.drawString(headerReturn, sx+7, sy+72, headerColor);
|
||||
fr.drawString(headerInventory, sx+38, sy+120, headerColor);
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
|
||||
if(!tfFilter.isFocused() && tfFilter.getText().isEmpty()) {
|
||||
fr.drawString(infoTextFilter, tfFilter.xPosition, tfFilter.yPosition, 0x707070);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.gui.AbstractMachineContainer;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.util.ItemUtil;
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -25,14 +29,18 @@ import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
|
||||
public class InventoryPanelContainer extends AbstractMachineContainer implements InventoryDatabaseServer.ChangeLog {
|
||||
|
||||
private static final int CRAFTING_GRID_X = 7;
|
||||
private static final int CRAFTING_GRID_Y = 16;
|
||||
public static final int CRAFTING_GRID_X = 7;
|
||||
public static final int CRAFTING_GRID_Y = 16;
|
||||
|
||||
private static final int RETURN_INV_X = 7;
|
||||
private static final int RETURN_INV_Y = 82;
|
||||
public static final int RETURN_INV_X = 7;
|
||||
public static final int RETURN_INV_Y = 82;
|
||||
|
||||
private final HashSet<InventoryDatabaseServer.ItemEntry> changedItems;
|
||||
|
||||
private int indexCraftingSlot;
|
||||
private int startReturnSlot;
|
||||
private int endReturnSlot;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public InventoryPanelContainer(InventoryPlayer playerInv, TileInventoryPanel te) {
|
||||
super(playerInv, te);
|
||||
@@ -47,6 +55,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
|
||||
@Override
|
||||
protected void addMachineSlots(InventoryPlayer playerInv) {
|
||||
indexCraftingSlot = inventorySlots.size();
|
||||
addSlotToContainer(new SlotCrafting(playerInv.player, tileEntity, tileEntity, 9, CRAFTING_GRID_X+59, CRAFTING_GRID_Y+18) {
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack p_82870_2_) {
|
||||
@@ -86,11 +95,13 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
}
|
||||
}
|
||||
|
||||
startReturnSlot = inventorySlots.size();
|
||||
for(int y=0,i=10 ; y<2 ; y++) {
|
||||
for(int x=0 ; x<5 ; x++,i++) {
|
||||
addSlotToContainer(new Slot(tileEntity, i, RETURN_INV_X+x*18, RETURN_INV_Y+y*18));
|
||||
}
|
||||
}
|
||||
endReturnSlot = inventorySlots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,6 +172,29 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
tileEntity.setInventorySlotContents(9, CraftingManager.getInstance().findMatchingRecipe(tmp, tileEntity.getWorldObj()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94530_a(ItemStack par1, Slot slot) {
|
||||
return !(slot instanceof SlotCrafting) && super.func_94530_a(par1, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SlotRange> getTargetSlotsForTransfer(int slotIndex, Slot slot) {
|
||||
SlotDefinition slotDef = tileEntity.getSlotDefinition();
|
||||
if(slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(false));
|
||||
}
|
||||
if(slotDef.isOutputSlot(slotIndex) || slotIndex == indexCraftingSlot) {
|
||||
return Collections.singletonList(getPlayerInventorySlotRange(true));
|
||||
}
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
ArrayList<SlotRange> res = new ArrayList<SlotRange>();
|
||||
res.add(new SlotRange(startReturnSlot, endReturnSlot, false));
|
||||
addPlayerSlotRanges(res, slotIndex);
|
||||
return res;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entryChanged(InventoryDatabaseServer.ItemEntry entry) {
|
||||
changedItems.add(entry);
|
||||
@@ -213,10 +247,6 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
slot = null;
|
||||
targetStack = player.inventory.getItemStack();
|
||||
maxStackSize = player.inventory.getInventoryStackLimit();
|
||||
|
||||
if(targetStack != null && targetStack.stackSize > 0) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
slot = getSlot(targetSlot);
|
||||
targetStack = slot.getStack();
|
||||
|
||||
Reference in new issue
Block a user