Changeset 12152 for lang/java/NanikaKit
- Timestamp:
- 05/22/08 00:20:08 (5 years ago)
- Location:
- lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika
- Files:
-
- 3 modified
-
SakuraGhost.java (modified) (12 diffs)
-
SakuraShell.java (modified) (4 diffs)
-
SakuraSurface.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraGhost.java
r11027 r12152 11 11 import java.awt.EventQueue; 12 12 import java.awt.Graphics2D; 13 import java.awt.Point; 13 14 import java.awt.Rectangle; 14 15 import java.awt.event.ActionEvent; 15 16 import java.awt.event.MouseEvent; 16 17 import java.awt.event.MouseWheelEvent; 17 import java.awt.geom.AffineTransform;18 18 import java.awt.image.BufferedImage; 19 19 import java.io.File; 20 20 import java.io.IOException; 21 21 import java.util.LinkedHashMap; 22 import java.util.Map; 22 23 import java.util.Properties; 23 24 import java.util.concurrent.Executors; … … 49 50 50 51 /** シェル */ 51 private LinkedHashMap<Integer, SakuraShell> shell = new LinkedHashMap<Integer, SakuraShell>();52 private LinkedHashMap<Integer, SakuraShell> shells = new LinkedHashMap<Integer, SakuraShell>(); 52 53 53 54 /** NAR ファイル */ … … 188 189 { 189 190 if (popupMenu.isVisible()) return; 191 192 // 当たり判定 193 hit(mouseevent.getPoint()); 190 194 191 195 // reset(); … … 371 375 372 376 // sakura 373 shell .put(0, sakura);377 shells.put(0, sakura); 374 378 // shell.get(0).setSurface(0); 375 379 376 380 // kero 377 shell .put(1, kero);381 shells.put(1, kero); 378 382 // shell.get(1).setSurface(10); 379 383 } … … 387 391 { 388 392 log.info("close"); 389 shell .clear();393 shells.clear(); 390 394 nar = null; 391 395 currentShell = null; … … 403 407 { 404 408 log.info("vanish"); 405 shell .clear();409 shells.clear(); 406 410 nar = null; 407 411 currentShell = null; … … 434 438 { 435 439 log.debug("scope=" + scope); 436 currentShell = shell .get(scope);440 currentShell = shells.get(scope); 437 441 438 442 return this; … … 522 526 public SakuraGhost talk(String message) 523 527 { 524 log.debug(message);528 // log.debug(message); 525 529 // if (currentShell.getBalloon() != null) 526 530 // { … … 601 605 public void draw(Graphics2D g) 602 606 { 603 SakuraShell sakura = shell .get(0);604 SakuraShell kero = shell .get(1);607 SakuraShell sakura = shells.get(0); 608 SakuraShell kero = shells.get(1); 605 609 606 610 Rectangle clip = g.getClipBounds(); 607 log.debug("clip=" + clip);611 // log.debug("clip=" + clip); 608 612 int x = clip.x; 609 613 int y = clip.y; … … 614 618 if (sakura != null && sakura.getSurface() != null) 615 619 { 616 AffineTransform tx = new AffineTransform();620 // AffineTransform tx = new AffineTransform(); 617 621 // tx.scale(0.8, 0.8); 618 622 // Rectangle rect = sakura.getBounds(); 619 Rectangle rect = tx.createTransformedShape(sakura.getSurface()).getBounds(); 623 // Rectangle rect = tx.createTransformedShape(sakura.getSurface()).getBounds(); 624 Rectangle rect = sakura.getSurface().getBounds(); 620 625 // log.debug("rect=" + rect); 621 626 rect.x = right - rect.width; 622 627 rect.y = bottom - rect.height; 623 628 // tx.shear(-0.5, 0); 624 tx.rotate(Math.toRadians(0), right - rect.width / 2, bottom); 625 tx.translate(rect.x, rect.y); 626 g.setTransform(tx); 629 // tx.rotate(Math.toRadians(0), right - rect.width / 2, bottom); 630 // tx.translate(rect.x, rect.y); 631 // g.setTransform(tx); 632 sakura.setLocation(rect.getLocation()); 627 633 sakura.draw(g); 628 634 right = rect.x; … … 632 638 if (kero != null && kero.getSurface() != null) 633 639 { 634 AffineTransform tx = new AffineTransform();640 // AffineTransform tx = new AffineTransform(); 635 641 Rectangle rect = kero.getSurface().getBounds(); 636 642 // rect.x = x + (right - x) / 2 - rect.width / 2; 637 643 rect.x = right - rect.width; 638 644 rect.y = bottom - rect.height; 639 tx.translate(rect.x, rect.y);645 // tx.translate(rect.x, rect.y); 640 646 // tx.shear(0.5, 0); 641 g.setTransform(tx); 647 // g.setTransform(tx); 648 kero.setLocation(rect.getLocation()); 642 649 kero.draw(g); 643 650 } … … 662 669 663 670 /** 671 * 当たり判定を確認します。 672 * 673 * @param p クリック位置 674 */ 675 public void hit(Point p) 676 { 677 System.out.println("click: " + p); 678 log.debug("hit: " + p + ", shell: " + shells); 679 for (Map.Entry<Integer, SakuraShell> entry : shells.entrySet()) 680 { 681 int id = entry.getKey(); 682 SakuraShell s = entry.getValue(); 683 String name = s.hit(p); 684 if (name != null) System.out.println("hit! " + name); 685 log.debug("id: " + id + ", shell: " + s); 686 } 687 } 688 689 /** 664 690 * サムネールを返します。 665 691 * -
lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraShell.java
r9435 r12152 9 9 10 10 import java.awt.Graphics2D; 11 import java.awt.Point; 12 import java.awt.geom.AffineTransform; 11 13 import java.io.File; 12 14 import java.io.IOException; … … 72 74 private SakuraBalloon balloon; 73 75 76 /** 表示座標 */ 77 private Point loc = new Point(); 78 74 79 /** 75 80 * シェルを構築します。 … … 264 269 265 270 /** 271 * 表示座標を設定します。 272 * 273 * @param p 表示座標 274 */ 275 public void setLocation(Point p) 276 { 277 loc.setLocation(p); 278 } 279 280 /** 266 281 * サーフェスを描画します。 267 282 * … … 270 285 public void draw(Graphics2D g) 271 286 { 287 AffineTransform tx = new AffineTransform(); 288 tx.translate(loc.x, loc.y); 289 g.setTransform(tx); 290 272 291 if (surface != null) surface.draw(g); 273 292 if (balloon != null) balloon.draw(g); 293 } 294 295 /** 296 * 当たり判定します。 297 * 298 * @param p 当たり判定座標 299 * @return 当たりの場合は当たった部分の名前。そうでない場合は null 300 */ 301 public String hit(Point p) 302 { 303 return surface != null ? surface.hit(p.x - loc.x, p.y - loc.y) : null; 274 304 } 275 305 -
lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraSurface.java
r11027 r12152 64 64 65 65 /** 66 * サーフェスを ロードします。66 * サーフェスを構築します。 67 67 * 68 68 * @param id サーフェス ID 69 * @param nar NAR アーカイブ 70 * @return サーフェス 71 * @throws IOException 入力エラーが発生した場合 72 */ 73 public static SakuraSurface getSurface(int id, NanikaArchive nar) throws IOException 74 { 75 File file = new File(nar.getShellDirectory(), String.format("surface%s.png", id)); 76 log.debug(id + "=" + file); 77 NanikaEntry entry = nar.getEntry(file); 78 // log.debug(id + "=" + entry.getName()); 79 80 String descript = loadDescript(id, nar); 81 BufferedImage image = ImageIO.read(entry.getInputStream()); 82 // log.debug("image=" + image); 83 // log.debug("image=" + image.getWidth() + "x" + image.getHeight() + "," + image.getType() + "," + image.getColorModel()); 84 // int rgb = image.getRGB(0, 0); 85 // log.debug("rgb=0x" + Integer.toHexString(rgb)); 86 SakuraSurface surface = new SakuraSurface("" + id, image, descript); 87 return surface; 88 } 69 * @param image サーフェスイメージ 70 */ 71 public SakuraSurface(String id, BufferedImage image) 72 { 73 this(id, image, null); 74 } 75 76 /** 77 * サーフェスを構築します。 78 * 79 * @param id サーフェス ID 80 * @param image サーフェスイメージ 81 * @param descript サーフェス定義 82 */ 83 public SakuraSurface(String id, BufferedImage image, String descript) 84 { 85 this.id = id; 86 this.image = image; 87 this.rect = new Rectangle(0, 0, image.getWidth(), image.getHeight()); 88 if (descript != null) parseDescript(descript); 89 } 90 91 /** 92 * サーフェスをロードします。 93 * 94 * @param id サーフェス ID 95 * @param nar NAR アーカイブ 96 * @return サーフェス 97 * @throws IOException 入力エラーが発生した場合 98 */ 99 public static SakuraSurface getSurface(int id, NanikaArchive nar) throws IOException 100 { 101 File file = new File(nar.getShellDirectory(), String.format("surface%s.png", id)); 102 log.debug(id + "=" + file); 103 NanikaEntry entry = nar.getEntry(file); 104 // log.debug(id + "=" + entry.getName()); 105 106 String descript = loadDescript(id, nar); 107 BufferedImage image = ImageIO.read(entry.getInputStream()); 108 // log.debug("image=" + image); 109 // log.debug("image=" + image.getWidth() + "x" + image.getHeight() + "," + image.getType() + "," + image.getColorModel()); 110 // int rgb = image.getRGB(0, 0); 111 // log.debug("rgb=0x" + Integer.toHexString(rgb)); 112 SakuraSurface surface = new SakuraSurface("" + id, image, descript); 113 return surface; 114 } 89 115 90 116 /** … … 124 150 return null; 125 151 } 126 }127 128 /**129 * サーフェスを構築します。130 *131 * @param id サーフェス ID132 * @param image サーフェスイメージ133 */134 public SakuraSurface(String id, BufferedImage image)135 {136 this(id, image, null);137 }138 139 /**140 * サーフェスを構築します。141 *142 * @param id サーフェス ID143 * @param image サーフェスイメージ144 * @param descript サーフェス定義145 */146 public SakuraSurface(String id, BufferedImage image, String descript)147 {148 this.id = id;149 this.image = image;150 this.rect = new Rectangle(0, 0, image.getWidth(), image.getHeight());151 if (descript != null) parseDescript(descript);152 152 } 153 153 … … 176 176 Rectangle rect = new Rectangle(new Point(x1, y1)); 177 177 rect.add(new Point(x2, y2)); 178 System.out.println("当たり判定: " + head + ": " + name + ": " + rect);178 log.debug("当たり判定: " + head + ": " + name + ": " + rect); 179 179 collisions.put(name, rect); 180 180 } … … 191 191 int y = Integer.parseInt(token[3]); 192 192 Point p = new Point(x, y); 193 System.out.println("ベースサーフェス: " + head + ": " + Arrays.toString(new Object[]{type, filename, p}));193 log.debug("ベースサーフェス: " + head + ": " + Arrays.toString(new Object[]{type, filename, p})); 194 194 } 195 195 else if (s.hasNext("(.+?interval),(.+)")) … … 199 199 String head = m.group(1); 200 200 String body = m.group(2); 201 System.out.println("アニメーション開始: " + head + ": " + Arrays.toString(body.split(",")));201 log.debug("アニメーション開始: " + head + ": " + Arrays.toString(body.split(","))); 202 202 } 203 203 else if (s.hasNext("(.+?pattern.+?),(.+)")) … … 207 207 String head = m.group(1); 208 208 String body = m.group(2); 209 System.out.println("アニメーションパターン: " + head + ": " + Arrays.toString(body.split(",")));209 log.debug("アニメーションパターン: " + head + ": " + Arrays.toString(body.split(","))); 210 210 } 211 211 else if (s.hasNext("(.+?option),(.+)")) … … 215 215 String head = m.group(1); 216 216 String body = m.group(2); 217 System.out.println("オプション: " + head + ": " + Arrays.toString(body.split(",")));217 log.debug("オプション: " + head + ": " + Arrays.toString(body.split(","))); 218 218 } 219 219 else if (s.hasNextLine()) 220 220 { 221 221 String line = s.nextLine(); 222 if (line.trim().length() > 0) System.out.println("未定義: " + line);222 if (line.trim().length() > 0) log.debug("未定義: " + line); 223 223 } 224 224 else … … 248 248 { 249 249 rect.setLocation(x, y); 250 }251 252 /**253 * サーフェスの文字列表現を返します。254 *255 * @return サーフェスの文字列表現256 */257 public String toString()258 {259 return String.format("%s[%d, %d, %dx%d, 0x%x]", id, rect.x, rect.y, rect.width, rect.height, image.getRGB(0, 0));260 250 } 261 251 … … 313 303 public String hit(int x, int y) 314 304 { 305 // System.out.println("location: " + x + ", " + y); 306 // System.out.println("shape: " + rect); 315 307 for (Map.Entry<String, Rectangle> entry : collisions.entrySet()) 316 308 { 317 309 String name = entry.getKey(); 318 310 Rectangle rect = entry.getValue(); 311 // System.out.println("hit? " + name + ", " + rect); 319 312 if (rect.contains(x, y)) return name; 320 313 } 321 314 322 315 return null; 316 } 317 318 /** 319 * サーフェスの文字列表現を返します。 320 * 321 * @return サーフェスの文字列表現 322 */ 323 public String toString() 324 { 325 return String.format("%s[%d, %d, %dx%d, 0x%x]", id, rect.x, rect.y, rect.width, rect.height, image.getRGB(0, 0)); 323 326 } 324 327
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)