Search in sources :

Example 1 with GuiEventListener

use of net.minecraft.client.gui.components.events.GuiEventListener in project BuildingGadgets by Direwolf20-MC.

the class ModeRadialMenu method render.

@Override
public void render(PoseStack matrices, int mx, int my, float partialTicks) {
    float stime = 5F;
    float fract = Math.min(stime, this.timeIn + partialTicks) / stime;
    int x = this.width / 2;
    int y = this.height / 2;
    int radiusMin = 26;
    int radiusMax = 60;
    double dist = new Vec3(x, y, 0).distanceTo(new Vec3(mx, my, 0));
    boolean inRange = false;
    if (this.segments != 0) {
        inRange = dist > radiusMin && dist < radiusMax;
        for (GuiEventListener button : children()) {
            if (button instanceof PositionedIconActionable) {
                ((PositionedIconActionable) button).setFaded(inRange);
            }
        }
    }
    // This triggers the animation on creation
    matrices.pushPose();
    matrices.translate((1 - fract) * x, (1 - fract) * y, 0);
    matrices.scale(fract, fract, fract);
    super.render(matrices, mx, my, partialTicks);
    matrices.popPose();
    if (this.segments == 0) {
        return;
    }
    float angle = mouseAngle(x, y, mx, my);
    float totalDeg = 0;
    float degPer = 360F / this.segments;
    List<NameDisplayData> nameData = new ArrayList<>();
    ItemStack tool = this.getGadget();
    if (tool.isEmpty()) {
        return;
    }
    this.slotSelected = -1;
    List<ResourceLocation> signs;
    int modeIndex;
    if (tool.getItem() instanceof GadgetBuilding) {
        modeIndex = GadgetBuilding.getToolMode(tool).ordinal();
        signs = Arrays.stream(BuildingModes.values()).map(e -> new ResourceLocation(Reference.MODID, e.getIcon())).collect(Collectors.toList());
    } else if (tool.getItem() instanceof GadgetExchanger) {
        modeIndex = GadgetExchanger.getToolMode(tool).ordinal();
        signs = Arrays.stream(ExchangingModes.values()).map(e -> new ResourceLocation(Reference.MODID, e.getIcon())).collect(Collectors.toList());
    } else {
        modeIndex = GadgetCopyPaste.getToolMode(tool).ordinal();
        signs = signsCopyPaste;
    }
    boolean shouldCenter = (this.segments + 2) % 4 == 0;
    int indexBottom = this.segments / 4;
    int indexTop = indexBottom + this.segments / 2;
    for (int seg = 0; seg < this.segments; seg++) {
        boolean mouseInSector = this.isCursorInSlice(angle, totalDeg, degPer, inRange);
        float radius = Math.max(0F, Math.min((this.timeIn + partialTicks - seg * 6F / this.segments) * 40F, radiusMax));
        float gs = 0.25F;
        if (seg % 2 == 0) {
            gs += 0.1F;
        }
        float r = gs;
        float g = gs + (seg == modeIndex ? 1F : 0.0F);
        float b = gs;
        float a = 0.4F;
        if (mouseInSector) {
            this.slotSelected = seg;
            r = g = b = 1F;
        }
        MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource();
        VertexConsumer buffer = bufferSource.getBuffer(OurRenderTypes.TRIANGLE_STRIP);
        for (float i = degPer; i >= 0; i--) {
            float rad = (float) ((i + totalDeg) / 180F * Math.PI);
            float xp = (float) (x + Math.cos(rad) * radius);
            float yp = (float) (y + Math.sin(rad) * radius);
            if ((int) i == (int) (degPer / 2))
                nameData.add(new NameDisplayData((int) xp, (int) yp, mouseInSector, shouldCenter && (seg == indexBottom || seg == indexTop)));
            Matrix4f pose = matrices.last().pose();
            buffer.vertex(pose, (float) (x + Math.cos(rad) * radius / 2.3F), (float) (y + Math.sin(rad) * radius / 2.3F), 0).color(r, g, b, a).endVertex();
            buffer.vertex(xp, yp, 0).color(r, g, b, a).endVertex();
        }
        bufferSource.endBatch(OurRenderTypes.TRIANGLE_STRIP);
        totalDeg += degPer;
    }
    // This is the naming logic for the text that pops up
    for (int i = 0; i < nameData.size(); i++) {
        matrices.pushPose();
        NameDisplayData data = nameData.get(i);
        int xp = data.getX();
        int yp = data.getY();
        String name;
        if (tool.getItem() instanceof GadgetBuilding) {
            name = ForgeI18n.getPattern(BuildingModes.values()[i].getTranslationKey());
        } else if (tool.getItem() instanceof GadgetExchanger) {
            name = ForgeI18n.getPattern(ExchangingModes.values()[i].getTranslationKey());
        } else {
            name = GadgetCopyPaste.ToolMode.values()[i].getTranslation().format();
        }
        int xsp = xp - 4;
        int ysp = yp;
        int width = font.width(name);
        if (xsp < x) {
            xsp -= width - 8;
        }
        if (ysp < y) {
            ysp -= 9;
        }
        Color color = i == modeIndex ? Color.GREEN : Color.WHITE;
        if (data.isSelected())
            font.drawShadow(matrices, name, xsp + (data.isCentralized() ? width / 2f - 4 : 0), ysp, color.getRGB());
        double mod = 0.7;
        int xdp = (int) ((xp - x) * mod + x);
        int ydp = (int) ((yp - y) * mod + y);
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 1);
        RenderSystem.setShaderTexture(0, signs.get(i));
        blit(matrices, xdp - 8, ydp - 8, 0, 0, 16, 16, 16, 16);
        matrices.popPose();
    }
    float s = 1.8F * fract;
    PoseStack stack = RenderSystem.getModelViewStack();
    stack.pushPose();
    stack.scale(s, s, s);
    matrices.popPose();
    stack.translate(x / s - (tool.getItem() instanceof GadgetCopyPaste ? 8 : 8.5), y / s - 8, 0);
    this.itemRenderer.renderAndDecorateItem(tool, 0, 0);
    stack.popPose();
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Arrays(java.util.Arrays) InputConstants(com.mojang.blaze3d.platform.InputConstants) com.direwolf20.buildinggadgets.common.network.packets(com.direwolf20.buildinggadgets.common.network.packets) KeyBindings(com.direwolf20.buildinggadgets.client.KeyBindings) Item(net.minecraft.world.item.Item) Styles(com.direwolf20.buildinggadgets.common.util.lang.Styles) Matrix4f(com.mojang.math.Matrix4f) BuildingModes(com.direwolf20.buildinggadgets.common.items.modes.BuildingModes) GadgetUtils(com.direwolf20.buildinggadgets.common.util.GadgetUtils) GuiSliderInt(com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt) RadialTranslation(com.direwolf20.buildinggadgets.common.util.lang.RadialTranslation) MessageTranslation(com.direwolf20.buildinggadgets.common.util.lang.MessageTranslation) PoseStack(com.mojang.blaze3d.vertex.PoseStack) ArrayList(java.util.ArrayList) OurRenderTypes(com.direwolf20.buildinggadgets.client.renderer.OurRenderTypes) Config(com.direwolf20.buildinggadgets.common.config.Config) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) Button(net.minecraft.client.gui.components.Button) GameRenderer(net.minecraft.client.renderer.GameRenderer) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) Screen(net.minecraft.client.gui.screens.Screen) PacketHandler(com.direwolf20.buildinggadgets.common.network.PacketHandler) Collectors(java.util.stream.Collectors) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) java.awt(java.awt) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Reference(com.direwolf20.buildinggadgets.common.util.ref.Reference) Vec3(net.minecraft.world.phys.Vec3) ExchangingModes(com.direwolf20.buildinggadgets.common.items.modes.ExchangingModes) GuiIconActionable(com.direwolf20.buildinggadgets.client.screen.components.GuiIconActionable) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) KeyMapping(net.minecraft.client.KeyMapping) ForgeI18n(net.minecraftforge.common.ForgeI18n) com.direwolf20.buildinggadgets.common.items(com.direwolf20.buildinggadgets.common.items) ItemStack(net.minecraft.world.item.ItemStack) Mth(net.minecraft.util.Mth) OurSounds(com.direwolf20.buildinggadgets.client.OurSounds) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) GuiTranslation(com.direwolf20.buildinggadgets.common.util.lang.GuiTranslation) PoseStack(com.mojang.blaze3d.vertex.PoseStack) ArrayList(java.util.ArrayList) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) Vec3(net.minecraft.world.phys.Vec3) ResourceLocation(net.minecraft.resources.ResourceLocation) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Matrix4f(com.mojang.math.Matrix4f) GameRenderer(net.minecraft.client.renderer.GameRenderer) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with GuiEventListener

