Examples of MapPosition


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

                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

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

        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

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

     * @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

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

        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

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

        Dimension tileSize = scenario.getTileSize();
        int row = (int) (y * scenario.getNumberRows() - size.height / 2 / tileSize.height);
        int column = (int) (x * scenario.getNumberColumns() - size.width / 2 / tileSize.width);
        row = Math.max(row, 0);
        column = Math.max(column, 0);
        MapPosition p = new MapPosition(row, column);
        if (!p.equals(offset)) {
            offset.setFrom(p);
            repaint();
        }
    }
View Full Code Here

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

        }

        // traverse map and store index for each nation or Max value if ther eis no nation (sea)
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                Nation nation = scenario.getNationAt(new MapPosition(row, column));
                if (nation != null) {
                    // put the nations ID
                    politicalMap[row][column] = nationIDs.get(nation);
                } else {
                    // it's sea
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.