Package games.stendhal.client
Class GameScreen
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
games.stendhal.client.GameScreen
- All Implemented Interfaces:
GameObjects.GameObjectListener
,DropTarget
,IGameScreen
,StendhalClient.ZoneChangeListener
,ImageObserver
,MenuContainer
,Serializable
public final class GameScreen
extends JComponent
implements IGameScreen, DropTarget, GameObjects.GameObjectListener, StendhalClient.ZoneChangeListener
The game screen. This manages and renders the visual elements of the game.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface games.stendhal.client.IGameScreen
SIZE_UNIT_PIXELS
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAchievementBox(String title, String description, String category)
Draw a box for a reached achievement with given title, description and category.void
addEffect(EffectLayer effect)
Add a map wide visual effect.void
Called when a top level entity is added to the user's zone.void
addStaticText(Sprite sprite, int textLength, int priority)
Add a text box bound to the bottom of the screen, with a timeout dependent on the text length.void
addTextBox(Sprite sprite, double x, double y, int textLength)
Adds a text bubble at a give position.boolean
Check if the DropTarget can accept a certain entity.void
center()
Center the view.void
Removes all the text entities.convertScreenViewToWorld(int x, int y)
Convert screen view coordinates to world coordinates.Convert screen view coordinates to world coordinates.void
dropEntity(IEntity entity, int amount, Point point)
Drop an entity at a given location.static GameScreen
get()
EntityView<?>
getEntityViewAt(double x, double y)
Gets an entity view at given coordinates.EntityView<?>
getMovableEntityViewAt(double x, double y)
Get a movable entity view at given coordinates.getTextAt(int x, int y)
Get the text bubble at specific coordinates.boolean
isScaled()
Check if the screen uses scaling.void
Prepare screen for the next frame to be rendered and move it if needed .void
onZoneChange(Zone zone)
Called when the user is changing zone.void
onZoneChangeCompleted(Zone zone)
Called when the user has changed zone.void
onZoneUpdate(Zone zone)
Called when the zone is updated, such as when the coloring changes.void
void
paintImmediately(int x, int y, int w, int h)
void
positionChanged(double x, double y)
The user position changed.void
removeEntity(IEntity entity)
Called when a top level entity is removed from the user's zone.void
removeText(RemovableSprite entity)
Removes a text bubble.static void
setDefaultScreen(GameScreen screen)
Set the default [singleton] screen.void
setOffline(boolean offline)
Set the offline indication state.void
setUseScaling(boolean useScaling)
Set whether the screen should be drawn scaled, or in native resolution.void
Switch to spell casting triggered by a key event.void
switchToSpellCastingState(RPObject spell)
Switch to spell casting with an already chosen spell.Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
GameScreen
Create a game screen.- Parameters:
client
- The client.
-
-
Method Details
-
setUseScaling
public void setUseScaling(boolean useScaling)Set whether the screen should be drawn scaled, or in native resolution.- Parameters:
useScaling
- iftrue
the screen will scale the view will be scaled to fit the screen size, otherwise it will be drawn using the native resolution.
-
isScaled
public boolean isScaled()Check if the screen uses scaling. Note that if the native resolution is in use, the screen size must not be allowed to grow larger thanstandhal.getScreenSize()
.- Returns:
true
if the graphics are scaled to the screen size,false
if the native resolution is used
-
setDefaultScreen
Set the default [singleton] screen.- Parameters:
screen
- The screen.
-
get
- Returns:
- the GameScreen object.
-
nextFrame
public void nextFrame()Description copied from interface:IGameScreen
Prepare screen for the next frame to be rendered and move it if needed .- Specified by:
nextFrame
in interfaceIGameScreen
-
addEntity
Description copied from interface:GameObjects.GameObjectListener
Called when a top level entity is added to the user's zone.- Specified by:
addEntity
in interfaceGameObjects.GameObjectListener
-
addEffect
Add a map wide visual effect.- Parameters:
effect
- effect renderer
-
removeEntity
Description copied from interface:GameObjects.GameObjectListener
Called when a top level entity is removed from the user's zone.- Specified by:
removeEntity
in interfaceGameObjects.GameObjectListener
-
center
public void center()Description copied from interface:IGameScreen
Center the view.- Specified by:
center
in interfaceIGameScreen
-
paintImmediately
public void paintImmediately(int x, int y, int w, int h)- Overrides:
paintImmediately
in classJComponent
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
setOffline
public void setOffline(boolean offline)Description copied from interface:IGameScreen
Set the offline indication state.- Specified by:
setOffline
in interfaceIGameScreen
- Parameters:
offline
-true
if offline.
-
addTextBox
Adds a text bubble at a give position.- Parameters:
sprite
-x
- x coordinatey
- y coordinatetextLength
- length of the text in characters
-
removeText
Description copied from interface:IGameScreen
Removes a text bubble.- Specified by:
removeText
in interfaceIGameScreen
- Parameters:
entity
- The text to be removed.
-
clearTexts
public void clearTexts()Description copied from interface:IGameScreen
Removes all the text entities.- Specified by:
clearTexts
in interfaceIGameScreen
-
getEntityViewAt
Description copied from interface:IGameScreen
Gets an entity view at given coordinates.- Specified by:
getEntityViewAt
in interfaceIGameScreen
- Parameters:
x
- The X world coordinate.y
- The Y world coordinate.- Returns:
- The entity view, or
null
if none found.
-
getMovableEntityViewAt
Description copied from interface:IGameScreen
Get a movable entity view at given coordinates.- Specified by:
getMovableEntityViewAt
in interfaceIGameScreen
- Parameters:
x
- The X world coordinate.y
- The Y world coordinate.- Returns:
- The entity view, or
null
if none found.
-
getTextAt
Description copied from interface:IGameScreen
Get the text bubble at specific coordinates.- Specified by:
getTextAt
in interfaceIGameScreen
- Parameters:
x
- Screen X coordinate.y
- Screen Y world coordinate.- Returns:
- the text bubble at the given coordinate or
null
if not found.
-
convertScreenViewToWorld
Description copied from interface:IGameScreen
Convert screen view coordinates to world coordinates.- Specified by:
convertScreenViewToWorld
in interfaceIGameScreen
- Parameters:
p
- The screen view coordinates.- Returns:
- World coordinates.
-
convertScreenViewToWorld
Description copied from interface:IGameScreen
Convert screen view coordinates to world coordinates.- Specified by:
convertScreenViewToWorld
in interfaceIGameScreen
- Parameters:
x
- The screen view X coordinate.y
- The screen view Y coordinate.- Returns:
- World coordinates.
-
positionChanged
public void positionChanged(double x, double y)Description copied from interface:IGameScreen
The user position changed. This sets the target coordinates that the screen centers on.- Specified by:
positionChanged
in interfaceIGameScreen
- Parameters:
x
- The X coordinate (in world units).y
- The Y coordinate (in world units).
-
dropEntity
Description copied from interface:DropTarget
Drop an entity at a given location. Called when dragging ends.- Specified by:
dropEntity
in interfaceDropTarget
- Parameters:
entity
- dropped entityamount
- number of dropped entities. -1 in case everything in the stack should be droppedpoint
- location within the DropTarget
-
addAchievementBox
Draw a box for a reached achievement with given title, description and category.- Parameters:
title
- title of the achievementdescription
- achievement descriptioncategory
- achievement category
-
addStaticText
Add a text box bound to the bottom of the screen, with a timeout dependent on the text length.- Parameters:
sprite
- text box spritetextLength
- text length in characterspriority
- importance of the message to keep it above others
-
onZoneUpdate
Description copied from interface:StendhalClient.ZoneChangeListener
Called when the zone is updated, such as when the coloring changes.- Specified by:
onZoneUpdate
in interfaceStendhalClient.ZoneChangeListener
- Parameters:
zone
- the updated zone
-
onZoneChange
Description copied from interface:StendhalClient.ZoneChangeListener
Called when the user is changing zone.- Specified by:
onZoneChange
in interfaceStendhalClient.ZoneChangeListener
- Parameters:
zone
- the new zone to be changed to. This is not guaranteed to have complete zone data at this stage.
-
onZoneChangeCompleted
Description copied from interface:StendhalClient.ZoneChangeListener
Called when the user has changed zone.- Specified by:
onZoneChangeCompleted
in interfaceStendhalClient.ZoneChangeListener
- Parameters:
zone
- the new zone
-
switchToSpellCasting
Switch to spell casting triggered by a key event.- Parameters:
e
- triggering key event
-
switchToSpellCastingState
Switch to spell casting with an already chosen spell.- Parameters:
spell
- the chosen spell
-
canAccept
Description copied from interface:DropTarget
Check if the DropTarget can accept a certain entity.- Specified by:
canAccept
in interfaceDropTarget
- Parameters:
entity
- entity to be checked- Returns:
true
, if the DropTarget can process the entity in question,false
otherwise
-