mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-24 22:14:33 +00:00
Universal GUI (#872)
Co-authored-by: Kogepan229 <[email protected]> Co-authored-by: Kogepan229 <[email protected]> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
225 files changed
+8182
-5684
No files matched your search
@@ -1,71 +1,34 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.client.gui.slots.VirtualMESlotSingle;
|
||||
import appeng.container.implementations.ContainerPatternValueAmount;
|
||||
import appeng.core.localization.GuiColors;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketPatternValueSet;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.parts.reporting.PartPatternTerminalEx;
|
||||
|
||||
public class GuiPatternValueAmount extends GuiAmount {
|
||||
|
||||
private final int valueIndex;
|
||||
private final int originalAmount;
|
||||
private final ContainerPatternValueAmount container;
|
||||
private final VirtualMESlotSingle slot;
|
||||
|
||||
@Reflected
|
||||
public GuiPatternValueAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
|
||||
super(new ContainerPatternValueAmount(inventoryPlayer, te));
|
||||
GuiContainer gui = (GuiContainer) Minecraft.getMinecraft().currentScreen;
|
||||
if (gui != null && gui.theSlot != null && gui.theSlot.getHasStack()) {
|
||||
Slot slot = gui.theSlot;
|
||||
originalAmount = slot.getStack().stackSize;
|
||||
valueIndex = slot.slotNumber;
|
||||
} else {
|
||||
valueIndex = -1;
|
||||
originalAmount = 0;
|
||||
}
|
||||
this.container = (ContainerPatternValueAmount) this.inventorySlots;
|
||||
|
||||
this.slot = new VirtualMESlotSingle(34, 53, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
this.amountTextField.setText(String.valueOf(originalAmount));
|
||||
this.amountTextField.setCursorPositionEnd();
|
||||
this.amountTextField.setSelectionPos(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setOriginGUI(Object target) {
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IParts parts = definitions.parts();
|
||||
|
||||
if (target instanceof PartPatternTerminal) {
|
||||
for (final ItemStack stack : parts.patternTerminal().maybeStack(1).asSet()) {
|
||||
myIcon = stack;
|
||||
}
|
||||
this.originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
|
||||
if (target instanceof PartPatternTerminalEx) {
|
||||
for (final ItemStack stack : parts.patternTerminalEx().maybeStack(1).asSet()) {
|
||||
myIcon = stack;
|
||||
}
|
||||
this.originalGui = GuiBridge.GUI_PATTERN_TERMINAL_EX;
|
||||
}
|
||||
this.registerVirtualSlots(this.slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,10 +41,9 @@ public class GuiPatternValueAmount extends GuiAmount {
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
super.drawBG(offsetX, offsetY, mouseX, mouseY);
|
||||
this.nextBtn.displayString = GuiText.Set.getLocal();
|
||||
this.nextBtn.enabled = valueIndex >= 0;
|
||||
|
||||
try {
|
||||
int resultI = getAmount();
|
||||
long resultI = getAmountLong();
|
||||
this.nextBtn.enabled = resultI > 0;
|
||||
} catch (final NumberFormatException e) {
|
||||
this.nextBtn.enabled = false;
|
||||
@@ -95,9 +57,12 @@ public class GuiPatternValueAmount extends GuiAmount {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
try {
|
||||
if (btn == this.nextBtn && btn.enabled) {
|
||||
NetworkHandler.instance
|
||||
.sendToServer(new PacketPatternValueSet(originalGui.ordinal(), getAmount(), valueIndex));
|
||||
if (btn == this.nextBtn && btn.enabled && slot.getAEStack() != null) {
|
||||
NetworkHandler.instance.sendToServer(
|
||||
new PacketPatternValueSet(
|
||||
this.container.getAEStack().setStackSize(getAmountLong()),
|
||||
this.container.getInvName(),
|
||||
this.container.getSlotIndex()));
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
@@ -108,4 +73,11 @@ public class GuiPatternValueAmount extends GuiAmount {
|
||||
protected String getBackground() {
|
||||
return "guis/craftAmt.png";
|
||||
}
|
||||
|
||||
public void update() {
|
||||
this.slot.setAEStack(this.container.getAEStack());
|
||||
this.amountTextField.setText(String.valueOf(this.container.getAEStack().getStackSize()));
|
||||
this.amountTextField.setCursorPositionEnd();
|
||||
this.amountTextField.setSelectionPos(0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user