Search in sources :

Example 1 with TextraLabel

use of com.github.tommyettinger.textra.TextraLabel in project TGMT by raeleus.

the class Core method openRoom.

public void openRoom(int index) {
    root.clear();
    var room = rooms.get(index);
    var table = new Table();
    table.pad(20);
    table.align(Align.top);
    var top = new ScrollPane(table, skin, "panel");
    top.setFadeScrollBars(false);
    top.setScrollingDisabled(true, false);
    top.addListener(new ScrollFocusListener(stage));
    for (var element : room.elements) {
        boolean show = true;
        for (var requiredKey : element.requiredKeys) {
            if (!playerKeys.contains(requiredKey, false)) {
                show = false;
                break;
            }
        }
        for (var bannedKey : element.bannedKeys) {
            if (playerKeys.contains(bannedKey, false)) {
                show = false;
                break;
            }
        }
        if (show) {
            if (element instanceof TextElement) {
                var textElement = (TextElement) element;
                var label = new TextraLabel(textElement.text, skin);
                label.setWrap(true);
                table.add(label).growX();
            }
            if (element instanceof ImageElement) {
                var imageElement = (ImageElement) element;
                var image = new Image(assetManager.get(imageElement.image, Texture.class));
                image.setScaling(Scaling.fit);
                image.setAlign(Align.left);
                var container = new AspectRatioContainer<>(image, image.getDrawable().getMinWidth(), image.getDrawable().getMinHeight());
                table.add(container).growX();
            } else if (element instanceof MusicElement) {
                var musicElement = (MusicElement) element;
                Music music = assetManager.get(musicElement.music);
                music.setLooping(true);
                music.play();
                if (Core.music != null && Core.music != music) {
                    Core.music.stop();
                }
                Core.music = music;
            } else if (element instanceof SoundElement) {
                var soundElement = (SoundElement) element;
                Sound sound = assetManager.get(soundElement.sound);
                sound.play();
            }
            table.row();
        }
    }
    var horizontalGroup = new HorizontalGroup();
    horizontalGroup.pad(20);
    horizontalGroup.wrap();
    horizontalGroup.rowAlign(Align.center);
    horizontalGroup.align(Align.center);
    var bottom = new ScrollPane(horizontalGroup, skin, "panel");
    bottom.setFadeScrollBars(false);
    bottom.addListener(new ScrollFocusListener(stage));
    for (var action : room.actions) {
        boolean hasKeys = true;
        for (var requiredKey : action.requiredKeys) {
            if (!playerKeys.contains(requiredKey, false)) {
                hasKeys = false;
                break;
            }
        }
        if (hasKeys)
            for (var bannedKey : action.bannedKeys) {
                if (playerKeys.contains(bannedKey, false)) {
                    hasKeys = false;
                    break;
                }
            }
        if (hasKeys) {
            var textButton = new TextButton(action.name, skin);
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    if (action.sound != null) {
                        Sound sound = assetManager.get(action.sound);
                        sound.play();
                    }
                    playerKeys.removeAll(action.removeKeys, false);
                    if (action.removeAllKeys)
                        playerKeys.clear();
                    playerKeys.addAll(action.giveKeys);
                    openRoom(action.targetRoom);
                }
            });
            horizontalGroup.addActor(textButton);
        }
    }
    var splitPane = new SplitPane(top, bottom, true, skin);
    splitPane.setSplitAmount(.75f);
    root.add(splitPane).grow();
}
Also used : ScrollFocusListener(com.ray3k.stripe.ScrollFocusListener) Sound(com.badlogic.gdx.audio.Sound) Texture(com.badlogic.gdx.graphics.Texture) TextraLabel(com.github.tommyettinger.textra.TextraLabel) Music(com.badlogic.gdx.audio.Music) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

Music (com.badlogic.gdx.audio.Music)1 Sound (com.badlogic.gdx.audio.Sound)1 Texture (com.badlogic.gdx.graphics.Texture)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 TextraLabel (com.github.tommyettinger.textra.TextraLabel)1 ScrollFocusListener (com.ray3k.stripe.ScrollFocusListener)1