/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.core.Std; /* */ import NET.worlds.network.NetUpdate; /* */ import NET.worlds.network.ProgressDialog; /* */ import NET.worlds.network.URL; /* */ import NET.worlds.scape.BGLoaded; /* */ import NET.worlds.scape.BackgroundLoader; /* */ import NET.worlds.scape.Room; /* */ import NET.worlds.scape.World; /* */ import java.awt.Component; /* */ import java.awt.Dimension; /* */ import java.awt.Event; /* */ import java.awt.Graphics; /* */ import java.awt.Image; /* */ import java.awt.Panel; /* */ import java.io.DataInputStream; /* */ import java.io.File; /* */ import java.io.FileInputStream; /* */ import java.io.FileNotFoundException; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ import java.util.StringTokenizer; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class UniversePanel /* */ extends Panel /* */ implements MainCallback, ImageButtonsCallback, BGLoaded /* */ { /* */ private static final long serialVersionUID = 4029344486393517219L; /* */ UniverseImage bg; /* 292 */ int xOff = 0; /* 293 */ int yOff = 0; /* */ /* */ ImageButtons backButton; /* */ /* */ DefaultConsole owningConsole; /* */ /* 299 */ private static String datName = "universe/universe.dat"; /* 300 */ private static String bgName = "universe/universe.jpg"; /* */ static String lastCacheDat; /* */ /* 303 */ public UniversePanel(DefaultConsole cons) { this.owningConsole = cons; /* 304 */ setLayout(null); /* */ /* 306 */ this.backButton = new ImageButtons(Console.message("back.gif"), 60, 22, this); /* */ /* 308 */ String rbgName = IniFile.override().getIniString("UniverseBgFile", /* 309 */ bgName); /* 310 */ String rdatName = IniFile.override().getIniString("UniverseDatFile", /* 311 */ datName); /* */ /* 313 */ if (!new File(datName).exists()) /* */ { /* */ /* 316 */ lastCacheDat = ""; /* 317 */ if (!ProgressDialog.copyFile("universe.dat", datName)) /* 318 */ ProgressDialog.copyFile("../universe.dat", datName); /* */ } /* 320 */ readUniverseFile(datName); /* */ /* 322 */ if (!new File(bgName).exists()) { /* 323 */ lastCacheBg = ""; /* 324 */ if (!ProgressDialog.copyFile("universe.jpg", bgName)) /* 325 */ ProgressDialog.copyFile("../universe.jpg", bgName); /* */ } /* 327 */ this.bg = new UniverseImage(bgName); /* 328 */ add(this.bg); /* */ /* 330 */ Dimension image = this.bg.imageSize(); /* 331 */ this.bg.setSize(image.width, image.height); /* */ /* */ /* 334 */ String serv = NetUpdate.getUpgradeServerURL(); /* 335 */ BackgroundLoader.get(this, URL.make(serv + rbgName)); /* 336 */ BackgroundLoader.get(this, URL.make(serv + rdatName)); /* */ } /* */ /* */ /* */ static String lastCacheBg; /* 341 */ static Object locker = new Object(); /* */ Image offscreen; /* */ private boolean registered; /* */ int upDownState; /* */ int leftRightState; /* */ int lastKeyTime; /* */ /* */ private boolean safeCopyFile(String name) /* */ { /* 350 */ synchronized (locker) { /* 351 */ if ((name.endsWith("dat")) && (!name.equals(lastCacheDat))) /* */ { /* 353 */ lastCacheDat = name; /* 354 */ if (ProgressDialog.copyFile(name, datName)) { /* 355 */ readUniverseFile(datName); /* 356 */ add(this.bg); /* 357 */ return true; /* */ } /* 359 */ } else if ((name.endsWith("jpg")) && (!name.equals(lastCacheBg))) { /* 360 */ lastCacheBg = name; /* 361 */ if (ProgressDialog.copyFile(name, bgName)) { /* 362 */ remove(this.bg); /* 363 */ this.bg.flushImage(); /* */ /* 365 */ add(this.bg = new UniverseImage(bgName)); /* */ /* 367 */ Dimension image = this.bg.imageSize(); /* 368 */ this.bg.setSize(image.width, image.height); /* 369 */ return true; /* */ } /* */ } /* 372 */ return false; /* */ } /* */ } /* */ /* */ public void flushImage() /* */ { /* 378 */ remove(this.bg); /* 379 */ this.bg.flushImage(); /* */ } /* */ /* */ public synchronized Object asyncBackgroundLoad(String localName, URL remoteURL) /* */ { /* 384 */ return localName; /* */ } /* */ /* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) { /* 388 */ String localName = (String)obj; /* 389 */ if ((localName != null) && (new File(localName).exists()) && /* 390 */ (safeCopyFile(localName))) /* */ { /* 392 */ invalidate(); /* 393 */ validate(); /* 394 */ doLayout(); /* 395 */ repaint(); /* */ } /* */ /* 398 */ return false; /* */ } /* */ /* */ public Room getBackgroundLoadRoom() { /* 402 */ return null; /* */ } /* */ /* */ public synchronized void setViewportPos() /* */ { /* 407 */ Dimension viewport = getSize(); /* 408 */ Dimension image = this.bg.imageSize(); /* */ /* 410 */ int centerToLeft = image.width - viewport.width >> 1; /* 411 */ int centerToTop = image.height - viewport.height >> 1; /* */ /* 413 */ if (centerToLeft < 0) /* 414 */ this.xOff = 0; /* 415 */ if (centerToTop < 0) { /* 416 */ this.yOff = 0; /* */ } /* 418 */ int x = this.xOff + centerToLeft; /* 419 */ int y = this.yOff + centerToTop; /* */ /* */ /* 422 */ Dimension backSize = this.backButton.getPreferredSize(); /* 423 */ this.backButton.setSize(backSize); /* 424 */ this.backButton.setLocation(viewport.width - backSize.width - 5, /* 425 */ viewport.height - backSize.height - 3); /* */ /* 427 */ this.bg.setLocation(-x, -y); /* 428 */ int i = this.buttons.size(); /* 429 */ do { WorldButton b = (WorldButton)this.buttons.elementAt(i); /* 430 */ b.setLocation(-x + b.buttonX, -y + b.buttonY); /* */ /* 432 */ WorldButtonBullet bl = (WorldButtonBullet)this.bullets.elementAt(i); /* 433 */ bl.setLocation(-x + bl.circleX, -y + bl.circleY);i--; /* 428 */ } while (i >= 0); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void invalidate() /* */ { /* 441 */ super.invalidate(); /* 442 */ this.offscreen = null; /* */ } /* */ /* */ public void update(Graphics g) /* */ { /* 447 */ paint(g); /* */ } /* */ /* */ public synchronized void paint(Graphics g) /* */ { /* 452 */ setViewportPos(); /* */ /* 454 */ if (this.offscreen == null) { /* 455 */ this.offscreen = createImage(getSize().width, getSize().height); /* */ } /* 457 */ Graphics og = this.offscreen.getGraphics(); /* 458 */ og.setClip(0, 0, getSize().width, getSize().height); /* 459 */ super.paint(og); /* */ try { /* 461 */ g.drawImage(this.offscreen, 0, 0, this); /* */ /* */ } /* */ catch (NullPointerException e) /* */ { /* 466 */ this.offscreen = null; /* */ } /* 468 */ og.dispose(); /* */ /* 470 */ startWatch(); /* */ } /* */ /* */ /* */ public synchronized void startWatch() /* */ { /* 476 */ if (!this.registered) { /* 477 */ Main.register(this); /* 478 */ this.registered = true; /* */ } /* */ } /* */ /* */ public synchronized void stopWatch() /* */ { /* 484 */ if (this.registered) { /* 485 */ Main.unregister(this); /* 486 */ this.registered = false; /* */ } /* */ } /* */ /* */ public void setOffset(int x, int y) /* */ { /* 492 */ if (!this.owningConsole.isUniverseMode()) { /* 493 */ return; /* */ } /* 495 */ Dimension viewport = getSize(); /* 496 */ Dimension image = this.bg.imageSize(); /* */ /* */ /* 499 */ int centerToLeft = image.width - viewport.width >> 1; /* 500 */ int centerToTop = image.height - viewport.height >> 1; /* */ /* 502 */ x += centerToLeft; /* 503 */ y += centerToTop; /* */ /* 505 */ if (x < 0) { /* 506 */ x = 0; /* 507 */ } else if (x + viewport.width > image.width) { /* 508 */ x = image.width - viewport.width; /* */ } /* 510 */ if (y < 0) { /* 511 */ y = 0; /* 512 */ } else if (y + viewport.height > image.height) { /* 513 */ y = image.height - viewport.height; /* */ } /* */ /* 516 */ x -= centerToLeft; /* 517 */ y -= centerToTop; /* */ /* */ /* 520 */ if (viewport.width > image.width) { /* 521 */ x = 0; /* */ } /* 523 */ if (viewport.height > image.height) { /* 524 */ y = 0; /* */ } /* 526 */ if ((x != this.xOff) || (y != this.yOff)) { /* 527 */ this.xOff = x; /* 528 */ this.yOff = y; /* */ /* 530 */ repaint(); /* */ } /* */ } /* */ /* */ public void addOffset(int dx, int dy) /* */ { /* 536 */ setOffset(this.xOff + dx, this.yOff + dy); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ @Deprecated /* */ public boolean keyUp(Event event, int key) /* */ { /* 549 */ if ((key != 1004) && /* 550 */ (key != 1005) && /* 551 */ (key != 1006) && /* 552 */ (key != 1007)) /* */ { /* 554 */ return super.keyUp(event, key); /* */ } /* 556 */ if ((this.upDownState != 0) || (this.leftRightState != 0)) /* */ { /* 558 */ mainCallback(); /* */ /* 560 */ this.upDownState = 0; /* 561 */ this.leftRightState = 0; /* */ } /* */ /* 564 */ return true; /* */ } /* */ /* */ public synchronized void mainCallback() { /* 568 */ int now = Std.getRealTime(); /* 569 */ int xDiff = 0; /* 570 */ int yDiff = 0; /* */ /* 572 */ if (this.upDownState != 0) { /* 573 */ yDiff = this.upDownState * (now - this.lastKeyTime) / 5; /* */ } /* 575 */ if (this.leftRightState != 0) { /* 576 */ xDiff = this.leftRightState * (now - this.lastKeyTime) / 5; /* */ } /* 578 */ if (xDiff < -50) /* 579 */ xDiff = -50; /* 580 */ if (xDiff > 50) /* 581 */ xDiff = 50; /* 582 */ if (yDiff < -50) /* 583 */ yDiff = -50; /* 584 */ if (yDiff > 50) { /* 585 */ yDiff = 50; /* */ } /* 587 */ String curpkg = WorldsMarkPart.getCurrentPackageName(); /* 588 */ if ((curpkg != null) && (!curpkg.equals(WorldButton.currentPackageName))) { /* 589 */ WorldButton.currentPackageName = curpkg; /* 590 */ if ((xDiff == 0) && (yDiff == 0)) { /* 591 */ repaint(); /* */ } /* */ } /* 594 */ if ((xDiff != 0) || (yDiff != 0)) { /* 595 */ addOffset(xDiff, yDiff); /* */ } /* 597 */ this.lastKeyTime = now; /* */ /* 599 */ if ((this.owningConsole != Console.getActive()) || /* 600 */ (!this.owningConsole.isUniverseMode())) { /* 601 */ stopWatch(); /* */ } /* */ } /* */ /* */ @Deprecated /* */ public synchronized boolean keyDown(Event event, int key) /* */ { /* 608 */ boolean changed = false; /* */ /* 610 */ if (key == 1004) { /* 611 */ if (this.upDownState != -1) { /* 612 */ this.upDownState = -1; /* 613 */ changed = true; /* */ } /* 615 */ } else if (key == 1005) { /* 616 */ if (this.upDownState != 1) { /* 617 */ this.upDownState = 1; /* 618 */ changed = true; /* */ } /* 620 */ } else if (key == 1006) { /* 621 */ if (this.leftRightState != -1) { /* 622 */ this.leftRightState = -1; /* 623 */ changed = true; /* */ } /* 625 */ } else if (key == 1007) { /* 626 */ if (this.leftRightState != 1) { /* 627 */ this.leftRightState = 1; /* 628 */ changed = true; /* */ } /* */ } else { /* 631 */ return super.keyDown(event, key); /* */ } /* 633 */ if (changed) /* */ { /* 635 */ startWatch(); /* 636 */ this.lastKeyTime = (Std.getRealTime() - 20); /* */ } /* */ /* 639 */ return true; /* */ } /* */ /* 642 */ Vector buttons = new Vector(); /* 643 */ Vector bullets = new Vector(); /* */ /* */ private synchronized void readUniverseFile(String localName) { /* 646 */ removeAll(); /* */ /* 648 */ this.buttons = new Vector(); /* 649 */ this.bullets = new Vector(); /* 650 */ boolean showAll = IniFile.gamma().getIniInt("ShowAllWorlds", 0) != 0; /* */ /* 652 */ add(this.backButton); /* */ /* */ try /* */ { /* 656 */ FileInputStream in = new FileInputStream(localName); /* 657 */ DataInputStream dis = new DataInputStream(in); /* */ /* */ String line; /* 660 */ while ((line = dis.readLine()) != null) { String line; /* 661 */ StringTokenizer st = new StringTokenizer(line); /* 662 */ if ((st.hasMoreTokens()) && (line.charAt(0) != ';')) { /* 663 */ int circleX = Integer.parseInt(st.nextToken()); /* 664 */ int circleY = Integer.parseInt(st.nextToken()); /* 665 */ int buttonX = Integer.parseInt(st.nextToken()); /* 666 */ int buttonY = Integer.parseInt(st.nextToken()); /* */ /* 668 */ String pkg = st.nextToken(); /* */ /* */ /* 671 */ int privacy = Integer.parseInt(st.nextToken()); /* */ /* 673 */ String text = st.nextToken("").trim(); /* */ /* 675 */ Dimension sz = WorldButton.measure(text); /* */ /* 677 */ String[] texts = { text }; /* 678 */ boolean isLoaded = WorldsMarkPart.findPackage(pkg) != null; /* */ /* */ /* 681 */ if ((showAll) || (privacy == 0) || ((privacy == 1) && /* 682 */ (!World.isCloistered())) || ((privacy <= 2) && /* 683 */ (isLoaded)) || ((privacy == 3) && /* 684 */ (!World.isWorldsStoreProscribed()))) { /* 685 */ WorldButton button = new WorldButton(isLoaded, buttonX, /* 686 */ buttonY, sz.width, sz.height, texts, pkg, /* 687 */ privacy, this.owningConsole, this); /* 688 */ add(button); /* 689 */ this.buttons.addElement(button); /* */ /* 691 */ WorldButtonBullet bullet = new WorldButtonBullet( /* 692 */ circleX, circleY, button); /* 693 */ if ((circleX > 0) || (circleY > 0)) /* 694 */ add(bullet); /* 695 */ this.bullets.addElement(bullet); /* */ } /* */ } /* */ } /* */ /* 700 */ dis.close(); /* 701 */ in.close(); /* */ } catch (FileNotFoundException e) { /* 703 */ System.out.println(e); /* */ } catch (IOException e) { /* 705 */ System.out.println(e); /* */ } /* */ } /* */ /* */ public Object imageButtonsCallback(Component who, int which) { /* 710 */ if ((who instanceof WorldButton)) { /* 711 */ ((WorldButton)who).doAction(); /* 712 */ } else if (who == this.backButton) { /* 713 */ this.owningConsole.toggleUniverseMode(); /* */ } /* 715 */ return null; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\UniversePanel.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */