List of usage examples for com.badlogic.gdx.scenes.scene2d.ui List List
public List(Skin skin, String styleName)
From source file:at.hid.tabletopsimulator.screens.About.java
License:Apache License
@Override public void show() { TableTopSimulator.debug(this.getClass().toString(), "creating About screen"); stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); Gdx.input.setInputProcessor(stage);//from w w w . j av a 2 s. co m // creating skin TableTopSimulator.debug(this.getClass().toString(), "creating skin"); skin = TableTopSimulator.assets.get("ui/gui.json", Skin.class); table = new Table(skin); // table.setFillParent(true); // table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // creating heading TableTopSimulator.debug(this.getClass().toString(), "creating heading"); Label lblHeading = new Label(TableTopSimulator.getLangBundle().format("About.lblHeading.text"), skin); final Label lblContent = new Label("http://libgdx.badlogicgames.com/\r\n" + "\r\n" + "libGDX is licensed under the Apache 2 License,\r\n" + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n" + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!", skin, "content"); // creating list final List<String> listAbout = new List<String>(skin, "content"); ArrayList<String> newItems = new ArrayList<String>(); newItems.add("libgdx"); newItems.add("libgdx-utils"); newItems.add("flare gameart"); String[] data = new String[newItems.size()]; listAbout.setItems(newItems.toArray(data)); listAbout.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (listAbout.getSelected().equals("libgdx")) { lblContent.clear(); lblContent.setText("http://libgdx.badlogicgames.com/\r\n" + "\r\n" + "libGDX is licensed under the Apache 2 License,\r\n" + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n" + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!"); } else if (listAbout.getSelected().equals("libgdx-utils")) { lblContent.clear(); lblContent.setText("https://bitbucket.org/dermetfan/libgdx-utils/wiki/Home\r\n" + "\r\n" + "/* Copyright (c) 2014 PixelScientists\r\n" + "*\r\n" + "* The MIT License (MIT)\r\n" + "*\r\n" + "* Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n" + "* this software and associated documentation files (the \"Software\"), to deal in\r\n" + "* the Software without restriction, including without limitation the rights to\r\n" + "* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n" + "* the Software, and to permit persons to whom the Software is furnished to do so,\r\n" + "* subject to the following conditions:\r\n" + "*\r\n" + "* The above copyright notice and this permission notice shall be included in all\r\n" + "* copies or substantial portions of the Software.\r\n" + "*\r\n" + "* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n" + "* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n" + "* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n" + "* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n" + "* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n" + "* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n" + "*/"); } else if (listAbout.getSelected().equals("flare gameart")) { lblContent.clear(); lblContent.setText("https://github.com/clintbellanger/flare-game\r\n" + "\r\n" + "Flare (the game) is Copyright 2010-2013 Clint Bellanger. Contributors retain copyrights to their original contributions.\r\n" + "\r\n" + "The Flare Engine is released under GPL version 3 or later.\r\n" + "\r\n" + "All of Flare's art and data files are released under CC-BY-SA 3.0. Later versions are permitted.\r\n" + "\r\n" + "The Liberation Sans fonts version 2 are released under the SIL Open Font License, Version 1.1.\r\n" + "\r\n" + "The GNU Unifont font is released under GPL v2, with the exception that embedding the font in a document does not in itself bind that document to the terms of the GPL."); } } }); // creating buttons TableTopSimulator.debug(this.getClass().toString(), "creating buttons"); TextButton btnBack = new TextButton(TableTopSimulator.getLangBundle().format("About.btnBack.text"), skin); btnBack.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { TableTopSimulator.debug(this.getClass().toString(), "switching to Options screen"); ((Game) Gdx.app.getApplicationListener()).setScreen(new Options()); dispose(); } }); btnBack.pad(10); ScrollPane spAboutList = new ScrollPane(null, skin); ScrollPane spAboutContent = new ScrollPane(null, skin); SplitPane splitAbout = new SplitPane(spAboutList, spAboutContent, false, skin); splitAbout.setSplitAmount(0.2f); spAboutList.setWidget(listAbout); spAboutContent.setWidget(lblContent); // building ui TableTopSimulator.debug(this.getClass().toString(), "building ui"); table.add(lblHeading).spaceBottom(100).row(); table.add(splitAbout).spaceBottom(15).width(1200).row(); table.add(btnBack).spaceBottom(15).row(); if (TableTopSimulator.DEBUG) { table.debug(); // draw debug lines splitAbout.debug(); // draw debug lines } stage.addActor(table); }
From source file:com.prisonbreak.game.MapControlRenderer.java
private void showHideInventory() { // create an array of names of Player's items Array<String> names = new Array<String>(); if (player.getInventory().size == 0) { names.add("Nothing"); } else {/*w w w.j a va2 s. c o m*/ for (Item item : player.getInventory()) { names.add(item.getItemName()); } } // create the List panel to display the inventory inventory = new List(PrisonBreakGame.gameSkin, "dimmed"); inventory.setItems(names); inventory.setSelectedIndex(0); inventory.setSize(Gdx.graphics.getWidth() / 6, Gdx.graphics.getHeight() / 2); inventory.setPosition(Gdx.graphics.getWidth() * 3 / 4 - inventory.getWidth() / 2, Gdx.graphics.getHeight() / 2 - inventory.getHeight() / 2); // create the description Label to display description of each item descLabel = new Label("", PrisonBreakGame.gameSkin, "custom-small"); descLabel.setSize(Gdx.graphics.getWidth() / 6, Gdx.graphics.getHeight() / 4); descLabel.setPosition(inventory.getX() + inventory.getWidth(), inventory.getY() + inventory.getHeight() - descLabel.getHeight()); descLabel.setAlignment(Align.topLeft); descLabel.setWrap(true); if (player.getInventory().size > 0) { descLabel.setText(player.getInventory().get(inventory.getSelectedIndex()).getDescription()); } stage.addActor(descLabel); // create title: Inventory titleLabel = new Label("INVENTORY", PrisonBreakGame.gameSkin, "subtitle"); titleLabel.setSize(inventory.getWidth(), titleLabel.getHeight() * 3 / 2); titleLabel.setPosition(inventory.getX(), inventory.getY() + inventory.getHeight()); titleLabel.setAlignment(Align.center); stage.addActor(titleLabel); // add InputListener to inventory inventory.addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { int currentIndex = inventory.getSelectedIndex(); int upIndex = currentIndex - 1; int downIndex = currentIndex + 1; String desc = ""; if (upIndex < 0) upIndex = inventory.getItems().size - 1; if (downIndex >= inventory.getItems().size) downIndex = 0; switch (keycode) { case Keys.UP: // scroll up the item objectItems inventory.setSelectedIndex(upIndex); // display the corresponding description in descLabel if (player.getInventory().size > 0) desc = player.getInventory().get(upIndex).getDescription(); descLabel.setText(desc); break; case Keys.DOWN: // scroll down the item objectItems inventory.setSelectedIndex(downIndex); // display the corresponding description in descLabel if (player.getInventory().size > 0) desc = player.getInventory().get(downIndex).getDescription(); descLabel.setText(desc); break; case Keys.I: // if the inventory is currently opened, press I again // to close descLabel.remove(); // remove actors inventory.remove(); titleLabel.remove(); state = STATE.ONGOING; // unpause the game resetInputProcessor(); // reset InputProcessor to this MapControlRenderer break; default: break; } return true; } }); stage.addActor(inventory); stage.setKeyboardFocus(inventory); Gdx.input.setInputProcessor(stage); // change InputProcessor to stage }
From source file:com.prisonbreak.game.MapControlRenderer.java
private void searchInteraction() { // if no items if (objectItems == null) { if (indexForMessageTree == messageTree.get(0).size) { state = STATE.ONGOING; // unpause the game interactHappen = false; // flip the flag again typeInteraction = TYPE_INTERACTION.NO_INTERACTION; // reset type of interaction to // NO_INTERACTION indexForMessageTree = 0;/*from ww w.ja va 2 s .c o m*/ dialogBoxLabel.remove(); return; } // create conversation box // for the first message if (indexForMessageTree == 0) { dialogBoxLabel = new Label(messageTree.get(0).get(0), PrisonBreakGame.gameSkin, "custom"); dialogBoxLabel.setPosition(0, 0); dialogBoxLabel.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 5); dialogBoxLabel.setAlignment(Align.topLeft); // dialogBoxLabel.setFontScale(2f); stage.addActor(dialogBoxLabel); } // for every next message else { dialogBoxLabel.setText(messageTree.get(0).get(indexForMessageTree)); } ++indexForMessageTree; // increment index } // if it does contain items else { // Gdx.app.log("class: ", "" + objectItems.getClass()); if (indexForMessageTree == messageTree.get(1).size) { state = STATE.ONGOING; // unpause the game interactHappen = false; // flip the flag again typeInteraction = TYPE_INTERACTION.NO_INTERACTION; // reset type of interaction to // NO_INTERACTION indexForMessageTree = 0; dialogBoxLabel.remove(); return; } // in case Player choose "Nothing" -> does not pick anything if (indexForMessageTree > messageTree.get(1).size) { indexForMessageTree = messageTree.get(1).size; return; } // for the first message if (indexForMessageTree == 0) { // create a String array of items' names Array<String> itemNames = new Array<String>(); for (Item item : objectItems) { itemNames.add(item.getItemName()); } itemNames.add("Nothing"); // add additional value - for not choosing any items // create conversation box dialogBoxLabel = new Label(messageTree.get(1).get(0), PrisonBreakGame.gameSkin, "custom"); dialogBoxLabel.setPosition(0, 0); dialogBoxLabel.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 5); dialogBoxLabel.setAlignment(Align.topLeft); // dialogBoxLabel.setFontScale(2f); stage.addActor(dialogBoxLabel); // create objectItems of items itemList = new List(PrisonBreakGame.gameSkin, "custom"); itemList.setItems(itemNames); 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; // Gdx.app.log("currentIndex: ", "" + currentIndex); // Gdx.app.log("upIndex: ", "" + upIndex); // Gdx.app.log("downIndex: ", "" + downIndex); switch (keycode) { case Keys.UP: // scroll up the item list itemList.setSelectedIndex(upIndex); break; case Keys.DOWN: // scroll down the item list itemList.setSelectedIndex(downIndex); break; case Keys.F: int index = itemList.getSelectedIndex(); // if Player chooses "Nothing" if ("Nothing".equals((String) itemList.getSelected())) { // remove list of items from stage itemList.remove(); // confirm the selection dialogBoxLabel.setText("You choose nothing."); // end the "conversation" indexForMessageTree = messageTree.get(1).size + 1; resetInputProcessor(); break; } // otherwise; // add the chosen item into Player's objectItems of items player.addItem(objectItems.get(index)); // remove that item from the overall listItems objectItems.removeIndex(index); // remove list of items from stage itemList.remove(); // reconfirm message dialogBoxLabel.setText(messageTree.get(1).get(indexForMessageTree)); resetInputProcessor(); break; default: break; } return true; } }); stage.addActor(itemList); stage.setKeyboardFocus(itemList); // set InputProcessor to stage Gdx.input.setInputProcessor(stage); } // for every next message else { dialogBoxLabel.setText(messageTree.get(1).get(indexForMessageTree) + player.getInventory().get(player.getInventory().size - 1).getItemName() + "."); } ++indexForMessageTree; // increment index } }
From source file:com.prisonbreak.game.MapControlRenderer.java
private void openLockInteraction() { if (objectItems == null) { Gdx.app.log("Error in locked door: ", "objectItems == null"); return;/*w w w. j av a 2 s .c o m*/ } // if the door is locked if (latestDoorLocked) { // end of "conversation" -> reset if (indexForMessageTree == messageTree.get(2).size) { state = STATE.ONGOING; interactHappen = false; typeInteraction = TYPE_INTERACTION.NO_INTERACTION; indexForMessageTree = 0; neededKey = null; latestDoorLocked = false; // latestObjectName = ""; dialogBoxLabel.remove(); return; } // first if (indexForMessageTree == 0) { // create conversation box dialogBoxLabel = new Label(messageTree.get(2).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 the needed "key" to unlock boolean haveIt = false; for (Item item : player.getInventory()) { if (item.getItemID() == objectItems.get(0).getItemID()) { haveIt = true; neededKey = item; break; } } // Gdx.app.log("haveIt: ", "" + haveIt); // if Player DOEST NOT have the neccessary key -> end the "conversation" dialog // otherwise; let it go on if (!haveIt) { indexForMessageTree = messageTree.get(2).size - 1; } } // second else if (indexForMessageTree == 1) { dialogBoxLabel.setText(messageTree.get(2).get(1) + " " + neededKey.getItemName() + "."); } // third else if (indexForMessageTree == 2) { dialogBoxLabel.setText(messageTree.get(2).get(2)); // 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 choose "Yes" -> unlock the door if (itemList.getSelectedIndex() == 0) { // 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); // set "locked" to false in object of ... } // if "No" -> end dialog "conversation" else { indexForMessageTree = messageTree.get(2).size; // end the dialog } // 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); } // others else { dialogBoxLabel.setText(messageTree.get(2).get(indexForMessageTree)); } ++indexForMessageTree; } // if current door is not locked else { // end of "conversation" -> reset if (indexForMessageTree == messageTree.get(3).size) { state = STATE.ONGOING; interactHappen = false; typeInteraction = TYPE_INTERACTION.NO_INTERACTION; indexForMessageTree = 0; neededKey = null; latestDoorLocked = false; // latestObjectName = ""; dialogBoxLabel.remove(); return; } // first if (indexForMessageTree == 0) { // create conversation box dialogBoxLabel = new Label(messageTree.get(3).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 the requied key to lock the door boolean haveIt = false; for (Item item : player.getInventory()) { if (item.getItemID() == objectItems.get(0).getItemID()) { haveIt = true; neededKey = item; } } // if Player DOEST NOT have the neccessary key -> end the "conversation" dialog // otherwise; let it go on if (!haveIt) { indexForMessageTree = messageTree.get(3).size - 1; } } // second else if (indexForMessageTree == 1) { dialogBoxLabel.setText(messageTree.get(3).get(1) + " " + neededKey.getItemName() + "."); } // third else if (indexForMessageTree == 2) { dialogBoxLabel.setText(messageTree.get(3).get(2)); // 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 item objectItems itemList.setSelectedIndex(upIndex); break; case Keys.DOWN: // scroll down the item objectItems itemList.setSelectedIndex(downIndex); break; case Keys.F: // if Player choose "Yes" -> lock the door if (itemList.getSelectedIndex() == 0) { // set "locked" to true in object of DoorCollision MapObject object = doorObjects.get(latestObjectName); object.getProperties().put("locked", true); // set "locked" to true in object of ObjectInteration object = interactionObjects.get(latestObjectName); object.getProperties().put("locked", true); // set "locked" to true in object of ... } // if "No" -> end dialog "conversation" else { indexForMessageTree = messageTree.get(3).size; // end the dialog } // 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); } // others else { dialogBoxLabel.setText(messageTree.get(3).get(indexForMessageTree)); } ++indexForMessageTree; } }
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 www .j a va 2 s .co 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:com.prisonbreak.game.MapControlRenderer.java
private void breakInteraction() { // end of "conversation" -> reset if (indexForMessageTree == messageTree.get(7).size) { state = STATE.ONGOING;/*from w w w . ja v 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(7).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 has the required item to break the door boolean haveIt = false; for (Item item : player.getInventory()) { if (item.getItemID() == objectItems.first().getItemID()) { haveIt = true; break; } } // if not -> end the dialog if (!haveIt) { indexForMessageTree = messageTree.get(7).size - 1; } } // third else if (indexForMessageTree == 2) { dialogBoxLabel.setText(messageTree.get(7).get(2)); // 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 choose "Yes" -> crack the door open if (itemList.getSelectedIndex() == 0) { // remove the door // extract neccessary attributes MapObject object = doorObjects.get(latestObjectName); String layerName = object.getProperties().get("tileLayerName", "", String.class); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(layerName); int x = object.getProperties().get("lowerLeftX", Integer.class); int y = object.getProperties().get("lowerLeftY", Integer.class); // extract the tiles of the door tile1 = layer.getCell(x, y).getTile(); // lower left tile2 = layer.getCell(x + 1, y).getTile(); // lower right tile3 = layer.getCell(x, y + 1).getTile(); // upper left tile4 = layer.getCell(x + 1, y + 1).getTile(); // upper right // "erase" the door layer.getCell(x, y).setTile(null); layer.getCell(x + 1, y).setTile(null); layer.getCell(x, y + 1).setTile(null); layer.getCell(x + 1, y + 1).setTile(null); // set "locked" to false in object of DoorCollision object = doorObjects.get(latestObjectName); object.getProperties().put("locked", false); // set "broken" to true in object of ObjectInteration object = interactionObjects.get(latestObjectName); object.getProperties().put("broken", true); } // if "No" -> end dialog "conversation" else { indexForMessageTree = messageTree.get(7).size; // end the dialog } // 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); } // others else { dialogBoxLabel.setText(messageTree.get(7).get(indexForMessageTree)); } ++indexForMessageTree; }
From source file:de.cwclan.gdxtest.core.screens.LevelMenu.java
@Override public void show() { stage = new Stage(); Gdx.input.setInputProcessor(stage);//from ww w . j a va 2 s .co m skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), new TextureAtlas("ui/atlas.pack")); List list = new List(new String[] { "de.cwclan.gdxtest.core.games.CarGame", "de.cwclan.gdxtest.core.games.JumperGame", "de.cwclan.gdxtest.core.games.TiledGame" }, skin); list.setSelectedIndex(0); ScrollPane scrollPane = new ScrollPane(list, skin); scrollPane.setWidth(30); TextButton playButton = new TextButton("Druf da", skin); playButton.pad(5); playButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { try { Class<? extends Screen> clazz = (Class<? extends Screen>) Class.forName(list.getSelection()); Screen screen = clazz.newInstance(); ((Game) Gdx.app.getApplicationListener()).setScreen(screen); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { System.err.println(ex.getMessage()); } } }); TextButton backButton = new TextButton("zurck", skin, "small"); backButton.pad(5); backButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu()); } }); table = new Table(skin); table.setFillParent(true); table.debug(); table.setFillParent(true); table.add("Select Level", "big").colspan(3).expandX().spaceBottom(50).row(); table.add(scrollPane).uniformX().left().expandY(); table.add(playButton).uniformX(); table.add(backButton).uniformY().bottom().right(); stage.addActor(table); }
From source file:de.longri.cachebox3.develop.tools.skin_editor.actors.OptionsPane.java
License:Apache License
/** * *///from ww w. j a v a2 s . c o m public OptionsPane(final SkinEditorGame game, PreviewPane previewPane) { super(); //this.setDebug(true); this.game = game; this.previewPane = previewPane; left(); top(); setBackground(game.skin.getDrawable("default-pane")); styleLabelCell = add(new Label("Styles", game.skin, "title")).pad(5); styleLabelCell.row(); styleLabelCellPrefHeight = styleLabelCell.getPrefHeight(); listStyles = new List<String>(game.skin, "dimmed"); listStyles.setItems(listItems); ScrollPane styleScrollPane = new ScrollPane(listStyles, game.skin); styleScrollPane.setFlickScroll(false); styleScrollPane.setFadeScrollBars(false); styleScrollPane.setScrollbarsOnTop(true); styleScrollPane.setScrollBarPositions(false, true); styleScrollPane.setScrollingDisabled(true, false); styleCell = add(styleScrollPane).height(200).expandX().fillX().pad(5); styleCell.row(); // Add buttons Table tableStylesButtons = new Table(); TextButton buttonNewStyle = new TextButton("New Style", game.skin); TextButton buttonDeleteStyle = new TextButton("Delete Style", game.skin); tableStylesButtons.add(buttonNewStyle).pad(5); tableStylesButtons.add(buttonDeleteStyle).pad(5); styleButtonCell = add(tableStylesButtons); styleButtonCell.row(); styleButtonCellPrefHeight = styleButtonCell.getPrefHeight(); // Callbacks listStyles.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { String key = (String) listStyles.getSelected(); if (key != null) { Gdx.app.log("OptionsPane", "Selected style: " + key); currentStyle = styles.get(key); updateTableFields(key); } } }); buttonNewStyle.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { createNewStyle(); } }); buttonDeleteStyle.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { showDeleteDialog(); } }); // Initialize table add(new Label("Fields", game.skin, "title")).pad(5).padTop(10).row(); tableFields = new Table(game.skin); tableFields.setBackground(game.skin.getDrawable("dialogDim")); tableFields.left().top(); ScrollPane scroll2 = new ScrollPane(tableFields, game.skin); scroll2.setFlickScroll(false); scroll2.setFadeScrollBars(false); scroll2.setScrollbarsOnTop(true); scroll2.setScrollBarPositions(false, true); scroll2.setScrollingDisabled(true, false); add(scroll2).pad(5).expand().fill(); this.layout(); }
From source file:nl.basroding.explorer.scenes.gamescene.ui.PlanetInfo.java
public PlanetInfo() { String[] attributes = { "Name:", "Radius:", "Temperature:" }; attributesList = new List(attributes, UIOverlay.defaultSkin); attributesList.setSelectable(false); String[] values = { "Jupiter", "14364240024 km", "-42 degrees" }; valueList = new List(values, UIOverlay.defaultSkin); valueList.setSelectable(false);//from w ww . jav a2 s.com valueList.setX(attributesList.getWidth() + 25); addActor(attributesList); addActor(valueList); this.setWidth(200); this.setHeight(attributesList.getHeight()); }
From source file:nl.basroding.explorer.scenes.gamescene.ui.RocketInfo.java
public RocketInfo() { String[] attributes = { "Name:", "Speed:", "Heading for:" }; attributesList = new List(attributes, UIOverlay.defaultSkin); attributesList.setSelectable(false); String[] values = { "Explorer #13", "100000 km/h", "Jupiter" }; valueList = new List(values, UIOverlay.defaultSkin); valueList.setSelectable(false);/*from w w w. ja v a2 s .c om*/ valueList.setX(attributesList.getWidth() + 25); button = new TextButton("Set course", UIOverlay.defaultSkin); addActor(attributesList); addActor(valueList); addActor(button); this.setWidth(200); this.setHeight(attributesList.getHeight()); }