@Override public void show() { player = new Player(Assets.random()); client = new Client(player); stage = new Stage(); Image logo = new Image(Assets.LOGO); logo.setPosition((Gdx.graphics.getWidth() - logo.getWidth()) / 2, Gdx.graphics.getHeight() * 0.85f); Image shadow = dropShadow(logo); stage.addActor(logo); stage.addActor(shadow); stage.addActor(new PlayGroup(client)); stage.getRoot().addCaptureListener(new InputListener() { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { if (!(event.getTarget() instanceof TextField)) stage.setKeyboardFocus(null); return true; } }); Gdx.input.setInputProcessor(stage); }
public MultiplayerConnectMenu() { super(); title = new Label(Localization.get("menu.multiplayer.title"), skin.get("title", Label.LabelStyle.class)); address = new TextField("", skin); address.setMessageText(Localization.get("menu.multiplayer.address")); port = new TextField("", skin); port.setMessageText(Localization.get("menu.multiplayer.port", 24842)); //Not "Settings.getIntegerSettingValue(Settings.NETWORKING_PORT)" because the port is set on the server port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); connect = new TextButton(Localization.get("menu.multiplayer.connect"), skin); back = MenuTools.getBackButton(this); connect.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { Adapter.setMenu(new MultiplayerLoadingMenu(address.getText().isEmpty() ? "localhost" : address.getText(), port.getText().isEmpty() ? 24842 : Integer.parseInt(port.getText()))); } }); stage.addActor(title); stage.addActor(address); stage.addActor(port); stage.addActor(connect); stage.addActor(back); }
private TextField getTextField(VisualSettingManager visualSettingManager) { final TextField textField = new TextField(i + "", visualSettingManager.getSkin()); textField.addListener(new EventListener() { @Override public boolean handle(Event event) { if (!(event instanceof SettingsMenu.SaveEvent)) return false; try { int n = Integer.parseInt(textField.getText()); if (hasRange && (n < rangeStart || n > rangeEnd)) { throw new NumberFormatException(); } else { set(n); return true; } } catch (Exception e) { textField.setText(i + ""); return false; } } }); textField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); if (hasRange) textField.setMessageText("(" + rangeStart + "-" + rangeEnd + ")"); return textField; }
public AskForIpDialog(SettingsChoosingState state, ConnectionInfo defaultConnection) { super("Connect to server", Settings.DEFAULT_SKIN); this.linkedState = state; ipField = new TextField(defaultConnection.getIp(), getSkin()); text("Server ip: "); this.getContentTable().add(ipField); this.getContentTable().row(); text("Tcp port: "); tcpPortField = new IntegerField(defaultConnection.getTcpPort(), getSkin(), MAX_PORT_DIGITS); this.getContentTable().add(tcpPortField); this.getContentTable().row(); text("Udp port: "); udpPortField = new IntegerField(defaultConnection.getUdpPort(), getSkin(), MAX_PORT_DIGITS); this.getContentTable().add(udpPortField); this.getContentTable().row(); this.button("Ok", DialogResults.OK); button("Cancel", DialogResults.CANCEL); }
public ServerSetupMenu(final Save save) { super(); title = new Label(Localization.get("menu.server.title"), skin.get("title", Label.LabelStyle.class)); saveLabel = new Label(Localization.get("menu.server.save", save.name), skin); saveLabel.setAlignment(Align.center); port = new TextField("", skin); port.setMessageText(Localization.get("menu.server.port", Settings.getIntegerSettingValue(Settings.NETWORKING_PORT))); port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); start = new TextButton(Localization.get("menu.server.start"), skin); back = MenuTools.getBackButton(this); start.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { int p = port.getText().isEmpty() ? Settings.getIntegerSettingValue(Settings.NETWORKING_PORT) : Integer.parseInt(port.getText()); Adapter.setMenu(new ServerRunningMenu(save, p)); } }); stage.addActor(title); stage.addActor(saveLabel); stage.addActor(port); stage.addActor(start); stage.addActor(back); }
private void createButton() { Skin skin = getGameObject().getComponentInParent(JCanvas.class).getSkin(); // TextFieldStyle style = new TextFieldStyle(skin.get("default", TextFieldStyle.class)); int realSize = (int) (((getTransform().getScale().x + getTransform().getScale().y) / 2) * fontSize); SmartFontGenerator fontGen = new SmartFontGenerator(); FileHandle exoFile = Gdx.files.internal(fontResource.getResourcePath()); BitmapFont fontBitmap = fontGen.createFont(exoFile, fontResource.getResourcePath() + realSize, realSize); TextFieldStyle styleDefault = skin.get("default", TextFieldStyle.class); TextFieldStyle style = new TextFieldStyle(fontBitmap, fontColor, styleDefault.cursor, styleDefault.selection, styleDefault.background); style.fontColor = fontColor; textField = new TextField(text, style); textField.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { text = textField.getText(); } }); }
public SettingScreenOld(Viewport viewport, Skin skin) { float screenWidth = Gdx.graphics.getWidth(); float screenHeight = Gdx.graphics.getHeight(); stage = new Stage(viewport); Label label = new Label("Player 1", skin); label.setPosition(screenWidth / 2, screenHeight - 10, Align.top); stage.addActor(label); label = new Label("Forward", skin); label.setPosition(10, screenHeight - 60); stage.addActor(label); TextField field = new TextField("", skin); field.setPosition(50, screenHeight - 20); field.setWidth(100); field.setHeight(50); stage.addActor(field); }
@Test @NeedGL public void shouldParseTextField() throws Exception { FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf"); CocoStudioUIEditor editor = new CocoStudioUIEditor( Gdx.files.internal("textField/MainScene.json"), null, null, defaultFont, null); Group group = editor.createGroup(); TextField textField = group.findActor("TextField_1"); assertThat(textField.getText(), is("Here is text")); assertThat(textField.getMessageText(), is("Place Holder")); assertThat(textField.getText(), is("Here is text")); assertThat(textField.getColor().toString(), is("008000ff")); assertThat(textField.getListeners().size, is(1)); textField = group.findActor("TextField_2"); assertThat(textField.getText(), is("")); assertThat(textField.getMessageText(), is("Place Holder")); assertThat(textField.getColor().toString(), is("ff0000ff")); assertThat(textField.getListeners().size, is(1)); }
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(); }
public SaveAsDialog(Skin skin) { super("save as..", skin); getContentTable().pad(15); Label nameLabel = new Label("Name:", skin); getContentTable().add(nameLabel); final TextField textField = new TextField("", skin); textField.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { resultValue = textField.getText(); } }); getContentTable().add(textField); button("save", true); button("cancel", false); pack(); }
public ConsoleView(Skin skin) { this.skin = skin; entriesStack = new Table(skin); entriesStack.setFillParent(true); scrollPane = new ScrollPane(entriesStack, skin); scrollPane.setFadeScrollBars(false); scrollPane.setScrollbarsOnTop(false); scrollPane.setOverscroll(false, false); inputField = new TextField("", skin); this.add(scrollPane).expand().fill().pad(2).row(); this.add(inputField).expandX().fillX().pad(4); setTouchable(Touchable.enabled); clearEntries(); }
private void createStaticMenu() { Table container = new Table(); container.setFillParent(true); container.top(); stage.addActor(container); Label title = new Label("Game Over", uiSkin, "title"); Label scoreLabel = new Label ("Score : "+ remoteScore.getScore(), uiSkin); usernameField = new TextField("", uiSkin); submitButton = new TextButton("Envoyer", uiSkin); submitButton.addListener(new SubmitScoreListener(usernameField, remoteScore, stage)); TextButton menuButton = new TextButton("Quitter", uiSkin); menuButton.addListener(new ButtonRedirectListener(game, new MainMenuScreen(game))); Table actorContainer = new Table(); actorContainer.add(scoreLabel).padBottom(10).colspan(2); actorContainer.row(); actorContainer.add(usernameField).padRight(10); actorContainer.add(submitButton); container.add(title).padTop(10); container.row(); container.add(actorContainer).expand(); container.row(); container.add(menuButton).bottom().left().pad(10); }
@Override protected void processForActor(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { // Applied if not in a cell. if (actor instanceof Label) { ((Label) actor).setAlignment(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else if (actor instanceof Table) { ((Table) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else if (actor instanceof Image) { ((Image) actor).setAlign(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else if (actor instanceof HorizontalGroup) { ((HorizontalGroup) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else if (actor instanceof VerticalGroup) { ((VerticalGroup) actor).align(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else if (actor instanceof TextField) { ((TextField) actor).setAlignment(LmlUtilities.parseAlignment(parser, actor, rawAttributeData)); } else { // Exception: super.processForActor(parser, tag, actor, rawAttributeData); } }
@Override public void process(final LmlParser parser, final LmlTag tag, final TextField actor, final String rawAttributeData) { @SuppressWarnings("unchecked") final ActorConsumer<Boolean, Character> filter = (ActorConsumer<Boolean, Character>) parser .parseAction(rawAttributeData, Character.valueOf(' ')); if (filter == null) { parser.throwErrorIfStrict( "Text field filter attribute requires ID of an action that consumes a Character and returns a boolean or Boolean. Valid action not found for name: " + rawAttributeData); return; } actor.setTextFieldFilter(new TextFieldFilter() { @Override public boolean acceptChar(final TextField textField, final char character) { return filter.consume(character); } }); }
@Override public void process(final LmlParser parser, final LmlTag tag, final TextField actor, final String rawAttributeData) { final ActorConsumer<?, Character> listener = parser.parseAction(rawAttributeData, Character.valueOf(' ')); if (listener == null) { parser.throwErrorIfStrict( "Text field listener attribute requires ID of an action that consumes a Character. Valid action not found for name: " + rawAttributeData); return; } actor.setTextFieldListener(new TextFieldListener() { @Override public void keyTyped(final TextField textField, final char character) { listener.consume(character); } }); }
@Override public void create () { stage = new Stage(); Gdx.input.setInputProcessor(stage); skin = new Skin(Gdx.files.internal("data/uiskin.json")); TextArea textArea = new TextArea( "Text Area\nEssentially, a text field\nwith\nmultiple\nlines.\n" + "It can even handle very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong lines.", skin); textArea.setX(10); textArea.setY(10); textArea.setWidth(200); textArea.setHeight(200); TextField textField = new TextField("Text field", skin); textField.setX(10); textField.setY(220); textField.setWidth(200); textField.setHeight(30); stage.addActor(textArea); stage.addActor(textField); }
public static void setup(){ registerSerializer(Actor.class, new ActorSerializer()); registerSerializer(Scene.class, new SceneSerializer()); registerSerializer(ImageJson.class, new ImageJson()); registerSerializer(Label.class, new LabelSerializer()); registerSerializer(Button.class, new ButtonSerializer()); registerSerializer(TextButton.class, new TextButtonSerializer()); registerSerializer(Table.class, new TableSerializer()); registerSerializer(CheckBox.class, new CheckBoxSerializer()); registerSerializer(SelectBox.class, new SelectBoxSerializer()); registerSerializer(List.class, new ListSerializer()); registerSerializer(Slider.class, new SliderSerializer()); registerSerializer(TextField.class, new TextFieldSerializer()); registerSerializer(Touchpad.class, new TouchpadSerializer()); registerSerializer(Sprite.class, new SpriteSerializer()); registerSerializer(Dialog.class, new DialogSerializer()); registerSerializer(SplitPane.class, new SplitPaneSerializer()); registerSerializer(ScrollPane.class, new ScrollPaneSerializer()); registerSerializer(Stack.class, new StackSerializer()); registerSerializer(Tree.class, new TreeSerializer()); registerSerializer(Table.class, new TableSerializer()); registerSerializer(ButtonGroup.class, new ButtonGroupSerializer()); registerSerializer(HorizontalGroup.class, new HorizontalGroupSerializer()); registerSerializer(VerticalGroup.class, new VerticalGroupSerializer()); }
/** 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; getParent().localToStageCoordinates(tmp1.set(getX(), getY())); TextField textField = 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 = findNextTextField(getStage().getActors(), null, tmp2, tmp1, up); } if (textField != null) stage.setKeyboardFocus(textField); else Gdx.input.setOnscreenKeyboardVisible(false); }
@Override public void keyTyped(TextField actor, char c) { if (c == 13) { // ENTER KEY updateModel(actor.getName(), ((TextField) actor).getText()); EditorLogger.debug("Updating property: " + actor.getName()); } } }); tf.addListener(new FocusListener() { @Override public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) { updateModel(actor.getName(), ((TextField) actor).getText()); EditorLogger.debug("Updating property: " + actor.getName()); } } }); }
@SuppressWarnings("unchecked") public void setProperty(String name, String value) { SnapshotArray<Actor> actors = table.getChildren(); for (Actor a : actors) { if (name.equals(a.getName())) { if (a instanceof SelectBox<?>) { ((SelectBox<String>) a).setSelected(value == null ? "" : value); } else { ((TextField) a).setText(value == null ? "" : value); } return; } } }
public AddStateDialog(final Stage stage, final Skin skin, final MusicEventManager eventManager) { super("Add State", skin); this.stage = stage; this.skin = skin; this.eventManager = eventManager; Table content = this.getContentTable(); Label label = new Label("State name", skin); label.setAlignment(Align.left); content.add(label).left().fillX().expandX().row(); eventName = new TextField("", skin); content.add(eventName).right().fillX().expandX().row(); Table buttons = this.getButtonTable(); buttons.defaults().fillX().expandX(); this.button("Ok", true); this.button("Cancel", false); key(Keys.ENTER, true); key(Keys.ESCAPE, false); }
private boolean initialize() { if (SharedAssetManager.isLoaded(Assets.TEX_PANEL_TRANSPARENT_9patch) && SharedAssetManager.isLoaded(Assets.FNT_MONO) && Styles.TXT_COMMANDLINE != null && Styles.TXT_COMMANDLINE.font != null) { setBackground(new NinePatchDrawable(GraphicsFactory.createNinePatch(Assets.TEX_PANEL_TRANSPARENT_9patch, Sizes.panelTransparentRadius()))); textField = new TextField("", Styles.TXT_COMMANDLINE); textField.setWidth(getWidth()); LabelStyle consoleStyle = new LabelStyle(); consoleStyle.font = SharedAssetManager.get(Assets.FNT_MONO, BitmapFont.class); consoleStyle.fontColor = Color.GRAY; add(new Label("$ ", consoleStyle)); add(textField).width(getWidth()); setY(Sizes.worldHeight() - textField.getHeight()); setHeight(textField.getHeight()); return true; } else { return false; } }
protected LinearLayout buildSearchButton() { LinearLayout searchActor = new LinearLayout(true); IconButton icon = WidgetBuilder.toolbarIcon(SkinConstants.IC_SEARCH, i18N.m("search")); search = new TextField("", skin); search.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { if (keycode == Input.Keys.ENTER) { loadContents(); return true; } return false; } }); searchActor.add(icon); searchActor.add(search).marginRight(WidgetBuilder.dpToPixels(16)); return searchActor; }
@Override public void save(XmlWriter writer, Actor actor, LayoutParserContext context) throws LayoutParseException { try { TextField textField = (TextField) actor; writer.element(getElementName()); ElementParserHelper.writeDefaultAttributes(writer, actor); if (!textField.getText().isEmpty()) { writer.text(textField.getText()); } writer.pop(); } catch (IOException e) { throw new LayoutParseException(e); } }
@Override protected void onInitUI() { Skin skin = GdxUISkin.instance().getDeafult(); input = new TextField("", skin); ClickListener mClickListener = new ClickListener() { public boolean keyDown (InputEvent event, int keycode) { if(keycode == Keys.ENTER && !isHide()) { if(!handleCmdString(input.getText())) { //clear input input.setText(null); } } return true; } }; input.addCaptureListener(mClickListener); input.setTextFieldFilter(new TextFieldFilter() { @Override public boolean acceptChar(TextField textField, char c) { if(c == '`' || c == '~') { hide(); return false; } return true; } }); label = new Label("", skin); maxTmp = GdxUIConfig.instance().consoleMaxOutputLine; input.setSize(getUIWidth()/2, 32); input.setPosition(20, getUIHeight() * 0.25f); addUI(input); addUI(label); skin = null; }
public static void parseUqAttr(Actor actor, XmlReader.Element element){ Class cls = EditorManager.getInstance().getActorType(actor); if (cls.equals(Label.class)){ parseLabel((Label) actor,element); }else if (cls.equals(Image.class)){ parseImage((Image) actor,element); }else if (cls.equals(Button.class)){ parseButton((VisImageButton) actor,element); }else if (cls.equals(TextField.class)){ parseTextField((TextField) actor,element); } }
public static void parseTextField(TextField textField, XmlReader.Element element){ String text = element.get("text",""); String messageText = element.get("messageText",""); textField.setText(text); textField.setMessageText(messageText); attr2TextField(textField); }
AssetTextFieldImpl(LibGdxAssetCache cache, String initialFieldText, TextFieldDescriptor textFieldDescriptor) { this.cache = cache; this.textFieldDescriptor = textFieldDescriptor; textFont = cache.getFont(textFieldDescriptor.getFont()); hintFont = cache.getFont(textFieldDescriptor.getMessageFont()); backgroundTexture = cache.getPixMapTexture(Color.WHITE); textField = new TextField(initialFieldText, createTextFieldStyle()); textField.setMessageText(textFieldDescriptor.getHintText()); }
/** * Create text style. */ private TextField.TextFieldStyle createTextFieldStyle() { TextField.TextFieldStyle style = new TextField.TextFieldStyle(); style.font = textFont; style.messageFont = hintFont; style.fontColor = textFieldDescriptor.getFontColor(); style.messageFontColor = textFieldDescriptor.getMessageFontColor(); style.background = new TextureRegionDrawable(new TextureRegion(backgroundTexture)); return style; }
public ServerSetupMenu(final Save save) { super(); title = new Label(Localization.get("menu.server.title"), skin.get("title", Label.LabelStyle.class)); saveLabel = new Label(Localization.get("menu.server.save", save.name), skin); saveLabel.setAlignment(Align.center); port = new TextField("", skin); port.setMessageText( Localization.get("menu.server.port", Settings.getIntegerSettingValue(Settings.NETWORKING_PORT))); port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter()); start = new TextButton(Localization.get("menu.server.start"), skin); back = MenuTools.getBackButton(this); start.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { int p = port.getText().isEmpty() ? Settings.getIntegerSettingValue(Settings.NETWORKING_PORT) : Integer.parseInt(port.getText()); Adapter.setMenu(new ServerRunningMenu(save, p)); } }); stage.addActor(title); stage.addActor(saveLabel); stage.addActor(port); stage.addActor(start); stage.addActor(back); }
public IntegerSetting(int i) { this.i = i; this.hasRange = false; this.rangeStart = 0; this.rangeEnd = 0; this.type = Type.TextField; }
@Override public Actor getActor(VisualSettingManager visualSettingManager) { switch (type) { case TextField: return getTextField(visualSettingManager); case Slider: return getSlider(visualSettingManager); } return null; }
@Override public Actor getActor(VisualSettingManager visualSettingManager) { final TextField textField = new TextField(s, visualSettingManager.getSkin()); textField.addListener(new EventListener() { @Override public boolean handle(Event event) { if (!(event instanceof SettingsMenu.SaveEvent)) return false; set(textField.getText()); return true; } }); return textField; }
public FloatSetting(float f) { this.f = f; this.hasRange = false; this.rangeStart = 0; this.rangeEnd = 0; this.type = Type.TextField; }
public ConsoleDialog(UserInterface linkedInterface) { super("Console", Settings.DEFAULT_SKIN); this.linkedInterface = linkedInterface; setBounds(400, 700, 600, 150); Button closeButton = new CloseButton(this); getTitleTable().add(closeButton).size(15, 15).padRight(-5).top().right(); Table table = getContentTable(); inputTextField = new TextField("", getSkin()); inputTextField.addListener(new InputListener(){ @Override public boolean keyDown(InputEvent event, int keycode) { if(!ConsoleDialog.this.isVisible()) inputTextField.setDisabled(true); if(keycode == Keys.ENTER) { addMessageToList(); sendCommandToExecute(); } return false; } }); consolePane = new ConsolePane(); table.add(consolePane).fillX(); table.row(); table.add(inputTextField).width(570).align(Align.bottom); table.align(Align.bottom); }
public ChatDialog(UserInterface linkedInterface) { super("Chat", Settings.DEFAULT_SKIN); this.linkedInterface = linkedInterface; setBounds(0, 0, 400, 200); Button closeButton = new CloseButton(this); getTitleTable().add(closeButton).size(15, 15).padRight(-5).top().right(); Table table = getContentTable(); chatTextField = new TextField("", getSkin()); chatTextField.addListener(new InputListener(){ @Override public boolean keyDown(InputEvent event, int keycode) { if(!ChatDialog.this.isVisible()) chatTextField.setDisabled(true); if(keycode == Keys.ENTER) sendMessage(); return false; } }); chatPane = new ChatPane(); table.add(chatPane).fillX(); table.row(); table.add(chatTextField).fillX().align(Align.bottom); table.align(Align.bottom); }