Пример #1
0
 @Override
 public void onTilesetParsed(Tileset parsedTileset) {
   if (loadTilesets && !parsedTileset.isTextureLoaded()) {
     parsedTileset.loadTexture(fileHandle.parent());
   }
   this.tilesets.add(parsedTileset);
 }
  /**
   * Get the animated sprite for an indexed tile of a tileset.
   *
   * @param tileset The tileset to load from.
   * @param index The index with-in the tileset.
   * @return A sprite, or <code>null</code> if no mapped sprite.
   */
  public Sprite getSprite(final Tileset tileset, final int index) {
    final Mapping mapping = animations.get(Integer.valueOf(index));

    if (mapping == null) {
      return null;
    }

    final int[] frameIndexes = mapping.getIndices();
    final int[] frameDelays = mapping.getDelays();

    final Sprite[] frames = new Sprite[frameIndexes.length];

    for (int i = 0; i < frameIndexes.length; i++) {
      frames[i] = tileset.getSprite(frameIndexes[i]);
    }

    // Use the reference of the first frame as the reference for the whole
    // group
    Object ref = null;
    Sprite first = frames[0];
    if (first != null) {
      ref = first.getReference();
    }
    return new AnimatedSprite(frames, frameDelays, true, ref);
  }
Пример #3
0
  /** Loads the icons for the tile patterns list. */
  private void loadIcons() {

    tilePatternIcons.clear();

    for (TilePattern tilePattern : tileset.getTilePatterns()) {
      tilePatternIcons.add(new TilePatternIcon(tilePattern, tileset));
    }
  }
Пример #4
0
  /** Closes this editor without confirmation. */
  @Override
  public void close() {
    tileset.deleteObservers();

    // Notify the children views.
    tilePatternsView.setTileset(null);
    tilesetImageView.setTileset(null);
  }
Пример #5
0
  /** Saves the current resource. */
  public void save() {

    try {
      tileset.save();
    } catch (QuestEditorException ex) {
      GuiTools.errorDialog("Could not save the tileset: " + ex.getMessage());
    }
  }
Пример #6
0
  /**
   * Constructs a map from a TMX file
   *
   * @param fileHandle A {@link FileHandle} to a .tmx file
   * @param loadTilesets True if the tileset images should be loaded
   * @throws IOException Thrown if the map file could not be parsed
   */
  public TiledMap(FileHandle fileHandle, boolean loadTilesets) throws IOException {
    this();
    this.loadTilesets = loadTilesets;
    this.fileHandle = fileHandle;

    TiledParser parser = new TiledParser();
    parser.addListener(this);
    parser.parse(fileHandle);

    if (loadTilesets) {
      layerCache = new SpriteCache(getWidth() * getHeight() * tileLayers.size(), true);
      for (int layer = 0; layer < tileLayers.size(); layer++) {
        layerCache.beginCache();
        for (int y = 0; y < getHeight(); y++) {
          for (int x = 0; x < getWidth(); x++) {
            int tileId = tileLayers.get(layer).getTileId(x, y);

            if (tileId > 0) {
              int tileRenderX = x * getTileWidth();
              int tileRenderY = y * getTileHeight();

              for (int i = 0; i < tilesets.size(); i++) {
                Tileset tileset = tilesets.get(i);
                if (tileset.contains(tileId)) {
                  layerCache.add(tileset.getTile(tileId).getTileImage(), tileRenderX, tileRenderY);
                  break;
                }
              }
            }
          }
        }
        int layerCacheId = layerCache.endCache();
        layerCacheIds.put(tileLayers.get(layer), layerCacheId);
      }
    }
  }
Пример #7
0
  /**
   * This function is called when the user wants to close the current tileset. If the tileset is not
   * saved, we propose to save it.
   *
   * @return false if the user cancelled
   */
  public boolean checkCurrentFileSaved() {
    boolean result = true;

    if (tileset != null && !tileset.isSaved()) {
      int answer =
          JOptionPane.showConfirmDialog(
              this,
              "The tileset has been modified. Do you want to save it?",
              "Save the modifications",
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.WARNING_MESSAGE);
      if (answer == JOptionPane.YES_OPTION) {
        save();
      } else if (answer == JOptionPane.CANCEL_OPTION) {
        result = false;
      }
    }

    return result;
  }
Пример #8
0
  /**
   * Sets the tileset observed.
   *
   * @param tileset the current tileset, or null if there is no tileset
   */
  public void setTileset(Tileset tileset) {

    if (tileset != this.tileset) {

      if (this.tileset != null) {
        this.tileset.deleteObserver(tilePatternsListModel);
      }

      this.tileset = tileset;
      tilesetPropertiesView.setTileset(tileset);
      tilePatternView.setTileset(tileset);

      if (tileset != null) {
        tileset.addObserver(tilePatternsListModel);

        loadIcons();
        tilePatternsListModel.update(tileset, null);
      } else {
        repaint();
      }
    }
  }
Пример #9
0
  // ____________________________________________________________________________________
  public AmountSelector(Listener listener, Activity context, Tileset tileset, MenuItem item) {
    mItem = item;
    mListener = listener;
    mMax = item.getMaxCount();

    mRoot = Util.inflate(context, R.layout.amount_selector, R.id.dlg_frame);
    ImageView tileView = (ImageView) mRoot.findViewById(R.id.amount_tile);
    final SeekBar seek = ((SeekBar) mRoot.findViewById(R.id.amount_slider));
    if (item.getTile() != 0 && tileset.hasTiles()) {
      tileView.setVisibility(View.VISIBLE);
      tileView.setImageDrawable(new TileDrawable(tileset, item.getTile()));
    } else {
      tileView.setVisibility(View.GONE);
    }

    ((TextView) mRoot.findViewById(R.id.amount_title)).setText(" " + item.getName().toString());

    mAmountText = (TextView) mRoot.findViewById(R.id.amount);
    int pad = 9;
    while (pad <= mMax) pad = pad * 10 + 9;
    int w = (int) FloatMath.floor(mAmountText.getPaint().measureText(" " + Integer.toString(pad)));
    mAmountText.setWidth(w);

    seek.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {
          public void onStopTrackingTouch(SeekBar seekBar) {}

          public void onStartTrackingTouch(SeekBar seekBar) {}

          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAmountText.setText(Integer.toString(progress));
          }
        });
    seek.setMax(mMax);
    seek.setProgress(mMax);

    mRoot
        .findViewById(R.id.btn_inc)
        .setOnTouchListener(
            new OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  mAmountTuner.start(v, seek, true);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                  mAmountTuner.stop(v);
                }
                return true;
              }
            });

    mRoot
        .findViewById(R.id.btn_dec)
        .setOnTouchListener(
            new OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  mAmountTuner.start(v, seek, false);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                  mAmountTuner.stop(v);
                }
                return true;
              }
            });

    mRoot
        .findViewById(R.id.btn_0)
        .setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                if (mRoot != null) {
                  dismiss(seek.getProgress());
                }
              }
            });
    mRoot
        .findViewById(R.id.btn_1)
        .setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                dismiss(-1);
              }
            });

    seek.requestFocus();
    seek.requestFocusFromTouch();
  }
Пример #10
0
 /**
  * Give the name of the resource opened in the editor
  *
  * @return the name of the map
  */
 public String getTitle() {
   return tileset == null ? "" : "Tileset " + tileset.getName();
 }