Skip to content

Commit

Permalink
Fixes AppliedEnergistics#2608: Handle scrollbar on mouseclicks not du…
Browse files Browse the repository at this point in the history
…ring rendering.

(cherry picked from commit 6c91e85)
  • Loading branch information
yueh authored and xsun2001 committed Aug 8, 2017
1 parent f296445 commit d826e42
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/main/java/appeng/client/gui/AEBaseGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import appeng.container.slot.*;
import appeng.container.slot.AppEngSlot.hasCalculatedValidness;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketSwapSlots;
Expand Down Expand Up @@ -141,12 +142,6 @@ public void drawScreen( final int mouseX, final int mouseY, final float btn )
{
super.drawScreen( mouseX, mouseY, btn );

final boolean hasClicked = Mouse.isButtonDown( 0 );
if( hasClicked && this.scrollBar != null )
{
this.scrollBar.click( this, mouseX - this.guiLeft, mouseY - this.guiTop );
}

for( final Object c : this.buttonList )
{
if( c instanceof ITooltip )
Expand Down Expand Up @@ -270,9 +265,9 @@ protected final void drawGuiContainerForegroundLayer( final int x, final int y )
final int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );

if( this.scrollBar != null )
if( this.getScrollBar() != null )
{
this.scrollBar.draw( this );
this.getScrollBar().draw( this );
}

this.drawFG( ox, oy, x, y );
Expand All @@ -298,7 +293,8 @@ protected final void drawGuiContainerBackgroundLayer( final float f, final int x
{
if( fs.isEnabled() )
{
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18 );
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18,
18 );
}
else
{
Expand Down Expand Up @@ -332,6 +328,11 @@ protected void mouseClicked( final int xCoord, final int yCoord, final int btn )
}
}

if( this.getScrollBar() != null )
{
this.getScrollBar().click( this, xCoord - this.guiLeft, yCoord - this.guiTop );
}

super.mouseClicked( xCoord, yCoord, btn );
}

Expand All @@ -341,6 +342,11 @@ protected void mouseClickMove( final int x, final int y, final int c, final long
final Slot slot = this.getSlot( x, y );
final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();

if( this.getScrollBar() != null )
{
this.getScrollBar().click( this, x - this.guiLeft, y - this.guiTop );
}

if( slot instanceof SlotFake && itemstack != null )
{
this.drag_click.add( slot );
Expand All @@ -360,13 +366,13 @@ protected void mouseClickMove( final int x, final int y, final int c, final long
}

@Override
protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int key )
protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton )
{
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;

if( slot instanceof SlotFake )
{
final InventoryAction action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
final InventoryAction action = mouseButton == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;

if( this.drag_click.size() > 1 )
{
Expand All @@ -381,14 +387,14 @@ protected void handleMouseClick( final Slot slot, final int slotIdx, final int c

if( slot instanceof SlotPatternTerm )
{
if( key == 6 )
if( mouseButton == 6 )
{
return; // prevent weird double clicks..
}

try
{
NetworkHandler.instance.sendToServer( ( (SlotPatternTerm) slot ).getRequest( key == 1 ) );
NetworkHandler.instance.sendToServer( ( (SlotPatternTerm) slot ).getRequest( isShiftKeyDown() ) );
}
catch( final IOException e )
{
Expand All @@ -397,19 +403,20 @@ protected void handleMouseClick( final Slot slot, final int slotIdx, final int c
}
else if( slot instanceof SlotCraftingTerm )
{
if( key == 6 )
if( mouseButton == 6 )
{
return; // prevent weird double clicks..
}

InventoryAction action = null;
if( key == 1 )
if( isShiftKeyDown() )
{
action = InventoryAction.CRAFT_SHIFT;
}
else
{
action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
// Craft stack on right-click, craft single on left-click
action = ( mouseButton == 1 ) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}

final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
Expand Down Expand Up @@ -446,7 +453,7 @@ else if( slot instanceof SlotCraftingTerm )
{
InventoryAction action = null;

switch( key )
switch( mouseButton )
{
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
Expand Down Expand Up @@ -483,7 +490,7 @@ else if( slot instanceof SlotCraftingTerm )
InventoryAction action = null;
IAEItemStack stack = null;

switch( key )
switch( mouseButton )
{
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
Expand Down Expand Up @@ -557,7 +564,9 @@ else if( this.dbl_whichItem != null )
final List<Slot> slots = this.getInventorySlots();
for( final Slot inventorySlot : slots )
{
if( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.func_94527_a( inventorySlot, this.dbl_whichItem, true ) )
if( inventorySlot != null && inventorySlot.canTakeStack(
this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.func_94527_a(
inventorySlot, this.dbl_whichItem, true ) )
{
this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, ctrlDown, 1 );
}
Expand All @@ -567,7 +576,7 @@ else if( this.dbl_whichItem != null )
this.disableShiftClick = false;
}

super.handleMouseClick( slot, slotIdx, ctrlDown, key );
super.handleMouseClick( slot, slotIdx, ctrlDown, mouseButton );
}

@Override
Expand Down Expand Up @@ -661,9 +670,9 @@ public void handleMouseInput()
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
this.mouseWheelEvent( x, y, i / Math.abs( i ) );
}
else if( i != 0 && this.scrollBar != null )
else if( i != 0 && this.getScrollBar() != null )
{
this.scrollBar.wheel( i );
this.getScrollBar().wheel( i );
}
}

Expand Down Expand Up @@ -807,6 +816,7 @@ private void drawSlot( final Slot s )
tessellator.addVertexWithUV( par1 + 0, par2 + 0, this.zLevel, ( par3 + 0 ) * f, ( par4 + 0 ) * f1 );
tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, 1.0f );
tessellator.draw();

}
catch( final Exception err )
{
Expand All @@ -819,7 +829,8 @@ private void drawSlot( final Slot s )
{
if( ( (AppEngSlot) s ).getIsValid() == hasCalculatedValidness.NotAvailable )
{
boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
boolean isValid = s.isItemValid(
is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
if( isValid && s instanceof SlotRestrictedInput )
{
try
Expand Down Expand Up @@ -901,7 +912,7 @@ private void safeDrawSlot( final Slot s )

public void bindTexture( final String file )
{
final ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/" + file );
final ResourceLocation loc = new ResourceLocation( AppEng.MOD_ID, "textures/" + file );
this.mc.getTextureManager().bindTexture( loc );
}

Expand Down

0 comments on commit d826e42

Please sign in to comment.