use of net.minecraftforge.fml.client.GuiModList in project Galacticraft by micdoodle8.
the class GuiModListScroll method draw.
public static void draw(GuiModList gui, int mouseX, int mouseY) {
ModContainer selectedMod = ReflectionManager.getField(GuiModList.class, ModContainer.class, gui, "selectedMod");
if (selectedMod != lastMod) {
lastMod = selectedMod;
scroll = 0;
timeStart = ClientUtils.getRenderTime();
}
if (!scrollMods.contains(selectedMod) || selectedMod.getMetadata().autogenerated) {
return;
}
int y1 = calcDescY(gui, selectedMod);
int y1draw = y1 + 10;
int y2 = gui.height - 38;
int x1 = ReflectionManager.getField(GuiModList.class, Integer.class, gui, "listWidth") + 20;
int x2 = gui.width - 20;
if (x2 - x1 <= 20) {
return;
}
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
GlStateManager.colorMask(false, false, false, false);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
// clear stencil buffer
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);
screenshotStencil(1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
// add description area (even below button)
GuiDraw.drawRect(x1, y1, gui.width - x1, gui.height - y1, -1);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
// subtract done button
GuiDraw.drawRect(gui.width / 2 - 75, y2, 200, 20, -1);
screenshotStencil(2);
GlStateManager.colorMask(true, true, true, true);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// fill stencil with background
gui.drawDefaultBackground();
GlStateManager.colorMask(false, false, false, false);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
GuiDraw.drawRect(x1, y1draw, x2 - x1, y2 - y1draw, -1);
screenshotStencil(3);
GlStateManager.colorMask(true, true, true, true);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
String description = selectedMod.getMetadata().description;
int height = GuiDraw.fontRenderer.listFormattedStringToWidth(description, x2 - x1).size() * GuiDraw.fontRenderer.FONT_HEIGHT;
boolean needsScroll = height > y2 - y1draw;
if ((ClientUtils.getRenderTime() - timeStart) > 40 && needsScroll) {
double dt = ClientUtils.getRenderTime() - lastFrameTime;
if (new Rectangle4i(x1, y1draw, x2 - x1, y2 - y1draw).contains(mouseX, mouseY)) {
double d = Keyboard.isKeyDown(Keyboard.KEY_UP) ? -1 : Keyboard.isKeyDown(Keyboard.KEY_DOWN) ? 1 : 0;
scroll += d * dt * 1.5;
} else {
scroll += dt * 0.2;
}
}
lastFrameTime = ClientUtils.getRenderTime();
// draw description
double dy = scroll % (height + 20);
GlStateManager.pushMatrix();
GlStateManager.translate(0, -dy, 0);
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
if (needsScroll) {
GlStateManager.translate(0, height + 20, 0);
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
}
GlStateManager.popMatrix();
glDisable(GL_STENCIL_TEST);
}
Aggregations