Search in sources :

Example 6 with Interpolator

use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.

the class GuidePageEditorWidget method moveDown.

public void moveDown(Widget widget) {
    int index = stream.indexOf(widget);
    if (index >= 0 && index < stream.size() - 1) {
        Widget target = stream.get(index + 1);
        if (interpolator == null) {
            int offsetD = 5 + target.getSize().height;
            int offsetU = target.getPosition().y - widget.getPosition().y;
            int y1 = widget.getSelfPosition().y;
            int y2 = target.getSelfPosition().y;
            interpolator = new Interpolator(0, 1, 10, Eases.EaseLinear, value -> {
                widget.setSelfPosition(new Position(widget.getSelfPosition().x, (int) (y1 + value.floatValue() * offsetD)));
                target.setSelfPosition(new Position(target.getSelfPosition().x, (int) (y2 - value.floatValue() * offsetU)));
                if (widget == selected) {
                    setToolButton(selected);
                }
                widget.setVisible(widget.getSelfPosition().y < getSize().height - xBarHeight && widget.getSelfPosition().y + widget.getSize().height > 0);
                target.setVisible(target.getSelfPosition().y < getSize().height - xBarHeight && target.getSelfPosition().y + target.getSize().height > 0);
            }, value -> {
                interpolator = null;
                stream.remove(widget);
                stream.add(index + 1, widget);
            }).start();
        }
    } else {
        int index2 = fixed.indexOf(widget);
        if (index2 > 0) {
            Widget target = fixed.get(index2 - 1);
            fixed.remove(widget);
            fixed.add(index2 - 1, widget);
        }
    }
}
Also used : Position(gregtech.api.util.Position) CustomPositionSizeWidget(gregtech.api.terminal.gui.widgets.CustomPositionSizeWidget) Widget(gregtech.api.gui.Widget) GuidePageWidget(gregtech.common.terminal.app.guide.widget.GuidePageWidget) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) IGuideWidget(gregtech.common.terminal.app.guide.widget.IGuideWidget) Interpolator(gregtech.api.util.interpolate.Interpolator)

Example 7 with Interpolator

use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.

the class TerminalMenuWidget method hideMenu.

@SideOnly(Side.CLIENT)
public void hideMenu() {
    if (!isHide && interpolator == null) {
        int y = getSelfPosition().y;
        interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x - getSize().width, 6, Eases.EaseLinear, value -> setSelfPosition(new Position(value.intValue(), y)), value -> {
            setVisible(false);
            interpolator = null;
            isHide = true;
        });
        interpolator.start();
        os.desktop.removeTopWidget(this);
    }
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) SystemCall(gregtech.api.terminal.os.SystemCall) Size(gregtech.api.util.Size) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) WidgetGroup(gregtech.api.gui.widgets.WidgetGroup) Eases(gregtech.api.util.interpolate.Eases) GlStateManager(net.minecraft.client.renderer.GlStateManager) Tuple(net.minecraft.util.Tuple) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) ArrayList(java.util.ArrayList) java.awt(java.awt) Position(gregtech.api.util.Position) Interpolator(gregtech.api.util.interpolate.Interpolator) List(java.util.List) Widget(gregtech.api.gui.Widget) Side(net.minecraftforge.fml.relauncher.Side) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Position(gregtech.api.util.Position) Interpolator(gregtech.api.util.interpolate.Interpolator) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with Interpolator

use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.

the class AppCardWidget method hookDrawInForeground.

@Override
public void hookDrawInForeground(int mouseX, int mouseY) {
    // hover
    int x = getPosition().x;
    int y = getPosition().y;
    int width = getSize().width;
    int height = getSize().height;
    if (isMouseOverElement(mouseX, mouseY) && store.getOs().desktop.widgets.stream().noneMatch(app -> app instanceof TerminalDialogWidget)) {
        int dur = 7;
        // 0-255!!!!!
        int maxAlpha = 100;
        float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
        if (alpha != maxAlpha && interpolator == null) {
            interpolator = new Interpolator(0, maxAlpha, dur, Eases.EaseLinear, value -> alpha = value.intValue(), value -> interpolator = null);
            interpolator.start();
        }
        // smooth
        int color;
        if (alpha == maxAlpha) {
            color = TerminalTheme.COLOR_B_2.getColor() & 0x00ffffff | ((alpha) << 24);
        } else {
            color = TerminalTheme.COLOR_B_2.getColor() & 0x00ffffff | ((alpha + (int) (maxAlpha * partialTicks / dur)) << 24);
        }
        int finalColor = color;
        RenderUtil.useScissor(store.getPosition().x, store.getPosition().y, store.getSize().width, store.getSize().height, () -> {
            drawSolidRect(0, 0, gui.getScreenWidth(), y, finalColor);
            drawSolidRect(0, y + height, gui.getScreenWidth(), gui.getScreenHeight(), finalColor);
            drawSolidRect(0, y, x, height, finalColor);
            drawSolidRect(x + width, y, gui.getScreenWidth(), height, finalColor);
            drawBorder(x, y, width, height, application.getThemeColor(), -1);
        });
    } else {
        alpha = 0;
    }
    super.hookDrawInForeground(mouseX, mouseY);
}
Also used : IRenderContext(gregtech.api.gui.IRenderContext) TerminalOSWidget(gregtech.api.terminal.os.TerminalOSWidget) gregtech.api.gui.resources(gregtech.api.gui.resources) Eases(gregtech.api.util.interpolate.Eases) AnimaWidgetGroup(gregtech.api.terminal.gui.widgets.AnimaWidgetGroup) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) java.awt(java.awt) Interpolator(gregtech.api.util.interpolate.Interpolator) List(java.util.List) GTValues(gregtech.api.GTValues) FontRenderer(net.minecraft.client.gui.FontRenderer) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) RenderUtil(gregtech.client.utils.RenderUtil) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) Shaders(gregtech.client.shader.Shaders) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TerminalBehaviour(gregtech.common.items.behaviors.TerminalBehaviour) PacketBuffer(net.minecraft.network.PacketBuffer) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) Interpolator(gregtech.api.util.interpolate.Interpolator)

Example 9 with Interpolator

use of gregtech.api.util.interpolate.Interpolator 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)

Aggregations

Interpolator (gregtech.api.util.interpolate.Interpolator)9 Position (gregtech.api.util.Position)7 Eases (gregtech.api.util.interpolate.Eases)7 IRenderContext (gregtech.api.gui.IRenderContext)6 CircleButtonWidget (gregtech.api.terminal.gui.widgets.CircleButtonWidget)6 Widget (gregtech.api.gui.Widget)5 Size (gregtech.api.util.Size)5 List (java.util.List)5 GlStateManager (net.minecraft.client.renderer.GlStateManager)5 Side (net.minecraftforge.fml.relauncher.Side)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 WidgetGroup (gregtech.api.gui.widgets.WidgetGroup)4 AbstractApplication (gregtech.api.terminal.app.AbstractApplication)4 TerminalOSWidget (gregtech.api.terminal.os.TerminalOSWidget)4 TerminalTheme (gregtech.api.terminal.os.TerminalTheme)4 java.awt (java.awt)4 IGuiTexture (gregtech.api.gui.resources.IGuiTexture)3 ArrayList (java.util.ArrayList)3 ColorRectTexture (gregtech.api.gui.resources.ColorRectTexture)2 ImageWidget (gregtech.api.gui.widgets.ImageWidget)2