Search in sources :

Example 1 with ColorRectTexture

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

the class PartBuilderWidget method initScene.

@OnlyIn(Dist.CLIENT)
private void initScene() {
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
    tileEntity = (DummyComponentTileEntity) world.getBlockEntity(BlockPos.ZERO);
    this.addWidget(new ImageWidget(30, 59, 138, 138, new GuiTextureGroup(new ColorBorderTexture(3, -1), new ColorRectTexture(0xaf444444))));
    this.addWidget(new SceneWidget(30, 59, 138, 138, world).setRenderedCore(Collections.singleton(BlockPos.ZERO), null).setRenderSelect(false).setRenderFacing(false));
    this.addWidget(new ImageWidget(30, 65, 138, 15, textTexture = new TextTexture("", 0xff00ff00).setDropShadow(true).setWidth(138).setType(TextTexture.TextType.ROLL)));
}
Also used : ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with ColorRectTexture

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

the class PartBuilderWidget method walkFile.

private void walkFile(String type, IGuiTexture icon, File path, BiConsumer<JsonElement, File> consumer) {
    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, files.size() * 22, containers.getSize().width, 20).setOnSelected(group -> {
            JsonElement jsonElement = FileUtility.loadJson(file);
            if (jsonElement != null && jsonElement.isJsonObject()) {
                try {
                    setNewRenderer(Multiblocked.GSON.fromJson(jsonElement, PartDefinition.class).baseRenderer, type);
                } catch (Exception ignored) {
                }
            }
        }).setSelectedTexture(-2, 0xff00aa00).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 && jsonElement.isJsonObject()) {
                try {
                    consumer.accept(jsonElement, file);
                } 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, icon));
        files.add(widgetGroup);
        containers.addWidget(widgetGroup);
    }
}
Also used : ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) 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)

Example 3 with ColorRectTexture

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

the class PatternWidget method onPosSelected.

private void onPosSelected(BlockPos pos, Direction facing) {
    if (index >= patterns.length || index < 0)
        return;
    TraceabilityPredicate predicate = patterns[index].predicateMap.get(pos);
    if (predicate != null) {
        predicates.clear();
        predicates.addAll(predicate.common);
        predicates.addAll(predicate.limited);
        // why it happens?
        predicates.removeIf(p -> p == null || p.candidates == null);
        if (candidates != null) {
            for (SlotWidget candidate : candidates) {
                removeWidget(candidate);
            }
        }
        List<List<ItemStack>> candidateStacks = new ArrayList<>();
        List<List<String>> predicateTips = new ArrayList<>();
        for (SimplePredicate simplePredicate : predicates) {
            List<ItemStack> itemStacks = simplePredicate.getCandidates();
            if (!itemStacks.isEmpty()) {
                candidateStacks.add(itemStacks);
                predicateTips.add(simplePredicate.getToolTips(predicate));
            }
        }
        candidates = new SlotWidget[candidateStacks.size()];
        CycleItemStackHandler itemHandler = new CycleItemStackHandler(candidateStacks);
        for (int i = 0; i < candidateStacks.size(); i++) {
            int finalI = i;
            candidates[i] = new SlotWidget(itemHandler, i, 9 + (i / 6) * 18, 33 + (i % 6) * 18, false, false).setItemHook(this::itemHook).setBackgroundTexture(new ColorRectTexture(0x4fffffff)).setOnAddedTooltips((slot, list) -> predicateTips.get(finalI).forEach(tip -> list.add(new StringTextComponent(tip))));
            addWidget(candidates[i]);
        }
        updateClientSlots();
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) BlockComponent(com.lowdragmc.multiblocked.api.block.BlockComponent) ItemStackKey(com.lowdragmc.lowdraglib.utils.ItemStackKey) Direction(net.minecraft.util.Direction) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) Dist(net.minecraftforge.api.distmarker.Dist) Block(net.minecraft.block.Block) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) Map(java.util.Map) StringTextComponent(net.minecraft.util.text.StringTextComponent) NonNullList(net.minecraft.util.NonNullList) BlockState(net.minecraft.block.BlockState) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) LongSet(it.unimi.dsi.fastutil.longs.LongSet) CycleBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.CycleBlockStateRenderer) Collection(java.util.Collection) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) LongSets(it.unimi.dsi.fastutil.longs.LongSets) Set(java.util.Set) Collectors(java.util.stream.Collectors) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Objects(java.util.Objects) Vector3d(net.minecraft.util.math.vector.Vector3d) List(java.util.List) BlockItem(net.minecraft.item.BlockItem) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClickData(com.lowdragmc.lowdraglib.gui.util.ClickData) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) Minecraft(net.minecraft.client.Minecraft) MultiblockShapeInfo(com.lowdragmc.multiblocked.api.pattern.MultiblockShapeInfo) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) BlockPos(net.minecraft.util.math.BlockPos) IGuiTexture(com.lowdragmc.lowdraglib.gui.texture.IGuiTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) ArrayList(java.util.ArrayList) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) ArrayList(java.util.ArrayList) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)

Example 4 with ColorRectTexture

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

the class MultiCapabilityTrait method initSettingDialog.

protected void initSettingDialog(DialogWidget dialog, DraggableWidgetGroup slot, final int index) {
    ImageWidget imageWidget = (ImageWidget) slot.widgets.get(0);
    dialog.addWidget(new SelectorWidget(5, 30, 40, 15, Arrays.stream(IO.VALUES).map(Enum::name).collect(Collectors.toList()), -1).setValue(capabilityIO[index].name()).setOnChanged(io -> {
        capabilityIO[index] = IO.valueOf(io);
        imageWidget.setImage(new GuiTextureGroup(new ColorRectTexture(getColorByIO(guiIO[index])), new ColorBorderTexture(1, getColorByIO(capabilityIO[index]))));
    }).setButtonBackground(ResourceBorderTexture.BUTTON_COMMON).setBackground(new ColorRectTexture(0xffaaaaaa)).setHoverTooltips("multiblocked.gui.trait.capability_io"));
    dialog.addWidget(new SelectorWidget(50, 30, 40, 15, Arrays.stream(IO.VALUES).map(Enum::name).collect(Collectors.toList()), -1).setValue(guiIO[index].name()).setOnChanged(io -> {
        guiIO[index] = IO.valueOf(io);
        imageWidget.setImage(new GuiTextureGroup(new ColorRectTexture(getColorByIO(guiIO[index])), new ColorBorderTexture(1, getColorByIO(capabilityIO[index]))));
    }).setButtonBackground(ResourceBorderTexture.BUTTON_COMMON).setBackground(new ColorRectTexture(0xffaaaaaa)).setHoverTooltips("multiblocked.gui.trait.gui_io"));
    dialog.addWidget(new SelectorWidget(100, 30, 65, 15, Arrays.asList("multiblocked.gui.trait.auto_io", "multiblocked.gui.trait.passive_io"), -1).setValue(autoIO[index] ? "multiblocked.gui.trait.auto_io" : "multiblocked.gui.trait.passive_io").setOnChanged(auto -> autoIO[index] = auto.equals("multiblocked.gui.trait.auto_io")).setButtonBackground(ResourceBorderTexture.BUTTON_COMMON).setBackground(new ColorRectTexture(0xffaaaaaa)).setHoverTooltips("multiblocked.gui.trait.auto"));
}
Also used : ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) SelectorWidget(com.lowdragmc.lowdraglib.gui.widget.SelectorWidget) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup)

Example 5 with ColorRectTexture

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

the class PlayerCapabilityTrait method initSettingDialog.

protected void initSettingDialog(DialogWidget dialog, DraggableWidgetGroup slot) {
    ImageWidget imageWidget = (ImageWidget) slot.widgets.get(0);
    ButtonWidget setting = (ButtonWidget) slot.widgets.get(1);
    dialog.addWidget(new TextFieldWidget(5, 25, 50, 15, null, s -> {
        width = Integer.parseInt(s);
        Size size = new Size(width, height);
        slot.setSize(size);
        imageWidget.setSize(size);
        ((TextTexture) imageWidget.getImage()).setWidth(width);
        setting.setSelfPosition(new Position(width - 8, 0));
    }).setCurrentString(width + "").setNumbersOnly(10, 180).setHoverTooltips("set width"));
    dialog.addWidget(new TextFieldWidget(5, 45, 50, 15, null, s -> {
        height = Integer.parseInt(s);
        Size size = new Size(width, height);
        slot.setSize(size);
        imageWidget.setSize(size);
        setting.setSelfPosition(new Position(width - 8, 0));
    }).setCurrentString(height + "").setNumbersOnly(10, 180).setHoverTooltips("set height"));
    dialog.addWidget(new SelectorWidget(5, 5, 50, 15, Arrays.stream(TextTexture.TextType.values()).map(Enum::name).collect(Collectors.toList()), -1).setValue(textType.name()).setOnChanged(io -> {
        textType = TextTexture.TextType.valueOf(io);
        ((TextTexture) imageWidget.getImage()).setType(textType);
    }).setButtonBackground(ResourceBorderTexture.BUTTON_COMMON).setBackground(new ColorRectTexture(0xffaaaaaa)).setHoverTooltips("TextType"));
}
Also used : Position(com.lowdragmc.lowdraglib.utils.Position) Size(com.lowdragmc.lowdraglib.utils.Size) SelectorWidget(com.lowdragmc.lowdraglib.gui.widget.SelectorWidget) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Aggregations

ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)24 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)18 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)17 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)17 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)13 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)10 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)9 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)9 GuiTextureGroup (com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup)8 SelectorWidget (com.lowdragmc.lowdraglib.gui.widget.SelectorWidget)7 JsonElement (com.google.gson.JsonElement)6 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)6 SelectableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup)6 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)6 ItemStack (net.minecraft.item.ItemStack)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)5 DraggableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableWidgetGroup)5 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)5 List (java.util.List)5