Search in sources :

Example 71 with Table

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

the class LoadSaveScreen method show.

@Override
public void show() {
    float size = DPIUtils.getPrefButtonSize();
    float pad = DPIUtils.getMarginSize();
    final Skin skin = ui.getSkin();
    final World world = World.getInstance();
    // loadScreenMode = ui.getScreen(Screens.LOAD_GAME_SCREEN) == this;
    loadScreenMode = world.getCurrentScene() == null;
    stage = new Stage(new ScreenViewport());
    slotWidth = (int) (stage.getViewport().getWorldWidth() / (ROW_SLOTS + 1) - 2 * pad);
    slotHeight = (int) (slotWidth * stage.getViewport().getScreenHeight() / stage.getViewport().getScreenWidth());
    LoadSaveScreenStyle style = skin.get(LoadSaveScreenStyle.class);
    Drawable bg = style.background;
    if (bg == null && style.bgFile != null) {
        bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
        bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        bg = new TextureRegionDrawable(new TextureRegion(bgTexFile));
    }
    Table table = new Table(skin);
    table.setFillParent(true);
    table.center();
    table.pad(pad);
    Label title = new Label(loadScreenMode ? I18N.getString("ui.load") : I18N.getString("ui.save"), skin, "title");
    Button back = new Button(skin, "back");
    back.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.MENU_SCREEN);
        }
    });
    Table header = new Table();
    // header.padBottom(pad);
    Container<Button> cont = new Container<Button>(back);
    cont.size(size);
    header.add(cont);
    header.add(title).fillX().expandX().left();
    table.add(header).fillX().expandX().left();
    if (bg != null)
        table.setBackground(bg);
    table.addListener(new InputListener() {

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
                if (world.getCurrentScene() != null)
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);
            return true;
        }
    });
    final PagedScrollPane scroll = new PagedScrollPane();
    scroll.setFlingTime(0.1f);
    scroll.setPageSpacing(0);
    Table slots = new Table().pad(pad);
    slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
    int c = 0;
    // Add "new slot" slot for save screen
    if (!loadScreenMode) {
        slots.add(getSlotButton(Long.toString(new Date().getTime()))).fill().expand();
        c++;
    }
    final List<String> sl = getSlots();
    Collections.sort(sl);
    for (int j = sl.size() - 1; j >= 0; j--) {
        String s = sl.get(j);
        if (c % ROW_SLOTS == 0 && c % (ROW_SLOTS * COL_SLOTS) != 0)
            slots.row();
        if (c != 0 && c % (ROW_SLOTS * COL_SLOTS) == 0) {
            scroll.addPage(slots);
            slots = new Table().pad(pad);
            slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
        }
        Button removeButton = new Button(skin, "delete_game");
        removeButton.setName(s);
        removeButton.addListener(removeClickListener);
        Container<Button> container = new Container<Button>(removeButton);
        container.size(DPIUtils.getPrefButtonSize() * .75f);
        container.align(Align.topRight);
        slots.stack(getSlotButton(s), container).fill().expand();
        c++;
    }
    // Add last page
    if (slots.getCells().size > 0)
        scroll.addPage(slots);
    table.row();
    if (loadScreenMode && sl.size() == 0) {
        Label lbl = new Label(I18N.getString("ui.noSavedGames"), skin, "title");
        lbl.setAlignment(Align.center);
        lbl.setWrap(true);
        table.add(lbl).expand().fill();
    } else {
        table.add(scroll).expand().fill();
    }
    table.pack();
    stage.setKeyboardFocus(table);
    stage.addActor(table);
    pointer = new Pointer(ui.getSkin());
    stage.addActor(pointer);
    Gdx.input.setInputProcessor(stage);
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) World(com.bladecoder.engine.model.World) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Date(java.util.Date) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 72 with Table

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

the class PagedScrollPane method setup.

private void setup() {
    content = new Table();
    content.defaults().space(50);
    super.setActor(content);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table)

Example 73 with Table

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

the class SpriteAtlasTool method create.

