Example usage for com.badlogic.gdx.scenes.scene2d.ui SvgSkin SvgSkin

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui SvgSkin SvgSkin

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui SvgSkin SvgSkin.

Prototype

public SvgSkin(boolean forceCreateNewAtlas, String name, StorageType storageType, FileHandle skinFolder) 

Source Link

Document

Create a Skin from given Jason-file!

Usage

From source file:de.longri.cachebox3.gui.stages.initial_tasks.SkinLoaderTask.java

License:Open Source License

@Override
public void runnable() {

    //initial sizes
    DevicesSizes ui = new DevicesSizes();
    ui.Window = new SizeF(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ui.Density = CB.getScalefactor();/*from  w w w  .ja  va2 s. c om*/
    ui.isLandscape = false;

    String skinName = null;
    SvgSkin.StorageType storageType = null;
    FileHandle skinFileHandle = null;

    //Get selected skin name and check if available
    if (Settings.nightMode.getValue()) {
        if (!Settings.nightSkinName.isDefault()) {
            // check if skin exist into skin folder
            FileHandle skinFolder = Gdx.files.absolute(Settings.SkinFolder.getValue());
            if (skinFolder.exists()) {
                FileHandle skin = skinFolder.child(Settings.nightSkinName.getValue());
                if (skin.exists()) {
                    skinName = Settings.nightSkinName.getValue();
                    storageType = SvgSkin.StorageType.LOCAL;
                    skinFileHandle = skin;
                }
            }
        }

        if (skinName == null) {
            // use default internal night skin
            skinName = Settings.nightSkinName.getDefaultValue();
            storageType = SvgSkin.StorageType.INTERNAL;
            skinFileHandle = Gdx.files.internal("skins/night");
        }
    } else {
        if (!Settings.daySkinName.isDefault()) {
            // check if skin exist into skin folder
            FileHandle skinFolder = Gdx.files.absolute(Settings.SkinFolder.getValue());
            if (skinFolder.exists()) {
                FileHandle skin = skinFolder.child(Settings.daySkinName.getValue());
                if (skin.exists()) {
                    skinName = Settings.daySkinName.getValue();
                    storageType = SvgSkin.StorageType.LOCAL;
                    skinFileHandle = skin;
                }
            }
        }

        if (skinName == null) {
            // use default internal day skin
            skinName = Settings.daySkinName.getDefaultValue();
            storageType = SvgSkin.StorageType.INTERNAL;
            skinFileHandle = Gdx.files.internal("skins/day");
        }
    }

    // the SvgSkin must create in a OpenGL context. so we post a runnable and wait!
    final AtomicBoolean wait = new AtomicBoolean(true);

    final String finalSkinName = skinName;
    final SvgSkin.StorageType finalType = storageType;
    final FileHandle finalSkinFileHandle = skinFileHandle;
    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run() {
            CB.setActSkin(new SvgSkin(false, finalSkinName, finalType, finalSkinFileHandle));
            CB.backgroundColor = CB.getColor("background");
            wait.set(false);
        }
    });

    while (wait.get()) {
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
        }
    }

    //add myLocationModel to skin
    SvgSkin skin = CB.getSkin();
    skin.add("MyLocationModel", myLocationModel, Model.class);
    skin.add("compassModel", compassModel, Model.class);
    skin.add("compassGrayModel", compassGrayModel, Model.class);
    skin.add("compassYellowModel", compassYellowModel, Model.class);
}