Search in sources :

Example 26 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project gdx-skineditor by cobolfoo.

the class PreviewPane method refresh.

/**
 */
public void refresh() {
    Gdx.app.log("PreviewPane", "Refresh pane!");
    clear();
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
    try {
        Class<?> style = Class.forName(widgetStyle);
        ObjectMap<String, ?> styles = game.skinProject.getAll(style);
        if (styles == null) {
            Label label = new Label("No styles defined for this widget type", game.skin, "error");
            add(label).row().pad(10);
        } else {
            Keys<String> keys = styles.keys();
            Array<String> sortedKeys = new Array<String>();
            for (String key : keys) {
                sortedKeys.add(key);
            }
            sortedKeys.sort();
            for (String key : sortedKeys) {
                // We render one per key
                add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
                try {
                    if (widget.equals("Label")) {
                        Label w = new Label("This is a Label widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("Button")) {
                        // Button
                        Button w = new Button(game.skinProject, key);
                        add(w).width(120).height(32).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextButton")) {
                        // TextButton
                        TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("ImageButton")) {
                        // ImageButton
                        ImageButton w = new ImageButton(game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("CheckBox")) {
                        // CheckBox
                        CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
                        w.setChecked(true);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextField")) {
                        // TextField
                        TextField w = new TextField("This is a TextField widget", game.skinProject, key);
                        if (w.getStyle().fontColor == null) {
                            throw new Exception("Textfield style requires a font color!");
                        }
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).row();
                    } else if (widget.equals("List")) {
                        // List
                        List w = new List(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("List widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SelectBox")) {
                        // SelectBox
                        SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("SelectBox widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("ProgressBar")) {
                        // ProgressBar
                        ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
                        // Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
                        if (progressStyle.knob == null && progressStyle.knobBefore == null) {
                            throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
                        }
                        ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
                        w.setValue(50);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Slider")) {
                        // Slider
                        Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                        w.addListener(stopTouchDown);
                        Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
                        add(w2).pad(10).padBottom(20).expandX().fillX().row();
                        w2.addListener(stopTouchDown);
                    } else if (widget.equals("ScrollPane")) {
                        // ScrollPane
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 20; i++) {
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").row();
                        }
                        ScrollPane w = new ScrollPane(t, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.setFlickScroll(true);
                        w.setScrollbarsOnTop(true);
                        w.setScrollBarPositions(true, true);
                        w.setFadeScrollBars(false);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SplitPane")) {
                        for (int j = 0; j < 2; j++) {
                            Table t = new Table(game.skin);
                            t.setBackground(game.skin.getDrawable("default-rect"));
                            Table t2 = new Table(game.skin);
                            t2.setBackground(game.skin.getDrawable("default-rect"));
                            for (int i = 0; i < 20; i++) {
                                t.add("This is a SplitPane Widget").pad(10).row();
                                t2.add("This is a SplitPane Widget").pad(10).row();
                            }
                            SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
                            w.addListener(stopTouchDown);
                            add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
                        }
                        row();
                    } else if (widget.equals("Window")) {
                        // Window
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 5; i++) {
                            t.add("This is a Window Widget").row();
                        }
                        Window w = new Window("This is a Window Widget", game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.add(t);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Touchpad")) {
                        // Touchpad
                        Touchpad w = new Touchpad(0, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Tree")) {
                        // Tree
                        Tree w = new Tree(game.skinProject, key);
                        Tree.Node node = new Tree.Node(new Label("This", game.skin));
                        Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
                        Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
                        Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
                        Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
                        node3.add(node4);
                        node2.add(node3);
                        node1.add(node2);
                        node.add(node1);
                        w.add(node);
                        w.expandAll();
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else {
                        add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
                    }
                } catch (Exception e) {
                    add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Node(com.badlogic.gdx.graphics.g3d.model.Node) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Example 27 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project ultimate-java by pantinor.

the class TinkerDialog method initialize.

private void initialize() {
    screen.gameTimer.active = false;
    setModal(true);
    internalTable = new Table(skin);
    internalTable.defaults().pad(5);
    defaults().space(10).pad(2);
    add(internalTable).expand().fill();
    row();
    internalTable.add(new Label("Owned Items", skin)).align(Align.left);
    internalTable.add();
    internalTable.add(new Label("Tinkering Table", skin)).align(Align.left);
    internalTable.row();
    Array<String> tmp = new Array<>();
    for (Constants.Item item : Constants.Item.values()) {
        if ((party.getSaveGame().items & (1 << item.ordinal())) > 0 && item.isVisible()) {
            tmp.add(item.getDesc());
        }
    }
    ownedList = new List<>(skin);
    ownedList.setItems(tmp);
    tinkeringList = new List<>(skin);
    tinkeringList.setItems(new Array<>());
    buttonTable = new Table(skin);
    buttonTable.defaults().padLeft(20).padRight(20).padTop(5);
    add = new TextButton("Add", skin, "wood");
    add.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            String sel = ownedList.getSelected();
            if (sel == null) {
                return;
            }
            tinkeringList.getItems().add(sel);
        // tinkeringList.setItems(tmp);
        }
    });
    buttonTable.add(add).expandX().left().width(100);
    clear = new TextButton("Clear", skin, "wood");
    clear.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            tinkeringList.clearItems();
        }
    });
    buttonTable.row();
    buttonTable.add(clear).expandX().left().width(100).padBottom(30);
    mix = new TextButton("Tinker", skin, "wood");
    mix.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (tinkeringList == null || tinkeringList.getItems() == null || tinkeringList.getItems().size == 0) {
                Sounds.play(Sound.NEGATIVE_EFFECT);
                animateText("Bah, that won't work!", Color.WHITE, 10, 180, 350, 180, 2f);
                return;
            }
            if (500 > party.getSaveGame().gold) {
                Sounds.play(Sound.NEGATIVE_EFFECT);
                animateText("I fear you have not the funds, perhaps another time..", Color.WHITE, 10, 180, 200, 180, 2.5f);
                return;
            }
            if (tinkeringList.getItems().contains(Constants.Item.IRON_ORE.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.RUNE_MOLD.getDesc(), false)) {
                Sounds.play(Sound.POSITIVE_EFFECT);
                animateText("Excellent! you have made the Iron Rune!", Color.GREEN, 10, 180, 250, 180, 2.5f);
                party.adjustGold(-500);
                party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.IRON_ORE.getLoc());
                party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.RUNE_MOLD.getLoc());
                party.getSaveGame().items |= Constants.Item.IRON_RUNE.getLoc();
                party.getMember(0).awardXP(400);
                party.adjustKarma(Constants.KarmaAction.FOUND_ITEM);
            } else if (tinkeringList.getItems().contains(Constants.Item.IRON_RUNE.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.SONG_HUM.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.PARCH.getDesc(), false) && (party.getSaveGame().runes & Constants.Virtue.HUMILITY.getLoc()) == 0) {
                Sounds.play(Sound.POSITIVE_EFFECT);
                animateText("Congatulations! You now have the Rune of Humility!", Color.GREEN, 10, 180, 250, 180, 2.5f);
                party.adjustGold(-500);
                party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.IRON_RUNE.getLoc());
                party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.SONG_HUM.getLoc());
                party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.PARCH.getLoc());
                party.getSaveGame().runes |= Constants.Virtue.HUMILITY.getLoc();
                party.adjustKarma(Constants.KarmaAction.FOUND_ITEM);
                party.getMember(0).awardXP(500);
            } else {
                Sounds.play(Sound.NEGATIVE_EFFECT);
                animateText("Oh I'm afraid t'is a messy failure we have heahh..", Color.RED, 10, 180, 250, 180, 2f);
            }
            tinkeringList.clearItems();
            ownedList.clearItems();
            Array<String> tmp = new Array<>();
            for (Constants.Item item : Constants.Item.values()) {
                if ((party.getSaveGame().items & (1 << item.ordinal())) > 0 && item.isVisible()) {
                    tmp.add(item.getDesc());
                }
            }
            ownedList.setItems(tmp);
        }
    });
    buttonTable.row();
    buttonTable.add(mix).expandX().left().width(100);
    exit = new TextButton("Quit", skin, "wood");
    exit.addListener(new ChangeListener() {

        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            hide();
        }
    });
    buttonTable.row();
    buttonTable.add(exit).expandX().left().width(100);
    internalTable.add(ownedList).align(Align.top).minWidth(150).minHeight(150);
    internalTable.add(buttonTable).align(Align.top);
    internalTable.add(tinkeringList).align(Align.top).padRight(10).minWidth(150).minHeight(150);
    internalTable.row();
    focusListener = new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        @Override
        public void scrollFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        private void focusChanged(FocusListener.FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == TinkerDialog.this) {
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(TinkerDialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) {
                    event.cancel();
                }
            }
        }
    };
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Constants(ultima.Constants) Array(com.badlogic.gdx.utils.Array) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Example 28 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createInventoryPanel.

