📄 boardview1.java
字号:
private Image getScaledImage(Image base) { if (base == null) { return null; } if (zoomIndex == BASE_ZOOM_INDEX) { return base; } Image scaled = scaledImageCache.get(base); if (scaled == null) { MediaTracker tracker = new MediaTracker(this); if(base.getWidth(null) == -1 || base.getHeight(null) == -1) { tracker.addImage(base,0); try { tracker.waitForID(0); } catch (InterruptedException e) { e.printStackTrace(); } tracker.removeImage(base); } int width = (int)(base.getWidth( null ) * scale); int height = (int)(base.getHeight( null ) * scale); scaled = scale(base, width, height); tracker.addImage( scaled, 1 ); // Wait for image to load try{ tracker.waitForID( 1 ); } catch (InterruptedException e) { e.printStackTrace(); } tracker.removeImage(scaled); scaledImageCache.put(base, scaled); } return scaled; } /** * The actual scaling code. */ private static Image scale(Image img, int width, int height) { ImageFilter filter; filter = new ImprovedAveragingScaleFilter(img.getWidth(null), img.getHeight(null), width, height); ImageProducer prod; prod = new FilteredImageSource(img.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(prod); } /** * Draw an outline around legal deployment hexes */ private void drawDeployment() { // only update visible hexes int drawX = view.x / (int) (HEX_WC * scale) - 1; int drawY = view.y / (int) (HEX_H * scale) - 1; int drawWidth = view.width / (int) (HEX_WC * scale) + 3; int drawHeight = view.height / (int) (HEX_H * scale) + 3; IBoard board = game.getBoard(); // loop through the hexes for (int i = 0; i < drawHeight; i++) { for (int j = 0; j < drawWidth; j++) { Coords c = new Coords(j + drawX, i + drawY); Point p = getHexLocation(c); p.translate(-(view.x), -(view.y)); if (board.isLegalDeployment(c, m_plDeployer)) { backGraph.setColor(Color.yellow); int[] xcoords = {p.x + (int) (21 * scale), p.x + (int) (62 * scale), p.x + (int) (83 * scale), p.x + (int) (83 * scale), p.x + (int) (62 * scale), p.x + (int) (21 * scale), p.x, p.x}; int[] ycoords = {p.y, p.y, p.y + (int) (35 * scale), p.y + (int) (36 * scale), p.y + (int) (71 * scale), p.y + (int) (71 * scale), p.y + (int) (36 * scale), p.y + (int) (35 * scale)}; backGraph.drawPolygon(xcoords, ycoords, 8); } } } } /** * returns the weapon selected in the mech display, * or null if none selected or it is not artillery * or null if the selected entity is not owned */ private Mounted getSelectedArtilleryWeapon() { if (selectedEntity == null || selectedWeapon == null) { return null; } //TODO please eliminate the usage of the clientgui if (clientgui != null && !selectedEntity.getOwner().equals(clientgui.getClient().getLocalPlayer())) { return null; // Not my business to see this } if (selectedEntity.getEquipmentNum(selectedWeapon) == -1) { return null; //inconsistent state - weapon not on entity } if (!(selectedWeapon.getType() instanceof WeaponType && selectedWeapon.getType().hasFlag(WeaponType.F_ARTILLERY))) { return null; //not artillery } //otherwise, a weapon is selected, and it is artillery return selectedWeapon; } /** * Display artillery modifier in pretargeted hexes */ private void drawArtilleryHexes() { Mounted weapon = getSelectedArtilleryWeapon(); if (game.getArtillerySize() == 0 && weapon == null) { return; //nothing to do } int drawX = view.x / (int) (HEX_WC * scale) - 1; int drawY = view.y / (int) (HEX_H * scale) - 1; int drawWidth = view.width / (int) (HEX_WC * scale) + 3; int drawHeight = view.height / (int) (HEX_H * scale) + 3; IBoard board = game.getBoard(); Image scaledImage; // loop through the hexes for (int i = 0; i < drawHeight; i++) { for (int j = 0; j < drawWidth; j++) { Coords c = new Coords(j + drawX, i + drawY); Point p = getHexLocation(c); p.translate(-(view.x), -(view.y)); if (!board.contains(c)) { continue; } if (weapon != null) { //process targetted hexes int amod; //Check the predesignated hexes if (selectedEntity.getOwner().getArtyAutoHitHexes().contains(c)) { amod = TargetRoll.AUTOMATIC_SUCCESS; } else { amod = selectedEntity.aTracker.getModifier(weapon, c); } if (amod != 0) { //draw the crosshairs if (amod == TargetRoll.AUTOMATIC_SUCCESS) { //predesignated or already hit scaledImage = getScaledImage(tileManager.getArtilleryTarget(TilesetManager.ARTILLERY_AUTOHIT)); } else { scaledImage = getScaledImage(tileManager.getArtilleryTarget(TilesetManager.ARTILLERY_ADJUSTED)); } backGraph.drawImage(scaledImage, p.x, p.y, this); } } //process incoming attacks - requires server to update client's view of game for (Enumeration attacks = game.getArtilleryAttacks(); attacks.hasMoreElements();) { ArtilleryAttackAction a = (ArtilleryAttackAction) attacks.nextElement(); if (a.getWR().waa.getTarget(game).getPosition().equals(c)) { scaledImage = getScaledImage(tileManager.getArtilleryTarget(TilesetManager.ARTILLERY_INCOMING)); backGraph.drawImage(scaledImage, p.x, p.y, this); break; //do not draw multiple times, tooltop will show all attacks } } } } } private Vector getArtilleryAttacksAtLocation(Coords c) { Vector v = new Vector(); for (Enumeration attacks = game.getArtilleryAttacks(); attacks.hasMoreElements();) { ArtilleryAttackAction a = (ArtilleryAttackAction) attacks.nextElement(); if (a.getWR().waa.getTarget(game).getPosition().equals(c)) { v.addElement(a); } } return v; } /** * Writes "MINEFIELD" in minefield hexes... */ private void drawMinefields() { // only update visible hexes int drawX = view.x / (int) (HEX_WC * scale) - 1; int drawY = view.y / (int) (HEX_H * scale) - 1; int drawWidth = view.width / (int) (HEX_WC * scale) + 3; int drawHeight = view.height / (int) (HEX_H * scale) + 3; IBoard board = game.getBoard(); // loop through the hexes for (int i = 0; i < drawHeight; i++) { for (int j = 0; j < drawWidth; j++) { Coords c = new Coords(j + drawX, i + drawY); Point p = getHexLocation(c); p.translate(-(view.x), -(view.y)); if (!board.contains(c)) { continue; } if (!game.containsMinefield(c)) { continue; } Minefield mf = (Minefield) game.getMinefields(c).elementAt(0); Image tmpImage = getScaledImage(tileManager.getMinefieldSign()); backGraph.drawImage(tmpImage, p.x + (int) (13 * scale), p.y + (int) (13 * scale), this); backGraph.setColor(Color.black); int nbrMfs = game.getNbrMinefields(c); if (nbrMfs > 1) { drawCenteredString(Messages.getString("BoardView1.Multiple"), //$NON-NLS-1$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); } else if (nbrMfs == 1) { switch (mf.getType()) { case (Minefield.TYPE_CONVENTIONAL): drawCenteredString(Messages.getString("BoardView1.Conventional"), //$NON-NLS-1$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); break; case (Minefield.TYPE_THUNDER): drawCenteredString(Messages.getString("BoardView1.Thunder") + mf.getDamage() + ")", //$NON-NLS-1$ //$NON-NLS-2$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); break; case (Minefield.TYPE_THUNDER_INFERNO): drawCenteredString(Messages.getString("BoardView1.Thunder-Inf") + mf.getDamage() + ")", //$NON-NLS-1$ //$NON-NLS-2$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); break; case (Minefield.TYPE_THUNDER_ACTIVE): drawCenteredString(Messages.getString("BoardView1.Thunder-Actv") + mf.getDamage() + ")", //$NON-NLS-1$ //$NON-NLS-2$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); break; case (Minefield.TYPE_COMMAND_DETONATED): drawCenteredString(Messages.getString("BoardView1.Command-"), //$NON-NLS-1$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); drawCenteredString(Messages.getString("BoardView1.detonated"), //$NON-NLS-1$ p.x, p.y + (int) (60 * scale), font_minefield, backGraph); break; case (Minefield.TYPE_VIBRABOMB): drawCenteredString(Messages.getString("BoardView1.Vibrabomb"), //$NON-NLS-1$ p.x, p.y + (int) (51 * scale), font_minefield, backGraph); if (mf.getPlayerId() == localPlayer.getId()) { drawCenteredString("(" + mf.getSetting() + ")", //$NON-NLS-1$ //$NON-NLS-2$ p.x, p.y + (int) (60 * scale), font_minefield, backGraph); } break; } } } } } private void drawCenteredString(String string, int x, int y, Font font, Graphics graph) { FontMetrics currentMetrics = getFontMetrics(font); int stringWidth = currentMetrics.stringWidth(string); x += ((hex_size.width - stringWidth) / 2); graph.setFont(font); graph.drawString(string, x, y); } /** * Updates the board buffer to contain all the hexes needed by the view. */ private void updateBoardImage() { // check to make sure image is big enough if (boardGraph == null || view.width > boardRect.width || view.height > boardRect.height) { /* Ok, some history here. Before the zoom patch, the boardImage was created with the same size as the view. After the zoom patch, the boardImage was created with the same size as the entire board (all maps). This change ate up a hideous amount of memory (eg: in a 3x3 map set test with one mech, memory usage went from about 15MB to 60MB). I have now changed it back to the old way, and the zoom feature *seems* to still work. Why the zoom author made the change, I cannot say. */ boardImage = createImage(view.width, view.height); //boardImage = createImage(boardSize.width, boardSize.height); /* ----- */ if(boardGraph != null) boardGraph.dispose(); boardGraph = boardImage.getGraphics(); // Handle resizes correctly. checkScrollBounds(); boardRect = new Rectangle(view); System.out.println("boardview1: made a new board buffer " + boardRect); //$NON-NLS-1$ drawHexes(view); dirtyBoard = false; } if (!boardRect.union(view).equals(boardRect) || dirtyBoard) { moveBoardImage();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -