From 1a81100185a655c9d47da3abe6002a1569646bed Mon Sep 17 00:00:00 2001 From: Andrei Laiff Date: Thu, 12 Oct 2023 12:41:15 +0300 Subject: [PATCH] feat: Support back navigation functionality --- ...tingStatus.java => GuiCraftingStatus.java} | 25 +++++--- .../client/gui/GuiFluidCraftAmount.java | 8 +++ .../client/gui/GuiFluidCraftConfirm.java | 20 ++++--- .../github/client/gui/GuiRenamer.java | 57 ++++++++++++++++++- .../github/client/gui/base/FCGuiAmount.java | 5 +- 5 files changed, 96 insertions(+), 19 deletions(-) rename src/main/java/com/glodblock/github/client/gui/{GuiFluidPatternTerminalCraftingStatus.java => GuiCraftingStatus.java} (73%) diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalCraftingStatus.java b/src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java similarity index 73% rename from src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalCraftingStatus.java rename to src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java index decac25b2..93aeb5012 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalCraftingStatus.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java @@ -8,25 +8,26 @@ import com.glodblock.github.common.parts.PartFluidPatternTerminal; import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; import com.glodblock.github.common.parts.PartFluidTerminal; +import com.glodblock.github.common.parts.PartLevelTerminal; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IWirelessTerminal; import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory; import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; +import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.util.Ae2ReflectClient; import appeng.api.storage.ITerminalHost; -import appeng.client.gui.implementations.GuiCraftingStatus; import appeng.client.gui.widgets.GuiTabButton; -public class GuiFluidPatternTerminalCraftingStatus extends GuiCraftingStatus { +public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraftingStatus { private GuiTabButton originalGuiBtn; private final ITerminalHost host; - public GuiFluidPatternTerminalCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) { + public GuiCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) { super(inventoryPlayer, te); host = te; } @@ -37,17 +38,20 @@ public void initGui() { Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERMINAL, 1)); else if (host instanceof PartFluidPatternTerminalEx) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERMINAL_EX, 1)); - else if (host instanceof PartFluidTerminal) { + else if (host instanceof PartFluidTerminal) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERM, 1)); - } else if (host instanceof IWirelessTerminal && ((IWirelessTerminal) host).isUniversal(host)) { + else if (host instanceof PartLevelTerminal) + Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.LEVEL_TERMINAL, 1)); + else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_ULTRA_TERM, 1)); - } else if (host instanceof WirelessFluidTerminalInventory) { + else if (host instanceof WirelessFluidTerminalInventory) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_FLUID_TERM, 1)); - } else if (host instanceof WirelessPatternTerminalInventory) { + else if (host instanceof WirelessPatternTerminalInventory) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_PATTERN_TERM, 1)); - } else if (host instanceof WirelessInterfaceTerminalInventory) { + else if (host instanceof WirelessInterfaceTerminalInventory) Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_INTERFACE_TERM, 1)); - } + else if (host instanceof WirelessLevelTerminalInventory) + Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_LEVEL_TERM, 1)); super.initGui(); originalGuiBtn = Ae2ReflectClient.getOriginalGuiButton(this); } @@ -59,6 +63,7 @@ protected void actionPerformed(final GuiButton btn) { else if (host instanceof PartFluidPatternTerminalEx) InventoryHandler.switchGui(GuiType.FLUID_PATTERN_TERMINAL_EX); else if (host instanceof PartFluidTerminal) InventoryHandler.switchGui(GuiType.FLUID_TERMINAL); + else if (host instanceof PartLevelTerminal) InventoryHandler.switchGui(GuiType.LEVEL_TERMINAL); else if (host instanceof IWirelessTerminal && ((IWirelessTerminal) host).isUniversal(host)) InventoryHandler .switchGui(ItemWirelessUltraTerminal.readMode(((IWirelessTerminal) host).getItemStack())); else if (host instanceof WirelessFluidTerminalInventory) @@ -67,6 +72,8 @@ else if (host instanceof WirelessPatternTerminalInventory) InventoryHandler.switchGui(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); else if (host instanceof WirelessInterfaceTerminalInventory) InventoryHandler.switchGui(GuiType.WIRELESS_INTERFACE_TERMINAL); + else if (host instanceof WirelessLevelTerminalInventory) + InventoryHandler.switchGui(GuiType.WIRELESS_LEVEL_TERMINAL); } else { super.actionPerformed(btn); } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java index f535b0c5f..326d72789 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java @@ -10,8 +10,10 @@ import com.glodblock.github.common.parts.PartFluidPatternTerminal; import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; import com.glodblock.github.common.parts.PartFluidTerminal; +import com.glodblock.github.common.parts.PartLevelTerminal; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.network.CPacketCraftRequest; @@ -73,12 +75,18 @@ protected void setOriginGUI(Object target) { } else if (target instanceof PartFluidTerminal) { this.myIcon = new ItemStack(ItemAndBlockHolder.FLUID_TERM, 1); this.originalGui = GuiType.FLUID_TERMINAL; + } else if (target instanceof PartLevelTerminal) { + myIcon = new ItemStack(ItemAndBlockHolder.LEVEL_TERMINAL, 1); + originalGui = GuiType.LEVEL_TERMINAL; } else if (target instanceof IWirelessTerminal && ((IWirelessTerminal) target).isUniversal(target)) { this.myIcon = new ItemStack(ItemAndBlockHolder.WIRELESS_ULTRA_TERM, 1); this.originalGui = ItemWirelessUltraTerminal.readMode(((IWirelessTerminal) target).getItemStack()); } else if (target instanceof WirelessPatternTerminalInventory) { this.myIcon = new ItemStack(ItemAndBlockHolder.WIRELESS_PATTERN_TERM, 1); this.originalGui = GuiType.FLUID_TERMINAL; + } else if (target instanceof WirelessLevelTerminalInventory) { + myIcon = new ItemStack(ItemAndBlockHolder.LEVEL_TERMINAL, 1); + originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; } } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java index 2ed531213..16b1a3170 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java @@ -6,33 +6,39 @@ import com.glodblock.github.common.item.ItemWirelessUltraTerminal; import com.glodblock.github.common.parts.PartFluidPatternTerminal; import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; +import com.glodblock.github.common.parts.PartLevelTerminal; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; import com.glodblock.github.network.CPacketSwitchGuis; import appeng.api.storage.ITerminalHost; import appeng.client.gui.implementations.GuiCraftConfirm; -public class GuiFluidCraftConfirm extends GuiCraftConfirm { +public class GuiFluidCraftConfirm extends GuiCraftConfirm implements IGuiTooltipHandler { - private GuiType OriginalGui; + private GuiType originalGui; public GuiFluidCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { super(inventoryPlayer, te); if (te instanceof PartFluidPatternTerminal) { - this.OriginalGui = GuiType.FLUID_PATTERN_TERMINAL; + this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; } else if (te instanceof PartFluidPatternTerminalEx) { - this.OriginalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; + this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; + } else if (te instanceof PartLevelTerminal) { + originalGui = GuiType.LEVEL_TERMINAL; } else if (te instanceof IWirelessTerminal && ((IWirelessTerminal) te).isUniversal(te)) { - this.OriginalGui = ItemWirelessUltraTerminal.readMode(((IWirelessTerminal) te).getItemStack()); + this.originalGui = ItemWirelessUltraTerminal.readMode(((IWirelessTerminal) te).getItemStack()); } else if (te instanceof WirelessPatternTerminalInventory) { - this.OriginalGui = GuiType.FLUID_TERMINAL; + this.originalGui = GuiType.FLUID_TERMINAL; + } else if (te instanceof WirelessLevelTerminalInventory) { + originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; } } @Override public void switchToOriginalGUI() { - FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(this.OriginalGui)); + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(this.originalGui)); } } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java b/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java index a81ec4cdf..93f461c4c 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java @@ -1,5 +1,6 @@ package com.glodblock.github.client.gui; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -7,10 +8,19 @@ import com.glodblock.github.FluidCraft; import com.glodblock.github.client.gui.container.ContainerRenamer; +import com.glodblock.github.common.item.ItemWirelessUltraTerminal; +import com.glodblock.github.common.parts.PartLevelTerminal; +import com.glodblock.github.inventory.InventoryHandler; +import com.glodblock.github.inventory.gui.GuiType; +import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; +import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; +import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.network.CPacketRenamer; import appeng.api.storage.ITerminalHost; import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiTabButton; import appeng.client.gui.widgets.IDropToFillTextField; import appeng.client.gui.widgets.MEGuiTextField; import appeng.core.localization.GuiColors; @@ -18,20 +28,46 @@ public class GuiRenamer extends AEBaseGui implements IDropToFillTextField { - private final MEGuiTextField textField; + protected final MEGuiTextField textField; + + protected final ITerminalHost host; + protected GuiTabButton originalGuiBtn; + + protected ItemStack icon = null; public GuiRenamer(InventoryPlayer ip, ITerminalHost monitorable) { super(new ContainerRenamer(ip, monitorable)); + this.host = monitorable; this.xSize = 256; this.textField = new MEGuiTextField(230, 12); this.textField.setMaxStringLength(32); } + @SuppressWarnings("unchecked") @Override public void initGui() { super.initGui(); FluidCraft.proxy.netHandler.sendToServer(new CPacketRenamer(CPacketRenamer.Action.GET_TEXT)); + if (host instanceof PartLevelTerminal) { + icon = new ItemStack(ItemAndBlockHolder.LEVEL_TERMINAL, 1); + } else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) { + icon = new ItemStack(ItemAndBlockHolder.WIRELESS_ULTRA_TERM, 1); + } else if (host instanceof WirelessLevelTerminalInventory) { + icon = new ItemStack(ItemAndBlockHolder.WIRELESS_LEVEL_TERM, 1); + } else if (host instanceof WirelessInterfaceTerminalInventory) { + icon = new ItemStack(ItemAndBlockHolder.WIRELESS_INTERFACE_TERM, 1); + } + if (this.icon != null) { + this.buttonList.add( + this.originalGuiBtn = new GuiTabButton( + this.guiLeft + 231, + this.guiTop - 4, + this.icon, + this.icon.getDisplayName(), + itemRender)); + this.originalGuiBtn.setHideEdge(13); + } this.textField.x = this.guiLeft + 12; this.textField.y = this.guiTop + 35; this.textField.setFocused(true); @@ -68,6 +104,25 @@ public boolean isOverTextField(final int mousex, final int mousey) { return textField.isMouseIn(mousex, mousey); } + @Override + protected void actionPerformed(GuiButton button) { + if (button == originalGuiBtn) { + switchGui(); + } else { + super.actionPerformed(button); + } + } + + public void switchGui() { + if (host instanceof PartLevelTerminal) InventoryHandler.switchGui(GuiType.LEVEL_TERMINAL); + else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) + InventoryHandler.switchGui(ItemWirelessUltraTerminal.readMode(((IWirelessTerminal) host).getItemStack())); + else if (host instanceof WirelessInterfaceTerminalInventory) + InventoryHandler.switchGui(GuiType.WIRELESS_INTERFACE_TERMINAL); + else if (host instanceof WirelessLevelTerminalInventory) + InventoryHandler.switchGui(GuiType.WIRELESS_LEVEL_TERMINAL); + } + public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) { textField.setText(displayName); } diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java index 86b58fa03..1e655e238 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java @@ -65,11 +65,12 @@ public void initGui() { if (this.originalGui != null && this.myIcon != null) { this.buttonList.add( this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 154, - this.guiTop, + this.guiLeft + 151, + this.guiTop - 4, this.myIcon, this.myIcon.getDisplayName(), itemRender)); + this.originalGuiBtn.setHideEdge(13); } this.amountBox = new GuiTextField(