📄 minimap.java
字号:
} } } } } } // draw declared fire if (IGame.PHASE_FIRING==m_game.getPhase() || IGame.PHASE_PHYSICAL==m_game.getPhase()) { for (Enumeration iter = m_game.getActions(); iter.hasMoreElements(); ) { Object action = iter.nextElement(); if (action instanceof AttackAction) { paintAttack(g,(AttackAction) action); } } } for (Enumeration iter = m_game.getEntities(); iter.hasMoreElements(); ) { Entity e = (Entity)iter.nextElement(); if (e.getPosition() == null) continue; paintUnit(g, e, true); } } drawBtn(g); repaint(); } /** * 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 paintHeight(Graphics g, IHex h, int x, int y) { if (heightDisplayMode == SHOW_NO_HEIGHT) return; if(zoom > 2){ int baseX = x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin; int baseY = (2*y + 1 + x%2)* hexSideByCos30[zoom] + topMargin; g.setColor(Color.white); int height = 0; if (h.getTerrain(Terrains.BUILDING) != null && heightDisplayMode == SHOW_BUILDING_HEIGHT) { height = h.ceiling(); } else if (heightDisplayMode == SHOW_GROUND_HEIGHT) { height = h.floor(); } else if (heightDisplayMode == SHOW_TOTAL_HEIGHT) { height = ((h.getTerrain(Terrains.BUILDING) != null) || (h.getTerrain(Terrains.FUEL_TANK) != null)) ? h.ceiling() : h.floor(); } if (height != 0) { g.drawString(height + "", baseX + 5, baseY + 5); //$NON-NLS-1$ } } } private void paintSingleCoordBorder(Graphics g, int x, int y, Color c) { int baseX = x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin; int baseY = (2*y + 1 + x%2)* hexSideByCos30[zoom] + topMargin; int [] xPoints = new int[6]; int [] yPoints = new int[6]; xPoints[0] = baseX; yPoints[0] = baseY; 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.setColor(c); g.drawPolygon(xPoints,yPoints,6); } private void paintCoord(Graphics g, int x, int y, boolean border) { int baseX = x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin; int baseY = (2*y + 1 + x%2)* hexSideByCos30[zoom] + topMargin; int [] xPoints = new int[6]; int [] yPoints = new int[6]; xPoints[0] = baseX; yPoints[0] = baseY; 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); } } /** * Draw a line to represent an attack */ private void paintAttack(Graphics g, AttackAction attack) { Entity source = m_game.getEntity(attack.getEntityId()); Targetable target = m_game.getTarget(attack.getTargetType(), attack.getTargetId()); // sanity check... if (null==source || null==target) { return; } if (attack.getTargetType() == Targetable.TYPE_INARC_POD) { // iNarc pods don't have a position, so lets scrap this idea, shall we? return; } if (attack instanceof WeaponAttackAction) { WeaponAttackAction waa = (WeaponAttackAction)attack; if ((attack.getTargetType() == Targetable.TYPE_HEX_ARTILLERY) && waa.getEntity(m_game).getOwner().getId() != m_client.getLocalPlayer().getId()) { return; } } Color oldColor = g.getColor(); int[] xPoints = new int[4]; int[] yPoints = new int[4]; xPoints[0] = source.getPosition().x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin + (int)1.5*hexSide[zoom] -2; yPoints[0] = (2*source.getPosition().y + 1 + source.getPosition().x%2)* hexSideByCos30[zoom] + topMargin; xPoints[1] = target.getPosition().x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin + (int)1.5*hexSide[zoom] -2; yPoints[1] = (2*target.getPosition().y + 1 + target.getPosition().x%2)* hexSideByCos30[zoom] + topMargin; xPoints[2] = xPoints[1]+2; xPoints[3] = xPoints[0]+2; if ((source.getPosition().x > target.getPosition().x && source.getPosition().y < target.getPosition().y) || (source.getPosition().x < target.getPosition().x && source.getPosition().y > target.getPosition().y)) { yPoints[3] = yPoints[0]+2; yPoints[2] = yPoints[1]+2; } else { yPoints[3] = yPoints[0]-2; yPoints[2] = yPoints[1]-2; } g.setColor(PlayerColors.getColor(source.getOwner().getColorIndex())); g.fillPolygon(xPoints,yPoints,4); g.setColor(Color.black); g.drawPolygon(xPoints,yPoints,4); // if this is mutual fire, draw a half-and-half line for (Enumeration iter = m_game.getActions(); iter.hasMoreElements(); ) { Object action = iter.nextElement(); if (action instanceof AttackAction) { AttackAction otherAttack = (AttackAction) action; if (attack.getEntityId() == otherAttack.getTargetId() && otherAttack.getEntityId() == attack.getTargetId() ) { // attackTarget _must_ be an entity since it's shooting back (?) Entity attackTarget = m_game.getEntity(otherAttack.getEntityId()); g.setColor(PlayerColors.getColor(attackTarget.getOwner().getColorIndex())); xPoints[0] = xPoints[3]; yPoints[0] = yPoints[3]; xPoints[1] = xPoints[2]; yPoints[1] = yPoints[2]; xPoints[2] = xPoints[1]+2; xPoints[3] = xPoints[0]+2; if ((source.getPosition().x > target.getPosition().x && source.getPosition().y < target.getPosition().y) || (source.getPosition().x < target.getPosition().x && source.getPosition().y > target.getPosition().y)) { yPoints[3] = yPoints[0]+2; yPoints[2] = yPoints[1]+2; } else { yPoints[3] = yPoints[0]-2; yPoints[2] = yPoints[1]-2; } g.fillPolygon(xPoints,yPoints,4); g.setColor(Color.black); g.drawPolygon(xPoints,yPoints,4); break; } } } g.setColor(oldColor); } private void paintUnit (Graphics g, Entity entity, boolean border) { int baseX = entity.getPosition().x *(hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin + hexSide[zoom]; int baseY = (2*entity.getPosition().y + 1 + entity.getPosition().x%2)* hexSideByCos30[zoom] + topMargin; int [] xPoints; int [] yPoints; if (entity instanceof Mech) { xPoints = new int[3]; yPoints = new int[3]; xPoints[0] = baseX; yPoints[0] = baseY - unitSize; xPoints[1] = baseX - unitSize; yPoints[1] = baseY + unitSize / 2; xPoints[2] = baseX + unitSize; yPoints[2] = baseY + unitSize / 2; } else if (entity instanceof VTOL) { xPoints = new int[8]; yPoints = new int[8]; xPoints[0] = baseX - unitSize; xPoints[1] = baseX - unitSize / 3; xPoints[2] = baseX; xPoints[3] = baseX + unitSize / 3; xPoints[4] = baseX + unitSize; xPoints[5] = xPoints[3]; xPoints[6] = xPoints[2]; xPoints[7] = xPoints[1]; yPoints[0] = baseY; yPoints[1] = baseY - unitSize / 3; yPoints[2] = baseY - unitSize; yPoints[3] = baseY - unitSize / 3; yPoints[4] = baseY; yPoints[5] = baseY + unitSize / 3; yPoints[6] = baseY + unitSize; yPoints[7] = baseY + unitSize / 3; } else if (entity instanceof Tank) { xPoints = new int[4]; yPoints = new int[4]; xPoints[0] = baseX - unitSize * 2 / 3; yPoints[0] = baseY - unitSize * 2 / 3; xPoints[1] = baseX - unitSize * 2 / 3; yPoints[1] = baseY + unitSize * 2 / 3; xPoints[2] = baseX + unitSize * 2 / 3; yPoints[2] = baseY + unitSize * 2 / 3; xPoints[3] = baseX + unitSize * 2 / 3; yPoints[3] = baseY - unitSize * 2 / 3; } else if (entity instanceof Protomech) { xPoints = new int[3]; yPoints = new int[3]; xPoints[0] = baseX; yPoints[0] = baseY + unitSize; xPoints[1] = baseX + unitSize; yPoints[1] = baseY - unitSize / 2; xPoints[2] = baseX - unitSize; yPoints[2] = baseY - unitSize / 2; } else if (entity instanceof GunEmplacement) { int twip = unitSize * 2 / 3; xPoints = new int[8]; yPoints = new int[8]; xPoints[0] = baseX - (twip / 2); yPoints[0] = baseY - (twip * 3 / 2); xPoints[1] = xPoints[0] - twip; yPoints[1] = yPoints[0] + twip; xPoints[2] = xPoints[1]; yPoints[2] = yPoints[1] + twip; xPoints[3] = xPoints[2] + twip; yPoints[3] = yPoints[2] + twip; xPoints[4] = xPoints[3] + twip; yPoints[4] = yPoints[3]; xPoints[5] = xPoints[4] + twip; yPoints[5] = yPoints[4] - twip; xPoints[6] = xPoints[5]; yPoints[6] = yPoints[5] - twip; xPoints[7] = xPoints[6] - twip; yPoints[7] = yPoints[6] - twip; } else { // entity instanceof Infantry xPoints = new int[4]; yPoints = new int[4]; xPoints[0] = baseX; yPoints[0] = baseY - unitSize; xPoints[1] = baseX - unitSize; yPoints[1] = baseY; xPoints[2] = baseX; yPoints[2] = baseY + unitSize; xPoints[3] = baseX + unitSize; yPoints[3] = baseY; } g.setColor (PlayerColors.getColor(entity.getOwner().getColorIndex())); if (! entity.isSelectableThisTurn()) { // entity has moved (or whatever) already g.setColor (g.getColor().darker()); } g.fillPolygon (xPoints, yPoints, xPoints.length);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -