Search in sources :

Example 1 with SimpleAnimValue

use of cc.hyperium.utils.SimpleAnimValue in project Hyperium by HyperiumClient.

the class AbstractTab method render.

/**
 * Render - Renders the Tab
 *
 * @param x      - Given X Position
 * @param y      - Given Y Position
 * @param width  - Given Width
 * @param height - Given Height
 */
public void render(int x, int y, int width, int height) {
    ScaledResolution sr = ResolutionUtil.current();
    int sw = sr.getScaledWidth();
    int sh = sr.getScaledHeight();
    // X grid
    int xg = width / 9;
    /* Begin new scissor state */
    ScissorState.scissor(x, y, width, height, true);
    /* Get mouse X and Y */
    // Mouse X
    final int mx = Mouse.getX() * sw / Minecraft.getMinecraft().displayWidth;
    // Mouse Y
    final int my = sh - Mouse.getY() * sh / Minecraft.getMinecraft().displayHeight - 1;
    if (scrollAnim.getValue() != scroll * 18 && scrollAnim.isFinished()) {
        scrollAnim = new SimpleAnimValue(1000L, scrollAnim.getValue(), scroll * 18);
    }
    y += scrollAnim.getValue();
    /* Render each tab component */
    for (AbstractTabComponent comp : filter == null ? components : components.stream().filter(c -> c.filter(filter)).collect(Collectors.toList())) {
        comp.render(x, y, width, mx, my);
        /* If mouse is over component, set as hovered */
        if (mx >= x && mx <= x + width && my > y && my <= y + comp.getHeight()) {
            comp.hover = true;
            // For slider
            comp.mouseEvent(mx - xg, my - y);
            if (Mouse.isButtonDown(0)) {
                if (!clickStates.computeIfAbsent(comp, ignored -> false)) {
                    comp.onClick(mx, my - y);
                    clickStates.put(comp, true);
                }
            } else if (clickStates.computeIfAbsent(comp, ignored -> false))
                clickStates.put(comp, false);
        } else {
            comp.hover = false;
        }
        y += comp.getHeight();
    }
    /* End scissor state */
    ScissorState.endScissor();
}
Also used : List(java.util.List) ResolutionUtil(cc.hyperium.mods.sk1ercommon.ResolutionUtil) HyperiumMainGui(cc.hyperium.gui.hyperium.HyperiumMainGui) Minecraft(net.minecraft.client.Minecraft) ScaledResolution(net.minecraft.client.gui.ScaledResolution) Map(java.util.Map) ScissorState(cc.hyperium.gui.ScissorState) SimpleAnimValue(cc.hyperium.utils.SimpleAnimValue) HashMap(java.util.HashMap) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ScaledResolution(net.minecraft.client.gui.ScaledResolution) SimpleAnimValue(cc.hyperium.utils.SimpleAnimValue)

Example 2 with SimpleAnimValue

use of cc.hyperium.utils.SimpleAnimValue in project Hyperium by HyperiumClient.

the class PurchaseCarousel method render.

