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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested 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_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface games.stendhal.client.IGameScreen
SIZE_UNIT_PIXELSFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAchievementBox(String title, String description, String category) Draw a box for a reached achievement with given title, description and category.voidaddEffect(EffectLayer effect) Add a map wide visual effect.voidvoidCalled when a top level entity is added to the user's zone.voidaddStaticText(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.voidaddTextBox(Sprite sprite, double x, double y, int textLength) Adds a text bubble at a give position.voidaddTextBox(Sprite sprite, Entity entity, int textLength) Adds a text bubble that follows an entity.booleanCheck if the DropTarget can accept a certain entity.voidcenter()Center the view.voidvoidRemoves all the text entities.convertScreenViewToWorld(int x, int y) Convert screen view coordinates to world coordinates.Convert screen view coordinates to world coordinates.voiddropEntity(IEntity entity, int amount, Point point) Drop an entity at a given location.static GameScreenget()Retrieves the singleton instance.static GameScreenget(StendhalClient client) Retrieves the singleton instance.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.booleanisScaled()Check if the screen uses scaling.voidPrepare screen for the next frame to be rendered and move it if needed .voidonZoneChange(Zone zone) Called when the user is changing zone.voidonZoneChangeCompleted(Zone zone) Called when the user has changed zone.voidonZoneUpdate(Zone zone) Called when the zone is updated, such as when the coloring changes.voidvoidpaintImmediately(int x, int y, int w, int h) voidpositionChanged(double x, double y) The user position changed.voidremoveEmoji(RemovableSprite entity) voidremoveEntity(IEntity entity) Called when a top level entity is removed from the user's zone.voidremoveText(RemovableSprite entity) Removes a text bubble.static voidsetDefaultScreen(GameScreen screen) Set the default [singleton] screen.voidsetOffline(boolean offline) Set the offline indication state.voidsetUseScaling(boolean useScaling) Set whether the screen should be drawn scaled, or in native resolution.voidSwitch to spell casting triggered by a key event.voidSwitch 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, updateUIMethods 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, validateTreeMethods 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
-
Method Details
-
get
Retrieves the singleton instance.- Parameters:
client- The client.- Returns:
- The GameScreen object.
-
get
Retrieves the singleton instance.- Returns:
- The GameScreen object.
-
setUseScaling
public void setUseScaling(boolean useScaling) Set whether the screen should be drawn scaled, or in native resolution.- Parameters:
useScaling- iftruethe 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:
trueif the graphics are scaled to the screen size,falseif the native resolution is used
-
setDefaultScreen
Set the default [singleton] screen.- Parameters:
screen- The screen.
-
nextFrame
public void nextFrame()Description copied from interface:IGameScreenPrepare screen for the next frame to be rendered and move it if needed .- Specified by:
nextFramein interfaceIGameScreen
-
addEntity
Description copied from interface:GameObjects.GameObjectListenerCalled when a top level entity is added to the user's zone.- Specified by:
addEntityin interfaceGameObjects.GameObjectListener
-
addEffect
Add a map wide visual effect.- Parameters:
effect- effect renderer
-
removeEntity
Description copied from interface:GameObjects.GameObjectListenerCalled when a top level entity is removed from the user's zone.- Specified by:
removeEntityin interfaceGameObjects.GameObjectListener
-
center
public void center()Description copied from interface:IGameScreenCenter the view.- Specified by:
centerin interfaceIGameScreen
-
paintImmediately
public void paintImmediately(int x, int y, int w, int h) - Overrides:
paintImmediatelyin classJComponent
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
setOffline
public void setOffline(boolean offline) Description copied from interface:IGameScreenSet the offline indication state.- Specified by:
setOfflinein interfaceIGameScreen- Parameters:
offline-trueif offline.
-
addTextBox
Adds a text bubble at a give position.- Parameters:
sprite-x- X coordinate.y- Y coordinate.textLength- Length of the text in characters.
-
addTextBox
Adds a text bubble that follows an entity.- Parameters:
sprite-entity- Entity to follow.textLength- Length of the text in characters.
-
removeText
Description copied from interface:IGameScreenRemoves a text bubble.- Specified by:
removeTextin interfaceIGameScreen- Parameters:
entity- The text to be removed.
-
addEmoji
-
removeEmoji
-
clearTexts
public void clearTexts()Description copied from interface:IGameScreenRemoves all the text entities.- Specified by:
clearTextsin interfaceIGameScreen
-
clearEmojis
public void clearEmojis() -
getEntityViewAt
Description copied from interface:IGameScreenGets an entity view at given coordinates.- Specified by:
getEntityViewAtin interfaceIGameScreen- Parameters:
x- The X world coordinate.y- The Y world coordinate.- Returns:
- The entity view, or
nullif none found.
-
getMovableEntityViewAt
Description copied from interface:IGameScreenGet a movable entity view at given coordinates.- Specified by:
getMovableEntityViewAtin interfaceIGameScreen- Parameters:
x- The X world coordinate.y- The Y world coordinate.- Returns:
- The entity view, or
nullif none found.
-
getTextAt
Description copied from interface:IGameScreenGet the text bubble at specific coordinates.- Specified by:
getTextAtin interfaceIGameScreen- Parameters:
x- Screen X coordinate.y- Screen Y world coordinate.- Returns:
- the text bubble at the given coordinate or
nullif not found.
-
convertScreenViewToWorld
Description copied from interface:IGameScreenConvert screen view coordinates to world coordinates.- Specified by:
convertScreenViewToWorldin interfaceIGameScreen- Parameters:
p- The screen view coordinates.- Returns:
- World coordinates.
-
convertScreenViewToWorld
Description copied from interface:IGameScreenConvert screen view coordinates to world coordinates.- Specified by:
convertScreenViewToWorldin 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:IGameScreenThe user position changed. This sets the target coordinates that the screen centers on.- Specified by:
positionChangedin interfaceIGameScreen- Parameters:
x- The X coordinate (in world units).y- The Y coordinate (in world units).
-
dropEntity
Description copied from interface:DropTargetDrop an entity at a given location. Called when dragging ends.- Specified by:
dropEntityin 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.ZoneChangeListenerCalled when the zone is updated, such as when the coloring changes.- Specified by:
onZoneUpdatein interfaceStendhalClient.ZoneChangeListener- Parameters:
zone- the updated zone
-
onZoneChange
Description copied from interface:StendhalClient.ZoneChangeListenerCalled when the user is changing zone.- Specified by:
onZoneChangein 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.ZoneChangeListenerCalled when the user has changed zone.- Specified by:
onZoneChangeCompletedin 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:DropTargetCheck if the DropTarget can accept a certain entity.- Specified by:
canAcceptin interfaceDropTarget- Parameters:
entity- entity to be checked- Returns:
true, if the DropTarget can process the entity in question,falseotherwise
-