Search in sources :

Example 6 with DraggableScrollableWidgetGroup

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

the class ItemsContentWidget method openConfigurator.

@Override
public void openConfigurator(WidgetGroup dialog) {
    super.openConfigurator(dialog);
    int x = 5;
    int y = 25;
    dialog.addWidget(new LabelWidget(5, y + 3, "multiblocked.gui.label.amount"));
    dialog.addWidget(new TextFieldWidget(125 - 60, y, 60, 15, null, number -> {
        content = content.isTag() ? new ItemsIngredient(content.getTag(), Integer.parseInt(number)) : new ItemsIngredient(content.ingredient, Integer.parseInt(number));
        onContentUpdate();
    }).setNumbersOnly(1, Integer.MAX_VALUE).setCurrentString(content.getAmount() + ""));
    TextFieldWidget tag;
    WidgetGroup groupOre = new WidgetGroup(x, y + 40, 120, 80);
    WidgetGroup groupIngredient = new WidgetGroup(x, y + 20, 120, 80);
    DraggableScrollableWidgetGroup container = new DraggableScrollableWidgetGroup(0, 20, 120, 50).setBackground(new ColorRectTexture(0xffaaaaaa));
    groupIngredient.addWidget(container);
    dialog.addWidget(groupIngredient);
    dialog.addWidget(groupOre);
    groupOre.addWidget(tag = new TextFieldWidget(30, 3, 90, 15, () -> content.isTag() ? content.getTag() : "", null).setResourceLocationOnly());
    IItemHandlerModifiable handler;
    PhantomSlotWidget phantomSlotWidget = new PhantomSlotWidget(handler = new ItemStackHandler(1), 0, 0, 1).setClearSlotOnRightClick(false);
    groupOre.addWidget(phantomSlotWidget);
    phantomSlotWidget.setChangeListener(() -> {
        ItemStack newStack = handler.getStackInSlot(0);
        if (newStack.isEmpty())
            return;
        ITagCollection<Item> tags = TagCollectionManager.getInstance().getItems();
        Collection<ResourceLocation> ids = tags.getMatchingTags(newStack.getItem());
        if (ids.size() > 0) {
            String tagString = ids.stream().findAny().get().toString();
            content = new ItemsIngredient(tagString, content.getAmount());
            tag.setCurrentString(tagString);
            phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ": " + ids.stream().map(ResourceLocation::toString).reduce("", (a, b) -> a + "\n" + b));
        } else {
            content = new ItemsIngredient("", content.getAmount());
            tag.setCurrentString("");
            handler.setStackInSlot(0, ItemStack.EMPTY);
        }
        onContentUpdate();
    }).setBackgroundTexture(new ColorRectTexture(0xaf444444));
    tag.setTextResponder(tagS -> {
        content = new ItemsIngredient(tagS, content.getAmount());
        ItemStack[] matches = content.ingredient.getItems();
        handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
        phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ":\n" + content.getTag());
        onContentUpdate();
    });
    tag.setHoverTooltips("multiblocked.gui.trait.item.ore_dic");
    dialog.addWidget(new SwitchWidget(x, y + 22, 50, 15, (cd, r) -> {
        groupOre.setVisible(r);
        content = r ? new ItemsIngredient(tag.getCurrentString(), content.getAmount()) : new ItemsIngredient(content.ingredient, content.getAmount());
        groupIngredient.setVisible(!r);
        if (r) {
            ItemStack[] matches = content.ingredient.getItems();
            handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
            phantomSlotWidget.setHoverTooltips("oreDict: \n" + content.getTag());
        } else {
            updateIngredientWidget(container);
        }
        onContentUpdate();
    }).setPressed(content.isTag()).setHoverBorderTexture(1, -1).setBaseTexture(ResourceBorderTexture.BUTTON_COMMON, new TextTexture("tag (N)")).setPressedTexture(ResourceBorderTexture.BUTTON_COMMON, new TextTexture("tag (Y)")).setHoverTooltips("using tag dictionary"));
    groupIngredient.setVisible(!content.isTag());
    groupOre.setVisible(content.isTag());
    if (content.isTag()) {
        ItemStack[] matches = content.ingredient.getItems();
        handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
        phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ":\n" + content.getTag());
    } else {
        updateIngredientWidget(container);
    }
    groupIngredient.addWidget(new LabelWidget(x + 50, 5, "multiblocked.gui.tips.settings"));
    groupIngredient.addWidget(new ButtonWidget(100, 0, 20, 20, cd -> {
        ItemStack[] stacks = content.ingredient.getItems();
        content = new ItemsIngredient(Ingredient.of(ArrayUtils.add(stacks, new ItemStack(Items.IRON_INGOT))), content.getAmount());
        updateIngredientWidget(container);
        onContentUpdate();
    }).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/add.png")).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.trait.item.add"));
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) Arrays(java.util.Arrays) TagCollectionManager(net.minecraft.tags.TagCollectionManager) LocalizationUtils(com.lowdragmc.lowdraglib.utils.LocalizationUtils) Item(net.minecraft.item.Item) ItemsIngredient(com.lowdragmc.multiblocked.api.recipe.ItemsIngredient) ArrayUtils(org.apache.commons.lang3.ArrayUtils) PhantomSlotWidget(com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ContentWidget(com.lowdragmc.multiblocked.api.gui.recipe.ContentWidget) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) Collection(java.util.Collection) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) Items(net.minecraft.item.Items) Collectors(java.util.stream.Collectors) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ITagCollection(net.minecraft.tags.ITagCollection) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Collections(java.util.Collections) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) PhantomSlotWidget(com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) ItemsIngredient(com.lowdragmc.multiblocked.api.recipe.ItemsIngredient) ResourceLocation(net.minecraft.util.ResourceLocation) ITagCollection(net.minecraft.tags.ITagCollection) Collection(java.util.Collection) ITagCollection(net.minecraft.tags.ITagCollection) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) ItemStack(net.minecraft.item.ItemStack)

