Skip to content

Commit

Permalink
CPU table enhancements: cycling, show in crafting confirmation dialog (
Browse files Browse the repository at this point in the history
…#167)

* Factor out the cpu table clientside widget

* Recursive GuiSync support

* Factor out container, add back cpu cycling via the big button

* Add busy cpu preference

* Use CPU table in craft confirmation dialog
  • Loading branch information
eigenraven authored Aug 24, 2022
1 parent aa14ac0 commit ef93068
Show file tree
Hide file tree
Showing 16 changed files with 939 additions and 699 deletions.
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/gui/AEBaseGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public void bindTexture( final String base, final String file )
this.mc.getTextureManager().bindTexture( loc );
}

protected void drawItem( final int x, final int y, final ItemStack is )
public void drawItem( final int x, final int y, final ItemStack is )
{
this.zLevel = 100.0F;
itemRender.zLevel = 100.0F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiCraftingCPUTable;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ICraftingCPUTableHolder;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.CraftingCPUStatus;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.core.localization.GuiColors;
Expand Down Expand Up @@ -55,10 +58,11 @@
import java.util.List;


public class GuiCraftConfirm extends AEBaseGui
public class GuiCraftConfirm extends AEBaseGui implements ICraftingCPUTableHolder
{

private final ContainerCraftConfirm ccc;
private final GuiCraftingCPUTable cpuTable;

private final int rows = 5;

Expand All @@ -84,6 +88,8 @@ public GuiCraftConfirm( final InventoryPlayer inventoryPlayer, final ITerminalHo
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar( scrollbar );

this.cpuTable = new GuiCraftingCPUTable( this, ((ContainerCraftConfirm) inventorySlots).cpuTable );

this.ccc = (ContainerCraftConfirm) this.inventorySlots;

if( te instanceof WirelessTerminalGuiObject )
Expand Down Expand Up @@ -112,7 +118,13 @@ public GuiCraftConfirm( final InventoryPlayer inventoryPlayer, final ITerminalHo
}
}

boolean isAutoStart()
@Override
public GuiCraftingCPUTable getCPUTable()
{
return cpuTable;
}

boolean isAutoStart()
{
return ( (ContainerCraftConfirm) this.inventorySlots ).isAutoStart();
}
Expand Down Expand Up @@ -143,7 +155,15 @@ public void drawScreen( final int mouseX, final int mouseY, final float btn )
{
this.updateCPUButtonText();

cpuTable.drawScreen( );

this.start.enabled = !( this.ccc.hasNoCPU() || this.isSimulation() );
if (this.start.enabled) {
CraftingCPUStatus selected = this.cpuTable.getContainer().getSelectedCPU();
if (selected == null || selected.getStorage() < this.ccc.getUsedBytes() || selected.isBusy()) {
this.start.enabled = false;
}
}
this.selectCPU.enabled = !this.isSimulation();

final int gx = ( this.width - this.xSize ) / 2;
Expand Down Expand Up @@ -212,6 +232,8 @@ private boolean isSimulation()
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
cpuTable.drawFG( offsetX, offsetY, mouseX, mouseY, guiLeft, guiTop );

final long BytesUsed = this.ccc.getUsedBytes();
final String byteUsed = NumberFormat.getInstance().format( BytesUsed );
final String Add = BytesUsed > 0 ? ( byteUsed + ' ' + GuiText.BytesUsed.getLocal() ) : GuiText.CalculatingWait.getLocal();
Expand Down Expand Up @@ -369,6 +391,7 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
cpuTable.drawBG( offsetX, offsetY );
this.setScrollBar();
this.bindTexture( "guis/craftingreport.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
Expand Down Expand Up @@ -529,14 +552,7 @@ protected void actionPerformed( final GuiButton btn )

if( btn == this.selectCPU )
{
try
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "Terminal.Cpu", backwards ? "Prev" : "Next" ) );
}
catch( final IOException e )
{
AELog.debug( e );
}
cpuTable.cycleCPU(backwards);
}

if( btn == this.cancel )
Expand All @@ -559,4 +575,33 @@ protected void actionPerformed( final GuiButton btn )
public ItemStack getHoveredStack() {
return hoveredStack;
}

@Override
protected void mouseClicked( int xCoord, int yCoord, int btn )
{
super.mouseClicked( xCoord, yCoord, btn );
cpuTable.mouseClicked( xCoord - guiLeft, yCoord - guiTop, btn );
}

@Override
protected void mouseClickMove( int x, int y, int c, long d )
{
super.mouseClickMove( x, y, c, d );
cpuTable.mouseClickMove( x - guiLeft, y - guiTop );
}

@Override
public void handleMouseInput()
{
if ( cpuTable.handleMouseInput(guiLeft, guiTop) )
{
return;
}
super.handleMouseInput();
}

public boolean hideItemPanelSlot( int x, int y, int w, int h )
{
return cpuTable.hideItemPanelSlot(x - guiLeft, y - guiTop, w, h );
}
}
Loading

0 comments on commit ef93068

Please sign in to comment.