Advertisement
Guest User

Untitled

a guest
Oct 28th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.event.FocusEvent;
  8. import java.awt.event.FocusListener;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.event.KeyListener;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14. import java.awt.event.MouseWheelEvent;
  15. import java.awt.event.MouseWheelListener;
  16. import java.awt.event.WindowEvent;
  17. import java.awt.event.WindowListener;
  18. import java.awt.Insets;
  19.  
  20. public class RSApplet extends Applet implements Runnable, MouseListener, MouseMotionListener, MouseWheelListener, KeyListener, FocusListener, WindowListener {
  21.  
  22. /**
  23. *
  24. */
  25.  
  26. private static final long serialVersionUID = 1473917011474991756L;
  27. final void createClientFrame(int i, int j) {
  28. myWidth = j;
  29. myHeight = i;
  30. gameFrame = new RSFrame(this, myWidth, myHeight);
  31. graphics = getGameComponent().getGraphics();
  32. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  33. startRunnable(this, 1);
  34. }
  35.  
  36. final void initClientFrame(int i, int j) {
  37. myWidth = j;
  38. myHeight = i;
  39. graphics = getGameComponent().getGraphics();
  40. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  41. startRunnable(this, 1);
  42. }
  43.  
  44. public void mouseWheelMoved(MouseWheelEvent event) {
  45. int rotation = event.getWheelRotation();
  46. handleInterfaceScrolling(event);
  47. if(mouseX > 0 && mouseX < 512 && mouseY > 503 - 165 && mouseY < 503 - 25) {
  48. int scrollPos = client.anInt1089;
  49. scrollPos -= rotation * 30;
  50. if(scrollPos < 0)
  51. scrollPos = 0;
  52. if(scrollPos > client.anInt1211 - 110)
  53. scrollPos = client.anInt1211 - 110;
  54. if(client.anInt1089 != scrollPos) {
  55. client.anInt1089 = scrollPos;
  56. client.inputTaken = true;
  57. }
  58. }
  59. }
  60. public void handleInterfaceScrolling(MouseWheelEvent event) {
  61. int rotation = event.getWheelRotation();
  62. int positionX = 0;
  63. int positionY = 0;
  64. int width = 0;
  65. int height = 0;
  66. int offsetX = 0;
  67. int offsetY = 0;
  68. int childID = 0;
  69. /* Tab interface scrolling */
  70. int tabInterfaceID = client.tabInterfaceIDs[client.tabID];
  71. if (tabInterfaceID != -1) {
  72. RSInterface tab = RSInterface.interfaceCache[tabInterfaceID];
  73. offsetX = 765 - 218;
  74. offsetY = 503 - 298;
  75. for (int index = 0; index < tab.children.length; index++) {
  76. if (RSInterface.interfaceCache[tab.children[index]].scrollMax > 0) {
  77. childID = index;
  78. positionX = tab.childX[index];
  79. positionY = tab.childY[index];
  80. width = RSInterface.interfaceCache[tab.children[index]].width;
  81. height = RSInterface.interfaceCache[tab.children[index]].height;
  82. break;
  83. }
  84. }
  85. if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && mouseX < offsetX + positionX + width && mouseY < offsetY + positionY + height) {
  86. RSInterface.interfaceCache[tab.children[childID]].scrollPosition += rotation * 30;
  87. client.tabAreaAltered = true;
  88. client.needDrawTabArea = true;
  89. }
  90. }
  91. /* Main interface scrolling */
  92. if (client.openInterfaceID != -1) {
  93. RSInterface rsi = RSInterface.interfaceCache[client.openInterfaceID];
  94. offsetX = 4;
  95. offsetY = 4;
  96. for (int index = 0; index < rsi.children.length; index++) {
  97. if (RSInterface.interfaceCache[rsi.children[index]].scrollMax > 0) {
  98. childID = index;
  99. positionX = rsi.childX[index];
  100. positionY = rsi.childY[index];
  101. width = RSInterface.interfaceCache[rsi.children[index]].width;
  102. height = RSInterface.interfaceCache[rsi.children[index]].height;
  103. break;
  104. }
  105. }
  106. if (mouseX > offsetX + positionX && mouseY > offsetY + positionY && mouseX < offsetX + positionX + width && mouseY < offsetY + positionY + height) {
  107. RSInterface.interfaceCache[rsi.children[childID]].scrollPosition += rotation * 30;
  108. }
  109. }
  110. }
  111. public void run()
  112. {
  113. getGameComponent().addMouseListener(this);
  114. getGameComponent().addMouseMotionListener(this);
  115. getGameComponent().addKeyListener(this);
  116. getGameComponent().addFocusListener(this);
  117. getGameComponent().addMouseWheelListener(this);
  118. if(gameFrame != null)
  119. gameFrame.addWindowListener(this);
  120. //drawLoadingText(0, "Loading...");
  121. startUp();
  122. int i = 0;
  123. int j = 256;
  124. int k = 1;
  125. int i1 = 0;
  126. int j1 = 0;
  127. for(int k1 = 0; k1 < 10; k1++)
  128. aLongArray7[k1] = System.currentTimeMillis();
  129.  
  130. System.currentTimeMillis();
  131. while(anInt4 >= 0)
  132. {
  133. if(anInt4 > 0)
  134. {
  135. anInt4--;
  136. if(anInt4 == 0)
  137. {
  138. exit();
  139. return;
  140. }
  141. }
  142. int i2 = j;
  143. int j2 = k;
  144. j = 300;
  145. k = 1;
  146. long l1 = System.currentTimeMillis();
  147. if(aLongArray7[i] == 0L)
  148. {
  149. j = i2;
  150. k = j2;
  151. } else
  152. if(l1 > aLongArray7[i])
  153. j = (int)((long)(2560 * delayTime) / (l1 - aLongArray7[i]));
  154. if(j < 25)
  155. j = 25;
  156. if(j > 256)
  157. {
  158. j = 256;
  159. k = (int)((long) delayTime - (l1 - aLongArray7[i]) / 10L);
  160. }
  161. if(k > delayTime)
  162. k = delayTime;
  163. aLongArray7[i] = l1;
  164. i = (i + 1) % 10;
  165. if(k > 1)
  166. {
  167. for(int k2 = 0; k2 < 10; k2++)
  168. if(aLongArray7[k2] != 0L)
  169. aLongArray7[k2] += k;
  170.  
  171. }
  172. if(k < minDelay)
  173. k = minDelay;
  174. try
  175. {
  176. Thread.sleep(k);
  177. }
  178. catch(InterruptedException _ex)
  179. {
  180. j1++;
  181. }
  182. for(; i1 < 256; i1 += j)
  183. {
  184. clickMode3 = clickMode1;
  185. saveClickX = clickX;
  186. saveClickY = clickY;
  187. aLong29 = clickTime;
  188. clickMode1 = 0;
  189. processGameLoop();
  190. readIndex = writeIndex;
  191. }
  192.  
  193. i1 &= 0xff;
  194. if(delayTime > 0)
  195. fps = (1000 * j) / (delayTime * 256);
  196. processDrawing();
  197. if(shouldDebug)
  198. {
  199. System.out.println("ntime:" + l1);
  200. for(int l2 = 0; l2 < 10; l2++)
  201. {
  202. int i3 = ((i - l2 - 1) + 20) % 10;
  203. System.out.println("otim" + i3 + ":" + aLongArray7[i3]);
  204. }
  205.  
  206. System.out.println("fps:" + fps + " ratio:" + j + " count:" + i1);
  207. System.out.println("del:" + k + " deltime:" + delayTime + " mindel:" + minDelay);
  208. System.out.println("intex:" + j1 + " opos:" + i);
  209. shouldDebug = false;
  210. j1 = 0;
  211. }
  212. }
  213. if(anInt4 == -1)
  214. exit();
  215. }
  216.  
  217.  
  218.  
  219. private void exit()
  220. {
  221. anInt4 = -2;
  222. cleanUpForQuit();
  223. if(gameFrame != null)
  224. {
  225. try
  226. {
  227. Thread.sleep(1000L);
  228. }
  229. catch(Exception _ex) { }
  230. try
  231. {
  232. System.exit(0);
  233. }
  234. catch(Throwable _ex) { }
  235. }
  236. }
  237.  
  238. final void method4(int i)
  239. {
  240. delayTime = 1000 / i;
  241. }
  242.  
  243. public final void start()
  244. {
  245. if(anInt4 >= 0)
  246. anInt4 = 0;
  247. }
  248.  
  249. public final void stop()
  250. {
  251. if(anInt4 >= 0)
  252. anInt4 = 4000 / delayTime;
  253. }
  254.  
  255. public final void destroy()
  256. {
  257. anInt4 = -1;
  258. try
  259. {
  260. Thread.sleep(5000L);
  261. }
  262. catch(Exception _ex) { }
  263. if(anInt4 == -1)
  264. exit();
  265. }
  266.  
  267. public final void update(Graphics g)
  268. {
  269. if(graphics == null)
  270. graphics = g;
  271. shouldClearScreen = true;
  272. raiseWelcomeScreen();
  273. }
  274.  
  275. public final void paint(Graphics g)
  276. {
  277. if(graphics == null)
  278. graphics = g;
  279. shouldClearScreen = true;
  280. raiseWelcomeScreen();
  281. }
  282.  
  283. public boolean mouseWheelDown;
  284. public final void mousePressed(MouseEvent mouseevent)
  285. {
  286. int i = mouseevent.getX();
  287. int j = mouseevent.getY();
  288. if(gameFrame != null)
  289. {
  290. i -= 4;//4
  291. j -= 22;//22
  292. }
  293. idleTime = 0;
  294. clickX = i;
  295. clickY = j;
  296. clickTime = System.currentTimeMillis();
  297. int type = mouseevent.getButton();
  298. if (type == 2) {
  299. mouseWheelDown = true;
  300. mouseWheelX = mouseX;
  301. mouseWheelY = mouseY;
  302. return;
  303. }
  304. if(mouseevent.isMetaDown())
  305. {
  306. clickMode1 = 2;
  307. clickMode2 = 2;
  308. } else
  309. {
  310. clickMode1 = 1;
  311. clickMode2 = 1;
  312. }
  313. }
  314.  
  315. public final void mouseReleased(MouseEvent mouseevent)
  316. {
  317. idleTime = 0;
  318. clickMode2 = 0;
  319. mouseWheelDown = false;
  320. }
  321.  
  322. public final void mouseClicked(MouseEvent mouseevent)
  323. {
  324. }
  325.  
  326. public final void mouseEntered(MouseEvent mouseevent)
  327. {
  328. }
  329.  
  330. public final void mouseExited(MouseEvent mouseevent)
  331. {
  332. idleTime = 0;
  333. mouseX = -1;
  334. mouseY = -1;
  335. }
  336. public int mouseWheelX;
  337. public int mouseWheelY;
  338. public final void mouseDragged(MouseEvent e) {
  339. int x = e.getX();
  340. int y = e.getY();
  341. if(gameFrame != null) {
  342. Insets insets = gameFrame.getInsets();
  343. x -= insets.left;//4
  344. y -= insets.top;//22
  345. }
  346. if (mouseWheelDown) {
  347. y = mouseWheelX - e.getX();
  348. int k = mouseWheelY - e.getY();
  349. mouseWheelDragged(y, -k);
  350. mouseWheelX = e.getX();
  351. mouseWheelY = e.getY();
  352. return;
  353. }
  354. idleTime = 0;
  355. mouseX = x;
  356. mouseY = y;
  357. mouseWheelDown = true;
  358. }
  359.  
  360. void mouseWheelDragged(int param1, int param2) {
  361.  
  362. }
  363.  
  364. public final void mouseMoved(MouseEvent mouseevent)
  365. {
  366. int i = mouseevent.getX();
  367. int j = mouseevent.getY();
  368. if(gameFrame != null)
  369. {
  370. i -= 4;
  371. j -= 22;
  372. }
  373. if (System.currentTimeMillis() - clickTime >= 250L
  374. || Math.abs(saveClickX - i) > 5 || Math.abs(saveClickY - j) > 5) {
  375. idleTime = 0;
  376. mouseX = i;
  377. mouseY = j;
  378. }
  379. }
  380. public static int hotKey = 508;
  381. public final void keyPressed(KeyEvent keyevent)
  382. {
  383. idleTime = 0;
  384. int i = keyevent.getKeyCode();
  385. int j = keyevent.getKeyChar();
  386. if(j < 30)
  387. j = 0;
  388. if(i == 37)
  389. j = 1;
  390. if(i == 39)
  391. j = 2;
  392. if(i == 38)
  393. j = 3;
  394. if(i == 40)
  395. j = 4;
  396. if(i == 17)
  397. j = 5;
  398. if(i == 8)
  399. j = 8;
  400. if(i == 127)
  401. j = 8;
  402. if(i == 9)
  403. j = 9;
  404. if(i == 10)
  405. j = 10;
  406. if(i >= 112 && i <= 123)
  407. j = (1008 + i) - 112;
  408. if(i == 36)
  409. j = 1000;
  410. if(i == 35)
  411. j = 1001;
  412. if(i == 33)
  413. j = 1002;
  414. if(i == 34)
  415. j = 1003;
  416. if (i == KeyEvent.VK_ESCAPE) {
  417. client.setTab(3);
  418. }
  419. if (i == KeyEvent.VK_F1) {
  420. client.setTab(0);
  421. }
  422. if (i == KeyEvent.VK_F2) {
  423. client.setTab(1);
  424. }
  425. if (i == KeyEvent.VK_F3) {
  426. client.setTab(2);
  427. }
  428. if (i == KeyEvent.VK_F4) {
  429. client.setTab(4);
  430. }
  431. if (i == KeyEvent.VK_F5) {
  432. client.setTab(5);
  433. }
  434. if (i == KeyEvent.VK_F6) {
  435. client.setTab(6);
  436. }
  437. if (i == KeyEvent.VK_F7) {
  438. client.setTab(7);
  439. }
  440. if (i == KeyEvent.VK_F8) {
  441. client.setTab(8);
  442. }
  443. if (i == KeyEvent.VK_F9) {
  444. client.setTab(9);
  445. }
  446. if (i == KeyEvent.VK_F10) {
  447. client.setTab(11);
  448. }
  449. if (i == KeyEvent.VK_F11) {
  450. client.setTab(12);
  451. }
  452. if (i == KeyEvent.VK_F12) {
  453. client.setTab(13);
  454. }
  455. if(j > 0 && j < 128)
  456. keyArray[j] = 1;
  457. if(j > 4)
  458. {
  459. charQueue[writeIndex] = j;
  460. writeIndex = writeIndex + 1 & 0x7f;
  461. }
  462. }
  463.  
  464. public final void keyReleased(KeyEvent keyevent)
  465. {
  466. idleTime = 0;
  467. int i = keyevent.getKeyCode();
  468. char c = keyevent.getKeyChar();
  469. if(c < '\036')
  470. c = '\0';
  471. if(i == 37)
  472. c = '\001';
  473. if(i == 39)
  474. c = '\002';
  475. if(i == 38)
  476. c = '\003';
  477. if(i == 40)
  478. c = '\004';
  479. if(i == 17)
  480. c = '\005';
  481. if(i == 8)
  482. c = '\b';
  483. if(i == 127)
  484. c = '\b';
  485. if(i == 9)
  486. c = '\t';
  487. if(i == 10)
  488. c = '\n';
  489. if(c > 0 && c < '\200')
  490. keyArray[c] = 0;
  491. }
  492.  
  493. public final void keyTyped(KeyEvent keyevent)
  494. {
  495. }
  496.  
  497. final int readChar(int dummy)
  498. {
  499. while(dummy >= 0)
  500. {
  501. for(int j = 1; j > 0; j++);
  502. }
  503. int k = -1;
  504. if(writeIndex != readIndex)
  505. {
  506. k = charQueue[readIndex];
  507. readIndex = readIndex + 1 & 0x7f;
  508. }
  509. return k;
  510. }
  511.  
  512. public final void focusGained(FocusEvent focusevent)
  513. {
  514. awtFocus = true;
  515. shouldClearScreen = true;
  516. raiseWelcomeScreen();
  517. }
  518.  
  519. public final void focusLost(FocusEvent focusevent)
  520. {
  521. awtFocus = false;
  522. for(int i = 0; i < 128; i++)
  523. keyArray[i] = 0;
  524.  
  525. }
  526.  
  527. public final void windowActivated(WindowEvent windowevent)
  528. {
  529. }
  530.  
  531. public final void windowClosed(WindowEvent windowevent)
  532. {
  533. }
  534.  
  535. public final void windowClosing(WindowEvent windowevent)
  536. {
  537. destroy();
  538. }
  539.  
  540. public final void windowDeactivated(WindowEvent windowevent)
  541. {
  542. }
  543.  
  544. public final void windowDeiconified(WindowEvent windowevent)
  545. {
  546. }
  547.  
  548. public final void windowIconified(WindowEvent windowevent)
  549. {
  550. }
  551.  
  552. public final void windowOpened(WindowEvent windowevent)
  553. {
  554. }
  555.  
  556. void startUp()
  557. {
  558. }
  559.  
  560. void processGameLoop()
  561. {
  562. }
  563.  
  564. void cleanUpForQuit()
  565. {
  566. }
  567.  
  568. void processDrawing()
  569. {
  570. }
  571.  
  572. void raiseWelcomeScreen()
  573. {
  574. }
  575.  
  576. Component getGameComponent()
  577. {
  578. if(gameFrame != null)
  579. return gameFrame;
  580. else
  581. return this;
  582. }
  583.  
  584. public void startRunnable(Runnable runnable, int priority)
  585. {
  586. Thread thread = new Thread(runnable);
  587. thread.start();
  588. thread.setPriority(priority);
  589. }
  590.  
  591. void drawLoadingText(int i, String s)
  592. {
  593. while(graphics == null)
  594. {
  595. graphics = getGameComponent().getGraphics();
  596. try
  597. {
  598. getGameComponent().repaint();
  599. }
  600. catch(Exception _ex) { }
  601. try
  602. {
  603. Thread.sleep(1000L);
  604. }
  605. catch(Exception _ex) { }
  606. }
  607. Font font = new Font("Helvetica", 1, 13);
  608. FontMetrics fontmetrics = getGameComponent().getFontMetrics(font);
  609. Font font1 = new Font("Helvetica", 0, 13);
  610. getGameComponent().getFontMetrics(font1);
  611. if(shouldClearScreen)
  612. {
  613. graphics.setColor(Color.black);
  614. graphics.fillRect(0, 0, myWidth, myHeight);
  615. shouldClearScreen = false;
  616. }
  617. Color color = new Color(140, 17, 17);
  618. int j = myHeight / 2 - 18;
  619. graphics.setColor(color);
  620. graphics.drawRect(myWidth / 2 - 152, j, 304, 34);
  621. graphics.fillRect(myWidth / 2 - 150, j + 2, i * 3, 30);
  622. graphics.setColor(Color.black);
  623. graphics.fillRect((myWidth / 2 - 150) + i * 3, j + 2, 300 - i * 3, 30);
  624. graphics.setFont(font);
  625. graphics.setColor(Color.white);
  626. graphics.drawString(s, (myWidth - fontmetrics.stringWidth(s)) / 2, j + 22);
  627. }
  628.  
  629. RSApplet()
  630. {
  631. delayTime = 20;
  632. minDelay = 1;
  633. aLongArray7 = new long[10];
  634. shouldDebug = false;
  635. shouldClearScreen = true;
  636. awtFocus = true;
  637. keyArray = new int[128];
  638. charQueue = new int[128];
  639. }
  640.  
  641. private int anInt4;
  642. private int delayTime;
  643. int minDelay;
  644. private final long[] aLongArray7;
  645. int fps;
  646. boolean shouldDebug;
  647. int myWidth;
  648. int myHeight;
  649. Graphics graphics;
  650. RSImageProducer fullGameScreen;
  651. RSFrame gameFrame;
  652. private boolean shouldClearScreen;
  653. boolean awtFocus;
  654. int idleTime;
  655. int clickMode2;
  656. public int mouseX;
  657. public int mouseY;
  658. private int clickMode1;
  659. private int clickX;
  660. private int clickY;
  661. private long clickTime;
  662. int clickMode3;
  663. int saveClickX;
  664. int saveClickY;
  665. long aLong29;
  666. final int[] keyArray;
  667. private final int[] charQueue;
  668. private int readIndex;
  669. private int writeIndex;
  670. public static int anInt34;
  671. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement