Search in sources :

Example 1 with DisplayElement

use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.

the class GeneralConfigGui method initGui.

@Override
public void initGui() {
    super.initGui();
    reg((edit = new GuiButtonIcon(1, new ResourceLocation("textures/chromahud/iconsheet.png"), 5, 0, 1, .4f)), button -> {
        // Open Gui for editing element
        if (currentElement != null) {
            Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(currentElement, mod));
        }
    });
    ((GuiButtonIcon) edit).setOutline(true);
    reg(new GuiButton(2, 2, ResolutionUtil.current().getScaledHeight() - 22, 100, 20, "New"), (guiButton) -> {
        DisplayElement blank = DisplayElement.blank();
        ChromaHUDApi.getInstance().getElements().add(blank);
        Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(blank, mod));
    });
    edit.visible = false;
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) GuiButtonIcon(cc.hyperium.gui.GuiButtonIcon) ResourceLocation(net.minecraft.util.ResourceLocation) DisplayElement(cc.hyperium.mods.chromahud.DisplayElement)

Example 2 with DisplayElement

use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.

the class GeneralConfigGui method handleMouseInput.

@Override
public void handleMouseInput() throws IOException {
    super.handleMouseInput();
    ScaledResolution current = ResolutionUtil.current();
    int i = Mouse.getEventDWheel();
    List<DisplayElement> elements = ChromaHUDApi.getInstance().getElements();
    if (elements.size() > 0) {
        if (i < 0) {
            if (currentElement == null) {
                currentElement = elements.get(0);
            } else {
                int i1 = elements.indexOf(currentElement);
                i1++;
                if (i1 > elements.size() - 1)
                    i1 = 0;
                currentElement = elements.get(i1);
            }
        } else if (i > 0) {
            if (currentElement == null) {
                currentElement = elements.get(0);
            } else {
                int i1 = elements.indexOf(currentElement);
                i1--;
                if (i1 < 0)
                    i1 = elements.size() - 1;
                currentElement = elements.get(i1);
            }
        }
    }
    boolean isOver = false;
    for (GuiButton button : buttonList) {
        if (button.isMouseOver())
            isOver = true;
    }
    if (!mouseDown && Mouse.isButtonDown(0) && !isOver) {
        // Mouse pushed down. Calculate current element
        int clickX = Mouse.getX() / current.getScaleFactor();
        int clickY = Mouse.getY() / current.getScaleFactor();
        boolean found = false;
        for (DisplayElement element : mod.getDisplayElements()) {
            Dimension dimension = element.getDimensions();
            double displayXLoc = current.getScaledWidth_double() * element.getXloc();
            if (element.isRightSided())
                displayXLoc -= element.getDimensions().getWidth();
            double displayYLoc = current.getScaledHeight_double() - current.getScaledHeight_double() * element.getYloc();
            if (clickX > displayXLoc && clickX < displayXLoc + dimension.getWidth() && clickY < displayYLoc && clickY > displayYLoc - dimension.getHeight()) {
                // Open gui
                if (currentElement != null && currentElement == element && pastClick) {
                    // Safely nuke the fields and deactivate the chroma effect
                    element.setSelected(false);
                    currentElement = null;
                    mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
                    Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(element, mod));
                    return;
                }
                currentElement = element;
                element.setSelected(true);
                found = true;
                break;
            }
        }
        if (!found) {
            if (currentElement != null)
                currentElement.setSelected(false);
            currentElement = null;
        }
    }
    mouseDown = Mouse.isButtonDown(0);
    if (mouseDown) {
        pastClick = true;
        dTick = 5;
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) GuiButton(net.minecraft.client.gui.GuiButton) ResourceLocation(net.minecraft.util.ResourceLocation) Dimension(cc.hyperium.mods.chromahud.api.Dimension) DisplayElement(cc.hyperium.mods.chromahud.DisplayElement)

Example 3 with DisplayElement

use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.

the class GeneralConfigGui method drawScreen.

@SuppressWarnings("Duplicates")
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    ScaledResolution current = ResolutionUtil.current();
    drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
    super.drawScreen(mouseX, mouseY, partialTicks);
    List<DisplayElement> elementList = mod.getDisplayElements();
    elementList.stream().filter(element -> currentElement == null || currentElement != element).forEach(element -> {
        ElementRenderer.startDrawing(element);
        try {
            element.drawForConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ElementRenderer.endDrawing(element);
    });
    if (currentElement != null) {
        ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
        double offset = currentElement.isRightSided() ? currentElement.getDimensions().getWidth() : 0;
        // Left top right bottom
        double x1 = currentElement.getXloc() * resolution.getScaledWidth_double() - offset;
        double x2 = currentElement.getXloc() * resolution.getScaledWidth_double() + currentElement.getDimensions().getWidth() - offset;
        double y1 = currentElement.getYloc() * resolution.getScaledHeight_double();
        double y2 = currentElement.getYloc() * resolution.getScaledHeight_double() + currentElement.getDimensions().getHeight();
        // Chroma selection background
        if (currentElement.isSelected()) {
            HyperiumGui.drawChromaBox((int) x1 - 2, (int) y1 - 2, (int) x2 + 2, (int) y2 - 2, 0.2F);
        }
        ElementRenderer.startDrawing(currentElement);
        // Draw the element after the background
        currentElement.drawForConfig();
        ElementRenderer.endDrawing(currentElement);
        // Turns the edit image on
        edit.visible = true;
        int propX = (int) x1 - 5;
        int propY = (int) y1 - 20;
        if (propX < 10 || propX > resolution.getScaledWidth() - 200) {
            propX = resolution.getScaledWidth() / 2;
        }
        if (propY > resolution.getScaledHeight() - 5 || propY < 0)
            propY = resolution.getScaledHeight() / 2;
        edit.xPosition = propX;
        edit.yPosition = propY;
        // moving the thing
        if (Mouse.isButtonDown(0)) {
            if (mouseX > x1 - 2 && mouseX < x2 + 2 && mouseY > y1 - 2 && mouseY < y2 + 2 || lastD) {
                // inside
                double x3 = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
                double y3 = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
                currentElement.setXloc(currentElement.getXloc() - (lastX - x3) / ((double) ResolutionUtil.current().getScaleFactor()));
                currentElement.setYloc(currentElement.getYloc() + (lastY - y3) / ((double) ResolutionUtil.current().getScaleFactor()));
                // Math to keep it inside screen
                if (currentElement.getXloc() * resolution.getScaledWidth_double() - offset < 0) {
                    if (currentElement.isRightSided())
                        currentElement.setXloc(offset / resolution.getScaledWidth_double());
                    else
                        currentElement.setXloc(0);
                }
                if (currentElement.getYloc() < 0)
                    currentElement.setYloc(0);
                if (currentElement.getXloc() * resolution.getScaledWidth() + currentElement.getDimensions().getWidth() - offset > resolution.getScaledWidth()) {
                    currentElement.setXloc(currentElement.isRightSided() ? 1.0 : (resolution.getScaledWidth_double() - currentElement.getDimensions().getWidth()) / resolution.getScaledWidth_double());
                }
                if (currentElement.getYloc() * resolution.getScaledHeight() + currentElement.getDimensions().getHeight() > resolution.getScaledHeight()) {
                    currentElement.setYloc((resolution.getScaledHeight_double() - currentElement.getDimensions().getHeight()) / resolution.getScaledHeight_double());
                }
                lastD = true;
            }
        } else {
            lastD = false;
        }
    } else {
        edit.visible = false;
    }
    lastX = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
    lastY = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
    if (dTick <= 0 && pastClick)
        pastClick = false;
    if (pastClick)
        dTick--;
}
Also used : GuiButtonIcon(cc.hyperium.gui.GuiButtonIcon) ChromaHUDApi(cc.hyperium.mods.chromahud.ChromaHUDApi) ResolutionUtil(cc.hyperium.mods.sk1ercommon.ResolutionUtil) GuiButton(net.minecraft.client.gui.GuiButton) ScaledResolution(net.minecraft.client.gui.ScaledResolution) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) ElementRenderer(cc.hyperium.mods.chromahud.ElementRenderer) IOException(java.io.IOException) HashMap(java.util.HashMap) Keyboard(org.lwjgl.input.Keyboard) Mouse(org.lwjgl.input.Mouse) java.awt(java.awt) Consumer(java.util.function.Consumer) Dimension(cc.hyperium.mods.chromahud.api.Dimension) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) DisplayElement(cc.hyperium.mods.chromahud.DisplayElement) Minecraft(net.minecraft.client.Minecraft) HyperiumGui(cc.hyperium.gui.HyperiumGui) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) Hyperium(cc.hyperium.Hyperium) ChromaHUD(cc.hyperium.mods.chromahud.ChromaHUD) ScaledResolution(net.minecraft.client.gui.ScaledResolution) DisplayElement(cc.hyperium.mods.chromahud.DisplayElement) IOException(java.io.IOException)

Example 4 with DisplayElement

use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.

