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());
      //				}
      //			});
    }
  }
예제 #2
0
  public PanelProperties(String title, Skin skin) {
    super(title, skin);

    scroll.getListeners().removeIndex(0);

    TextFieldFilter filter =
        new TextFieldFilter() {
          @Override
          public boolean acceptChar(TextField textField, char c) {
            textBuffer = textField.getText();
            cursorBuffer = textField.getCursorPosition();
            if (c == '-' && (cursorBuffer == 0 || updateProperties)) return true;
            if (c >= '0' && c <= '9' || c == '.') return true;

            return false;
          }
        };

    TextFieldListener listener =
        new TextFieldListener() {
          @Override
          public void keyTyped(TextField textField, char c) {
            if (editActors == null || c == 0 || c == '\t') return;

            if (c == '\r' || c == '\n') {
              getStage().setKeyboardFocus(null);
              return;
            }

            GroupCommand groupCommand = new GroupCommand();

            for (Actor model : editActors) {
              if (textField == name) {
                NameCommand nameCommand = new NameCommand();
                nameCommand.setNewName(textField.getText());
                nameCommand.addActor(model);
                nameCommand.addUpdater(
                    ((MainScreen) GameInstance.game.getScreen()).getTree().panelUpdater);
                groupCommand.addCommand(nameCommand);
              } else {
                if (c == '.'
                    && textField.getText().indexOf(c) != textField.getText().lastIndexOf(c)) {
                  textField.setText(textBuffer);
                  textField.setCursorPosition(cursorBuffer);
                  return;
                }

                if (textField.getText().isEmpty()) return;

                try {
                  Float value = Float.parseFloat(textField.getText());
                  if (textField == positionX) {
                    TranslateCommand transCommand = new TranslateCommand();
                    transCommand.setNewPosition(value, model.getY());
                    transCommand.addActor(model);
                    groupCommand.addCommand(transCommand);
                  } else if (textField == positionY) {
                    TranslateCommand transCommand = new TranslateCommand();
                    transCommand.setNewPosition(model.getX(), value);
                    transCommand.addActor(model);
                    groupCommand.addCommand(transCommand);
                  } else if (textField == rotation) {
                    RotateCommand rotateCommand = new RotateCommand();
                    rotateCommand.setAngle(value);
                    rotateCommand.addActor(model);
                    groupCommand.addCommand(rotateCommand);
                  } else if (textField == scaleX) {
                    ScaleCommand scaleCommand = new ScaleCommand();
                    scaleCommand.setNewScale(
                        value, lockRatio.isChecked() ? value : model.getScaleY());
                    scaleCommand.addActor(model);
                    groupCommand.addCommand(scaleCommand);

                    if (lockRatio.isChecked()) scaleY.setText(scaleX.getText());
                  } else if (textField == scaleY) {
                    ScaleCommand scaleCommand = new ScaleCommand();
                    scaleCommand.setNewScale(model.getScaleX(), value);
                    scaleCommand.addActor(model);
                    groupCommand.addCommand(scaleCommand);
                  } else {
                    ColorCommand colorCommand = new ColorCommand();
                    colorCommand.addActor(model);
                    value /= 255.0f;
                    value = Math.min(1.0f, Math.max(0.0f, value));
                    if (textField == r) colorCommand.setR(value);
                    else if (textField == g) colorCommand.setG(value);
                    else if (textField == b) colorCommand.setB(value);
                    else colorCommand.setA(value);
                    groupCommand.addCommand(colorCommand);
                  }
                } catch (NumberFormatException exception) {
                }
              }
            }

            if (groupCommand.getCommands().size > 0)
              CommandController.instance.addCommand(groupCommand, false);
          }
        };

    InputListener tabListener =
        new InputListener() {
          @Override
          public boolean keyUp(InputEvent event, int keycode) {
            if (event.getCharacter() == '\t') {
              Actor actor = event.getListenerActor();
              if (actor instanceof TextField) ((TextField) actor).selectAll();
            }
            return true;
          }
        };

    // name
    name = new TextField("", skin);
    name.setTextFieldListener(listener);
    name.addListener(tabListener);
    content.add(new Label("Name: ", skin));
    content.add(name);

    // visible
    visible = new CheckBox(" visible", skin);
    visible.getStyle().disabledFontColor = disableColor;
    visible.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            if (updateProperties || editActors == null) return;

            GroupCommand groupCommand = new GroupCommand();

            for (Actor model : editActors) {
              VisibleCommand command = new VisibleCommand();
              command.setNewVisible(visible.isChecked());
              command.addActor(model);
              groupCommand.addCommand(command);
            }

            CommandController.instance.addCommand(groupCommand);
          }
        });
    content.add(visible);

    content.row();

    // position
    positionX = new TextField("", skin);
    positionX.setTextFieldListener(listener);
    positionX.setTextFieldFilter(filter);
    positionX.addListener(tabListener);
    positionY = new TextField("", skin);
    positionY.setTextFieldListener(listener);
    positionY.setTextFieldFilter(filter);
    positionY.addListener(tabListener);
    content.add(new Label("Position: ", skin));
    content.add(positionX);
    content.add(positionY);

    content.row();

    // angle
    rotation = new TextField("", skin);
    rotation.setTextFieldListener(listener);
    rotation.setTextFieldFilter(filter);
    rotation.addListener(tabListener);
    content.add(new Label("Angle: ", skin));
    content.add(rotation);

    lockRatio = new CheckBox(" ratio", skin);
    lockRatio.getStyle().disabledFontColor = disableColor;
    lockRatio.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            if (updateProperties || editActors == null) return;

            scaleY.setDisabled(lockRatio.isChecked());
            scaleY.setColor(lockRatio.isChecked() ? disableColor : enableColor);

            if (lockRatio.isChecked()) {
              scaleY.setText(scaleX.getText());

              GroupCommand groupCommand = new GroupCommand();
              for (Actor model : editActors) {
                ScaleCommand scaleCommand = new ScaleCommand();
                scaleCommand.setNewScale(model.getScaleX(), model.getScaleX());
                scaleCommand.addActor(model);
                groupCommand.addCommand(scaleCommand);
              }
              CommandController.instance.addCommand(groupCommand);
            }
          }
        });
    content.add(lockRatio);

    content.row();

    // scale
    scaleX = new TextField("", skin);
    scaleX.setTextFieldListener(listener);
    scaleX.setTextFieldFilter(filter);
    scaleX.addListener(tabListener);
    scaleY = new TextField("", skin);
    scaleY.setTextFieldListener(listener);
    scaleY.setTextFieldFilter(filter);
    scaleX.addListener(tabListener);
    content.add(new Label("Scale: ", skin));
    content.add(scaleX);
    content.add(scaleY);

    content.row();

    r = new TextField("", skin);
    r.setTextFieldListener(listener);
    r.setTextFieldFilter(filter);
    r.addListener(tabListener);
    g = new TextField("", skin);
    g.setTextFieldListener(listener);
    g.setTextFieldFilter(filter);
    g.addListener(tabListener);
    b = new TextField("", skin);
    b.setTextFieldListener(listener);
    b.setTextFieldFilter(filter);
    b.addListener(tabListener);
    a = new TextField("", skin);
    a.setTextFieldListener(listener);
    a.setTextFieldFilter(filter);
    a.addListener(tabListener);
    content.add(new Label("Color: ", skin));

    Table colorTable = new Table(skin);
    colorTable.defaults().spaceBottom(10);
    colorTable.defaults().space(10);
    colorTable.add(r).width(75);
    colorTable.add(g).width(75);
    content.add(colorTable);
    colorTable = new Table(skin);
    colorTable.defaults().spaceBottom(10);
    colorTable.defaults().space(10);
    colorTable.add(b).width(75);
    colorTable.add(a).width(75);
    content.add(colorTable);

    content.row();

    final TextButtonStyle styleButton = skin.get(TextButtonStyle.class);
    TextButtonStyle style =
        new TextButtonStyle(styleButton.up, styleButton.down, styleButton.down, styleButton.font);
    style.disabledFontColor = disableColor;
    advancedButton = new TextButton("Advanced", style);
    advancedButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            PanelAdvanced advanced = ((MainScreen) GameInstance.game.getScreen()).getAdvanced();
            advanced.setVisible(advancedButton.isChecked());
          }
        });
    content.add(new Label("Settings: ", skin));
    content.add(advancedButton);

    setSize(450, 300);
    setEditActors(null);
  }