@Override
public void create() {
    Pixmap pixmap = new Pixmap(dim, dim, Format.RGBA8888);
    pixmap.setColor(new Color(1, 1, 0, .8f));
    int w = 1;
    pixmap.fillRectangle(0, 0, w, dim);
    pixmap.fillRectangle(dim - w, 0, w, dim);
    pixmap.fillRectangle(w, 0, dim - 2 * w, w);
    pixmap.fillRectangle(w, dim - w, dim - 2 * w, w);
    box = new Texture(pixmap);
    Texture tx = new Texture(Gdx.files.absolute("D:\\work\\gdx-andius\\src\\main\\resources\\assets\\data\\uf_heroes.png"));
    canvasGridWidth = tx.getWidth() / dim;
    canvasGridHeight = tx.getHeight() / dim;
    sprBg = new Sprite(tx, 0, 0, tx.getWidth(), tx.getHeight());
    gridItems = new ArrayList<>();
    font = new BitmapFont();
    font.setColor(Color.WHITE);
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("assets/skin/uiskin.json"));
    stage = new Stage();
    readAtlas();
    final List<MyListItem> list = new List<>(skin);
    try {
        MyListItem[] tileNames = new MyListItem[Tile.values().length];
        int x = 0;
        for (Tile t : Tile.values()) {
            tileNames[x] = new MyListItem(t.toString(), 0, 0);
            x++;
        }
        list.setItems(tileNames);
    } catch (Exception ex) {
    }
    list.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            selectedTileName = list.getSelected();
        }
    });
    ScrollPane scrollPane = new ScrollPane(list, skin);
    scrollPane.setScrollingDisabled(true, false);
    TextButton makeButton = new TextButton("Make Atlas", skin, "default");
    makeButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            makeAtlas();
        }
    });
    Table table = new Table(skin);
    table.defaults().pad(2);
    table.add(makeButton).expandX().left().width(175);
    table.row();
    table.add(scrollPane).expandX().left().width(175).maxHeight(screenHeight);
    table.setPosition(screenWidth - 175, 0);
    table.setFillParent(true);
    stage.addActor(table);
    Gdx.input.setInputProcessor(new InputMultiplexer(stage, this));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Color(com.badlogic.gdx.graphics.Color) Tile(objects.Tile) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) IOException(java.io.IOException) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ArrayList(java.util.ArrayList) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 74 with Table

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

the class ConversationDialog method initialize.

