DisconnectWindow.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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: DisconnectControls.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author: Bryan Cleveland - March 2001
  25. // Desc: GUI menu for network disconnects
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "GameClient/GameWindow.h"
  30. #include "GameClient/GameText.h"
  31. #include "GameClient/Gadget.h"
  32. #include "GameClient/GadgetTextEntry.h"
  33. #include "GameClient/GadgetListBox.h"
  34. #include "GameClient/GameClient.h"
  35. #include "GameClient/DisconnectMenu.h"
  36. #include "GameClient/GameWindowManager.h"
  37. #include "Common/NameKeyGenerator.h"
  38. #include "GameNetwork/GameInfo.h"
  39. // Private Data -----------------------------
  40. static WindowLayout *disconnectMenuLayout;
  41. static NameKeyType textEntryID = NAMEKEY_INVALID;
  42. static NameKeyType textDisplayID = NAMEKEY_INVALID;
  43. static GameWindow *textEntryWindow = NULL;
  44. static GameWindow *textDisplayWindow = NULL;
  45. static NameKeyType buttonQuitID = NAMEKEY_INVALID;
  46. static GameWindow *buttonQuitWindow = NULL;
  47. static NameKeyType buttonVotePlayer1ID = NAMEKEY_INVALID;
  48. static NameKeyType buttonVotePlayer2ID = NAMEKEY_INVALID;
  49. static NameKeyType buttonVotePlayer3ID = NAMEKEY_INVALID;
  50. static NameKeyType buttonVotePlayer4ID = NAMEKEY_INVALID;
  51. static NameKeyType buttonVotePlayer5ID = NAMEKEY_INVALID;
  52. static NameKeyType buttonVotePlayer6ID = NAMEKEY_INVALID;
  53. static NameKeyType buttonVotePlayer7ID = NAMEKEY_INVALID;
  54. static GameWindow *buttonVotePlayer1Window = NULL;
  55. static GameWindow *buttonVotePlayer2Window = NULL;
  56. static GameWindow *buttonVotePlayer3Window = NULL;
  57. static GameWindow *buttonVotePlayer4Window = NULL;
  58. static GameWindow *buttonVotePlayer5Window = NULL;
  59. static GameWindow *buttonVotePlayer6Window = NULL;
  60. static GameWindow *buttonVotePlayer7Window = NULL;
  61. static void InitDisconnectWindow( void ) {
  62. textEntryID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:TextEntry"));
  63. textDisplayID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ListboxTextDisplay"));
  64. textEntryWindow = TheWindowManager->winGetWindowFromId(NULL, textEntryID);
  65. textDisplayWindow = TheWindowManager->winGetWindowFromId(NULL, textDisplayID);
  66. if (textEntryWindow != NULL) {
  67. GadgetTextEntrySetText(textEntryWindow, UnicodeString::TheEmptyString);
  68. TheWindowManager->winSetFocus(textEntryWindow);
  69. }
  70. buttonQuitID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonQuitGame"));
  71. buttonQuitWindow = TheWindowManager->winGetWindowFromId(NULL, buttonQuitID);
  72. buttonVotePlayer1ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer1"));
  73. buttonVotePlayer2ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer2"));
  74. buttonVotePlayer3ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer3"));
  75. buttonVotePlayer4ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer4"));
  76. buttonVotePlayer5ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer5"));
  77. buttonVotePlayer6ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer6"));
  78. buttonVotePlayer7ID = TheNameKeyGenerator->nameToKey( AsciiString("DisconnectScreen.wnd:ButtonKickPlayer7"));
  79. buttonVotePlayer1Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer1ID);
  80. buttonVotePlayer2Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer2ID);
  81. buttonVotePlayer3Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer3ID);
  82. buttonVotePlayer4Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer4ID);
  83. buttonVotePlayer5Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer5ID);
  84. buttonVotePlayer6Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer6ID);
  85. buttonVotePlayer7Window = TheWindowManager->winGetWindowFromId(NULL, buttonVotePlayer7ID);
  86. }
  87. //------------------------------------------------------
  88. /** Show the Disconnect Screen */
  89. //------------------------------------------------------
  90. void ShowDisconnectWindow( void )
  91. {
  92. // load the quit menu from the layout file if needed
  93. if( disconnectMenuLayout == NULL )
  94. {
  95. // load layout from disk
  96. disconnectMenuLayout = TheWindowManager->winCreateLayout( "Menus/DisconnectScreen.wnd" );
  97. // init it
  98. InitDisconnectWindow();
  99. // show it
  100. disconnectMenuLayout->hide( FALSE );
  101. } // end if
  102. else
  103. {
  104. disconnectMenuLayout->hide( FALSE );
  105. } // end else
  106. // Disallow voting for 2-player games. Cheating punk.
  107. if ( TheGameInfo && TheGameInfo->getNumPlayers() < 3 )
  108. {
  109. buttonVotePlayer1Window->winEnable(FALSE);
  110. buttonVotePlayer2Window->winEnable(FALSE);
  111. buttonVotePlayer3Window->winEnable(FALSE);
  112. buttonVotePlayer4Window->winEnable(FALSE);
  113. buttonVotePlayer5Window->winEnable(FALSE);
  114. buttonVotePlayer6Window->winEnable(FALSE);
  115. buttonVotePlayer7Window->winEnable(FALSE);
  116. }
  117. else
  118. {
  119. buttonVotePlayer1Window->winEnable(TRUE);
  120. buttonVotePlayer2Window->winEnable(TRUE);
  121. buttonVotePlayer3Window->winEnable(TRUE);
  122. buttonVotePlayer4Window->winEnable(TRUE);
  123. buttonVotePlayer5Window->winEnable(TRUE);
  124. buttonVotePlayer6Window->winEnable(TRUE);
  125. buttonVotePlayer7Window->winEnable(TRUE);
  126. }
  127. buttonQuitWindow->winEnable(TRUE);
  128. disconnectMenuLayout->bringForward();
  129. GadgetListBoxReset(textDisplayWindow);
  130. GadgetListBoxAddEntryText(textDisplayWindow, TheGameText->fetch("GUI:InternetDisconnectionMenuBody1"),
  131. GameMakeColor(255,255,255,255), -1);
  132. } // end ToggleQuitMenu
  133. //------------------------------------------------------
  134. /** Hide the Disconnect Screen */
  135. //------------------------------------------------------
  136. void HideDisconnectWindow( void )
  137. {
  138. // load the quit menu from the layout file if needed
  139. if( disconnectMenuLayout == NULL )
  140. {
  141. // load layout from disk
  142. disconnectMenuLayout = TheWindowManager->winCreateLayout( "Menus/DisconnectScreen.wnd" );
  143. // init it
  144. InitDisconnectWindow();
  145. // show it
  146. disconnectMenuLayout->hide( TRUE );
  147. } // end if
  148. else
  149. {
  150. disconnectMenuLayout->hide( TRUE );
  151. } // end else
  152. } // end ToggleQuitMenu
  153. //-------------------------------------------------------------------------------------------------
  154. /** Input callback for the control bar parent */
  155. //-------------------------------------------------------------------------------------------------
  156. WindowMsgHandledType DisconnectControlInput( GameWindow *window, UnsignedInt msg,
  157. WindowMsgData mData1, WindowMsgData mData2 )
  158. {
  159. return MSG_IGNORED;
  160. } // end DisconnectControlInput
  161. //-------------------------------------------------------------------------------------------------
  162. /** System callback for the control bar parent */
  163. //-------------------------------------------------------------------------------------------------
  164. WindowMsgHandledType DisconnectControlSystem( GameWindow *window, UnsignedInt msg,
  165. WindowMsgData mData1, WindowMsgData mData2 )
  166. {
  167. switch( msg )
  168. {
  169. //---------------------------------------------------------------------------------------------
  170. case GBM_SELECTED:
  171. {
  172. GameWindow *control = (GameWindow *) mData1;
  173. Int controlID = control->winGetWindowId();
  174. if (controlID == buttonQuitID) {
  175. TheDisconnectMenu->quitGame();
  176. buttonQuitWindow->winEnable(FALSE);
  177. } else if (controlID == buttonVotePlayer1ID) {
  178. TheDisconnectMenu->voteForPlayer(0);
  179. buttonVotePlayer1Window->winEnable(FALSE);
  180. } else if (controlID == buttonVotePlayer2ID) {
  181. TheDisconnectMenu->voteForPlayer(1);
  182. buttonVotePlayer2Window->winEnable(FALSE);
  183. } else if (controlID == buttonVotePlayer3ID) {
  184. TheDisconnectMenu->voteForPlayer(2);
  185. buttonVotePlayer3Window->winEnable(FALSE);
  186. } else if (controlID == buttonVotePlayer4ID) {
  187. TheDisconnectMenu->voteForPlayer(3);
  188. buttonVotePlayer4Window->winEnable(FALSE);
  189. } else if (controlID == buttonVotePlayer5ID) {
  190. TheDisconnectMenu->voteForPlayer(4);
  191. buttonVotePlayer5Window->winEnable(FALSE);
  192. } else if (controlID == buttonVotePlayer6ID) {
  193. TheDisconnectMenu->voteForPlayer(5);
  194. buttonVotePlayer6Window->winEnable(FALSE);
  195. } else if (controlID == buttonVotePlayer7ID) {
  196. TheDisconnectMenu->voteForPlayer(6);
  197. buttonVotePlayer7Window->winEnable(FALSE);
  198. }
  199. break;
  200. } // end button selected
  201. case GEM_EDIT_DONE:
  202. {
  203. // DEBUG_LOG(("DisconnectControlSystem - got GEM_EDIT_DONE.\n"));
  204. GameWindow *control = (GameWindow *)mData1;
  205. Int controlID = control->winGetWindowId();
  206. // Take the user's input and echo it into the chat window as well as
  207. // send it to the other clients on the lan
  208. if ( controlID == textEntryID )
  209. {
  210. UnicodeString txtInput;
  211. // DEBUG_LOG(("DisconnectControlSystem - GEM_EDIT_DONE was from the text entry control.\n"));
  212. // read the user's input
  213. txtInput.set(GadgetTextEntryGetText( textEntryWindow ));
  214. // Clear the text entry line
  215. GadgetTextEntrySetText(textEntryWindow, UnicodeString::TheEmptyString);
  216. // Clean up the text (remove leading/trailing chars, etc)
  217. txtInput.trim();
  218. // Echo the user's input to the chat window
  219. if (!txtInput.isEmpty()) {
  220. // DEBUG_LOG(("DisconnectControlSystem - sending string %ls\n", txtInput.str()));
  221. TheDisconnectMenu->sendChat(txtInput);
  222. }
  223. }// if ( controlID == textEntryChatID )
  224. break;
  225. }
  226. //---------------------------------------------------------------------------------------------
  227. default:
  228. return MSG_IGNORED;
  229. } // end switch( msg )
  230. return MSG_HANDLED;
  231. } // end ControlBarSystem