private void cleaningTextFieldsToBlank() { userField.addListener( new ClickListener() { public void clicked(InputEvent e, float x, float y) { userField.setText(""); } }); passwordField.addListener( new ClickListener() { public void clicked(InputEvent e, float x, float y) { passwordField.setText(""); passwordField.setPasswordMode(true); passwordField.setPasswordCharacter('*'); } }); passwordCheckField.addListener( new ClickListener() { public void clicked(InputEvent e, float x, float y) { passwordCheckField.setText(""); passwordCheckField.setPasswordMode(true); passwordCheckField.setPasswordCharacter('*'); } }); emailField.addListener( new ClickListener() { public void clicked(InputEvent e, float x, float y) { emailField.setText(""); } }); }
public void handleAutocompleteResponse(AutocompleteResponseEvent event) { if (event.getOwnerUI() == cld.ownerUI) { consoleArrow.setText(cld.parser.getInputPrefix()); consoleField.setText(event.getText()); consoleField.setCursorPosition(consoleField.getText().length()); } }
public void setEditActors(Array<Actor> models) { updateProperties = true; if (models == null || models.size <= 0) editActors = null; else editActors = models; boolean disable = (editActors == null); name.setDisabled(disable); visible.setDisabled(disable); positionX.setDisabled(disable); positionY.setDisabled(disable); rotation.setDisabled(disable); lockRatio.setDisabled(disable); scaleX.setDisabled(disable); scaleY.setDisabled(disable); r.setDisabled(disable); g.setDisabled(disable); b.setDisabled(disable); a.setDisabled(disable); // variablesButton.setDisabled(disable); disableActors(getChildren(), disable); updateProperties = false; if (!disable) updateProperties(); }
public ShapeTable(Skin skin, GDXShape shape) { super(skin); resourceField = new TextField(shape.getResource(), skin); resourceField.setMessageText("<resource name>"); densityField = new TextField(shape.getDensity() + "", skin); densityField.setMessageText("<density, calculates mass>"); frictionField = new TextField(shape.getFriction() + "", skin); frictionField.setMessageText("<friction>"); restitutionField = new TextField(shape.getRestitution() + "", skin); restitutionField.setMessageText("<restitution>"); tagField = new TextField(shape.getTag(), skin); tagField.setMessageText("<tag>"); filterTable = new FilterTable(skin, shape.getFilter()); add("Resource: "); add(resourceField); row(); add("Tag: "); add(tagField); row(); add("Friction: "); add(frictionField); row(); add("Density: "); add(densityField); row(); add("Restitution: "); add(restitutionField); row(); add("Filter "); add(filterTable); }
@Override public void update() { if (readyToConnect && !connectStarted) { Client.reset(new LanClient()); Input.setup(Client.get()); connectStarted = true; } if (Input.isActive(Commands.get(Aigilas.Commands.Start), 0)) { if (ipIn.getText() != null && !ipIn.getText().isEmpty()) { String[] contents = ipIn.getText().split(":"); String address = contents[0]; if (contents.length > 1) { int port = Parse.inte(contents[1]); Config.get().setPort(port); } label.setText(waitMessage); Config.get().setServerIp(address); readyToConnect = true; ipIn.setVisible(false); } } if (Client.get().isGameStarting()) { for (int ii = 0; ii < Client.get().getPlayerCount(); ii++) { Input.setContext(Contexts.get(Sps.Contexts.Free), ii); } StateManager.loadState(new LoadingState()); } }
public void signIn() { menu = Assets.menuSigninRegion; menuComponents = new ArrayList<MenuComponent>(); menuTextFields = new ArrayList<TextField>(); menuComponents.add(0, new MenuComponent(200, 300, 100, 50, Assets.menuUsernameRegion)); menuComponents.add(1, new MenuComponent(200, 200, 100, 50, Assets.menuPasswordRegion)); menuComponents.add(2, new MenuComponent(600, 50, 100, 50, Assets.menuSubmitRegion)); Skin usernameSkin = new Skin(Gdx.files.internal("data/uiskin.json")); TextField usernameTextField = new TextField("", usernameSkin); usernameTextField.setPosition(300, 300); usernameTextField.setWidth(400); usernameTextField.setFocusTraversal(false); Skin passwordSkin = new Skin(Gdx.files.internal("data/uiskin.json")); TextField passwordTextField = new TextField("", passwordSkin); passwordTextField.setPosition(300, 200); passwordTextField.setPasswordMode(true); passwordTextField.setPasswordCharacter('a'); passwordTextField.setWidth(400); passwordTextField.setFocusTraversal(false); menuTextFields.add(0, usernameTextField); menuTextFields.add(1, passwordTextField); menuNumber = 2; }
private TextField findNextTextField( Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor == this) continue; if (actor instanceof TextField) { TextField textField = (TextField) actor; if (textField.isDisabled() || !textField.focusTraversal) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) { if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) { best = (TextField) actor; bestCoords.set(actorCoords); } } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
public void enterClicked() { EventManager.get_instance() .broadcast(new CommandLineEvent(cld.ownerUI, consoleField.getText())); cld.previousCommands.add(consoleField.getText()); consoleArrow.setText(cld.parser.getInputPrefix()); consoleField.setText(""); setKeyboardFocus(); }
public GDXShape apply(GDXShape shape) { shape.setDensity(Float.parseFloat(densityField.getText())); shape.setFriction(Float.parseFloat(frictionField.getText())); shape.setResource(resourceField.getText()); shape.setRestitution(Float.parseFloat(restitutionField.getText())); shape.setFilter(filterTable.createFilterFromUI()); shape.setTag(tagField.getText()); return shape; }
private void registerJson() { JsonObject json = new JsonObject(); json.add("username", new JsonPrimitive(userField.getText())); json.add("password", new JsonPrimitive(passwordField.getText())); json.add("email", new JsonPrimitive(emailField.getText())); final Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.POST); httpRequest.setUrl(Assets.HTTP_SERVER + "registration"); httpRequest.setHeader("Content-Type", "application/json"); httpRequest.setContent(json.toString()); Gdx.net.sendHttpRequest( httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(final Net.HttpResponse httpResponse) { System.out.print(httpResponse.getResultAsString()); if (httpResponse.getStatus().getStatusCode() == 200) { Gdx.app.postRunnable( new Runnable() { @Override public void run() { stage.addAction( Actions.sequence( Actions.fadeOut(1), Actions.run( new Runnable() { @Override public void run() { login( userField.getText().toString(), passwordField.getText().toString(), false); game.setScreen(new PlayScreen(game)); } }))); } }); } } @Override public void failed(Throwable t) { labelMessage.setText("Please check your Internet connection."); } @Override public void cancelled() { Gdx.app.postRunnable( new Runnable() { @Override public void run() { // ????? } }); } }); }
private void init(final Controller controller) { time.setRightAligned(true); time.setMaxLength(MAX_DURATION_LENGTH); time.setText(String.valueOf(frame.getTime())); time.setTextFieldFilter( new TextFieldFilter() { @Override public boolean acceptChar(TextField textField, char c) { return Character.isDigit(c) || c == '.'; } }); time.addListener( new InputListener() { private String previousText = time.getText(); @Override public boolean keyTyped(InputEvent event, char character) { String text = time.getText(); if (!text.isEmpty() && !text.equals(previousText)) { float timeVal = previousTime; try { timeVal = Float.valueOf(text); } catch (NumberFormatException formatEx) { Gdx.app.error( "FrameWidget", "Error getting frame time, setting previous time: " + previousTime, formatEx); } if (timeVal != previousTime) { controller.action(SetFrameTime.class, frame, timeVal); previousText = String.valueOf(timeVal); } } return true; } }); EditorGameAssets assets = controller.getEditorGameAssets(); assets.get( ((es.eucm.ead.schema.renderers.Image) frame.getRenderer()).getUri(), Texture.class, new AssetLoadedCallback<Texture>() { @Override public void loaded(String fileName, Texture asset) { ((Image) widget).setDrawable(new TextureRegionDrawable(new TextureRegion(asset))); } }, true); controller.getModel().addFieldListener(frame, textfieldListener); }
void timeChanged(float newValue) { int cursosPos = time.getCursorPosition(); time.setText(String.valueOf(newValue)); time.setCursorPosition(cursosPos); previousTime = newValue; int index = timeline.indexOf(FrameWidget.this); if (index != -1) { listener.frameTimeChanged(index, newValue); } }
private void creatingTheTextFields() { userField = new TextField(Constant.USER_NAME, skin); userField.setColor(1, 0, 0, 0.5f); passwordField = new TextField(Constant.PASSWORD, skin); passwordField.setColor(1, 0, 0, 0.5f); passwordCheckField = new TextField(RE_PASSWORD, skin); passwordCheckField.setColor(1, 0, 0, 0.5f); emailField = new TextField(EMAIL, skin); emailField.setColor(1, 0, 0, 0.5f); }
public NPCPropertyTable(final Skin skin, final GDXNPC npc) { super(skin); this.npc = npc; for (Entry<String, String> entry : npc.getProperties().entrySet()) { add(entry.getKey() + ": "); final TextField propertyField = new TextField("", skin); propertyField.setMessageText("<" + entry.getKey() + ">"); if (entry.getValue() != null) propertyField.setText(entry.getValue()); properties.put(entry.getKey(), propertyField); add(propertyField); row(); } }
public JoinServerAsGuestState() { Input.setContext(Contexts.get(Sps.Contexts.Non_Free), Client.get().getFirstPlayerIndex()); stage = new Stage(); Gdx.input.setInputProcessor(stage); Label.LabelStyle lblStyle = new Label.LabelStyle(Assets.get().font(), Color.WHITE); label = new Label("Server IP:", lblStyle); TextField.TextFieldStyle style = new TextField.TextFieldStyle(); style.font = Assets.get().font(); style.cursor = UiAssets.getNewCursor(); style.fontColor = Color.WHITE; style.background = UiAssets.getNewBtnBg(); ipIn = new TextField("", style); stage.setKeyboardFocus(ipIn); ipIn.addListener( new ChangeListener() { @Override public void changed(ChangeEvent changeEvent, Actor actor) { ipIn.setBlinkTime(1); } }); Table table = new Table(); table.setFillParent(true); table.add(label); table.add(ipIn).minWidth(300); stage.addActor(table); }
public void btnClicked() { if (ans == Integer.parseInt(answer.getText())) { feedback.setText("Correct"); } else { feedback.setText("Incorrect"); } }
public void addProperty(String name, String value, Types type) { table.row(); table.add(new Label(name, skin)).expandX().left(); if (type == Types.BOOLEAN) { SelectBox<String> sb = new SelectBox<String>(skin); sb.setItems(BOOLEAN_VALUES); if (value != null) sb.setSelected(value); sb.setName(name); table.add(sb).expandX().left(); sb.addListener( new ChangeListener() { @SuppressWarnings("unchecked") @Override public void changed(ChangeEvent event, Actor actor) { updateModel(actor.getName(), ((SelectBox<String>) actor).getSelected()); } }); } else { TextField tf = new TextField(value == null ? "" : value, skin); tf.setName(name); table.add(tf).expandX().left(); if (type == Types.INTEGER) tf.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); tf.setTextFieldListener( new TextFieldListener() { @Override public void keyTyped(TextField actor, char c) { updateModel(actor.getName(), ((TextField) actor).getText()); } }); // tf.addListener(new FocusListener() { // // @Override // public void keyboardFocusChanged (FocusEvent event, Actor actor, boolean focused) { // if(!focused) // updateModel(actor.getName(), ((TextField)actor).getText()); // } // }); } }
@Override public void render(float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClearColor(1, 1, 1, 1); if (ipTextField.getText().length() > 0 && portTextField.getText().length() > 0) { connectionButton.setDisabled(false); } else if (!connectionButton.isDisabled()) { connectionButton.setDisabled(true); } stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); Assets.soundController.draw(batch, this); }
@Override public void setObject(TextButtonItem object) { item = object; lblTxtBox = ui.getTextBoxById("buttonText"); lblTxtBox.setText(item.getDataVO().text); setListeners(); }
public WeldTable(Skin skin, WeldJoint joint) { super(skin, joint, JointType.WeldJoint); anchorTable = new VertexTable(joint.getAnchor(), skin); referenceAngleField = new TextField(joint.getReferenceAngle() + "", skin); referenceAngleField.setMessageText("<reference angle>"); add("Anchor: "); add(anchorTable); row(); add("Reference Angle: "); add(referenceAngleField); }
/** * Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text * field is not in a stage. * * @param up If true, the TextField with the same or next smallest y coordinate is found, else the * next highest. */ public void next(boolean up) { Stage stage = getStage(); if (stage == null) return; TextField current = this; while (true) { current.getParent().localToStageCoordinates(tmp1.set(getX(), getY())); TextField textField = current.findNextTextField(stage.getActors(), null, tmp2, tmp1, up); if (textField == null) { // Try to wrap around. if (up) tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE); else tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE); textField = current.findNextTextField(getStage().getActors(), null, tmp2, tmp1, up); } if (textField == null) { Gdx.input.setOnscreenKeyboardVisible(false); break; } if (stage.setKeyboardFocus(textField)) break; current = textField; } }
@Override public void render() { Gdx.gl.glClearColor( background.rgb.getRed() / 255f, background.rgb.getGreen() / 255f, background.rgb.getBlue() / 255f, background.rgb.getAlpha() / 255f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); boolean hasUserInput = false; if (input.getText() != null && input.getText().length() != 0) hasUserInput = true; final String text = hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog"; float scale = scaleSlider.getValue(); cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.setProjectionMatrix(cam.combined); batch.getProjectionMatrix().scale(scale, scale, 0.0f); // batch.getTransformMatrix().scale(scale, scale, 0.0f); if (fonts != null) { batch.begin(); int x = 5; int y = 0; for (FontElement e : fonts) { y += e.font.getLineHeight() + 5; String str = hasUserInput ? text : e.name + " " + e.size + ": " + text; e.font.draw(batch, str, x, y); } batch.end(); } input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5); labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5); labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5); scaleSlider.setY(input.getY() - input.getHeight() - 5); scaleAmt.setY(scaleSlider.getY()); linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10); stage.act(); stage.draw(); }
@Override public void setFocus(boolean focus) { super.setFocus(focus); top.setVisible(focus); if (!focus) { if (topCell.hasWidget()) { topCell.setWidget(null); } } else { topCell.setWidget(top); } top.invalidateHierarchy(); previousTime = Float.valueOf(time.getText()); }
public void addEntry(final String name, int width) { final TextField textField = new TextField("", getSkin()); nameToTextField.put(name, textField); add(new Label(name, getSkin())).fill().left(); if (width != -1) { add(textField).fill().right().width(width); } else { add(textField).fill().right(); } textField.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (listener != null) { listener.onChange(name, textField.getText()); } } }); row(); pack(); }
private void setListeners() { lblTxtBox.addListener( new ClickListener() { public boolean keyUp(InputEvent event, int keycode) { if (keycode == 66) { // set item id to String text = lblTxtBox.getText(); if (item != null) { (item).getDataVO().text = text; item.renew(); } } return true; } }); }
public MathsScreen(Game g) { game = g; stage = new Stage(); Gdx.input.setInputProcessor(stage); // get input from our stage num1 = MathUtils.random(10, 100); // libgdx easy random numbers :) num2 = MathUtils.random(10, 100); ans = num1 * num2; Skin skin = new Skin( Gdx.files.internal( "uiskin.json")); // set what the UI elements are going to look like, libgdx provides // file abstraction to make it easy to access files on any platform question = new Label( "What is the area of a rectangle of " + num1 + " by " + num2, skin); // Create a label element question.setPosition(100, 500); // Position it stage.addActor(question); // Add the lable to the stage answer = new TextField("", skin); // Create a textfield element answer.setPosition(300, 340); // Position it stage.addActor(answer); // Add it to the stage feedback = new Label("", skin); // Create a label element feedback.setPosition(300, 150); // Position it stage.addActor(feedback); // Add the lable to the stage check = new TextButton("Check your answer", skin); check.setPosition(300, 200); check.addListener( new ClickListener() // add the listener as an anonymous? method, inline method { // autocomplete the code below by typing clicked and then ctrl + space, modify to add our // own btClicked method public void clicked(InputEvent e, float x, float y) { btnClicked(); } }); stage.addActor(check); }
protected void disableActors(SnapshotArray<Actor> actors, boolean disable) { Color color = disable ? disableColor : enableColor; for (Actor actor : actors) { actor.setColor(color); if (actor instanceof Group) { if (!(actor instanceof CheckBox)) disableActors(((Group) actor).getChildren(), disable); } if (disable) { if (actor instanceof TextField) { ((TextField) actor).setText(""); } else if (actor instanceof CheckBox) { CheckBox checkBox = (CheckBox) actor; checkBox.setChecked(false); } } } }
public void update() { gcl = new ArrayList<GhostComponent>(); if (SelectionManager._instance.singleSelected != null) { BuildingComponent bc = sm.singleSelected.getComponent(BuildingComponent.class); GhostComponent gc = sm.singleSelected.getComponent(GhostComponent.class); if (bc != null && bc.bc.playerControlled) { if (bp.getStage() == null) { stage.clear(); stage.addActor(bp); } } else if (gc != null && gc.bc.playerControlled) { gcl.add(gc); if (gp.getStage() == null) { stage.clear(); stage.addActor(gp); } } } else if (SelectionManager._instance.selected.size() > 0) { for (Entity e : sm.selected) { GhostComponent gc = e.getComponent(GhostComponent.class); if (gc != null) gcl.add(gc); } if (gp.getStage() == null) { stage.clear(); stage.addActor(gp); } } else if (!HW4.stop) { if (rs.getStage() == null || !display) stage.clear(); } f.setText("Souls: " + GhostComponent.money); if (cw.getStage() == null) stage.addActor(cw); if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { display = !display; } if ((HW4.win || display) && rs.getStage() == null) { stage.addActor(rs); } }
public void welcome(String username, int wins, int losses, String charityName, int charityIcon) { shouldClear = true; shouldAddScrollPane = false; charityScrollPane = false; characterScrollPane = false; scrollPaneContainer = null; menu = Assets.menuSplashBlankRegion; menuComponents = new ArrayList<MenuComponent>(); menuTextFields = new HashMap<String, TextField>(); TextField usernameTextField = new TextField(("WELCOME " + username.toUpperCase() + "!"), Assets.tfsBigBlue70); usernameTextField.setPosition(50, 290); usernameTextField.setWidth(700); usernameTextField.setHeight(50); usernameTextField.setAlignment(Align.center); usernameTextField.setFocusTraversal(false); usernameTextField.setDisabled(true); menuTextFields.put("usernameTF", usernameTextField); menuNumber = this.MENU_WELCOME; }
public void splash() { shouldClear = true; shouldAddScrollPane = false; charityScrollPane = false; characterScrollPane = false; scrollPaneContainer = null; menu = Assets.menuSplashBlankRegion; menuComponents = new ArrayList<MenuComponent>(); menuTextFields = new HashMap<String, TextField>(); menuNumber = this.MENU_SPLASH; blinkTimer = 0; TextField charityChampsTextField = new TextField(("CHARITY CHAMPS!"), Assets.tfsTrans100); charityChampsTextField.setPosition(50, 190); charityChampsTextField.setWidth(700); charityChampsTextField.setHeight(150); charityChampsTextField.setAlignment(Align.center); charityChampsTextField.setFocusTraversal(false); charityChampsTextField.setDisabled(true); menuTextFields.put("charityChampsTF", charityChampsTextField); this.isSplash = true; }