Search in sources :

Example 1 with Category

use of net.wurstclient.features.Category in project Wurst-MC-1.12 by Wurst-Imperium.

the class ClickGui method init.

public void init() {
    LinkedHashMap<Category, Window> windowMap = new LinkedHashMap<>();
    for (Category category : Category.values()) windowMap.put(category, new Window(category.getName()));
    ArrayList<Feature> features = new ArrayList<>();
    features.addAll(WurstClient.INSTANCE.mods.getAllMods());
    features.addAll(WurstClient.INSTANCE.commands.getAllCommands());
    features.addAll(WurstClient.INSTANCE.special.getAllFeatures());
    for (Feature f : features) if (f.getCategory() != null)
        windowMap.get(f.getCategory()).add(new FeatureButton(f));
    windows.addAll(windowMap.values());
    int x = 5;
    int y = 5;
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    for (Window window : windows) {
        window.pack();
        window.setMinimized(true);
        if (x + window.getWidth() + 5 > sr.getScaledWidth()) {
            x = 5;
            y += 18;
        }
        window.setX(x);
        window.setY(y);
        x += window.getWidth() + 5;
    }
    JsonObject json;
    try (BufferedReader reader = Files.newBufferedReader(windowsFile)) {
        json = JsonUtils.jsonParser.parse(reader).getAsJsonObject();
    } catch (NoSuchFileException e) {
        saveWindows();
        return;
    } catch (Exception e) {
        System.out.println("Failed to load " + windowsFile.getFileName());
        e.printStackTrace();
        saveWindows();
        return;
    }
    for (Window window : windows) {
        JsonElement jsonWindow = json.get(window.getTitle());
        if (jsonWindow == null || !jsonWindow.isJsonObject())
            continue;
        JsonElement jsonX = jsonWindow.getAsJsonObject().get("x");
        if (jsonX.isJsonPrimitive() && jsonX.getAsJsonPrimitive().isNumber())
            window.setX(jsonX.getAsInt());
        JsonElement jsonY = jsonWindow.getAsJsonObject().get("y");
        if (jsonY.isJsonPrimitive() && jsonY.getAsJsonPrimitive().isNumber())
            window.setY(jsonY.getAsInt());
        JsonElement jsonMinimized = jsonWindow.getAsJsonObject().get("minimized");
        if (jsonMinimized.isJsonPrimitive() && jsonMinimized.getAsJsonPrimitive().isBoolean())
            window.setMinimized(jsonMinimized.getAsBoolean());
        JsonElement jsonPinned = jsonWindow.getAsJsonObject().get("pinned");
        if (jsonPinned.isJsonPrimitive() && jsonPinned.getAsJsonPrimitive().isBoolean())
            window.setPinned(jsonPinned.getAsBoolean());
    }
    saveWindows();
}
Also used : Category(net.wurstclient.features.Category) ArrayList(java.util.ArrayList) NoSuchFileException(java.nio.file.NoSuchFileException) JsonObject(com.google.gson.JsonObject) Feature(net.wurstclient.features.Feature) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ScaledResolution(net.minecraft.client.gui.ScaledResolution) JsonElement(com.google.gson.JsonElement) BufferedReader(java.io.BufferedReader)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 Category (net.wurstclient.features.Category)1 Feature (net.wurstclient.features.Feature)1