Example 7 with DraggableScrollableWidgetGroup

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

the class MBDIModelRenderer method createConfigurator.

@Override
public Supplier<IMultiblockedRenderer> createConfigurator(WidgetGroup parent, DraggableScrollableWidgetGroup group, IMultiblockedRenderer current) {
    TextFieldWidget tfw = new TextFieldWidget(1, 1, 150, 20, null, null);
    group.addWidget(tfw);
    File path = new File(Multiblocked.location, "assets/multiblocked/models");
    group.addWidget(new ButtonWidget(155, 1, 20, 20, cd -> DialogWidget.showFileDialog(parent, "select a java model", path, true, DialogWidget.suffixFilter(".json"), r -> {
        if (r != null && r.isFile()) {
            tfw.setCurrentString("multiblocked:" + r.getPath().replace(path.getPath(), "").substring(1).replace(".json", "").replace('\\', '/'));
        }
    })).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/darkened_slot.png"), new TextTexture("F", -1)).setHoverTooltips("multiblocked.gui.tips.file_selector"));
    if (current instanceof IModelRenderer && ((IModelRenderer) current).modelLocation != null) {
        tfw.setCurrentString(((IModelRenderer) current).modelLocation.toString());
    }
    return () -> {
        if (tfw.getCurrentString().isEmpty()) {
            return null;
        } else {
            return new MBDIModelRenderer(new ResourceLocation(tfw.getCurrentString()));
        }
    };
}
Also used : JsonObject(com.google.gson.JsonObject) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) IModelRenderer(com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer) Supplier(java.util.function.Supplier) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) File(java.io.File) DialogWidget(com.lowdragmc.lowdraglib.gui.widget.DialogWidget) Gson(com.google.gson.Gson) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) IModelRenderer(com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer) File(java.io.File) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Example 8 with DraggableScrollableWidgetGroup

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

the class TemplateBuilderWidget method readInitialData.

@Override
public void readInitialData(PacketBuffer buffer) {
    super.readInitialData(buffer);
    this.addWidget(containers = new DraggableScrollableWidgetGroup(200, 120, 150, 98));
    containers.setClientSideWidget();
    for (int i = buffer.readVarInt(); i > 0; i--) {
        ItemStack itemStack = buffer.readItem();
        int slotIndex = buffer.readVarInt();
        containers.addWidget(new SelectableWidgetGroup(0, containers.widgets.size() * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(w -> onSelected(itemStack, slotIndex)).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(itemStack.getDisplayName().getString()).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(itemStack))));
    }
}
Also used : ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) ItemStack(net.minecraft.item.ItemStack) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint)

Example 9 with DraggableScrollableWidgetGroup

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

the class MultiCapabilityTrait method openConfigurator.

@Override
public void openConfigurator(WidgetGroup parentDialog) {
    DraggableScrollableWidgetGroup dragGroup = new DraggableScrollableWidgetGroup((384 - 176) / 2, 0, 176, 256);
    parentDialog.addWidget(dragGroup);
    refreshSlots(dragGroup);
    // add new slot
    parentDialog.addWidget(new ButtonWidget((384 - 176) / 2 - 20, 35, 20, 20, new ResourceTexture("multiblocked:textures/gui/add.png"), cd -> {
        addSlot();
        refreshSlots(dragGroup);
    }).setHoverTooltips("multiblocked.gui.trait.add_slot"));
}
Also used : DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Aggregations

DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)9 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)6 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)6 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)5 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)4 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)4 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)3 TextFieldWidget (com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget)3 BlockState (net.minecraft.block.BlockState)3 ItemStack (net.minecraft.item.ItemStack)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)2 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)2 IMultiblockedRenderer (com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer)2 File (java.io.File)2 Collections (java.util.Collections)2 List (java.util.List)2 Supplier (java.util.function.Supplier)2 ResourceLocation (net.minecraft.util.ResourceLocation)2