renegadedialogmgr.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/commando/renegadedialogmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/19/02 2:00p $*
  29. * *
  30. * $Revision:: 51 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "renegadedialogmgr.h"
  36. #include "dialogmgr.h"
  37. #include "dialogbase.h"
  38. #include "dialogtests.h"
  39. #include "dialogresource.h"
  40. #include "dlgloadspgame.h"
  41. #include "dlgevaencyclopedia.h"
  42. #include "dlgmultiplayoptions.h"
  43. #include "dlgcharacteroptions.h"
  44. #include "dlgcheatoptions.h"
  45. #include "dlgtechoptions.h"
  46. #include "dlgmovieoptions.h"
  47. #include "dlgpreviewoptions.h"
  48. #include "dlgcredits.h"
  49. #include "inputctrl.h"
  50. #include "translatedb.h"
  51. #include "string_ids.h"
  52. #include "dlgmplanhostoptions.h"
  53. #include "dlginternetoptions.h"
  54. #include "gamemode.h"
  55. #include "dlgmplangamelist.h"
  56. #include "directinput.h"
  57. #include "input.h"
  58. #include "dlgmainmenu.h"
  59. #include "dlgwebpage.h"
  60. #include "dlgmpwolpagebuddy.h"
  61. #include "dlgmpwolbuddies.h"
  62. #include "dlgmpwolchat.h"
  63. #include "dlgmpwolgamelist.h"
  64. #include "dlgsavegame.h"
  65. #include "dlgcontrols.h"
  66. #include "dlgmpwolquickmatchoptions.h"
  67. #include "dlgmpwolmain.h"
  68. #include "dlgwolsettings.h"
  69. #include "dlghelpscreen.h"
  70. #include "dlgcncreference.h"
  71. #include "wwmemlog.h"
  72. #include "consolemode.h"
  73. #include "specialbuilds.h"
  74. ////////////////////////////////////////////////////////////////
  75. // Globals
  76. ////////////////////////////////////////////////////////////////
  77. WWUIInputClass * _TheWWUIInput = NULL;
  78. ////////////////////////////////////////////////////////////////
  79. // Static data
  80. ////////////////////////////////////////////////////////////////
  81. DialogFactoryBaseClass *FactoryArray[FACTORY_COUNT] =
  82. {
  83. new DialogFactoryClass<StartSPGameDialogClass>,
  84. NULL,
  85. NULL,
  86. new DialogFactoryClass<OptionsMenuClass>,
  87. new DialogFactoryClass<DifficultyMenuClass>,
  88. NULL, //IDC_MENU_START_TUTORIAL_BUTTON
  89. new DialogFactoryClass<LoadSPGameMenuClass>,
  90. NULL, //IDC_MENU_DIFFCULTY01_BUTTON
  91. NULL, //IDC_MENU_DIFFCULTY02_BUTTON
  92. NULL, //IDC_MENU_DIFFCULTY04_BUTTON
  93. NULL, //IDC_MENU_DIFFCULTY04_BUTTON
  94. new DialogFactoryClass<ControlsMenuClass>,
  95. new DialogFactoryClass<CharacterOptionsMenuClass>,
  96. new DialogFactoryClass<CheatOptionsMenuClass>,
  97. new DialogFactoryClass<TechOptionsMenuClass>,
  98. new DialogFactoryClass<MovieOptionsMenuClass>,
  99. new DialogFactoryClass<PreviewOptionsMenuClass>,
  100. new DialogFactoryClass<CreditsMenuClass>,
  101. new DialogFactoryClass<QuitVerificationDialogClass>,
  102. new DialogFactoryClass<EVAEncyclopediaMenuClass>,
  103. new DialogFactoryClass<MainMenuDialogClass>,
  104. new DialogFactoryClass<SaveGameMenuClass>,
  105. new DialogFactoryClass<MPLanMenuClass>,
  106. //new DialogFactoryClass<MPInternetMenuClass>,
  107. NULL,
  108. NULL,//new DialogFactoryClass<MPGameMenuClass>,
  109. new DialogFactoryClass<MPJoinMenuClass>,
  110. NULL,//new DialogFactoryClass<MPServerStartMenuClass>,
  111. new DialogFactoryClass<MultiplayOptionsMenuClass>,
  112. NULL,
  113. new DialogFactoryClass<MPWolMainMenuClass>,
  114. new DialogFactoryClass<MPLanGameListMenuClass>,
  115. NULL, //IDC_MENU_MP_LAN_JOIN_BUTTON
  116. NULL, //IDC_MENU_MP_LAN_START_BUTTON
  117. };
  118. ////////////////////////////////////////////////////////////////
  119. // Local Prototypes
  120. ////////////////////////////////////////////////////////////////
  121. bool CALLBACK Default_On_Command (DialogBaseClass *dialog, int ctrl_id, int mesage_id, DWORD param);
  122. void Stop_Main_Loop (int);
  123. ////////////////////////////////////////////////////////////////
  124. // RenegadeUIInputClass
  125. ////////////////////////////////////////////////////////////////
  126. class RenegadeUIInputClass : public WWUIInputClass
  127. {
  128. const Vector3 &
  129. Get_Mouse_Pos (void) const
  130. {
  131. DirectInput::Get_Cursor_Pos (&MousePos);
  132. return MousePos;
  133. }
  134. void
  135. Set_Mouse_Pos (const Vector3 &pos)
  136. {
  137. MousePos = pos;
  138. DirectInput::Reset_Cursor_Pos (Vector2 (pos.X, pos.Y));
  139. return ;
  140. }
  141. bool
  142. Is_Button_Down (int vk_mouse_button_id)
  143. {
  144. bool retval = false;
  145. switch (vk_mouse_button_id)
  146. {
  147. case VK_LBUTTON:
  148. retval = Input::Is_Button_Down (DirectInput::BUTTON_MOUSE_LEFT);
  149. break;
  150. case VK_MBUTTON:
  151. retval = Input::Is_Button_Down (DirectInput::BUTTON_MOUSE_CENTER);
  152. break;
  153. case VK_RBUTTON:
  154. retval = Input::Is_Button_Down (DirectInput::BUTTON_MOUSE_RIGHT);
  155. break;
  156. }
  157. return retval;
  158. }
  159. void
  160. Enter_Menu_Mode (void)
  161. {
  162. Input::Menu_Enable (true);
  163. return ;
  164. }
  165. void
  166. Exit_Menu_Mode (void)
  167. {
  168. Input::Menu_Enable (false);
  169. DirectInput::Eat_Mouse_Held_States ();
  170. return ;
  171. }
  172. private:
  173. mutable Vector3 MousePos;
  174. };
  175. ////////////////////////////////////////////////////////////////
  176. //
  177. // Initialize
  178. //
  179. ////////////////////////////////////////////////////////////////
  180. void
  181. RenegadeDialogMgrClass::Initialize (void)
  182. {
  183. WWMEMLOG(MEM_GAMEDATA);
  184. const char * STYLE_MGR_INI = "stylemgr.ini";
  185. _TheWWUIInput = new RenegadeUIInputClass;
  186. _TheWWUIInput->InitIME(MainWindow);
  187. //
  188. // Simple-pass thru to the WWUI dialog mgr system
  189. //
  190. if (!ConsoleBox.Is_Exclusive()) {
  191. DialogBaseClass::Set_Default_Command_Handler (Default_On_Command);
  192. DialogMgrClass::Initialize (STYLE_MGR_INI);
  193. }
  194. DialogMgrClass::Install_Input (_TheWWUIInput);
  195. return ;
  196. }
  197. ////////////////////////////////////////////////////////////////
  198. //
  199. // Do_Simple_Dialog
  200. //
  201. ////////////////////////////////////////////////////////////////
  202. void
  203. RenegadeDialogMgrClass::Do_Simple_Dialog (int dlg_res_id)
  204. {
  205. //
  206. // Show the dialog
  207. //
  208. PopupDialogClass *dialog = new PopupDialogClass (dlg_res_id);
  209. dialog->Start_Dialog ();
  210. REF_PTR_RELEASE (dialog);
  211. return ;
  212. }
  213. ////////////////////////////////////////////////////////////////
  214. //
  215. // Goto_Location
  216. //
  217. ////////////////////////////////////////////////////////////////
  218. void
  219. RenegadeDialogMgrClass::Goto_Location (LOCATION location)
  220. {
  221. WWMEMLOG(MEM_GAMEDATA);
  222. switch (location)
  223. {
  224. case LOC_MAIN_MENU:
  225. MainMenuDialogClass::Display ();
  226. break;
  227. case LOC_SPLASH_IN:
  228. START_DIALOG (SplashIntroMenuDialogClass);
  229. break;
  230. case LOC_SPLASH_OUT:
  231. START_DIALOG (SplashOutroMenuDialogClass);
  232. break;
  233. case LOC_INTERNET_MAIN:
  234. MPWolMainMenuClass::Display ();
  235. break;
  236. case LOC_INTERNET_GAME_LIST:
  237. MPWolGameListMenuClass::DoDialog ();
  238. break;
  239. case LOC_LAN_MAIN:
  240. MPLanGameListMenuClass::Display ();
  241. break;
  242. case LOC_ENCYCLOPEDIA:
  243. EVAEncyclopediaMenuClass::Display ();
  244. break;
  245. case LOC_OBJECTIVES:
  246. EVAEncyclopediaMenuClass::Display (EVAEncyclopediaMenuClass::TAB_OBJECTIVES);
  247. break;
  248. case LOC_MAP:
  249. EVAEncyclopediaMenuClass::Display (EVAEncyclopediaMenuClass::TAB_MAP);
  250. break;
  251. case LOC_CNC_REFERENCE:
  252. CnCReferenceMenuClass::Display ();
  253. break;
  254. case LOC_LOAD_GAME:
  255. LoadSPGameMenuClass::Display ();
  256. break;
  257. case LOC_IN_GAME_HELP:
  258. HelpScreenDialogClass::Display ();
  259. break;
  260. //GAMESPY
  261. case LOC_GAMESPY_MAIN:
  262. START_DIALOG (GameSpyMainDialogClass);
  263. break;
  264. }
  265. //
  266. // Activate the menu game mode (if necessary)
  267. //
  268. GameModeClass *menu_game_mode = GameModeManager::Find ("Menu");
  269. if (menu_game_mode != NULL && menu_game_mode->Is_Active () == false) {
  270. menu_game_mode->Activate ();
  271. }
  272. return ;
  273. }
  274. ////////////////////////////////////////////////////////////////
  275. //
  276. // Shutdown
  277. //
  278. ////////////////////////////////////////////////////////////////
  279. void
  280. RenegadeDialogMgrClass::Shutdown (void)
  281. {
  282. //
  283. // Simple-pass thru to the WWUI dialog mgr system
  284. //
  285. DialogMgrClass::Shutdown ();
  286. //
  287. // Release our hold on the input mechanism
  288. //
  289. REF_PTR_RELEASE (_TheWWUIInput);
  290. //
  291. // Free the factories so we don't get memory leaks when we quit. ST - 6/11/2001 8:23PM
  292. //
  293. for (int i=0 ; i<FACTORY_COUNT ; i++) {
  294. if (FactoryArray[i]) {
  295. delete FactoryArray[i];
  296. FactoryArray[i] = NULL;
  297. }
  298. }
  299. return ;
  300. }
  301. ////////////////////////////////////////////////////////////////
  302. //
  303. // Default_On_Command
  304. //
  305. ////////////////////////////////////////////////////////////////
  306. bool CALLBACK
  307. Default_On_Command (DialogBaseClass *dialog, int ctrl_id, int mesage_id, DWORD param)
  308. {
  309. bool handled = true;
  310. //
  311. // Is this one of our "auto-link" buttons?
  312. //
  313. if (ctrl_id >= DIALOG_LINK_FIRST && ctrl_id < DIALOG_LINK_LAST) {
  314. if (FactoryArray[ctrl_id - DIALOG_LINK_FIRST] != NULL) {
  315. //
  316. // Do the dialog associated with this command
  317. //
  318. FactoryArray[ctrl_id - DIALOG_LINK_FIRST]->Do_Dialog ();
  319. }
  320. }
  321. switch (ctrl_id)
  322. {
  323. case IDC_MENU_BACK_BUTTON:
  324. case IDC_BACK:
  325. case IDCANCEL:
  326. {
  327. dialog->End_Dialog ();
  328. break ;
  329. }
  330. case IDC_MP_SHORTCUT_NEWS:
  331. DlgWebPage::DoDialog("News");
  332. break;
  333. case IDC_MP_SHORTCUT_CLANS:
  334. DlgWebPage::DoDialog("BattleClans");
  335. break;
  336. case IDC_MP_SHORTCUT_RANKINGS:
  337. DlgWebPage::DoDialog("Ladder");
  338. break;
  339. case IDC_MP_SHORTCUT_ACCOUNT:
  340. DlgWOLSettings::DoDialog();
  341. break;
  342. #ifdef QUICKMATCH_OPTIONS
  343. case IDC_MP_SHORTCUT_QUICKMATCH_OPTIONS:
  344. START_DIALOG(MPWolQuickMatchOptionsMenuClass);
  345. break;
  346. #endif // QUICKMATCH_OPTIONS
  347. case IDC_MP_SHORTCUT_NET_STATUS:
  348. DlgWebPage::DoDialog("NetStatus");
  349. break;
  350. case IDC_MP_SHORTCUT_BUDDIES:
  351. MPWolBuddiesMenuClass::Display();
  352. break;
  353. case IDC_MP_SHORTCUT_PAGE_BUDDY:
  354. START_DIALOG (MPWolPageBuddyPopupClass);
  355. break;
  356. case IDC_MP_SHORTCUT_CHAT:
  357. MPWolChatMenuClass::DoDialog();
  358. break;
  359. case IDC_MP_SHORTCUT_GAMELIST:
  360. MPWolGameListMenuClass::DoDialog();
  361. break;
  362. case IDC_MP_SHORTCUT_INTERNET_OPTIONS:
  363. START_DIALOG (MultiplayOptionsMenuClass);
  364. break;
  365. case IDC_QUIT:
  366. #ifdef MULTIPLAYERDEMO
  367. DialogMgrClass::Flush_Dialogs ();
  368. START_DIALOG (SplashOutroMenuDialogClass);
  369. /*dialog->End_Dialog ();
  370. {
  371. MainMenuDialogClass *main_menu = MainMenuDialogClass::Get_Instance ();
  372. if (main_menu != NULL) {
  373. main_menu->End_Dialog ();
  374. }
  375. }*/
  376. #else
  377. Stop_Main_Loop (EXIT_SUCCESS);
  378. #endif //MULTIPLAYERDEMO
  379. break ;
  380. default:
  381. handled = false;
  382. break;
  383. }
  384. return handled;
  385. }
  386. //
  387. // Called as follows: If IDS_TEST is the string you wish to load and
  388. // WCHAR Buffer[128] is your buffer, the call would be
  389. // MyLoadStringW(IDS_TEST,Buffer,128);
  390. // If it succeeds, the function returns the number of characters copied
  391. // into the buffer, not including the NULL terminating character, or
  392. // zero if the string resource does not exist.
  393. //
  394. int MyLoadStringW (UINT str_id, LPWSTR buffer, int buffer_len)
  395. {
  396. //
  397. // Compute the block and offset
  398. //
  399. int block = (str_id >> 4) + 1;
  400. int num = str_id & 0xF;
  401. //
  402. // Find the resource
  403. //
  404. HRSRC resource = ::FindResourceEx (NULL, RT_STRING, MAKEINTRESOURCE (block),
  405. MAKELANGID (LANG_NEUTRAL, SUBLANG_NEUTRAL));
  406. //
  407. // Load the resource into memory
  408. //
  409. HGLOBAL hglobal = ::LoadResource (NULL, resource);
  410. LPWSTR res_string = (LPWSTR)::LockResource (hglobal);
  411. int length = 0;
  412. if (res_string != NULL) {
  413. for (int index = 0; index < num; index ++) {
  414. res_string += *res_string + 1;
  415. }
  416. //
  417. // Copy the string to our buffer
  418. //
  419. length = min ((int)(buffer_len - 1), (int)(*res_string));
  420. ::wcsncpy (buffer, res_string + 1, length);
  421. }
  422. //
  423. // Null terminate the buffer
  424. //
  425. buffer[length] = '\0';
  426. //
  427. // Return the number of bytes copied
  428. //
  429. return length;
  430. }