コード例 #1
0
  /** Updates the information displayed in the fields. */
  public void update() {
    super.update(); // update the common fields

    InteractiveEntity interactiveEntity = (InteractiveEntity) entity;
    String sprite = interactiveEntity.getProperty("sprite");
    String behavior = interactiveEntity.getProperty("behavior");
    EntitySubtype subtype = interactiveEntity.getSubtype();

    boolean hasSprite = (!sprite.equals("_none"));

    withSpriteField.setSelected(hasSprite);
    spriteField.setSelectedId(hasSprite ? sprite : "");

    spriteField.setEnabled(hasSprite);

    if (behavior.equals("map")) {
      behaviorField.setSelectedIndex(1);
      messageField.setEnabled(false);
      itemField.setEnabled(false);
    } else if (behavior.substring(0, 5).equals("item#")) {
      behaviorField.setSelectedIndex(2);
      messageField.setEnabled(false);
      itemField.setEnabled(true);
      itemField.setSelectedId(behavior.substring(5));
    } else if (behavior.substring(0, 7).equals("dialog#")) {
      behaviorField.setSelectedIndex(0);
      messageField.setEnabled(true);
      itemField.setEnabled(false);
      messageField.setText(behavior.substring(7));
    }
  }
コード例 #2
0
  /** Creates the specific fields for this kind of entity. */
  protected void createSpecificFields() {

    // has a sprite?
    withSpriteField = new JCheckBox("Display a sprite");
    addField("Visibility", withSpriteField);

    // sprite name
    spriteField = new ResourceChooser(ResourceType.SPRITE, true);
    addField("Sprite name", spriteField);

    // behavior
    behaviorField = new RadioField("Show a message", "Call the map script", "Call an item script");
    addField("Action", behaviorField);

    // message
    messageField = new JTextField(15);
    addField("Message to show", messageField);

    // item
    itemField = new ItemChooser(false, false);
    addField("Item script to call", itemField);

    // listeners
    withSpriteField.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            spriteField.setEnabled(withSpriteField.isSelected());
          }
        });

    behaviorField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            messageField.setEnabled(behaviorField.getSelectedIndex() == 0);
            itemField.setEnabled(behaviorField.getSelectedIndex() == 2);
          }
        });

    subtypeField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {

            Subtype subtype = (Subtype) subtypeField.getValue();
            withSpriteField.setEnabled(subtype != Subtype.NON_PLAYING_CHARACTER);
          }
        });
  }