Class HexagonMap


  • public class HexagonMap
    extends java.lang.Object
    • Field Detail

      • hexagonSize

        public final int hexagonSize
      • graphicsXpadding

        public int graphicsXpadding
      • graphicsYpadding

        public int graphicsYpadding
      • renderCoordinates

        public boolean renderCoordinates
      • onHexClickedCallback

        public java.util.List<HexagonCallback> onHexClickedCallback
      • onHexEnteredCallback

        public java.util.List<HexagonCallback> onHexEnteredCallback
      • onHexExitCallback

        public java.util.List<HexagonCallback> onHexExitCallback
    • Constructor Detail

      • HexagonMap

        public HexagonMap​(int hexagonSize)
        Creates an empty HexagonMap
        Parameters:
        hexagonSize - the distance between the center and one corner
      • HexagonMap

        public HexagonMap​(int hexagonSize,
                          javafx.scene.image.Image image,
                          int mapWidthInHexes)
        Generates a HexagonMap from an Image
        Parameters:
        hexagonSize - the distance between the center and one corner
        image - an Image which will be used to generate a HexagonMap
        mapWidthInHexes - the number of hexagons on the x-axis
      • HexagonMap

        public HexagonMap​(int hexagonSize,
                          javafx.scene.image.Image image,
                          int mapWidthInHexes,
                          IHexagonCreator hexagonCreator)
        Generates a HexagonMap from an Image
        Parameters:
        hexagonSize - the distance between the center and one corner
        image - an Image which will be used to generate a HexagonMap
        mapWidthInHexes - the number of hexagons on the x-axis
        hexagonCreator - a class implementing IHexagonCreator. This is how you decide HOW the HexagonMap should be generated from the Image. In it's most basic form:

        public void createHexagon(int q, int r, Color imagePixelColor, HexagonMap map) { Hexagon h = new Hexagon(q, r); h.setBackgroundColor(imagePixelColor); map.addHexagon(h); }

    • Method Detail

      • addHexagon

        public Hexagon addHexagon​(Hexagon hexagon)
        Add a Hexagon to the HexagonMap
        Parameters:
        hexagon - new hexagon
        Returns:
        the same hexagon
      • getAllHexagons

        public java.util.Collection<Hexagon> getAllHexagons()
        Returns:
        all Hexagons that has been added to the map
      • getGraphicsHexagonHeight

        public int getGraphicsHexagonHeight()
      • getGraphicsHorizontalDistanceBetweenHexagons

        public double getGraphicsHorizontalDistanceBetweenHexagons()
      • getGraphicsverticalDistanceBetweenHexagons

        public double getGraphicsverticalDistanceBetweenHexagons()
      • getHexagon

        public Hexagon getHexagon​(int q,
                                  int r)
        Retrieves the Hexagon at the specified position (axial coordinates)
        Parameters:
        q - the Q coordinate
        r - the R coordinate
        Returns:
        the Hexagon if there is no Hexagon at the specified position
      • getHexagonByCube

        public Hexagon getHexagonByCube​(int x,
                                        int y,
                                        int z)
      • getHexagonContainingPixel

        public Hexagon getHexagonContainingPixel​(int x,
                                                 int y)
        Parameters:
        x - carthesian x coordinate
        y - carthesian y coordinate
        Returns:
        the hexagon that is rendered on a specific position on the screen if there is no Hexagon at the specified position
      • getImageMapHorizontalRelation

        public java.util.Optional<java.lang.Double> getImageMapHorizontalRelation()
        If the map was created from an Image, this will return the horizontal pixel relation between the image and the generated map
        Returns:
        scaling factor between pixel and grid
      • getImageMapVerticalRelation

        public java.util.Optional<java.lang.Double> getImageMapVerticalRelation()
        If the map was created from an Image, this will return the vertical pixel relation between the image and the generated map
        Returns:
        scaling factor between pixel and grid
      • getPaddingX

        public double getPaddingX()
      • getPaddingY

        public double getPaddingY()
      • registerCanvasMouseLiner

        public void registerCanvasMouseLiner​(javafx.scene.canvas.Canvas canvas)
      • removeHexagon

        public void removeHexagon​(Hexagon hexagon)
        Removes a Hexagon from the HexagonMap
        Parameters:
        hexagon - to be removed
      • render

        public void render​(javafx.scene.canvas.Canvas canvas)
        Renders the HexagonMap
        Parameters:
        canvas - the JaxaFX Group where all the hexagons should be rendered
      • render

        public void render​(javafx.scene.Group group)
        Renders the HexagonMap
        Parameters:
        group - the JaxaFX Group where all the hexagons should be rendered
      • renderContour

        public void renderContour​(javafx.scene.canvas.Canvas canvas)
        Renders the contours of the HexagonMap
        Parameters:
        canvas - the JaxaFX Group where all the hexagons should be rendered
      • setOnHexagonClickedCallback

        public void setOnHexagonClickedCallback​(HexagonCallback callback)
        A callback when the user clicks on a Hexagon
        Parameters:
        callback - call-back function handler
      • setOnHexagonEnteredCallback

        public void setOnHexagonEnteredCallback​(HexagonCallback callback)
        A callback when the user moves into a Hexagon
        Parameters:
        callback - call-back function handler
      • setOnHexagonExitCallback

        public void setOnHexagonExitCallback​(HexagonCallback callback)
        A callback when the user moves out of a Hexagon
        Parameters:
        callback - call-back function handler
      • setPadding

        public void setPadding​(int left,
                               int top)
        Tells the renderer that you want some space before the HexagonMap is rendered
        Parameters:
        left - padding margin left
        top - padding margin right
      • setRenderCoordinates

        public void setRenderCoordinates​(boolean b)
        If you want the coordinates rendered on the screen
        Parameters:
        b - true: render coordinates
      • setRenderFont

        public void setRenderFont​(javafx.scene.text.Font font)
        Sets the font used to draw the hexagon positions
        Parameters:
        font - for rendering the hex positions