예제 #3
0
  @Override
  public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion image = new TextureRegion(texture1);
    TextureRegion imageFlipped = new TextureRegion(image);
    imageFlipped.flip(true, true);
    TextureRegion image2 = new TextureRegion(texture2);
    // stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, new
    // PolygonSpriteBatch());
    stage = new Stage();
    // stage.setViewport(new ExtendViewport(800, 480));
    Gdx.input.setInputProcessor(stage);

    // Group.debug = true;

    ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
    style.imageUp = new TextureRegionDrawable(image);
    style.imageDown = new TextureRegionDrawable(imageFlipped);
    ImageButton iconButton = new ImageButton(style);

    Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin, "toggle");
    Button imgButton = new Button(new Image(image), skin);
    Button imgToggleButton = new Button(new Image(image), skin, "toggle");

    Label myLabel = new Label("this is some text.", skin);
    myLabel.setWrap(true);

    Table t = new Table();
    t.row();
    t.add(myLabel);

    t.layout();

    CheckBox checkBox = new CheckBox("Check me", skin);
    final Slider slider = new Slider(0, 10, 1, false, skin);
    TextField textfield = new TextField("", skin);
    textfield.setMessageText("Click here!");
    SelectBox dropdown = new SelectBox(skin);
    dropdown.setItems(
        "Android1",
        "Windows1",
        "Linux1",
        "OSX1",
        "Android2",
        "Windows2",
        "Linux2",
        "OSX2",
        "Android3",
        "Windows3",
        "Linux3",
        "OSX3",
        "Android4",
        "Windows4",
        "Linux4",
        "OSX4",
        "Android5",
        "Windows5",
        "Linux5",
        "OSX5",
        "Android6",
        "Windows6",
        "Linux6",
        "OSX6",
        "Android7",
        "Windows7",
        "Linux7",
        "OSX7");
    dropdown.setSelected("Linux6");
    Image imageActor = new Image(image2);
    ScrollPane scrollPane = new ScrollPane(imageActor);
    List list = new List(skin);
    list.setItems(listEntries);
    list.getSelection().setMultiple(true);
    list.getSelection().setRequired(false);
    // list.getSelection().setToggle(true);
    ScrollPane scrollPane2 = new ScrollPane(list, skin);
    scrollPane2.setFlickScroll(false);
    SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin, "default-horizontal");
    fpsLabel = new Label("fps:", skin);

    // configures an example of a TextField in password mode.
    final Label passwordLabel = new Label("Textfield in password mode: ", skin);
    final TextField passwordTextField = new TextField("", skin);
    passwordTextField.setMessageText("password");
    passwordTextField.setPasswordCharacter('*');
    passwordTextField.setPasswordMode(true);

    // window.debug();
    Window window = new Window("Dialog", skin);
    window.getButtonTable().add(new TextButton("X", skin)).height(window.getPadTop());
    window.setPosition(0, 0);
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    window.add(iconButton);
    window.add(buttonMulti);
    window.add(imgButton);
    window.add(imgToggleButton);
    window.row();
    window.add(checkBox);
    window.add(slider).minWidth(100).fillX().colspan(3);
    window.row();
    window.add(dropdown);
    window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
    window.row();
    window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
    window.row();
    window.add(passwordLabel).colspan(2);
    window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
    window.row();
    window.add(fpsLabel).colspan(4);
    window.pack();

    // stage.addActor(new Button("Behind Window", skin));
    stage.addActor(window);

    textfield.setTextFieldListener(
        new TextFieldListener() {
          public void keyTyped(TextField textField, char key) {
            if (key == '\n') textField.getOnscreenKeyboard().show(false);
          }
        });

    slider.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("UITest", "slider: " + slider.getValue());
          }
        });

    iconButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            new Dialog("Some Dialog", skin, "dialog") {
              protected void result(Object object) {
                System.out.println("Chosen: " + object);
              }
            }.text("Are you enjoying this demo?")
                .button("Yes", true)
                .button("No", false)
                .key(Keys.ENTER, true)
                .key(Keys.ESCAPE, false)
                .show(stage);
          }
        });
  }
