Class GameScreen

All Implemented Interfaces:
GameObjects.GameObjectListener, DropTarget, IGameScreen, StendhalClient.ZoneChangeListener, ImageObserver, MenuContainer, Serializable

The game screen. This manages and renders the visual elements of the game.
See Also:
Serialized Form
  • Constructor Details

    • GameScreen

      public GameScreen(StendhalClient client)
      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 - if true 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 than standhal.getScreenSize().
      Returns:
      true if the graphics are scaled to the screen size, false if the native resolution is used
    • setDefaultScreen

      public static void setDefaultScreen(GameScreen screen)
      Set the default [singleton] screen.
      Parameters:
      screen - The screen.
    • get

      public static GameScreen 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 interface IGameScreen
    • addEntity

      public void addEntity(IEntity entity)
      Description copied from interface: GameObjects.GameObjectListener
      Called when a top level entity is added to the user's zone.
      Specified by:
      addEntity in interface GameObjects.GameObjectListener
    • addEffect

      public void addEffect(EffectLayer effect)
      Add a map wide visual effect.
      Parameters:
      effect - effect renderer
    • removeEntity

      public void removeEntity(IEntity entity)
      Description copied from interface: GameObjects.GameObjectListener
      Called when a top level entity is removed from the user's zone.
      Specified by:
      removeEntity in interface GameObjects.GameObjectListener
    • center

      public void center()
      Description copied from interface: IGameScreen
      Center the view.
      Specified by:
      center in interface IGameScreen
    • paintImmediately

      public void paintImmediately(int x, int y, int w, int h)
      Overrides:
      paintImmediately in class JComponent
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • setOffline

      public void setOffline(boolean offline)
      Description copied from interface: IGameScreen
      Set the offline indication state.
      Specified by:
      setOffline in interface IGameScreen
      Parameters:
      offline - true if offline.
    • addTextBox

      public void addTextBox(Sprite sprite, double x, double y, int textLength)
      Adds a text bubble at a give position.
      Parameters:
      sprite -
      x - x coordinate
      y - y coordinate
      textLength - length of the text in characters
    • removeText

      public void removeText(RemovableSprite entity)
      Description copied from interface: IGameScreen
      Removes a text bubble.
      Specified by:
      removeText in interface IGameScreen
      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 interface IGameScreen
    • getEntityViewAt

      public EntityView<?> getEntityViewAt(double x, double y)
      Description copied from interface: IGameScreen
      Gets an entity view at given coordinates.
      Specified by:
      getEntityViewAt in interface IGameScreen
      Parameters:
      x - The X world coordinate.
      y - The Y world coordinate.
      Returns:
      The entity view, or null if none found.
    • getMovableEntityViewAt

      public EntityView<?> getMovableEntityViewAt(double x, double y)
      Description copied from interface: IGameScreen
      Get a movable entity view at given coordinates.
      Specified by:
      getMovableEntityViewAt in interface IGameScreen
      Parameters:
      x - The X world coordinate.
      y - The Y world coordinate.
      Returns:
      The entity view, or null if none found.
    • getTextAt

      public RemovableSprite getTextAt(int x, int y)
      Description copied from interface: IGameScreen
      Get the text bubble at specific coordinates.
      Specified by:
      getTextAt in interface IGameScreen
      Parameters:
      x - Screen X coordinate.
      y - Screen Y world coordinate.
      Returns:
      the text bubble at the given coordinate or null if not found.
    • convertScreenViewToWorld

      public Point2D convertScreenViewToWorld(Point p)
      Description copied from interface: IGameScreen
      Convert screen view coordinates to world coordinates.
      Specified by:
      convertScreenViewToWorld in interface IGameScreen
      Parameters:
      p - The screen view coordinates.
      Returns:
      World coordinates.
    • convertScreenViewToWorld

      public Point2D convertScreenViewToWorld(int x, int y)
      Description copied from interface: IGameScreen
      Convert screen view coordinates to world coordinates.
      Specified by:
      convertScreenViewToWorld in interface IGameScreen
      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 interface IGameScreen
      Parameters:
      x - The X coordinate (in world units).
      y - The Y coordinate (in world units).
    • dropEntity

      public void dropEntity(IEntity entity, int amount, Point point)
      Description copied from interface: DropTarget
      Drop an entity at a given location. Called when dragging ends.
      Specified by:
      dropEntity in interface DropTarget
      Parameters:
      entity - dropped entity
      amount - number of dropped entities. -1 in case everything in the stack should be dropped
      point - location within the DropTarget
    • addAchievementBox

      public void addAchievementBox(String title, String description, String category)
      Draw a box for a reached achievement with given title, description and category.
      Parameters:
      title - title of the achievement
      description - achievement description
      category - achievement category
    • addStaticText

      public 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.
      Parameters:
      sprite - text box sprite
      textLength - text length in characters
      priority - importance of the message to keep it above others
    • onZoneUpdate

      public void onZoneUpdate(Zone zone)
      Description copied from interface: StendhalClient.ZoneChangeListener
      Called when the zone is updated, such as when the coloring changes.
      Specified by:
      onZoneUpdate in interface StendhalClient.ZoneChangeListener
      Parameters:
      zone - the updated zone
    • onZoneChange

      public void onZoneChange(Zone zone)
      Description copied from interface: StendhalClient.ZoneChangeListener
      Called when the user is changing zone.
      Specified by:
      onZoneChange in interface StendhalClient.ZoneChangeListener
      Parameters:
      zone - the new zone to be changed to. This is not guaranteed to have complete zone data at this stage.
    • onZoneChangeCompleted

      public void onZoneChangeCompleted(Zone zone)
      Description copied from interface: StendhalClient.ZoneChangeListener
      Called when the user has changed zone.
      Specified by:
      onZoneChangeCompleted in interface StendhalClient.ZoneChangeListener
      Parameters:
      zone - the new zone
    • switchToSpellCasting

      public void switchToSpellCasting(KeyEvent e)
      Switch to spell casting triggered by a key event.
      Parameters:
      e - triggering key event
    • switchToSpellCastingState

      public void switchToSpellCastingState(RPObject spell)
      Switch to spell casting with an already chosen spell.
      Parameters:
      spell - the chosen spell
    • canAccept

      public boolean canAccept(IEntity entity)
      Description copied from interface: DropTarget
      Check if the DropTarget can accept a certain entity.
      Specified by:
      canAccept in interface DropTarget
      Parameters:
      entity - entity to be checked
      Returns:
      true, if the DropTarget can process the entity in question, false otherwise