use of net.minecraft.client.gui.components.events.GuiEventListener in project BuildingGadgets by Direwolf20-MC.

the class ModeRadialMenu method updateButtons.

private void updateButtons(ItemStack tool) {
    int posRight = 0;
    int posLeft = 0;
    int dim = 24;
    int padding = 10;
    boolean isDestruction = tool.getItem() instanceof GadgetDestruction;
    ScreenPosition right = isDestruction ? ScreenPosition.BOTTOM : ScreenPosition.RIGHT;
    for (GuiEventListener widget : children()) {
        if (!(widget instanceof PositionedIconActionable))
            continue;
        PositionedIconActionable button = (PositionedIconActionable) widget;
        if (!button.visible) {
            continue;
        }
        int offset;
        boolean isRight = button.position == right;
        if (isRight) {
            posRight += dim + padding;
            offset = 70;
        } else {
            posLeft += dim + padding;
            offset = -70 - dim;
        }
        button.setWidth(dim);
        button.setHeight(dim);
        if (isDestruction)
            button.y = height / 2 + (isRight ? 10 : -button.getHeight() - 10);
        else
            button.x = width / 2 + offset;
    }
    posRight = resetPos(tool, padding, posRight);
    posLeft = resetPos(tool, padding, posLeft);
    for (GuiEventListener widget : children()) {
        if (!(widget instanceof PositionedIconActionable))
            continue;
        PositionedIconActionable button = (PositionedIconActionable) widget;
        if (!button.visible) {
            continue;
        }
        boolean isRight = button.position == right;
        int pos = isRight ? posRight : posLeft;
        if (isDestruction) {
            button.x = pos;
        } else {
            button.y = pos;
        }
        if (isRight) {
            posRight += dim + padding;
        } else {
            posLeft += dim + padding;
        }
    }
}
Also used : GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener)

