PopupJoinGame.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. ** Command & Conquer Generals(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: PopupJoinGame.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Jul 2002
  34. //
  35. // Filename: PopupJoinGame.cpp
  36. //
  37. // author: Matthew D. Campbell
  38. //
  39. // purpose: Contains the Callbacks for the Join Game Popup
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  50. #include "Common/GlobalData.h"
  51. #include "Common/NameKeyGenerator.h"
  52. #include "GameClient/WindowLayout.h"
  53. #include "GameClient/Gadget.h"
  54. #include "GameClient/KeyDefs.h"
  55. #include "GameClient/GadgetTextEntry.h"
  56. #include "GameClient/GadgetStaticText.h"
  57. #include "GameNetwork/GameSpy/Peerdefs.h"
  58. #include "GameNetwork/GameSpy/PeerThread.h"
  59. #include "GameNetwork/GameSpyOverlay.h"
  60. //-----------------------------------------------------------------------------
  61. // DEFINES ////////////////////////////////////////////////////////////////////
  62. //-----------------------------------------------------------------------------
  63. static NameKeyType parentPopupID = NAMEKEY_INVALID;
  64. static NameKeyType textEntryGamePasswordID = NAMEKEY_INVALID;
  65. static NameKeyType buttonCancelID = NAMEKEY_INVALID;
  66. static GameWindow *parentPopup = NULL;
  67. static GameWindow *textEntryGamePassword = NULL;
  68. static void joinGame( AsciiString password );
  69. //-----------------------------------------------------------------------------
  70. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  71. //-----------------------------------------------------------------------------
  72. //-------------------------------------------------------------------------------------------------
  73. /** Initialize the PopupHostGameInit menu */
  74. //-------------------------------------------------------------------------------------------------
  75. void PopupJoinGameInit( WindowLayout *layout, void *userData )
  76. {
  77. parentPopupID = TheNameKeyGenerator->nameToKey(AsciiString("PopupJoinGame.wnd:ParentJoinPopUp"));
  78. parentPopup = TheWindowManager->winGetWindowFromId(NULL, parentPopupID);
  79. textEntryGamePasswordID = TheNameKeyGenerator->nameToKey(AsciiString("PopupJoinGame.wnd:TextEntryGamePassword"));
  80. textEntryGamePassword = TheWindowManager->winGetWindowFromId(parentPopup, textEntryGamePasswordID);
  81. GadgetTextEntrySetText(textEntryGamePassword, UnicodeString::TheEmptyString);
  82. NameKeyType staticTextGameNameID = TheNameKeyGenerator->nameToKey(AsciiString("PopupJoinGame.wnd:StaticTextGameName"));
  83. GameWindow *staticTextGameName = TheWindowManager->winGetWindowFromId(parentPopup, staticTextGameNameID);
  84. GadgetStaticTextSetText(staticTextGameName, UnicodeString::TheEmptyString);
  85. buttonCancelID = NAMEKEY("PopupJoinGame.wnd:ButtonCancel");
  86. GameSpyStagingRoom *ourRoom = TheGameSpyInfo->findStagingRoomByID(TheGameSpyInfo->getCurrentStagingRoomID());
  87. if (ourRoom)
  88. GadgetStaticTextSetText(staticTextGameName, ourRoom->getGameName());
  89. TheWindowManager->winSetFocus( parentPopup );
  90. TheWindowManager->winSetModal( parentPopup );
  91. }
  92. //-------------------------------------------------------------------------------------------------
  93. /** PopupHostGameInput callback */
  94. //-------------------------------------------------------------------------------------------------
  95. WindowMsgHandledType PopupJoinGameInput( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  96. {
  97. switch( msg )
  98. {
  99. // --------------------------------------------------------------------------------------------
  100. case GWM_CHAR:
  101. {
  102. UnsignedByte key = mData1;
  103. UnsignedByte state = mData2;
  104. // if (buttonPushed)
  105. // break;
  106. switch( key )
  107. {
  108. // ----------------------------------------------------------------------------------------
  109. case KEY_ESC:
  110. {
  111. //
  112. // send a simulated selected event to the parent window of the
  113. // back/exit button
  114. //
  115. if( BitTest( state, KEY_STATE_UP ) )
  116. {
  117. GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
  118. SetLobbyAttemptHostJoin( FALSE );
  119. parentPopup = NULL;
  120. } // end if
  121. // don't let key fall through anywhere else
  122. return MSG_HANDLED;
  123. } // end escape
  124. } // end switch( key )
  125. } // end char
  126. } // end switch( msg )
  127. return MSG_IGNORED;
  128. }
  129. //-------------------------------------------------------------------------------------------------
  130. /** PopupHostGameSystem callback */
  131. //-------------------------------------------------------------------------------------------------
  132. WindowMsgHandledType PopupJoinGameSystem( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  133. {
  134. switch( msg )
  135. {
  136. // --------------------------------------------------------------------------------------------
  137. case GWM_CREATE:
  138. {
  139. break;
  140. } // end create
  141. //---------------------------------------------------------------------------------------------
  142. case GWM_DESTROY:
  143. {
  144. break;
  145. } // end case
  146. //---------------------------------------------------------------------------------------------
  147. case GBM_SELECTED:
  148. {
  149. GameWindow *control = (GameWindow *)mData1;
  150. Int controlID = control->winGetWindowId();
  151. if (controlID == buttonCancelID)
  152. {
  153. GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
  154. SetLobbyAttemptHostJoin( FALSE );
  155. parentPopup = NULL;
  156. }
  157. break;
  158. }
  159. //----------------------------------------------------------------------------------------------
  160. case GWM_INPUT_FOCUS:
  161. {
  162. // if we're givin the opportunity to take the keyboard focus we must say we want it
  163. if( mData1 == TRUE )
  164. *(Bool *)mData2 = TRUE;
  165. break;
  166. } // end input
  167. //---------------------------------------------------------------------------------------------
  168. case GEM_EDIT_DONE:
  169. {
  170. GameWindow *control = (GameWindow *)mData1;
  171. Int controlID = control->winGetWindowId();
  172. if( controlID == textEntryGamePasswordID )
  173. {
  174. // read the user's input and clear the entry box
  175. UnicodeString txtInput;
  176. txtInput.set(GadgetTextEntryGetText( textEntryGamePassword ));
  177. GadgetTextEntrySetText(textEntryGamePassword, UnicodeString::TheEmptyString);
  178. txtInput.trim();
  179. if (!txtInput.isEmpty())
  180. {
  181. AsciiString munkee;
  182. munkee.translate(txtInput);
  183. joinGame(munkee);
  184. }
  185. }
  186. break;
  187. }
  188. default:
  189. return MSG_IGNORED;
  190. } // end switch
  191. return MSG_HANDLED;
  192. }
  193. //-----------------------------------------------------------------------------
  194. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  195. //-----------------------------------------------------------------------------
  196. static void joinGame( AsciiString password )
  197. {
  198. GameSpyStagingRoom *ourRoom = TheGameSpyInfo->findStagingRoomByID(TheGameSpyInfo->getCurrentStagingRoomID());
  199. if (!ourRoom)
  200. {
  201. GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
  202. SetLobbyAttemptHostJoin( FALSE );
  203. parentPopup = NULL;
  204. return;
  205. }
  206. PeerRequest req;
  207. req.peerRequestType = PeerRequest::PEERREQUEST_JOINSTAGINGROOM;
  208. req.text = ourRoom->getGameName().str();
  209. req.stagingRoom.id = ourRoom->getID();
  210. req.password = password.str();
  211. TheGameSpyPeerMessageQueue->addRequest(req);
  212. DEBUG_LOG(("Attempting to join game %d(%ls) with password [%s]\n", ourRoom->getID(), ourRoom->getGameName().str(), password.str()));
  213. GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
  214. parentPopup = NULL;
  215. }