List of usage examples for com.badlogic.gdx.scenes.scene2d.ui TextField setText
public void setText(String str)
From source file:com.digitale.screens.CharCreator.java
License:Open Source License
public CharCreator(final Integer muser) { Stardust3d.currencharacteruid = "" + Stardust3d.charList[0].getUid(); // populate avatardropdown for (int i = 0; i < Stardust3d.avatarList.size(); i++) { listEntries[i] = Stardust3d.avatarList.get(i).getDescription(); // do avatar dropdown population from db here }//from w ww .j a v a2s.c om selectedAvatar = ("avatar00.jpg"); OrthographicCamera camera; batch = new SpriteBatch(); skin = new Skin(Gdx.files.internal("data/uiskin.json"), Gdx.files.internal("data/uiskin.png")); xfadeTexture = new Texture(Gdx.files.internal("data/blackpixel.png"), Format.RGB565, true); xfadeTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); background = new Texture(Gdx.files.internal("data/bgpland.jpg")); camera = new OrthographicCamera(); camera.setToOrtho(false, Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getHeight()); fadeIn(); stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); Gdx.input.setInputProcessor(stage); // Group.debug = true; final Button buttonSaveCharacter = new TextButton("Save Character", skin.getStyle(TextButtonStyle.class), "button-save-char"); final Button buttonCancel = new TextButton("Cancel", skin.getStyle(TextButtonStyle.class), "button-cancel"); final Button buttonRandName = new TextButton("Generate Random Name", skin.getStyle(TextButtonStyle.class), "button-random-name"); final SelectBox dropdown = new SelectBox(listEntries, skin.getStyle(SelectBoxStyle.class), "combo"); final SelectBox dropdownsex = new SelectBox(listsexEntries, skin.getStyle(SelectBoxStyle.class), "combosex"); final SelectBox dropdownrace = new SelectBox(listraceEntries, skin.getStyle(SelectBoxStyle.class), "comborace"); final TextField textfieldFirstName = new TextField("", "Firstname", skin.getStyle(TextFieldStyle.class), "textfieldfirstname"); final TextField textfieldSurName = new TextField("", "Surname", skin.getStyle(TextFieldStyle.class), "textfieldsurname"); final Label lableracepicker = new Label("Race", skin.getStyle(LabelStyle.class), "label-race-picker"); final Label lablesexpicker = new Label("Sex", skin.getStyle(LabelStyle.class), "label-sex-picker"); final Label lableportraitpicker = new Label("Portrait", skin.getStyle(LabelStyle.class), "label-portrait-picker"); final Label lablefirstname = new Label("First name", skin.getStyle(LabelStyle.class), "label-firstname"); final Label lablesurname = new Label("Surname", skin.getStyle(LabelStyle.class), "label-surname"); imageActor = new Image(image0); final FlickScrollPane scrollPane = new FlickScrollPane(imageActor, "flickscroll"); final List list = new List(listEntries, skin.getStyle(ListStyle.class), "list"); final ScrollPane scrollPane2 = new ScrollPane(list, skin.getStyle(ScrollPaneStyle.class), "scroll"); scrollPane2.setWidget(list); final SplitPane splitPane = new SplitPane(scrollPane, scrollPane, false, skin.getStyle("default-horizontal", SplitPaneStyle.class), "split"); final Label lablerace = new Label(racetext, skin.getStyle(LabelStyle.class), "label-race"); lablerace.setWrap(true); final ScrollPane scrollPanerace = new ScrollPane(lablerace, skin.getStyle(ScrollPaneStyle.class), "scroll"); // set defaults selectedAvatar = (Stardust3d.avatarList.get(0).getImagename()); racetext = "Humans small size compared to other races, nimble hands and excellent sight allows them to handle thier ships with more finesse than other races."; racetext = racetext + "\n\n Racial Bonus:- +1 to dexterity."; racetext = racetext + "\n Skilled with Human ships and weaponry."; PrimaryStat = "Stamina " + 1 + "\nIntelligence " + 1 + "\nSocial " + 1 + "\nDexterity " + 2 + "\nLeadership " + 1 + "\nRecuperation " + 1 + ""; final Label PrimaryStatLabel = new Label(PrimaryStat + Stardust3d.myCharacter.getIntelligence(), skin.getStyle(LabelStyle.class), "primary-stat"); Window window = new Window("Create Character", skin.getStyle(WindowStyle.class), "window"); if (Stardust3d.DEBUG) window.debug(); window.x = window.y = 0; window.setFillParent(true); window.setMovable(false); window.defaults().pad(5); window.defaults().spaceBottom(5).align("top"); window.row().fill().expandX(); window.add(buttonCancel).colspan(2); window.add().colspan(2).maxWidth(200); window.add(buttonSaveCharacter).colspan(2); window.row(); window.add(lableracepicker).align("middleleft"); window.add(dropdownrace).colspan(1).maxHeight(32); window.add(lableportraitpicker).align("middleleft"); window.add(dropdown).colspan(1).maxHeight(32); window.add(lablesexpicker).align("middleleft"); window.add(dropdownsex).colspan(1).maxHeight(32); window.row(); window.add(scrollPanerace).fill().expand().colspan(2).align("topleft"); window.add(PrimaryStatLabel).colspan(2); window.add().minHeight(256).colspan(2); window.row(); window.add(lablefirstname).align("middleleft"); window.add(textfieldFirstName); window.add(lablesurname).align("middleleft"); window.add(textfieldSurName); window.add(buttonRandName).colspan(2); window.pack(); stage.addActor(window); dropdown.setSelectionListener(new SelectionListener() { @Override public void selected(Actor actor, int index, String value) { SoundManager.playuiclick(); selectedAvatar = (Stardust3d.avatarList.get(index).getImagename()); } }); dropdownsex.setSelectionListener(new SelectionListener() { @Override public void selected(Actor actor, int index, String value) { SoundManager.playuiclick(); selectedSex = value; } }); dropdownrace.setSelectionListener(new SelectionListener() { @Override public void selected(Actor actor, int index, String value) { SoundManager.playuiclick(); switch (index) { case 0: racetext = "Humans small size compared to other races, nimble hands and excellent sight allows them to handle thier ships with more finesse than other races."; racetext = racetext + "\n\n Racial Bonus:- +1 to dexterity."; racetext = racetext + "\n Skilled with Human ships and weaponry."; selectedRace = "Human"; PrimaryStat = "Stamina " + 1 + "\nIntelligence " + 1 + "\nSocial " + 1 + "\nDexterity " + 2 + "\nLeadership " + 1 + "\nRecuperation " + 1; break; case 1: racetext = "Jelkek are a war-like race, for generations they have subjugated the Orinians to further their technological advancement. Fearless and bloodthirsty tendencies make their combat pilots unequalled."; racetext = racetext + "\n\n Racial Bonus:- +1 to recuperation."; racetext = racetext + "\n Skilled with Jelkek ships and weaponry."; selectedRace = "Jelkek"; PrimaryStat = "Stamina " + 1 + "\nIntelligence " + 1 + "\nSocial " + 1 + "\nDexterity " + 1 + "\nLeadership " + 1 + "\nRecuperation " + 2; break; case 2: racetext = "Orinians are masters of biotechnology, their skills make them the foremost manufacturers in the universe."; racetext = racetext + "\n\n Racial Bonus:- +1 to intelligence."; racetext = racetext + "\n Skilled with Orinian ships and weaponry."; selectedRace = "Orinian"; PrimaryStat = "Stamina " + 1 + "\nIntelligence " + 2 + "\nSocial " + 1 + "\nDexterity " + 1 + "\nLeadership " + 1 + "\nRecuperation " + 1; break; case 3: racetext = "Gulhurg colonies are unarguably the most complex systems known to science. Their hive-like social structure gives them an unrivalled empathy with others, making them excellent traders."; racetext = racetext + "\n\n Racial Bonus:- +1 to social."; racetext = racetext + "\n Skilled with Gulhurg ships and weaponry."; selectedRace = "Gulhurg"; PrimaryStat = "Stamina " + 1 + "\nIntelligence " + 1 + "\nSocial " + 2 + "\nDexterity " + 1 + "\nLeadership " + 1 + "\nRecuperation " + 1; break; } } }); buttonSaveCharacter.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { if (Stardust3d.DEBUG) System.out.println("Charmaker Complete"); if (textfieldFirstName.getText().length() < 1) { SoundManager.playError(); stage.addActor(Actors.bottomToast("Character first name cannot be blank.", 4, skin)); } else { SoundManager.playuiclick(); // populate game from db, based on this char // Stardust3d.gameMode = 4; String result = Stardust3d.MyDataOp.makeAvatar(selectedAvatar, selectedRace, selectedSex, textfieldFirstName.getText(), textfieldSurName.getText(), muser); if (Stardust3d.DEBUG) System.out.println(LOG_TAG + "Everworld: char creation result: " + result); if (result.trim().equals("ok")) { Stardust3d.gameMode = 3; // repopulate players characters Stardust3d.populateCharacterlist(Stardust3d.muser); doneflag = true; } else { SoundManager.playError(); stage.addActor(Actors.bottomToast("This character name is taken, please choose another.", 4, skin)); } } } }); buttonCancel.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { SoundManager.playuiclick(); stage.addActor(Actors.bottomToast("Cancelling character creation", 4, skin)); doneflag = true; Stardust3d.gameMode = 3; } }); buttonRandName.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { SoundManager.playuiclick(); // generate human female name if (selectedSex.equals("Female") && selectedRace.equals("Human")) { Stardust3d.MyDataOp.getRandomHumanFemaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate human male name } else if (selectedSex.equals("Male") && selectedRace.equals("Human")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Jelkek female name } else if (selectedSex.equals("Female") && selectedRace.equals("Jelkek")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Jelkek male name } else if (selectedSex.equals("Male") && selectedRace.equals("Jelkek")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Orinian female name } else if (selectedSex.equals("Female") && selectedRace.equals("Orinian")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Orinain male name } else if (selectedSex.equals("Male") && selectedRace.equals("Orinain")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Gulhurg female name } else if (selectedSex.equals("Female") && selectedRace.equals("Gulhurg")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); // generate Gulhurg male name } else if (selectedSex.equals("Male") && selectedRace.equals("Gulhurg")) { Stardust3d.MyDataOp.getRandomHumanMaleName(); textfieldFirstName.setText(Stardust3d.generatedFirstName); textfieldSurName.setText(Stardust3d.generatedSurName); } } }); DialogListener dialogListener = (new DialogListener() { @Override public void optionSelected(int option) { if (Stardust3d.DEBUG) System.out.println("option " + option); if (option == 1) { if (Stardust3d.DEBUG) System.out.println("no"); stage.removeActor(dialog); } if (option == 0) { if (Stardust3d.DEBUG) System.out.println("yes"); stage.removeActor(dialog); } } }); }
From source file:com.digitale.screens.Chat.java
License:Open Source License
public Chat(String chatlines, Stage stage) { // populate channel dropdown for (int i = 0; i < Stardust3d.channelList.size(); i++) { listEntries[i] = Stardust3d.channelList.get(i).getChannelname(); }/*www.j ava 2s . c o m*/ //get prefs, if no prefs (-1) use factory setting int temp = prefs.getInteger("selectedchatchannel", -1); if (temp > 0) { selectedChannel = temp; } else if (temp < -1) { selectedChannel = 8; } temp = prefs.getInteger("chatchanneltype", -1); if (temp != -1) selectedChannelType = temp; batch = new SpriteBatch(); skin = new Skin(Gdx.files.internal("data/uiskin.json"), Gdx.files.internal("data/uiskin.png")); xfadeTexture = new Texture(Gdx.files.internal("data/blackpixel.png"), Format.RGB565, true); xfadeTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); fadeIn(); Gdx.input.setInputProcessor(stage); // Group.debug = true; final Button buttonSend = new TextButton("Send", skin.getStyle(TextButtonStyle.class), "buttonsend"); final Button buttonClose = new TextButton("Close", skin.getStyle(TextButtonStyle.class), "buttonClose"); final TextField textfieldText = new TextField("", "Type message here", skin.getStyle(TextFieldStyle.class), "textfield"); final SelectBox dropdown = new SelectBox(listEntries, skin.getStyle(SelectBoxStyle.class), "combo"); // final List list = new List(listEntries, // skin.getStyle(ListStyle.class), "list"); final Label labelchatlines = new Label("Chat:", skin.getStyle(LabelStyle.class), "labelchat"); final Label labelchattitle = new Label("Chat:", skin.getStyle(LabelStyle.class), "labelchattitle"); labelchatlines.setWrap(true); final ScrollPane scrollPane2 = new ScrollPane(labelchatlines, skin.getStyle(ScrollPaneStyle.class), "scroll"); dropdown.setSelection(selectedChannel); final Label lableNews = new Label("Chat: ", skin); Window window = new Window("Chat Screen", skin.getStyle(WindowStyle.class), "chatWindow"); if (Stardust3d.DEBUG) window.debug(); window.x = window.y = 0; window.setFillParent(true); window.setMovable(false); window.defaults().pad(5); // build table window.row().fill().expandX(); window.add(dropdown).align("Centre"); window.add(); window.add(buttonSend).colspan(1).align("right"); window.add(buttonClose).colspan(1).align("center"); window.row(); window.add(textfieldText).minWidth(100).expandX().fillX().colspan(4); window.row(); window.add(labelchattitle).align("left"); window.row(); window.add(scrollPane2).fill().expand().colspan(4); window.row(); window.pack(); stage.addActor(window); textfieldText.setTextFieldListener(new TextFieldListener() { public void keyTyped(TextField textField, char key) { if (key == '\n') textField.getOnscreenKeyboard().show(false); } }); dropdown.setSelectionListener(new SelectionListener() { @Override public void selected(Actor actor, int index, String value) { SoundManager.playuiclick(); selectedChannelType = (Stardust3d.channelList.get(index).getChanneltype()); selectedChannel = (Stardust3d.channelList.get(index).getUid()); Stardust3d.chatChannel = selectedChannel; Stardust3d.chatChannelName = Stardust3d.channelList.get(index).getChannelname(); prefs.putInteger("chatchanneltype", selectedChannelType); prefs.putInteger("selectedchatchannel", selectedChannel); prefs.flush(); Stardust3d.chatListReset = true; Stardust3d.refreshChat(Stardust3d.chatChannel, false); } }); buttonClose.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { if (Stardust3d.DEBUG) System.out.println("close chat button pressed"); SoundManager.playuiclick(); Stardust3d.stationScreen = 104; doneflag = true; isDone(); } }); buttonSend.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { SoundManager.playuiclick(); if (Stardust3d.DEBUG) System.out.println("send button pressed"); text = textfieldText.getText().toString(); if (selectedChannelType == 0 || selectedChannelType == 8) { Renderer.stage .addActor(Actors.bottomToast("You cannot send messages to this channel.", 4, skin)); SoundManager.playError(); } else if (!text.isEmpty()) { String passed = Stardust3d.MyDataOp.postChat(text, selectedChannel, Stardust3d.myCharacter.getUid()); textfieldText.setText(""); Stardust3d.refreshChat(selectedChannel, false); } } }); }
From source file:com.digitale.screens.Login.java
License:Open Source License
public Login(String newslines) { //all sounds loaded, now bind them try {/*from w w w.ja v a2 s.c om*/ Renderer.bindMeshes(0); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } OrthographicCamera camera; batch = new SpriteBatch(); skin = new Skin(Gdx.files.internal("data/uiskin.json"), Gdx.files.internal("data/uiskin.png")); xfadeTexture = new Texture(Gdx.files.internal("data/blackpixel.png"), Format.RGB565, true); xfadeTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); background = new Texture(Gdx.files.internal("data/bgpland.jpg")); camera = new OrthographicCamera(); camera.setToOrtho(false, Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getHeight()); fadeIn(); stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); Gdx.input.setInputProcessor(stage); // Group.debug = true; final Button buttonLogin = new TextButton("Log in", skin.getStyle(TextButtonStyle.class), "buttonLogin"); final Button buttonHelp = new TextButton("Quick Help", skin.getStyle(TextButtonStyle.class), "buttonHelp"); final Button buttonNewAccount = new TextButton("New Account", skin.getStyle(TextButtonStyle.class), "buttonNewAccount"); final Button buttonOptions = new TextButton("Options", skin.getStyle(TextButtonStyle.class), "buttonOptions"); final CheckBox checkBox = new CheckBox("Remember account name and password.", skin.getStyle(CheckBoxStyle.class), "checkbox"); final TextField textfieldUserName = new TextField("", "Account Name", skin.getStyle(TextFieldStyle.class), "textfield"); // final List list = new List(listEntries, // skin.getStyle(ListStyle.class), "list"); final Label labelStories = new Label(newslines, skin); labelStories.setWrap(true); final ScrollPane scrollPane2 = new ScrollPane(labelStories, skin.getStyle(ScrollPaneStyle.class), "scroll"); // configures an example of a TextField in password mode. final Label lableNews = new Label("News: ", skin); final TextField passwordTextField = new TextField("", "password", skin); passwordTextField.setPasswordCharacter('*'); passwordTextField.setPasswordMode(true); textfieldUserName.getOnscreenKeyboard().show(true); Boolean booltemp = prefs.getBoolean("nopoly", false); //is save account checked in prefs if (booltemp) { //if preferences account is too short to have been set to a valid account name checkBox.setChecked(true); String temp = prefs.getString("un", ""); ac = temp; textfieldUserName.setText(ac); temp = prefs.getString("cullingtree", ""); String pw = null; try { pw = new String(mcrypt.decrypt(temp.trim())); pw = pw.replace('~', ' ').trim(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } passwordTextField.setText(pw); } Window window = new Window("Login Screen", skin.getStyle(WindowStyle.class), "window"); if (Stardust3d.DEBUG) window.debug(); window.x = window.y = 0; window.setFillParent(true); window.setMovable(false); window.defaults().pad(5); //build table window.row().fill().expandX(); window.add(buttonNewAccount).colspan(1).align("Centre"); window.add(buttonOptions).colspan(1).align("center"); window.add(buttonHelp).colspan(1).align("center"); window.add(buttonLogin).colspan(1).align("right"); window.row(); window.add(textfieldUserName).minWidth(100).expandX().fillX().colspan(2); window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2); window.row(); window.add(lableNews).align("left"); window.row(); window.add(scrollPane2).fill().expand().colspan(4); window.row(); window.add(checkBox).colspan(4); window.row(); window.pack(); stage.addActor(window); SoundManager.init(); try { Renderer.bindMeshes(1); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } textfieldUserName.setTextFieldListener(new TextFieldListener() { public void keyTyped(TextField textField, char key) { if (key == '\n') textField.getOnscreenKeyboard().show(false); } }); buttonLogin.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { try { Renderer.bindMeshes(2); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (Stardust3d.DEBUG) System.out.println("login button pressed"); SoundManager.playuiclick(); ac = textfieldUserName.getText().toString(); String pw = passwordTextField.getText().toString(); if (checkpass(pw, pw) && checkuser(ac)) { String passed = Stardust3d.MyDataOp.login(ac, pw); if (Stardust3d.DEBUG) System.out.println("passed " + passed); if (passed.equals("true")) { SoundManager.playconfirm(); stage.addActor(Actors.bottomToast("Login sucessful", 4, skin)); Stardust3d.mloginOK = true; Stardust3d.gameMode = 3; //get players characters Stardust3d.populateCharacterlist(Stardust3d.muser); doneflag = true; isDone(); } else if (passed.equals("NOT_ACTIVE")) { SoundManager.playError(); stage.addActor(Actors.bottomToast( "Login failed, this account is not active, check your Email.", 4, skin)); } else if (passed.equals("false")) { SoundManager.playError(); stage.addActor(Actors.bottomToast( "Login failed, please check your account name and password.", 4, skin)); } } } }); buttonOptions.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { if (Stardust3d.DEBUG) System.out.println("options button pressed"); SoundManager.playuiclick(); Stardust3d.gameMode = 6; doneflag = true; } }); buttonNewAccount.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { if (Stardust3d.DEBUG) System.out.println("New account button pressed"); SoundManager.playuiclick(); Stardust3d.gameMode = 14; doneflag = true; } }); buttonHelp.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { if (Stardust3d.DEBUG) System.out.println("help button pressed"); SoundManager.playuiclick(); Stardust3d.gameMode = 9; doneflag = true; } }); checkBox.setClickListener(new ClickListener() { public void click(Actor actor, float x, float y) { SoundManager.playuiclick(); String encrypted = null; if (Stardust3d.DEBUG) System.out.println("remeber account name pressed"); Stardust3d.mremeberAccountname = checkBox.isChecked(); //if user wants to save login if (Stardust3d.mremeberAccountname) { String pw = passwordTextField.getText().toString(); String acc = textfieldUserName.getText().toString(); //check user has entered account details before saving if (pw.length() > 8 && acc.length() > 8) { /* Encrypt */ try { encrypted = (mcrypt.encrypt(pw)); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } prefs.putBoolean("nopoly", Stardust3d.mremeberAccountname); prefs.putString("un", acc); prefs.putString("cullingtree", encrypted); prefs.flush(); } else { stage.addActor(Actors.bottomToast( "You need to enter your account name and password before trying to save them.", 4, skin)); checkBox.setChecked(false); } } else { stage.addActor(Actors.bottomToast("Saved account details cleared.", 4, skin)); //clear saved account details prefs.putBoolean("nopoly", Stardust3d.mremeberAccountname); prefs.putString("un", ""); prefs.putString("cullingtree", ""); prefs.flush(); } } }); }
From source file:com.ray3k.skincomposer.dialog.DialogColors.java
License:Open Source License
private void renameDialog(ColorData color) { TextField textField = new TextField("", skin); TextButton okButton;/*from w w w .j av a 2 s. co m*/ Dialog dialog = new Dialog("Rename Color?", skin, "bg") { @Override protected void result(Object object) { if ((boolean) object) { renameColor(color, textField.getText()); } } @Override public Dialog show(Stage stage) { Dialog dialog = super.show(stage); main.getStage().setKeyboardFocus(textField); return dialog; } }; dialog.getTitleTable().padLeft(5.0f); float brightness = Utils.brightness(color.color); Color borderColor; if (brightness > .35f) { borderColor = Color.BLACK; } else { borderColor = Color.WHITE; } Table bg = new Table(skin); bg.setBackground("white"); bg.setColor(borderColor); dialog.getContentTable().add(bg); Label label = new Label(color.getName(), skin, "white"); label.setColor(color.color); bg.add(label).pad(10); dialog.getContentTable().row(); label = new Label("What do you want to rename the color to?", skin); dialog.getContentTable().add(label); dialog.getContentTable().row(); textField.setText(color.getName()); textField.selectAll(); textField.addListener(main.getIbeamListener()); dialog.getContentTable().add(textField); dialog.getCell(dialog.getContentTable()).pad(15.0f); dialog.button("OK", true); dialog.button("Cancel", false).key(Keys.ESCAPE, false); okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor(); okButton.setDisabled(true); okButton.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getButtonTable().padBottom(15.0f); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !ColorData.validate(textField.getText()); if (!disable) { for (ColorData data : jsonData.getColors()) { if (data.getName().equals(textField.getText())) { disable = true; break; } } } okButton.setDisabled(disable); } }); textField.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!okButton.isDisabled()) { renameColor(color, textField.getText()); dialog.hide(); } } } }); textField.setFocusTraversal(false); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
private void renameDrawableDialog(DrawableData drawable) { TextField textField = new TextField("", getSkin()); Dialog dialog = new Dialog("Rename drawable?", getSkin(), "bg") { @Override/* ww w. j a v a 2 s. com*/ protected void result(Object object) { super.result(object); if (object instanceof Boolean && (boolean) object == true) { renameDrawable(drawable, textField.getText()); } getStage().setScrollFocus(scrollPane); } @Override public Dialog show(Stage stage) { Dialog dialog = super.show(stage); stage.setKeyboardFocus(textField); return dialog; } }; dialog.getTitleTable().padLeft(5.0f); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.getButtonTable().padBottom(15.0f); dialog.getContentTable().add(new Label("Please enter a new name for the drawable: ", getSkin())); dialog.button("OK", true); dialog.button("Cancel", false).key(Keys.ESCAPE, false); TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor(); okButton.setDisabled(true); okButton.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getContentTable().row(); textField.setText(drawable.name); textField.selectAll(); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !DrawableData.validate(textField.getText()); if (!disable) { for (DrawableData data : atlasData.getDrawables()) { if (data.name.equals(textField.getText())) { disable = true; break; } } } okButton.setDisabled(disable); } }); textField.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!okButton.isDisabled()) { renameDrawable(drawable, textField.getText()); dialog.hide(); } } } }); textField.addListener(main.getIbeamListener()); dialog.getContentTable().add(textField); textField.setFocusTraversal(false); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogFonts.java
License:Open Source License
private void renameDialog(FontData font) { TextField textField = new TextField("", skin); TextButton okButton;/*from w w w .j a v a 2 s. c o m*/ Dialog dialog = new Dialog("Rename Font?", skin, "bg") { @Override protected void result(Object object) { if ((boolean) object) { renameFont(font, textField.getText()); } } @Override public Dialog show(Stage stage) { Dialog dialog = super.show(stage); main.getStage().setKeyboardFocus(textField); return dialog; } }; dialog.getContentTable().padLeft(10.0f).padRight(10.0f); dialog.getTitleTable().padLeft(5.0f); Table bg = new Table(skin); bg.setBackground("white"); bg.setColor(Color.WHITE); dialog.getContentTable().add(bg); Label label = new Label(font.getName(), skin, "white"); label.setColor(Color.BLACK); bg.add(label).pad(10); dialog.getContentTable().row(); label = new Label("What do you want to rename the font to?", skin); dialog.getContentTable().add(label); dialog.getContentTable().row(); textField.setText(font.getName()); textField.selectAll(); textField.addListener(main.getIbeamListener()); dialog.getContentTable().add(textField); dialog.button("OK", true); dialog.button("Cancel", false).key(Keys.ESCAPE, false); okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor(); okButton.setDisabled(true); okButton.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getButtonTable().padBottom(15.0f); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !FontData.validate(textField.getText()); if (!disable) { for (ColorData data : jsonData.getColors()) { if (data.getName().equals(textField.getText())) { disable = true; break; } } } okButton.setDisabled(disable); } }); textField.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!okButton.isDisabled()) { renameFont(font, textField.getText()); dialog.hide(); } } } }); textField.setFocusTraversal(false); dialog.show(getStage()); }
From source file:com.uwsoft.editor.gdx.ui.dialogs.DlgExport.java
License:Apache License
private void setPathProvider(final String type, final TextField textField, final TextButtonItem btn, final String defaultPath) { btn.addListener(new ClickListener() { public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); //chooser creation FileChooser fileChooser = new FileChooser(FileChooser.Mode.OPEN); fileChooser.setSelectionMode(FileChooser.SelectionMode.DIRECTORIES); fileChooser.setMultiselectionEnabled(false); fileChooser.setListener(new FileChooserAdapter() { @Override// www . j a v a 2s . c o m public void selected(FileHandle file) { textField.setText(file.path()); if (type.equals("global")) { setMiniPaths(); } paths.put(type, file.file()); } }); stage.addActor(fileChooser.fadeIn()); } }); }
From source file:com.uwsoft.editor.gdx.ui.dialogs.DlgImport.java
License:Apache License
private void setPathProvider(final String type, final TextField textField, final TextButtonItem btn, final String defaultPath) { btn.addListener(new ClickListener() { public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); FileChooser fileChooser = new FileChooser(FileChooser.Mode.OPEN); fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES); fileChooser.setMultiselectionEnabled(true); fileChooser.setListener(new FileChooserAdapter() { @Override//from w w w . ja v a2s . co m public void selected(Array<FileHandle> result) { ArrayList<File> files = new ArrayList<>(); String fileNames = ""; for (int i = 0; i < result.size; i++) { if (i > 0) fileNames = fileNames + ", "; fileNames = fileNames + result.get(i).name(); files.add(result.get(i).file()); } textField.setText(fileNames); paths.put(type, files); } }); stage.addActor(fileChooser.fadeIn()); } }); }
From source file:de.hasait.tanks.app.common.MainMenuScreen.java
License:Apache License
public MainMenuScreen(final TanksScreenContext pContext) { super(pContext, 800, 600); setBackgroundColor(new Color(0.0f, 0.0f, 0.2f, 1.0f)); addInputProcessor(_inputProcessor);/* w w w . j av a 2 s. co m*/ final Table layout = addLayout(); layout.setFillParent(true); layout.defaults().pad(5.0f).align(Align.left).fill(); final Label titleLabel = createLabel("Welcome to Tanks", 2.0f); layout.add(titleLabel).colspan(2).padBottom(20.0f); final Preferences preferences = obtainPreferences(); layout.row(); layout.add(createLabel("Room")); _roomNameField = createTextField(preferences.getString(PREFKEY__ROOM_NAME, "Default")); layout.add(_roomNameField); for (int i = 0; i < 2; i++) { layout.row(); layout.add(createLabel("Player " + (i + 1))); final TextField playerNameField = createTextField(); layout.add(playerNameField); _playerNameFields.add(playerNameField); PlayerConfig playerConfig = null; final String preferencesString = preferences.getString(PREFKEY__PLAYER_CONFIG + i); if (!Util.isEmpty(preferencesString)) { try { playerConfig = (PlayerConfig) Util.serializeFromString(preferencesString); Gdx.app.log("PlayerConfig", "Read for player " + i); } catch (final RuntimeException pE) { Gdx.app.error("PlayerConfig", "Cannot read for player " + i, pE); } } if (playerConfig == null) { Gdx.app.log("PlayerConfig", "New for player " + i); playerConfig = new PlayerConfig(); if (i == 0) { playerConfig.setName("Player " + (i + 1)); setActionSet1(playerConfig); } else if (i == 1) { setActionSet2(playerConfig); } } playerNameField.setText(playerConfig.getName()); playerNameField.setUserObject(playerConfig); layout.add(actionConfig("Fire", playerConfig::getFire, playerConfig::setFire)); layout.row(); layout.add(createLabel(Util.EMPTY)); layout.add(actionConfig("Move Forward", playerConfig::getMoveForward, playerConfig::setMoveForward)); layout.add(actionConfig("Move Backward", playerConfig::getMoveBackward, playerConfig::setMoveBackward)); layout.row(); layout.add(createLabel(Util.EMPTY)); layout.add(actionConfig("Rotate Left", playerConfig::getRotateLeft, playerConfig::setRotateLeft)); layout.add(actionConfig("Rotate Right", playerConfig::getRotateRight, playerConfig::setRotateRight)); layout.row(); layout.add(createLabel(Util.EMPTY)); layout.add(actionConfig("Turret Left", playerConfig::getTurrentRotateLeft, playerConfig::setTurrentRotateLeft)); layout.add(actionConfig("Turret Right", playerConfig::getTurrentRotateRight, playerConfig::setTurrentRotateRight)); } layout.row(); _connectButton = createTextButton("Connect"); layout.add(_connectButton).colspan(2); _connectButton.addListener(pEvent -> { if (pEvent instanceof ChangeListener.ChangeEvent) { _connect = true; } return false; }); }
From source file:org.shadebob.skineditor.actors.MenuBar.java
License:Apache License
protected void showExportDialog() { final Preferences prefs = Gdx.app .getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject()); final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin); Dialog dlg = new Dialog("Export to Directory", game.skin) { @Override/*from www . java 2 s . c o m*/ protected void result(Object object) { if ((Boolean) object == true) { if (textDirectory.getText().isEmpty() == true) { game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage); return; } FileHandle targetDirectory = new FileHandle(textDirectory.getText()); if (targetDirectory.exists() == false) { game.showNotice("Warning", "Directory not found!", game.screenMain.stage); return; } // Copy uiskin.* and *.fnt FileHandle projectFolder = Gdx.files.local("projects") .child(game.screenMain.getcurrentProject()); for (FileHandle file : projectFolder.list()) { if (file.name().startsWith("uiskin.") || (file.extension() == "fnt")) { Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ..."); FileHandle target = targetDirectory.child(file.name()); file.copyTo(target); } } game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage); } } }; dlg.pad(20); Table table = dlg.getContentTable(); table.padTop(20); table.add("Directory:"); table.add(textDirectory).width(320); TextButton buttonChoose = new TextButton("...", game.skin); buttonChoose.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Need to steal focus first with this hack (Thanks to Z-Man) Frame frame = new Frame(); frame.setUndecorated(true); // TODO falls frame.setOpacity(0); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.toFront(); frame.setVisible(false); frame.dispose(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); textDirectory.setText(f.getAbsolutePath()); // Store to file prefs.putString("export_to_directory", f.getAbsolutePath()); prefs.flush(); } } }); table.add(buttonChoose); table.row(); table.padBottom(20); dlg.button("Export", true); dlg.button("Cancel", false); dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true); dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false); dlg.show(getStage()); }