Beispiel #1
0
  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);
  }
  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());
      //				}
      //			});
    }
  }
  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);
  }