From ca738e606526c9ac4f1480caf26710553d5ad135 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 16 Feb 2014 03:09:20 -0600 Subject: [PATCH] Standard and Auto Search Settings. --- .../gui/implementations/GuiMEMonitorable.java | 48 ++++++++++++++++--- client/gui/widgets/MEGuiTextField.java | 28 +++++++++++ core/AEConfig.java | 25 ++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 client/gui/widgets/MEGuiTextField.java diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index 61398819..d05e2e4d 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -3,8 +3,8 @@ package appeng.client.gui.implementations; import java.util.List; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.InventoryPlayer; +import appeng.api.config.SearchBoxMode; import appeng.api.config.Settings; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IMEChest; @@ -14,6 +14,7 @@ import appeng.client.gui.AEBaseMEGui; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.ISortSource; +import appeng.client.gui.widgets.MEGuiTextField; import appeng.client.me.InternalSlotME; import appeng.client.me.ItemRepo; import appeng.container.implementations.ContainerMEMonitorable; @@ -28,7 +29,7 @@ import appeng.util.Platform; public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource { - GuiTextField searchField; + MEGuiTextField searchField; ItemRepo repo; GuiText myName; @@ -81,6 +82,12 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource myScrollBar.setRange( 0, (repo.size() + perRow - 1) / perRow - rows, Math.max( 1, rows / 6 ) ); } + public void re_init() + { + this.buttonList.clear(); + this.initGui(); + } + @Override public void initGui() { @@ -121,15 +128,21 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource offset += 20; } - buttonList.add( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, AEConfig.instance.settings - .getSetting( Settings.SORT_DIRECTION ) ) ); + buttonList + .add( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, AEConfig.instance.settings.getSetting( Settings.SORT_DIRECTION ) ) ); + offset += 20; - searchField = new GuiTextField( fontRendererObj, this.guiLeft + Math.max( 82, xoffset ), this.guiTop + 6, 89, fontRendererObj.FONT_HEIGHT ); + buttonList.add( new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ) ) ); + + searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 82, xoffset ), this.guiTop + 6, 89, fontRendererObj.FONT_HEIGHT ); searchField.setEnableBackgroundDrawing( false ); searchField.setMaxStringLength( 25 ); searchField.setTextColor( 0xFFFFFF ); searchField.setVisible( true ); - searchField.setFocused( true ); + + // Enum setting = AEConfig.instance.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH ); + Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); + searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting ); setScrollBar(); @@ -155,9 +168,29 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); iBtn.set( next ); repo.updateView(); + + if ( next.getClass() == SearchBoxMode.class ) + re_init(); } } + @Override + protected void mouseClicked(int xCoord, int yCoord, int btn) + { + Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); + if ( !(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting) ) + searchField.mouseClicked( xCoord, yCoord, btn ); + + if ( btn == 1 && searchField.isMouseIn( xCoord, yCoord ) ) + { + searchField.setText( "" ); + repo.searchString = ""; + repo.updateView(); + } + + super.mouseClicked( xCoord, yCoord, btn ); + } + @Override protected void keyTyped(char character, int key) { @@ -190,7 +223,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource this.drawTexturedModalRect( offsetX, offsetY + 16 + rows * 18 + lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + reservedSpace - lowerTextureOffset ); - searchField.drawTextBox(); + if ( searchField != null ) + searchField.drawTextBox(); } protected String getBackground() diff --git a/client/gui/widgets/MEGuiTextField.java b/client/gui/widgets/MEGuiTextField.java new file mode 100644 index 00000000..73f3159d --- /dev/null +++ b/client/gui/widgets/MEGuiTextField.java @@ -0,0 +1,28 @@ +package appeng.client.gui.widgets; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + +public class MEGuiTextField extends GuiTextField +{ + + int posX; + int posY; + + int myWidth; + int myHeight; + + public MEGuiTextField(FontRenderer par1FontRenderer, int xPos, int yPos, int width, int height) { + super( par1FontRenderer, xPos, yPos, width, height ); + posX = xPos; + posY = yPos; + myWidth = width; + myHeight = height; + } + + public boolean isMouseIn(int xCoord, int yCoord) + { + return xCoord >= posX && xCoord < posX + myWidth && yCoord >= posY && yCoord < posY + myHeight; + } + +} diff --git a/core/AEConfig.java b/core/AEConfig.java index adfe47ae..ff714bc6 100644 --- a/core/AEConfig.java +++ b/core/AEConfig.java @@ -8,6 +8,7 @@ import net.minecraftforge.common.config.Property; import appeng.api.config.CondenserOuput; import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerUnits; +import appeng.api.config.SearchBoxMode; import appeng.api.config.Settings; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; @@ -116,6 +117,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo settings.registerSetting( Settings.SEARCH_TOOLTIPS, YesNo.YES ); settings.registerSetting( Settings.SORT_BY, SortOrder.NAME ); settings.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING ); + settings.registerSetting( Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH ); WirelessBaseCost = get( "wireless", "WirelessBaseCost", WirelessBaseCost ).getDouble( WirelessBaseCost ); WirelessCostMultiplier = get( "wireless", "WirelessCostMultiplier", WirelessCostMultiplier ).getDouble( WirelessCostMultiplier ); @@ -232,4 +234,27 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo return false; } + public Enum getSetting(String Category, Class class1, Enum myDefault) + { + String name = class1.getSimpleName(); + Property p = get( Category, name, myDefault.name() ); + + try + { + return (Enum) class1.getField( p.toString() ).get( class1 ); + } + catch (Throwable t) + { + // :{ + } + + return myDefault; + } + + public void setSetting(String Category, Enum s) + { + String name = s.getClass().getSimpleName(); + get( Category, name, s.name() ).set( s.name() ); + save(); + } }