Search in sources :

Example 11 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.

the class Skin method add.

public void add(String name, Object resource, Class type) {
    if (name == null)
        throw new IllegalArgumentException("name cannot be null.");
    if (resource == null)
        throw new IllegalArgumentException("resource cannot be null.");
    ObjectMap<String, Object> typeResources = resources.get(type);
    if (typeResources == null) {
        typeResources = new ObjectMap(type == TextureRegion.class || type == Drawable.class || type == Sprite.class ? 256 : 64);
        resources.put(type, typeResources);
    }
    typeResources.put(name, resource);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ObjectMap(com.badlogic.gdx.utils.ObjectMap) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)

Example 12 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project ProjektGG by eskalon.

the class LoadingScreen method onFinishedLoading.

@Override
protected void onFinishedLoading() {
    BitmapFont main19Font = assetManager.get(MAIN_FONT_19_PATH());
    BitmapFont main22Font = assetManager.get(MAIN_FONT_22_PATH());
    BitmapFont letter20Font = assetManager.get(LETTER_FONT_20_PATH());
    BitmapFont handwritten20Font = assetManager.get(HANDWRITTEN_FONT_20_PATH());
    ObjectMap<String, Object> fontMap = new ObjectMap<String, Object>();
    fontMap.put("main-19", main19Font);
    fontMap.put("main-22", main22Font);
    fontMap.put("letter-20", letter20Font);
    fontMap.put("handwritten-20", handwritten20Font);
    assetManager.load(SKIN_PATH, Skin.class, new SkinLoader.SkinParameter(SKIN_TEXTURE_ATLAS_PATH, fontMap));
    assetManager.finishLoadingAsset(SKIN_PATH);
    // game.setUISkin(assetManager.get(SKIN_PATH));
    VisUI.load();
    game.setUISkin(VisUI.getSkin());
    // Notify loaded screens
    game.getScreen("mainMenu").finishLoading();
    game.getScreen("serverBrowser").finishLoading();
    game.getScreen("lobby").finishLoading();
    game.getScreen("lobbyCreation").finishLoading();
    game.pushScreen("mainMenu");
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SkinLoader(com.badlogic.gdx.assets.loaders.SkinLoader)

Example 13 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project commons-gdx by gemserk.

the class GpuMemUtils method getTexturePathDuplicates.

private static List<String> getTexturePathDuplicates(List<Texture> managedTextures) {
    ObjectMap<String, Object> pathErrors = new ObjectMap<String, Object>();
    ObjectMap<String, Object> paths = new ObjectMap<String, Object>();
    for (Texture texture : managedTextures) {
        String path = getFilePath(texture);
        if (path != null) {
            if (paths.containsKey(path))
                pathErrors.put(path, null);
            paths.put(path, null);
        }
    }
    List<String> duplicatePaths = new ArrayList<String>(pathErrors.size);
    Keys<String> keys = pathErrors.keys();
    while (keys.hasNext()) {
        String path = (String) keys.next();
        duplicatePaths.add(path);
    }
    return duplicatePaths;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) ArrayList(java.util.ArrayList) Texture(com.badlogic.gdx.graphics.Texture)

Example 14 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project commons-gdx by gemserk.

the class GpuMemUtils method getTextureReferenceDuplicates.

private static List<String> getTextureReferenceDuplicates(List<Texture> managedTextures) {
    ObjectMap<Texture, Object> referenceErrors = new ObjectMap<Texture, Object>();
    ObjectMap<Texture, Object> references = new ObjectMap<Texture, Object>();
    for (Texture texture : managedTextures) {
        if (references.containsKey(texture))
            referenceErrors.put(texture, null);
        references.put(texture, null);
    }
    List<String> duplicatePaths = new ArrayList<String>(referenceErrors.size);
    Keys<Texture> keys = referenceErrors.keys();
    while (keys.hasNext()) {
        Texture texture = (Texture) keys.next();
        String path = getFilePath(texture);
        if (path == null)
            path = "NoPath -" + texture.getTextureData().getClass() + " - " + texture.getWidth() + "x" + texture.getHeight();
        duplicatePaths.add(path);
    }
    return duplicatePaths;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) ArrayList(java.util.ArrayList) Texture(com.badlogic.gdx.graphics.Texture)

Example 15 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project gdx-skineditor by cobolfoo.

the class OptionsPane method updateTableFields.

/**
 */
private void updateTableFields(final String style) {
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    Gdx.app.log("OptionsPane", "Update fields table for widget: " + widget + ", style: " + style);
    tableFields.clear();
    tableFields.add(new Label("Name", game.skin, "title")).left().width(170);
    tableFields.add(new Label("Value", game.skin, "title")).left().width(60).padRight(50);
    tableFields.row();
    Field[] fields = ClassReflection.getFields(currentStyle.getClass());
    for (final Field field : fields) {
        try {
            // Grey optional
            if (game.opt.isFieldOptional(currentStyle.getClass(), field.getName())) {
                tableFields.add(new Label(field.getName(), game.skin, "optional")).left();
            } else {
                tableFields.add(new Label(field.getName(), game.skin, "default")).left();
            }
            Actor actor;
            // field type
            String name = field.getType().getSimpleName();
            Object obj = field.get(currentStyle);
            if (name.equals("Drawable")) {
                /**
                 * Handle Drawable object
                 */
                Drawable drawable = (Drawable) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if (drawable != null) {
                    resourceName = game.skinProject.resolveObjectName(Drawable.class, drawable);
                    buttonStyle.imageUp = drawable;
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showDrawableDialog(field);
                    }
                });
            } else if (name.equals("Color")) {
                /**
                 * Handle Color object
                 */
                Color color = (Color) field.get(currentStyle);
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                String resourceName = "";
                if (color != null) {
                    resourceName = game.skinProject.resolveObjectName(Color.class, color);
                    resourceName += " (" + color.toString() + ")";
                    // Create drawable on the fly
                    Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
                    pixmap.setColor(color);
                    pixmap.fill();
                    pixmap.setColor(Color.BLACK);
                    pixmap.drawRectangle(0, 0, 18, 18);
                    Texture texture = new Texture(pixmap);
                    buttonStyle.imageUp = new SpriteDrawable(new Sprite(texture));
                    pixmap.dispose();
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showColorPickerDialog(field);
                    }
                });
            } else if (name.equals("BitmapFont")) {
                /**
                 * Handle BitmapFont object
                 */
                BitmapFont font = (BitmapFont) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if (font != null) {
                    resourceName = game.skinProject.resolveObjectName(BitmapFont.class, font);
                    buttonStyle.font = font;
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFontPickerDialog(field);
                    }
                });
            } else if (name.equals("float")) {
                /**
                 * Handle Float object
                 */
                Float value = (Float) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if ((value != null) && (value != 0)) {
                    resourceName = String.valueOf(value);
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFloatInputDialog(field);
                    }
                });
            } else if (name.equals("ListStyle")) {
                /**
                 * Handle ListStyle object
                 */
                ListStyle listStyle = (ListStyle) field.get(currentStyle);
                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();
                final ObjectMap<String, ListStyle> values = game.skinProject.getAll(ListStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;
                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);
                    if (listStyle == values.get(key)) {
                        selection = key;
                    }
                }
                ((SelectBox) actor).setItems(items);
                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        game.screenMain.saveToSkin();
                        refresh();
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }
                });
            } else if (name.equals("ScrollPaneStyle")) {
                /**
                 * Handle ListStyle object
                 */
                ScrollPaneStyle scrollStyle = (ScrollPaneStyle) field.get(currentStyle);
                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();
                final ObjectMap<String, ScrollPaneStyle> values = game.skinProject.getAll(ScrollPaneStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;
                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);
                    if (scrollStyle == values.get(key)) {
                        selection = key;
                    }
                }
                ((SelectBox) actor).setItems(items);
                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        game.screenMain.saveToSkin();
                        refresh();
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }
                });
            } else {
                Gdx.app.log("OptionsPane", "Unknown type: " + name);
                actor = new Label("Unknown Type", game.skin);
            }
            tableFields.add(actor).left().height(32).padRight(24).expandX().fillX();
            tableFields.row();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Field(com.badlogic.gdx.utils.reflect.Field) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Iterator(java.util.Iterator) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Array(com.badlogic.gdx.utils.Array) Pixmap(com.badlogic.gdx.graphics.Pixmap) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Aggregations

ObjectMap (com.badlogic.gdx.utils.ObjectMap)15 Texture (com.badlogic.gdx.graphics.Texture)7 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 IOException (java.io.IOException)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 DirectImageResolver (com.badlogic.gdx.maps.ImageResolver.DirectImageResolver)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)2 Array (com.badlogic.gdx.utils.Array)2 ArrayList (java.util.ArrayList)2 AssetLoader (com.badlogic.gdx.assets.loaders.AssetLoader)1 SkinLoader (com.badlogic.gdx.assets.loaders.SkinLoader)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1