Search in sources :

Example 1 with UIWindow

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

the class BleachFileHelper method readUI.

public static void readUI() {
    JsonObject jo = BleachJsonHelper.readJsonFile("ui.json");
    if (jo == null)
        return;
    Map<String, UIWindow> uiWindows = UIClickGuiScreen.INSTANCE.getUIContainer().windows;
    for (Entry<String, JsonElement> e : jo.entrySet()) {
        if (!e.getValue().isJsonObject() || !uiWindows.containsKey(e.getKey()))
            continue;
        JsonObject jw = e.getValue().getAsJsonObject();
        if (!jw.has("x") || !jw.has("y"))
            continue;
        Position pos = new Position(jw.get("x").getAsDouble(), jw.get("y").getAsDouble());
        if (jw.has("attachments")) {
            for (Entry<String, JsonElement> ja : jw.get("attachments").getAsJsonObject().entrySet()) {
                if (uiWindows.containsKey(ja.getKey()) || ja.getKey().length() == 1) {
                    pos.addAttachment(ja.getKey(), ja.getValue().getAsInt());
                }
            }
        }
        uiWindows.get(e.getKey()).position = pos;
    }
}
Also used : Position(org.bleachhack.gui.clickgui.window.UIWindow.Position) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) UIWindow(org.bleachhack.gui.clickgui.window.UIWindow)

Example 2 with UIWindow

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

the class BleachFileHelper method saveUI.

public static void saveUI() {
    JsonObject jo = new JsonObject();
    for (Entry<String, UIWindow> w : UIClickGuiScreen.INSTANCE.getUIContainer().windows.entrySet()) {
        JsonObject jw = new JsonObject();
        jw.addProperty("x", w.getValue().position.xPercent);
        jw.addProperty("y", w.getValue().position.yPercent);
        JsonObject ja = new JsonObject();
        for (Object2IntMap.Entry<String> atm : w.getValue().position.getAttachments().object2IntEntrySet()) {
            ja.add(atm.getKey(), new JsonPrimitive(atm.getIntValue()));
        }
        if (ja.size() > 0) {
            jw.add("attachments", ja);
        }
        jo.add(w.getKey(), jw);
    }
    BleachJsonHelper.setJsonFile("ui.json", jo);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) JsonObject(com.google.gson.JsonObject) UIWindow(org.bleachhack.gui.clickgui.window.UIWindow)

Example 3 with UIWindow

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

the class UIClickGuiScreen method render.

public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    BleachFileHelper.SCHEDULE_SAVE_UI.set(true);
    uiContainer.updatePositions(width, height);
    for (UIWindow w : uiContainer.windows.values()) {
        boolean shouldClose = w.shouldClose();
        if (shouldClose && !w.closed)
            w.detachFromOthers(false);
        w.closed = shouldClose;
    }
    super.render(matrices, mouseX, mouseY, delta);
}
Also used : UIWindow(org.bleachhack.gui.clickgui.window.UIWindow)

Aggregations

UIWindow (org.bleachhack.gui.clickgui.window.UIWindow)3 JsonObject (com.google.gson.JsonObject)2 JsonElement (com.google.gson.JsonElement)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)1 Position (org.bleachhack.gui.clickgui.window.UIWindow.Position)1