Search in sources :

Example 1 with Window

use of org.bleachhack.gui.window.Window in project BleachHack by BleachDrinker420.

the class BleachFileHelper method readClickGui.

public static void readClickGui() {
    JsonObject jo = BleachJsonHelper.readJsonFile("clickgui.json");
    if (jo == null)
        return;
    for (Entry<String, JsonElement> e : jo.entrySet()) {
        if (!e.getValue().isJsonObject())
            continue;
        for (Window w : ModuleClickGuiScreen.INSTANCE.getWindows()) {
            if (w.title.equals(e.getKey())) {
                JsonObject jw = e.getValue().getAsJsonObject();
                try {
                    w.x1 = jw.get("x").getAsInt();
                    w.y1 = jw.get("y").getAsInt();
                    if (w instanceof ClickGuiWindow && jw.has("hidden")) {
                        ((ClickGuiWindow) w).hiding = jw.get("hidden").getAsBoolean();
                    }
                } catch (Exception ex) {
                    BleachLogger.logger.error("Error trying to load clickgui window: " + e.getKey() + " with data: " + e.getValue());
                }
            }
        }
    }
}
Also used : UIWindow(org.bleachhack.gui.clickgui.window.UIWindow) ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) Window(org.bleachhack.gui.window.Window) ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 2 with Window

use of org.bleachhack.gui.window.Window in project BleachHack by BleachDrinker420.

the class BleachFileHelper method saveClickGui.

public static void saveClickGui() {
    JsonObject jo = new JsonObject();
    for (Window w : ModuleClickGuiScreen.INSTANCE.getWindows()) {
        JsonObject jw = new JsonObject();
        jw.addProperty("x", w.x1);
        jw.addProperty("y", w.y1);
        if (w instanceof ClickGuiWindow) {
            jw.addProperty("hidden", ((ClickGuiWindow) w).hiding);
        }
        jo.add(w.title, jw);
    }
    BleachJsonHelper.setJsonFile("clickgui.json", jo);
}
Also used : UIWindow(org.bleachhack.gui.clickgui.window.UIWindow) ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) Window(org.bleachhack.gui.window.Window) ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) JsonObject(com.google.gson.JsonObject)

Example 3 with Window

use of org.bleachhack.gui.window.Window in project BleachHack by BleachDrinker420.

the class EntityMenuEditScreen method init.

@Override
public void init() {
    super.init();
    addWindow(new Window(width / 4, height / 6, width - width / 4, height - height / 6, "Edit Interactions", new ItemStack(Items.OAK_SIGN)));
    if (editNameField == null) {
        editNameField = new TextFieldWidget(textRenderer, 0, 0, 1000, 16, LiteralText.EMPTY);
    }
    if (editValueField == null) {
        editValueField = new TextFieldWidget(textRenderer, 0, 0, 1000, 16, LiteralText.EMPTY);
    }
}
Also used : Window(org.bleachhack.gui.window.Window) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Window

use of org.bleachhack.gui.window.Window in project BleachHack by BleachDrinker420.

the class UpdateScreen method init.

