Android Open Source - TinyVoxel G U I






From Project

Back to project page TinyVoxel.

License

The source code is released under:

GNU General Public License

If you think the Android project TinyVoxel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.toet.TinyVoxel.Screens;
/* w  w w  .  j  a  va 2  s  .  co m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.*;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.*;
import com.toet.TinyVoxel.Debug.LogHandler;

/**
 * Created by Kajos on 9/7/2014.
 */
public class GUI {
    public Stage stage;
    protected Viewport viewport;
    protected static GUI INSTANCE;

    protected static BitmapFont font;
    protected static TextButton.TextButtonStyle textButtonStyle;
    protected static TextButton.TextButtonStyle textButtonStyle2;

    protected static Label.LabelStyle labelStyle;
    protected static SelectBox.SelectBoxStyle selectBoxStyle;
    protected static CheckBox.CheckBoxStyle checkBoxStyle;

    protected static NinePatchDrawable ninePatch;
    protected static NinePatchDrawable ninePatch2;
    protected static Texture texture;
    protected static Texture texture2;

    protected final static int MAX_LABELS = 15;
    protected Label[] labels = new Label[MAX_LABELS];


    public static GUI get() {
        if (INSTANCE == null)
            INSTANCE = new GUI();

        return INSTANCE;
    }

    public void addToMultiplexer(InputMultiplexer multiplexer) {
        multiplexer.addProcessor(stage);
    }
    public void removeFromMultiplexer(InputMultiplexer multiplexer) {
        multiplexer.removeProcessor(stage);
    }

    private static NinePatch processNinePatchFile(Texture t) {
        final int width = t.getWidth() - 2;
        final int height = t.getHeight() - 2;
        return new NinePatch(new TextureRegion(t, 1, 1, width, height), 8, 8, 8, 8);
    }

    private static boolean isLoaded = false;
    public static void load() {
        if (isLoaded)
            return;

        isLoaded = true;

        font = new BitmapFont(Gdx.files.internal("font/Foobar Pro-Regular-32.fnt"));
        font.setScale(.6f, .6f);
        Skin prepSkin = new Skin();

        // Store the default libgdx font under the name "default".
        prepSkin.add("default", font);

        texture = new Texture(Gdx.files.internal("textures/np.png"));
        texture2 = new Texture(Gdx.files.internal("textures/np2.png"));
        ninePatch = new NinePatchDrawable(processNinePatchFile(texture));
        ninePatch2 = new NinePatchDrawable(processNinePatchFile(texture2));

        checkBoxStyle = new CheckBox.CheckBoxStyle();
        checkBoxStyle.font = prepSkin.getFont("default");
        checkBoxStyle.checkboxOff = ninePatch;
        checkBoxStyle.checkboxOn = ninePatch2;

        textButtonStyle = new TextButton.TextButtonStyle(ninePatch, ninePatch, ninePatch, prepSkin.getFont("default"));
        textButtonStyle.downFontColor = Color.GRAY;
        textButtonStyle.fontColor = Color.WHITE;
        textButtonStyle.overFontColor = Color.BLACK;
        textButtonStyle.font = prepSkin.getFont("default");
        prepSkin.add("default", textButtonStyle);

        textButtonStyle2 = new TextButton.TextButtonStyle(ninePatch2, ninePatch2, ninePatch2, prepSkin.getFont("default"));
        textButtonStyle2.downFontColor = Color.GRAY;
        textButtonStyle2.fontColor = Color.WHITE;
        textButtonStyle2.overFontColor = Color.BLACK;
        textButtonStyle2.font = prepSkin.getFont("default");

        ScrollPane.ScrollPaneStyle scrollPaneStyle = new ScrollPane.ScrollPaneStyle(ninePatch, ninePatch2, ninePatch2, ninePatch2, ninePatch2);
        List.ListStyle listStyle = new List.ListStyle(prepSkin.getFont("default"), Color.BLACK, Color.WHITE, ninePatch2);

        selectBoxStyle = new SelectBox.SelectBoxStyle(prepSkin.getFont("default"), Color.WHITE, ninePatch, scrollPaneStyle, listStyle);
        prepSkin.add("default", selectBoxStyle);

        labelStyle = new Label.LabelStyle();
        labelStyle.font = prepSkin.getFont("default");
        labelStyle.fontColor = Color.WHITE;
        prepSkin.add("default", labelStyle);
    }

    public GUI() {
        load();

        viewport = new StretchViewport(1000,1000);
        stage = new Stage(viewport);
    }

    public Image addPalette(int x, int y, Pixmap palette, InputListener clickListener) {
        Image image = new Image(new Texture(palette));
        image.setPosition(x, y);
        image.addListener(clickListener);
        stage.addActor(image);
        return image;
    }

    public Image addImage(String filename, int x, int y, int width, int height) {
        Image image = new Image(new Texture(Gdx.files.internal(filename)));
        image.setPosition(x, y);
        image.setWidth(width);
        image.setHeight(height);
        image.setOrigin(width / 2, height / 2);
        stage.addActor(image);
        return image;
    }

    public SelectBox addSelectBox(int x, int y, Array items) {
        final SelectBox box = new SelectBox(selectBoxStyle);
        box.setItems(items);
        box.setWidth(150f);
        box.setPosition(x, y);
        stage.addActor(box);
        return box;
    }

