[Jrisk-cvs] SF.net SVN: domination-code:[2607] Domination/swingUI/src/net/yura/ domination/tools/m
Brought to you by:
yuranet
|
From: <yu...@us...> - 2025-01-09 21:23:59
|
Revision: 2607
http://sourceforge.net/p/domination/code/2607
Author: yuranet
Date: 2025-01-09 21:23:56 +0000 (Thu, 09 Jan 2025)
Log Message:
-----------
more teg maps support
Modified Paths:
--------------
Domination/swingUI/src/net/yura/domination/tools/mapeditor/TegMapLoader.java
Modified: Domination/swingUI/src/net/yura/domination/tools/mapeditor/TegMapLoader.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/tools/mapeditor/TegMapLoader.java 2024-12-31 04:14:19 UTC (rev 2606)
+++ Domination/swingUI/src/net/yura/domination/tools/mapeditor/TegMapLoader.java 2025-01-09 21:23:56 UTC (rev 2607)
@@ -2,6 +2,9 @@
import java.awt.Color;
import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.RGBImageFilter;
@@ -19,10 +22,10 @@
* @author Yura Mamyrin
*/
public class TegMapLoader {
-
- class MyFilter extends RGBImageFilter {
+
+ static class ImgMapFilter extends RGBImageFilter {
int color;
- public MyFilter(int color) {
+ public ImgMapFilter(int color) {
this.color = color;
}
public int filterRGB(int x, int y, int rgb) {
@@ -30,22 +33,30 @@
return alpha > 127 ? color : 0;
}
}
-
+
+ static class ImgPicFilter extends RGBImageFilter {
+ public int filterRGB(int x, int y, int rgb) {
+ int alpha = ColorUtil.getAlpha(rgb);
+ return alpha > 127 ? rgb : 0;
+ }
+ }
+
public void load(File xmlfile, RiskGame map, MapEditor editor) throws Exception {
BufferedImage board=null,imgMap=null;
File dir = xmlfile.getParentFile();
-
+
InputStream input = new FileInputStream(xmlfile);
-
+
KXmlParser parser = new KXmlParser();
parser.setInput(input, null);
parser.nextTag();
// read start tag
-
+
int continentId=0;
int countryId=0;
+ Point armiesPos = null;
while (parser.nextTag() != KXmlParser.END_TAG) {
String name = parser.getName();
@@ -80,12 +91,12 @@
BufferedImage countryImage = ImageIO.read( new File(dir, file) );
Graphics g = board.getGraphics();
- g.drawImage(countryImage, continentX+pos_x, continentY+pos_y, null);
+ drawTegCountry(g, countryImage, continentX+pos_x, continentY+pos_y);
g.dispose();
Color color = new Color(countryId+1, countryId+1, countryId+1);
- FilteredImageSource filteredSrc = new FilteredImageSource(countryImage.getSource(), new MyFilter( color.getRGB() ) );
- java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().createImage(filteredSrc);
+ FilteredImageSource filteredSrc = new FilteredImageSource(countryImage.getSource(), new ImgMapFilter(color.getRGB()));
+ Image image = Toolkit.getDefaultToolkit().createImage(filteredSrc);
Graphics g2 = imgMap.getGraphics();
g2.drawImage(image, continentX+pos_x, continentY+pos_y, null);
@@ -115,12 +126,34 @@
board = MapEditor.makeRGBImage( ImageIO.read(boardFile) );
imgMap = MapEditor.newImageMap(board.getWidth(), board.getHeight());
}
-
+ else if ("armies_pos".equals(name)) {
+ //<armies_pos x="358" y="24" background="false" dragable="false"/>
+ String x = parser.getAttributeValue(null, "x");
+ String y = parser.getAttributeValue(null, "y");
+ armiesPos = new Point(Integer.parseInt(x), Integer.parseInt(y));
+ }
+
// read end tag
parser.skipSubTree();
}
}
-
+
+ if (armiesPos != null) {
+ Graphics g2 = board.getGraphics();
+ int yOffset = g2.getFontMetrics().getAscent();
+ int xOffset = g2.getFontMetrics().stringWidth(" 9 ");
+ g2.setColor(Color.BLACK);
+
+ for (Continent continent : map.getContinents()) {
+ // some maps use different colors for the continents, so this may be wrong
+ //g2.setColor(new Color(continent.getColor()));
+ g2.drawString(" " + continent.getArmyValue(), armiesPos.x, armiesPos.y + yOffset);
+ g2.drawString(continent.getName(), armiesPos.x + xOffset, armiesPos.y + yOffset);
+ yOffset = yOffset + g2.getFontMetrics().getHeight();
+ }
+ g2.dispose();
+ }
+
editor.setImagePic(board, null, false);
editor.setImageMap(imgMap);
}
@@ -137,4 +170,15 @@
default: throw new RuntimeException("strange teg id " + tegId);
}
}
+
+ private void drawTegCountry(Graphics g, BufferedImage countryImage, int x, int y) {
+ if (countryImage.getAlphaRaster() != null) {
+ g.drawImage(countryImage, x, y, null);
+ }
+ else {
+ FilteredImageSource filteredSrc = new FilteredImageSource(countryImage.getSource(), new ImgPicFilter());
+ Image image = Toolkit.getDefaultToolkit().createImage(filteredSrc);
+ g.drawImage(image, x, y, null);
+ }
+ }
}
|