private Table createInventoryPanel() {
    Table inventory = new Table();
    inventory.defaults().pad(MARGIN);
    for (int i = 0; i < INVENTORY_COLS * INVENTORY_ROWS; i++) {
        if (i % INVENTORY_COLS == 0)
            inventory.row();
        ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
        RendererDrawable r = new RendererDrawable();
        s.imageUp = r;
        ImageButton b = new ImageButton(s);
        inventory.add(b).fill().expand();
        b.setUserObject(i);
        inventorySlots.add(b);
        b.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                int i = (Integer) event.getListenerActor().getUserObject();
                Inventory inv = World.getInstance().getInventory();
                target = null;
                if (i < inv.getNumItems()) {
                    InteractiveActor actor = inv.get(i);
                    if (currentVerb.equals("use") || currentVerb.equals("give")) {
                        target = actor;
                    } else {
                        sceneScreen.runVerb(actor, currentVerb, null);
                    }
                }
            }
        });
        b.getImageCell().pad(MARGIN).expand().fill();
    }
    return inventory;
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Inventory(com.bladecoder.engine.model.Inventory)

Example 29 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createArrowPanel.

private Table createArrowPanel() {
    Table arrows = new Table();
    arrows.defaults().pad(MARGIN);
    ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
    s.imageUp = style.upArrow;
    ImageButton up = new ImageButton(s);
    arrows.add(up).fillY().expandY();
    up.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            if (scroll > 0)
                scroll--;
        }
    });
    arrows.row();
    ImageButton.ImageButtonStyle s2 = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
    s2.imageUp = style.downArrow;
    ImageButton down = new ImageButton(s2);
    arrows.add(down).fillY().expandY();
    down.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            Inventory inv = World.getInstance().getInventory();
            int itemsLeft = inv.getNumItems() - scroll * INVENTORY_COLS;
            if (itemsLeft > inventorySlots.size())
                scroll++;
        }
    });
    return arrows;
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Inventory(com.bladecoder.engine.model.Inventory)

Example 30 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createVerbPanel.

private Table createVerbPanel() {
    Table verbs = new Table();
    verbs.defaults().pad(MARGIN);
    for (int i = 0; i < VERBS.size(); i++) {
        if (i % VERB_COLS == 0)
            verbs.row();
        TextButton b = new TextButton(VERBS_DESC.get(i), style.verbButtonStyle);
        b.setName(VERBS.get(i));
        b.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                currentVerb = event.getListenerActor().getName();
                infoLine.setText(((TextButton) event.getListenerActor()).getText());
                target = null;
            }
        });
        verbs.add(b).fill().expand();
    }
    return verbs;
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Table (com.badlogic.gdx.scenes.scene2d.ui.Table)93 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)56 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)50 Stage (com.badlogic.gdx.scenes.scene2d.Stage)48 Actor (com.badlogic.gdx.scenes.scene2d.Actor)43 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)38 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)34 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)32 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)25 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)23 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)18 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)18 Texture (com.badlogic.gdx.graphics.Texture)17 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)14 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)14 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)13 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)13 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)12 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)12