Download BnnWidget — Minecraft Mods — MetaMods

BnnWidget

Active

Downloads

0

Last update

6 years ago
Client
Libraries

BnnWidget - Library for Creating Animated Interfaces in Minecraft

BnnWidget is a specialized library that is part of the SignPicture mod and provides developers with a powerful toolkit for creating dynamic graphical interfaces with minimal effort.

Key Features

Simplified Animation - Built-in animation system with smooth transition support allows bringing interface elements to life without complex programming.

Intuitive Coordinate System - Relative positioning eliminates the need for complex mathematical calculations to determine element coordinates.

Flexible Architecture - Modular library structure ensures ease of functionality extension and creation of custom components.

Usage Example

import javax.annotation.Nonnull;
import net.teamfruit.bnnwidget.WBase;
import net.teamfruit.bnnwidget.WEvent;
import net.teamfruit.bnnwidget.WFrame;
import net.teamfruit.bnnwidget.WPanel;
import net.teamfruit.bnnwidget.WRenderer;
import net.teamfruit.bnnwidget.motion.Easings;
import net.teamfruit.bnnwidget.position.Area;
import net.teamfruit.bnnwidget.position.Point;
import net.teamfruit.bnnwidget.position.R;
import net.teamfruit.bnnwidget.render.OpenGL;
import net.teamfruit.bnnwidget.var.V;
import net.teamfruit.bnnwidget.var.VMotion;

// Main interface class extends WFrame
public class MyGui extends WFrame {
    // Widget initialization in initWidget method
    @Override
    protected void initWidget() {
        // Adding panel that extends WPanel
        add(new WPanel(new R()) {
            @Override
            protected void initWidget() {
                // Class R defines relative positioning area
                add(new WBase(new R()) {
                    // VMotion represents animated value
                    VMotion m = V.pm(0);

                    @Override
                    public void draw(final @Nonnull WEvent ev, final @Nonnull Area pgp, final @Nonnull Point p, final float frame, final float opacity) {
                        // Preparation for rendering
                        WRenderer.startShape();
                        // OpenGL wrapper for compatibility between Minecraft versions
                        // Value from class V is obtained by get() method
                        OpenGL.glColor4f(0f, 0f, 0f, this.m.get());
                        // Drawing with detailed positioning
                        draw(getGuiPosition(pgp));
                    }

                    private boolean mouseinside;

                    @Override
                    public void update(final @Nonnull WEvent ev, final @Nonnull Area pgp, final @Nonnull Point p) {
                        // Getting widget area relative to parent
                        final Area a = getGuiPosition(pgp);
                        // Checking if cursor is over widget
                        if (a.pointInside(p)) {
                            if (!this.mouseinside) {
                                this.mouseinside = true;
                                // Starting animation on hover
                                this.m.stop().add(Easings.easeLinear.move(.2f, 0f)).start();
                            }
                        } else if (this.mouseinside) {
                            this.mouseinside = false;
                            // Starting animation when cursor leaves
                            this.m.stop().add(Easings.easeLinear.move(.2f, .5f)).start();
                        }
                        super.update(ev, pgp, p);
                    }

                    // Handling interface close request
                    @Override
                    public boolean onCloseRequest() {
                        // Starting close animation
                        this.m.stop().add(Easings.easeLinear.move(.25f, 0f)).start();
                        return false;
                    }

                    // Checking animation completion before closing
                    @Override
                    public boolean onClosing(final @Nonnull WEvent ev, final @Nonnull Area pgp, final @Nonnull Point mouse) {
                        return this.m.isFinished();
                    }
                });
            }
        });
    }
}

Frequently Asked Questions

Bug Reports and Suggestions - If you find a bug or have ideas for improving the library, you can leave your comments in the appropriate section.

Usage in Modifications - BnnWidget is distributed under the MIT license, allowing free use of the library in your own projects and modifications.

Development Participation - The library source code is open for anyone wishing to contribute to the project development by adding new features or fixing errors.

Project members
Kamesuta

Kamesuta

Created: 17 Feb 2019

ID: 37011