예제 #4
0
  public void signUp() {
    shouldClear = true;
    // shouldAddScrollPane = false;
    shouldAddScrollPane = true;
    charityScrollPane = true;
    characterScrollPane = false;
    menu = Assets.menuSplashBlankRegion;
    menuComponents = new ArrayList<MenuComponent>();
    menuTextFields = new HashMap<String, TextField>();

    menuComponents.add(
        0, new MenuComponent(600, 100, 175, 75, Assets.menuButtonSmallRegion)); // submit
    menuComponents.add(
        1, new MenuComponent(400, 100, 175, 75, Assets.menuButtonSmallRegion)); // return

    // right now I am using the metric of setting the width to be 175 and height 50 (for textfields)
    // and making them 88 units below the buttons and 73 units below. thats maybe like 1 or 2 units
    // higher than it needs to be, but it looks aight

    TextField signUpTextField = new TextField(("SIGN UP!"), Assets.tfsTrans100);
    signUpTextField.setPosition(50, 330);
    signUpTextField.setWidth(700);
    signUpTextField.setHeight(150);
    signUpTextField.setAlignment(Align.center);
    signUpTextField.setFocusTraversal(false);
    signUpTextField.setDisabled(true);

    TextField returnTextField = new TextField(("RETURN"), Assets.tfsTransWhite40);
    returnTextField.setPosition(312, 27);
    returnTextField.setWidth(175); // to be centered well make the width about 325
    returnTextField.setHeight(50);
    returnTextField.setAlignment(Align.center);
    returnTextField.setFocusTraversal(false);
    returnTextField.setDisabled(true);

    TextField submitTextField = new TextField(("SUBMIT"), Assets.tfsTransWhite40);
    submitTextField.setPosition(512, 27);
    submitTextField.setWidth(175);
    submitTextField.setHeight(50);
    submitTextField.setAlignment(Align.center);
    submitTextField.setFocusTraversal(false);
    submitTextField.setDisabled(true);

    final TextField usernameTextField = new TextField("USERNAME", Assets.tfs);
    usernameTextField.setPosition(100, 300);
    usernameTextField.setWidth(300);
    usernameTextField.setHeight(50);
    usernameTextField.setFocusTraversal(false);
    usernameTextField.addListener(
        new ClickListener() {
          public void clicked(InputEvent e, float x, float y) {
            if (usernameTextField.getText().equals("USERNAME")) usernameTextField.setText("");
          }
        });
    usernameTextField.setTextFieldListener(
        new TextField.TextFieldListener() { // if enter is pressed, remove the keyboard
          @Override
          public void keyTyped(TextField textField, char c) {
            if ((c == '\r') || (c == '\n')) {
              Gdx.input.setOnscreenKeyboardVisible(false);
              unfocusAll = true;
            }
          }
        });

    final TextField passwordTextField = new TextField("PASSWORD", Assets.tfs);
    // passwordTextField.setPosition(100, 240);
    passwordTextField.setPosition(450, 300);
    passwordTextField.setPasswordMode(false);
    // passwordTextField.setPasswordCharacter('*');
    passwordTextField.setWidth(300);
    passwordTextField.setHeight(50);
    passwordTextField.setFocusTraversal(false);
    passwordTextField.addListener(
        new ClickListener() {
          public void clicked(InputEvent e, float x, float y) {
            if (passwordTextField.getText().equals("PASSWORD"))
              passwordTextField.setPasswordMode(true);
            passwordTextField.setPasswordCharacter('*');
            passwordTextField.setText("");
          }
        });
    passwordTextField.setTextFieldListener(
        new TextField.TextFieldListener() { // if enter is pressed, remove the keyboard
          @Override
          public void keyTyped(TextField textField, char c) {
            if ((c == '\r') || (c == '\n')) {
              Gdx.input.setOnscreenKeyboardVisible(false);
              unfocusAll = true;
            }
          }
        });

    /*final TextField emailTextField = new TextField("EMAIL", Assets.tfs);
    emailTextField.setPosition(450, 300);
    emailTextField.setWidth(300);
    emailTextField.setHeight(50);
    emailTextField.setFocusTraversal(false);
    emailTextField.addListener(new ClickListener() {
        public void clicked(InputEvent e, float x, float y) {
            if (emailTextField.getText().equals("EMAIL"))
                emailTextField.setText("");

        }
    });
    emailTextField.setTextFieldListener(new TextField.TextFieldListener() {//if enter is pressed, remove the keyboard
        @Override
        public void keyTyped(TextField textField, char c) {
            if ((c == '\r') || (c == '\n')) {
                Gdx.input.setOnscreenKeyboardVisible(false);
                unfocusAll = true;
            }
        }
    });*/

    final TextField charityTextField =
        new TextField(
            "SELECT A CHARITY",
            Assets.tfsTrans40); // obviously want to replace these with a real charity selection
    charityTextField.setPosition(250, 240);
    charityTextField.setDisabled(true);
    charityTextField.setWidth(300);
    charityTextField.setHeight(50);
    charityTextField.setFocusTraversal(false);

    menuTextFields.put("usernameTF", usernameTextField);
    menuTextFields.put("passwordTF", passwordTextField);
    // menuTextFields.put("emailTF", emailTextField);
    menuTextFields.put("charityTF", charityTextField);
    menuTextFields.put("returnTF", returnTextField);
    menuTextFields.put("submitTF", submitTextField);
    menuTextFields.put("signUpTF", signUpTextField);

    menuNumber = this.MENU_SIGNUP;
  }
