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
The 2D view of an entity.
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Model values affecting animation.protected T
The entity this view is for.protected boolean
Model values affecting visual representation changed.protected boolean
The visibility value changed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Handle entity changes.void
attachSprite(Sprite sprite, HorizontalAlignment xAlign, VerticalAlignment yAlign, int xOffset, int yOffset)
Attach a sprite to the view.protected void
buildActions(List<String> list)
Build a list of entity specific actions.protected void
buildRepresentation(T entity)
Rebuild the representation using the base entity.protected void
calculateOffset(T entity, int swidth, int sheight)
Calculate sprite image offset for the entity.void
detachSprite(Sprite sprite)
Detach a sprite that has been previously attached to the view.void
draw(Graphics2D g2d)
Draw the entity.protected void
draw(Graphics2D g2d, int x, int y, int width, int height)
Draw the entity.protected void
drawEntity(Graphics2D g2d, int x, int y, int width, int height)
Draw the base entity part.void
drawTop(Graphics2D g2d)
Draw the top layer parts of an entity.protected void
drawTop(Graphics2D g2d, int x, int y, int width, int height)
Draw the entity.String[]
Get the list of actions.getArea()
Get the screen area this is drawn in.protected String
Get the class resource sub-path.protected AlphaComposite
Get the drawing composite.gets the mouse cursor image to use for this entity.protected Rectangle
Get the drawn area used by the entity.Get the view's entity.int
Get the height.Get the sprite image for this entity.protected int
Get the entity's visibility.int
getWidth()
Get the width.protected int
getX()
Get the entity's X coordinate.protected int
Get the X offset alignment adjustment.protected int
getY()
Get the entity's Y coordinate.protected int
Get the Y offset alignment adjustment.int
Determines on top of which other entities this entity should be drawn.void
initialize(T entity)
protected boolean
Determine if this view is currently animatable.boolean
Determine if this view is contained, and should render in a compressed (it's defined) area without clipping anything important.boolean
is this entity interactive so that the player can click or move it?boolean
Determine if this entity can be moved (e.g.protected boolean
Check if the view has been released.void
onAction()
Perform the default action.void
onAction(ActionType at)
Perform an action.boolean
Perform the default action unless it is not safe.void
release()
Release any view resources.protected void
reorderActions(List<String> list)
Reorder the actions list (if needed).void
setContained(boolean contained)
Set whether this view is contained, and should render in a compressed (it's defined) area without clipping anything important.void
setInspector(Inspector inspector)
Set the content inspector for this entity (if needed).protected void
Set the sprite.void
setVisibleScreenArea(Rectangle area)
protected String
Translate a resource name into it's sprite image path.protected void
update()
Handle updates.
-
Field Details
-
entity
The entity this view is for. -
animatedChanged
protected volatile boolean animatedChangedModel values affecting animation. -
representationChanged
protected volatile boolean representationChangedModel values affecting visual representation changed. -
visibilityChanged
protected volatile boolean visibilityChangedThe visibility value changed.
-
-
Constructor Details
-
Entity2DView
public Entity2DView()
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfaceEntityView<T extends IEntity>
-
applyChanges
public void applyChanges()Handle entity changes.- Specified by:
applyChanges
in interfaceEntityView<T extends IEntity>
-
buildActions
Build a list of entity specific actions. NOTE: The first entry should be the default.- Parameters:
list
- The list to populate.
-
buildRepresentation
Rebuild the representation using the base entity.- Parameters:
entity
- the eEntity to build the representation for
-
calculateOffset
Calculate sprite image offset for the entity.- Parameters:
entity
- entityswidth
- 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 directionyAlign
- alignment in vertical directionxOffset
- x coordinate offset that is used in addition to the alignment informationyOffset
- y coordinate offset that is used in addition to the alignment information
-
detachSprite
Detach a sprite that has been previously attached to the view.- Parameters:
sprite
- sprite to be detached
-
draw
Draw the entity.- Specified by:
draw
in interfaceEntityView<T extends IEntity>
- Parameters:
g2d
- The graphics to drawn on.
-
draw
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
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
Draw the top layer parts of an entity. This will be on down after all other game layers are rendered.- Specified by:
drawTop
in interfaceEntityView<T extends IEntity>
- Parameters:
g2d
- The graphics to drawn on.
-
drawTop
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
Get the screen area this is drawn in. NOTE: This only covers the area for the main sprite.- Specified by:
getArea
in interfaceEntityView<T extends IEntity>
- Returns:
- The area this draws in.
-
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
Get the class resource sub-path. The is the base sprite image name, relative totranslate()
.- Returns:
- The resource path.
-
getComposite
Get the drawing composite.- Returns:
- The drawing composite.
-
getHeight
public int getHeight()Get the height.- Returns:
- The height (in pixels).
-
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 interfaceEntityView<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
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 interfaceEntityView<T extends IEntity>
- Parameters:
contained
-true
if contained.
-
setInspector
Set the content inspector for this entity (if needed).- Specified by:
setInspector
in interfaceInspectable
- Parameters:
inspector
- The inspector.
-
setVisibleScreenArea
- Specified by:
setVisibleScreenArea
in interfaceEntityView<T extends IEntity>
-
setSprite
Set the sprite.- Parameters:
sprite
- The sprite.
-
translate
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
Get the list of actions.- Specified by:
getActions
in interfaceEntityView<T extends IEntity>
- Returns:
- The list of actions.
-
getEntity
Get the view's entity.- Specified by:
getEntity
in interfaceEntityView<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 interfaceEntityView<T extends IEntity>
- Returns:
true
if the entity is movable.
-
onAction
public void onAction()Perform the default action.- Specified by:
onAction
in interfaceEntityView<T extends IEntity>
-
onHarmlessAction
public boolean onHarmlessAction()Perform the default action unless it is not safe.- Specified by:
onHarmlessAction
in interfaceEntityView<T extends IEntity>
- Returns:
true
if the action was performed,false
if nothing was done
-
onAction
Perform an action.- Specified by:
onAction
in interfaceEntityView<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 interfaceEntityView<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 interfaceEntityView<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
gets the mouse cursor image to use for this entity.- Specified by:
getCursor
in interfaceEntityView<T extends IEntity>
- Returns:
- StendhalCursor
-