Search in sources :

Example 16 with ResourceTexture

use of com.lowdragmc.lowdraglib.gui.texture.ResourceTexture in project Multiblocked by Low-Drag-MC.

the class BlueprintTableWidget method recipeMapBuilder.

private void recipeMapBuilder(ClickData clickData) {
    widgets.forEach(this::waitToRemoved);
    WidgetGroup group = new WidgetGroup(0, 0, getSize().width, getSize().height).setClientSideWidget();
    this.addWidget(0, group);
    if (clickData.isRemote) {
        group.addWidget(0, new ImageWidget(0, 0, getSize().width, getSize().height, new ResourceTexture("multiblocked:textures/gui/blueprint_page.png")));
        group.addWidget(new RecipeMapBuilderWidget(this, 200, 31, 150, 188));
    }
}
Also used : ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget)

Example 17 with ResourceTexture

use of com.lowdragmc.lowdraglib.gui.texture.ResourceTexture in project Multiblocked by Low-Drag-MC.

the class ControllerBuilderWidget method updateList.

protected void updateList() {
    int size = files.size();
    files.forEach(containers::waitToRemoved);
    files.clear();
    File path = new File(Multiblocked.location, "definition/controller");
    if (!path.isDirectory()) {
        if (!path.mkdirs()) {
            return;
        }
    }
    for (File file : Optional.ofNullable(path.listFiles((s, name) -> name.endsWith(".json"))).orElse(new File[0])) {
        SelectableWidgetGroup widgetGroup = (SelectableWidgetGroup) new SelectableWidgetGroup(0, (containers.widgets.size() - size) * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
            templateButton.setVisible(false);
            selected = null;
            onJsonSelected(file);
        }).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(134, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> {
            JsonElement jsonElement = FileUtility.loadJson(file);
            if (jsonElement != null) {
                try {
                    String recipeMap = jsonElement.getAsJsonObject().get("recipeMap").getAsString();
                    JsonBlockPattern pattern = Multiblocked.GSON.fromJson(jsonElement.getAsJsonObject().get("basePattern"), JsonBlockPattern.class);
                    ControllerDefinition definition = Multiblocked.GSON.fromJson(jsonElement, ControllerDefinition.class);
                    new ControllerWidget(this, definition, pattern, recipeMap, jsonObject -> {
                        if (jsonObject != null) {
                            FileUtility.saveJson(file, jsonObject);
                        }
                    });
                } catch (Exception ignored) {
                }
            }
        }).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(Items.PAPER)));
        files.add(widgetGroup);
        containers.addWidget(widgetGroup);
    }
}
Also used : Arrays(java.util.Arrays) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) Direction(net.minecraft.util.Direction) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint) BlueprintTableTileEntity(com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) ClickData(com.lowdragmc.lowdraglib.gui.util.ClickData) MBDBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer) I18n(net.minecraft.client.resources.I18n) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) Desktop(java.awt.Desktop) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ControllerWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget) File(java.io.File) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ResourceLocation(net.minecraft.util.ResourceLocation) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) Optional(java.util.Optional) FileUtility(com.lowdragmc.lowdraglib.utils.FileUtility) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) PacketBuffer(net.minecraft.network.PacketBuffer) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ControllerWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) JsonElement(com.google.gson.JsonElement) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) File(java.io.File)

Example 18 with ResourceTexture

use of com.lowdragmc.lowdraglib.gui.texture.ResourceTexture 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)

Example 19 with ResourceTexture

use of com.lowdragmc.lowdraglib.gui.texture.ResourceTexture in project Multiblocked by Low-Drag-MC.

the class ComponentWidget method createScene.

