Convert GuiFormulaicAssemblicator to using GuiButtonImageMek

This commit is contained in:
pupnewfster committed 2019-07-13 14:35:14 -04:00
1 parent 8dbd4f431f
commit 981de488bf
4 files changed
+140 -151

No files matched your search

@@ -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();
}
}
}