mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-21 20:52:15 +00:00
264 lines
10 KiB
Java
264 lines
10 KiB
Java
/*
|
|
* This file is part of Applied Energistics 2. Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. Applied
|
|
* Energistics 2 is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
|
|
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
|
|
* later version. Applied Energistics 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
* Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
|
|
* Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
*/
|
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
import java.io.IOException;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
import appeng.api.config.AccessRestriction;
|
|
import appeng.api.config.ActionItems;
|
|
import appeng.api.config.ExtractionMode;
|
|
import appeng.api.config.FuzzyMode;
|
|
import appeng.api.config.Settings;
|
|
import appeng.api.config.StorageFilter;
|
|
import appeng.api.config.Upgrades;
|
|
import appeng.api.parts.IStorageBus;
|
|
import appeng.api.storage.data.IAEStackType;
|
|
import appeng.client.gui.slots.VirtualMEPhantomSlot;
|
|
import appeng.client.gui.widgets.GuiImgButton;
|
|
import appeng.client.gui.widgets.GuiTabButton;
|
|
import appeng.container.implementations.ContainerStorageBus;
|
|
import appeng.core.AELog;
|
|
import appeng.core.localization.ColorUtils;
|
|
import appeng.core.localization.GuiText;
|
|
import appeng.core.sync.GuiBridge;
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
import appeng.core.sync.packets.PacketConfigButton;
|
|
import appeng.core.sync.packets.PacketSwitchGuis;
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
|
import appeng.tile.inventory.IAEStackInventory;
|
|
|
|
public class GuiStorageBus extends GuiUpgradeable {
|
|
|
|
private GuiImgButton rwMode;
|
|
private GuiImgButton storageFilter;
|
|
private GuiTabButton priority;
|
|
private GuiImgButton partition;
|
|
private GuiImgButton clear;
|
|
private GuiImgButton extractionMode;
|
|
private VirtualMEPhantomSlot[] configSlots;
|
|
private final ContainerStorageBus containerStorageBus;
|
|
private final IStorageBus storageBus;
|
|
|
|
public GuiStorageBus(final InventoryPlayer inventoryPlayer, final IStorageBus te) {
|
|
super(new ContainerStorageBus(inventoryPlayer, te));
|
|
this.containerStorageBus = (ContainerStorageBus) inventorySlots;
|
|
this.storageBus = te;
|
|
this.ySize = 251;
|
|
}
|
|
|
|
@Override
|
|
@SuppressWarnings("unchecked")
|
|
protected void addButtons() {
|
|
this.clear = new GuiImgButton(this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE);
|
|
this.partition = new GuiImgButton(this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH);
|
|
this.rwMode = new GuiImgButton(
|
|
this.guiLeft - 18,
|
|
this.guiTop + 48,
|
|
Settings.ACCESS,
|
|
AccessRestriction.READ_WRITE);
|
|
this.extractionMode = new GuiImgButton(
|
|
this.guiLeft - 18,
|
|
this.guiTop + 68,
|
|
Settings.EXTRACTION_MODE,
|
|
ExtractionMode.LOOSE);
|
|
this.storageFilter = new GuiImgButton(
|
|
this.guiLeft - 18,
|
|
this.guiTop + 88,
|
|
Settings.STORAGE_FILTER,
|
|
StorageFilter.EXTRACTABLE_ONLY);
|
|
this.fuzzyMode = new GuiImgButton(
|
|
this.guiLeft - 18,
|
|
this.guiTop + 108,
|
|
Settings.FUZZY_MODE,
|
|
FuzzyMode.IGNORE_ALL);
|
|
this.oreFilter = new GuiImgButton(
|
|
this.guiLeft - 18,
|
|
this.guiTop + 108,
|
|
Settings.ACTIONS,
|
|
ActionItems.ORE_FILTER);
|
|
|
|
this.buttonList.add(
|
|
this.priority = new GuiTabButton(
|
|
this.guiLeft + 154,
|
|
this.guiTop,
|
|
2 + 4 * 16,
|
|
GuiText.Priority.getLocal(),
|
|
itemRender));
|
|
|
|
this.buttonList.add(this.storageFilter);
|
|
this.buttonList.add(this.fuzzyMode);
|
|
this.buttonList.add(this.rwMode);
|
|
this.buttonList.add(this.extractionMode);
|
|
this.buttonList.add(this.partition);
|
|
this.buttonList.add(this.clear);
|
|
this.buttonList.add(this.oreFilter);
|
|
}
|
|
|
|
@Override
|
|
public void initGui() {
|
|
super.initGui();
|
|
initVirtualSlots();
|
|
}
|
|
|
|
@Override
|
|
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
|
this.fontRendererObj.drawString(
|
|
this.getGuiDisplayName(this.storageBus.getPartName()),
|
|
8,
|
|
6,
|
|
ColorUtils.guiTextColorGray.getColor());
|
|
this.fontRendererObj.drawString(
|
|
GuiText.inventory.getLocal(),
|
|
8,
|
|
this.ySize - 96 + 3,
|
|
ColorUtils.guiTextColorGray.getColor());
|
|
|
|
if (this.cvb instanceof ContainerStorageBus csb) {
|
|
if (this.fuzzyMode != null) {
|
|
this.fuzzyMode.set(csb.getFuzzyMode());
|
|
}
|
|
if (this.storageFilter != null) {
|
|
this.storageFilter.set(csb.getStorageFilter());
|
|
}
|
|
if (this.rwMode != null) {
|
|
this.rwMode.set(csb.getReadWriteMode());
|
|
}
|
|
if (this.extractionMode != null) {
|
|
this.extractionMode.set(csb.getExtractionMode());
|
|
|
|
if (this.rwMode != null) {
|
|
this.extractionMode.setEnabled(csb.getReadWriteMode() == AccessRestriction.READ_WRITE);
|
|
}
|
|
}
|
|
if (this.partition != null) {
|
|
this.partition.set(csb.getPartitionMode());
|
|
}
|
|
}
|
|
|
|
updateSlotVisibility();
|
|
}
|
|
|
|
@Override
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
|
super.drawBG(offsetX, offsetY, mouseX, mouseY);
|
|
|
|
final boolean isOreDict = this.containerStorageBus.getUpgradeable().getInstalledUpgrades(Upgrades.ORE_FILTER)
|
|
> 0;
|
|
final int capacity = isOreDict ? 0
|
|
: this.containerStorageBus.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
if (isOreDict || i >= capacity + 2) {
|
|
// fadeout slots
|
|
this.drawTexturedModalRect(offsetX + 7, offsetY + 28 + (18 * i), 7, 46, 162, 18);
|
|
} else {
|
|
// normal slots
|
|
this.drawTexturedModalRect(offsetX + 7, offsetY + 28 + (18 * i), 7, 28, 162, 18);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected String getBackground() {
|
|
return "guis/storagebus.png";
|
|
}
|
|
|
|
@Override
|
|
protected void actionPerformed(final GuiButton btn) {
|
|
super.actionPerformed(btn);
|
|
|
|
final boolean backwards = Mouse.isButtonDown(1);
|
|
|
|
try {
|
|
if (btn == this.partition) {
|
|
NetworkHandler.instance.sendToServer(
|
|
new PacketValueConfig("StorageBus.Action", backwards ? "Partition-Clear" : "Partition"));
|
|
} else if (btn == this.clear) {
|
|
NetworkHandler.instance.sendToServer(new PacketValueConfig("StorageBus.Action", "Clear"));
|
|
} else if (btn == this.priority) {
|
|
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PRIORITY));
|
|
} else if (btn == this.rwMode) {
|
|
NetworkHandler.instance.sendToServer(new PacketConfigButton(this.rwMode.getSetting(), backwards));
|
|
} else if (btn == this.extractionMode) {
|
|
NetworkHandler.instance
|
|
.sendToServer(new PacketConfigButton(this.extractionMode.getSetting(), backwards));
|
|
} else if (btn == this.storageFilter) {
|
|
NetworkHandler.instance
|
|
.sendToServer(new PacketConfigButton(this.storageFilter.getSetting(), backwards));
|
|
}
|
|
} catch (final IOException e) {
|
|
AELog.debug(e);
|
|
}
|
|
}
|
|
|
|
private void initVirtualSlots() {
|
|
this.configSlots = new VirtualMEPhantomSlot[63];
|
|
final IAEStackInventory inputInv = this.containerStorageBus.getConfig();
|
|
final int xo = 8;
|
|
final int yo = -133;
|
|
|
|
for (int y = 0; y < 7; y++) {
|
|
for (int x = 0; x < 9; x++) {
|
|
VirtualMEPhantomSlot slot = new VirtualMEPhantomSlot(
|
|
xo + x * 18,
|
|
yo + y * 18 + 9 * 18,
|
|
inputInv,
|
|
x + y * 9,
|
|
this::acceptType);
|
|
this.configSlots[x + y * 9] = slot;
|
|
this.registerVirtualSlots(slot);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void updateSlotVisibility() {
|
|
final boolean isOreDict = this.containerStorageBus.getUpgradeable().getInstalledUpgrades(Upgrades.ORE_FILTER)
|
|
> 0;
|
|
final int capacity = isOreDict ? -2
|
|
: this.containerStorageBus.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
|
|
|
|
for (VirtualMEPhantomSlot slot : this.configSlots) {
|
|
slot.setHidden(slot.getSlotIndex() >= (18 + (9 * capacity)));
|
|
}
|
|
}
|
|
|
|
public boolean handleBookmarkGroupDrop(int mouseX, int mouseY, Iterable<ItemStack> stacks) {
|
|
final int x = mouseX - this.guiLeft + 1;
|
|
final int y = mouseY - this.guiTop + 1;
|
|
this.updateSlotVisibility();
|
|
|
|
int slotIndex = -1;
|
|
for (VirtualMEPhantomSlot slot : this.configSlots) {
|
|
if (slot.isHovered(x, y)) {
|
|
slotIndex = slot.getSlotIndex();
|
|
break;
|
|
}
|
|
}
|
|
if (slotIndex < 0) return false;
|
|
|
|
for (ItemStack stack : stacks) {
|
|
if (slotIndex >= this.configSlots.length || this.configSlots[slotIndex].isHidden()) break;
|
|
this.configSlots[slotIndex++].handleMouseClicked(stack, false, 0);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private boolean acceptType(VirtualMEPhantomSlot slot, IAEStackType<?> type, int mouseButton) {
|
|
return type == containerStorageBus.getStackType();
|
|
}
|
|
}
|