예제 #5
0
  public void signIn() {
    shouldClear = true;
    shouldAddScrollPane = false;
    charityScrollPane = false;
    characterScrollPane = false;
    scrollPaneContainer = null;
    menu = Assets.menuSplashBlankRegion;
    menuComponents = new ArrayList<MenuComponent>();
    menuTextFields = new HashMap<String, TextField>();

    menuComponents.add(
        0, new MenuComponent(600, 100, 175, 75, Assets.menuButtonSmallRegion)); // lets go
    menuComponents.add(
        1, new MenuComponent(400, 100, 175, 75, Assets.menuButtonSmallRegion)); // sign up

    // right now I am using the metric of setting the width to be 175 and height 50 (for textfields)
    // and making them 88 units below the buttons and 73 units below. thats maybe like 1 or 2 units
    // higher than it needs to be, but it looks aight

    menuComponents.add(2, new MenuComponent(45, 45, 178, 267, Assets.menuSpenceRegion));

    TextField logInTextField = new TextField(("LOG IN"), Assets.tfsTrans100);
    logInTextField.setPosition(50, 330);
    logInTextField.setWidth(700);
    logInTextField.setHeight(150);
    logInTextField.setAlignment(Align.center);
    logInTextField.setFocusTraversal(false);
    logInTextField.setDisabled(true);

    TextField letsGoTextField = new TextField(("LETS GO"), Assets.tfsTransWhite40);
    letsGoTextField.setPosition(512, 27);
    letsGoTextField.setWidth(175); // to be centered well make the width about 325
    letsGoTextField.setHeight(50);
    letsGoTextField.setAlignment(Align.center);
    letsGoTextField.setFocusTraversal(false);
    letsGoTextField.setDisabled(true);

    TextField signUpTextField = new TextField(("SIGN UP"), Assets.tfsTransWhite40);
    signUpTextField.setPosition(312, 27);
    signUpTextField.setWidth(175);
    signUpTextField.setHeight(50);
    signUpTextField.setAlignment(Align.center);
    signUpTextField.setFocusTraversal(false);
    signUpTextField.setDisabled(true);

    final TextField usernameTextField = new TextField("USERNAME", Assets.tfs);
    usernameTextField.setPosition(50, 270);
    usernameTextField.setWidth(300);
    usernameTextField.setHeight(50);
    usernameTextField.setFocusTraversal(false);
    usernameTextField.addListener(
        new ClickListener() {
          public void clicked(InputEvent e, float x, float y) {
            if (usernameTextField.getText().equals("USERNAME")) usernameTextField.setText("");
          }
        });
    usernameTextField.setTextFieldListener(
        new TextField.TextFieldListener() { // if enter is pressed, remove the keyboard
          @Override
          public void keyTyped(TextField textField, char c) {
            if ((c == '\r') || (c == '\n')) {
              Gdx.input.setOnscreenKeyboardVisible(false);
              unfocusAll = true;
            }
          }
        });

    final TextField passwordTextField = new TextField("PASSWORD", Assets.tfs);
    passwordTextField.setPosition(450, 270);
    passwordTextField.setPasswordMode(false);
    // passwordTextField.setPasswordCharacter('*');
    passwordTextField.setWidth(300);
    passwordTextField.setHeight(50);
    passwordTextField.setFocusTraversal(false);
    passwordTextField.addListener(
        new ClickListener() {
          public void clicked(InputEvent e, float x, float y) {
            if (passwordTextField.getText().equals("PASSWORD"))
              passwordTextField.setPasswordMode(true);
            passwordTextField.setPasswordCharacter('*');
            passwordTextField.setText("");
          }
        });
    passwordTextField.setTextFieldListener(
        new TextField.TextFieldListener() { // if enter is pressed, remove the keyboard
          @Override
          public void keyTyped(TextField textField, char c) {
            if ((c == '\r') || (c == '\n')) {
              Gdx.input.setOnscreenKeyboardVisible(false);
              unfocusAll = true;
            }
          }
        });

    menuTextFields.put("usernameTF", usernameTextField);
    menuTextFields.put("passwordTF", passwordTextField);
    menuTextFields.put("letsGoTF", letsGoTextField);
    menuTextFields.put("signUpTF", signUpTextField);
    menuTextFields.put("loginTF", logInTextField);

    menuNumber = this.MENU_SIGNIN;
  }