public void init() {
    super.init();
    int wd = Math.min(width / 2 - 30, 175);
    addWindow(new Window(width / 2 - wd, height / 16, width / 2 + wd, height - height / 16, String.format("BleachHack Update [%s -> %s]", BleachHack.VERSION, updateJson.get("name").getAsString()), new ItemStack(Items.MAGENTA_GLAZED_TERRACOTTA)));
    int w = getWindow(0).x2 - getWindow(0).x1;
    int h = getWindow(0).y2 - getWindow(0).y1;
    getWindow(0).addWidget(new WindowTextWidget("A new BleachHack update is available.", true, WindowTextWidget.TextAlign.MIDDLE, 1.5f, w / 2, 18, 0xe0e0e0));
    getWindow(0).addWidget(new WindowBoxWidget(3, 50, w - 3, h - 23));
    ImmutablePairList<String, Boolean> changelog = new ImmutablePairList<>();
    if (updateJson.has("changelog") && updateJson.get("changelog").isJsonArray()) {
        for (JsonElement je : updateJson.get("changelog").getAsJsonArray()) {
            if (je.isJsonPrimitive()) {
                String string = je.getAsString();
                if (string.charAt(0) == '-')
                    string = "\u00a77-\u00a7r" + string.substring(1);
                List<StringVisitable> wrapped = client.textRenderer.getTextHandler().wrapLines(string, w - 32, Style.EMPTY);
                for (int i = 0; i < wrapped.size(); i++) changelog.add(wrapped.get(i).getString(), i == 0);
            }
        }
    } else {
        changelog.add("Could not find changelog.", false);
    }
    changelogWidgets.clear();
    changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(updateJson.get("name").getAsString(), true, WindowTextWidget.TextAlign.MIDDLE, 2.5f, w / 2, 58, 0xe0e0e0)));
    for (int i = 0; i < changelog.size(); i++) {
        if (changelog.get(i).getValue()) {
            changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget("*", true, 10, 87 + i * 10, 0xa0a0a0)));
        }
        changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(changelog.get(i).getKey(), true, 19, 85 + i * 10, 0xe0e0e0)));
    }
    scrollbar = getWindow(0).addWidget(new WindowScrollbarWidget(w - 14, 51, 37 + changelog.size() * 10, h - 75, 0));
    getWindow(0).addWidget(new WindowButtonWidget(3, h - 21, w / 2 - 2, h - 3, "Website", () -> Util.getOperatingSystem().open(URI.create("https://bleachhack.org/"))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 + 2, h - 21, w - 3, h - 3, "Update", () -> {
        try {
            JsonObject installerJson = updateJson.get("installer").getAsJsonObject();
            if (installerJson.has("os") && installerJson.get("os").isJsonPrimitive() && !System.getProperty("os.name").startsWith(installerJson.get("os").getAsString())) {
                updateResult = "Updater doesn't support your OS!";
                selectWindow(1);
                return;
            }
            File modpath = new File(FabricLoader.getInstance().getModContainer("bleachhack").get().getOrigin().getPaths().get(0).toUri());
            if (!modpath.isFile()) {
                updateResult = "Invalid mod path!";
                selectWindow(1);
                return;
            }
            String link = installerJson.get("link").getAsString();
            String name = link.replaceFirst("^.*\\/", "");
            File installerFile = new File(System.getProperty("java.io.tmpdir"), name);
            BleachLogger.logger.info("\n> Installer path: " + installerFile + "\n> Installer URL: " + link + "\n> Installer file name: " + name + "\n> Regular File: " + Files.isRegularFile(installerFile.toPath()) + "\n> File Length: " + installerFile.length());
            if (!Files.isRegularFile(installerFile.toPath()) || installerFile.length() <= 1024L) {
                FileUtils.copyURLToFile(new URL(link), installerFile);
            }
            String execCommand = link.endsWith(".jar") ? "java -jar " : "cmd /c start ";
            Runtime.getRuntime().exec(execCommand + installerFile.getAbsolutePath() + " " + modpath + " " + installerJson.get("url").getAsString());
            client.scheduleStop();
        } catch (Exception e) {
            updateResult = "Unknown error!";
            selectWindow(1);
            e.printStackTrace();
        }
    }));
    wd = Math.min(width / 2 - 20, 90);
    addWindow(new Window(width / 2 - wd, height / 2 - 15, width / 2 + wd, height / 2 + 15, "Error updating!", new ItemStack(Items.RED_BANNER), true));
    getWindow(1).addWidget(new WindowTextWidget("", true, WindowTextWidget.TextAlign.MIDDLE, wd, 16, 0xc05050).withRenderEvent((wg, ms, wx, wy) -> ((WindowTextWidget) wg).setText(new LiteralText(updateResult))));
}
Also used : Window(org.bleachhack.gui.window.Window) FabricLoader(net.fabricmc.loader.api.FabricLoader) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) Util(net.minecraft.util.Util) URL(java.net.URL) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Style(net.minecraft.text.Style) StringVisitable(net.minecraft.text.StringVisitable) Window(org.bleachhack.gui.window.Window) BleachLogger(org.bleachhack.util.BleachLogger) ImmutablePairList(org.bleachhack.util.collections.ImmutablePairList) URI(java.net.URI) org.bleachhack.gui.window.widget(org.bleachhack.gui.window.widget) WindowScreen(org.bleachhack.gui.window.WindowScreen) Files(java.nio.file.Files) BleachHack(org.bleachhack.BleachHack) MatrixStack(net.minecraft.client.util.math.MatrixStack) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) Items(net.minecraft.item.Items) File(java.io.File) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) ImmutablePairList(org.bleachhack.util.collections.ImmutablePairList) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) JsonElement(com.google.gson.JsonElement) StringVisitable(net.minecraft.text.StringVisitable) ItemStack(net.minecraft.item.ItemStack) File(java.io.File) LiteralText(net.minecraft.text.LiteralText)

Example 5 with Window

use of org.bleachhack.gui.window.Window in project BleachHack by BleachDrinker420.

