Search in sources :

Example 1 with RecipeMapWidget

use of com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget in project Multiblocked by Low-Drag-MC.

the class RecipeMapBuilderWidget method updateRecipeMapList.

private void updateRecipeMapList() {
    recipeMapList.clearAllWidgets();
    if (onRecipeMapSelected != null) {
        onRecipeMapSelected.accept(RecipeMap.EMPTY);
    }
    selected = null;
    File path = new File(Multiblocked.location, "recipe_map");
    if (!path.isDirectory()) {
        if (!path.mkdirs()) {
            return;
        }
    }
    for (File file : Optional.ofNullable(path.listFiles()).orElse(new File[0])) {
        if (file.isFile() && file.getName().endsWith(".json")) {
            recipeMapList.addWidget(new SelectableWidgetGroup(5, 1 + recipeMapList.widgets.size() * 22, getSize().width - 30, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
                selected = file;
                if (onRecipeMapSelected != null) {
                    onRecipeMapSelected.accept(Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class));
                }
            }).addWidget(new ImageWidget(0, 0, 120, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(104, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> new RecipeMapWidget(parent, Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class), recipeMap -> {
                if (recipeMap != null) {
                    if (selected == file) {
                        if (onRecipeMapSelected != null) {
                            onRecipeMapSelected.accept(recipeMap);
                        }
                    }
                    JsonElement element = Multiblocked.GSON.toJsonTree(recipeMap);
                    FileUtility.saveJson(file, element);
                }
            })).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(2, 0, 96, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(96).setType(TextTexture.TextType.ROLL))));
        }
    }
}
Also used : SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap) Desktop(java.awt.Desktop) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) RecipeMapWidget(com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget) IOException(java.io.IOException) UUID(java.util.UUID) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) File(java.io.File) JsonElement(com.google.gson.JsonElement) Consumer(java.util.function.Consumer) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) Optional(java.util.Optional) FileUtility(com.lowdragmc.lowdraglib.utils.FileUtility) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) RecipeMapWidget(com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) JsonElement(com.google.gson.JsonElement) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) File(java.io.File) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Aggregations

JsonElement (com.google.gson.JsonElement)1 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)1 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)1 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)1 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)1 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)1 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)1 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 SelectableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup)1 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)1 FileUtility (com.lowdragmc.lowdraglib.utils.FileUtility)1 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)1 RecipeMapWidget (com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget)1 RecipeMap (com.lowdragmc.multiblocked.api.recipe.RecipeMap)1 Desktop (java.awt.Desktop)1 File (java.io.File)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1