Package games.stendhal.client.gui.j2d.entity

Source Code of games.stendhal.client.gui.j2d.entity.User2DView

/* $Id: User2DView.java,v 1.31 2010/11/26 21:45:50 martinfuchs Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.client.gui.j2d.entity;

import games.stendhal.client.entity.ActionType;
import games.stendhal.client.entity.IEntity;
import games.stendhal.client.entity.User;
import games.stendhal.client.gui.j2DClient;

import java.util.List;

/**
* The 2D view of a user.
*/
class User2DView extends Player2DView {
  @Override
  public void initialize(final IEntity entity) {
    super.initialize(entity);
    j2DClient.get().setPosition(entity.getX(), entity.getY());
  }
  //
  // RPEntity2DView
  //

  /**
   * Determine is the user can see this entity while in ghostmode.
   *
   * @return <code>true</code> if the client user can see this entity while in
   *         ghostmode.
   */
  @Override
  protected boolean isVisibleGhost() {
    return true;
  }

  //
  // Entity2DView
  //

  /**
   * Build a list of entity specific actions. <strong>NOTE: The first entry
   * should be the default.</strong>
   *
   * @param list
   *            The list to populate.
   */
  @Override
  protected void buildActions(final List<String> list) {
    super.buildActions(list);

    list.remove(ActionType.ATTACK.getRepresentation());
    list.remove(ActionType.ADD_BUDDY.getRepresentation());
    list.remove(ActionType.IGNORE.getRepresentation());
    list.remove(ActionType.UNIGNORE.getRepresentation());
    list.remove(ActionType.PUSH.getRepresentation());
    list.remove(ActionType.TRADE.getRepresentation());

    list.add(ActionType.SET_OUTFIT.getRepresentation());
    list.add(ActionType.WHERE.getRepresentation());

    User user = (User) entity;
    if (user != null) {
      if (user.hasSheep()) {
        list.add(ActionType.LEAVE_SHEEP.getRepresentation());
      }

      if (user.hasPet()) {
        list.add(ActionType.LEAVE_PET.getRepresentation());
      }
    }
  }

  //
  // EntityChangeListener
  //

  /**
   * An entity was changed.
   *
   * @param entity
   *            The entity that was changed.
   * @param property
   *            The property identifier.
   */
  @Override
  public void entityChanged(final IEntity entity, final Object property) {
    super.entityChanged(entity, property);

    if (property == IEntity.PROP_POSITION) {
      j2DClient.get().setPosition(entity.getX(), entity.getY());
    }
  }

  //
  // EntityView
  //

  /**
   * Perform an action.
   *
   * @param at
   *            The action.
   */
  @Override
  public void onAction(final ActionType at) {

    switch (at) {
    case SET_OUTFIT:
      j2DClient.get().chooseOutfit();
      break;
     
    case WHERE:
    case LEAVE_SHEEP:
    case LEAVE_PET:
      at.send(at.fillTargetInfo(entity.getRPObject()));
      break;

    default:
      super.onAction(at);
      break;
    }
  }
}
TOP

Related Classes of games.stendhal.client.gui.j2d.entity.User2DView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.