Example 3 with GuiEventListener

use of net.minecraft.client.gui.components.events.GuiEventListener in project TAS-Battle by MCPfannkuchenYT.

the class TASBattleScreen method init.

/**
 * Adds all TASBattle Widgets
 */
@Override
protected void init() {
    int x = 5;
    for (int i = 0; i < TASBattle.servers.size(); i++) {
        int FUCKYOUJAVAIWILLKILLYOU = i;
        btns.add(addRenderableWidget(new Button(x, 35, 20, 20, new TextComponent(""), b -> {
            for (GuiEventListener btnl : new ArrayList<>(children())) if (btns.contains(btnl))
                ((Button) btnl).active = true;
            b.active = false;
            /* Add Labels */
            selected = TASBattle.servers.get(FUCKYOUJAVAIWILLKILLYOU);
        }) {

            ResourceLocation loc = new ResourceLocation("textures/" + TASBattle.servers.get(FUCKYOUJAVAIWILLKILLYOU).item + ".png");

            @Override
            public void renderButton(PoseStack poseStack, int i, int j, float f) {
                super.renderButton(poseStack, i, j, f);
                if (this.isHovered()) {
                    this.renderToolTip(poseStack, i, j);
                }
                // how to draw image 101
                RenderSystem.setShader(GameRenderer::getPositionTexShader);
                RenderSystem.setShaderTexture(0, loc);
                RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
                RenderSystem.enableBlend();
                RenderSystem.defaultBlendFunc();
                RenderSystem.enableDepthTest();
                RenderSystem.enableTexture();
                blit(poseStack, x + 2, y + 2, 0, 0, 16, 16, 16, 16);
            }
        }));
        x += 20;
    }
    addRenderableWidget(new Button(5, height - 30, 250, 20, new TextComponent("Connect to the server"), b -> {
        ConnectScreen.startConnecting(this, minecraft, new ServerAddress("mgnet.work", 25567), new ServerData("asd", "mgnet.work:25567", false));
    }));
    addRenderableWidget(new Button(255, height - 30, width - 260, 20, new TextComponent("Connect to the anarchy server"), b -> {
        ConnectScreen.startConnecting(this, minecraft, new ServerAddress("mgnet.work", 25568), new ServerData("asd", "mgnet.work:25568", false));
    }));
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ServerData(net.minecraft.client.multiplayer.ServerData) ResourceLocation(net.minecraft.resources.ResourceLocation) GlStateManager(com.mojang.blaze3d.platform.GlStateManager) GuiComponent(net.minecraft.client.gui.GuiComponent) GameRenderer(net.minecraft.client.renderer.GameRenderer) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) Screen(net.minecraft.client.gui.screens.Screen) DefaultVertexFormat(com.mojang.blaze3d.vertex.DefaultVertexFormat) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) TASBattle(de.pfannekuchen.tasbattle.TASBattle) List(java.util.List) Tesselator(com.mojang.blaze3d.vertex.Tesselator) TASServer(de.pfannekuchen.tasbattle.TASBattle.TASServer) TextComponent(net.minecraft.network.chat.TextComponent) ConnectScreen(net.minecraft.client.gui.screens.ConnectScreen) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ServerAddress(net.minecraft.client.multiplayer.resolver.ServerAddress) Button(net.minecraft.client.gui.components.Button) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Button(net.minecraft.client.gui.components.Button) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) GameRenderer(net.minecraft.client.renderer.GameRenderer) ServerAddress(net.minecraft.client.multiplayer.resolver.ServerAddress) ServerData(net.minecraft.client.multiplayer.ServerData) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener)

