Skip to content

Commit

Permalink
Add APIs to allow reuse of GUI classes in the Wireless Crafting Termi…
Browse files Browse the repository at this point in the history
…nal mod (#168)
  • Loading branch information
eigenraven authored Aug 24, 2022
1 parent ef93068 commit 4e0d3c4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ public void initGui()
this.selectCPU.enabled = false;
this.buttonList.add( this.selectCPU );

if( this.OriginalGui != null )
{
this.cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
}

this.cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
this.buttonList.add( this.cancel );
}

Expand Down Expand Up @@ -557,7 +553,7 @@ protected void actionPerformed( final GuiButton btn )

if( btn == this.cancel )
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( this.OriginalGui ) );
switchToOriginalGUI();
}

if( btn == this.start )
Expand All @@ -572,6 +568,12 @@ protected void actionPerformed( final GuiButton btn )
}
}
}

public void switchToOriginalGUI()
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( this.OriginalGui ) );
}

public ItemStack getHoveredStack() {
return hoveredStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
import appeng.core.sync.GuiBridge;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -87,4 +91,9 @@ public void setItemToCraft( @Nonnull final IAEItemStack itemToCreate )
{
this.itemToCreate = itemToCreate;
}

public void openConfirmationGUI( EntityPlayer player, TileEntity te )
{
Platform.openGUI( player, te, this.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,50 +254,58 @@ private boolean cpuMatches( final CraftingCPUStatus c )

public void startJob()
{
GuiBridge originalGui = null;

final IActionHost ah = this.getActionHost();
if( ah instanceof WirelessTerminalGuiObject )
{
originalGui = GuiBridge.GUI_WIRELESS_TERM;
}

if( ah instanceof PartTerminal )
{
originalGui = GuiBridge.GUI_ME;
}

if( ah instanceof PartCraftingTerminal )
{
originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
}

if( ah instanceof PartPatternTerminal )
{
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
}

if( ah instanceof PartPatternTerminalEx)
{
originalGui = GuiBridge.GUI_PATTERN_TERMINAL_EX;
}

if( this.result != null && !this.isSimulation() && getGrid() != null)
{
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
CraftingCPUStatus selected = this.cpuTable.getSelectedCPU();
final ICraftingLink g = cc.submitJob( this.result, null, (selected == null) ? null : selected.getServerCluster(), true, this.getActionSrc() );
this.setAutoStart( false );
if( g != null && originalGui != null && this.getOpenContext() != null )
if( g != null )
{
NetworkHandler.instance.sendTo( new PacketSwitchGuis( originalGui ), (EntityPlayerMP) this.getInventoryPlayer().player );

final TileEntity te = this.getOpenContext().getTile();
Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui );
this.switchToOriginalGUI();
}
}
}

public void switchToOriginalGUI()
{
GuiBridge originalGui = null;

final IActionHost ah = this.getActionHost();
if( ah instanceof WirelessTerminalGuiObject )
{
originalGui = GuiBridge.GUI_WIRELESS_TERM;
}

if( ah instanceof PartTerminal )
{
originalGui = GuiBridge.GUI_ME;
}

if( ah instanceof PartCraftingTerminal )
{
originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
}

if( ah instanceof PartPatternTerminal )
{
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
}

if( ah instanceof PartPatternTerminalEx)
{
originalGui = GuiBridge.GUI_PATTERN_TERMINAL_EX;
}

if (originalGui != null && this.getOpenContext() != null)
{
NetworkHandler.instance.sendTo( new PacketSwitchGuis( originalGui ), (EntityPlayerMP) this.getInventoryPlayer().player );

final TileEntity te = this.getOpenContext().getTile();
Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui );
}
}

private BaseActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public void serverPacketData( final INetworkInfo manager, final AppEngPacket pac
if( context != null )
{
final TileEntity te = context.getTile();
Platform.openGUI( player, te, cca.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM );
cca.openConfirmationGUI( player, te );

if( player.openContainer instanceof ContainerCraftConfirm )
if( player.openContainer instanceof ContainerCraftConfirm )
{
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setAutoStart( this.heldShift );
Expand Down

0 comments on commit 4e0d3c4

Please sign in to comment.