Search in sources :

Example 1 with CheckboxSetting

use of net.wurstclient.settings.CheckboxSetting in project Wurst-MC-1.12 by Wurst-Imperium.

the class SetCheckboxCmd method call.

@Override
public void call(String[] args) throws CmdException {
    if (args.length != 3)
        throw new CmdSyntaxError();
    // find feature
    Feature feature = null;
    String featureName = args[0];
    for (Iterator itr = wurst.navigator.iterator(); itr.hasNext(); ) {
        Feature item = (Feature) itr.next();
        if (featureName.equalsIgnoreCase(item.getName())) {
            feature = item;
            break;
        }
    }
    if (feature == null)
        throw new CmdError("A feature named \"" + featureName + "\" could not be found.");
    // find setting
    Setting setting = null;
    String settingName = args[1].replace("_", " ");
    for (Setting featureSetting : feature.getSettings()) if (featureSetting.getName().equalsIgnoreCase(settingName)) {
        setting = featureSetting;
        break;
    }
    if (setting == null)
        throw new CmdError("A setting named \"" + settingName + "\" could not be found in " + feature.getName() + ".");
    // check that setting is checkbox setting
    if (!(setting instanceof CheckboxSetting))
        throw new CmdError(feature.getName() + " " + setting.getName() + " is not a checkbox setting.");
    CheckboxSetting checkboxSetting = (CheckboxSetting) setting;
    // set check
    String valueName = args[2];
    if (valueName.equalsIgnoreCase("on"))
        checkboxSetting.setChecked(true);
    else if (valueName.equalsIgnoreCase("off"))
        checkboxSetting.setChecked(false);
    else if (valueName.equalsIgnoreCase("toggle"))
        checkboxSetting.toggle();
    else
        throw new CmdSyntaxError();
}
Also used : Setting(net.wurstclient.settings.Setting) CheckboxSetting(net.wurstclient.settings.CheckboxSetting) Iterator(java.util.Iterator) Feature(net.wurstclient.features.Feature) CheckboxSetting(net.wurstclient.settings.CheckboxSetting)

Example 2 with CheckboxSetting

use of net.wurstclient.settings.CheckboxSetting in project Wurst-MC-1.12 by Wurst-Imperium.

the class NavigatorFeatureScreen method onMouseClick.

@Override
protected void onMouseClick(int x, int y, int button) {
    // popups
    if (WurstClient.INSTANCE.getGui().handleNavigatorPopupClick(x - middleX + 154, y - 60 - scroll + 13, button))
        return;
    Rectangle area = new Rectangle(width / 2 - 154, 60, 308, height - 103);
    if (!area.contains(x, y))
        return;
    // buttons
    if (activeButton != null) {
        WSoundEvents.playButtonClick();
        activeButton.press();
        WurstClient.INSTANCE.navigator.addPreference(feature.getName());
        ConfigFiles.NAVIGATOR.save();
        return;
    }
    // sliders
    area.height = 12;
    for (int i = 0; i < sliders.size(); i++) {
        area.y = sliders.get(i).getY() + scroll;
        if (area.contains(x, y)) {
            sliding = i;
            return;
        }
    }
    // checkboxes
    for (int i = 0; i < checkboxes.size(); i++) {
        CheckboxSetting checkbox = checkboxes.get(i);
        area.y = checkbox.getY() + scroll;
        if (area.contains(x, y)) {
            checkbox.toggle();
            WurstClient wurst = WurstClient.INSTANCE;
            wurst.navigator.addPreference(feature.getName());
            ConfigFiles.NAVIGATOR.save();
            return;
        }
    }
    // component settings
    WurstClient.INSTANCE.getGui().handleNavigatorMouseClick(x - middleX + 154, y - 60 - scroll - window.getY(), button, window);
}
Also used : WurstClient(net.wurstclient.WurstClient) Rectangle(java.awt.Rectangle) CheckboxSetting(net.wurstclient.settings.CheckboxSetting)

Example 3 with CheckboxSetting

use of net.wurstclient.settings.CheckboxSetting 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

CheckboxSetting (net.wurstclient.settings.CheckboxSetting)3 Rectangle (java.awt.Rectangle)1 Iterator (java.util.Iterator)1 GuiButton (net.minecraft.client.gui.GuiButton)1 WurstClient (net.wurstclient.WurstClient)1 Component (net.wurstclient.clickgui.Component)1 Feature (net.wurstclient.features.Feature)1 Setting (net.wurstclient.settings.Setting)1 SliderSetting (net.wurstclient.settings.SliderSetting)1