⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boardview1.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }    }    /**     * This method creates an image the size of the entire board (all     * mapsheets), draws the hexes onto it, and returns that image.     */    public Image getEntireBoardImage() {        Image entireBoard = createImage(boardSize.width, boardSize.height);        Graphics temp = boardImage.getGraphics();        boardGraph = entireBoard.getGraphics();        drawHexes(new Rectangle(boardSize));        boardGraph.dispose();        boardGraph = temp;        return entireBoard;    }    /**     * Moves the board view to another area.     */    private void moveBoardImage() {        // salvage the old        boardGraph.setClip(0, 0, boardRect.width, boardRect.height);        boardGraph.copyArea(0, 0, boardRect.width, boardRect.height,                boardRect.x - view.x, boardRect.y - view.y);        // what's left to paint?        int midX = Math.max(view.x, boardRect.x);        int midWidth = view.width - Math.abs(view.x - boardRect.x);        Rectangle unLeft = new Rectangle(view.x, view.y, boardRect.x - view.x, view.height);        Rectangle unRight = new Rectangle(boardRect.x + boardRect.width, view.y, view.x - boardRect.x, view.height);        Rectangle unTop = new Rectangle(midX, view.y, midWidth, boardRect.y - view.y);        Rectangle unBottom = new Rectangle(midX, boardRect.y + boardRect.height, midWidth, view.y - boardRect.y);        // update boardRect        boardRect = new Rectangle(view);                if(dirtyBoard) {            drawHexes(view);            dirtyBoard = false;        } else {            // paint needed areas            if (unLeft.width > 0) {                drawHexes(unLeft);            } else if (unRight.width > 0) {                drawHexes(unRight);            }            if (unTop.height > 0) {                drawHexes(unTop);            } else if (unBottom.height > 0) {                drawHexes(unBottom);            }        }    }    /**     * Redraws all hexes in the specified rectangle     */    private void drawHexes(Rectangle rect) {        // rect is the view        int drawX = (int) (rect.x / (HEX_WC * scale)) - 1;        int drawY = (int) (rect.y / (HEX_H * scale)) - 1;        int drawWidth = (int) (rect.width / (HEX_WC * scale)) + 3;        int drawHeight = (int) (rect.height / (HEX_H * scale)) + 3;        // only draw what we came to draw        boardGraph.setClip(rect.x - boardRect.x, rect.y - boardRect.y,                rect.width, rect.height);        // clear, if we need to        if (rect.x < (21 * scale)) {            boardGraph.clearRect(rect.x - boardRect.x, rect.y - boardRect.y,                    (int) (21 * scale) - rect.x, rect.height);        }        if (rect.y < (36 * scale)) {            boardGraph.clearRect(rect.x - boardRect.x, rect.y - boardRect.y,                    rect.width, (int) (36 * scale) - rect.y);        }        if (rect.x > boardSize.width - view.width - (21 * scale)) {            boardGraph.clearRect(boardRect.width - (int) (21 * scale), rect.y - boardRect.y,                    (int) (21 * scale), rect.height);        }        if (rect.y > boardSize.height - view.height - (int) (36 * scale)) {            boardGraph.clearRect(rect.x - boardRect.x, boardRect.height - (int) (36 * scale),                    rect.width, (int) (36 * scale));        }        // draw some hexes        for (int i = 0; i < drawHeight; i++) {            for (int j = 0; j < drawWidth; j++) {                drawHex(new Coords(j + drawX, i + drawY));            }        }    }    /**     * Redraws a hex and all the hexes immediately around it.  Used when the     * hex is on the screen, as opposed to when it is scrolling onto the screen,     * so it resets the clipping rectangle before drawing.     */    private void redrawAround(Coords c) {        boardGraph.setClip(0, 0, boardRect.width, boardRect.height);        drawHex(c);        drawHex(c.translated(0));        drawHex(c.translated(1));        drawHex(c.translated(2));        drawHex(c.translated(3));        drawHex(c.translated(4));        drawHex(c.translated(5));    }    /**     * Draws a hex onto the board buffer.  This assumes that boardRect is     * current, and does not check if the hex is visible.     */    private void drawHex(Coords c) {        if (!game.getBoard().contains(c)) {            return;        }        final IHex hex = game.getBoard().getHex(c);        final Point hexLoc = getHexLocation(c);        int level = hex.getElevation();        int depth = hex.depth();        int height = Math.max(hex.terrainLevel(Terrains.BLDG_ELEV), hex.terrainLevel(Terrains.BRIDGE_ELEV));        // offset drawing point                int drawX = hexLoc.x - boardRect.x;        int drawY = hexLoc.y - boardRect.y;        // draw picture        Image baseImage = tileManager.baseFor(hex);        Image scaledImage = getScaledImage(baseImage);        boardGraph.drawImage(scaledImage, drawX, drawY, this);        if (tileManager.supersFor(hex) != null) {            for (Iterator i = tileManager.supersFor(hex).iterator(); i.hasNext();) {                scaledImage = getScaledImage((Image) i.next());                boardGraph.drawImage(scaledImage, drawX, drawY, this);            }        }        if (ecmHexes != null) {            Integer tint = ecmHexes.get(c);            if (tint != null) {                scaledImage = getScaledImage(tileManager.getEcmShade(tint.intValue()));                boardGraph.drawImage(scaledImage, drawX, drawY, this);            }        }        if (GUIPreferences.getInstance().getBoolean(GUIPreferences.ADVANCED_DARKEN_MAP_AT_NIGHT) &&                game.getOptions().booleanOption("night_battle") &&                !game.isPositionIlluminated(c)) {            scaledImage = getScaledImage(tileManager.getNightFog());            boardGraph.drawImage(scaledImage, drawX, drawY, this);        }        boardGraph.setColor(GUIPreferences.getInstance().getMapTextColor());                // draw hex number        if (scale >= 0.5) {            drawCenteredString(c.getBoardNum(),                    drawX,                    drawY + (int) (12 * scale),                    font_hexnum,                    boardGraph);        }        // draw terrain level / water depth / building height        if (zoomIndex > 3) {            int ypos = 70;            if (level != 0) {                drawCenteredString(Messages.getString("BoardView1.LEVEL") + level, //$NON-NLS-1$                        drawX,                        drawY + (int) (ypos * scale),                        font_elev,                        boardGraph);                ypos -= 10;            }            if (depth != 0) {                drawCenteredString(Messages.getString("BoardView1.DEPTH") + depth, //$NON-NLS-1$                        drawX,                        drawY + (int) (ypos * scale),                        font_elev,                        boardGraph);                ypos -= 10;            }            if (height > 0) {                boardGraph.setColor(GUIPreferences.getInstance().getColor("AdvancedBuildingTextColor"));                drawCenteredString(Messages.getString("BoardView1.HEIGHT") + height, //$NON-NLS-1$                        drawX,                        drawY + (int) (ypos * scale),                        font_elev,                        boardGraph);                ypos -= 10;            }        }                // draw elevation borders        boardGraph.setColor(Color.black);        if (drawElevationLine(c, 0)) {            boardGraph.drawLine(drawX + (int) (21 * scale), drawY, drawX + (int) (62 * scale), drawY);        }        if (drawElevationLine(c, 1)) {            boardGraph.drawLine(drawX + (int) (62 * scale), drawY, drawX + (int) (83 * scale), drawY + (int) (35 * scale));        }        if (drawElevationLine(c, 2)) {            boardGraph.drawLine(drawX + (int) (83 * scale), drawY + (int) (36 * scale), drawX + (int) (62 * scale), drawY + (int) (71 * scale));        }        if (drawElevationLine(c, 3)) {            boardGraph.drawLine(drawX + (int) (62 * scale), drawY + (int) (71 * scale), drawX + (int) (21 * scale), drawY + (int) (71 * scale));        }        if (drawElevationLine(c, 4)) {            boardGraph.drawLine(drawX + (int) (21 * scale), drawY + (int) (71 * scale), drawX, drawY + (int) (36 * scale));        }        if (drawElevationLine(c, 5)) {            boardGraph.drawLine(drawX, drawY + (int) (35 * scale), drawX + (int) (21 * scale), drawY);        }        // draw mapsheet borders        if (GUIPreferences.getInstance().getShowMapsheets()) {            boardGraph.setColor(GUIPreferences.getInstance().getColor(GUIPreferences.ADVANCED_MAPSHEET_COLOR));            if (c.x % 16 == 0) {                //left edge of sheet (edge 4 & 5)                boardGraph.drawLine(drawX + (int) (21 * scale), drawY + (int) (71 * scale), drawX, drawY + (int) (36 * scale));                boardGraph.drawLine(drawX, drawY + (int) (35 * scale), drawX + (int) (21 * scale), drawY);            } else if (c.x % 16 == 15) {                //right edge of sheet (edge 1 & 2)                boardGraph.drawLine(drawX + (int) (62 * scale), drawY, drawX + (int) (83 * scale), drawY + (int) (35 * scale));                boardGraph.drawLine(drawX + (int) (83 * scale), drawY + (int) (36 * scale), drawX + (int) (62 * scale), drawY + (int) (71 * scale));            }            if (c.y % 17 == 0) {                //top edge of sheet (edge 0 and possible 1 & 5)                boardGraph.drawLine(drawX + (int) (21 * scale), drawY, drawX + (int) (62 * scale), drawY);                if (c.x % 2 == 0) {                    boardGraph.drawLine(drawX + (int) (62 * scale), drawY, drawX + (int) (83 * scale), drawY + (int) (35 * scale));                    boardGraph.drawLine(drawX, drawY + (int) (35 * scale), drawX + (int) (21 * scale), drawY);                }            } else if (c.y % 17 == 16) {                //bottom edge of sheet (edge 3 and possible 2 & 4)                boardGraph.drawLine(drawX + (int) (62 * scale), drawY + (int) (71 * scale), drawX + (int) (21 * scale), drawY + (int) (71 * scale));                if (c.x % 2 == 1) {                    boardGraph.drawLine(drawX + (int) (83 * scale), drawY + (int) (36 * scale), drawX + (int) (62 * scale), drawY + (int) (71 * scale));                    boardGraph.drawLine(drawX + (int) (21 * scale), drawY + (int) (71 * scale), drawX, drawY + (int) (36 * scale));                }            }            boardGraph.setColor(Color.black);        }    }    /**     * Returns true if an elevation line should be drawn between the starting     * hex and the hex in the direction specified.  Results should be     * transitive, that is, if a line is drawn in one direction, it should be     * drawn in the opposite direction as well.     */    private boolean drawElevationLine(Coords src, int direction) {        final IHex srcHex = game.getBoard().getHex(src);        final IHex destHex = game.getBoard().getHexInDir(src, direction);        return destHex != null && srcHex.floor() != destHex.floor();    }    /**     * Returns the absolute position of the upper-left hand corner     * of the hex graphic     */    private Point getHexLocation(int x, int y) {        return new Point(x * (int) (HEX_WC * scale),                y * (int) (HEX_H * scale) + ((x & 1) == 1 ? (int) (HEX_H / 2 * scale) : 0));    }    private Point getHexLocation(Coords c) {        return getHexLocation(c.x, c.y);    }    // added by kenn    /**     * Returns the absolute position of the centre     * of the hex graphic     */    private Point getCentreHexLocation(int x, int y) {        Point p = getHexLocation(x, y);        p.x += (HEX_W / 2 * scale);        p.y += (HEX_H / 2 * scale);        return p;    }    private Point getCentreHexLocation(Coords c) {        return getCentreHexLocation(c.x, c.y);    }    // end kenn    /**     * Returns the coords at the specified point     */    Coords getCoordsAt(Point p) {        final int x = (p.x + scroll.x - offset.x) / (int) (HEX_WC * scale);        final int y = ((p.y + scroll.y - offset.y) - ((x & 1) == 1 ? (int) (HEX_H / 2 * scale) : 0)) / (int) (HEX_H * scale);        return new Coords(x, y);    }    /**     * The text to be displayed when the mouse is at a certain point     */    public String getToolTipText(MouseEvent me) {        Point point = me.getPoint();        int stringsSize = 0;        IHex mhex = null;        // first, we have to determine how much text we are going to have        // are we on a hex?        final Coords mcoords = getCoordsAt(point);        if (GUIPreferences.getInstance().getShowMapHexPopup() && game.getBoard().contains(mcoords)) {            mhex = game.getBoard().getHex(mcoords);            stringsSize += 1;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -