Add grid filter icon + name fields
This commit is contained in:
@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.container;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilter;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerGridFilter;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerGridFilterIcon;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -30,7 +31,9 @@ public class ContainerGridFilter extends ContainerBase {
|
||||
}
|
||||
}
|
||||
|
||||
addPlayerInventory(8, 126);
|
||||
addSlotToContainer(new SlotFilter(new ItemHandlerGridFilterIcon(stack), 0, 8, 117));
|
||||
|
||||
addPlayerInventory(8, 149);
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.container.ContainerGridFilter;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemGridFilter;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageGridFilterUpdate;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -14,19 +15,22 @@ public class GuiGridFilter extends GuiBase {
|
||||
private int compare;
|
||||
private int mode;
|
||||
private boolean modFilter;
|
||||
private String name;
|
||||
|
||||
private GuiCheckBox compareDamage;
|
||||
private GuiCheckBox compareNBT;
|
||||
private GuiCheckBox compareOredict;
|
||||
private GuiCheckBox toggleModFilter;
|
||||
private GuiButton toggleMode;
|
||||
private GuiTextField nameField;
|
||||
|
||||
public GuiGridFilter(ContainerGridFilter container) {
|
||||
super(container, 176, 208);
|
||||
super(container, 176, 231);
|
||||
|
||||
this.compare = ItemGridFilter.getCompare(container.getStack());
|
||||
this.mode = ItemGridFilter.getMode(container.getStack());
|
||||
this.modFilter = ItemGridFilter.isModFilter(container.getStack());
|
||||
this.name = ItemGridFilter.getName(container.getStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +41,13 @@ public class GuiGridFilter extends GuiBase {
|
||||
toggleModFilter = addCheckBox(0, y + 71 + 25, t("gui.refinedstorage:grid_filter.mod_filter"), modFilter);
|
||||
toggleMode = addButton(x + 7, y + 71 + 21, 0, 20, "");
|
||||
updateModeButton(mode);
|
||||
nameField = new GuiTextField(0, fontRendererObj, x + 34, y + 121, 137 - 6, fontRendererObj.FONT_HEIGHT);
|
||||
nameField.setText(name);
|
||||
nameField.setEnableBackgroundDrawing(false);
|
||||
nameField.setVisible(true);
|
||||
nameField.setCanLoseFocus(true);
|
||||
nameField.setFocused(false);
|
||||
nameField.setTextColor(16777215);
|
||||
}
|
||||
|
||||
private void updateModeButton(int mode) {
|
||||
@@ -55,12 +66,30 @@ public class GuiGridFilter extends GuiBase {
|
||||
bindTexture("gui/grid_filter.png");
|
||||
|
||||
drawTexture(x, y, 0, 0, width, height);
|
||||
|
||||
nameField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
drawString(7, 7, t("gui.refinedstorage:grid_filter"));
|
||||
drawString(7, 115, t("container.inventory"));
|
||||
drawString(7, 137, t("container.inventory"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char character, int keyCode) throws IOException {
|
||||
if (!checkHotbarKeys(keyCode) && nameField.textboxKeyTyped(character, keyCode)) {
|
||||
sendUpdate();
|
||||
} else {
|
||||
super.keyTyped(character, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int clickedButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, clickedButton);
|
||||
|
||||
nameField.mouseClicked(mouseX, mouseY, clickedButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +109,10 @@ public class GuiGridFilter extends GuiBase {
|
||||
modFilter = !modFilter;
|
||||
}
|
||||
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridFilterUpdate(compare, mode, modFilter));
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
private void sendUpdate() {
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridFilterUpdate(compare, mode, modFilter, nameField.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.raoulvdberge.refinedstorage.inventory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.item.ItemGridFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class ItemHandlerGridFilterIcon extends ItemStackHandler {
|
||||
private ItemStack stack;
|
||||
|
||||
public ItemHandlerGridFilterIcon(ItemStack stack) {
|
||||
super(1);
|
||||
|
||||
this.stack = stack;
|
||||
|
||||
setStackInSlot(0, ItemGridFilter.getIcon(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
ItemGridFilter.setIcon(stack, getStackInSlot(0));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ public class ItemGridFilter extends ItemBase {
|
||||
private static final String NBT_COMPARE = "Compare";
|
||||
private static final String NBT_MODE = "Mode";
|
||||
private static final String NBT_MOD_FILTER = "ModFilter";
|
||||
private static final String NBT_NAME = "Name";
|
||||
private static final String NBT_ICON = "Icon";
|
||||
|
||||
public ItemGridFilter() {
|
||||
super("grid_filter");
|
||||
@@ -98,4 +100,28 @@ public class ItemGridFilter extends ItemBase {
|
||||
|
||||
stack.getTagCompound().setBoolean(NBT_MOD_FILTER, modFilter);
|
||||
}
|
||||
|
||||
public static String getName(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_NAME) ? stack.getTagCompound().getString(NBT_NAME) : "";
|
||||
}
|
||||
|
||||
public static void setName(ItemStack stack, String name) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
stack.getTagCompound().setString(NBT_NAME, name);
|
||||
}
|
||||
|
||||
public static ItemStack getIcon(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ICON) ? new ItemStack(stack.getTagCompound().getCompoundTag(NBT_ICON)) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static void setIcon(ItemStack stack, ItemStack icon) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
stack.getTagCompound().setTag(NBT_ICON, icon.serializeNBT());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,23 @@ import com.raoulvdberge.refinedstorage.container.ContainerGridFilter;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemGridFilter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
public class MessageGridFilterUpdate extends MessageHandlerPlayerToServer<MessageGridFilterUpdate> implements IMessage {
|
||||
private int compare;
|
||||
private int mode;
|
||||
private boolean modFilter;
|
||||
private String name;
|
||||
|
||||
public MessageGridFilterUpdate() {
|
||||
}
|
||||
|
||||
public MessageGridFilterUpdate(int compare, int mode, boolean modFilter) {
|
||||
public MessageGridFilterUpdate(int compare, int mode, boolean modFilter, String name) {
|
||||
this.compare = compare;
|
||||
this.mode = mode;
|
||||
this.modFilter = modFilter;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,6 +28,7 @@ public class MessageGridFilterUpdate extends MessageHandlerPlayerToServer<Messag
|
||||
compare = buf.readInt();
|
||||
mode = buf.readInt();
|
||||
modFilter = buf.readBoolean();
|
||||
name = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,6 +36,7 @@ public class MessageGridFilterUpdate extends MessageHandlerPlayerToServer<Messag
|
||||
buf.writeInt(compare);
|
||||
buf.writeInt(mode);
|
||||
buf.writeBoolean(modFilter);
|
||||
ByteBufUtils.writeUTF8String(buf, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +45,7 @@ public class MessageGridFilterUpdate extends MessageHandlerPlayerToServer<Messag
|
||||
ItemGridFilter.setCompare(((ContainerGridFilter) player.openContainer).getStack(), message.compare);
|
||||
ItemGridFilter.setMode(((ContainerGridFilter) player.openContainer).getStack(), message.mode);
|
||||
ItemGridFilter.setModFilter(((ContainerGridFilter) player.openContainer).getStack(), message.modFilter);
|
||||
ItemGridFilter.setName(((ContainerGridFilter) player.openContainer).getStack(), message.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user