RenegadeSim.Java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //RenegadeSim.java
  19. import com.ms.wfc.app.*;
  20. import com.ms.wfc.core.*;
  21. import com.ms.wfc.ui.*;
  22. import java.util.*;
  23. /**
  24. * @author: Application Wizard
  25. * @version: 1.0
  26. * This class can take a variable number of parameters on the command
  27. * line. Program execution begins with the main() method. The class
  28. * constructor is not invoked unless an object of type 'RenegadeSim'
  29. * created in the main() method.
  30. */
  31. public class RenegadeSim extends Form implements RenegadeNetCaller
  32. {
  33. private Date _seed = new Date();
  34. private Random _rand = new Random(_seed.getSeconds());
  35. public void doNew(Object sender, Event e)
  36. {
  37. // New
  38. }
  39. private void saveAsMenu_click(Object sender, Event e)
  40. {
  41. // Save As
  42. }
  43. private void saveMenu_click(Object sender, Event e)
  44. {
  45. // Save
  46. }
  47. private void doOpen(Object sender, Event e)
  48. {
  49. // Open
  50. }
  51. public void wordWrapMenu_click(Object sender, Event e)
  52. {
  53. // WordWrap
  54. }
  55. public void doDateTime(Object sender, Event e)
  56. {
  57. // Date/Time
  58. }
  59. public void doPaste(Object sender, Event e)
  60. {
  61. // Paste
  62. try
  63. {
  64. }
  65. catch (Exception ecx)
  66. {
  67. }
  68. }
  69. public void doCopy(Object sender, Event e)
  70. {
  71. // Copy
  72. }
  73. public void doCut(Object sender, Event e)
  74. {
  75. // Cut
  76. }
  77. public void exitMenu_click(Object sender, Event e)
  78. {
  79. // Exit
  80. Application.exit();
  81. }
  82. private void aboutMenu_click(Object sender, Event e)
  83. {
  84. About myAbout = new About();
  85. myAbout.showDialog ();
  86. }
  87. private void toolBar_buttonClick(Object source, ToolBarButtonClickEvent e)
  88. {
  89. if (e.button == openToolBarButton) {
  90. // Open
  91. doOpen(source,e);
  92. }
  93. else if (e.button == saveToolBarButton) {
  94. // Save
  95. doSave(source,e);
  96. }
  97. else if (e.button == setupToolBarButton) {
  98. // Setup
  99. ClientSetup myClientSetup = new ClientSetup();
  100. myClientSetup.showDialog();
  101. }
  102. else {
  103. ; //nop
  104. }
  105. }
  106. public RenegadeSim()
  107. {
  108. super();
  109. //Required for Visual J++ Form Designer support
  110. initForm();
  111. //TODO: Add any constructor code after initForm call
  112. RenegadeNet.startWinSock();
  113. _refreshButtonStates();
  114. Application.addOnIdle(new EventHandler(this.RenegadeSim_Idle));
  115. }
  116. /**
  117. * RenegadeSim overrides dispose so it can clean up the
  118. * component list.
  119. */
  120. public void dispose()
  121. {
  122. super.dispose();
  123. components.dispose();
  124. RenegadeNet.stopWinSock();
  125. }
  126. private void RenegadeSim_Idle(Object sender, Event e)
  127. {
  128. // Set the statusBarStates
  129. /*StatusBarPanel sbPanel[] = statusBar.getPanels ();
  130. if ((GetKeyState(VK_CAPITAL) & 1) == 1)
  131. sbPanel[1].setText ("CAP");
  132. else
  133. sbPanel[1].setText ("");
  134. if ((GetKeyState(VK_NUMLOCK) & 1) == 1)
  135. sbPanel[2].setText ("NUM");
  136. else
  137. sbPanel[2].setText (""); */
  138. }
  139. private boolean doSave(Object sender, Event e)
  140. {
  141. boolean bRc = false;
  142. return bRc;
  143. }
  144. private void RenegadeSim_click(Object source, Event e)
  145. {
  146. }
  147. private void label1_click(Object source, Event e)
  148. {
  149. }
  150. private void butSimulate_click(Object source, Event e)
  151. {
  152. int[] indices = lbPlayers.getSelectedIndices();
  153. int i = 0;
  154. lbResults.removeAll();
  155. for(i = 0; i < lbPlayers.getItemCount(); i++)
  156. lbResults.addItem(new String("--"));
  157. for(i = 0; i < indices.length; i++)
  158. {
  159. // Simulate a score. We want a score x such that -0.5 <= x <= 0.5
  160. // and we want to weight it slightly more towards the positive side.
  161. double score = _rand.nextDouble() - 0.3;
  162. if( score > 0.5 ) score = 0.5;
  163. if( score < -0.5 ) score = -0.5;
  164. lbResults.setItem(indices[i], new String("" + (_rand.nextDouble() - 0.5)));
  165. }
  166. _refreshButtonStates();
  167. }
  168. private void butSelectToggle_click(Object source, Event e)
  169. {
  170. int[] indices = lbPlayers.getSelectedIndices();
  171. for(int i = 0; i < lbPlayers.getItemCount(); i++)
  172. lbPlayers.setSelected(i, (indices.length == 0));
  173. _refreshButtonStates();
  174. }
  175. private void _refreshButtonStates()
  176. {
  177. boolean valid = false;
  178. // Check for Send button
  179. for(int i = 0; i < lbResults.getItemCount(); i++)
  180. {
  181. String item = (String)lbResults.getItem(i);
  182. if( item.compareTo("--") != 0 )
  183. valid = true;
  184. }
  185. butSend.setEnabled(valid);
  186. // Check for simulate button
  187. int[] indices = lbPlayers.getSelectedIndices();
  188. butSimulate.setEnabled(indices.length > 0);
  189. }
  190. private void lbPlayers_selectedIndexChanged(Object source, Event e)
  191. {
  192. _refreshButtonStates();
  193. }
  194. private void butSend_click(Object source, Event e)
  195. {
  196. int[] indices = lbPlayers.getSelectedIndices();
  197. String logins[] = new String[indices.length];
  198. double scores[] = new double[indices.length];
  199. Double tmpDouble = null;
  200. for(int i = 0; i < indices.length; i++)
  201. {
  202. logins[i] = new String((String)lbPlayers.getItem(indices[i]));
  203. try
  204. {
  205. tmpDouble = new Double((String)lbResults.getItem(indices[i]));
  206. }
  207. catch( NumberFormatException exp )
  208. {
  209. /* TODO: Error dialog... */
  210. }
  211. scores[i] = tmpDouble.doubleValue();
  212. }
  213. _setStatusMessage("Connecting to games2.westwood.com:4608...");
  214. RenegadeNet net = new RenegadeNet(this);
  215. net.sendGameResults(logins, scores);
  216. }
  217. public void grDoneCallback(int packetlen)
  218. {
  219. if( packetlen <= 0 )
  220. _setStatusMessage("ERROR: " + packetlen + " (The server may be down)");
  221. else
  222. _setStatusMessage("Sent " + packetlen + " bytes to server successfully.");
  223. }
  224. private void _setStatusMessage(String s)
  225. {
  226. (statusBar.getPanels())[0].setText(s);
  227. }
  228. private void setupMenu_click(Object source, Event e)
  229. {
  230. ClientSetup myClientSetup = new ClientSetup();
  231. myClientSetup.showDialog();
  232. }
  233. /**
  234. * NOTE: The following code is required by the Visual J++ form
  235. * designer. It can be modified using the form editor. Do not
  236. * modify it using the code editor.
  237. */
  238. Container components = new Container();
  239. MainMenu mainMenu1 = new MainMenu();
  240. MenuItem fileMenu = new MenuItem();
  241. MenuItem openMenu = new MenuItem();
  242. MenuItem saveMenu = new MenuItem();
  243. MenuItem seperator3Menu = new MenuItem();
  244. MenuItem exitMenu = new MenuItem();
  245. Label label1 = new Label();
  246. MenuItem helpMenu = new MenuItem();
  247. MenuItem aboutMenu = new MenuItem();
  248. MenuItem saveAsMenu = new MenuItem();
  249. StatusBar statusBar = new StatusBar();
  250. StatusBarPanel mainStatusBarPanel = new StatusBarPanel();
  251. ListBox lbResults = new ListBox();
  252. ToolBar toolBar = new ToolBar();
  253. ToolBarButton openToolBarButton = new ToolBarButton();
  254. ToolBarButton saveToolBarButton = new ToolBarButton();
  255. ToolBarButton toolBarButton1 = new ToolBarButton();
  256. ImageList toolBarImageList = new ImageList();
  257. Label label2 = new Label();
  258. Button butSend = new Button();
  259. Button butSimulate = new Button();
  260. ListBox lbPlayers = new ListBox();
  261. GroupBox groupBox1 = new GroupBox();
  262. Button butSelectToggle = new Button();
  263. MenuItem setupMenu = new MenuItem();
  264. MenuItem menuItem1 = new MenuItem();
  265. ToolBarButton setupToolBarButton = new ToolBarButton();
  266. private void initForm()
  267. {
  268. // NOTE: This form is storing resource information in an
  269. // external file. Do not modify the string parameter to any
  270. // resources.getObject() function call. For example, do not
  271. // modify "foo1_location" in the following line of code
  272. // even if the name of the Foo object changes:
  273. // foo1.setLocation((Point)resources.getObject("foo1_location"));
  274. IResourceManager resources = new ResourceManager(this, "RenegadeSim");
  275. openMenu.setShortcut(Shortcut.CTRL_O);
  276. openMenu.setText("&Open Results...");
  277. openMenu.addOnClick(new EventHandler(this.doOpen));
  278. saveMenu.setShortcut(Shortcut.CTRL_S);
  279. saveMenu.setText("&Save Results...");
  280. saveMenu.addOnClick(new EventHandler(this.saveMenu_click));
  281. seperator3Menu.setText("-");
  282. exitMenu.setText("E&xit");
  283. exitMenu.addOnClick(new EventHandler(this.exitMenu_click));
  284. label1.setLocation(new Point(16, 16));
  285. label1.setSize(new Point(72, 16));
  286. label1.setTabIndex(2);
  287. label1.setTabStop(false);
  288. label1.setText("Players:");
  289. label1.addOnClick(new EventHandler(this.label1_click));
  290. aboutMenu.setText("&About...");
  291. aboutMenu.addOnClick(new EventHandler(this.aboutMenu_click));
  292. helpMenu.setMenuItems(new MenuItem[] {
  293. aboutMenu});
  294. helpMenu.setText("&Help");
  295. saveAsMenu.setText("Save &As...");
  296. saveAsMenu.addOnClick(new EventHandler(this.saveAsMenu_click));
  297. mainStatusBarPanel.setAutoSize(StatusBarPanelAutoSize.SPRING);
  298. mainStatusBarPanel.setWidth(256);
  299. statusBar.setBackColor(Color.CONTROL);
  300. statusBar.setLocation(new Point(0, 289));
  301. statusBar.setSize(new Point(272, 20));
  302. statusBar.setTabIndex(1);
  303. statusBar.setText("");
  304. statusBar.setShowPanels(true);
  305. statusBar.setPanels(new StatusBarPanel[] {
  306. mainStatusBarPanel});
  307. lbResults.setLocation(new Point(120, 32));
  308. lbResults.setSize(new Point(128, 147));
  309. lbResults.setTabIndex(1);
  310. lbResults.setText("listBox1");
  311. lbResults.setUseTabStops(true);
  312. lbResults.setItems(new Object[] {
  313. "--",
  314. "--",
  315. "--",
  316. "--",
  317. "--",
  318. "--",
  319. "--",
  320. "--",
  321. "--",
  322. "--"});
  323. openToolBarButton.setImageIndex(1);
  324. openToolBarButton.setToolTipText("Open Results");
  325. saveToolBarButton.setImageIndex(2);
  326. saveToolBarButton.setToolTipText("Save Results");
  327. toolBarButton1.setStyle(ToolBarButtonStyle.SEPARATOR);
  328. toolBarButton1.setText("toolBarButton4");
  329. toolBarImageList.setImageSize(new Point(16, 15));
  330. toolBarImageList.setImageStream((ImageListStreamer)resources.getObject("toolBarImageList_imageStream"));
  331. /* @designTimeOnly toolBarImageList.setLocation(new Point(176, 8)); */
  332. label2.setLocation(new Point(120, 16));
  333. label2.setSize(new Point(48, 16));
  334. label2.setTabIndex(3);
  335. label2.setTabStop(false);
  336. label2.setText("Results:");
  337. butSend.setLocation(new Point(184, 256));
  338. butSend.setSize(new Point(80, 23));
  339. butSend.setTabIndex(3);
  340. butSend.setText("Send Results");
  341. butSend.addOnClick(new EventHandler(this.butSend_click));
  342. butSimulate.setLocation(new Point(128, 216));
  343. butSimulate.setSize(new Point(128, 16));
  344. butSimulate.setTabIndex(2);
  345. butSimulate.setText("Simulate Game Results");
  346. butSimulate.addOnClick(new EventHandler(this.butSimulate_click));
  347. lbPlayers.setLocation(new Point(16, 32));
  348. lbPlayers.setSize(new Point(88, 147));
  349. lbPlayers.setTabIndex(0);
  350. lbPlayers.setText("listBox1");
  351. lbPlayers.setSelectionMode(SelectionMode.MULTI_SIMPLE);
  352. lbPlayers.setUseTabStops(true);
  353. lbPlayers.setItems(new Object[] {
  354. "test1",
  355. "test5",
  356. "test7",
  357. "test8",
  358. "test9",
  359. "test13",
  360. "test14",
  361. "test16",
  362. "noxstinky",
  363. "goodmach"});
  364. lbPlayers.addOnSelectedIndexChanged(new EventHandler(this.lbPlayers_selectedIndexChanged));
  365. groupBox1.setLocation(new Point(8, 32));
  366. groupBox1.setSize(new Point(256, 216));
  367. groupBox1.setTabIndex(6);
  368. groupBox1.setTabStop(false);
  369. groupBox1.setText("Renegade Game Simulator");
  370. butSelectToggle.setLocation(new Point(16, 184));
  371. butSelectToggle.setSize(new Point(88, 16));
  372. butSelectToggle.setTabIndex(4);
  373. butSelectToggle.setText("Select All / None");
  374. butSelectToggle.addOnClick(new EventHandler(this.butSelectToggle_click));
  375. setupMenu.setText("&Client Setup");
  376. setupMenu.addOnClick(new EventHandler(this.setupMenu_click));
  377. menuItem1.setText("-");
  378. fileMenu.setMenuItems(new MenuItem[] {
  379. openMenu,
  380. saveMenu,
  381. saveAsMenu,
  382. seperator3Menu,
  383. setupMenu,
  384. menuItem1,
  385. exitMenu});
  386. fileMenu.setText("&File");
  387. mainMenu1.setMenuItems(new MenuItem[] {
  388. fileMenu,
  389. helpMenu});
  390. /* @designTimeOnly mainMenu1.setLocation(new Point(80, 8)); */
  391. this.setAnchor(ControlAnchor.ALL);
  392. this.setLocation(new Point(298, 88));
  393. this.setText("Renegade Simulator Applet");
  394. this.setAutoScaleBaseSize(new Point(5, 13));
  395. this.setBorderStyle(FormBorderStyle.FIXED_TOOLWINDOW);
  396. this.setClientSize(new Point(272, 309));
  397. this.setMaximizeBox(false);
  398. this.setMenu(mainMenu1);
  399. this.addOnClick(new EventHandler(this.RenegadeSim_click));
  400. setupToolBarButton.setImageIndex(4);
  401. setupToolBarButton.setToolTipText("Client Setup");
  402. toolBar.setSize(new Point(272, 25));
  403. toolBar.setTabIndex(0);
  404. toolBar.setButtons(new ToolBarButton[] {
  405. openToolBarButton,
  406. saveToolBarButton,
  407. toolBarButton1,
  408. setupToolBarButton});
  409. toolBar.setDropDownArrows(true);
  410. toolBar.setImageList(toolBarImageList);
  411. toolBar.setShowToolTips(true);
  412. toolBar.addOnButtonClick(new ToolBarButtonClickEventHandler(this.toolBar_buttonClick));
  413. this.setNewControls(new Control[] {
  414. butSimulate,
  415. butSend,
  416. groupBox1,
  417. toolBar,
  418. statusBar});
  419. groupBox1.setNewControls(new Control[] {
  420. butSelectToggle,
  421. label2,
  422. label1,
  423. lbResults,
  424. lbPlayers});
  425. }
  426. /**
  427. * The main entry point for the application.
  428. *
  429. * @param args Array of parameters passed to the application
  430. * via the command line.
  431. */
  432. public static void main(String args[])
  433. {
  434. Application.run(new RenegadeSim());
  435. }
  436. public static final int VK_CAPITAL = 0x14;
  437. public static final int VK_NUMLOCK = 0x90;
  438. /**
  439. * @dll.import("USER32",auto)
  440. */
  441. public static native short GetKeyState(int nVirtKey);
  442. }