2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.gui.util;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public class GuiButtonBiDirectional extends GuiNpcButton {
|
|
|
|
|
public static final ResourceLocation resource = new ResourceLocation("customnpcs:textures/gui/arrowbuttons.png");
|
|
|
|
|
|
|
|
|
|
public GuiButtonBiDirectional(int id, int x, int y, int width, int height, String[] arr, int current) {
|
|
|
|
|
super(id, x, y, width, height, arr, current);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
2018-09-13 12:03:28 -04:00
|
|
|
if (!this.visible)
|
2025-03-12 20:12:01 -04:00
|
|
|
return;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
boolean hover = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
2025-03-12 20:12:01 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
boolean hoverL = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + 11 && mouseY < this.yPosition + this.height;
|
|
|
|
|
|
|
|
|
|
boolean hoverR = !hoverL && mouseX >= this.xPosition + width - 11 && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
2025-03-12 20:12:01 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
mc.getTextureManager().bindTexture(resource);
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, hoverL ? 40 : 20, 11, 20);
|
|
|
|
|
|
|
|
|
|
this.drawTexturedModalRect(this.xPosition + width - 11, this.yPosition, 11, hoverR ? 40 : 20, 11, 20);
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
int l = 0xffffff;
|
2025-03-12 20:12:01 -04:00
|
|
|
if (packedFGColour != 0) {
|
2018-09-13 12:03:28 -04:00
|
|
|
l = packedFGColour;
|
2025-03-12 20:12:01 -04:00
|
|
|
} else if (!this.enabled) {
|
2018-09-13 12:03:28 -04:00
|
|
|
l = 10526880;
|
2025-03-12 20:12:01 -04:00
|
|
|
} else if (hover) {
|
2018-09-13 12:03:28 -04:00
|
|
|
l = 16777120;
|
|
|
|
|
}
|
|
|
|
|
String text = "";
|
|
|
|
|
float maxWidth = this.width - 36;
|
2025-03-12 20:12:01 -04:00
|
|
|
if (mc.fontRenderer.getStringWidth(displayString) > maxWidth) {
|
|
|
|
|
for (int h = 0; h < displayString.length(); h++) {
|
|
|
|
|
char c = displayString.charAt(h);
|
|
|
|
|
text += c;
|
|
|
|
|
if (mc.fontRenderer.getStringWidth(text) > maxWidth)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
text += "...";
|
|
|
|
|
} else
|
|
|
|
|
text = displayString;
|
|
|
|
|
if (hover)
|
|
|
|
|
text = (char) 167 + "n" + text;
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
this.drawCenteredString(mc.fontRenderer, text, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) {
|
|
|
|
|
int value = getValue();
|
|
|
|
|
boolean bo = super.mousePressed(minecraft, mouseX, mouseY);
|
|
|
|
|
if (bo && display != null && display.length != 0) {
|
2018-09-13 12:03:28 -04:00
|
|
|
boolean hoverL = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + 11 && mouseY < this.yPosition + this.height;
|
2025-12-09 17:46:07 +02:00
|
|
|
if (rightClicked.get())
|
|
|
|
|
hoverL = true;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
boolean hoverR = !hoverL && mouseX >= this.xPosition + 11 && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (hoverR)
|
|
|
|
|
value = (value + 1) % display.length;
|
|
|
|
|
if (hoverL) {
|
|
|
|
|
if (value <= 0)
|
|
|
|
|
value = display.length;
|
|
|
|
|
value--;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
this.setDisplay(value);
|
|
|
|
|
}
|
|
|
|
|
return bo;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
}
|