    public CheckBox addCheckBox(int x, int y, String text) {
        final CheckBox box = new CheckBox(" "+text, checkBoxStyle);
        box.setPosition(x, y);
        stage.addActor(box);
        return box;
    }

    public TextButton addButton(String name, int x, int y, InputListener clickListener) {
        TextButton button = new TextButton(name, textButtonStyle);
        button.setPosition(x, y);
        button.setTransform(true);
        button.addListener(clickListener);
        button.pad(0);
        stage.addActor(button);
        return button;
    }

    public ImageButton addImageButton(String file, int x, int y, int width, int height, InputListener clickListener) {
        Texture tex = new Texture(Gdx.files.internal(file));
        Drawable draw = new TextureRegionDrawable(new TextureRegion(tex));
        ImageButton button = new ImageButton(draw);
        button.setOrigin(width / 2, height / 2);
        button.setWidth(width);
        button.setHeight(height);
        button.setPosition(x, y);
        button.setTransform(true);
        button.addListener(clickListener);
        button.pad(0);
        stage.addActor(button);
        return button;
    }

    public TextButton addButtonOther(String name, int x, int y, InputListener clickListener) {
        TextButton button = new TextButton(name, textButtonStyle2);
        button.setPosition(x, y);
        button.setTransform(true);
        button.addListener(clickListener);
        button.pad(0);
        stage.addActor(button);
        return button;
    }

    public Label setLabel(int id, String name, int x, int y) {
        if (id >= MAX_LABELS) {
            LogHandler.log("Not enough space for labels!");
            return null;
        }

        Label label = labels[id];
        if (label == null) {
            label = new Label(name, labelStyle);
            label.setPosition(x, y);
            labels[id] = label;
            stage.addActor(label);
            enableLabel(id);
        } else {
            label.setPosition(x,y);
            label.setText(name);
            enableLabel(id);
        }

        return label;
    }

    public void enableLabel(int id) {
        if (labels[id] != null) {
            labels[id].setVisible(true);
        }
    }

    public void disableLabel(int id) {
        if (labels[id] != null) {
            labels[id].setVisible(false);
        }
    }

    public boolean render() {
        stage.act();
        stage.draw();
        return true;
    }

    public void resize(int width, int height) {
        viewport.update(width, height, false);
    }
}




Java Source Code List

com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration.java
com.badlogic.gdx.backends.gwt.GwtApplication.java
com.badlogic.gdx.backends.gwt.GwtGL20.java
com.badlogic.gdx.backends.gwt.GwtInput.java
com.badlogic.gdx.backends.gwt.GwtNet.java
com.badlogic.gdx.graphics.Pixmap.java
com.toet.TinyVoxel.Config.java
com.toet.TinyVoxel.Game.java
com.toet.TinyVoxel.IOSConfig.java
com.toet.TinyVoxel.IOSLauncher.java
com.toet.TinyVoxel.OuyaController.java
com.toet.TinyVoxel.Time.java
com.toet.TinyVoxel.Character.Character.java
com.toet.TinyVoxel.Debug.LogHandler.java
com.toet.TinyVoxel.GameControllers.CharacterController.java
com.toet.TinyVoxel.GameControllers.CustomTouchPad.java
com.toet.TinyVoxel.GameControllers.KeyBoardController.java
com.toet.TinyVoxel.GameControllers.TouchPadController.java
com.toet.TinyVoxel.Importer.BinvoxImporter.java
com.toet.TinyVoxel.Importer.DataInputStream.java
com.toet.TinyVoxel.Importer.MeshImporter.java
com.toet.TinyVoxel.Renderer.BlockBuilder.java
com.toet.TinyVoxel.Renderer.Floor.java
com.toet.TinyVoxel.Renderer.Manager.java
com.toet.TinyVoxel.Renderer.Bundles.ArrayBundle.java
com.toet.TinyVoxel.Renderer.Bundles.Bundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridBundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridInterface.java
com.toet.TinyVoxel.Renderer.Bundles.Grid.java
com.toet.TinyVoxel.Renderer.Bundles.GroundBundle.java
com.toet.TinyVoxel.Renderer.Bundles.SingleBundle.java
com.toet.TinyVoxel.Renderer.Bundles.TinyGrid.java
com.toet.TinyVoxel.Renderer.Tools.BrushUtils.java
com.toet.TinyVoxel.Renderer.Tools.GridUtils.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedBoolean.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedInteger.java
com.toet.TinyVoxel.Screens.GUI.java
com.toet.TinyVoxel.Screens.Menu.java
com.toet.TinyVoxel.Shaders.ShaderManager.java
com.toet.TinyVoxel.Shadow.ShadowManager.java
com.toet.TinyVoxel.Util.Box.java
com.toet.TinyVoxel.Util.FullscreenQuad.java
com.toet.TinyVoxel.Util.JobManager.java
com.toet.TinyVoxel.Util.NonBackedTexture.java
com.toet.TinyVoxel.Util.Position.java
com.toet.TinyVoxel.Util.RLEInputStream.java
com.toet.TinyVoxel.Util.RLEOutputStream.java
com.toet.TinyVoxel.Util.SimpleMath.java
com.toet.TinyVoxel.Util.StreamUtil.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.client.GwtConfig.java
com.toet.TinyVoxel.client.HtmlLauncher.java
com.toet.TinyVoxel.desktop.DesktopConfig.java
com.toet.TinyVoxel.desktop.DesktopLauncher.java