Skip to content

Commit

Permalink
Improve terminal search box (#3064)
Browse files Browse the repository at this point in the history
Uses exsting JEI filter in JEI mode.
Preselects text for easy delete/change without using rightclick.
QoL improvements for focus handling.
  • Loading branch information
fscan authored and yueh committed Sep 16, 2017
1 parent 54c0ce4 commit 4dd0a4c
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 45 deletions.
20 changes: 0 additions & 20 deletions src/main/java/appeng/client/gui/AEBaseGui.java
Expand Up @@ -84,7 +84,6 @@

public abstract class AEBaseGui extends GuiContainer
{
private static boolean switchingGuis;
private final List<InternalSlotME> meSlots = new LinkedList<>();
// drag y
private final Set<Slot> drag_click = new HashSet<>();
Expand All @@ -94,13 +93,10 @@ public abstract class AEBaseGui extends GuiContainer
private Stopwatch dbl_clickTimer = Stopwatch.createStarted();
private ItemStack dbl_whichItem = ItemStack.EMPTY;
private Slot bl_clicked;
private boolean subGui;

public AEBaseGui( final Container container )
{
super( container );
this.subGui = switchingGuis;
switchingGuis = false;
}

protected static String join( final Collection<String> toolTip, final String delimiter )
Expand All @@ -123,11 +119,6 @@ protected int getQty( final GuiButton btn )
}
}

public boolean isSubGui()
{
return this.subGui;
}

@Override
public void initGui()
{
Expand Down Expand Up @@ -588,7 +579,6 @@ protected boolean checkHotbarKeys( final int keyCode )
public void onGuiClosed()
{
super.onGuiClosed();
this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI )
}

protected Slot getSlot( final int mouseX, final int mouseY )
Expand Down Expand Up @@ -871,14 +861,4 @@ protected List<InternalSlotME> getMeSlots()
{
return this.meSlots;
}

public static final synchronized boolean isSwitchingGuis()
{
return switchingGuis;
}

public static final synchronized void setSwitchingGuis( final boolean switchingGuis )
{
AEBaseGui.switchingGuis = switchingGuis;
}
}
Expand Up @@ -60,6 +60,7 @@
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.integration.Integrations;
import appeng.parts.reporting.AbstractPartTerminal;
import appeng.tile.misc.TileSecurityStation;
import appeng.util.IConfigManagerHost;
Expand Down Expand Up @@ -304,6 +305,7 @@ public void initGui()
this.searchField.setEnableBackgroundDrawing( false );
this.searchField.setMaxStringLength( 25 );
this.searchField.setTextColor( 0xFFFFFF );
this.searchField.setSelectionColor( 0xFF99FF99 );
this.searchField.setVisible( true );

if( this.viewCell || this instanceof GuiWirelessTerm )
Expand All @@ -313,13 +315,19 @@ public void initGui()
this.craftingStatusBtn.setHideEdge( 13 );
}

// Enum setting = AEConfig.instance().getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH );
final Enum setting = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_MODE );
this.searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.JEI_AUTOSEARCH == setting );
this.searchField.setCanLoseFocus( SearchBoxMode.MANUAL_SEARCH == setting || SearchBoxMode.JEI_MANUAL_SEARCH == setting );

if( this.isSubGui() )
if( setting == SearchBoxMode.JEI_AUTOSEARCH || setting == SearchBoxMode.JEI_MANUAL_SEARCH )
{
memoryText = Integrations.jei().getSearchText();
}

