Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java
T

121 lines
4.5 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.client.gui.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
2018-09-13 12:03:28 -04:00
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
2018-09-13 12:03:28 -04:00
2025-03-12 20:12:01 -04:00
public class GuiMenuSideButton extends GuiNpcButton {
public static final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/menusidebutton.png");
public static final ResourceLocation resource2 = new ResourceLocation("customnpcs", "textures/gui/menusidebutton2.png");
2018-09-13 12:03:28 -04:00
public boolean active;
public boolean rightSided;
public ItemStack renderStack;
public ResourceLocation renderResource;
public int renderIconPosX = 0;
public int renderIconPosY = 0;
2018-09-13 12:03:28 -04:00
2025-03-12 20:12:01 -04:00
public GuiMenuSideButton(int id, int x, int y, String s) {
this(id, x, y, 200, 20, s);
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
public GuiMenuSideButton(int id, int x, int y, int width, int height, String s) {
super(id, x, y, width, height, s);
2018-09-13 12:03:28 -04:00
active = false;
}
@Override
2025-03-12 20:12:01 -04:00
public int getHoverState(boolean flag) {
2018-09-13 12:03:28 -04:00
if (active)
return 0;
return super.getHoverState(flag);
2018-09-13 12:03:28 -04:00
}
@Override
2025-03-12 20:12:01 -04:00
public void drawButton(Minecraft minecraft, int i, int j) {
if (!visible) {
2018-09-13 12:03:28 -04:00
return;
}
FontRenderer fontrenderer = minecraft.fontRenderer;
2018-09-13 12:03:28 -04:00
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2025-03-12 20:12:01 -04:00
int width = this.width + (active ? 2 : 0);
2018-09-13 12:03:28 -04:00
field_146123_n = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
int k = getHoverState(field_146123_n);
if (this.rightSided) {
minecraft.renderEngine.bindTexture(resource2);
2025-03-12 20:12:01 -04:00
drawTexturedModalRect(xPosition, yPosition, 197 - width, k * 22, width, height);
} else {
minecraft.renderEngine.bindTexture(resource);
2025-03-12 20:12:01 -04:00
drawTexturedModalRect(xPosition, yPosition, 0, k * 22, width, height);
}
2018-09-13 12:03:28 -04:00
mouseDragged(minecraft, i, j);
// Render Custom Icon
if (this.renderResource != null) {
this.zLevel = 100.0F;
minecraft.renderEngine.bindTexture(renderResource);
2025-03-12 20:12:01 -04:00
drawTexturedModalRect(xPosition + 2, yPosition + height / 2 - 8, renderIconPosX, renderIconPosY, 16, 16);
this.zLevel = 0.0F;
}
if (this.renderStack != null) {
RenderHelper.enableGUIStandardItemLighting();
this.zLevel = 100.0F;
RenderItem itemRenderer = RenderItem.getInstance();
itemRenderer.zLevel = 100.0F;
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
itemRenderer.renderItemAndEffectIntoGUI(minecraft.fontRenderer,
2025-03-12 20:12:01 -04:00
minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height / 2 - 8);
itemRenderer.renderItemOverlayIntoGUI(minecraft.fontRenderer,
2025-03-12 20:12:01 -04:00
minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height / 2 - 8);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
itemRenderer.zLevel = 0.0F;
this.zLevel = 0.0F;
RenderHelper.disableStandardItemLighting();
}
2018-09-13 12:03:28 -04:00
String text = "";
float maxWidth = width * 0.75f;
2025-03-12 20:12:01 -04:00
if (fontrenderer.getStringWidth(displayString) > maxWidth) {
for (int h = 0; h < displayString.length(); h++) {
char c = displayString.charAt(h);
if (fontrenderer.getStringWidth(text + c) > maxWidth)
break;
text += c;
}
text += "...";
} else
text = displayString;
if (active) {
2018-09-13 12:03:28 -04:00
drawCenteredString(fontrenderer, text, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
2025-03-12 20:12:01 -04:00
} else if (field_146123_n) {
2018-09-13 12:03:28 -04:00
drawCenteredString(fontrenderer, text, xPosition + width / 2, yPosition + (height - 8) / 2, 0xffffa0);
2025-03-12 20:12:01 -04:00
} else {
2018-09-13 12:03:28 -04:00
drawCenteredString(fontrenderer, text, xPosition + width / 2, yPosition + (height - 8) / 2, 0xe0e0e0);
}
}
@Override
2025-03-12 20:12:01 -04:00
protected void mouseDragged(Minecraft minecraft, int i, int j) {
2018-09-13 12:03:28 -04:00
}
@Override
2025-03-12 20:12:01 -04:00
public void mouseReleased(int i, int j) {
2018-09-13 12:03:28 -04:00
}
@Override
2025-03-12 20:12:01 -04:00
public boolean mousePressed(Minecraft minecraft, int i, int j) {
2018-09-13 12:03:28 -04:00
return !active && visible && field_146123_n;
}
}