Search in sources :

Example 6 with ImageWidget

use of com.lowdragmc.lowdraglib.gui.widget.ImageWidget in project Multiblocked by Low-Drag-MC.

the class GTRenderer method addTextureSelector.

protected void addTextureSelector(int x, int y, int width, int height, String text, WidgetGroup parent, WidgetGroup group, ResourceLocation init, Consumer<ResourceLocation> newTexture) {
    ImageWidget imageWidget;
    if (init != null) {
        imageWidget = new ImageWidget(x, y, width, height, new GuiTextureGroup(new ColorBorderTexture(1, -1), new ResourceTexture(init.getNamespace() + ":textures/" + init.getPath() + ".png")));
    } else {
        imageWidget = new ImageWidget(x, y, width, height, new ColorBorderTexture(1, -1));
    }
    group.addWidget(imageWidget);
    group.addWidget(new ButtonWidget(x, y, width, height, null, cd -> new ResourceTextureWidget(parent, texture -> {
        if (texture != null) {
            imageWidget.setImage(new GuiTextureGroup(new ColorBorderTexture(1, -1), texture));
            newTexture.accept(new ResourceLocation(texture.imageLocation.toString().replace("textures/", "").replace(".png", "")));
        }
    })).setHoverTexture(new ColorRectTexture(0x4faaaaaa)).setHoverTooltips(String.format("select the %s texture", text)));
}
Also used : JsonObject(com.google.gson.JsonObject) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) CustomBakedModel(com.lowdragmc.lowdraglib.client.model.custommodel.CustomBakedModel) IBakedModel(net.minecraft.client.renderer.model.IBakedModel) Random(java.util.Random) Direction(net.minecraft.util.Direction) Supplier(java.util.function.Supplier) BlockModel(net.minecraft.client.renderer.model.BlockModel) Dist(net.minecraftforge.api.distmarker.Dist) Minecraft(net.minecraft.client.Minecraft) Gson(com.google.gson.Gson) IBlockDisplayReader(net.minecraft.world.IBlockDisplayReader) BlockState(net.minecraft.block.BlockState) ModelLoader(net.minecraftforge.client.model.ModelLoader) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) Nonnull(javax.annotation.Nonnull) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceTextureWidget(com.lowdragmc.multiblocked.api.gui.dialogs.ResourceTextureWidget) EnumMap(java.util.EnumMap) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) IPartComponent(com.lowdragmc.multiblocked.api.tile.part.IPartComponent) IModelData(net.minecraftforge.client.model.data.IModelData) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) AtlasTexture(net.minecraft.client.renderer.texture.AtlasTexture) ModelFactory(com.lowdragmc.lowdraglib.client.model.ModelFactory) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup) IControllerComponent(com.lowdragmc.multiblocked.api.tile.IControllerComponent) BlockPos(net.minecraft.util.math.BlockPos) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Consumer(java.util.function.Consumer) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) IUnbakedModel(net.minecraft.client.renderer.model.IUnbakedModel) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) Collections(java.util.Collections) ResourceTextureWidget(com.lowdragmc.multiblocked.api.gui.dialogs.ResourceTextureWidget) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup)

Example 7 with ImageWidget

use of com.lowdragmc.lowdraglib.gui.widget.ImageWidget in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method initTraitUI.

protected void initTraitUI(TabContainer tabContainer, PlayerEntity PlayerEntity) {
    WidgetGroup group = new WidgetGroup(20, 0, 176, 256);
    tabContainer.addTab(new TabButton(0, tabContainer.containerGroup.widgets.size() * 20, 20, 20).setTexture(new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0, 1, 0.5), new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0.5, 1, 0.5)), group);
    group.addWidget(new ImageWidget(0, 0, 176, 256, new ResourceTexture(JSONUtils.getAsString(definition.traits, "background", "multiblocked:textures/gui/custom_gui.png"))));
    if (traits.size() > 0) {
        for (int row = 0; row < 3; row++) {
            for (int col = 0; col < 9; col++) {
                group.addWidget(new SlotWidget(PlayerEntity.inventory, col + (row + 1) * 9, 7 + col * 18, 173 + row * 18).setLocationInfo(true, false));
            }
        }
        for (int slot = 0; slot < 9; slot++) {
            group.addWidget(new SlotWidget(PlayerEntity.inventory, slot, 7 + slot * 18, 231).setLocationInfo(true, true));
        }
    }
    for (CapabilityTrait trait : traits.values()) {
        trait.createUI(this, group, PlayerEntity);
    }
}
Also used : SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) TabButton(com.lowdragmc.lowdraglib.gui.widget.TabButton) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget)

Example 8 with ImageWidget

use of com.lowdragmc.lowdraglib.gui.widget.ImageWidget 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 9 with ImageWidget

use of com.lowdragmc.lowdraglib.gui.widget.ImageWidget in project Multiblocked by Low-Drag-MC.

the class ControllerBuilderWidget method updateScene.

@OnlyIn(Dist.CLIENT)
private void updateScene(JsonBlockPattern jsonPattern) {
    if (thread != null) {
        thread.interrupt();
        thread = null;
    }
    TrackedDummyWorld world = new TrackedDummyWorld();
    sceneWidget.createScene(world);
    ImageWidget imageWidget;
    sceneWidget.addWidget(imageWidget = new ImageWidget(0, 0, sceneWidget.getSize().width, sceneWidget.getSize().height));
    imageWidget.setVisible(jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length() > 1000);
    thread = new Thread(() -> {
        int[] centerOffset = jsonPattern.getCenterOffset();
        String[][] pattern = jsonPattern.pattern;
        Set<BlockPos> posSet = new HashSet<>();
        int offset = Math.max(pattern.length, Math.max(pattern[0].length, pattern[0][0].length()));
        int sum = jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length();
        AtomicDouble progress = new AtomicDouble(0);
        imageWidget.setImage(new TextTexture("multiblocked.gui.tips.building_scene").setSupplier(() -> I18n.get("multiblocked.gui.tips.building_scene") + String.format(" %.1f", progress.get()) + "%%").setWidth(sceneWidget.getSize().width));
        int count = 0;
        for (int i = 0; i < pattern.length; i++) {
            for (int j = 0; j < pattern[0].length; j++) {
                for (int k = 0; k < pattern[0][0].length(); k++) {
                    if (Thread.interrupted()) {
                        sceneWidget.waitToRemoved(imageWidget);
                        return;
                    }
                    count++;
                    progress.set(count * 100.0 / sum);
                    char symbol = pattern[i][j].charAt(k);
                    BlockPos pos = jsonPattern.getActualPosOffset(k - centerOffset[2], j - centerOffset[1], i - centerOffset[0], Direction.NORTH).offset(offset, offset, offset);
                    if (jsonPattern.symbolMap.containsKey(symbol)) {
                        List<BlockInfo> candidates = new ArrayList<>();
                        for (String s : jsonPattern.symbolMap.get(symbol)) {
                            SimplePredicate predicate = jsonPattern.predicates.get(s);
                            if (predicate instanceof PredicateComponent && ((PredicateComponent) predicate).definition != null) {
                                world.addBlock(pos, BlockInfo.fromBlock(MbdComponents.DummyComponentBlock));
                                DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(pos);
                                assert tileEntity != null;
                                tileEntity.setDefinition(((PredicateComponent) predicate).definition);
                                tileEntity.isFormed = false;
                                tileEntity.setLevelAndPosition(world, pos);
                                posSet.add(pos);
                                break;
                            } else if (predicate != null && predicate.candidates != null) {
                                candidates.addAll(Arrays.asList(predicate.candidates.get()));
                            }
                        }
                        if (candidates.size() > 0) {
                            world.addBlock(pos, candidates.get(0));
                            posSet.add(pos);
                        }
                    }
                }
            }
        }
        Minecraft.getInstance().execute(() -> {
            sceneWidget.setRenderedCore(posSet, null);
            sceneWidget.waitToRemoved(imageWidget);
        });
        thread = null;
    });
    thread.start();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) BlockPos(net.minecraft.util.math.BlockPos) ArrayList(java.util.ArrayList) List(java.util.List) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 10 with ImageWidget

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

Aggregations

ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)23 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)18 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)15 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)15 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)13 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)10 GuiTextureGroup (com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup)8 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)7 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)7 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)7 JsonElement (com.google.gson.JsonElement)6 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)6 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)6 SelectableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup)6 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)6 JsonObject (com.google.gson.JsonObject)5 DraggableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableWidgetGroup)5 SelectorWidget (com.lowdragmc.lowdraglib.gui.widget.SelectorWidget)5 TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)5 File (java.io.File)5