Search in sources :

Example 1 with TerminalOSWidget

use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.

the class AppPageWidget method updateTerminalAppTier.

private void updateTerminalAppTier(int tier, int lastTier) {
    TerminalOSWidget os = store.getOs();
    os.openedApps.stream().filter(app -> app.getRegistryName().equals(this.application.getRegistryName())).findFirst().ifPresent(app -> os.closeApplication(app, os.isRemote()));
    if (lastTier == -1) {
        // update terminal
        NBTTagList installed = os.tabletNBT.getTagList("_installed", Constants.NBT.TAG_STRING);
        installed.appendTag(new NBTTagString(application.getRegistryName()));
        os.tabletNBT.setTag("_installed", installed);
        os.installApplication(application);
    }
    NBTTagCompound tag = os.tabletNBT.getCompoundTag(application.getRegistryName());
    tag.setInteger("_tier", tier);
    os.tabletNBT.setTag(application.getRegistryName(), tag);
    lineWidth = 0;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 2 with TerminalOSWidget

use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.

the class AppPageWidget method hookDrawInBackground.

@Override
public void hookDrawInBackground(int mouseX, int mouseY, float partialTicks, IRenderContext context) {
    int x = getPosition().x;
    int y = getPosition().y;
    int width = getSize().width;
    int height = getSize().height;
    GlStateManager.disableDepth();
    drawSolidRect(x, y, width, height, store.darkMode ? 0xcf000000 : 0xdfdddddd);
    super.hookDrawInBackground(mouseX, mouseY, partialTicks, context);
    int stage;
    TerminalOSWidget os = store.getOs();
    if (!os.installedApps.contains(application)) {
        stage = 0;
    } else if (TerminalBehaviour.isCreative(os.itemStack)) {
        stage = application.getMaxTier() + 1;
    } else {
        stage = Math.min(os.tabletNBT.getCompoundTag(application.getRegistryName()).getInteger("_tier"), application.getMaxTier()) + 1;
    }
    int maxStage = application.getMaxTier() + 1;
    int color = application.getThemeColor();
    int lightColor = color & 0x00ffffff | ((0x6f) << 24);
    int dur = 323 / (maxStage + 1);
    int hover = -1;
    for (int i = 0; i < buttons.length; i++) {
        if (buttons[i].isMouseOverElement(mouseX, mouseY)) {
            hover = i;
        }
    }
    // draw current tier
    drawSolidRect(x, y + 110 - 2, dur * stage, 4, color);
    if (stage == maxStage) {
        drawSolidRect(x + stage * dur, y + 110 - 2, dur, 4, color);
    } else {
        drawSolidRect(x + stage * dur, y + 110 - 2, dur, 4, lightColor);
    }
    int end = dur * (hover + 1 - stage);
    if (hover + 1 > stage) {
        if (lineWidth != end && (interpolator == null || back)) {
            back = false;
            interpolator = new Interpolator(lineWidth, end, (end - lineWidth) / 15, Eases.EaseLinear, value -> lineWidth = value.intValue(), value -> interpolator = null);
            interpolator.start();
        }
    } else {
        if (lineWidth != 0 && (interpolator == null || !back)) {
            back = true;
            interpolator = new Interpolator(lineWidth, 0, lineWidth / 15, Eases.EaseLinear, value -> lineWidth = value.intValue(), value -> interpolator = null);
            interpolator.start();
        }
    }
    if (lineWidth != 0) {
        int smoothWidth = lineWidth;
        if (hover + 1 > stage) {
            if (lineWidth != end) {
                smoothWidth += partialTicks * end / 10;
            }
        } else {
            smoothWidth -= partialTicks * end / 10;
        }
        drawSolidRect(x + stage * dur, y + 110 - 2, smoothWidth, 4, color);
    }
    // description
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    List<String> description = fr.listFormattedStringToWidth(application.getDescription(), 210);
    int fColor = store.darkMode ? -1 : 0xff333333;
    String localizedName = I18n.format(application.getUnlocalizedName());
    drawStringSized(localizedName, x + 100, y + 14, fColor, store.darkMode, 2, false);
    if (isMouseOver(x + 100, y + 14, fr.getStringWidth(localizedName) * 2, fr.FONT_HEIGHT * 2, mouseX, mouseY)) {
        drawHoveringText(ItemStack.EMPTY, Collections.singletonList("(" + application.getRegistryName() + ")"), 200, mouseX, mouseY);
    }
    for (int i = 0; i < description.size(); i++) {
        fr.drawString(description.get(i), x + 100, y + 35 + i * fr.FONT_HEIGHT, fColor, store.darkMode);
    }
    drawBorder(x + 10, y + 15, 80, 80, store.darkMode ? -1 : 0xff333333, 2);
    GlStateManager.enableDepth();
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) Eases(gregtech.api.util.interpolate.Eases) Constants(net.minecraftforge.common.util.Constants) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) NBTTagString(net.minecraft.nbt.NBTTagString) ImageWidget(gregtech.api.gui.widgets.ImageWidget) ArrayList(java.util.ArrayList) TerminalRegistry(gregtech.api.terminal.TerminalRegistry) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Minecraft(net.minecraft.client.Minecraft) TerminalBehaviour(gregtech.common.items.behaviors.TerminalBehaviour) SlotWidget(gregtech.api.gui.widgets.SlotWidget) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GlStateManager(net.minecraft.client.renderer.GlStateManager) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) Collectors(java.util.stream.Collectors) GuiTextures(gregtech.api.gui.GuiTextures) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) Interpolator(gregtech.api.util.interpolate.Interpolator) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) SingleItemStackHandler(gregtech.common.inventory.handlers.SingleItemStackHandler) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) Collections(java.util.Collections) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) Interpolator(gregtech.api.util.interpolate.Interpolator) FontRenderer(net.minecraft.client.gui.FontRenderer) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 3 with TerminalOSWidget

use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.

the class AppPageWidget method buttonClicked.

private void buttonClicked(int tier) {
    int lastTier;
    TerminalOSWidget os = store.getOs();
    if (!os.installedApps.contains(application)) {
        lastTier = -1;
    } else if (TerminalBehaviour.isCreative(os.itemStack)) {
        lastTier = application.getMaxTier();
    } else {
        lastTier = Math.min(os.tabletNBT.getCompoundTag(application.getRegistryName()).getInteger("_tier"), application.getMaxTier());
    }
    String name = application.getRegistryName();
    if (tier > lastTier) {
        // inventory match
        boolean match = true;
        List<ItemStack> requirements = new ArrayList<>();
        ItemStack missStack = null;
        if (!gui.entityPlayer.isCreative()) {
            for (int i = lastTier + 1; i <= tier; i++) {
                for (ItemStack condition : TerminalRegistry.getAppHardwareUpgradeConditions(name, i)) {
                    boolean miss = true;
                    for (ItemStack requirement : requirements) {
                        if (requirement.isItemEqual(condition)) {
                            requirement.setCount(requirement.getCount() + condition.getCount());
                            miss = false;
                            break;
                        }
                    }
                    if (miss) {
                        requirements.add(condition.copy());
                    }
                }
            }
            for (ItemStack requirement : requirements) {
                int left = requirement.getCount();
                for (ItemStack hold : gui.entityPlayer.inventory.mainInventory) {
                    if (requirement.isItemEqual(hold)) {
                        if (hold.getCount() < left) {
                            left -= hold.getCount();
                        } else {
                            left = 0;
                        }
                        if (left == 0) {
                            break;
                        }
                    }
                }
                if (left > 0) {
                    missStack = requirement.copy();
                    missStack.setCount(left);
                    match = false;
                    break;
                }
            }
        }
        if (match) {
            if (os.isRemote()) {
                appCardWidget.updateState(tier == application.getMaxTier() ? 0 : 1);
            }
            if (!gui.entityPlayer.isCreative()) {
                // cost
                TerminalDialogWidget.showConfirmDialog(store.getOs(), "terminal.dialog.notice", "terminal.store.match", res -> {
                    if (res) {
                        for (ItemStack requirement : requirements) {
                            int left = requirement.getCount();
                            for (ItemStack hold : gui.entityPlayer.inventory.mainInventory) {
                                if (requirement.isItemEqual(hold)) {
                                    if (hold.getCount() <= left) {
                                        hold.setCount(0);
                                        left -= hold.getCount();
                                    } else {
                                        hold.setCount(hold.getCount() - left);
                                        left = 0;
                                    }
                                    if (left == 0) {
                                        break;
                                    }
                                }
                            }
                        }
                        updateTerminalAppTier(tier, lastTier);
                    }
                }).open();
            } else {
                updateTerminalAppTier(tier, lastTier);
            }
        } else {
            if (isRemote()) {
                TerminalDialogWidget.showInfoDialog(store.getOs(), "terminal.dialog.notice", I18n.format("terminal.store.miss", missStack.getDisplayName(), missStack.getCount())).setClientSide().open();
            }
        }
    }
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) Eases(gregtech.api.util.interpolate.Eases) Constants(net.minecraftforge.common.util.Constants) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) NBTTagString(net.minecraft.nbt.NBTTagString) ImageWidget(gregtech.api.gui.widgets.ImageWidget) ArrayList(java.util.ArrayList) TerminalRegistry(gregtech.api.terminal.TerminalRegistry) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Minecraft(net.minecraft.client.Minecraft) TerminalBehaviour(gregtech.common.items.behaviors.TerminalBehaviour) SlotWidget(gregtech.api.gui.widgets.SlotWidget) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GlStateManager(net.minecraft.client.renderer.GlStateManager) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) Collectors(java.util.stream.Collectors) GuiTextures(gregtech.api.gui.GuiTextures) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) Interpolator(gregtech.api.util.interpolate.Interpolator) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) SingleItemStackHandler(gregtech.common.inventory.handlers.SingleItemStackHandler) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) Collections(java.util.Collections) ArrayList(java.util.ArrayList) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TerminalOSWidget (gregtech.api.terminal.os.TerminalOSWidget)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 NBTTagString (net.minecraft.nbt.NBTTagString)3 GuiTextures (gregtech.api.gui.GuiTextures)2 IRenderContext (gregtech.api.gui.IRenderContext)2 ColorRectTexture (gregtech.api.gui.resources.ColorRectTexture)2 IGuiTexture (gregtech.api.gui.resources.IGuiTexture)2 ImageWidget (gregtech.api.gui.widgets.ImageWidget)2 SlotWidget (gregtech.api.gui.widgets.SlotWidget)2 TerminalRegistry (gregtech.api.terminal.TerminalRegistry)2 AbstractApplication (gregtech.api.terminal.app.AbstractApplication)2 CircleButtonWidget (gregtech.api.terminal.gui.widgets.CircleButtonWidget)2 TerminalDialogWidget (gregtech.api.terminal.os.TerminalDialogWidget)2 TerminalTheme (gregtech.api.terminal.os.TerminalTheme)2 Eases (gregtech.api.util.interpolate.Eases)2 Interpolator (gregtech.api.util.interpolate.Interpolator)2 SingleItemStackHandler (gregtech.common.inventory.handlers.SingleItemStackHandler)2 TerminalBehaviour (gregtech.common.items.behaviors.TerminalBehaviour)2 ArrayList (java.util.ArrayList)2