DisconnectWindow.cpp 10 KB

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