Search in sources :

Example 1 with ButtonWidget

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

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

Example 3 with ButtonWidget

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

the class PlayerCapabilityTrait method refreshSlots.

protected void refreshSlots(DraggableScrollableWidgetGroup dragGroup) {
    dragGroup.widgets.forEach(dragGroup::waitToRemoved);
    ButtonWidget setting = (ButtonWidget) new ButtonWidget(width - 8, 0, 8, 8, new ResourceTexture("multiblocked:textures/gui/option.png"), null).setHoverBorderTexture(1, -1).setHoverTooltips("settings");
    ImageWidget imageWidget = new ImageWidget(0, 0, width, height, new TextTexture("Player Name").setWidth(width).setType(textType).setBackgroundColor(0xff000000));
    setting.setVisible(false);
    DraggableWidgetGroup slot = new DraggableWidgetGroup(x, y, width, height);
    slot.setOnSelected(w -> setting.setVisible(true));
    slot.setOnUnSelected(w -> setting.setVisible(false));
    slot.addWidget(imageWidget);
    slot.addWidget(setting);
    slot.setOnEndDrag(b -> {
        x = b.getSelfPosition().x;
        y = b.getSelfPosition().y;
    });
    dragGroup.addWidget(slot);
    setting.setOnPressCallback(cd2 -> {
        DialogWidget dialog = new DialogWidget(dragGroup, true);
        dialog.addWidget(new ImageWidget(0, 0, 176, 256, new ColorRectTexture(0xaf000000)));
        initSettingDialog(dialog, slot);
    });
}
Also used : ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DraggableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableWidgetGroup) DialogWidget(com.lowdragmc.lowdraglib.gui.widget.DialogWidget) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Example 4 with ButtonWidget

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

the class ItemsContentWidget method updateIngredientWidget.

private void updateIngredientWidget(DraggableScrollableWidgetGroup container) {
    container.widgets.forEach(container::waitToRemoved);
    ItemStack[] matchingStacks = ArrayUtils.clone(content.ingredient.getItems());
    for (int i = 0; i < matchingStacks.length; i++) {
        ItemStack stack = matchingStacks[i];
        IItemHandlerModifiable handler;
        int finalI = i;
        int x = (i % 4) * 30;
        int y = (i / 4) * 20;
        container.addWidget(new PhantomSlotWidget(handler = new ItemStackHandler(1), 0, x + 1, y + 1).setClearSlotOnRightClick(false).setChangeListener(() -> {
            ItemStack newStack = handler.getStackInSlot(0);
            matchingStacks[finalI] = newStack;
            content = new ItemsIngredient(Ingredient.of(matchingStacks), content.getAmount());
            onContentUpdate();
        }).setBackgroundTexture(new ColorRectTexture(0xaf444444)));
        handler.setStackInSlot(0, stack);
        container.addWidget(new ButtonWidget(x + 21, y + 1, 9, 9, cd -> {
            content = new ItemsIngredient(Ingredient.of(ArrayUtils.remove(matchingStacks, finalI)), content.getAmount());
            updateIngredientWidget(container);
            onContentUpdate();
        }).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/remove.png")).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.remove"));
    }
}
Also used : CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) PhantomSlotWidget(com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ItemsIngredient(com.lowdragmc.multiblocked.api.recipe.ItemsIngredient) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ItemStack(net.minecraft.item.ItemStack) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Example 5 with ButtonWidget

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

the class PredicateBlocks method addBlockSelectorWidget.

private void addBlockSelectorWidget(List<BlockState> blockList, DraggableScrollableWidgetGroup container, BlockState blockState) {
    BlockSelectorWidget bsw = new BlockSelectorWidget(0, container.widgets.size() * 21 + 1, false);
    container.addWidget(bsw);
    bsw.addWidget(new ButtonWidget(163, 1, 18, 18, cd -> {
        int index = (bsw.getSelfPosition().y - 1) / 21;
        blockList.remove(index);
        updateStates(blockList);
        for (int i = index + 1; i < container.widgets.size(); i++) {
            container.widgets.get(i).addSelfPosition(0, -21);
        }
        container.waitToRemoved(bsw);
    }).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/remove.png")).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.remove"));
    if (blockState != null) {
        bsw.setBlock(blockState);
    }
    bsw.setOnBlockStateUpdate(state -> {
        int index = (bsw.getSelfPosition().y - 1) / 21;
        blockList.set(index, state);
        updateStates(blockList);
    });
}
Also used : BlockSelectorWidget(com.lowdragmc.lowdraglib.gui.widget.BlockSelectorWidget) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Aggregations

ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)20 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)19 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)15 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)11 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)10 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)10 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)9 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)8 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)6 TextFieldWidget (com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget)6 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 JsonObject (com.google.gson.JsonObject)5 File (java.io.File)5 JsonElement (com.google.gson.JsonElement)4 GuiTextureGroup (com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup)4 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)4 DraggableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableWidgetGroup)4 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)4 IMultiblockedRenderer (com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer)4