Example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable setLeftWidth

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Drawable setLeftWidth

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable setLeftWidth.

Prototype

public void setLeftWidth(float leftWidth);

Source Link

Usage

From source file:com.jupiter.europa.screen.MainMenuScreen.java

License:Open Source License

private static void buildMainMenuSkin() {
    Skin skin = new Skin();

    // Fonts/*from w  ww . j  av a2 s .  c  om*/
    skin.add(BUTTON_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(BUTTON_FONT).toString()));
    skin.add(TITLE_FANCY_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TITLE_FANCY_FONT).toString()));
    skin.add(TITLE_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TITLE_FONT).toString()));
    skin.add(LIST_FONT_KEY,
            EuropaGame.game.getAssetManager().get(FileLocations.FONTS_DIRECTORY.resolve(LIST_FONT).toString()));
    skin.add(TEXT_FIELD_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TEXT_FIELD_FONT).toString()));
    skin.add(INFO_LABEL_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(INFO_LABEL_FONT).toString()));

    // Set the background texture
    Pixmap pixmap = new Pixmap(1, (int) 1, Pixmap.Format.RGB888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add(SOLID_TEXTURE_KEY, new Texture(pixmap));
    Drawable transparentDrawable = skin.newDrawable(SOLID_TEXTURE_KEY, TRANSPARENT);

    // Get values from the atlas
    skin.addRegions(
            EuropaGame.game.getAssetManager().get(MAIN_MENU_SKIN_DIRECTORY.resolve(ATLAS_KEY).toString()));

    // Colors
    Color textButtonFontColor = new Color(0.85f, 0.85f, 0.85f, 1.0f);

    // Set images
    Drawable textButtonBackground = new TextureRegionDrawable(
            skin.get(BUTTON_BACKGROUND_KEY, TextureRegion.class));
    textButtonBackground.setLeftWidth(32);
    textButtonBackground.setRightWidth(32);
    textButtonBackground.setTopHeight(5);
    textButtonBackground.setBottomHeight(5);
    skin.add(BUTTON_BACKGROUND_KEY, textButtonBackground);

    Drawable textButtonBackgroundDown = new TextureRegionDrawable(
            skin.get(BUTTON_DOWN_KEY, TextureRegion.class));
    textButtonBackgroundDown.setLeftWidth(32);
    textButtonBackgroundDown.setRightWidth(32);
    textButtonBackgroundDown.setTopHeight(5);
    textButtonBackgroundDown.setBottomHeight(5);
    skin.add(BUTTON_DOWN_KEY, textButtonBackgroundDown);

    Drawable listSelection = new TextureRegionDrawable(skin.get(LIST_SELECTION_KEY, TextureRegion.class));
    listSelection.setLeftWidth(7);
    listSelection.setRightWidth(7);
    listSelection.setTopHeight(0);
    listSelection.setBottomHeight(0);
    skin.add(LIST_SELECTION_KEY, listSelection);

    Drawable tabButtonBackground = new TextureRegionDrawable(
            skin.get(TAB_BUTTON_BACKGROUND_KEY, TextureRegion.class));
    tabButtonBackground.setLeftWidth(5);
    tabButtonBackground.setRightWidth(5);
    tabButtonBackground.setTopHeight(0);
    tabButtonBackground.setBottomHeight(0);
    skin.add(TAB_BUTTON_BACKGROUND_KEY, tabButtonBackground);

    Drawable tabButtonBackgroundSelected = new TextureRegionDrawable(
            skin.get(TAB_BUTTON_SELECTED_KEY, TextureRegion.class));
    tabButtonBackgroundSelected.setLeftWidth(5);
    tabButtonBackgroundSelected.setRightWidth(5);
    tabButtonBackgroundSelected.setTopHeight(0);
    tabButtonBackgroundSelected.setBottomHeight(0);
    skin.add(TAB_BUTTON_SELECTED_KEY, tabButtonBackgroundSelected);

    Drawable titleBackground = new TextureRegionDrawable(skin.get(TITLE_BACKGROUND_KEY, TextureRegion.class));
    titleBackground.setLeftWidth(10);
    titleBackground.setRightWidth(10);
    titleBackground.setTopHeight(0);
    titleBackground.setBottomHeight(0);
    skin.add(TITLE_BACKGROUND_KEY, titleBackground);

    Drawable numberIncreaseDrawable = new TextureRegionDrawable(
            skin.get(NUMBER_SELECTOR_INCREASE_KEY, TextureRegion.class));
    numberIncreaseDrawable.setLeftWidth(0);
    numberIncreaseDrawable.setRightWidth(0);
    numberIncreaseDrawable.setTopHeight(0);
    numberIncreaseDrawable.setBottomHeight(0);
    skin.add(NUMBER_SELECTOR_INCREASE_KEY, numberIncreaseDrawable);

    Drawable numberDecreaseDrawable = new TextureRegionDrawable(
            skin.get(NUMBER_SELECTOR_DECREASE_KEY, TextureRegion.class));
    numberDecreaseDrawable.setLeftWidth(0);
    numberDecreaseDrawable.setRightWidth(0);
    numberDecreaseDrawable.setTopHeight(0);
    numberDecreaseDrawable.setBottomHeight(0);
    skin.add(NUMBER_SELECTOR_DECREASE_KEY, numberDecreaseDrawable);

    skin.add(DIALOG_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(DIALOG_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(POPUP_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(POPUP_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(LIST_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(LIST_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(LIST_SELECTION_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(LIST_SELECTION_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(CREDITS_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(CREDITS_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));

    Drawable dropdownListBackground = skin.newDrawable(
            new TextureRegionDrawable(skin.get(DROP_DOWN_LIST_BACKGROUND, TextureRegion.class)),
            new Color(1, 1, 1, 1));
    dropdownListBackground.setLeftWidth(28);
    dropdownListBackground.setRightWidth(28);
    dropdownListBackground.setTopHeight(0);
    dropdownListBackground.setBottomHeight(0);
    skin.add(DROP_DOWN_LIST_BACKGROUND, dropdownListBackground);

    // Create a Label style for the title
    Label.LabelStyle titleStyle = new Label.LabelStyle();
    titleStyle.background = transparentDrawable;
    titleStyle.font = skin.getFont(TITLE_FONT_KEY);
    titleStyle.fontColor = new Color(Color.BLACK);
    skin.add(DEFAULT_KEY, titleStyle);

    // Fancy Character Label Style
    Label.LabelStyle fancyTitleStyle = new Label.LabelStyle();
    fancyTitleStyle.background = transparentDrawable;
    fancyTitleStyle.font = skin.getFont(TITLE_FANCY_FONT_KEY);
    fancyTitleStyle.fontColor = new Color(Color.BLACK);
    skin.add(FANCY_KEY, fancyTitleStyle);

    // Create a Label style for dialogs
    LabelStyle infoStyle = new LabelStyle();
    infoStyle.background = transparentDrawable;
    infoStyle.font = skin.getFont(INFO_LABEL_FONT_KEY);
    infoStyle.fontColor = new Color(Color.BLACK);
    skin.add(INFO_STYLE_KEY, infoStyle);

    // Default Button Style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = textButtonBackground;
    textButtonStyle.down = textButtonBackgroundDown;
    textButtonStyle.checked = textButtonBackground;
    textButtonStyle.over = textButtonBackgroundDown;
    textButtonStyle.disabled = textButtonBackground;
    textButtonStyle.font = skin.getFont(BUTTON_FONT_KEY);
    textButtonStyle.fontColor = textButtonFontColor;
    textButtonStyle.disabledFontColor = new Color(0.3f, 0.3f, 0.3f, 1.0f);
    //        textButtonStyle.pressedOffsetX = 2f;
    //        textButtonStyle.pressedOffsetY = -3f;
    skin.add(DEFAULT_KEY, textButtonStyle);

    // Tab Button Style
    TextButtonStyle tabButtonStyle = new TextButtonStyle();
    tabButtonStyle.up = tabButtonBackground;
    tabButtonStyle.down = tabButtonBackground;
    tabButtonStyle.checked = tabButtonBackgroundSelected;
    tabButtonStyle.over = tabButtonBackground;
    tabButtonStyle.disabled = tabButtonBackground;
    tabButtonStyle.font = skin.getFont(BUTTON_FONT_KEY);
    tabButtonStyle.fontColor = textButtonFontColor;
    tabButtonStyle.overFontColor = textButtonFontColor;
    tabButtonStyle.disabledFontColor = new Color(Color.GRAY);
    skin.add(TAB_STYLE_KEY, tabButtonStyle);

    // Create a TextField style
    TextFieldStyle textFieldStyle = new TextFieldStyle();
    textFieldStyle.background = skin.newDrawable(SOLID_TEXTURE_KEY, new Color(0f, 0f, 0f, 0.1f));
    textFieldStyle.selection = skin.newDrawable(SOLID_TEXTURE_KEY, new Color(0f, 0f, 1f, 0.3f));
    textFieldStyle.cursor = skin.newDrawable(SOLID_TEXTURE_KEY, Color.BLACK);
    textFieldStyle.font = skin.getFont(TEXT_FIELD_FONT_KEY);
    textFieldStyle.fontColor = Color.BLACK;
    skin.add(DEFAULT_KEY, textFieldStyle);

    // Create a List style
    ListStyle listStyle = new ListStyle();
    listStyle.font = skin.getFont(LIST_FONT_KEY);
    listStyle.fontColorSelected = Color.BLACK;
    listStyle.fontColorUnselected = Color.BLACK;
    listStyle.selection = listSelection;
    listStyle.background = transparentDrawable;
    skin.add(DEFAULT_KEY, listStyle);

    // Create a Scroll Pane Style
    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    scrollPaneStyle.background = transparentDrawable;
    //        scrollPaneStyle.vScroll = skin.newDrawable(MainMenuScreen.SCROLL_BAR_VERTICAL_KEY);
    //        scrollPaneStyle.vScrollKnob = skin.newDrawable(MainMenuScreen.SCROLL_BAR_VERTICAL_KNOB_KEY);
    skin.add(DEFAULT_KEY, scrollPaneStyle);

    // Create a Dialog Style
    WindowStyle dialogStyle = new WindowStyle();
    dialogStyle.background = new SpriteDrawable(
            new Sprite(EuropaGame.game.getAssetManager().get(BACKGROUND_FILE_NAME, Texture.class)));
    dialogStyle.titleFont = skin.getFont(TITLE_FONT_KEY);
    dialogStyle.titleFontColor = new Color(Color.BLACK);
    skin.add(DEFAULT_KEY, dialogStyle);

    // Popup Dialog Style
    WindowStyle popupStyle = new WindowStyle();
    popupStyle.titleFont = skin.getFont(TITLE_FONT_KEY);
    popupStyle.titleFontColor = new Color(Color.BLACK);
    skin.add(POPUP_DIALOG_STYLE_KEY, popupStyle);

    // Create a Slider Skin
    SliderStyle sliderStyle = new SliderStyle();
    sliderStyle.background = new TextureRegionDrawable(skin.get(SLIDER_BACKGROUND_KEY, TextureRegion.class));
    sliderStyle.knob = new TextureRegionDrawable(skin.get(SLIDER_KNOB_KEY, TextureRegion.class));
    skin.add(DEFAULT_KEY, sliderStyle);

    // Create a Drop Down Menu Skin
    SelectBoxStyle selectBoxStyle = new SelectBoxStyle();
    selectBoxStyle.background = textButtonBackground;
    selectBoxStyle.backgroundOpen = textButtonBackgroundDown;
    selectBoxStyle.backgroundOver = textButtonBackgroundDown;
    selectBoxStyle.scrollStyle = scrollPaneStyle;
    selectBoxStyle.font = skin.getFont(TEXT_FIELD_FONT_KEY);
    selectBoxStyle.fontColor = textButtonFontColor;
    ListStyle selectBoxListStyle = new ListStyle();
    selectBoxListStyle.font = skin.getFont(LIST_FONT_KEY);
    selectBoxListStyle.fontColorSelected = textButtonFontColor;
    selectBoxListStyle.fontColorUnselected = textButtonFontColor;
    selectBoxListStyle.selection = skin.newDrawable(SOLID_TEXTURE_KEY, SELECTION_COLOR);
    selectBoxListStyle.background = dropdownListBackground;
    selectBoxStyle.listStyle = selectBoxListStyle;
    skin.add(DEFAULT_KEY, selectBoxStyle);

    // NumberSelectorStyle
    NumberSelectorStyle numberStyle = new NumberSelectorStyle();
    numberStyle.decrease = numberDecreaseDrawable;
    numberStyle.increase = numberIncreaseDrawable;
    numberStyle.minimumNumberSize = 50;
    numberStyle.numberLabelStyle = infoStyle;
    numberStyle.spacing = COMPONENT_SPACING;
    skin.add(DEFAULT_KEY, numberStyle);

    // AttributeSelectorStyle
    MultipleNumberSelectorStyle attrStyle = new MultipleNumberSelector.MultipleNumberSelectorStyle();
    attrStyle.labelStyle = infoStyle;
    attrStyle.numberSelectorStyle = numberStyle;
    attrStyle.spacing = COMPONENT_SPACING;
    skin.add(DEFAULT_KEY, attrStyle);

    mainMenuSkin = skin;
}

From source file:com.vlaaad.dice.states.LoadGameResourcesState.java

License:Open Source License

@Override
protected void render(float delta) {
    stateTime += delta;/* ww  w.j  a  v a2s  .  c  o  m*/
    if (stateTime >= 1.7f) {
        stateTime -= 1.7f;
        if (loaded) {
            callback.onResourcesLoaded();
        }
    }
    if (!loaded && Config.assetManager.update(33)) {
        loaded = true;
        Config.thesaurus = Config.assetManager.get("thesaurus.yml", Thesaurus.class);
        Config.skin = Config.assetManager.get("gfx.json", Skin.class);
        Config.worldMapParams = Config.assetManager.get("world-map.yml", Map.class);
        Drawable back = Config.skin.getDrawable("ui-slider-background");
        back.setLeftWidth(2);
        back.setRightWidth(2);
        ObjectMap<String, Sound> sounds = new ObjectMap<String, Sound>();
        for (FileHandle file : Gdx.files.internal("sfx").list()) {
            Sound sound = Config.assetManager.get(file.path());
            sounds.put(file.nameWithoutExtension(), sound);
        }
        SoundManager.instance.putSounds(sounds);
        ObjectMap<String, Music> musics = new ObjectMap<String, Music>();
        for (FileHandle file : Gdx.files.internal("music").list()) {
            Music music = Config.assetManager.get(file.path());
            musics.put(file.nameWithoutExtension(), music);
        }
        SoundManager.instance.putMusics(musics);
        ObjectMap<String, ParticleEffectPool> particles = new ObjectMap<String, ParticleEffectPool>();
        for (FileHandle file : Gdx.files.internal("particles").list()) {
            ParticleEffect effect = Config.assetManager.get(file.path());
            ParticleEffectPool pool = new ParticleEffectPool(effect, 1, 6);
            particles.put(file.nameWithoutExtension(), pool);
        }
        Config.particles = new Particles(particles);
    }
    Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
    float x = (stage.getWidth() - progressWidth) / 2f;
    displayedProgress = displayedProgress + (Config.assetManager.getProgress() - displayedProgress) * 0.5f;
    Config.shapeRenderer.setColor(barBackgroundColor);
    Config.shapeRenderer.rect(x, progressY, progressWidth, progressHeight);
    Config.shapeRenderer.setColor(barProgressColor);
    Config.shapeRenderer.rect(x + progressPad, progressY + progressPad,
            (progressWidth - progressPad * 2) * displayedProgress, progressHeight - progressPad * 2);
    Config.shapeRenderer.end();
}