📄 mappreview.java
字号:
xPoints[1] = baseX + hexSideBySin30[zoom]; yPoints[1] = baseY + hexSideByCos30[zoom]; xPoints[2] = xPoints[1] + hexSide[zoom]; yPoints[2] = yPoints[1]; xPoints[3] = xPoints[2] + hexSideBySin30[zoom]; yPoints[3] = baseY; xPoints[4] = xPoints[2]; yPoints[4] = baseY - hexSideByCos30[zoom]; xPoints[5] = xPoints[1]; yPoints[5] = yPoints[4]; g.fillPolygon(xPoints,yPoints,6); if (border) { Color oldColor = g.getColor(); g.setColor(oldColor.darker()); g.drawPolygon(xPoints,yPoints,6); 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); } return terrColor; } /** * Draws green Button in the bottom to close and open mini map. Height of button is fixed to 14pix. */ private void drawBtn(Graphics g){ int [] xPoints = new int[3]; int [] yPoints = new int[3]; Color oldColor = g.getColor(); if (minimized){ xPoints[0] = Math.round((getSize().width - 11) / 2); yPoints[0] = getSize().height - 10; xPoints[1] = xPoints[0] + 11; yPoints[1] = yPoints[0]; xPoints[2] = xPoints[0] + 6; yPoints[2] = yPoints[0] + 5; } else { xPoints[0] = Math.round((getSize().width - 11) / 2); yPoints[0] = getSize().height - 4; xPoints[1] = xPoints[0] + 11; yPoints[1] = yPoints[0]; xPoints[2] = xPoints[0] + 5; yPoints[2] = yPoints[0] - 5; } g.setColor(Color.green.darker().darker()); g.fillRect(0,getSize().height - 14,getSize().width,14); g.setColor(Color.green.darker()); g.drawLine(0,getSize().height - 14,getSize().width,getSize().height -14); g.drawLine(0,getSize().height - 14,0,getSize().height); g.setColor(Color.black); g.drawLine(0,getSize().height-1,getSize().width,getSize().height-1); g.drawLine(getSize().width-1,getSize().height - 14,getSize().width-1,getSize().height); g.setColor(Color.yellow); g.fillPolygon(xPoints,yPoints,3); //drawing "+" and "-" buttons if (! minimized){ g.setColor(Color.black); g.drawLine(14 - 1,getSize().height - 14, 14 - 1,getSize().height); g.drawLine(getSize().width - 14 - 1,getSize().height - 14, getSize().width - 14 - 1,getSize().height); g.setColor(Color.green.darker()); g.drawLine(14,getSize().height - 14, 14,getSize().height); g.drawLine(getSize().width - 14 ,getSize().height - 14, getSize().width - 14,getSize().height); if (zoom == 0){ g.setColor(Color.gray.brighter()); } else { g.setColor(Color.yellow); } g.fillRect(3,getSize().height - 14 + 6, 8, 2); if (zoom == (hexSide.length - 1)){ g.setColor(Color.gray.brighter()); } else { g.setColor(Color.yellow); } g.fillRect(getSize().width - 14 + 3, getSize().height - 14 + 6, 8, 2); g.fillRect(getSize().width - 14 + 6, getSize().height - 14 + 3, 2, 8); if (zoom > 2) { // Button for displying heights. g.setColor(Color.black); g.drawLine(28 - 1,getSize().height - 14, 28 - 1,getSize().height); g.setColor(Color.green.darker()); g.drawLine(28, getSize().height - 14, 28, getSize().height); g.setColor(Color.yellow); String label; switch (heightDisplayMode) { case SHOW_NO_HEIGHT : label = Messages.getString("MiniMap.NoHeightLabel"); //$NON-NLS-1$ break; case SHOW_GROUND_HEIGHT : label = Messages.getString("MiniMap.GroundHeightLabel"); //$NON-NLS-1$ break; case SHOW_BUILDING_HEIGHT : label = Messages.getString("MiniMap.BuildingHeightLabel"); //$NON-NLS-1$ break; case SHOW_TOTAL_HEIGHT : label = Messages.getString("MiniMap.TotalHeightLabel"); //$NON-NLS-1$ break; default : label = ""; //$NON-NLS-1$ } g.drawString(label, 17, getSize().height - 14 + 12); } } g.setColor(oldColor); } 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(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -