Search in sources :

Example 6 with DisplayItem

use of cc.hyperium.mods.chromahud.api.DisplayItem 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)

Example 7 with DisplayItem

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

the class EditItemsGui method mouseClicked.

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
    if (modifying != null) {
        List<ButtonConfig> configs = ChromaHUDApi.getInstance().getButtonConfigs(modifying.getType());
        if (configs != null && !configs.isEmpty()) {
            for (ButtonConfig config : configs) {
                GuiButton button = config.getButton();
                if (button.mousePressed(mc, mouseX, mouseY)) {
                    config.getAction().accept(button, modifying);
                    return;
                }
            }
        }
        List<TextConfig> textConfigs = ChromaHUDApi.getInstance().getTextConfigs(modifying.getType());
        if (textConfigs != null && !textConfigs.isEmpty()) {
            for (TextConfig config : textConfigs) {
                GuiTextField textField = config.getTextField();
                textField.mouseClicked(mouseX, mouseY, mouseButton);
                if (textField.isFocused()) {
                    return;
                }
            }
        }
    }
    super.mouseClicked(mouseX, mouseY, mouseButton);
    if (mouseButton == 0) {
        DisplayItem item1 = null;
        // Check X range first since it is easy
        ScaledResolution current = ResolutionUtil.current();
        int xCenter = current.getScaledWidth() / 2;
        if (mouseX >= xCenter - 80 && mouseX <= xCenter + 80) {
            // now some super janky code
            int yPosition = 40;
            for (DisplayItem displayItem : element.getDisplayItems()) {
                if (mouseY >= yPosition && mouseY <= yPosition + 20) {
                    item1 = displayItem;
                    break;
                }
                // Adjust for 3 pixel gap
                yPosition += 23;
            }
        }
        for (GuiButton guiButton : super.buttonList) {
            if (guiButton.isMouseOver())
                return;
        }
        modifying = item1;
        if (modifying != null) {
            ChromaHUDApi.getInstance().getTextConfigs(modifying.getType()).forEach((config) -> config.getLoad().accept(config.getTextField(), modifying));
            ChromaHUDApi.getInstance().getButtonConfigs(modifying.getType()).forEach((button) -> button.getLoad().accept(button.getButton(), modifying));
            ChromaHUDApi.getInstance().getStringConfigs(modifying.getType()).forEach((button) -> button.getLoad().accept(modifying));
        }
    }
}
Also used : TextConfig(cc.hyperium.mods.chromahud.api.TextConfig) ButtonConfig(cc.hyperium.mods.chromahud.api.ButtonConfig) DisplayItem(cc.hyperium.mods.chromahud.api.DisplayItem)

Example 8 with DisplayItem

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

the class EditItemsGui method drawScreen.