@OnlyIn(Dist.CLIENT)
protected WidgetGroup createScene(int x, int y, String text, String tips, IMultiblockedRenderer init, Consumer<IMultiblockedRenderer> onUpdate) {
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
    DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(BlockPos.ZERO);
    tileEntity.setDefinition(new PartDefinition(new ResourceLocation(Multiblocked.MODID, "component_widget")));
    tileEntity.getDefinition().baseRenderer = init;
    WidgetGroup widgetGroup = new WidgetGroup(x, y, 90, 90);
    widgetGroup.addWidget(new LabelWidget(0, 0, text));
    widgetGroup.addWidget(new ImageWidget(0, 12, 90, 80, new ColorBorderTexture(2, 0xff4A82F7)));
    widgetGroup.addWidget(new SceneWidget(0, 12, 90, 80, world).setRenderedCore(Collections.singleton(BlockPos.ZERO), null).setRenderSelect(false).setRenderFacing(false));
    widgetGroup.addWidget(new ButtonWidget(90 - 15, 12, 15, 15, new ResourceTexture("multiblocked:textures/gui/option.png"), (cd) -> new IRendererWidget(this, tileEntity.getRenderer(), r -> {
        tileEntity.getDefinition().baseRenderer = r;
        onUpdate.accept(r);
    })).setHoverBorderTexture(1, -1).setHoverTooltips(tips));
    return widgetGroup;
}
Also used : JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) TabButton(com.lowdragmc.lowdraglib.gui.widget.TabButton) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) IRendererWidget(com.lowdragmc.multiblocked.api.gui.dialogs.IRendererWidget) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) TabContainer(com.lowdragmc.lowdraglib.gui.widget.TabContainer) Dist(net.minecraftforge.api.distmarker.Dist) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) TextBoxWidget(com.lowdragmc.lowdraglib.gui.widget.TextBoxWidget) Minecraft(net.minecraft.client.Minecraft) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) ComponentDefinition(com.lowdragmc.multiblocked.api.definition.ComponentDefinition) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTextureWidget(com.lowdragmc.multiblocked.api.gui.dialogs.ResourceTextureWidget) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) BlockPos(net.minecraft.util.math.BlockPos) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) DialogWidget(com.lowdragmc.lowdraglib.gui.widget.DialogWidget) MbdCapabilities(com.lowdragmc.multiblocked.api.registry.MbdCapabilities) Consumer(java.util.function.Consumer) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) Collections(java.util.Collections) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) IRendererWidget(com.lowdragmc.multiblocked.api.gui.dialogs.IRendererWidget) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) ResourceLocation(net.minecraft.util.ResourceLocation) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 20 with ResourceTexture

use of com.lowdragmc.lowdraglib.gui.texture.ResourceTexture in project Multiblocked by Low-Drag-MC.

the class ContentWidget method openConfigurator.

/**
 * Configurator.
 */
public void openConfigurator(WidgetGroup dialog) {
    dialog.addWidget(new LabelWidget(5, 8, "multiblocked.gui.label.chance"));
    dialog.addWidget(new TextFieldWidget(125 - 60, 5, 30, 15, null, number -> setContent(io, content, Float.parseFloat(number), perTick)).setNumbersOnly(0f, 1f).setCurrentString(chance + ""));
    dialog.addWidget(new SwitchWidget(125 - 25, 5, 15, 15, (cd, r) -> setContent(io, content, chance, r)).setBaseTexture(new ResourceTexture("multiblocked:textures/gui/boolean.png").getSubTexture(0, 0, 1, 0.5)).setPressedTexture(new ResourceTexture("multiblocked:textures/gui/boolean.png").getSubTexture(0, 0.5, 1, 0.5)).setHoverBorderTexture(1, -1).setPressed(perTick).setHoverTooltips("multiblocked.gui.content.per_tick"));
}
Also used : OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) LocalizationUtils(com.lowdragmc.lowdraglib.utils.LocalizationUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Dist(net.minecraftforge.api.distmarker.Dist) Lists(com.google.common.collect.Lists) DrawerHelper(com.lowdragmc.lowdraglib.gui.util.DrawerHelper) Minecraft(net.minecraft.client.Minecraft) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) IO(com.lowdragmc.multiblocked.api.capability.IO) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) Position(com.lowdragmc.lowdraglib.utils.Position) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) Size(com.lowdragmc.lowdraglib.utils.Size) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) Widget(com.lowdragmc.lowdraglib.gui.widget.Widget) Target(com.lowdragmc.lowdraglib.gui.ingredient.Target) IGuiTexture(com.lowdragmc.lowdraglib.gui.texture.IGuiTexture) Consumer(java.util.function.Consumer) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) Collections(java.util.Collections) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget)

Aggregations

ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)27 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)19 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)15 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)15 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)13 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)12 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)10 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)9 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)8 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)8 JsonObject (com.google.gson.JsonObject)7 SwitchWidget (com.lowdragmc.lowdraglib.gui.widget.SwitchWidget)6 TextFieldWidget (com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget)6 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)6 Collections (java.util.Collections)6 List (java.util.List)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 Dist (net.minecraftforge.api.distmarker.Dist)6 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)6 JsonElement (com.google.gson.JsonElement)5