Search in sources :

Example 1 with GuiScrollBar

use of mekanism.client.gui.element.scroll.GuiScrollBar in project Mekanism by mekanism.

the class GuiQIOFilterHandler method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiQIOFrequencyTab(this, tile));
    addButton(new GuiInnerScreen(this, 9, 16, imageWidth - 18, 12, () -> {
        List<ITextComponent> list = new ArrayList<>();
        QIOFrequency freq = tile.getQIOFrequency();
        if (freq == null) {
            list.add(MekanismLang.NO_FREQUENCY.translate());
        } else {
            list.add(MekanismLang.FREQUENCY.translate(freq.getKey()));
        }
        return list;
    }).tooltip(() -> {
        List<ITextComponent> list = new ArrayList<>();
        QIOFrequency freq = tile.getQIOFrequency();
        if (freq != null) {
            list.add(MekanismLang.QIO_ITEMS_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemCount()), TextUtils.format(freq.getTotalItemCountCapacity())));
            list.add(MekanismLang.QIO_TYPES_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemTypes(true)), TextUtils.format(freq.getTotalItemTypeCapacity())));
        }
        return list;
    }));
    // Filter holder
    addButton(new GuiElementHolder(this, 9, 30, 144, 68));
    // new filter button border
    addButton(new GuiElementHolder(this, 9, 98, 144, 22));
    addButton(new TranslationButton(this, 10, 99, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(new GuiQIOFilerSelect(this, tile))));
    scrollBar = addButton(new GuiScrollBar(this, 153, 30, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
    // Add each of the buttons and then just change visibility state to match filter info
    for (int i = 0; i < FILTER_COUNT; i++) {
        addButton(new MovableFilterButton(this, 10, 31 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, index -> {
            if (index > 0) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_UP, tile, index));
            }
        }, index -> {
            if (index < tile.getFilters().size() - 1) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_DOWN, tile, index));
            }
        }, this::onClick, filter -> {
            List<ItemStack> list = new ArrayList<>();
            if (filter != null) {
                if (filter instanceof IItemStackFilter) {
                    list.add(((IItemStackFilter<?>) filter).getItemStack());
                } else if (filter instanceof ITagFilter) {
                    String name = ((ITagFilter<?>) filter).getTagName();
                    if (name != null && !name.isEmpty()) {
                        list.addAll(TagCache.getItemTagStacks(((ITagFilter<?>) filter).getTagName()));
                    }
                } else if (filter instanceof IModIDFilter) {
                    list.addAll(TagCache.getModIDStacks(((IModIDFilter<?>) filter).getModID(), false));
                }
            }
            return list;
        }));
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) TextUtils(mekanism.common.util.text.TextUtils) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) QIOTagFilter(mekanism.common.content.qio.filter.QIOTagFilter) GuiQIOTagFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOTagFilter) ArrayList(java.util.ArrayList) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) GuiQIOFrequencyTab(mekanism.client.gui.element.tab.GuiQIOFrequencyTab) QIOFrequency(mekanism.common.content.qio.QIOFrequency) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) Nonnull(javax.annotation.Nonnull) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TileEntityQIOFilterHandler(mekanism.common.tile.qio.TileEntityQIOFilterHandler) TranslationButton(mekanism.client.gui.element.button.TranslationButton) Mekanism(mekanism.common.Mekanism) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiQIOItemStackFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOItemStackFilter) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) List(java.util.List) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) IModIDFilter(mekanism.common.content.filter.IModIDFilter) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) GuiInteraction(mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction) QIOModIDFilter(mekanism.common.content.qio.filter.QIOModIDFilter) MekanismLang(mekanism.common.MekanismLang) IFilter(mekanism.common.content.filter.IFilter) GuiQIOModIDFilter(mekanism.client.gui.element.window.filter.qio.GuiQIOModIDFilter) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) TagCache(mekanism.common.base.TagCache) TranslationButton(mekanism.client.gui.element.button.TranslationButton) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) GuiQIOFrequencyTab(mekanism.client.gui.element.tab.GuiQIOFrequencyTab) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) ArrayList(java.util.ArrayList) List(java.util.List) IModIDFilter(mekanism.common.content.filter.IModIDFilter) QIOFrequency(mekanism.common.content.qio.QIOFrequency)

Example 2 with GuiScrollBar

use of mekanism.client.gui.element.scroll.GuiScrollBar in project Mekanism by mekanism.

