Class Entity2DView<T extends IEntity>

java.lang.Object
games.stendhal.client.gui.j2d.entity.Entity2DView<T>
Type Parameters:
T - type of entity
All Implemented Interfaces:
Inspectable, EntityView<T>
Direct Known Subclasses:
FlyOverArea2DView, StackableItem2DView

public abstract class Entity2DView<T extends IEntity> extends Object implements EntityView<T>
The 2D view of an entity.
  • Field Details

    • entity

      protected T extends IEntity entity
      The entity this view is for.
    • animatedChanged

      protected volatile boolean animatedChanged
      Model values affecting animation.
    • representationChanged

      protected volatile boolean representationChanged
      Model values affecting visual representation changed.
    • visibilityChanged

      protected volatile boolean visibilityChanged
      The visibility value changed.
  • Constructor Details

    • Entity2DView

      public Entity2DView()
  • Method Details

    • initialize

      public void initialize(T entity)
      Specified by:
      initialize in interface EntityView<T extends IEntity>
    • applyChanges

      public void applyChanges()
      Handle entity changes.
      Specified by:
      applyChanges in interface EntityView<T extends IEntity>
    • buildActions

      protected void buildActions(List<String> list)
      Build a list of entity specific actions. NOTE: The first entry should be the default.
      Parameters:
      list - The list to populate.
    • buildRepresentation

      protected void buildRepresentation(T entity)
      Rebuild the representation using the base entity.
      Parameters:
      entity - the eEntity to build the representation for
    • calculateOffset

      protected void calculateOffset(T entity, int swidth, int sheight)
      Calculate sprite image offset for the entity.
      Parameters:
      entity - entity
      swidth - The sprite width (in pixels).
      sheight - The sprite height (in pixels).
    • attachSprite

      public void attachSprite(Sprite sprite, HorizontalAlignment xAlign, VerticalAlignment yAlign, int xOffset, int yOffset)
      Attach a sprite to the view. These are drawn on top of the main view sprite.
      Parameters:
      sprite -
      xAlign - alignment in horizontal direction
      yAlign - alignment in vertical direction
      xOffset - x coordinate offset that is used in addition to the alignment information
      yOffset - y coordinate offset that is used in addition to the alignment information
    • detachSprite

      public void detachSprite(Sprite sprite)
      Detach a sprite that has been previously attached to the view.
      Parameters:
      sprite - sprite to be detached
    • draw

      public void draw(Graphics2D g2d)
      Draw the entity.
      Specified by:
      draw in interface EntityView<T extends IEntity>
      Parameters:
      g2d - The graphics to drawn on.
    • draw

      protected void draw(Graphics2D g2d, int x, int y, int width, int height)
      Draw the entity.
      Parameters:
      g2d - The graphics context.
      x - The drawn X coordinate.
      y - The drawn Y coordinate.
      width - The drawn entity width.
      height - The drawn entity height.
    • drawEntity

      protected void drawEntity(Graphics2D g2d, int x, int y, int width, int height)
      Draw the base entity part.
      Parameters:
      g2d - The graphics context.
      x - The drawn X coordinate.
      y - The drawn Y coordinate.
      width - The drawn entity width.
      height - The drawn entity height.
    • drawTop

      public void drawTop(Graphics2D g2d)
      Draw the top layer parts of an entity. This will be on down after all other game layers are rendered.
      Specified by:
      drawTop in interface EntityView<T extends IEntity>
      Parameters:
      g2d - The graphics to drawn on.
    • drawTop

      protected void drawTop(Graphics2D g2d, int x, int y, int width, int height)
      Draw the entity.
      Parameters:
      g2d - The graphics context.
      x - The drawn X coordinate.
      y - The drawn Y coordinate.
      width - The drawn entity width.
      height - The drawn entity height.
    • getArea

      public Rectangle getArea()
      Get the screen area this is drawn in. NOTE: This only covers the area for the main sprite.
      Specified by:
      getArea in interface EntityView<T extends IEntity>
      Returns:
      The area this draws in.
    • getDrawingArea

      protected Rectangle getDrawingArea()
      Get the drawn area used by the entity. Used for checking if the entity should be drawn. By default the same as getArea(), but extending classes can override it to return a different area if they need it.
      Returns:
      The area this draws in.
    • getClassResourcePath

      protected String getClassResourcePath()
      Get the class resource sub-path. The is the base sprite image name, relative to translate().
      Returns:
      The resource path.
    • getComposite

      protected AlphaComposite getComposite()
      Get the drawing composite.
      Returns:
      The drawing composite.
    • getHeight

      public int getHeight()
      Get the height.
      Returns:
      The height (in pixels).
    • getSprite

      public Sprite getSprite()
      Get the sprite image for this entity.
      Returns:
      The image representation.
    • getVisibility

      protected int getVisibility()
      Get the entity's visibility.
      Returns:
      The visibility value (0-100).
    • getWidth

      public int getWidth()
      Get the width.
      Returns:
      The width (in pixels).
    • getX

      protected int getX()
      Get the entity's X coordinate.
      Returns:
      The X coordinate (in pixels).
    • getXOffset

      protected int getXOffset()
      Get the X offset alignment adjustment.
      Returns:
      The X offset (in pixels).
    • getY

      protected int getY()
      Get the entity's Y coordinate.
      Returns:
      The Y coordinate (in pixels).
    • getYOffset

      protected int getYOffset()
      Get the Y offset alignment adjustment.
      Returns:
      The Y offset (in pixels).
    • getZIndex

      public int getZIndex()
      Determines on top of which other entities this entity should be drawn. Entities with a high Z index will be drawn on top of ones with a lower Z index. Also, players can only interact with the topmost entity.
      Specified by:
      getZIndex in interface EntityView<T extends IEntity>
      Returns:
      The drawing index.
    • isAnimating

      protected boolean isAnimating()
      Determine if this view is currently animatable.
      Returns:
      true if animating enabled.
    • isContained

      public boolean isContained()
      Determine if this view is contained, and should render in a compressed (it's defined) area without clipping anything important.
      Returns:
      true if contained.
    • reorderActions

      protected void reorderActions(List<String> list)
      Reorder the actions list (if needed). Please use as last resort.
      Parameters:
      list - The list to reorder.
    • setContained

      public void setContained(boolean contained)
      Set whether this view is contained, and should render in a compressed (it's defined) area without clipping anything important.
      Specified by:
      setContained in interface EntityView<T extends IEntity>
      Parameters:
      contained - true if contained.
    • setInspector

      public void setInspector(Inspector inspector)
      Set the content inspector for this entity (if needed).
      Specified by:
      setInspector in interface Inspectable
      Parameters:
      inspector - The inspector.
    • setVisibleScreenArea

      public void setVisibleScreenArea(Rectangle area)
      Specified by:
      setVisibleScreenArea in interface EntityView<T extends IEntity>
    • setSprite

      protected void setSprite(Sprite sprite)
      Set the sprite.
      Parameters:
      sprite - The sprite.
    • translate

      protected String translate(String name)
      Translate a resource name into it's sprite image path.
      Parameters:
      name - The resource name.
      Returns:
      The full resource name.
    • update

      protected void update()
      Handle updates.
    • getActions

      public final String[] getActions()
      Get the list of actions.
      Specified by:
      getActions in interface EntityView<T extends IEntity>
      Returns:
      The list of actions.
    • getEntity

      public T getEntity()
      Get the view's entity.
      Specified by:
      getEntity in interface EntityView<T extends IEntity>
      Returns:
      The view's entity.
    • isMovable

      public boolean isMovable()
      Determine if this entity can be moved (e.g. via dragging).
      Specified by:
      isMovable in interface EntityView<T extends IEntity>
      Returns:
      true if the entity is movable.
    • onAction

      public void onAction()
      Perform the default action.
      Specified by:
      onAction in interface EntityView<T extends IEntity>
    • onHarmlessAction

      public boolean onHarmlessAction()
      Perform the default action unless it is not safe.
      Specified by:
      onHarmlessAction in interface EntityView<T extends IEntity>
      Returns:
      true if the action was performed, false if nothing was done
    • onAction

      public void onAction(ActionType at)
      Perform an action.
      Specified by:
      onAction in interface EntityView<T extends IEntity>
      Parameters:
      at - The action.
    • isInteractive

      public boolean isInteractive()
      is this entity interactive so that the player can click or move it?
      Specified by:
      isInteractive in interface EntityView<T extends IEntity>
      Returns:
      true if the player can interact with it, false otherwise.
    • release

      public void release()
      Release any view resources. This view should not be used after this is called.
      Specified by:
      release in interface EntityView<T extends IEntity>
    • isReleased

      protected boolean isReleased()
      Check if the view has been released. Usually a released view should not be used anymore, but in certain situations it may be preferable to send an action for a deleted entity to the server anyway. That can happen for example with items in bag, where a new view gets created after an item has changed, but the new view represents the same item stack as the old one.
      Returns:
      true if the view has been released, false otherwise
    • getCursor

      public StendhalCursor getCursor()
      gets the mouse cursor image to use for this entity.
      Specified by:
      getCursor in interface EntityView<T extends IEntity>
      Returns:
      StendhalCursor