Example 4 with GuiEventListener

use of net.minecraft.client.gui.components.events.GuiEventListener in project Cyclic by Lothrazar.

the class ScreenBase method drawButtonTooltips.

public void drawButtonTooltips(PoseStack ms, int mouseX, int mouseY) {
    for (GuiEventListener btn : this.children()) {
        if (btn instanceof IHasTooltip && btn.isMouseOver(mouseX, mouseY) && btn instanceof AbstractWidget) {
            ((AbstractWidget) btn).renderToolTip(ms, mouseX, mouseY);
            List<Component> localTooltip = ((IHasTooltip) btn).getTooltip();
            if (localTooltip != null) {
                this.renderComponentTooltip(ms, localTooltip, mouseX - leftPos, mouseY - topPos);
            }
        }
    }
    for (GuiEventListener widget : this.children()) {
        if (widget instanceof IHasTooltip && widget.isMouseOver(mouseX, mouseY)) {
            IHasTooltip txt = (IHasTooltip) widget;
            if (txt.getTooltip() != null) {
                this.renderComponentTooltip(ms, txt.getTooltip(), mouseX - leftPos, mouseY - topPos);
            }
        }
    }
}
Also used : GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) IHasTooltip(com.lothrazar.cyclic.api.IHasTooltip) AbstractWidget(net.minecraft.client.gui.components.AbstractWidget) Component(net.minecraft.network.chat.Component)

Example 5 with GuiEventListener

use of net.minecraft.client.gui.components.events.GuiEventListener in project RoughlyEnoughItems by shedaniel.

the class DraggableWidget method mouseDragged.

@Override
public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
    Point mouse = PointHelper.ofMouse();
    if (int_1 == 0) {
        if (!dragged) {
            if (getGrabBounds().contains(mouse)) {
                startPoint = new Point(midPoint.x, midPoint.y);
                relateX = mouse.x - midPoint.x;
                relateY = mouse.y - midPoint.y;
                dragged = true;
            }
        } else {
            Window window = minecraft.getWindow();
            midPoint = processMidPoint(midPoint, mouse, startPoint, window, relateX, relateY);
            updateWidgets(midPoint);
        }
        return true;
    }
    for (GuiEventListener listener : children()) if (listener.mouseDragged(double_1, double_2, int_1, double_3, double_4))
        return true;
    return false;
}
Also used : Window(com.mojang.blaze3d.platform.Window) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) Point(me.shedaniel.math.Point)

Aggregations

GuiEventListener (net.minecraft.client.gui.components.events.GuiEventListener)15 PoseStack (com.mojang.blaze3d.vertex.PoseStack)4 Point (me.shedaniel.math.Point)4 Minecraft (net.minecraft.client.Minecraft)4 TextComponent (net.minecraft.network.chat.TextComponent)4 InputConstants (com.mojang.blaze3d.platform.InputConstants)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Button (net.minecraft.client.gui.components.Button)3 Screen (net.minecraft.client.gui.screens.Screen)3 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)2 GameRenderer (net.minecraft.client.renderer.GameRenderer)2 Component (net.minecraft.network.chat.Component)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Mth (net.minecraft.util.Mth)2 KeyBindings (com.direwolf20.buildinggadgets.client.KeyBindings)1 OurSounds (com.direwolf20.buildinggadgets.client.OurSounds)1 OurRenderTypes (com.direwolf20.buildinggadgets.client.renderer.OurRenderTypes)1 GuiIconActionable (com.direwolf20.buildinggadgets.client.screen.components.GuiIconActionable)1 GuiSliderInt (com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt)1