Package org.iremake.common.model.map

Examples of org.iremake.common.model.map.MapPosition


        id = parent.getAttributeValueAsInt("id");
        name = parent.getAttributeValue("name");
        int row = parent.getAttributeValueAsInt("town-row");
        int column = parent.getAttributeValueAsInt("town-column");
        town = new MapPosition(row, column);
    }
View Full Code Here


            break;
        default:
            row = -1;
            column = -1;
        }
        return new MapPosition(row, column);
    }
View Full Code Here

        }
        return new MapPosition(row, column);
    }
   
    public boolean isSameTerrain(MapPosition p, TilesTransition t) {
        MapPosition q = getNeighbourPosition(p, t);
        if (containsPosition(p) && containsPosition(q) && map[p.row][p.column].terrainID == map[q.row][q.column].terrainID) {
            return true;
        }
        return false;
    }
View Full Code Here

        }
        return false;
    }
   
    public boolean isSameResource(MapPosition p, TilesTransition t) {
        MapPosition q = getNeighbourPosition(p, t);
        if (containsPosition(p) && containsPosition(q) && map[p.row][p.column].resourceID != Settings.RESOURCE_NONE && map[p.row][p.column].resourceID == map[q.row][q.column].resourceID) {
            return true;
        }
        return false;
    }   
