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

📄 minimap.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                Entity se = clientgui == null?null:m_game.getEntity(clientgui.getSelectedEntityNum());        if (entity == se) {            Color w = new Color (255,255,255);            Color b = new Color (0,0,0);            g.setColor (b);            g.drawRect (baseX-1, baseY-1, 3, 3);            g.setColor (w);            g.drawRect (baseX, baseY, 1, 1);        }        if (border) {            Color oldColor = g.getColor();            g.setColor (oldColor.darker().darker().darker());            g.drawPolygon (xPoints, yPoints, xPoints.length);            g.setColor (oldColor);        }    }    private void paintRoads (Graphics g){        int exits = 0;        int baseX, baseY, x, y;        int [] xPoints = new int[4];        int [] yPoints = new int[4];        Color oldColor = g.getColor();        g.setColor(m_terrainColors[Terrains.ROAD]);        for (Enumeration iter = roadHexIndexes.elements(); iter.hasMoreElements(); ){            int[] hex = (int[])iter.nextElement();            x = hex[0];            y = hex[1];            baseX = x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin + hexSide[zoom];            baseY = (2*y + 1 + x%2)* hexSideByCos30[zoom] + topMargin;            exits = hex[2];            // Is there a North exit?            if ( 0 != (exits & 0x0001) ) {                xPoints[0] = baseX - halfRoadWidth[zoom] ;                yPoints[0] = baseY;                xPoints[1] = baseX - halfRoadWidth[zoom];                yPoints[1] = baseY - hexSideByCos30[zoom];                xPoints[2] = baseX + halfRoadWidth[zoom];                yPoints[2] = baseY - hexSideByCos30[zoom];                xPoints[3] = baseX + halfRoadWidth[zoom];                yPoints[3] = baseY;                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }            // Is there a North-East exit?            if ( 0 != (exits & 0x0002) ) {                xPoints[0] = baseX - halfRoadWidthBySin30[zoom];                yPoints[0] = baseY - halfRoadWidthByCos30[zoom];                xPoints[1] = Math.round(baseX + 3*hexSide[zoom]/4 - halfRoadWidthBySin30[zoom]);                yPoints[1] = Math.round(baseY - hexSideByCos30[zoom]/2 - halfRoadWidthByCos30[zoom]);                xPoints[2] = xPoints[1] + 2 * halfRoadWidthBySin30[zoom];                yPoints[2] = yPoints[1] + 2 * halfRoadWidthByCos30[zoom];                xPoints[3] = baseX + halfRoadWidthBySin30[zoom];                yPoints[3] = baseY + halfRoadWidthByCos30[zoom];                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }            // Is there a South-East exit?            if ( 0 != (exits & 0x0004) ) {                xPoints[0] = baseX + halfRoadWidthBySin30[zoom];                yPoints[0] = baseY - halfRoadWidthByCos30[zoom];                xPoints[1] = Math.round(baseX + 3*hexSide[zoom]/4 + halfRoadWidthBySin30[zoom]);                yPoints[1] = Math.round(baseY + hexSideByCos30[zoom]/2 - halfRoadWidthByCos30[zoom]);                xPoints[2] = xPoints[1] - 2 * halfRoadWidthBySin30[zoom];                yPoints[2] = yPoints[1] + 2 * halfRoadWidthByCos30[zoom];                xPoints[3] = baseX - halfRoadWidthBySin30[zoom];                yPoints[3] = baseY + halfRoadWidthByCos30[zoom];                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }            // Is there a South exit?            if ( 0 != (exits & 0x0008) ) {                xPoints[0] = baseX + halfRoadWidth[zoom];                yPoints[0] = baseY;                xPoints[1] = baseX + halfRoadWidth[zoom];                yPoints[1] = baseY + hexSideByCos30[zoom];                xPoints[2] = baseX - halfRoadWidth[zoom];                yPoints[2] = baseY + hexSideByCos30[zoom];                xPoints[3] = baseX - halfRoadWidth[zoom];                yPoints[3] = baseY;                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }            // Is there a South-West exit?            if ( 0 != (exits & 0x0010) ) {                xPoints[0] = baseX + halfRoadWidthBySin30[zoom];                yPoints[0] = baseY + halfRoadWidthByCos30[zoom];                xPoints[1] = Math.round(baseX - 3*hexSide[zoom]/4 + halfRoadWidthBySin30[zoom]);                yPoints[1] = Math.round(baseY + hexSideByCos30[zoom]/2 + halfRoadWidthByCos30[zoom]);                xPoints[2] = xPoints[1] - 2*halfRoadWidthBySin30[zoom];                yPoints[2] = yPoints[1] - 2*halfRoadWidthByCos30[zoom];                xPoints[3] = baseX - halfRoadWidthBySin30[zoom];                yPoints[3] = baseY - halfRoadWidthByCos30[zoom];                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }            // Is there a North-West exit?            if ( 0 != (exits & 0x0020) ) {                xPoints[0] = baseX - halfRoadWidthBySin30[zoom];                yPoints[0] = baseY + halfRoadWidthByCos30[zoom];                xPoints[1] = Math.round(baseX - 3*hexSide[zoom]/4 - halfRoadWidthBySin30[zoom]);                yPoints[1] = Math.round(baseY - hexSideByCos30[zoom]/2 + halfRoadWidthByCos30[zoom]);                xPoints[2] = xPoints[1] + 2*halfRoadWidthBySin30[zoom];                yPoints[2] = yPoints[1] - 2*halfRoadWidthByCos30[zoom];                xPoints[3] = baseX + halfRoadWidthBySin30[zoom];                yPoints[3] = baseY - halfRoadWidthByCos30[zoom];                g.drawPolygon(xPoints,yPoints,4);                g.fillPolygon(xPoints,yPoints,4);            }        }        g.setColor(oldColor);    }    private Color terrainColor(IHex x, int boardX, int boardY) {        Color terrColor = m_terrainColors[0];        if (x.getElevation() < 0) {            // sinkholes have their own colour            terrColor = SINKHOLE;        }        int level = 0;        int terrain = 0;        for (int j = m_terrainColors.length - 1; j >= 0; j--) {            if (x.getTerrain(j) != null && m_terrainColors[j] != null) {                if (j == Terrains.ROAD || j == Terrains.BRIDGE){                    int [] roadHex = {boardX, boardY, x.getTerrain(j).getExits()};                    roadHexIndexes.addElement(roadHex);                    continue;                }                terrColor = m_terrainColors[j];                terrain = j;                // make heavy woods darker                if ((j == Terrains.WOODS || j == Terrains.JUNGLE) && x.getTerrain(j).getLevel() > 1) {                    terrColor = HEAVY_WOODS;                }                // contains both smoke and fire                if (j == Terrains.SMOKE && x.getTerrain(Terrains.FIRE) != null) {                    terrColor = SMOKE_AND_FIRE;                }                break;            }        }        int r, g, b;        switch (terrain) {            case 0 :            case Terrains.WOODS :            case Terrains.JUNGLE :            case Terrains.ROUGH :            case Terrains.RUBBLE :            case Terrains.WATER :            case Terrains.PAVEMENT :            case Terrains.ICE :                level = Math.abs(x.floor());                // By experiment it is possible to make only 6 distinctive color steps                if (level > 10) level = 10;                r = terrColor.getRed()-level*15;                g = terrColor.getGreen()-level*15;                b = terrColor.getBlue()-level*15;                if (r < 0) r = 0;                if (g < 0) g = 0;                if (b < 0) b = 0;                return new Color(r, g, b);            case Terrains.FUEL_TANK:            case Terrains.BUILDING :                level = Math.abs(x.ceiling());                // By experiment it is possible to make only 6 distinctive color steps                if (level > 10) level = 10;                r = terrColor.getRed()-level*15;                g = terrColor.getGreen()-level*15;                b = terrColor.getBlue()-level*15;                if (r < 0) r = 0;                if (g < 0) g = 0;                if (b < 0) b = 0;                return new Color(r, g, b);        }        /*          if (terrain < 5){          level = (int) Math.abs(x.floor());          // By experiment it is possible to make only 6 distinctive color steps          if (level > 5) level = 5;          int r = terrColor.getRed()-level*30;          int g = terrColor.getGreen()-level*30;          int b = terrColor.getBlue()-level*30;          if (r < 0) r = 0;          if (g < 0) g = 0;          if (b < 0) b = 0;          return new Color(r, g, b);          }        */        return terrColor;    }    private Coords translateCoords(int x, int y) {        int gridX = (x / (hexSideBySin30[zoom] + hexSide[zoom]));        int restX = x % (hexSideBySin30[zoom] + hexSide[zoom]);        int gridY = (y / (2 * hexSideByCos30[zoom]));        int restY = y % (2 * hexSideByCos30[zoom]);        boolean evenColumn = (gridX & 1) == 0;        if (restY < hexSideByCos30[zoom]) {            if (evenColumn) {                if (restX < ((restY - hexSideByCos30[zoom]) * hexSideBySin30[zoom] / hexSideByCos30[zoom] * -1)) {                    gridX--;                    gridY--;                }            } else {                if (restX < (restY * hexSideBySin30[zoom] / hexSideByCos30[zoom])) {                    gridX--;                } else {                    gridY--;                }            }        } else {            if (evenColumn) {                if (restX < ((restY- hexSideByCos30[zoom]) * hexSideBySin30[zoom] / hexSideByCos30[zoom])) {                    gridX--;                }            } else {                if (restX < ((restY - 2 * hexSideByCos30[zoom]) * hexSideBySin30[zoom] / hexSideByCos30[zoom] * -1)) {                    gridX--;                }            }        }        /*       restX = hexSideBySin30[zoom] + hexSide[zoom] - restX;                 restY -= hexSideByCos30[zoom];                 if (hexSideBySin30[zoom]*restX > hexSideByCos30[zoom]*restY) gridX ++;                 if (-hexSideBySin30[zoom]*restX > hexSideByCos30[zoom]*restY) gridY --;        */        if (gridX < 0) gridX = 0;        if (gridY < 0) gridY = 0;        return new Coords(gridX, gridY);    }    private void processMouseClick(int x, int y, MouseEvent me){        if (y > (getSize().height - 14)){            if(x < 14){                if (zoom == 0) return;                zoom --;                initializeMap();            }else if (x < 28 && zoom > 2) {                heightDisplayMode = ((++heightDisplayMode) > NBR_MODES) ? 0 : heightDisplayMode;                initializeMap();            }else if ( x> (getSize().width - 14)){                if (zoom == (hexSide.length - 1)) return;                zoom ++;                initializeMap();            } else{                if (minimized){                    //m_dialog.setResizable(true);                    setSize(getSize().width, heightBufer);                    m_mapImage = createImage(getSize().width, heightBufer);                }else{                    heightBufer = getSize().height;                    setSize(getSize().width, 14);                    m_mapImage = createImage(Math.max(1, getSize().width), 14);                    //m_dialog.setResizable(false);                }                minimized = ! minimized;                m_dialog.pack();                drawMap();            }        }else{            if ((x < margin) || (x > (getSize().width -  leftMargin)) || (y < topMargin) || (y > (getSize().height - topMargin - 14))){                return;            }			if ((me.getModifiers() & InputEvent.CTRL_MASK) != 0) {			    //              m_bview.checkLOS(translateCoords(x - leftMargin, y - topMargin));			    m_bview.mouseAction(translateCoords(x - leftMargin, y - topMargin), IBoardView.BOARD_HEX_CLICK, me.getModifiers());			} else {			    m_bview.centerOnHex(translateCoords(x - leftMargin, y - topMargin));			}        }    }    public int getZoom() {        return zoom;    }    protected BoardListener boardListener = new BoardListenerAdapter() {        public void boardNewBoard(BoardEvent b) {            initializeMap();        }                };    protected GameListener gameListener = new GameListenerAdapter(){        public void gamePhaseChange(GamePhaseChangeEvent e) {            drawMap();        }        public void gameTurnChange(GameTurnChangeEvent e) {            drawMap();        }                public void gameBoardNew(GameBoardNewEvent e) {            IBoard b = e.getOldBoard();            if (b != null) b.removeBoardListener(boardListener);            b = e.getNewBoard();            if (b != null) b.addBoardListener(boardListener);                            initializeMap();        }        public void gameBoardChanged(GameBoardChangeEvent e) {            drawMap();        }    };    BoardViewListener boardViewListener = new BoardViewListenerAdapter(){        public void hexCursor(BoardViewEvent b) {            update();        }                public void boardHexHighlighted(BoardViewEvent b) {            update();        }                public void hexSelected(BoardViewEvent b) {            update();        }                public void firstLOSHex(BoardViewEvent b) {            secondLOS = null;            firstLOS = b.getCoords();            drawMap();        }                public void secondLOSHex(BoardViewEvent b, Coords c) {            firstLOS = c;            secondLOS = b.getCoords();            drawMap();        }        private void update()        {            firstLOS = null;            secondLOS = null;            drawMap();                    }    };    MouseListener mouseListener = new MouseAdapter(){        public void mousePressed(MouseEvent me) {            // center main map on clicked area            processMouseClick(me.getX(), me.getY(), me);        }    };    ComponentListener componentListener = new ComponentAdapter() {        public void componentShown(ComponentEvent ce) {            drawMap();        }                public void componentResized(ComponentEvent ce) {            // if (!minimized) initializeMap();        }    };}

⌨️ 快捷键说明

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