the class GuiFilterHolder method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiInnerScreen(this, 9, 17, 46, 140));
    // Filter holder
    addButton(new GuiElementHolder(this, 55, 17, 98, 118));
    // new filter button border
    addButton(new GuiElementHolder(this, 55, 135, 98, 22));
    scrollBar = addButton(new GuiScrollBar(this, 153, 17, 140, () -> getFilters().size(), () -> FILTER_COUNT));
    // Add each of the buttons and then just change visibility state to match filter info
    for (int i = 0; i < FILTER_COUNT; i++) {
        addFilterButton(new MovableFilterButton(this, 56, 18 + i * 29, i, scrollBar::getCurrentSelection, this::getFilters, index -> {
            if (index > 0) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_UP, tile, index));
            }
        }, index -> {
            if (index < getFilters().size() - 1) {
                Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_DOWN, tile, index));
            }
        }, this::onClick, filter -> {
            List<ItemStack> list = new ArrayList<>();
            if (filter != null) {
                if (filter instanceof IItemStackFilter) {
                    list.add(((IItemStackFilter<?>) filter).getItemStack());
                } else if (filter instanceof ITagFilter) {
                    list.addAll(getTagStacks(((ITagFilter<?>) filter).getTagName()));
                } else if (filter instanceof IMaterialFilter) {
                    list.addAll(TagCache.getMaterialStacks(((IMaterialFilter<?>) filter).getMaterialItem()));
                } else if (filter instanceof IModIDFilter) {
                    list.addAll(TagCache.getModIDStacks(((IModIDFilter<?>) filter).getModID(), false));
                }
            }
            return list;
        }));
    }
}
Also used : GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) FilterButton(mekanism.client.gui.element.button.FilterButton) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) ITileFilterHolder(mekanism.common.tile.interfaces.ITileFilterHolder) ItemStack(net.minecraft.item.ItemStack) HashList(mekanism.common.lib.collection.HashList) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) Nonnull(javax.annotation.Nonnull) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Mekanism(mekanism.common.Mekanism) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) List(java.util.List) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) IModIDFilter(mekanism.common.content.filter.IModIDFilter) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) GuiInteraction(mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction) IFilter(mekanism.common.content.filter.IFilter) TagCache(mekanism.common.base.TagCache) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) MovableFilterButton(mekanism.client.gui.element.button.MovableFilterButton) ITagFilter(mekanism.common.content.filter.ITagFilter) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) ArrayList(java.util.ArrayList) HashList(mekanism.common.lib.collection.HashList) List(java.util.List) IModIDFilter(mekanism.common.content.filter.IModIDFilter)

Example 3 with GuiScrollBar

use of mekanism.client.gui.element.scroll.GuiScrollBar in project Mekanism by mekanism.

the class GuiFissionReactorLogicAdapter method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiElementHolder(this, 16, 31, 130, 90));
    scrollBar = addButton(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT));
    for (int i = 0; i < DISPLAY_COUNT; i++) {
        int typeShift = 22 * i;
        addButton(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, type -> {
            if (type == null) {
                return;
            }
            MekanismGenerators.packetHandler.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
        }));
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) MekanismGenerators(mekanism.generators.common.MekanismGenerators) ReactorLogicButton(mekanism.generators.client.gui.element.button.ReactorLogicButton) TileEntityFissionReactorLogicAdapter(mekanism.generators.common.tile.fission.TileEntityFissionReactorLogicAdapter) EmptyTileContainer(mekanism.common.inventory.container.tile.EmptyTileContainer) ITextComponent(net.minecraft.util.text.ITextComponent) GeneratorsLang(mekanism.generators.common.GeneratorsLang) MekanismLang(mekanism.common.MekanismLang) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) Nonnull(javax.annotation.Nonnull) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) PacketGeneratorsGuiInteract(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract) GeneratorsGuiInteraction(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract.GeneratorsGuiInteraction) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) PacketGeneratorsGuiInteract(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract)

Example 4 with GuiScrollBar

use of mekanism.client.gui.element.scroll.GuiScrollBar in project Mekanism by mekanism.

the class GuiFusionReactorLogicAdapter method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiElementHolder(this, 16, 31, 130, 90));
    addButton(new ToggleButton(this, 16, 19, 11, tile::isActiveCooled, () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.NEXT_MODE, tile)), getOnHover(GeneratorsLang.REACTOR_LOGIC_TOGGLE_COOLING)));
    scrollBar = addButton(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT));
    for (int i = 0; i < DISPLAY_COUNT; i++) {
        int typeShift = 22 * i;
        addButton(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, scrollBar::getCurrentSelection, tile::getModes, type -> {
            if (type == null) {
                return;
            }
            MekanismGenerators.packetHandler.sendToServer(new PacketGeneratorsGuiInteract(GeneratorsGuiInteraction.LOGIC_TYPE, tile, type.ordinal()));
        }));
    }
}
Also used : Mekanism(mekanism.common.Mekanism) EnumColor(mekanism.api.text.EnumColor) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) OnOff(mekanism.common.util.text.BooleanStateDisplay.OnOff) MekanismGenerators(mekanism.generators.common.MekanismGenerators) ToggleButton(mekanism.client.gui.element.button.ToggleButton) ReactorLogicButton(mekanism.generators.client.gui.element.button.ReactorLogicButton) EmptyTileContainer(mekanism.common.inventory.container.tile.EmptyTileContainer) ITextComponent(net.minecraft.util.text.ITextComponent) GeneratorsLang(mekanism.generators.common.GeneratorsLang) GuiInteraction(mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction) MekanismLang(mekanism.common.MekanismLang) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) Nonnull(javax.annotation.Nonnull) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) PacketGeneratorsGuiInteract(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract) TileEntityFusionReactorLogicAdapter(mekanism.generators.common.tile.fusion.TileEntityFusionReactorLogicAdapter) GeneratorsGuiInteraction(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract.GeneratorsGuiInteraction) ToggleButton(mekanism.client.gui.element.button.ToggleButton) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) PacketGeneratorsGuiInteract(mekanism.generators.common.network.to_server.PacketGeneratorsGuiInteract)

