From: ChadF <ch...@us...> - 2007-07-08 18:10:39
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/wt In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv6285/src/games/stendhal/client/gui/wt Modified Files: Minimap.java Log Message: Changed minimap to be more compatible with a listener based pos update. Pre-translated graphics context for all things drawn. Index: Minimap.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/wt/Minimap.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Minimap.java 8 Jul 2007 03:25:26 -0000 1.44 --- Minimap.java 8 Jul 2007 18:10:30 -0000 1.45 *************** *** 66,69 **** --- 66,89 ---- private int height; + /** + * The view X offset. + */ + private int panx; + + /** + * The view Y offset. + */ + private int pany; + + /** + * The player X coordinate. + */ + private double playerX; + + /** + * The player Y coordinate. + */ + private double playerY; + /** minimap image */ private BufferedImage image; *************** *** 138,163 **** } /** ! * Draws the minimap. ! * ! * @param g graphics object for the game main window */ ! @Override ! protected void drawContent(Graphics clientg) { ! super.drawContent(clientg); ! if ((player == null) || (image == null)) { return; } - // now calculate how to pan the minimap - int panx = 0; - int pany = 0; - int w = image.getWidth(); int h = image.getHeight(); ! int xpos = (int) (player.getX() * scale) - width / 2; ! int ypos = (int) ((player.getY() + 1) * scale) - width / 2; if (w > width) { --- 158,191 ---- } + /** ! * Update the player view coordinates. ! * TODO: Replace with listener based update later. */ ! private void updatePosition() { ! playerX = player.getX(); ! playerY = player.getY() + 1.0; ! updateView(); ! } ! ! ! /** ! * Update the view pan. This should be done when the map size or ! * player position changes. ! */ ! private void updateView() { ! panx = 0; ! pany = 0; ! ! if(image == null) { return; } int w = image.getWidth(); int h = image.getHeight(); ! int xpos = (int) ((playerX * scale) + 0.5) - width / 2; ! int ypos = (int) ((playerY * scale) + 0.5) - width / 2; if (w > width) { *************** *** 180,213 **** } } // draw minimap ! clientg.drawImage(image, -panx, -pany, null); // Enabled with -Dstendhal.superman=x. if (mininps && User.isAdmin()) { // draw npcs (and creatures/sheeps) - clientg.translate(-panx, -pany); - for (Entity entity : client.getGameObjects()) { ! drawNPC(clientg, entity); } - - clientg.translate(panx, pany); } // draw players - Color playerColor = Color.WHITE; for (Entity entity : client.getGameObjects()) { if (entity instanceof Player) { Player aPlayer = (Player) entity; if(!aPlayer.isGhostMode()) { ! drawCross(clientg, (int) (aPlayer.getX() * scale) - panx + 1, (int) ((aPlayer.getY() + 1) * scale) ! - pany + 2, playerColor); } } else if( entity instanceof Portal) { Portal portal = (Portal) entity; if (!portal.isHidden()) { ! drawDot(clientg, (int) (entity.getX() * scale) - panx, (int) ((entity.getY()) * scale) - pany, ! Color.WHITE); } } --- 208,257 ---- } } + } + + + /** + * Draws the minimap. + * + * @param g graphics object for the game main window + */ + @Override + protected void drawContent(Graphics g) { + super.drawContent(g); + + if ((player == null) || (image == null)) { + return; + } + + // TODO: Update position via events instead + updatePosition(); + + Graphics vg = g.create(); + vg.translate(-panx, -pany); // draw minimap ! vg.drawImage(image, 0, 0, null); // Enabled with -Dstendhal.superman=x. if (mininps && User.isAdmin()) { // draw npcs (and creatures/sheeps) for (Entity entity : client.getGameObjects()) { ! drawNPC(vg, entity); } } // draw players for (Entity entity : client.getGameObjects()) { if (entity instanceof Player) { Player aPlayer = (Player) entity; + if(!aPlayer.isGhostMode()) { ! drawCross(vg, (int) ((aPlayer.getX() * scale) + 0.5), (int) (((aPlayer.getY() + 1.0) * scale) + 0.5), Color.WHITE); } } else if( entity instanceof Portal) { Portal portal = (Portal) entity; + if (!portal.isHidden()) { ! drawDot(vg, (int) ((entity.getX() * scale) + 0.5), (int) ((entity.getY() * scale) + 0.5), Color.WHITE); } } *************** *** 215,221 **** // draw myself ! playerColor = Color.BLUE; ! drawCross(clientg, (int) (player.getX() * scale) - panx + 1, (int) ((player.getY() + 1) * scale) - pany + 2, ! playerColor); } --- 259,265 ---- // draw myself ! drawCross(vg, (int) ((playerX * scale) + 0.5), (int) ((playerY * scale) + 0.5), Color.BLUE); ! ! vg.dispose(); } *************** *** 255,258 **** --- 299,305 ---- int size = 2; + x += 1; + y += 2; + g.setColor(color); g.drawLine(x - size, y, x + size, y); *************** *** 295,300 **** int h = image.getHeight(); ! int xpos = (int) (player.getX() * scale) - width / 2; ! int ypos = (int) ((player.getY() + 1) * scale) - width / 2; if (w > width) { --- 342,347 ---- int h = image.getHeight(); ! int xpos = (int) (playerX * scale) - width / 2; ! int ypos = (int) (playerY * scale) - width / 2; if (w > width) { |