Gui/Container over haul to get Bus Guis working.

This commit is contained in:
AlgorithmX2 2014-01-01 02:57:16 -06:00
parent 2a4e4c0369
commit 6b37ef8847
10 changed files with 241 additions and 99 deletions

View File

@ -23,6 +23,8 @@ import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ITooltip;
import appeng.client.me.InternalSlotME;
import appeng.client.me.SlotME;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFake;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.helpers.InventoryAction;
import cpw.mods.fml.common.network.PacketDispatcher;
@ -69,6 +71,29 @@ public abstract class AEBaseGui extends GuiContainer
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if ( slot instanceof SlotFake )
{
InventoryAction action = null;
IAEItemStack stack = null;
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACESINGLE : InventoryAction.PICKUP_OR_SETDOWN;
if ( action != null )
{
PacketInventoryAction p;
try
{
p = new PacketInventoryAction( action, slotIdx, stack );
PacketDispatcher.sendPacketToServer( p.getPacket() );
}
catch (IOException e)
{
e.printStackTrace();
}
}
return;
}
if ( slot instanceof SlotME )
{
InventoryAction action = null;
@ -107,7 +132,7 @@ public abstract class AEBaseGui extends GuiContainer
PacketInventoryAction p;
try
{
p = new PacketInventoryAction( action, slotIdx, stack );
p = new PacketInventoryAction( action, inventorySlots.inventorySlots.size(), stack );
PacketDispatcher.sendPacketToServer( p.getPacket() );
}
catch (IOException e)
@ -276,6 +301,16 @@ public abstract class AEBaseGui extends GuiContainer
int oy = guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
drawBG( ox, oy, x, y );
for (Object o : inventorySlots.inventorySlots)
{
if ( o instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) o;
if ( fs.isEnabled() )
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 );
}
}
}
@Override

View File

@ -5,12 +5,16 @@ import appeng.api.implementations.IBusCommon;
import appeng.client.gui.AEBaseGui;
import appeng.container.implementations.ContainerBus;
import appeng.core.localization.GuiText;
import appeng.parts.automation.PartImportBus;
public class GuiBus extends AEBaseGui
{
IBusCommon bc;
public GuiBus(InventoryPlayer inventoryPlayer, IBusCommon te) {
super( new ContainerBus( inventoryPlayer, te ) );
bc = te;
this.xSize = hasToolbox() ? 246 : 211;
this.ySize = 184;
}
@ -33,7 +37,7 @@ public class GuiBus extends AEBaseGui
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
fontRenderer.drawString( GuiText.Drive.getLocal(), 8, 6, 4210752 );
fontRenderer.drawString( (bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus).getLocal(), 8, 6, 4210752 );
fontRenderer.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
}

View File

@ -43,6 +43,11 @@ public abstract class AEBaseContainer extends Container
tileEntity = te;
}
public boolean canDragIntoSlot(Slot s)
{
return ((AppEngSlot) s).isDraggable;
}
public TileEntity getTileEntity()
{
return tileEntity;
@ -298,6 +303,7 @@ public abstract class AEBaseContainer extends Container
private void updateSlot(Slot clickSlot)
{
// ???
detectAndSendChanges();
}
@ -329,11 +335,60 @@ public abstract class AEBaseContainer extends Container
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, IAEItemStack slotItem)
{
/*
* boolean isValidSlot = true;
*
* if ( slot < 0 || slot >= inventorySlots.size() ) isValidSlot = false;
*/
if ( slot >= 0 && slot < inventorySlots.size() )
{
Slot s = getSlot( slot );
if ( s instanceof SlotFake )
{
ItemStack hand = player.inventory.getItemStack();
switch (action)
{
case PICKUP_OR_SETDOWN:
if ( hand == null )
s.putStack( null );
else
s.putStack( hand.copy() );
break;
case SPLIT_OR_PLACESINGLE:
ItemStack is = s.getStack();
if ( is != null )
{
if ( hand == null )
is.stackSize--;
else if ( hand.isItemEqual( is ) )
is.stackSize = Math.min( is.getMaxStackSize(), is.stackSize + 1 );
else
{
is = hand.copy();
is.stackSize = 1;
}
s.putStack( is );
}
else if ( hand != null )
{
is = hand.copy();
is.stackSize = 1;
s.putStack( is );
}
break;
case CREATIVE_DUPLICATE:
case MOVE_REGION:
case SHIFT_CLICK:
default:
break;
}
}
return;
}
switch (action)
{

View File

@ -2,11 +2,13 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IBusCommon;
import appeng.container.AEBaseContainer;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFake;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.tile.inventory.AppEngInternalInventory;
@ -22,10 +24,10 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost
myte = te;
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 ) );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 )).setNotDraggable() );
if ( hasToolbox() )
{
@ -38,43 +40,51 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost
int y = 40;
IInventory inv = myte.getInventoryByName( "config" );
addSlotToContainer( new SlotFake( inv, 0, x, y ) );
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 1, x, y, -1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 2, x, y, 1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 3, x, y, 0, -1, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 4, x, y, 0, 1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 5, x, y, -1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 6, x, y, 1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 7, x, y, -1, 1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 8, x, y, 1, 1, 2 ) );
/*
* addSlotToContainer( new OptionalSlotFake( inv, this, 9, x, y, -2, 0, 3 ) ); addSlotToContainer( new
* OptionalSlotFake( inv, this, 10, x, y, 2, 0, 3 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 11,
* x, y, 0, -2, 3 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 12, x, y, 0, 2, 3 ) );
*
* addSlotToContainer( new OptionalSlotFake( inv, this, 13, x, y, 2, 1, 4 ) ); addSlotToContainer( new
* OptionalSlotFake( inv, this, 14, x, y, 2, -1, 4 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 15,
* x, y, -2, -1, 4 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 16, x, y, -2, 1, 4 ) );
*/
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
bindPlayerInventory( ip, 0, 184 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
for (Object o : inventorySlots)
{
if ( o instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) o;
if ( !fs.isEnabled() && fs.getDisplayStack() != null )
((OptionalSlotFake) fs).clearStack();
}
}
super.detectAndSendChanges();
}
public boolean hasToolbox()
{
// TODO Auto-generated method stub
return true;
return false;
}
@Override
public boolean isSlotEnabled(int idx, OptionalSlotFake osf)
{
if ( idx == 1 )
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
if ( idx == 1 && upgrades > 0 )
return true;
if ( idx == 2 )
if ( idx == 2 && upgrades > 1 )
return true;
return false;

View File

@ -1,5 +1,6 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@ -12,8 +13,15 @@ public class AppEngSlot extends Slot
NotAvailable, Valid, Invalid
};
public boolean isDraggable = true;
public boolean isPlayerSide = false;
public Slot setNotDraggable()
{
isDraggable = false;
return this;
}
public Slot setPlayerSide()
{
isPlayerSide = true;
@ -24,6 +32,17 @@ public class AppEngSlot extends Slot
public hasCalculatedValidness isValid;
public int defX, defY;
@Override
public boolean func_111238_b()
{
return isEnabled();
}
public boolean isEnabled()
{
return true;
}
public String getTooltip()
{
return null;
@ -48,6 +67,9 @@ public class AppEngSlot extends Slot
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
return null;
if ( isDisplay )
{
isDisplay = false;
@ -56,6 +78,34 @@ public class AppEngSlot extends Slot
return super.getStack();
}
@Override
public void putStack(ItemStack par1ItemStack)
{
if ( isEnabled() )
super.putStack( par1ItemStack );
}
public void clearStack()
{
super.putStack( null );
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
if ( isEnabled() )
return super.canTakeStack( par1EntityPlayer );
return false;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
if ( isEnabled() )
return super.isItemValid( par1ItemStack );
return false;
}
public ItemStack getDisplayStack()
{
return super.getStack();

View File

@ -1,6 +1,7 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFake extends SlotFake
{
@ -9,8 +10,8 @@ public class OptionalSlotFake extends SlotFake
final int groupNum;
IOptionalSlotHost host;
int srcX;
int srcY;
public int srcX;
public int srcY;
public OptionalSlotFake(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, idx, x + offX * 18, y + offY * 18 );
@ -18,11 +19,27 @@ public class OptionalSlotFake extends SlotFake
srcY = y;
invSlot = idx;
this.groupNum = groupNum;
host = containerBus;
}
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
{
if ( getDisplayStack() != null )
clearStack();
}
return super.getStack();
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum, this );
}

View File

@ -0,0 +1,27 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFakeTypeOnly extends OptionalSlotFake
{
public OptionalSlotFakeTypeOnly(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@Override
public void putStack(ItemStack is)
{
if ( is != null )
{
is = is.copy();
if ( is.stackSize > 1 )
is.stackSize = 1;
else if ( is.stackSize < -1 )
is.stackSize = -1;
}
super.putStack( is );
}
}

View File

@ -3,7 +3,6 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.util.Platform;
public class SlotFake extends AppEngSlot
{
@ -15,40 +14,6 @@ public class SlotFake extends AppEngSlot
invSlot = idx;
}
public boolean isEnabled()
{
return true;
}
public void addToInv(ItemStack is)
{
if ( is != null )
{
ItemStack current = this.inventory.getStackInSlot( invSlot );
if ( current != null && Platform.isSameItem( current, is ) )
{
current.stackSize += is.stackSize;
if ( current.stackSize > inventory.getInventoryStackLimit() )
current.stackSize = inventory.getInventoryStackLimit();
}
else
{
current = is.copy();
if ( current.stackSize > inventory.getInventoryStackLimit() )
current.stackSize = inventory.getInventoryStackLimit();
this.inventory.setInventorySlotContents( invSlot, current );
}
}
else
{
this.inventory.setInventorySlotContents( invSlot, null );
}
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
@ -58,18 +23,6 @@ public class SlotFake extends AppEngSlot
@Override
public ItemStack decrStackSize(int par1)
{
ItemStack current = this.inventory.getStackInSlot( invSlot );
if ( current != null )
{
current.stackSize--;
if ( current.stackSize <= 0 )
{
this.inventory.setInventorySlotContents( invSlot, null );
}
}
return null;
}
@ -79,15 +32,18 @@ public class SlotFake extends AppEngSlot
}
@Override
public void putStack(ItemStack par1ItemStack)
public void putStack(ItemStack is)
{
this.inventory.setInventorySlotContents( invSlot, par1ItemStack );
if ( is != null )
is = is.copy();
super.putStack( is );
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return true;
return false;
}
}

View File

@ -10,18 +10,6 @@ public class SlotFakeTypeOnly extends SlotFake
super( inv, idx, x, y );
}
@Override
public void addToInv(ItemStack is)
{
if ( is != null )
{
is = is.copy();
is.stackSize = 1;
}
super.putStack( is );
}
@Override
public void putStack(ItemStack is)
{

View File

@ -7,7 +7,7 @@ public enum GuiText
{
inventory("container"), // mc's default Inventory localization.
Chest, StoredEnergy, Of, Condenser, Drive, GrindStone, VibrationChamber, SpatialIOPort, NetworkStatus, LevelEmitter, Terminal, Interface, Config, StoredItems, Patterns;
Chest, StoredEnergy, Of, Condenser, Drive, GrindStone, VibrationChamber, SpatialIOPort, NetworkStatus, LevelEmitter, Terminal, Interface, Config, StoredItems, Patterns, ImportBus, ExportBus;
String root;