Esempio n. 1
0
 /**
  * Creates a new selector.
  *
  * @param screenDefinition Current screen definition
  */
 public Selector(final ScreenDefinition screenDefinition) {
   this.screenDefinition = screenDefinition;
   offsetX = 0;
   offsetY = 0;
   selectorPosX = screenDefinition.getWidthGameFrame() / 2;
   selectorPosY = screenDefinition.getHeight() / 2;
 }
Esempio n. 2
0
  /**
   * Centers the screen at the given position.
   *
   * @param pos position to center.
   */
  public void center(final Pos pos) {
    int newOffsetX = pos.getX() - screenDefinition.getWidthGameFrame() / 2;
    int newOffsetY = pos.getY() - screenDefinition.getHeight() / 2;
    setOffset(newOffsetX - offsetX, newOffsetY - offsetY);

    Pos selectedPos = getSelectedPosition();
    int newSelector1PosX = pos.getX() - selectedPos.getX();
    int newSelector1PosY = pos.getY() - selectedPos.getY();
    setSelectedPos(newSelector1PosX, newSelector1PosY);
  }
Esempio n. 3
0
  /**
   * Updates the x and the y offset. This changes the displayed fields.
   *
   * <p>The implementation ensured that the displayed fields are always between 0 and
   * screenDefinition.getWidthGameFrame() for x values and between 0 and
   * screenDefinition.getHeight() for y values.
   *
   * @param offX amount of change the x offset
   * @param offY amount of change the y offset
   */
  public void setOffset(final int offX, final int offY) {
    offsetX = offsetX + offX;
    if (offsetX + screenDefinition.getWidthGameFrame() > WorldMap.getInstance().getSizeX() - 1) {
      offsetX = WorldMap.getInstance().getSizeX() - screenDefinition.getWidthGameFrame() - 1;
    }
    if (offsetX < 0) {
      offsetX = 0;
    }

    offsetY = offsetY + offY;
    if (offsetY + screenDefinition.getHeight() > WorldMap.getInstance().getSizeY() - 1) {
      offsetY = WorldMap.getInstance().getSizeY() - screenDefinition.getHeight() - 1;
    }
    if (offsetY < 0) {
      offsetY = 0;
    }
  }
Esempio n. 4
0
  /**
   * Updates the x and the y position of the cursor.
   *
   * <p>The implementation ensured that the displayed fields are always between 0 and
   * screenDefinition.getWidthGameFrame() for x values and between 0 and
   * screenDefinition.getHeight() for y values.
   *
   * @param offsetX amount of change the x value
   * @param offsetY amount of change the y value
   */
  protected void setSelectedPos(final int offsetX, final int offsetY) {
    selectorPosX = selectorPosX + offsetX;
    if (selectorPosX > screenDefinition.getWidthGameFrame()) {
      selectorPosX = screenDefinition.getWidthGameFrame();
    }
    if (selectorPosX < 0) {
      selectorPosX = 0;
    }

    selectorPosY = selectorPosY + offsetY;
    if (selectorPosY > screenDefinition.getHeight()) {
      selectorPosY = screenDefinition.getHeight();
    }
    if (selectorPosY < 0) {
      selectorPosY = 0;
    }
  }
Esempio n. 5
0
 /**
  * Move the cursor one step east. The distance is depending on the current selection mode. If the
  * selection mode is off, the cursor moves 10 fields, otherwise one field.
  *
  * <p>The implementation ensured that the displayed fields are always between 0 and
  * screenDefinition.getWidthGameFrame().
  *
  * @param isSelectionMode Flag, if a selection mode is on
  */
 public void right(final boolean isSelectionMode) {
   if (isSelectionMode) {
     setSelectedPos(1, 0);
     if (selectorPosX == screenDefinition.getWidthGameFrame() - 4) {
       int offset = offsetX;
       setOffset(10, 0);
       setSelectedPos(offset - offsetX, 0);
     }
   } else {
     setOffset(10, 0);
   }
 }
Esempio n. 6
0
 /**
  * Move the cursor one step south. The distance is depending on the current selection mode. If the
  * selection mode is off, the cursor moves 10 fields, otherwise one field.
  *
  * <p>The implementation ensured that the displayed fields are always between 0 and
  * screenDefinition.getHeight().
  *
  * @param isSelectionMode Flag, if a selection mode is on
  */
 public void down(final boolean isSelectionMode) {
   if (isSelectionMode) {
     setSelectedPos(0, 1);
     if (selectorPosY == screenDefinition.getHeight() - 4) {
       int offset = offsetY;
       setOffset(0, 10);
       setSelectedPos(0, offset - getOffsetY());
     }
   } else {
     setOffset(0, 10);
   }
 }