mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 06:42:56 +00:00
Convert GuiFormulaicAssemblicator to using GuiButtonImageMek
This commit is contained in:
4 files changed
+140
-151
No files matched your search
@@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.client.gui.button.GuiButtonImageMek;
|
||||
import mekanism.client.gui.element.GuiEnergyInfo;
|
||||
import mekanism.client.gui.element.GuiPowerBar;
|
||||
import mekanism.client.gui.element.GuiRedstoneControl;
|
||||
@@ -14,7 +15,6 @@ import mekanism.client.gui.element.tab.GuiSecurityTab;
|
||||
import mekanism.client.gui.element.tab.GuiSideConfigurationTab;
|
||||
import mekanism.client.gui.element.tab.GuiTransporterConfigTab;
|
||||
import mekanism.client.gui.element.tab.GuiUpgradeTab;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.inventory.container.ContainerFormulaicAssemblicator;
|
||||
import mekanism.common.item.ItemCraftingFormula;
|
||||
@@ -23,8 +23,8 @@ import mekanism.common.tile.TileEntityFormulaicAssemblicator;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -34,6 +34,13 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiFormulaicAssemblicator extends GuiMekanismTile<TileEntityFormulaicAssemblicator> {
|
||||
|
||||
private GuiButtonImageMek encodeFormulaButton;
|
||||
private GuiButtonImageMek stockControlButton;
|
||||
private GuiButtonImageMek fillEmptyButton;
|
||||
private GuiButtonImageMek craftSingleButton;
|
||||
private GuiButtonImageMek craftAvailableButton;
|
||||
private GuiButtonImageMek autoModeButton;
|
||||
|
||||
public GuiFormulaicAssemblicator(InventoryPlayer inventory, TileEntityFormulaicAssemblicator tile) {
|
||||
super(tile, new ContainerFormulaicAssemblicator(inventory, tile));
|
||||
ResourceLocation resource = getGuiLocation();
|
||||
@@ -52,28 +59,58 @@ public class GuiFormulaicAssemblicator extends GuiMekanismTile<TileEntityFormula
|
||||
ySize += 64;
|
||||
}
|
||||
|
||||
private boolean overFillEmpty(int xAxis, int yAxis) {
|
||||
return xAxis >= 44 && xAxis <= 60 && yAxis >= 75 && yAxis <= 91;
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
encodeFormulaButton = new GuiButtonImageMek(0, guiLeft + 7, guiTop + 45, 14, 14, 176, 14, -14, 14, getGuiLocation());
|
||||
stockControlButton = new GuiButtonImageMek(1, guiLeft + 26, guiTop + 75, 16, 16, 238, 48 + 16, -16, 16, getGuiLocation());
|
||||
fillEmptyButton = new GuiButtonImageMek(2, guiLeft + 44, guiTop + 75, 16, 16, 238, 16, -16, 16, getGuiLocation());
|
||||
craftSingleButton = new GuiButtonImageMek(3, guiLeft + 71, guiTop + 75, 16, 16, 190, 16, -16, 16, getGuiLocation());
|
||||
craftAvailableButton = new GuiButtonImageMek(4, guiLeft + 89, guiTop + 75, 16, 16, 206, 16, -16, 16, getGuiLocation());
|
||||
autoModeButton = new GuiButtonImageMek(5, guiLeft + 107, guiTop + 75, 16, 16, 222, 16, -16, 16, getGuiLocation());
|
||||
|
||||
updateEnabledButtons();
|
||||
|
||||
buttonList.add(encodeFormulaButton);
|
||||
buttonList.add(stockControlButton);
|
||||
buttonList.add(fillEmptyButton);
|
||||
buttonList.add(craftSingleButton);
|
||||
buttonList.add(craftAvailableButton);
|
||||
buttonList.add(autoModeButton);
|
||||
}
|
||||
|
||||
private boolean overEncodeFormula(int xAxis, int yAxis) {
|
||||
return xAxis >= 7 && xAxis <= 21 && yAxis >= 45 && yAxis <= 59;
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) throws IOException {
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == encodeFormulaButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(1)));
|
||||
} else if (guibutton.id == stockControlButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(5)));
|
||||
} else if (guibutton.id == fillEmptyButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(4)));
|
||||
} else if (guibutton.id == craftSingleButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(2)));
|
||||
} else if (guibutton.id == craftAvailableButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(3)));
|
||||
} else if (guibutton.id == autoModeButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(0)));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean overCraftSingle(int xAxis, int yAxis) {
|
||||
return xAxis >= 71 && xAxis <= 87 && yAxis >= 75 && yAxis <= 91;
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
updateEnabledButtons();
|
||||
}
|
||||
|
||||
private boolean overCraftAvailable(int xAxis, int yAxis) {
|
||||
return xAxis >= 89 && xAxis <= 105 && yAxis >= 75 && yAxis <= 91;
|
||||
}
|
||||
|
||||
private boolean overAutoMode(int xAxis, int yAxis) {
|
||||
return xAxis >= 107 && xAxis <= 123 && yAxis >= 75 && yAxis <= 91;
|
||||
}
|
||||
|
||||
private boolean overStockControl(int xAxis, int yAxis) {
|
||||
return xAxis >= 26 && xAxis <= 42 && yAxis >= 75 && yAxis <= 91;
|
||||
private void updateEnabledButtons() {
|
||||
encodeFormulaButton.enabled = !tileEntity.autoMode && tileEntity.isRecipe && canEncode();
|
||||
stockControlButton.enabled = tileEntity.formula != null;
|
||||
fillEmptyButton.enabled = !tileEntity.autoMode;
|
||||
craftSingleButton.enabled = !tileEntity.autoMode && tileEntity.isRecipe;
|
||||
craftAvailableButton.enabled = !tileEntity.autoMode && tileEntity.isRecipe;
|
||||
autoModeButton.enabled = tileEntity.formula != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,17 +119,17 @@ public class GuiFormulaicAssemblicator extends GuiMekanismTile<TileEntityFormula
|
||||
fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
|
||||
int xAxis = mouseX - guiLeft;
|
||||
int yAxis = mouseY - guiTop;
|
||||
if (overFillEmpty(xAxis, yAxis)) {
|
||||
if (fillEmptyButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.fillEmpty"), xAxis, yAxis);
|
||||
} else if (overEncodeFormula(xAxis, yAxis)) {
|
||||
} else if (encodeFormulaButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.encodeFormula"), xAxis, yAxis);
|
||||
} else if (overCraftSingle(xAxis, yAxis)) {
|
||||
} else if (craftSingleButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.craftSingle"), xAxis, yAxis);
|
||||
} else if (overCraftAvailable(xAxis, yAxis)) {
|
||||
} else if (craftAvailableButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.craftAvailable"), xAxis, yAxis);
|
||||
} else if (overAutoMode(xAxis, yAxis)) {
|
||||
} else if (autoModeButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.autoModeToggle") + ": " + LangUtils.transOnOff(tileEntity.autoMode), xAxis, yAxis);
|
||||
} else if (overStockControl(xAxis, yAxis)) {
|
||||
} else if (stockControlButton.isMouseOver()) {
|
||||
drawHoveringText(LangUtils.localize("gui.stockControl") + ": " + LangUtils.transOnOff(tileEntity.stockControl), xAxis, yAxis);
|
||||
}
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
@@ -100,33 +137,6 @@ public class GuiFormulaicAssemblicator extends GuiMekanismTile<TileEntityFormula
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
|
||||
if (!tileEntity.autoMode) {
|
||||
drawTexturedModalRect(guiLeft + 44, guiTop + 75, 238, 0, overFillEmpty(xAxis, yAxis), 16);
|
||||
} else {
|
||||
drawTexturedModalRect(guiLeft + 44, guiTop + 75, 238, 32, 16, 16);
|
||||
}
|
||||
if (!tileEntity.autoMode && tileEntity.isRecipe) {
|
||||
if (canEncode()) {
|
||||
drawTexturedModalRect(guiLeft + 7, guiTop + 45, 176, 0, overEncodeFormula(xAxis, yAxis), 14);
|
||||
} else {
|
||||
drawTexturedModalRect(guiLeft + 7, guiTop + 45, 176, 28, 14, 14);
|
||||
}
|
||||
drawTexturedModalRect(guiLeft + 71, guiTop + 75, 190, 0, overCraftSingle(xAxis, yAxis), 16);
|
||||
drawTexturedModalRect(guiLeft + 89, guiTop + 75, 206, 0, overCraftAvailable(xAxis, yAxis), 16);
|
||||
} else {
|
||||
drawTexturedModalRect(guiLeft + 7, guiTop + 45, 176, 28, 14, 14);
|
||||
drawTexturedModalRect(guiLeft + 71, guiTop + 75, 176 + 14, 32, 16, 16);
|
||||
drawTexturedModalRect(guiLeft + 89, guiTop + 75, 176 + 30, 32, 16, 16);
|
||||
}
|
||||
|
||||
if (tileEntity.formula != null) {
|
||||
drawTexturedModalRect(guiLeft + 107, guiTop + 75, 222, 0, overAutoMode(xAxis, yAxis), 16);
|
||||
drawTexturedModalRect(guiLeft + 26, guiTop + 75, 238, 48, overStockControl(xAxis, yAxis), 16);
|
||||
} else {
|
||||
drawTexturedModalRect(guiLeft + 107, guiTop + 75, 176 + 46, 32, 16, 16);
|
||||
drawTexturedModalRect(guiLeft + 26, guiTop + 75, 176 + 62, 48 + 32, 16, 16);
|
||||
}
|
||||
|
||||
if (tileEntity.operatingTicks > 0) {
|
||||
int display = (int) ((double) tileEntity.operatingTicks * 22 / (double) tileEntity.ticksRequired);
|
||||
drawTexturedModalRect(guiLeft + 86, guiTop + 43, 176, 48, display, 16);
|
||||
@@ -159,54 +169,6 @@ public class GuiFormulaicAssemblicator extends GuiMekanismTile<TileEntityFormula
|
||||
return !formulaStack.isEmpty() && formulaStack.getItem() instanceof ItemCraftingFormula && ((ItemCraftingFormula) formulaStack.getItem()).getInventory(formulaStack) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
if (button == 0) {
|
||||
int xAxis = mouseX - guiLeft;
|
||||
int yAxis = mouseY - guiTop;
|
||||
if (!tileEntity.autoMode) {
|
||||
if (overFillEmpty(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(4);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
}
|
||||
|
||||
if (tileEntity.isRecipe) {
|
||||
if (canEncode()) {
|
||||
if (overEncodeFormula(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(1);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
}
|
||||
}
|
||||
|
||||
if (overCraftSingle(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(2);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
} else if (overCraftAvailable(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(3);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tileEntity.formula != null) {
|
||||
if (overAutoMode(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(0);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
} else if (overStockControl(xAxis, yAxis)) {
|
||||
SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK);
|
||||
TileNetworkList data = TileNetworkList.withContents(5);
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getGuiLocation() {
|
||||
return MekanismUtils.getResource(ResourceType.GUI, "GuiFormulaicAssemblicator.png");
|
||||
|
||||
Reference in new issue
Block a user