Improve terminal search box (#3064)

Uses exsting JEI filter in JEI mode.
Preselects text for easy delete/change without using rightclick.
QoL improvements for focus handling.
This commit is contained in:
fscan
2017-09-16 17:44:16 +02:00
committed by yueh
parent 54c0ce43ea
commit 4dd0a4cd96
7 changed files with 87 additions and 45 deletions
@@ -84,7 +84,6 @@ import appeng.helpers.InventoryAction;
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<>();
@@ -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 )
@@ -123,11 +119,6 @@ public abstract class AEBaseGui extends GuiContainer
}
}
public boolean isSubGui()
{
return this.subGui;
}
@Override
public void initGui()
{
@@ -588,7 +579,6 @@ public abstract class AEBaseGui extends GuiContainer
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 )
@@ -871,14 +861,4 @@ public abstract class AEBaseGui extends GuiContainer
{
return this.meSlots;
}
public static final synchronized boolean isSwitchingGuis()
{
return switchingGuis;
}
public static final synchronized void setSwitchingGuis( final boolean switchingGuis )
{
AEBaseGui.switchingGuis = switchingGuis;
}
}
@@ -60,6 +60,7 @@ import appeng.core.sync.network.NetworkHandler;
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;
@@ -304,6 +305,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
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 )
@@ -313,13 +315,19 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
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();
@@ -363,12 +371,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
@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 ) )
{
@@ -21,6 +21,10 @@ package appeng.client.gui.widgets;
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;
/**
@@ -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.
@@ -66,8 +71,11 @@ public class MEGuiTextField extends GuiTextField
super.mouseClicked( xPos, yPos, button );
final boolean requiresFocus = this.isMouseIn( xPos, yPos );
if( !this.isFocused() )
{
this.setFocused( requiresFocus );
}
this.setFocused( requiresFocus );
return true;
}
@@ -86,4 +94,69 @@ public class MEGuiTextField extends GuiTextField
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();
}
}
+1 -1
View File
@@ -194,7 +194,7 @@ public class ItemRepo
notDone = false;
}
if( terminalSearchToolTips && notDone )
if( terminalSearchToolTips && notDone && !searchMod )
{
for( final Object lp : Platform.getTooltip( is ) )
{
@@ -57,7 +57,6 @@ import appeng.core.AELog;
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;
@@ -353,8 +352,6 @@ public class ContainerCraftConfirm extends AEBaseContainer
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 );
}
@@ -26,7 +26,6 @@ import net.minecraft.entity.player.EntityPlayer;
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;
@@ -51,11 +50,6 @@ public class PacketSwitchGuis extends AppEngPacket
{
this.newGui = newGui;
if( Platform.isClient() )
{
AEBaseGui.setSwitchingGuis( true );
}
final ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
@@ -79,10 +73,4 @@ public class PacketSwitchGuis extends AppEngPacket
}
}
}
@Override
public void clientPacketData( final INetworkInfo network, final AppEngPacket packet, final EntityPlayer player )
{
AEBaseGui.setSwitchingGuis( true );
}
}