the class AddItemsGui method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    mouseLock = mouseLock && Mouse.isButtonDown(0);
    ScaledResolution current = ResolutionUtil.current();
    drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
    super.drawScreen(mouseX, mouseY, partialTicks);
    ElementRenderer.startDrawing(target);
    if (adding) {
        Color defaultColor = new Color(255, 255, 255, 100);
        int cursorY = 50 + offset;
        drawCenteredString(mc.fontRendererObj, "Click Explore to see examples!", current.getScaledWidth() / 2, cursorY - 30, Color.RED.getRGB());
        List<ChromaHUDParser> parsers = ChromaHUDApi.getInstance().getParsers();
        for (ChromaHUDParser parser : parsers) {
            Map<String, String> names = parser.getNames();
            for (Map.Entry<String, String> entry : names.entrySet()) {
                String s = entry.getKey();
                String text1 = entry.getValue() + "";
                drawRect(current.getScaledWidth() / 2 - 80, cursorY, current.getScaledWidth() / 2 + 80, cursorY + 20, defaultColor.getRGB());
                int j = Color.RED.getRGB();
                int width = 160;
                int height = 20;
                mc.fontRendererObj.drawString(text1, ((current.getScaledWidth() >> 1) - 80 + (width >> 1) - (mc.fontRendererObj.getStringWidth(text1) >> 1)), cursorY + ((height - 8) >> 1), j, false);
                int i = ResolutionUtil.current().getScaledHeight() - (Mouse.getY() / current.getScaleFactor());
                if (Mouse.isButtonDown(0) && !mouseLock)
                    if (i >= cursorY && i <= cursorY + 23) {
                        int i1 = Mouse.getX() / current.getScaleFactor();
                        if (i1 >= current.getScaledWidth() / 2 - 80 && i1 <= current.getScaledWidth() / 2 + 80) {
                            DisplayItem item = ChromaHUDApi.getInstance().parse(s, 0, new JsonHolder().put("type", s));
                            element.getDisplayItems().add(item);
                            element.adjustOrdinal();
                            mc.displayGuiScreen(new EditItemsGui(element, mod));
                        }
                    }
                cursorY += 23;
            }
        }
    } else {
        int cursorY = 50 + offset;
        List<ChromaHUDParser> parsers = ChromaHUDApi.getInstance().getParsers();
        for (ChromaHUDParser parser : parsers) {
            ChromaHUDDescription description = parser.description();
            String text = "Items in " + description.getName() + ".";
            mc.fontRendererObj.drawString(text, (current.getScaledWidth() - mc.fontRendererObj.getStringWidth(text)) >> 1, cursorY, Color.RED.getRGB(), true);
            cursorY += 30;
            Map<String, String> names = parser.getNames();
            for (Map.Entry<String, String> entry : names.entrySet()) {
                String s = entry.getKey();
                String text1 = entry.getValue() + ": ";
                DisplayElement displayElement = find(s);
                if (displayElement == null) {
                    String text2 = "ERROR LOCATING DISPLAY ELEMENT " + s;
                    mc.fontRendererObj.drawString(text2, (current.getScaledWidth() - mc.fontRendererObj.getStringWidth(text2)) >> 1, cursorY, Color.RED.getRGB(), true);
                    cursorY += 15;
                    continue;
                }
                Dimension dimensions = displayElement.getDimensions();
                int stringWidth = mc.fontRendererObj.getStringWidth(text1);
                double totalWidth = dimensions.getWidth() + stringWidth;
                double left = (current.getScaledWidth_double() - totalWidth) / 2;
                double startDraw = left + stringWidth;
                displayElement.setXloc(startDraw / current.getScaledWidth_double());
                displayElement.setYloc(((double) cursorY) / current.getScaledHeight_double());
                displayElement.drawForConfig();
                mc.fontRendererObj.drawString(text1, (float) ((current.getScaledWidth() - totalWidth) / 2), cursorY, Color.RED.getRGB(), true);
                cursorY += dimensions.getHeight() + 5;
            }
        }
    }
    ElementRenderer.endDrawing(target);
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) DisplayItem(cc.hyperium.mods.chromahud.api.DisplayItem) Dimension(cc.hyperium.mods.chromahud.api.Dimension) DisplayElement(cc.hyperium.mods.chromahud.DisplayElement) ScaledResolution(net.minecraft.client.gui.ScaledResolution) ChromaHUDParser(cc.hyperium.mods.chromahud.api.ChromaHUDParser) ChromaHUDDescription(cc.hyperium.mods.chromahud.api.ChromaHUDDescription) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DisplayElement (cc.hyperium.mods.chromahud.DisplayElement)4 Dimension (cc.hyperium.mods.chromahud.api.Dimension)3 GuiButton (net.minecraft.client.gui.GuiButton)3 ScaledResolution (net.minecraft.client.gui.ScaledResolution)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 GuiButtonIcon (cc.hyperium.gui.GuiButtonIcon)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Hyperium (cc.hyperium.Hyperium)1 HyperiumGui (cc.hyperium.gui.HyperiumGui)1 ChromaHUD (cc.hyperium.mods.chromahud.ChromaHUD)1 ChromaHUDApi (cc.hyperium.mods.chromahud.ChromaHUDApi)1 ElementRenderer (cc.hyperium.mods.chromahud.ElementRenderer)1 ChromaHUDDescription (cc.hyperium.mods.chromahud.api.ChromaHUDDescription)1 ChromaHUDParser (cc.hyperium.mods.chromahud.api.ChromaHUDParser)1 DisplayItem (cc.hyperium.mods.chromahud.api.DisplayItem)1 ResolutionUtil (cc.hyperium.mods.sk1ercommon.ResolutionUtil)1 JsonHolder (cc.hyperium.utils.JsonHolder)1 java.awt (java.awt)1 IOException (java.io.IOException)1