Search in sources :

Example 11 with TranslationButton

use of mekanism.client.gui.element.button.TranslationButton in project Mekanism by mekanism.

the class GuiPortableTeleporter method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiTeleporterStatus(this, () -> getFrequency() != null, menu::getStatus));
    addButton(new GuiVerticalPowerBar(this, new IBarInfoHandler() {

        @Override
        public ITextComponent getTooltip() {
            IEnergyContainer container = StorageUtils.getEnergyContainer(menu.getStack(), 0);
            return container == null ? EnergyDisplay.ZERO.getTextComponent() : EnergyDisplay.of(container).getTextComponent();
        }

        @Override
        public double getLevel() {
            IEnergyContainer container = StorageUtils.getEnergyContainer(menu.getStack(), 0);
            return container == null ? 0 : container.getEnergy().divideToLevel(container.getMaxEnergy());
        }
    }, 158, 26));
    teleportButton = addButton(new TranslationButton(this, 42, 147, 92, 20, MekanismLang.BUTTON_TELEPORT, () -> {
        TeleporterFrequency frequency = getFrequency();
        if (frequency != null && menu.getStatus() == 1) {
            // This should always be true if the teleport button is active, but validate it just in case
            ClientTickHandler.portableTeleport(getMinecraft().player, menu.getHand(), frequency.getIdentity());
            getMinecraft().player.closeContainer();
        } else {
            // If something did go wrong make the teleport button not able to be pressed
            teleportButton.active = false;
        }
    }));
    // Teleporter button starts as deactivated until we have a frequency get synced
    teleportButton.active = false;
    addButton(new GuiFrequencySelector<>(this, 14));
}
Also used : IBarInfoHandler(mekanism.client.gui.element.bar.GuiBar.IBarInfoHandler) IEnergyContainer(mekanism.api.energy.IEnergyContainer) TranslationButton(mekanism.client.gui.element.button.TranslationButton) TeleporterFrequency(mekanism.common.content.teleporter.TeleporterFrequency) GuiTeleporterStatus(mekanism.client.gui.element.custom.GuiTeleporterStatus) GuiVerticalPowerBar(mekanism.client.gui.element.bar.GuiVerticalPowerBar)

Aggregations

TranslationButton (mekanism.client.gui.element.button.TranslationButton)11 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)6 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)5 PacketGuiInteract (mekanism.common.network.to_server.PacketGuiInteract)5 ITextComponent (net.minecraft.util.text.ITextComponent)5 Nonnull (javax.annotation.Nonnull)4 GuiElementHolder (mekanism.client.gui.element.GuiElementHolder)4 GuiInnerScreen (mekanism.client.gui.element.GuiInnerScreen)4 MekanismLang (mekanism.common.MekanismLang)4 PlayerInventory (net.minecraft.entity.player.PlayerInventory)4 List (java.util.List)3 GuiVerticalPowerBar (mekanism.client.gui.element.bar.GuiVerticalPowerBar)3 MekanismImageButton (mekanism.client.gui.element.button.MekanismImageButton)3 ArrayList (java.util.ArrayList)2 GuiDigitalSwitch (mekanism.client.gui.element.GuiDigitalSwitch)2 IBarInfoHandler (mekanism.client.gui.element.bar.GuiBar.IBarInfoHandler)2 FilterButton (mekanism.client.gui.element.button.FilterButton)2 GuiProgress (mekanism.client.gui.element.progress.GuiProgress)2 GuiModuleScrollList (mekanism.client.gui.element.scroll.GuiModuleScrollList)2 GuiScrollBar (mekanism.client.gui.element.scroll.GuiScrollBar)2