@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);
    ElementRenderer.startDrawing(element);
    element.renderEditView();
    ElementRenderer.endDrawing(element);
    int xPosition = ResolutionUtil.current().getScaledWidth() / 2 - 80;
    int yPosition = 40;
    int width = 160;
    int height = 20;
    Color defaultColor = new Color(255, 255, 255, 100);
    Color otherColor = new Color(255, 255, 255, 150);
    for (DisplayItem displayItem : element.getDisplayItems()) {
        FontRenderer fontrenderer = mc.fontRendererObj;
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        boolean hovered = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height;
        drawRect(xPosition, yPosition, xPosition + width, yPosition + height, modifying != null && modifying.getOrdinal() == displayItem.getOrdinal() || hovered ? otherColor.getRGB() : defaultColor.getRGB());
        int j = Color.RED.getRGB();
        String displayString = ChromaHUDApi.getInstance().getName(displayItem.getType());
        fontrenderer.drawString(displayString, (xPosition + (width >> 1) - (fontrenderer.getStringWidth(displayString) >> 1)), yPosition + ((height - 8) >> 1), j, false);
        yPosition += 23;
    }
    if (modifying != null) {
        List<ButtonConfig> configs = ChromaHUDApi.getInstance().getButtonConfigs(modifying.getType());
        xPosition = 3;
        yPosition = 5 + 21 * 4;
        if (configs != null && !configs.isEmpty()) {
            for (ButtonConfig config : configs) {
                GuiButton button = config.getButton();
                button.xPosition = xPosition;
                button.yPosition = yPosition;
                button.drawButton(mc, mouseX, mouseY);
                yPosition += 23;
            }
        }
        List<TextConfig> textConfigs = ChromaHUDApi.getInstance().getTextConfigs(modifying.getType());
        if (textConfigs != null && !textConfigs.isEmpty()) {
            for (TextConfig config : textConfigs) {
                GuiTextField textField = config.getTextField();
                textField.xPosition = xPosition;
                textField.yPosition = yPosition;
                textField.drawTextBox();
                yPosition += 23;
                config.getAction().accept(textField, modifying);
            }
        }
        int rightBound = (int) (ResolutionUtil.current().getScaledWidth_double() / 2 - 90);
        List<StringConfig> stringConfigs = ChromaHUDApi.getInstance().getStringConfigs(modifying.getType());
        if (stringConfigs != null && !stringConfigs.isEmpty()) {
            for (StringConfig config : stringConfigs) {
                config.getDraw().accept(modifying);
                String draw = config.getString();
                List<String> lines = new ArrayList<>();
                String[] split = draw.split(" ");
                FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
                StringBuilder currentLine = new StringBuilder();
                for (String s : split) {
                    if (!s.contains("\n")) {
                        if (fontRendererObj.getStringWidth(" " + currentLine.toString()) + fontRendererObj.getStringWidth(s) + xPosition < rightBound - 10)
                            currentLine.append(" ").append(s);
                        else {
                            lines.add(currentLine.toString());
                            currentLine = new StringBuilder();
                            currentLine.append(s);
                        }
                    } else {
                        String[] split1 = s.split("\n");
                        Iterator<String> iterator = Arrays.asList(split1).iterator();
                        while (iterator.hasNext()) {
                            currentLine.append(" ").append(iterator.next());
                            if (iterator.hasNext()) {
                                lines.add(currentLine.toString());
                                currentLine = new StringBuilder();
                            }
                        }
                    }
                }
                lines.add(currentLine.toString());
                yPosition += 10;
                for (String string : lines) {
                    Minecraft.getMinecraft().fontRendererObj.drawString(string, xPosition, yPosition, Color.RED.getRGB());
                    yPosition += 10;
                }
            }
        }
    }
}
Also used : ButtonConfig(cc.hyperium.mods.chromahud.api.ButtonConfig) DisplayItem(cc.hyperium.mods.chromahud.api.DisplayItem) TextConfig(cc.hyperium.mods.chromahud.api.TextConfig) StringConfig(cc.hyperium.mods.chromahud.api.StringConfig)

Aggregations

DisplayItem (cc.hyperium.mods.chromahud.api.DisplayItem)8 ScaledResolution (net.minecraft.client.gui.ScaledResolution)4 ButtonConfig (cc.hyperium.mods.chromahud.api.ButtonConfig)3 TextConfig (cc.hyperium.mods.chromahud.api.TextConfig)3 JsonHolder (cc.hyperium.utils.JsonHolder)3 StringConfig (cc.hyperium.mods.chromahud.api.StringConfig)2 JsonArray (com.google.gson.JsonArray)2 Hyperium (cc.hyperium.Hyperium)1 EventBus (cc.hyperium.event.EventBus)1 AbstractMod (cc.hyperium.mods.AbstractMod)1 DisplayElement (cc.hyperium.mods.chromahud.DisplayElement)1 ChromaHUDDescription (cc.hyperium.mods.chromahud.api.ChromaHUDDescription)1 ChromaHUDParser (cc.hyperium.mods.chromahud.api.ChromaHUDParser)1 Dimension (cc.hyperium.mods.chromahud.api.Dimension)1 CommandChromaHUD (cc.hyperium.mods.chromahud.commands.CommandChromaHUD)1 cc.hyperium.mods.chromahud.displayitems.chromahud (cc.hyperium.mods.chromahud.displayitems.chromahud)1 ToggleSprintStatus (cc.hyperium.mods.chromahud.displayitems.hyperium.ToggleSprintStatus)1 GeneralConfigGui (cc.hyperium.mods.chromahud.gui.GeneralConfigGui)1 ChatColor (cc.hyperium.utils.ChatColor)1 java.io (java.io)1