mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
Add button to sync inventory panel search field with NEI
This commit is contained in:
1 parent
17d18995e9
commit
29fd49cc01
8 files changed
+91
-19
No files matched your search
@@ -24,6 +24,7 @@ public class IconButtonEIO extends GuiButton {
|
||||
private int yOrigin;
|
||||
|
||||
protected IGuiScreen gui;
|
||||
protected String[] toolTipText;
|
||||
|
||||
private GuiToolTip toolTip;
|
||||
private int marginY = 0;
|
||||
@@ -46,8 +47,19 @@ public class IconButtonEIO extends GuiButton {
|
||||
} else {
|
||||
toolTip.setToolTipText(tooltipText);
|
||||
}
|
||||
this.toolTipText = tooltipText;
|
||||
}
|
||||
|
||||
|
||||
protected void setToolTip(GuiToolTip newToolTip) {
|
||||
if (toolTip != null) {
|
||||
gui.removeToolTip(toolTip);
|
||||
}
|
||||
toolTip = newToolTip;
|
||||
if (toolTip != null) {
|
||||
gui.addToolTip(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
public final Rectangle getBounds() {
|
||||
return new Rectangle(xOrigin, yOrigin, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
|
||||
public class ToggleButtonEIO extends IconButtonEIO {
|
||||
@@ -8,9 +13,8 @@ public class ToggleButtonEIO extends IconButtonEIO {
|
||||
private boolean selected;
|
||||
private final IconEIO unselectedIcon;
|
||||
private final IconEIO selectedIcon;
|
||||
|
||||
private String[] selectedTooltip;
|
||||
private String[] unselectedTooltip;
|
||||
|
||||
private GuiToolTip selectedTooltip, unselectedTooltip;
|
||||
private boolean paintSelectionBorder;
|
||||
|
||||
public ToggleButtonEIO(IGuiScreen gui, int id, int x, int y, IconEIO unselectedIcon, IconEIO selectedIcon) {
|
||||
@@ -64,12 +68,14 @@ public class ToggleButtonEIO extends IconButtonEIO {
|
||||
}
|
||||
|
||||
public void setSelectedToolTip(String... tt) {
|
||||
this.selectedTooltip = tt;
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
selectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
public void setUnselectedToolTip(String... tt) {
|
||||
this.unselectedTooltip = tt;
|
||||
String[] combinedTooltip = ArrayUtils.addAll(toolTipText, tt);
|
||||
unselectedTooltip = new GuiToolTip(getBounds(), Lists.newArrayList(combinedTooltip));
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.nei.LayoutManager;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.fluid.Fluids;
|
||||
@@ -24,6 +26,7 @@ import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.MultiIconButtonEIO;
|
||||
import crazypants.enderio.gui.TextFieldEIO;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.gui.VScrollbarEIO;
|
||||
import crazypants.enderio.machine.gui.GuiMachineBase;
|
||||
@@ -51,6 +54,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
private static final int ID_SORT = 9876;
|
||||
private static final int ID_CLEAR = 9877;
|
||||
private static final int ID_SYNC = 9878;
|
||||
|
||||
private static final int GHOST_COLUMNS = 6;
|
||||
private static final int GHOST_ROWS = 5;
|
||||
@@ -58,6 +62,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
private final DatabaseView view;
|
||||
private final TextFieldEIO tfFilter;
|
||||
private final IconButtonEIO btnSort;
|
||||
private final ToggleButtonEIO btnSync;
|
||||
private final GuiToolTip ttRefill;
|
||||
private final GuiToolTip ttSetReceipe;
|
||||
private final VScrollbarEIO scrollbar;
|
||||
@@ -103,9 +108,18 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
btnSync = new ToggleButtonEIO(this, ID_SYNC, 24 + 233, 46, IconEIO.CROSS, IconEIO.TICK);
|
||||
btnSync.setToolTip(Lang.localize("gui.inventorypanel.tooltip.sync"));
|
||||
btnSync.setSelectedToolTip(Lang.localize("gui.enabled"));
|
||||
btnSync.setUnselectedToolTip(Lang.localize("gui.disabled"));
|
||||
btnSync.setSelected(getTileEntity().getGuiSync());
|
||||
if (!Loader.isModLoaded("NotEnoughItems")) {
|
||||
btnSync.enabled = false;
|
||||
}
|
||||
|
||||
tfFilter = new TextFieldEIO(fr, 24+108, 11, 106, 10);
|
||||
tfFilter.setEnableBackgroundDrawing(false);
|
||||
tfFilter.setText(te.getGuiFilterString());
|
||||
setText(tfFilter, te.getGuiFilterString());
|
||||
btnSort = new IconButtonEIO(this, ID_SORT, 24+233, 27, getSortOrderIcon()) {
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int x, int y) {
|
||||
@@ -121,6 +135,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
scrollbar = new VScrollbarEIO(this, 24+215, 27, 90);
|
||||
btnClear = new MultiIconButtonEIO(this, ID_CLEAR, 24+65, 60, IconEIO.X_BUT, IconEIO.X_BUT_PRESSED, IconEIO.X_BUT_HOVER);
|
||||
|
||||
@@ -200,7 +215,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
if(view.isSortOrderInverted()) {
|
||||
sortMode |= 1;
|
||||
}
|
||||
getTileEntity().setGuiParameter(sortMode, tfFilter.getText());
|
||||
getTileEntity().setGuiParameter(sortMode, tfFilter.getText(), btnSync.isSelected());
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@@ -234,16 +249,21 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
updateSortButton();
|
||||
btnSort.onGuiInit();
|
||||
btnClear.onGuiInit();
|
||||
btnSync.onGuiInit();
|
||||
addScrollbar(scrollbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == ID_CLEAR) {
|
||||
if(getContainer().clearCraftingGrid()) {
|
||||
if (b.id == ID_CLEAR) {
|
||||
if (getContainer().clearCraftingGrid()) {
|
||||
setCraftingHelper(null);
|
||||
}
|
||||
} else if (b.id == ID_SYNC) {
|
||||
if (Loader.isModLoaded("NotEnoughItems")) {
|
||||
updateNEI(((ToggleButtonEIO) b).isSelected() ? tfFilter.getText() : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,11 +345,22 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
}
|
||||
} else {
|
||||
tfFilter.setEnabled(false);
|
||||
tfFilter.setText("");
|
||||
setText(tfFilter, "");
|
||||
fr.drawString(infoTextOffline, tfFilter.xPosition, tfFilter.yPosition, 0x707070);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTextFieldChanged(TextFieldEIO tf, String old) {
|
||||
if (tf == tfFilter && btnSync.enabled && tfFilter.isFocused() && Loader.isModLoaded("NotEnoughItems")) {
|
||||
updateNEI(tfFilter.getText());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNEI(String text) {
|
||||
LayoutManager.searchField.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawFakeItemStack(int x, int y, ItemStack stack) {
|
||||
FontRenderer font = stack.getItem().getFontRenderer(stack);
|
||||
|
||||
@@ -13,15 +13,17 @@ public class PacketGuiSettings extends MessageTileEntity<TileInventoryPanel> imp
|
||||
|
||||
private int sortMode;
|
||||
private String filterString;
|
||||
|
||||
private boolean sync;
|
||||
|
||||
public PacketGuiSettings() {
|
||||
filterString = "";
|
||||
}
|
||||
|
||||
public PacketGuiSettings(TileInventoryPanel tile, int sortMode, String filterString) {
|
||||
public PacketGuiSettings(TileInventoryPanel tile, int sortMode, String filterString, boolean sync) {
|
||||
super(tile);
|
||||
this.sortMode = sortMode;
|
||||
this.filterString = filterString;
|
||||
this.sync = sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +66,7 @@ public class PacketGuiSettings extends MessageTileEntity<TileInventoryPanel> imp
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof TileInventoryPanel) {
|
||||
TileInventoryPanel teInvPanel = (TileInventoryPanel) te;
|
||||
teInvPanel.setGuiParameter(message.sortMode, message.filterString);
|
||||
teInvPanel.setGuiParameter(message.sortMode, message.filterString, message.sync);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
|
||||
private int guiSortMode;
|
||||
private String guiFilterString = "";
|
||||
private boolean guiSync;
|
||||
|
||||
private final ArrayList<StoredCraftingRecipe> storedCraftingRecipes;
|
||||
|
||||
@@ -224,12 +225,17 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
public String getGuiFilterString() {
|
||||
return guiFilterString;
|
||||
}
|
||||
|
||||
public boolean getGuiSync() {
|
||||
return guiSync;
|
||||
}
|
||||
|
||||
public void setGuiParameter(int sortMode, String filterString) {
|
||||
public void setGuiParameter(int sortMode, String filterString, boolean sync) {
|
||||
this.guiSortMode = sortMode;
|
||||
this.guiFilterString = filterString;
|
||||
this.guiSync = sync;
|
||||
if(worldObj != null && worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiSettings(this, sortMode, filterString));
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiSettings(this, sortMode, filterString, sync));
|
||||
} else {
|
||||
markDirty();
|
||||
}
|
||||
@@ -295,6 +301,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
nbtRoot.setInteger("guiSortMode", guiSortMode);
|
||||
nbtRoot.setString("guiFilterString", guiFilterString);
|
||||
nbtRoot.setBoolean("guiSync", guiSync);
|
||||
nbtRoot.setBoolean("extractionDisabled", extractionDisabled);
|
||||
|
||||
if(!storedCraftingRecipes.isEmpty()) {
|
||||
@@ -314,6 +321,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
guiSortMode = nbtRoot.getInteger("guiSortMode");
|
||||
guiFilterString = nbtRoot.getString("guiFilterString");
|
||||
guiSync = nbtRoot.getBoolean("guiSync");
|
||||
extractionDisabled = nbtRoot.getBoolean("extractionDisabled");
|
||||
faceModes = null;
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int key) {
|
||||
GuiTextField focused = null;
|
||||
for (GuiTextField f : textFields) {
|
||||
TextFieldEIO focused = null;
|
||||
for (TextFieldEIO f : textFields) {
|
||||
if (f.isFocused()) {
|
||||
focused = f;
|
||||
}
|
||||
@@ -98,7 +98,9 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
// If there is a focused text field, attempt to type into it
|
||||
if(focused != null) {
|
||||
String old = focused.getText();
|
||||
if(focused.textboxKeyTyped(c, key)) {
|
||||
onTextFieldChanged(focused, old);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +122,16 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
// If the key was not captured, let NEI do its thing
|
||||
super.keyTyped(c, key);
|
||||
}
|
||||
|
||||
protected final void setText(TextFieldEIO tf, String newText) {
|
||||
String old = tf.getText();
|
||||
tf.setText(newText);
|
||||
onTextFieldChanged(tf, old);
|
||||
}
|
||||
|
||||
protected void onTextFieldChanged(TextFieldEIO tf, String old) {
|
||||
|
||||
}
|
||||
|
||||
public boolean hideOverlays() {
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
@@ -212,7 +224,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
if(button == 1) {
|
||||
for (TextFieldEIO tf : textFields) {
|
||||
if(tf.contains(x, y)) {
|
||||
tf.setText("");
|
||||
setText(tf, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user