if( memoryText != null && !memoryText.isEmpty() )
{
this.searchField.setText( memoryText );
this.searchField.selectAll();
this.repo.setSearchString( memoryText );
this.repo.updateView();
this.setScrollBar();
Expand Down Expand Up @@ -363,12 +371,7 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
@Override
protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException
{
final Enum searchMode = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_MODE );

if( searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.JEI_AUTOSEARCH )
{
this.searchField.mouseClicked( xCoord, yCoord, btn );
}
this.searchField.mouseClicked( xCoord, yCoord, btn );

if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) )
{
Expand Down
75 changes: 74 additions & 1 deletion src/main/java/appeng/client/gui/widgets/MEGuiTextField.java
Expand Up @@ -21,6 +21,10 @@

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;


/**
Expand All @@ -39,6 +43,7 @@ public class MEGuiTextField extends GuiTextField
private final int _yPos;
private final int _width;
private final int _height;
private int selectionColor = 0xFF00FF00;

/**
* Uses the values to instantiate a padded version of a text field.
Expand Down Expand Up @@ -66,8 +71,11 @@ public boolean mouseClicked( final int xPos, final int yPos, final int button )
super.mouseClicked( xPos, yPos, button );

final boolean requiresFocus = this.isMouseIn( xPos, yPos );
if( !this.isFocused() )
{
this.setFocused( requiresFocus );
}

this.setFocused( requiresFocus );
return true;
}

Expand All @@ -86,4 +94,69 @@ public boolean isMouseIn( final int xCoord, final int yCoord )

return withinXRange && withinYRange;
}

public void selectAll()
{
this.setCursorPosition( 0 );
this.setSelectionPos( this.getMaxStringLength() );
}

public void setSelectionColor( int color )
{
this.selectionColor = color;
}

@Override
public void drawSelectionBox( int startX, int startY, int endX, int endY )
{
if( startX < endX )
{
int i = startX;
startX = endX;
endX = i;
}

startX += 1;
endX -= 1;

if( startY < endY )
{
int j = startY;
startY = endY;
endY = j;
}

startY -= PADDING;

if( endX > this.x + this.width )
{
endX = this.x + this.width;
}

if( startX > this.x + this.width )
{
startX = this.x + this.width;
}

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();

float red = (float) ( this.selectionColor >> 16 & 255 ) / 255.0F;
float blue = (float) ( this.selectionColor >> 8 & 255 ) / 255.0F;
float green = (float) ( this.selectionColor & 255 ) / 255.0F;
float alpha = (float) ( this.selectionColor >> 24 & 255 ) / 255.0F;

GlStateManager.color( red, green, blue, alpha );
GlStateManager.disableTexture2D();
GlStateManager.enableColorLogic();
GlStateManager.colorLogicOp( GlStateManager.LogicOp.OR_REVERSE );
bufferbuilder.begin( 7, DefaultVertexFormats.POSITION );
bufferbuilder.pos( (double) startX, (double) endY, 0.0D ).endVertex();
bufferbuilder.pos( (double) endX, (double) endY, 0.0D ).endVertex();
bufferbuilder.pos( (double) endX, (double) startY, 0.0D ).endVertex();
bufferbuilder.pos( (double) startX, (double) startY, 0.0D ).endVertex();
tessellator.draw();
GlStateManager.disableColorLogic();
GlStateManager.enableTexture2D();
}
}
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/me/ItemRepo.java
Expand Up @@ -194,7 +194,7 @@ public void updateView()
notDone = false;
}

if( terminalSearchToolTips && notDone )
if( terminalSearchToolTips && notDone && !searchMod )
{
for( final Object lp : Platform.getTooltip( is ) )
{
Expand Down
Expand Up @@ -57,7 +57,6 @@
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.PlayerSource;
import appeng.parts.reporting.PartCraftingTerminal;
Expand Down Expand Up @@ -353,8 +352,6 @@ public void startJob()
this.setAutoStart( false );
if( g != null && 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 );
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java
Expand Up @@ -26,7 +26,6 @@
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;

import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.core.sync.AppEngPacket;
Expand All @@ -51,11 +50,6 @@ public PacketSwitchGuis( final GuiBridge newGui )
{
this.newGui = newGui;

if( Platform.isClient() )
{
AEBaseGui.setSwitchingGuis( true );
}

final ByteBuf data = Unpooled.buffer();

data.writeInt( this.getPacketID() );
Expand All @@ -79,10 +73,4 @@ public void serverPacketData( final INetworkInfo manager, final AppEngPacket pac
}
}
}

@Override
public void clientPacketData( final INetworkInfo network, final AppEngPacket packet, final EntityPlayer player )
{
AEBaseGui.setSwitchingGuis( true );
}
}
1 change: 1 addition & 0 deletions src/main/resources/appeng_at.cfg
@@ -1,2 +1,3 @@
# GUI rendering
public net.minecraft.client.gui.inventory.GuiContainer func_146977_a(Lnet/minecraft/inventory/Slot;)V # drawSlot
public net.minecraft.client.gui.GuiTextField func_146188_c(IIII)V # drawSelectionBox

0 comments on commit 4dd0a4c

Please sign in to comment.