private void initialize() {
    screen.gameTimer.active = false;
    setModal(true);
    defaults().space(10);
    add(internalTable = new Table(Ultima4.skin)).expand().fill();
    row();
    internalTable.defaults().pad(1);
    scrollPane = new LogScrollPane(Ultima4.skin, width);
    scrollPane.setHeight(height);
    input = new TextField("", Ultima4.skin);
    input.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField tf, char key) {
            if (key == '\r') {
                if (tf.getText().length() == 0) {
                    if (!cancelHide) {
                        hide();
                    }
                    cancelHide = false;
                }
                Conversation conversation = person.getConversation();
                if (conversation != null) {
                    if (conversation instanceof CustomInputConversation) {
                        ((CustomInputConversation) conversation).setParty(screen.context.getParty());
                    }
                    String query = tf.getText();
                    Topic t = conversation.matchTopic(query);
                    if (t != null) {
                        if (t.getQuery() != null && t.getQuery().equals("join")) {
                            String name = conversation.getName();
                            Virtue virtue = screen.context.getParty().getVirtueForJoinable(name);
                            if (virtue != null) {
                                CannotJoinError join = screen.context.getParty().join(name);
                                if (join == CannotJoinError.JOIN_SUCCEEDED) {
                                    scrollPane.add("I am honored to join thee!");
                                    screen.context.getCurrentMap().removeJoinedPartyMemberFromPeopleList(screen.context.getParty());
                                } else {
                                    scrollPane.add("Thou art not " + (join == CannotJoinError.JOIN_NOT_VIRTUOUS ? virtue.getDescription() : "experienced") + " enough for me to join thee.");
                                }
                            } else {
                                scrollPane.add("I cannot join thee.");
                            }
                        } else {
                            if (!conversation.isStandardQuery(query)) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), t.getPhrase());
                            }
                            scrollPane.add(t.getPhrase());
                            if (t.getQuestion() != null) {
                                scrollPane.add(t.getQuestion());
                            }
                        }
                        previousTopic = t;
                    } else {
                        if (previousTopic != null && previousTopic.getQuestion() != null) {
                            if (query.toLowerCase().contains("y")) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getYesResponse());
                                scrollPane.add(previousTopic.getYesResponse());
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.BRAGGED);
                                }
                            } else {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getNoResponse());
                                scrollPane.add(previousTopic.getNoResponse());
                                if (previousTopic.isLbHeal()) {
                                    for (PartyMember pm : screen.context.getParty().getMembers()) {
                                        pm.heal(HealType.CURE);
                                        pm.heal(HealType.FULLHEAL);
                                    }
                                    Sounds.play(Sound.HEALING);
                                }
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.HUMBLE);
                                }
                            }
                        } else {
                            scrollPane.add("That I cannot help thee with.");
                        }
                        previousTopic = null;
                    }
                } else if (person.getRole() != null && vendor != null) {
                    String input = tf.getText();
                    vendor.setResponse(input);
                    vendor.nextDialog();
                }
                tf.setText("");
            }
        }
    });
    defaults().pad(5);
    internalTable.add(scrollPane).maxWidth(width).width(width);
    internalTable.row();
    internalTable.add(input).maxWidth(width).width(width);
    focusListener = new FocusListener() {

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

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

        private void focusChanged(FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == ConversationDialog.this) {
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(ConversationDialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) {
                    event.cancel();
                }
            }
        }
    };
    person.setTalking(true);
    if (person.getConversation() != null) {
        if (person.getRole() != null && person.getRole().getRole().equals("lordbritish")) {
            LordBritishConversation conv = (LordBritishConversation) person.getConversation();
            scrollPane.add(conv.intro(screen.context));
            SequenceAction seq = Actions.action(SequenceAction.class);
            Party party = screen.context.getParty();
            if (party.getMember(0).getPlayer().status == StatusType.DEAD) {
                party.getMember(0).heal(HealType.RESURRECT);
                party.getMember(0).heal(HealType.FULLHEAL);
                seq.addAction(Actions.run(new LBAction(Sound.HEALING, "I resurrect thee.")));
                seq.addAction(Actions.delay(3f));
            }
            for (int i = 0; i < party.getMembers().size(); i++) {
                PartyMember pm = party.getMember(i);
                if (pm.getPlayer().advanceLevel()) {
                    seq.addAction(Actions.run(new LBAction(Sound.MAGIC, pm.getPlayer().name + " thou art now level " + pm.getPlayer().getLevel())));
                    seq.addAction(Actions.delay(3f));
                }
            }
            stage.addAction(seq);
        } else if (person.getRole() != null && person.getRole().getRole().equals("hawkwind")) {
            HawkwindConversation conv = (HawkwindConversation) person.getConversation();
            conv.setParty(screen.context.getParty());
            scrollPane.add(conv.intro());
        } else {
            scrollPane.add("You meet " + person.getConversation().getDescription().toLowerCase() + ".");
        }
    } else if (person.getRole() != null && person.getRole().getInventoryType() != null) {
        vendor = Ultima4.vendorClassSet.getVendorImpl(person.getRole().getInventoryType(), Maps.get(screen.context.getCurrentMap().getId()), screen.context);
        vendor.setScreen(screen);
        vendor.setScrollPane(scrollPane);
        vendor.nextDialog();
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) PartyMember(objects.Party.PartyMember) LordBritishConversation(objects.LordBritishConversation) LogScrollPane(util.LogScrollPane) Conversation(objects.Conversation) CustomInputConversation(objects.CustomInputConversation) LordBritishConversation(objects.LordBritishConversation) HawkwindConversation(objects.HawkwindConversation) HawkwindConversation(objects.HawkwindConversation) Party(objects.Party) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) Topic(objects.Conversation.Topic) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction) CustomInputConversation(objects.CustomInputConversation)

Example 75 with Table

use of com.badlogic.gdx.scenes.scene2d.ui.Table in project ProjektGG by eskalon.

the class LobbyCreationScreen method initUI.

