GameSpyOverlay.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: wolscreens.cpp //////////////////////////////////////////////////////
  24. // Westwood Online screen setup/teardown
  25. // Author: Matthew D. Campbell, November 2001
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. #include "Common/AudioEventRTS.h"
  28. #include "GameClient/GadgetListBox.h"
  29. #include "GameClient/GameText.h"
  30. #include "GameClient/MessageBox.h"
  31. #include "GameClient/ShellHooks.h"
  32. //#include "GameNetwork/GameSpy.h"
  33. //#include "GameNetwork/GameSpyGP.h"
  34. #include "GameNetwork/GameSpyOverlay.h"
  35. //#include "GameNetwork/GameSpy/PeerDefs.h"
  36. #include "GameNetwork/GameSpy/BuddyThread.h"
  37. void deleteNotificationBox( void );
  38. static void raiseOverlays( void );
  39. // Message boxes -------------------------------------
  40. static GameWindow *messageBoxWindow = NULL;
  41. static GameWinMsgBoxFunc okFunc = NULL;
  42. static GameWinMsgBoxFunc cancelFunc = NULL;
  43. static Bool reOpenPlayerInfoFlag = FALSE;
  44. /**
  45. * messageBoxOK is called when a message box is destroyed
  46. * by way of an OK button, so we can clear our pointers to it.
  47. */
  48. static void messageBoxOK( void )
  49. {
  50. DEBUG_ASSERTCRASH(messageBoxWindow, ("Message box window went away without being there in the first place!"));
  51. messageBoxWindow = NULL;
  52. if (okFunc)
  53. {
  54. okFunc();
  55. okFunc = NULL;
  56. }
  57. }
  58. /**
  59. * messageBoxCancel is called when a message box is destroyed
  60. * by way of a Cancel button, so we can clear our pointers to it.
  61. */
  62. static void messageBoxCancel( void )
  63. {
  64. DEBUG_ASSERTCRASH(messageBoxWindow, ("Message box window went away without being there in the first place!"));
  65. messageBoxWindow = NULL;
  66. if (cancelFunc)
  67. {
  68. cancelFunc();
  69. cancelFunc = NULL;
  70. }
  71. }
  72. /**
  73. * clearGSMessageBoxes removes the current message box if
  74. * one is present. This is usually done when putting up a
  75. * second messageBox.
  76. */
  77. void ClearGSMessageBoxes( void )
  78. {
  79. if (messageBoxWindow)
  80. {
  81. TheWindowManager->winDestroy(messageBoxWindow);
  82. messageBoxWindow = NULL;
  83. }
  84. if (okFunc)
  85. {
  86. okFunc = NULL;
  87. }
  88. if (cancelFunc)
  89. {
  90. cancelFunc = NULL;
  91. }
  92. }
  93. /**
  94. * GSMessageBoxOk puts up an OK dialog box and saves the
  95. * pointers to it and its callbacks.
  96. */
  97. void GSMessageBoxOk(UnicodeString title, UnicodeString message, GameWinMsgBoxFunc newOkFunc)
  98. {
  99. ClearGSMessageBoxes();
  100. messageBoxWindow = MessageBoxOk(title, message, messageBoxOK);
  101. okFunc = newOkFunc;
  102. }
  103. /**
  104. * GSMessageBoxOkCancel puts up an OK/Cancel dialog box and saves the
  105. * pointers to it and its callbacks.
  106. */
  107. void GSMessageBoxOkCancel(UnicodeString title, UnicodeString message, GameWinMsgBoxFunc newOkFunc, GameWinMsgBoxFunc newCancelFunc)
  108. {
  109. ClearGSMessageBoxes();
  110. messageBoxWindow = MessageBoxOkCancel(title, message, messageBoxOK, messageBoxCancel);
  111. okFunc = newOkFunc;
  112. cancelFunc = newCancelFunc;
  113. }
  114. /**
  115. * GSMessageBoxYesNo puts up a Yes/No dialog box and saves the
  116. * pointers to it and its callbacks.
  117. */
  118. void GSMessageBoxYesNo(UnicodeString title, UnicodeString message, GameWinMsgBoxFunc newYesFunc, GameWinMsgBoxFunc newNoFunc)
  119. {
  120. ClearGSMessageBoxes();
  121. messageBoxWindow = MessageBoxYesNo(title, message, messageBoxOK, messageBoxCancel);
  122. okFunc = newYesFunc;
  123. cancelFunc = newNoFunc;
  124. }
  125. /**
  126. * If the screen transitions underneath the dialog box, we
  127. * need to raise it to keep it visible.
  128. */
  129. void RaiseGSMessageBox( void )
  130. {
  131. raiseOverlays();
  132. if (!messageBoxWindow)
  133. return;
  134. messageBoxWindow->winBringToTop();
  135. }
  136. // Overlay screens -------------------------------------
  137. /**
  138. * gsOverlays holds a list of the .wnd files used in GS overlays.
  139. * The entries *MUST* be in the same order as the GSOverlayType enum.
  140. */
  141. static const char * gsOverlays[GSOVERLAY_MAX] =
  142. {
  143. "Menus/PopupPlayerInfo.wnd", // Player info (right-click)
  144. "Menus/WOLMapSelectMenu.wnd", // Map select
  145. "Menus/WOLBuddyOverlay.wnd", // Buddy list
  146. "Menus/WOLPageOverlay.wnd", // Find/page
  147. "Menus/PopupHostGame.wnd", // Hosting options (game name, password, etc)
  148. "Menus/PopupJoinGame.wnd", // Joining options (password, etc)
  149. "Menus/PopupLadderSelect.wnd",// LadderSelect
  150. "Menus/PopupLocaleSelect.wnd",// Prompt for user's locale
  151. "Menus/OptionsMenu.wnd", // popup options
  152. };
  153. static WindowLayout *overlayLayouts[GSOVERLAY_MAX] =
  154. {
  155. NULL,
  156. NULL,
  157. NULL,
  158. NULL,
  159. NULL,
  160. NULL,
  161. NULL,
  162. NULL,
  163. NULL,
  164. };
  165. static void buddyTryReconnect( void )
  166. {
  167. BuddyRequest req;
  168. req.buddyRequestType = BuddyRequest::BUDDYREQUEST_RELOGIN;
  169. TheGameSpyBuddyMessageQueue->addRequest( req );
  170. }
  171. void GameSpyOpenOverlay( GSOverlayType overlay )
  172. {
  173. if (overlay == GSOVERLAY_BUDDY)
  174. {
  175. if (!TheGameSpyBuddyMessageQueue->isConnected())
  176. {
  177. // not connected - is it because we were disconnected?
  178. if (TheGameSpyBuddyMessageQueue->getLocalProfileID())
  179. {
  180. // used to be connected
  181. GSMessageBoxYesNo(TheGameText->fetch("GUI:GPErrorTitle"), TheGameText->fetch("GUI:GPDisconnected"), buddyTryReconnect, NULL);
  182. }
  183. else
  184. {
  185. // no profile
  186. GSMessageBoxOk(TheGameText->fetch("GUI:GPErrorTitle"), TheGameText->fetch("GUI:GPNoProfile"), NULL);
  187. }
  188. return;
  189. }
  190. AudioEventRTS buttonClick("GUICommunicatorOpen");
  191. if( TheAudio )
  192. {
  193. TheAudio->addAudioEvent( &buttonClick );
  194. } // end if
  195. }
  196. if (overlayLayouts[overlay])
  197. {
  198. overlayLayouts[overlay]->hide( FALSE );
  199. overlayLayouts[overlay]->bringForward();
  200. }
  201. else
  202. {
  203. overlayLayouts[overlay] = TheWindowManager->winCreateLayout( AsciiString( gsOverlays[overlay] ) );
  204. overlayLayouts[overlay]->runInit();
  205. overlayLayouts[overlay]->hide( FALSE );
  206. overlayLayouts[overlay]->bringForward();
  207. }
  208. }
  209. void GameSpyCloseOverlay( GSOverlayType overlay )
  210. {
  211. switch(overlay)
  212. {
  213. case GSOVERLAY_PLAYERINFO:
  214. DEBUG_LOG(("Closing overlay GSOVERLAY_PLAYERINFO\n"));
  215. break;
  216. case GSOVERLAY_MAPSELECT:
  217. DEBUG_LOG(("Closing overlay GSOVERLAY_MAPSELECT\n"));
  218. break;
  219. case GSOVERLAY_BUDDY:
  220. DEBUG_LOG(("Closing overlay GSOVERLAY_BUDDY\n"));
  221. break;
  222. case GSOVERLAY_PAGE:
  223. DEBUG_LOG(("Closing overlay GSOVERLAY_PAGE\n"));
  224. break;
  225. case GSOVERLAY_GAMEOPTIONS:
  226. DEBUG_LOG(("Closing overlay GSOVERLAY_GAMEOPTIONS\n"));
  227. break;
  228. case GSOVERLAY_GAMEPASSWORD:
  229. DEBUG_LOG(("Closing overlay GSOVERLAY_GAMEPASSWORD\n"));
  230. break;
  231. case GSOVERLAY_LADDERSELECT:
  232. DEBUG_LOG(("Closing overlay GSOVERLAY_LADDERSELECT\n"));
  233. break;
  234. case GSOVERLAY_OPTIONS:
  235. DEBUG_LOG(("Closing overlay GSOVERLAY_OPTIONS\n"));
  236. if( overlayLayouts[overlay] )
  237. {
  238. SignalUIInteraction(SHELL_SCRIPT_HOOK_OPTIONS_CLOSED);
  239. }
  240. break;
  241. }
  242. if( overlayLayouts[overlay] )
  243. {
  244. overlayLayouts[overlay]->runShutdown();
  245. overlayLayouts[overlay]->destroyWindows();
  246. overlayLayouts[overlay]->deleteInstance();
  247. overlayLayouts[overlay] = NULL;
  248. }
  249. }
  250. Bool GameSpyIsOverlayOpen( GSOverlayType overlay )
  251. {
  252. return (overlayLayouts[overlay] != NULL);
  253. }
  254. void GameSpyToggleOverlay( GSOverlayType overlay )
  255. {
  256. if (GameSpyIsOverlayOpen(overlay))
  257. GameSpyCloseOverlay(overlay);
  258. else
  259. GameSpyOpenOverlay(overlay);
  260. }
  261. void raiseOverlays( void )
  262. {
  263. for (int i=0; i<GSOVERLAY_MAX; ++i)
  264. {
  265. if (overlayLayouts[(GSOverlayType)i])
  266. {
  267. overlayLayouts[(GSOverlayType)i]->bringForward();
  268. }
  269. }
  270. }
  271. void GameSpyCloseAllOverlays( void )
  272. {
  273. for (int i=0; i<GSOVERLAY_MAX; ++i)
  274. {
  275. GameSpyCloseOverlay((GSOverlayType)i);
  276. }
  277. // if we're shutting down the rest, chances are we don't want this popping up.
  278. deleteNotificationBox();
  279. }
  280. void GameSpyUpdateOverlays( void )
  281. {
  282. for (int i=0; i<GSOVERLAY_MAX; ++i)
  283. {
  284. if (overlayLayouts[(GSOverlayType)i])
  285. {
  286. overlayLayouts[(GSOverlayType)i]->runUpdate();
  287. }
  288. }
  289. }
  290. void ReOpenPlayerInfo( void )
  291. {
  292. reOpenPlayerInfoFlag = TRUE;
  293. }
  294. void CheckReOpenPlayerInfo(void )
  295. {
  296. if(!reOpenPlayerInfoFlag)
  297. return;
  298. GameSpyOpenOverlay(GSOVERLAY_PLAYERINFO);
  299. reOpenPlayerInfoFlag = FALSE;
  300. }