Example 5 with GuiScrollBar

use of mekanism.client.gui.element.scroll.GuiScrollBar in project Mekanism by mekanism.

the class GuiOredictionificator method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    // Filter holder
    addButton(new GuiElementHolder(this, 9, 17, 144, 68));
    // new filter button border
    addButton(new GuiElementHolder(this, 9, 85, 144, 22));
    scrollBar = addButton(new GuiScrollBar(this, 153, 17, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
    addButton(new GuiProgress(() -> tile.didProcess, ProgressType.LARGE_RIGHT, this, 64, 119));
    addButton(new TranslationButton(this, 10, 86, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(GuiOredictionificatorFilter.create(this, tile))));
    // Add each of the buttons and then just change visibility state to match filter info
    for (int i = 0; i < FILTER_COUNT; i++) {
        addButton(new FilterButton(this, 10, 18 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, this::onClick, filter -> {
            if (filter instanceof OredictionificatorItemFilter) {
                return Collections.singletonList(((OredictionificatorItemFilter) filter).getResult());
            }
            return Collections.emptyList();
        })).warning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, filter -> filter != null && !filter.hasFilter());
    }
    // While we track and show warnings on the slots themselves we also need to track the warning
    // for if any of the set filters have it even if one of them is not visible
    // Note: We add this after all the buttons have their warnings added so that it is further down the tracker
    // so the tracker can short circuit on this type of warning and not have to check all the filters if one of
    // the ones that are currently being shown has the warning
    trackWarning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, () -> tile.getFilters().stream().anyMatch(filter -> !filter.hasFilter()));
}
Also used : TranslationButton(mekanism.client.gui.element.button.TranslationButton) GuiOredictionificatorFilter(mekanism.client.gui.element.window.filter.GuiOredictionificatorFilter) GuiProgress(mekanism.client.gui.element.progress.GuiProgress) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) FilterButton(mekanism.client.gui.element.button.FilterButton) GuiConfigurableTile(mekanism.client.gui.GuiConfigurableTile) ITextComponent(net.minecraft.util.text.ITextComponent) WarningType(mekanism.client.gui.warning.WarningTracker.WarningType) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter) ProgressType(mekanism.client.gui.element.progress.ProgressType) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) MekanismLang(mekanism.common.MekanismLang) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) IFilter(mekanism.common.content.filter.IFilter) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationButton(mekanism.client.gui.element.button.TranslationButton) GuiProgress(mekanism.client.gui.element.progress.GuiProgress) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) FilterButton(mekanism.client.gui.element.button.FilterButton) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter)

Aggregations

GuiScrollBar (mekanism.client.gui.element.scroll.GuiScrollBar)6 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)5 Nonnull (javax.annotation.Nonnull)5 GuiElementHolder (mekanism.client.gui.element.GuiElementHolder)5 PlayerInventory (net.minecraft.entity.player.PlayerInventory)5 ITextComponent (net.minecraft.util.text.ITextComponent)5 MekanismLang (mekanism.common.MekanismLang)4 EnumColor (mekanism.api.text.EnumColor)3 GuiMekanismTile (mekanism.client.gui.GuiMekanismTile)3 GuiInnerScreen (mekanism.client.gui.element.GuiInnerScreen)3 Mekanism (mekanism.common.Mekanism)3 IFilter (mekanism.common.content.filter.IFilter)3 MekanismTileContainer (mekanism.common.inventory.container.tile.MekanismTileContainer)3 PacketGuiInteract (mekanism.common.network.to_server.PacketGuiInteract)3 GuiInteraction (mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FilterButton (mekanism.client.gui.element.button.FilterButton)2 MovableFilterButton (mekanism.client.gui.element.button.MovableFilterButton)2 TranslationButton (mekanism.client.gui.element.button.TranslationButton)2