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
@@ -5,7 +5,7 @@ import java.util.ArrayList;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.client.gui.button.GuiButtonImageFixed;
|
||||
import mekanism.client.gui.button.GuiButtonImageMek;
|
||||
import mekanism.client.gui.element.GuiEnergyInfo;
|
||||
import mekanism.client.gui.element.GuiPowerBar;
|
||||
import mekanism.client.gui.element.GuiRedstoneControl;
|
||||
@@ -26,7 +26,6 @@ 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.client.gui.GuiButtonImage;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
@@ -39,10 +38,10 @@ public class GuiDigitalMiner extends GuiMekanismTile<TileEntityDigitalMiner> {
|
||||
private GuiButton startButton;
|
||||
private GuiButton stopButton;
|
||||
private GuiButton configButton;
|
||||
private GuiButtonImage resetButton;
|
||||
private GuiButtonImage silkTouchButton;
|
||||
private GuiButtonImage autoEjectButton;
|
||||
private GuiButtonImage autoPullButton;
|
||||
private GuiButtonImageMek resetButton;
|
||||
private GuiButtonImageMek silkTouchButton;
|
||||
private GuiButtonImageMek autoEjectButton;
|
||||
private GuiButtonImageMek autoPullButton;
|
||||
|
||||
public GuiDigitalMiner(InventoryPlayer inventory, TileEntityDigitalMiner tile) {
|
||||
super(tile, new ContainerDigitalMiner(inventory, tile));
|
||||
@@ -74,22 +73,14 @@ public class GuiDigitalMiner extends GuiMekanismTile<TileEntityDigitalMiner> {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
startButton = new GuiButton(0, guiLeft + 69, guiTop + 17, 60, 20, LangUtils.localize("gui.start"));
|
||||
if (tileEntity.searcher.state != State.IDLE && tileEntity.running) {
|
||||
startButton.enabled = false;
|
||||
}
|
||||
stopButton = new GuiButton(1, guiLeft + 69, guiTop + 37, 60, 20, LangUtils.localize("gui.stop"));
|
||||
if (tileEntity.searcher.state == State.IDLE || !tileEntity.running) {
|
||||
stopButton.enabled = false;
|
||||
}
|
||||
configButton = new GuiButton(2, guiLeft + 69, guiTop + 57, 60, 20, LangUtils.localize("gui.config"));
|
||||
if (tileEntity.searcher.state != State.IDLE) {
|
||||
configButton.enabled = false;
|
||||
}
|
||||
resetButton = new GuiButtonImageMek(3, guiLeft + 131, guiTop + 47, 14, 14, 208, 14, -14, getGuiLocation());
|
||||
silkTouchButton = new GuiButtonImageMek(4, guiLeft + 131, guiTop + 63, 14, 14, 222, 14, -14, getGuiLocation());
|
||||
autoEjectButton = new GuiButtonImageMek(5, guiLeft + 147, guiTop + 47, 14, 14, 180, 14, -14, getGuiLocation());
|
||||
autoPullButton = new GuiButtonImageMek(6, guiLeft + 147, guiTop + 63, 14, 14, 194, 14, -14, getGuiLocation());
|
||||
|
||||
resetButton = new GuiButtonImageFixed(3, guiLeft + 131, guiTop + 47, 14, 14, 208, 14, -14, getGuiLocation());
|
||||
silkTouchButton = new GuiButtonImageFixed(4, guiLeft + 131, guiTop + 63, 14, 14, 222, 14, -14, getGuiLocation());
|
||||
autoEjectButton = new GuiButtonImageFixed(5, guiLeft + 147, guiTop + 47, 14, 14, 180, 14, -14, getGuiLocation());
|
||||
autoPullButton = new GuiButtonImageFixed(6, guiLeft + 147, guiTop + 63, 14, 14, 194, 14, -14, getGuiLocation());
|
||||
updateEnabledButtons();
|
||||
|
||||
buttonList.add(startButton);
|
||||
buttonList.add(stopButton);
|
||||
@@ -103,19 +94,19 @@ public class GuiDigitalMiner extends GuiMekanismTile<TileEntityDigitalMiner> {
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) throws IOException {
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == 0) {
|
||||
if (guibutton.id == startButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(3)));
|
||||
} else if (guibutton.id == 1) {
|
||||
} else if (guibutton.id == stopButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(4)));
|
||||
} else if (guibutton.id == 2) {
|
||||
} else if (guibutton.id == configButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), 0, 0, 0));
|
||||
} else if (guibutton.id == 3) {
|
||||
} else if (guibutton.id == resetButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(5)));
|
||||
} else if (guibutton.id == 4) {
|
||||
} else if (guibutton.id == silkTouchButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(9)));
|
||||
} else if (guibutton.id == 5) {
|
||||
} else if (guibutton.id == autoEjectButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(0)));
|
||||
} else if (guibutton.id == 6) {
|
||||
} else if (guibutton.id == autoPullButton.id) {
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(tileEntity, TileNetworkList.withContents(1)));
|
||||
}
|
||||
}
|
||||
@@ -123,6 +114,10 @@ public class GuiDigitalMiner extends GuiMekanismTile<TileEntityDigitalMiner> {
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
updateEnabledButtons();
|
||||
}
|
||||
|
||||
private void updateEnabledButtons() {
|
||||
startButton.enabled = tileEntity.searcher.state == State.IDLE || !tileEntity.running;
|
||||
stopButton.enabled = tileEntity.searcher.state != State.IDLE && tileEntity.running;
|
||||
configButton.enabled = tileEntity.searcher.state == State.IDLE;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package mekanism.client.gui.button;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButtonImage;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiButtonImageFixed extends GuiButtonImage {
|
||||
|
||||
public GuiButtonImageFixed(int id, int x, int y, int width, int height, int offsetX, int offsetY, int hoverOffset, ResourceLocation resource) {
|
||||
super(id, x, y, width, height, offsetX, offsetY, hoverOffset, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.visible) {
|
||||
//Ensure that the color gets reset before attempting to draw our button
|
||||
MekanismRenderer.resetColor();
|
||||
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package mekanism.client.gui.button;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* From GuiButtonImage with a couple fixes and support for rendering differently when disabled
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiButtonImageMek extends GuiButton {
|
||||
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final int xTexStart;
|
||||
private final int yTexStart;
|
||||
private final int hoverOffset;
|
||||
private final int disabledOffset;
|
||||
|
||||
public GuiButtonImageMek(int id, int x, int y, int width, int height, int offsetX, int offsetY, int hoverOffset, ResourceLocation resource) {
|
||||
this(id, x, y, width, height, offsetX, offsetY, hoverOffset, 0, resource);
|
||||
}
|
||||
|
||||
public GuiButtonImageMek(int id, int x, int y, int width, int height, int offsetX, int offsetY, int hoverOffset, int disabledOffset, ResourceLocation resource) {
|
||||
super(id, x, y, width, height, "");
|
||||
this.xTexStart = offsetX;
|
||||
this.yTexStart = offsetY;
|
||||
this.hoverOffset = hoverOffset;
|
||||
this.disabledOffset = disabledOffset;
|
||||
this.resourceLocation = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.visible) {
|
||||
//Ensure the color gets reset. The default GuiButtonImage doesn't so other GuiButton's can have the color leak out of them
|
||||
MekanismRenderer.resetColor();
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
mc.getTextureManager().bindTexture(this.resourceLocation);
|
||||
GlStateManager.disableDepth();
|
||||
int j = this.yTexStart;
|
||||
|
||||
if (!this.enabled) {
|
||||
//Add support for having a different texture for when it is disabled
|
||||
j += this.disabledOffset;
|
||||
} else if (this.hovered) {
|
||||
j += this.hoverOffset;
|
||||
}
|
||||
|
||||
this.drawTexturedModalRect(this.x, this.y, this.xTexStart, j, this.width, this.height);
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user