Class BoardView

java.lang.Object
megamek.client.ui.clientGUI.boardview.AbstractBoardView
megamek.client.ui.clientGUI.boardview.BoardView
All Implemented Interfaces:
MouseListener, EventListener, IBoardView, KeyBindReceiver, BoardListener, IPreferenceChangeListener

Displays the board; lets the user scroll around and select points on it.
  • Field Details

    • HEX_DIAG

      public static final int HEX_DIAG
    • ISOMETRIC_OFFSET

      public static final int ISOMETRIC_OFFSET
      This value is the vertical pixel offset for each hex elevation that is used to draw isometric mode
      See Also:
    • allDirections

      public static final int[] allDirections
    • DROP_SHADOW_DISTANCE

      public int DROP_SHADOW_DISTANCE
    • zoomIndex

      public int zoomIndex
    • zoomOverview

      public boolean zoomOverview
    • C3_LINE_WIDTH

      public static final int C3_LINE_WIDTH
      See Also:
    • FLY_OVER_LINE_WIDTH

      public static final int FLY_OVER_LINE_WIDTH
      See Also:
    • game

      public final Game game
    • showAllDeployment

      public boolean showAllDeployment
      Keeps track of whether all deployment zones should be shown in the Arty Auto Hit Designation phase
  • Constructor Details

  • Method Details

    • shouldReceiveKeyCommands

      public boolean shouldReceiveKeyCommands()
      Description copied from interface: KeyBindReceiver
      This method should return true when this KeyBindReceiver is in a state to receive the keybind and may react to it, false otherwise. This should return false when the receiver is hidden, inactive or behind a modal dialog. It should return true when it would be expected to act on a keybind, i.e. when it has the appearance of being in focus.

      When this method returns false, this receiver will not be counted as having consumed the key press.

      Specified by:
      shouldReceiveKeyCommands in interface KeyBindReceiver
      Returns:
      True when the receiver is in a state to receive the keybind and may react to it. False otherwise.
    • preferenceChange

      public void preferenceChange(PreferenceChangeEvent e)
      Specified by:
      preferenceChange in interface IPreferenceChangeListener
    • draw

      public void draw(Graphics graphics)
      Description copied from interface: IBoardView
      This method should be overridden to do the actual drawing of the board image into the provided Graphics.
      Specified by:
      draw in interface IBoardView
      Parameters:
      graphics - The Graphics object to draw the board onto
    • clearShadowMap

      public void clearShadowMap()
    • drawHexBorder

      public void drawHexBorder(Graphics2D graphics2D, Color color, double padding, double lineWidth)
    • drawHexBorder

      public void drawHexBorder(Graphics2D graphics2D, Point point, Color col, double pad, double lineWidth)
    • getSelectedArtilleryWeapon

      public Mounted<?> getSelectedArtilleryWeapon()
      returns the weapon selected in the mek display, or null if none selected, or it is not artillery or null if the selected entity is not owned
    • getEntireBoardImage

      public BufferedImage getEntireBoardImage(boolean ignoreUnits, boolean useBaseZoom)
      Description copied from interface: IBoardView
      Returns an image of the entire board. Depending on parameters, the board may contain any currently present units or other game objects, and it may be drawn at zoom 1 or the current zoom level.
      Specified by:
      getEntireBoardImage in interface IBoardView
      Parameters:
      ignoreUnits - If true, no units are drawn, only the board
      useBaseZoom - If true, zoom = 1 is used, otherwise the current board zoom
      Returns:
      an image of the whole board
    • getNightDarkenedColor

      public int getNightDarkenedColor(int rgb)
      Given an int-packed RGB value, apply a modifier for the light level and return the result.
      Parameters:
      rgb - int-packed ARGB value.
      Returns:
      An int-packed ARGB value, which is an adjusted value of the input, based on the light level
    • getHexLocation

      public Point getHexLocation(Coords coords)
    • getCentreHexLocation

      public Point getCentreHexLocation(Coords coords)
    • getCentreHexLocation

      public Point getCentreHexLocation(Coords coords, boolean ignoreElevation)
    • drawRuler

      public void drawRuler(Coords startCoords, Coords endCoords, Color startColor, Color endColor)
    • getRulerStart

      public Coords getRulerStart()
    • getRulerEnd

      public Coords getRulerEnd()
    • getCoordsAt

      public Coords getCoordsAt(Point point)
      Specified by:
      getCoordsAt in interface IBoardView
      Returns:
      the coords at the specified point in the BoardView's image area. The point may be given e.g. as part of a MouseEvent.
    • setTooltipProvider

      public void setTooltipProvider(BoardViewTooltipProvider provider)
      Description copied from interface: IBoardView
      Adds the given BoardViewTooltipProvider to this BoardView to provide the tooltips that are shown, replacing the previous BoardViewTooltipProvider, if any.
      Specified by:
      setTooltipProvider in interface IBoardView
      Parameters:
      provider - The BoardViewTooltipProvider
      See Also:
    • redrawMovingEntity

      public void redrawMovingEntity(Entity entity, Coords position, int facing, int elevation)
    • isMovingUnits

      public boolean isMovingUnits()
    • redrawEntity

      public void redrawEntity(Entity entity)
      Clears the sprite for an entity and prepares it to be re-drawn. Replaces the old sprite with the new! Takes a reference to the Entity object before changes, in case it contained important state information, like DropShips taking off (airborne DropShips lose their secondary hexes). Try to prevent annoying ConcurrentModificationExceptions
    • redrawAllEntities

      public void redrawAllEntities()
      Clears all old entity sprites out of memory and sets up new ones.
    • centerOnSelected

      public void centerOnSelected()
      Centers the board on the position of the selected unit, if any. Uses smooth centering if activated in the client settings.
    • centerOn

      public void centerOn(@Nullable Entity entity)
      Centers the board on the position of the given unit. Uses smooth centering if activated in the client settings. The given entity may be null, in which case nothing happens.
      Parameters:
      entity - The unit to center on.
    • centerOnHex

      public void centerOnHex(@Nullable Coords coords)
      Description copied from interface: IBoardView
      Notifies this BoardView to center itself on the given Coords. Override this to be safe for null Coords.
      Specified by:
      centerOnHex in interface IBoardView
      Parameters:
      coords - The coordinates to center on
    • stopSoftCentering

      public void stopSoftCentering()
    • centerOnPointRel

      public void centerOnPointRel(double xRelative, double yRelative)
      Centers the board to a point
      Parameters:
      xRelative - the x position relative to board width.
      yRelative - the y position relative to board height. Both xRelative and yRelative should be between 0 and 1. The method will clip both values to this range.
    • getVisibleArea

      public double[] getVisibleArea()
      Returns the currently visible area of the board.
      Returns:
      an array of 4 double values indicating the relative size, where the first two values indicate the x and y position of the upper left corner of the visible area and the second two values the x and y position of the lower right corner. So when the whole board is visible, the values should be 0, 0, 1, 1. When the lower right corner of the board is visible and 90% of width and height: 0.1, 0.1, 1, 1 Due to board padding the values can be outside [0;1]
    • drawMovementData

      public void drawMovementData(Entity entity, MovePath movePath)
      Clears the old movement data and draws the new.
    • clearMovementData

      public void clearMovementData()
      Clears current movement data from the screen
    • addStrafingCoords

      public void addStrafingCoords(Coords coords)
    • setStrafingCoords

      public void setStrafingCoords(Collection<Coords> coords)
    • clearStrafingCoords

      public void clearStrafingCoords()
    • getClientgui

      public ClientGUI getClientgui()
    • getScale

      public float getScale()
    • getHexSize

      public Dimension getHexSize()
    • getTileManager

      public TilesetManager getTileManager()
    • getFacingPolys

      public Shape[] getFacingPolys()
    • getMovementPolys

      public Shape[] getMovementPolys()
    • getUpArrow

      public Shape getUpArrow()
    • getDownArrow

      public Shape getDownArrow()
    • markDeploymentHexesFor

      public void markDeploymentHexesFor(Entity ce)
      Specifies that this should mark the deployment hexes for a player. If the player is set to null, no hexes will be marked.
    • getDeployingEntity

      public Entity getDeployingEntity()
      Returns the entity that is currently being deployed
    • addFlyOverPath

      public void addFlyOverPath(Entity entity)
      add a fly over path to the sprite list
    • getEntitiesFlyingOver

      public ArrayList<Entity> getEntitiesFlyingOver(Coords coords)
      Parameters:
      coords - the given coords
      Returns:
      any entities flying over the given coords
    • addC3Link

      public void addC3Link(Entity entity)
      Adds a c3 line to the sprite list.
    • addAttack

      public void addAttack(AttackAction attackAction)
      Adds an attack to the sprite list.
    • removeAttacksFor

      public void removeAttacksFor(@Nullable Entity entity)
      Removes all attack sprites from a certain entity
    • refreshAttacks

      public void refreshAttacks()
      Clears out all attacks and re-adds the ones in the current game.
    • refreshMoveVectors

      public void refreshMoveVectors()
    • refreshMoveVectors

      public void refreshMoveVectors(Entity entity, MovePath movePath, Color color)
    • clearC3Networks

      public void clearC3Networks()
    • clearFlyOverPaths

      public void clearFlyOverPaths()
    • clearAllAttacks

      public void clearAllAttacks()
      Clears out all attacks that were being drawn
    • clearAllMoveVectors

      public void clearAllMoveVectors()
      Clears out all movement vectors that were being drawn
    • initPolys

      public void initPolys()
      Initializes the various overlay polygons with their vertices.
    • mousePressed

      public void mousePressed(MouseEvent mouseEvent)
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent mouseEvent)
      Specified by:
      mouseReleased in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Specified by:
      mouseExited in interface MouseListener
    • mouseClicked

      public void mouseClicked(MouseEvent me)
      Specified by:
      mouseClicked in interface MouseListener
    • isTileImagesLoaded

      public boolean isTileImagesLoaded()
      Returns:
      True if all hex tile images have been loaded and the board can be successfully drawn
    • setUseLosTool

      public void setUseLosTool(boolean use)
      Specified by:
      setUseLosTool in interface IBoardView
    • getTilesetManager

      public TilesetManager getTilesetManager()
    • setLastCursor

      public void setLastCursor(Coords lastCursor)
      Parameters:
      lastCursor - The lastCursor to set.
    • getLastCursor

      public Coords getLastCursor()
      Returns:
      Returns the lastCursor.
    • setSelected

      public void setSelected(Coords selected)
      Parameters:
      selected - The selected to set.
    • getSelected

      public Coords getSelected()
      Returns:
      Returns the selected.
    • setFirstLOS

      public void setFirstLOS(Coords firstLOS)
      Parameters:
      firstLOS - The firstLOS to set.
    • getFirstLOS

      public Coords getFirstLOS()
      Returns:
      Returns the firstLOS.
    • select

      public void select(Coords coords)
      Determines if this Board contains the Coords, and if so, "selects" that Coords.
      Specified by:
      select in interface IBoardView
      Parameters:
      coords - the Coords.
    • select

      public void select(int x, int y)
      "Selects" the specified Coords.
      Parameters:
      x - the x coordinate.
      y - the y coordinate.
    • highlight

      public void highlight(Coords coords)
      Determines if this Board contains the Coords, and if so, highlights that Coords.
      Specified by:
      highlight in interface IBoardView
      Parameters:
      coords - the Coords.
    • setHighlightColor

      public void setHighlightColor(Color color)
      Parameters:
      color - The new colour of the highlight cursor.
    • highlight

      public void highlight(int x, int y)
      Highlights the specified Coords.
      Parameters:
      x - the x coordinate.
      y - the y coordinate.
    • highlightSelectedEntity

      public void highlightSelectedEntity(Entity entity)
    • highlightSelectedEntities

      public void highlightSelectedEntities(List<Entity> entities)
      Highlights multiple entities on the board view. All entities in the provided list will be highlighted. All other entities will be unhighlighted.
      Parameters:
      entities - List of entities to highlight (can be empty to clear all highlights)
    • setHighlightedEntityHexes

      public void setHighlightedEntityHexes(List<Coords> hexes)
      Sets the hexes to highlight with white borders (for Nova CEWS network dialog). Draws white hexagon borders around the specified hex coordinates.
      Parameters:
      hexes - List of hex coordinates to highlight (can be empty to clear all highlights)
    • setDemolitionChargeHighlightHexes

      public void setDemolitionChargeHighlightHexes(List<Coords> hexes)
      Sets the demolition charge hexes to highlight (selected in the Detonate Charges dialog). These are drawn with a bold yellow/black hazard outline when the matching client setting is on, otherwise with the plain highlight.
      Parameters:
      hexes - List of hex coordinates to highlight (can be empty to clear all highlights)
    • cursor

      public void cursor(Coords coords)
      Determines if this Board contains the Coords, and if so, "cursors" that Coords.
      Specified by:
      cursor in interface IBoardView
      Parameters:
      coords - the Coords.
    • cursor

      public void cursor(int x, int y)
      "Cursors" the specified Coords.
      Parameters:
      x - the x coordinate.
      y - the y coordinate.
    • checkLOS

      public void checkLOS(Coords c)
    • mouseAction

      public void mouseAction(int x, int y, int mouseActionType, int modifiers, int mouseButton)
      Determines if this Board contains the (x, y) Coords, and if so, notifies listeners about the specified mouse action.
    • mouseAction

      public void mouseAction(Coords coords, int eventType, int modifiers, int mouseButton)
      Notifies listeners about the specified mouse action.
      Parameters:
      coords - - coords the Coords.
      eventType - - Board view event type
      modifiers - - mouse event modifiers mask such as SHIFT_DOWN_MASK etc.
      mouseButton - - mouse button associated with this event 0 = no button 1 = Button 1 2 = Button 2
    • boardNewBoard

      public void boardNewBoard(BoardEvent boardEvent)
      Description copied from interface: BoardListener
      Sent when the Board is completely changed. The board's size may have changed.
      Specified by:
      boardNewBoard in interface BoardListener
      Parameters:
      boardEvent - an event containing information about the change
    • boardChangedHex

      public void boardChangedHex(BoardEvent boardEvent)
      Description copied from interface: BoardListener
      Sent when a single hex on the Board changed.
      Specified by:
      boardChangedHex in interface BoardListener
      Parameters:
      boardEvent - an event containing information about the change
    • boardChangedAllHexes

      public void boardChangedAllHexes(BoardEvent boardEvent)
      Description copied from interface: BoardListener
      Sent when all hexes on the board changed.
      Specified by:
      boardChangedAllHexes in interface BoardListener
      Parameters:
      boardEvent - an event containing information about the change
    • clearSprites

      public void clearSprites()
      Description copied from class: AbstractBoardView
      Removes all sprites from this BoardView. This includes (possibly) sprites for units, attacks etc. Note that this is not communicated to the SpriteHandlers.
      Overrides:
      clearSprites in class AbstractBoardView
    • updateBoard

      public void updateBoard()
    • selectEntity

      public void selectEntity(Entity entity)
      Parameters:
      entity - the BoardView's currently selected entity
    • updateEcmList

      public void updateEcmList()
      Updates maps that determine how to shade hexes affected by E(C)CM. This is expensive, so precalculate only when entity changes occur
    • getComponent

      public Component getComponent()
      Specified by:
      getComponent in interface IBoardView
      Returns:
      a JScrollPane containing the board's panel.
    • setDisplayInvalidFields

      public void setDisplayInvalidFields(boolean displayInvalidFields)
      Description copied from interface: IBoardView
      Sets this BoardView to show or hide a warning in fields (hexes) that contain invalid information such as terrains that cannot be used together in a single hex. Usually this warning is shown in the board editor but not in a game.
      Specified by:
      setDisplayInvalidFields in interface IBoardView
      Parameters:
      displayInvalidFields - True when the invalid marker should be shown
    • setLocalPlayer

      public void setLocalPlayer(int playerId)
      Description copied from interface: IBoardView
      Sets the BoardView to use the given player ID as the player in whose client this BoardView is shown. This may affect what is shown and what is hidden in this BoardView; it will also affect what is considered an enemy and ally.
      Specified by:
      setLocalPlayer in interface IBoardView
      Parameters:
      playerId - The local player's ID as stored in the game.
    • getComponent

      public Component getComponent(boolean scrollBars)
    • showPopup

      public void showPopup(JPopupMenu popUp, Coords coords)
    • zoomIn

      public void zoomIn()
      Description copied from interface: IBoardView
      Zooms in the board (shows less of it at bigger size), if the maximum zoom has not been reached already.
      Specified by:
      zoomIn in interface IBoardView
    • zoomOut

      public void zoomOut()
      Description copied from interface: IBoardView
      Zooms out the board (shows more of it at smaller size), if the minimum zoom has not been reached already.
      Specified by:
      zoomOut in interface IBoardView
    • zoomReset

      public void zoomReset()
      Reset the zoom level to the BASE_ZOOM_INDEX
      Specified by:
      zoomReset in interface IBoardView
    • zoomOverviewToggle

      public void zoomOverviewToggle()
      Description copied from interface: IBoardView
      Toggles between two Zoom levels.
      Specified by:
      zoomOverviewToggle in interface IBoardView
    • getScaledImage

      @Nullable public Image getScaledImage(Image base, boolean useCache)
      Return a scaled version of the input. If the useCache flag is set, the scaled image will be stored in an image cache for later retrieval.
      Parameters:
      base - The image to get a scaled copy of. The current zoom level is used to determine the scale.
      useCache - This flag determines whether the scaled image should be stored in a cache for later retrieval.
    • toggleIsometric

      public void toggleIsometric()
    • updateEntityLabels

      public void updateEntityLabels()
    • createShadowMask

      public BufferedImage createShadowMask(Image image)
    • getChatterBoxActive

      public boolean getChatterBoxActive()
      Returns:
      Returns true if the BoardView has an active chatter box else false.
    • setChatterBoxActive

      public void setChatterBoxActive(boolean chatterBoxActive)
      Parameters:
      chatterBoxActive - whether the BoardView has an active chatter box or not.
    • setShouldIgnoreKeys

      public void setShouldIgnoreKeys(boolean shouldIgnoreKeys)
    • clearHexImageCache

      public void clearHexImageCache()
    • clearHexImageCache

      public void clearHexImageCache(Set<Coords> setCoords)
      Clear a specific list of Coords from the hex image cache.
      Parameters:
      setCoords - Set of Coords to remove
    • checkFoVHexImageCacheClear

      public void checkFoVHexImageCacheClear()
      Check to see if the HexImageCache should be cleared because of field-of-view changes.
    • getHexPoly

      public static Polygon getHexPoly()
    • changeTheme

      @Nullable public String changeTheme()
      Displays a dialog and changes the theme of all board hexes to the user-chosen theme.
    • getDisplayablesRect

      public Rectangle getDisplayablesRect()
    • shouldFovHighlight

      public boolean shouldFovHighlight()
    • shouldFovDarken

      public boolean shouldFovDarken()
    • setShowLobbyPlayerDeployment

      public void setShowLobbyPlayerDeployment(boolean showLobbyPlayerDeployment)
    • getPanel

      public JPanel getPanel()
      Specified by:
      getPanel in interface IBoardView
      Returns:
      The JPanel that contains this BoardView.
    • getBoardSize

      public Dimension getBoardSize()
      Description copied from interface: IBoardView
      Returns the pixel size of the entire board if drawn at the current zoom level. This should not include any padding, just the board itself.
      Specified by:
      getBoardSize in interface IBoardView
      Returns:
      The pixel size of the entire board at the current zoom level
    • getAnimatedImages

      public Set<Integer> getAnimatedImages()
      Specified by:
      getAnimatedImages in interface IBoardView
      Returns:
      A set of hashCodes of those image that are animated (such as animated tileset images) and therefore should prevent the hex image from being cached.
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle rectangle, int arg1, int arg2)
      Description copied from interface: IBoardView
      Override this to provide a return value exactly as the Scrollable interface method of the same name.
      Specified by:
      getScrollableUnitIncrement in interface IBoardView
      See Also:
    • getScrollableBlockIncrement

      public int getScrollableBlockIncrement(Rectangle rectangle, int arg1, int arg2)
      Description copied from interface: IBoardView
      Override this to provide a return value exactly as the Scrollable interface method of the same name.
      Specified by:
      getScrollableBlockIncrement in interface IBoardView
      See Also:
    • dispose

      public void dispose()
      Description copied from interface: IBoardView
      Frees the resources this BoardView uses and removes listeners. Call when this BoardView is not used anymore. The BoardView will no longer be functional after calling this method. When overriding this method, include a call to super.dispose().
      Specified by:
      dispose in interface IBoardView
      Overrides:
      dispose in class AbstractBoardView
    • getTurnDetailsOverlay

      @Nullable public TurnDetailsOverlay getTurnDetailsOverlay()
      Returns:
      The TurnDetailsOverlay if this BoardView has one.
    • getSelectedEntity

      @Nullable public Entity getSelectedEntity()
      Returns:
      The unit currently shown in the Unit Display. Note: This can be a unit than the one that is selected to move or fire.
    • getFovHighlighting

      public FovHighlightingAndDarkening getFovHighlighting()
    • getIsoWreckSprites

      public ArrayList<IsometricWreckSprite> getIsoWreckSprites()
    • getAttackSprites

      public ArrayList<AttackSprite> getAttackSprites()
    • repaint

      public void repaint()
      Description copied from interface: IBoardView
      Schedules a repaint of the BoardView.
      Specified by:
      repaint in interface IBoardView
      See Also:
    • addSprites

      public void addSprites(Collection<? extends Sprite> sprites)
      Description copied from interface: IBoardView
      Adds the given collection of Sprite to be shown on this BoardView to its set of sprites.
      Specified by:
      addSprites in interface IBoardView
      Overrides:
      addSprites in class AbstractBoardView
      Parameters:
      sprites - the Sprites to show
    • removeSprites

      public void removeSprites(Collection<? extends Sprite> sprites)
      Description copied from interface: IBoardView
      Removes the given collection of Sprite from this BoardView's set of sprites.
      Specified by:
      removeSprites in interface IBoardView
      Overrides:
      removeSprites in class AbstractBoardView
      Parameters:
      sprites - the Sprites to remove
    • getBoard

      public Board getBoard()
      Returns:
      This BoardView's displayed board.
    • isOnThisBord

      public boolean isOnThisBord(@Nullable Targetable targetable)
      Returns:
      True when the given Targetable is not null and is on this board as given by its boardId. Does *not* require the targetable to have a non-null position or a position contained within the board, nor is the targetable's deployment status checked.
    • isOnThisBord

      public boolean isOnThisBord(BoardLocation boardLocation)
      Returns:
      True when the given boardLocation is on this board according to its boardId only. Does *not* test the position of the boardLocation.
      See Also:
    • isShowingAnimation

      public boolean isShowingAnimation()
      Description copied from interface: IBoardView
      Returns true when this BoardView is showing some animation and should not be centered on another hex or be hidden right now. An example is showing a unit's move animation.
      Specified by:
      isShowingAnimation in interface IBoardView
      Returns:
      True when this BoardView is in the process of showing some animation
    • suspendTooltip

      public void suspendTooltip()
    • activateTooltip

      public void activateTooltip()
    • toggleShowDeployment

      public void toggleShowDeployment()
    • addHexDrawPlugin

      public void addHexDrawPlugin(HexDrawPlugin plugin)
    • getVerticalOffset

      public int getVerticalOffset()
      Returns:
      The currently used hex elevation vertical offset; when isometric mode is off, this is 0.