Search in sources :

Example 1 with Component

use of net.wurstclient.clickgui.Component in project Wurst-MC-1.12 by Wurst-Imperium.

the class NavigatorFeatureScreen method onRender.

@Override
protected void onRender(int mouseX, int mouseY, float partialTicks) {
    // title bar
    drawCenteredString(Fonts.segoe22, feature.getName(), middleX, 32, 0xffffff);
    glDisable(GL_TEXTURE_2D);
    // background
    int bgx1 = middleX - 154;
    int bgx2 = middleX + 154;
    int bgy1 = 60;
    int bgy2 = height - 43;
    setColorToBackground();
    drawQuads(bgx1, bgy1, bgx2, Math.max(bgy1, Math.min(bgy2 - (buttonList.isEmpty() ? 0 : 24), bgy1 + scroll + window.getY())));
    drawQuads(bgx1, Math.max(bgy1, Math.min(bgy2 - (buttonList.isEmpty() ? 0 : 24), bgy1 + scroll + window.getY() + window.getInnerHeight())), bgx2, bgy2);
    drawBoxShadow(bgx1, bgy1, bgx2, bgy2);
    // scissor box
    RenderUtils.scissorBox(bgx1, bgy1, bgx2, bgy2 - (buttonList.isEmpty() ? 0 : 24));
    glEnable(GL_SCISSOR_TEST);
    // settings
    WurstClient.INSTANCE.getGui().setTooltip(null);
    window.validate();
    int windowY = bgy1 + scroll + window.getY();
    GL11.glPushMatrix();
    GL11.glTranslated(bgx1, windowY, 0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    {
        int x1 = 0;
        int y1 = -13;
        int x2 = x1 + window.getWidth();
        int y2 = y1 + window.getHeight();
        int y3 = y1 + 13;
        int x3 = x1 + 2;
        int x5 = x2 - 2;
        // window background
        // left & right
        setColorToBackground();
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2i(x1, y3);
        GL11.glVertex2i(x1, y2);
        GL11.glVertex2i(x3, y2);
        GL11.glVertex2i(x3, y3);
        GL11.glVertex2i(x5, y3);
        GL11.glVertex2i(x5, y2);
        GL11.glVertex2i(x2, y2);
        GL11.glVertex2i(x2, y3);
        GL11.glEnd();
        setColorToBackground();
        GL11.glBegin(GL11.GL_QUADS);
        // window background
        // between children
        int xc1 = 2;
        int xc2 = x5 - x1;
        for (int i = 0; i < window.countChildren(); i++) {
            int yc1 = window.getChild(i).getY();
            int yc2 = yc1 - 2;
            GL11.glVertex2i(xc1, yc2);
            GL11.glVertex2i(xc1, yc1);
            GL11.glVertex2i(xc2, yc1);
            GL11.glVertex2i(xc2, yc2);
        }
        // window background
        // bottom
        int yc1;
        if (window.countChildren() == 0)
            yc1 = 0;
        else {
            Component lastChild = window.getChild(window.countChildren() - 1);
            yc1 = lastChild.getY() + lastChild.getHeight();
        }
        int yc2 = yc1 + 2;
        GL11.glVertex2i(xc1, yc2);
        GL11.glVertex2i(xc1, yc1);
        GL11.glVertex2i(xc2, yc1);
        GL11.glVertex2i(xc2, yc2);
        GL11.glEnd();
    }
    for (int i = 0; i < window.countChildren(); i++) window.getChild(i).render(mouseX - bgx1, mouseY - windowY);
    GL11.glPopMatrix();
    // sliders
    for (SliderSetting slider : sliders) {
        // rail
        int x1 = bgx1 + 2;
        int x2 = bgx2 - 2;
        int y1 = slider.getY() + scroll + 4;
        int y2 = y1 + 4;
        setColorToForeground();
        drawEngravedBox(x1, y1, x2, y2);
        int width = x2 - x1;
        // lock
        boolean renderAsDisabled = slider.isDisabled() || slider.isLocked();
        if (!renderAsDisabled && slider.isLimited()) {
            glColor4f(0.75F, 0.125F, 0.125F, 0.25F);
            double ratio = width / slider.getRange();
            drawQuads(x1, y1, (int) (x1 + ratio * (slider.getUsableMin() - slider.getMinimum())), y2);
            drawQuads((int) (x2 + ratio * (slider.getUsableMax() - slider.getMaximum())), y1, x2, y2);
        }
        // knob
        float percentage = slider.getPercentage();
        x1 = bgx1 + (int) ((width - 6) * percentage) + 1;
        x2 = x1 + 8;
        y1 -= 2;
        y2 += 2;
        if (renderAsDisabled)
            glColor4f(0.5F, 0.5F, 0.5F, 0.75F);
        else {
            float factor = 2 * percentage;
            glColor4f(factor, 2 - factor, 0F, 0.75F);
        }
        drawBox(x1, y1, x2, y2);
        // value
        String value = slider.getValueString();
        x1 = bgx2 - Fonts.segoe15.getStringWidth(value) - 2;
        y1 -= 12;
        drawString(Fonts.segoe15, value, x1, y1, renderAsDisabled ? 0xaaaaaa : 0xffffff);
        glDisable(GL_TEXTURE_2D);
    }
    // buttons
    activeButton = null;
    for (ButtonData buttonData : buttonDatas) {
        // positions
        int x1 = buttonData.x;
        int x2 = x1 + buttonData.width;
        int y1 = buttonData.y + scroll;
        int y2 = y1 + buttonData.height;
        // color
        float alpha;
        if (buttonData.isLocked())
            alpha = 0.25F;
        else if (mouseX >= x1 && mouseX <= x2 && mouseY >= y1 && mouseY <= y2) {
            alpha = 0.75F;
            activeButton = buttonData;
        } else
            alpha = 0.375F;
        float[] rgb = buttonData.color.getColorComponents(null);
        glColor4f(rgb[0], rgb[1], rgb[2], alpha);
        // button
        drawBox(x1, y1, x2, y2);
        // text
        drawCenteredString(Fonts.segoe15, buttonData.buttonText, (x1 + x2) / 2, y1 + (buttonData.height - 10) / 2 - 1, buttonData.isLocked() ? 0xaaaaaa : buttonData.textColor);
        glDisable(GL_TEXTURE_2D);
    }
    // checkboxes
    for (CheckboxSetting checkbox : checkboxes) {
        // positions
        int x1 = bgx1 + 2;
        int x2 = x1 + 10;
        int y1 = checkbox.getY() + scroll + 2;
        int y2 = y1 + 10;
        // hovering
        boolean hovering = !checkbox.isLocked() && mouseX >= x1 && mouseX <= bgx2 - 2 && mouseY >= y1 && mouseY <= y2;
        // box
        if (hovering)
            glColor4f(0.375F, 0.375F, 0.375F, 0.25F);
        else
            glColor4f(0.25F, 0.25F, 0.25F, 0.25F);
        drawBox(x1, y1, x2, y2);
        // check
        if (checkbox.isChecked()) {
            // check
            glColor4f(0F, 1F, 0F, hovering ? 0.75F : 0.375F);
            glBegin(GL_QUADS);
            {
                glVertex2i(x1 + 3, y1 + 5);
                glVertex2i(x1 + 4, y1 + 6);
                glVertex2i(x1 + 4, y1 + 8);
                glVertex2i(x1 + 2, y1 + 6);
                glVertex2i(x1 + 7, y1 + 2);
                glVertex2i(x1 + 8, y1 + 3);
                glVertex2i(x1 + 4, y1 + 8);
                glVertex2i(x1 + 4, y1 + 6);
            }
            glEnd();
            // shadow
            glColor4f(0.125F, 0.125F, 0.125F, hovering ? 0.75F : 0.375F);
            glBegin(GL_LINE_LOOP);
            {
                glVertex2i(x1 + 3, y1 + 5);
                glVertex2i(x1 + 4, y1 + 6);
                glVertex2i(x1 + 7, y1 + 2);
                glVertex2i(x1 + 8, y1 + 3);
                glVertex2i(x1 + 4, y1 + 8);
                glVertex2i(x1 + 2, y1 + 6);
            }
            glEnd();
        }
        // name
        x1 += 12;
        y1 -= 1;
        drawString(Fonts.segoe15, checkbox.getName(), x1, y1, checkbox.isLocked() ? 0xaaaaaa : 0xffffff);
        glDisable(GL_TEXTURE_2D);
    }
    // text
    drawString(Fonts.segoe15, text, bgx1 + 2, bgy1 + scroll, 0xffffff);
    // scissor box
    glDisable(GL_SCISSOR_TEST);
    GL11.glPushMatrix();
    GL11.glTranslated(bgx1, bgy1 + scroll - 13, 0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    WurstClient.INSTANCE.getGui().renderPopupsAndTooltip(mouseX - bgx1, mouseY - bgy1 - scroll + 13);
    GL11.glPopMatrix();
    // buttons below scissor box
    for (int i = 0; i < buttonList.size(); i++) {
        GuiButton button = buttonList.get(i);
        // positions
        int x1 = button.xPosition;
        int x2 = x1 + button.getButtonWidth();
        int y1 = button.yPosition;
        int y2 = y1 + 18;
        // color
        boolean hovering = mouseX >= x1 && mouseX <= x2 && mouseY >= y1 && mouseY <= y2;
        if (feature.isEnabled() && button.id == 0)
            if (feature.isBlocked())
                glColor4f(hovering ? 1F : 0.875F, 0F, 0F, 0.25F);
            else
                glColor4f(0F, hovering ? 1F : 0.875F, 0F, 0.25F);
        else if (hovering)
            glColor4f(0.375F, 0.375F, 0.375F, 0.25F);
        else
            glColor4f(0.25F, 0.25F, 0.25F, 0.25F);
        // button
        glDisable(GL_TEXTURE_2D);
        drawBox(x1, y1, x2, y2);
        // text
        drawCenteredString(Fonts.segoe18, button.displayString, (x1 + x2) / 2, y1 + 2, 0xffffff);
    }
    // GL resets
    glEnable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) SliderSetting(net.wurstclient.settings.SliderSetting) Component(net.wurstclient.clickgui.Component) CheckboxSetting(net.wurstclient.settings.CheckboxSetting)

Aggregations

GuiButton (net.minecraft.client.gui.GuiButton)1 Component (net.wurstclient.clickgui.Component)1 CheckboxSetting (net.wurstclient.settings.CheckboxSetting)1 SliderSetting (net.wurstclient.settings.SliderSetting)1