the class ClickGuiScreen method render.

public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    this.renderBackground(matrices);
    for (Window w : getWindows()) {
        if (w instanceof ClickGuiWindow) {
            ((ClickGuiWindow) w).updateKeys(mouseX, mouseY, keyDown, lmDown, rmDown, lmHeld, mwScroll);
        }
    }
    super.render(matrices, mouseX, mouseY, delta);
    matrices.push();
    matrices.translate(0, 0, 250);
    for (Window w : getWindows()) {
        if (w instanceof ClickGuiWindow) {
            Tooltip tooltip = ((ClickGuiWindow) w).getTooltip();
            if (tooltip != null) {
                int tooltipY = tooltip.y;
                String[] split = tooltip.text.split("\n", -1);
                ArrayUtils.reverse(split);
                for (String s : split) {
                    /* Match lines to end of words after it reaches 22 characters long */
                    Matcher mat = Pattern.compile(".{1,22}\\b\\W*").matcher(s);
                    List<String> lines = new ArrayList<>();
                    while (mat.find()) lines.add(mat.group().trim());
                    if (lines.isEmpty())
                        lines.add(s);
                    int start = tooltipY - lines.size() * 10;
                    for (int l = 0; l < lines.size(); l++) {
                        fill(matrices, tooltip.x, start + (l * 10) - 1, tooltip.x + textRenderer.getWidth(lines.get(l)) + 3, start + (l * 10) + 9, 0xff000000);
                        textRenderer.drawWithShadow(matrices, lines.get(l), tooltip.x + 2, start + (l * 10), -1);
                    }
                    tooltipY -= lines.size() * 10;
                }
            }
        }
    }
    Window.fill(matrices, width / 2 - 50, -1, width / 2 - 2, 12, mouseX >= width / 2 - 50 && mouseX <= width / 2 - 2 && mouseY >= 0 && mouseY <= 12 ? 0x60b070f0 : 0x60606090);
    Window.fill(matrices, width / 2 + 2, -1, width / 2 + 50, 12, mouseX >= width / 2 + 2 && mouseX <= width / 2 + 50 && mouseY >= 0 && mouseY <= 12 ? 0x60b070f0 : 0x60606090);
    drawCenteredText(matrices, textRenderer, "Modules", width / 2 - 26, 2, 0xf0f0f0);
    drawCenteredText(matrices, textRenderer, "UI", width / 2 + 26, 2, 0xf0f0f0);
    if (warningOpacity > 3) {
        drawCenteredText(matrices, textRenderer, "UI not available on the main menu!", width / 2, 17, warningOpacity > 255 ? 0xd14a3b : (warningOpacity << 24) | 0xd14a3b);
        warningOpacity -= 3;
    }
    matrices.pop();
    lmDown = false;
    rmDown = false;
    keyDown = -1;
    mwScroll = 0;
}
Also used : ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) Window(org.bleachhack.gui.window.Window) ClickGuiWindow(org.bleachhack.gui.clickgui.window.ClickGuiWindow) Matcher(java.util.regex.Matcher) Tooltip(org.bleachhack.gui.clickgui.window.ClickGuiWindow.Tooltip) ArrayList(java.util.ArrayList)

Aggregations

Window (org.bleachhack.gui.window.Window)15 ItemStack (net.minecraft.item.ItemStack)9 LiteralText (net.minecraft.text.LiteralText)6 ClickGuiWindow (org.bleachhack.gui.clickgui.window.ClickGuiWindow)6 MatrixStack (net.minecraft.client.util.math.MatrixStack)5 Items (net.minecraft.item.Items)5 WindowScreen (org.bleachhack.gui.window.WindowScreen)5 JsonObject (com.google.gson.JsonObject)4 FabricLoader (net.fabricmc.loader.api.FabricLoader)4 BleachHack (org.bleachhack.BleachHack)4 URL (java.net.URL)3 SharedConstants (net.minecraft.SharedConstants)3 WindowButtonWidget (org.bleachhack.gui.window.widget.WindowButtonWidget)3 WindowScrollbarWidget (org.bleachhack.gui.window.widget.WindowScrollbarWidget)3 WindowTextWidget (org.bleachhack.gui.window.widget.WindowTextWidget)3 WindowWidget (org.bleachhack.gui.window.widget.WindowWidget)3 Resources (com.google.common.io.Resources)2 JsonElement (com.google.gson.JsonElement)2 JsonParser (com.google.gson.JsonParser)2 GameProfile (com.mojang.authlib.GameProfile)2