public void render(int centerX, int centerY, int mouseX, int mouseY) {
    activeBlock = null;
    ScaledResolution current = ResolutionUtil.current();
    int totalWidth = current.getScaledWidth() / 3;
    int panel = totalWidth / 5;
    int mainWidth = panel * 3;
    int sideHeight = current.getScaledHeight() / 5 * 2;
    int mainHeight = current.getScaledHeight() / 5 * 3;
    int objLeft = centerX - mainWidth / 2;
    int objBottom = centerY + mainHeight / 2;
    int objRight = centerX + mainWidth / 2;
    if (index > 0) {
        // Draw left side
        RenderUtils.drawSmoothRect(centerX - panel * 2, centerY - sideHeight / 2, centerX, centerY + sideHeight / 2, 4, new Color(23, 23, 23, 100).getRGB());
    }
    if (index < items.length - 1) {
        RenderUtils.drawSmoothRect(centerX, centerY - sideHeight / 2, centerX + panel * 2, centerY + sideHeight / 2, 4, new Color(23, 23, 23, 100).getRGB());
    }
    RenderUtils.drawSmoothRect(objLeft, centerY - mainHeight / 2, objRight, objBottom, 10, new Color(23, 23, 23, 255).getRGB());
    CarouselItem item = items[index];
    GlStateManager.scale(.5, .5, .5);
    int barHeight = 16;
    fr.drawString(item.getName(), (objLeft + 5) * 2, (objBottom - 50) * 2, Color.WHITE.getRGB());
    int purchaseRight = (objLeft + 50) * 2;
    RenderUtils.drawSmoothRect((objLeft + 5) * 2, (objBottom - 20) * 2, purchaseRight, (objBottom - 20 + barHeight) * 2, 10, Color.WHITE.getRGB());
    GlStateManager.scale(2 / 3F, 2 / 3F, 2 / 3F);
    fr.drawString(item.isPurchased() ? I18n.format("gui.purchase.purchased") : I18n.format("gui.purchase.purchase"), (objLeft + 5) * 3, (objBottom - 18) * 3, new Color(23, 23, 23, 255).getRGB());
    GlStateManager.scale(3 / 2F, 3 / 2f, 3 / 2F);
    RenderUtils.drawFilledCircle(purchaseRight + barHeight * 2, (objBottom - 12) * 2, barHeight, Color.WHITE.getRGB());
    GlStateManager.color(0, 0, 0);
    Icons.SETTINGS.bind();
    Gui.drawScaledCustomSizeModalRect(purchaseRight + barHeight, (objBottom - 20) * 2, 0, 0, 144, 144, barHeight * 2, barHeight * 2, 144, 144);
    GlStateManager.scale(2.0, 2.0, 2.0);
    if (mouseX >= objLeft - 8 && mouseX <= objLeft && mouseY >= centerY - 5 && mouseY <= centerY + 5) {
        if (!lhover) {
            lhover = true;
            larrow = new SimpleAnimValue(500L, larrow.getValue(), 0.3f);
        }
    } else if (lhover) {
        lhover = false;
        larrow = new SimpleAnimValue(500L, larrow.getValue(), 0.5f);
    }
    float v = larrow.getValue();
    GlStateManager.scale(v, v, v);
    fr.drawCenteredString("<", (objLeft - 5) / v, centerY / v - 10, 0xffffff);
    GlStateManager.scale(1 / v, 1 / v, 1 / v);
    if (mouseX >= objRight && mouseX <= objRight + 8 && mouseY >= centerY - 5 && mouseY <= centerY + 5) {
        if (!rhover) {
            rhover = true;
            rarrow = new SimpleAnimValue(500L, rarrow.getValue(), 0.3f);
        }
    } else if (rhover) {
        rhover = false;
        rarrow = new SimpleAnimValue(500L, rarrow.getValue(), 0.5f);
    }
    v = rarrow.getValue();
    GlStateManager.scale(v, v, v);
    fr.drawCenteredString(">", (objRight + 5) / v, centerY / v - 10, 0xffffff);
    GlStateManager.scale(1 / v, 1 / v, 1 / v);
    String s = I18n.format("gui.purchase.state") + ": " + (getCurrent().isPurchased() ? (getCurrent().isActive() ? I18n.format("gui.purchase.active") : I18n.format("gui.purchase.inactive")) : I18n.format("gui.purchase.notpurchased"));
    float e = .5F;
    GlStateManager.scale(e, e, e);
    fr.drawString(s, (centerX - fr.getWidth(s) / 4) / e, (centerY - mainHeight / 2f + 15) / e, Color.GREEN.getRGB());
    if (getCurrent().isPurchased() && !getCurrent().isActive()) {
        s = I18n.format("gui.purchase.clicktouse");
        float width = fr.getWidth(s);
        float x = centerX - width / 4;
        int i = centerY - mainHeight / 2 + 35;
        activeBlock = new GuiBlock((int) x, (int) (x + width * 2), i, i + 10);
        fr.drawString(s, x / e, i / e, Color.GREEN.getRGB());
    }
    GlStateManager.scale(1 / e, 1 / e, 1 / e);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) SimpleAnimValue(cc.hyperium.utils.SimpleAnimValue) GuiBlock(cc.hyperium.gui.GuiBlock)

Aggregations

SimpleAnimValue (cc.hyperium.utils.SimpleAnimValue)2 ScaledResolution (net.minecraft.client.gui.ScaledResolution)2 GuiBlock (cc.hyperium.gui.GuiBlock)1 ScissorState (cc.hyperium.gui.ScissorState)1 HyperiumMainGui (cc.hyperium.gui.hyperium.HyperiumMainGui)1 ResolutionUtil (cc.hyperium.mods.sk1ercommon.ResolutionUtil)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Minecraft (net.minecraft.client.Minecraft)1 Mouse (org.lwjgl.input.Mouse)1