List of usage examples for com.badlogic.gdx.scenes.scene2d.ui TextField TextField
public TextField(String text, Skin skin, String styleName)
From source file:at.highstreeto.xnllayoutparser.element.TextFieldParser.java
License:Apache License
@Override public Actor load(Element element, LayoutParserContext context) throws LayoutParseException { String text = element.getText(); TextField textField = new TextField(text == null ? "" : text, context.getSkin(), ElementParserHelper.getStyle(element)); context.addActor(textField, element); ElementParserHelper.setActorName(element, textField); return textField; }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.UserScreen.java
License:Open Source License
private void addNewUserOptions() { addLabel("CREATE NEW USER", FONT_TITLE, FONT_SCALE, Color.WHITE, iX, iY).setTouchable(null); newUserTextField = new TextField("", getSkin(), "default"); newUserTextField.setSize(GlobalSettings.APPWIDTH * 3 / 4, (int) (50 * GlobalSettings.HD)); newUserTextField.setX(GlobalSettings.APPWIDTH / 8); newUserTextField.setY(iY + (GlobalSettings.ISHD ? -100 : -10)); // text that will be drawn in the text field if no text has been entered newUserTextField.setMessageText("Enter a new user"); newUserTextField.setTextFieldListener(newUserTextFieldListener); newUserTextField.setTextFieldFilter(newUserTextFilter); this.stage.addActor(newUserTextField); }
From source file:com.github.ykrasik.jaci.cli.libgdx.LibGdxCli.java
License:Apache License
/** * @param skin Skin to use./*ww w.ja v a 2 s .c o m*/ * @param hierarchy Command hierarchy. * @param maxBufferEntries Maximum amount of line entries in the buffer to keep. * @param maxCommandHistory Maximum amount of command history entries to keep. */ private LibGdxCli(Skin skin, CliCommandHierarchy hierarchy, int maxBufferEntries, int maxCommandHistory) { super(skin); // Buffer for cli output. final LibGdxCliOutputBuffer buffer = new LibGdxCliOutputBuffer(skin, maxBufferEntries); buffer.setName("buffer"); buffer.bottom().left(); // Label for 'working directory'. final Label workingDirectory = new Label("", skin, "workingDirectory"); workingDirectory.setName("workingDirectory"); // The above combine into a CliOutput. final CliOutput output = new LibGdxCliOutput(buffer, workingDirectory); // TextField as command line. final TextField commandLine = new TextField("", skin, "commandLine"); commandLine.setName("commandLine"); final CommandLineManager commandLineManager = new LibGdxCommandLineManager(commandLine); // LibGdx seems to ignore leading \t final CliSerializer serializer = new DefaultCliSerializer(" "); // Create the shell and the actual CLI. final CliShell shell = new CliShell.Builder(hierarchy, output).setSerializer(serializer) .setMaxCommandHistory(maxCommandHistory).build(); final Cli cli = new Cli(shell, commandLineManager); // Hook input events to CLI events. this.addListener(new LibGdxCliInputListener(cli)); // A close button. // TODO: Make this a graphical button, not an ugly text button. final Button closeButton = new TextButton("X", skin, "closeCliButton"); closeButton.padRight(15).padLeft(15); closeButton.setName("closeButton"); closeButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { setVisible(false); } }); // Some layout. final Table workingDirectoryTable = new Table(skin); workingDirectoryTable.setName("workingDirectoryTable"); workingDirectoryTable.setBackground("workingDirectoryBackground"); workingDirectoryTable.add(workingDirectory).fill().padLeft(3).padRight(5); // The bottom row contains the current path, command line and a close button. final Table bottomRow = new Table(skin); bottomRow.setName("bottomRow"); bottomRow.setBackground("bottomRowBackground"); bottomRow.add(workingDirectoryTable).fill(); bottomRow.add(commandLine).fill().expandX(); bottomRow.add(closeButton).fill(); this.setName("cli"); this.setBackground("cliBackground"); // TODO: This should operate on it's own stage. this.addVisibleListener(new VisibleListener() { @Override public void onVisibleChange(boolean wasVisible, boolean isVisible) { if (!wasVisible && isVisible) { setKeyboardFocus(commandLine); } } }); this.pad(0); this.add(buffer).fill().expand(); this.row(); this.add(bottomRow).fill(); this.top().left(); this.setFillParent(true); }
From source file:com.prisonbreak.game.MapControlRenderer.java
private void passUnlockInteraction() { // for door object if (objectItems.size == 1) { // end of "conversation" -> reset if (indexForMessageTree == messageTree.get(5).size) { state = STATE.ONGOING;//from w w w . j av a 2 s . c o m interactHappen = false; typeInteraction = TYPE_INTERACTION.NO_INTERACTION; indexForMessageTree = 0; dialogBoxLabel.remove(); return; } // first if (indexForMessageTree == 0) { // create conversation box dialogBoxLabel = new Label(messageTree.get(5).get(0), PrisonBreakGame.gameSkin, "custom"); dialogBoxLabel.setPosition(0, 0); dialogBoxLabel.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 5); dialogBoxLabel.setAlignment(Align.topLeft); stage.addActor(dialogBoxLabel); // check if Player have required card to unlock (obtained from the uniform) boolean haveIt = false; for (Item item : player.getInventory()) { if (item.getItemID() == 3) { // the required card in uniform - id = 3 haveIt = true; break; } } // if not if (!haveIt) { indexForMessageTree = messageTree.get(5).size - 1; } } // second else if (indexForMessageTree == 1) { dialogBoxLabel.setText(messageTree.get(5).get(1)); // create a List contain Yes/No options Array<String> options = new Array<String>(); options.add("Yes"); options.add("No"); itemList = new List(PrisonBreakGame.gameSkin, "custom"); itemList.setItems(options); itemList.setSelectedIndex(0); itemList.setSize(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 3); itemList.setPosition(Gdx.graphics.getWidth() - itemList.getWidth(), dialogBoxLabel.getHeight()); itemList.addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { int currentIndex = itemList.getSelectedIndex(); int upIndex = currentIndex - 1; int downIndex = currentIndex + 1; if (upIndex < 0) upIndex = itemList.getItems().size - 1; if (downIndex >= itemList.getItems().size) downIndex = 0; switch (keycode) { case Keys.UP: // scroll up the option list itemList.setSelectedIndex(upIndex); break; case Keys.DOWN: // scroll down the option list itemList.setSelectedIndex(downIndex); break; case Keys.F: // if Player chooses "No" -> end the dialog // otherwise; let it continue on if (itemList.getSelectedIndex() == 1) { indexForMessageTree = messageTree.get(5).size; } // remove list of items from stage itemList.remove(); resetInputProcessor(); break; default: break; } return true; } }); stage.addActor(itemList); stage.setKeyboardFocus(itemList); // set InputProcessor to stage Gdx.input.setInputProcessor(stage); } // third else if (indexForMessageTree == 2) { dialogBoxLabel.setText(messageTree.get(5).get(2)); // create a TextField for player to enter password passField = new TextField("Full name", PrisonBreakGame.gameSkin, "default"); passField.setHeight(25); passField.setPosition(Gdx.graphics.getWidth() / 2 - passField.getWidth() / 2, Gdx.graphics.getHeight() / 2 - passField.getHeight() / 2); stage.addActor(passField); // create button, goes with the textfield txtButton = new TextButton("Enter", PrisonBreakGame.gameSkin, "round"); txtButton.setHeight(passField.getHeight()); txtButton.setPosition(passField.getWidth() + passField.getX(), passField.getY()); txtButton.addListener(new ClickListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { // if player enters correct name of any guards -> unlock the door // note: in this case, we only check for the name 'Henry Karvick' String enterName = passField.getText(); if (enterName.equalsIgnoreCase(objectItems.first().getDescription())) { // unlock the door // set "locked" to false in object of DoorCollision MapObject object = doorObjects.get(latestObjectName); object.getProperties().put("locked", false); // set "locked" to false in object of ObjectInteration object = interactionObjects.get(latestObjectName); object.getProperties().put("locked", false); dialogBoxLabel.setText("Valid name."); } // enter wrong name else { dialogBoxLabel.setText("Invalid name."); // end the dialog indexForMessageTree = messageTree.get(5).size; } passField.remove(); // remove actors from stage txtButton.remove(); resetInputProcessor(); // reset InputProcessor to MapControlRenderer return true; } }); stage.addActor(txtButton); Gdx.input.setInputProcessor(stage); } // others else { dialogBoxLabel.setText(messageTree.get(5).get(indexForMessageTree)); } ++indexForMessageTree; } // for safe locker object else { // end of "conversation" -> reset if (indexForMessageTree == messageTree.get(6).size) { state = STATE.ONGOING; interactHappen = false; typeInteraction = TYPE_INTERACTION.NO_INTERACTION; indexForMessageTree = 0; dialogBoxLabel.remove(); return; } // first if (indexForMessageTree == 0) { // create conversation box dialogBoxLabel = new Label(messageTree.get(6).get(0), PrisonBreakGame.gameSkin, "custom"); dialogBoxLabel.setPosition(0, 0); dialogBoxLabel.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 5); dialogBoxLabel.setAlignment(Align.topLeft); stage.addActor(dialogBoxLabel); // create a TextField + TextButton -> prompt for password to unlock the safe locker // textfield passField = new TextField("", PrisonBreakGame.gameSkin, "default"); passField.setHeight(25); passField.setPosition(Gdx.graphics.getWidth() / 2 - passField.getWidth() / 2, Gdx.graphics.getHeight() / 2 - passField.getHeight() / 2); stage.addActor(passField); // textbutton txtButton = new TextButton("Enter", PrisonBreakGame.gameSkin, "round"); txtButton.setHeight(passField.getHeight()); txtButton.setPosition(passField.getWidth() + passField.getX(), passField.getY()); txtButton.addListener(new ClickListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { // if Player enters the correct password -> unlock the safe locker // -> Player obtains all items in it // password: 3863 - get from object in the map String enterPass = passField.getText(); if (enterPass.equalsIgnoreCase(objectItems.first().getDescription())) { // unlock the safe locker // set "locked" to false in object of ObjectInteraction MapObject object = interactionObjects.get(latestObjectName); object.getProperties().put("locked", false); dialogBoxLabel.setText("*Clicked*"); } // enter wrong password else { dialogBoxLabel.setText("Wrong password!"); // end the dialog indexForMessageTree = messageTree.get(6).size; } passField.remove(); // remove actors from stage txtButton.remove(); resetInputProcessor(); // reset InputProcessor to MapControlRenderer return true; } }); stage.addActor(txtButton); Gdx.input.setInputProcessor(stage); } // last - message when obtain items else if (indexForMessageTree == messageTree.get(6).size - 1) { dialogBoxLabel.setText(messageTree.get(6).get(indexForMessageTree) + objectItems.get(indexRemainingItems).getItemName()); // add the corresponding item into Player's inventory // player.getInventory().add(objectItems.get(indexRemainingItems++)); player.addItem(objectItems.get(indexRemainingItems++)); if (indexRemainingItems < objectItems.size) { --indexForMessageTree; } } // others else { dialogBoxLabel.setText(messageTree.get(6).get(indexForMessageTree)); } ++indexForMessageTree; } }
From source file:org.shadebob.skineditor.actors.PreviewPane.java
License:Apache License
/** * /*from w ww . ja va 2s.c o m*/ */ 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 ProgressBar w = new ProgressBar(0, 100, 5, false, game.skinProject, key); 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")) { // 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(); } }