View Full Code Here

    public TilesBorder getBorder(MapPosition p, TilesTransition transition) {
        // position has to belong to the map and there must be a province
        if (!containsPosition(p) || getTile(p).provinceID == Province.NONE) {
            return TilesBorder.None;
        }
        MapPosition p2 = getNeighbourPosition(p, transition);
        // neigboured postion must belong and there must be a province
        if (!containsPosition(p2) || getTile(p2).provinceID == Province.NONE) {
            return TilesBorder.None;
        }
        if (getTile(p).provinceID != getTile(p2).provinceID) {
View Full Code Here

        Random rnd = new Random(42);

        // set terrain
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                MapPosition pos = new MapPosition(row, column);
                Tile tile = scenario.getTileAt(pos);
                int i = column + row * columns;

                // set terrains
                // sea
View Full Code Here

                buffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
                for (int x = 0; x < size.width; x++) {
                    for (int y = 0; y < size.height; y++) {
                        int column = scenario.getNumberColumns() * x / size.width; // rounding down
                        int row = scenario.getNumberRows() * y / size.height;
                        Color color = scenario.getTerrainTileColorAt(new MapPosition(row, column));
                        buffer.setRGB(x, y, color.getRGB());
                    }
                }
                break;

            case Political:
                buffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
                for (int x = 0; x < size.width; x++) {
                    for (int y = 0; y < size.height; y++) {
                        int column = scenario.getNumberColumns() * x / size.width; // rounding down
                        int row = scenario.getNumberRows() * y / size.height;
                        Nation nation = scenario.getNationAt(new MapPosition(row, column));
                        if (nation != null) {
                            Color color = nation.getColor();
                            buffer.setRGB(x, y, color.getRGB());
                        } else {
                            // TODO ocean color?
View Full Code Here

        setBorder(BorderFactory.createLineBorder(Color.black, 1));

        addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                MapPosition p = getPositionFromXY(e.getX(), e.getY());

                // TODO the white pieces at the edge are handled how?
                if (scenario.containsPosition(p)) {
                    // inside, check if over new tile
                    if (!p.equals(hoover)) {
                        hoover.setFrom(p);
                        // hoovered tile changed
                        repaint(); // TODO only the two tiles
                        notifyTileFocusChangedListeners();
                    }
                } else {
                    // outside of area, deselect
                    hoover.setOff();
                    repaint(); // TODO only the one tile
                    notifyTileFocusChangedListeners();
                }
            }
        });
        addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    MapPosition p = getPositionFromXY(e.getX(), e.getY());

                    if (scenario.containsPosition(p)) {
                        notifyTileClickedListeners(p);
                    }
                }
View Full Code Here

     * @param x mouse x position
     * @param y mouse y position
     * @return map tile position
     */
    private MapPosition getPositionFromXY(int x, int y) {
        MapPosition p = new MapPosition();
        Dimension tileSize = scenario.getTileSize();
        p.row = y / tileSize.height + offset.row;
        int shift = p.row % 2 != 0 ? tileSize.width / 2 : 0;
        // -9..9/10 == 0, avoid negative divisions, because rounding is different there
        p.column = (x - shift + tileSize.width) / tileSize.width - 1 + offset.column;
View Full Code Here

        for (int r = -1; r < drawnRows + 1; r++) {
            for (int c = -1; c < drawnColumns + 1; c++) {
                // real row and column
                int row = r + offset.row;
                int column = c + offset.column;
                MapPosition p = new MapPosition(row, column);
                // compute left, upper corner (shift is every second, real row)
                int x = c * tileSize.width + ((row % 2 != 0) ? tileSize.width / 2 : 0);
                int y = r * tileSize.height;
                // still on the map?
                if (row >= 0 && row < scenario.getNumberRows() && column >= 0 && column < scenario.getNumberColumns()) {
                    fulldrawn.add(new ScreenPosition(x, y, p));
                } else {
                    row = Math.max(0, row);
                    row = Math.min(scenario.getNumberRows() - 1, row);
                    column = Math.max(0, column);
                    column = Math.min(scenario.getNumberColumns() - 1, column);
                    outside.add(new ScreenPosition(x, y, new MapPosition(row, column)));
                }
            }
        }

        // draw all terrain tiles
        for (ScreenPosition r : fulldrawn) {
            List<Pair<TilesTransition, Boolean>> list = new ArrayList<>(6);
            for (TilesTransition transition : TilesTransition.values()) {
                list.add(new Pair<TilesTransition, Boolean>(transition, scenario.isSameTerrain(r.p, transition)));
            }
            scenario.getTerrainTileAt(r.p).paint(g2d, r.x, r.y, list);
            // drawImageCentered(g2d, scenario.getTerrainTileAt(r.p), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
        }

        // draw terrain tiles for outside areas
        for (ScreenPosition r : outside) {
            drawImageCentered(g2d, scenario.getTerrainTileAt(r.p).getOuter(), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
        }

        // draw resources
        for (ScreenPosition r : fulldrawn) {
            if (scenario.isResourceVisibleAt(r.p)) {
                List<Pair<TilesTransition, Boolean>> list = new ArrayList<>(6);
                for (TilesTransition transition : TilesTransition.values()) {
                    list.add(new Pair<TilesTransition, Boolean>(transition, scenario.isSameResource(r.p, transition)));
                }
                scenario.getResourceOverlayAt(r.p).paint(g2d, r.x, r.y, list);
                // drawImageCentered(g2d, scenario.getResourceOverlayAt(r.p), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
            }
        }

        // draw rivers
        for (ScreenPosition r : fulldrawn) {
            Image overlay = scenario.getRiverOverlayAt(r.p);
            if (overlay != null) {
                drawImageCentered(g2d, overlay, r.x + tileSize.width / 2, r.y + tileSize.height / 2);
            }
        }


        // draw tile borders, first province borders
        for (ScreenPosition r : fulldrawn) {
            // draw tile border
            g2d.setColor(Color.white);
            TilesBorder border = scenario.getBorder(r.p, TilesTransition.East);
            if (border == TilesBorder.Province) {
                // right border
                drawBorder(g2d, border, r.x + tileSize.width, r.y, r.x + tileSize.width, r.y + tileSize.height);
            }
            border = scenario.getBorder(r.p, TilesTransition.SouthEast);
            if (border == TilesBorder.Province) {
                // lower right side
                drawBorder(g2d, border, r.x + tileSize.width / 2, r.y + tileSize.height, r.x + tileSize.width, r.y + tileSize.height);
            }
            border = scenario.getBorder(r.p, TilesTransition.SouthWest);
            if (border == TilesBorder.Province) {
                // lower right side
                drawBorder(g2d, border, r.x, r.y + tileSize.height, r.x + tileSize.width / 2, r.y + tileSize.height);
            }
        }

        // draw tile borders, then nation borders
        for (ScreenPosition r : fulldrawn) {
            // draw tile border
            g2d.setColor(Color.white);
            TilesBorder border = scenario.getBorder(r.p, TilesTransition.East);
            if (border == TilesBorder.Nation) {
                // right border
                drawBorder(g2d, border, r.x + tileSize.width, r.y, r.x + tileSize.width, r.y + tileSize.height);
            }
            border = scenario.getBorder(r.p, TilesTransition.SouthEast);
            if (border == TilesBorder.Nation) {
                // lower right side
                drawBorder(g2d, border, r.x + tileSize.width / 2, r.y + tileSize.height, r.x + tileSize.width, r.y + tileSize.height);
            }
            border = scenario.getBorder(r.p, TilesTransition.SouthWest);
            if (border == TilesBorder.Nation) {
                // lower right side
                drawBorder(g2d, border, r.x, r.y + tileSize.height, r.x + tileSize.width / 2, r.y + tileSize.height);
            }
        }

        // draw railroad
        for (ScreenPosition r : fulldrawn) {
            // TODO really have to draw after all other tiles are drawn, otherwise parts get overdrawn again
            g2d.setColor(Color.black);
            int xc = r.x + tileSize.width / 2;
            int yc = r.y + tileSize.height / 2;
            if (scenario.hasRailRoad(r.p, TilesTransition.East)) {
                g2d.drawLine(xc, yc, xc + tileSize.width, yc);
            }
            if (scenario.hasRailRoad(r.p, TilesTransition.SouthEast)) {
                g2d.drawLine(xc, yc, xc + tileSize.width / 2, yc + tileSize.height);
            }
            if (scenario.hasRailRoad(r.p, TilesTransition.SouthWest)) {
                g2d.drawLine(xc, yc, xc - tileSize.width / 2, yc + tileSize.height);
            }
        }

        // draw cities
        for (ScreenPosition r : fulldrawn) {
            // draw city
            String name = scenario.getTownAt(r.p);
            // name = "Test";
            if (name != null) {
                drawImageCentered(g2d, scenario.getTileGraphicsRepository().getMiscOverlay("city"), r.x + tileSize.width / 2, r.y + tileSize.height / 2);
                drawProvinceTownName(g2d, name, r.x + tileSize.width / 2, r.y + tileSize.height - 10);
            }
        }

        // draw units
        for (MapItem unit : scenario.getAllUnits()) {
            MapPosition p = unit.getPosition();

            int r = p.row - offset.row;
            int c = p.column - offset.column;
            // compute left, upper corner (shift is every second, real row)
            int x = c * tileSize.width + ((p.row % 2 != 0) ? tileSize.width / 2 : 0);
View Full Code Here

TOP

Related Classes of org.iremake.common.model.map.MapPosition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.