@Override
protected void initUI() {
    backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
    Sound clickSound = assetManager.get(BUTTON_SOUND);
    Label nameLabel = new Label("Name: ", skin);
    Label portLabel = new Label("Port: ", skin);
    TextField nameField = new TextField("", skin);
    TextField portField = new TextField("55789", skin);
    portField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
    Label difficultyLabel = new Label("Schwierigkeit: ", skin);
    CheckBox easyDifficultyCheckbox = new CheckBox("Einfach", skin);
    CheckBox normalDifficultyCheckbox = new CheckBox("Normal", skin);
    CheckBox hardDifficultyCheckbox = new CheckBox("Schwer", skin);
    ButtonGroup speedGroup = new ButtonGroup();
    speedGroup.add(easyDifficultyCheckbox);
    speedGroup.add(normalDifficultyCheckbox);
    speedGroup.add(hardDifficultyCheckbox);
    normalDifficultyCheckbox.setChecked(true);
    ImageTextButton backButton = new ImageTextButton("Zur�ck", skin);
    backButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            game.pushScreen("serverBrowser");
            clickSound.play(1F);
            return true;
        }
    });
    ImageTextButton createButton = new ImageTextButton("Erstellen", skin);
    createButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!nameField.getText().isEmpty() && !portField.getText().isEmpty()) {
                clickSound.play(1F);
                GameDifficulty difficulty = GameDifficulty.NORMAL;
                if (speedGroup.getChecked().equals(easyDifficultyCheckbox)) {
                    difficulty = GameDifficulty.EASY;
                } else if (speedGroup.getChecked().equals(normalDifficultyCheckbox)) {
                    difficulty = GameDifficulty.NORMAL;
                } else if (speedGroup.getChecked().equals(hardDifficultyCheckbox)) {
                    difficulty = GameDifficulty.HARD;
                }
                // Sever & Client starten
                game.getNetworkHandler().setUpConnectionAsHost(Integer.valueOf(portField.getText()), new GameSessionSetup(difficulty, GameMap.getMaps().get("Bamberg"), System.currentTimeMillis()));
                connectingDialog = new Dialog("Starten...", skin);
                connectingDialog.text("Server startet...");
                connectingDialog.show(stage);
            } else {
                Dialog dialog = new Dialog("Felder unausgef�llt", skin);
                dialog.text("Zum Starten m�ssen alle Felder ausgef�llt sein");
                dialog.button("Ok", true);
                dialog.key(Keys.ENTER, true);
                dialog.show(stage);
            }
            return true;
        }
    });
    Table settingsTable = new Table();
    Table settings2ColTable = new Table();
    Table settings3ColTable = new Table();
    Table buttonTable = new Table();
    settings2ColTable.add(nameLabel).padBottom(30);
    settings2ColTable.add(nameField).padBottom(30).row();
    settings2ColTable.add(portLabel);
    settings2ColTable.add(portField).row();
    settings3ColTable.add(difficultyLabel).colspan(3).row();
    settings3ColTable.add(easyDifficultyCheckbox);
    settings3ColTable.add(normalDifficultyCheckbox);
    settings3ColTable.add(hardDifficultyCheckbox);
    settingsTable.left().top().add(settings2ColTable).padBottom(40).row();
    settingsTable.add(settings3ColTable).row();
    buttonTable.add(backButton);
    buttonTable.add(createButton).padLeft(65);
    mainTable.add(settingsTable).width(580).height(405);
    mainTable.row();
    mainTable.add(buttonTable).height(50).bottom();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) GameDifficulty(de.gg.data.GameSessionSetup.GameDifficulty) Sound(com.badlogic.gdx.audio.Sound) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ButtonGroup(com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup) GameSessionSetup(de.gg.data.GameSessionSetup) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

Table (com.badlogic.gdx.scenes.scene2d.ui.Table)85 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)51 Stage (com.badlogic.gdx.scenes.scene2d.Stage)48 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)36 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)35 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)31 Actor (com.badlogic.gdx.scenes.scene2d.Actor)30 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)25 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)21 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)18 Texture (com.badlogic.gdx.graphics.Texture)17 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)16 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)15 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)14 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)12 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)11 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)11 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)9 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)8