WOLLocaleSelectPopup.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. ///////////////////////////////////////////////////////////////////////////////////////
  24. // FILE: WOLLocaleSelectPopup.cpp
  25. // Author: Matt Campbell, December 2001
  26. // Description: WOL locale select popup
  27. ///////////////////////////////////////////////////////////////////////////////////////
  28. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "GameClient/GameText.h"
  31. #include "Common/CustomMatchPreferences.h"
  32. #include "Common/GameEngine.h"
  33. #include "Common/GameSpyMiscPreferences.h"
  34. #include "GameClient/WindowLayout.h"
  35. #include "GameClient/Gadget.h"
  36. #include "GameClient/Shell.h"
  37. #include "GameClient/KeyDefs.h"
  38. #include "GameClient/GameWindowManager.h"
  39. #include "GameClient/GadgetListBox.h"
  40. #include "Common/GlobalData.h"
  41. #include "GameNetwork/GameSpyOverlay.h"
  42. #include "GameNetwork/GameSpy/PeerDefs.h"
  43. #include "GameNetwork/GameSpy/PeerThread.h"
  44. #include "GameNetwork/GameSpy/PersistentStorageDefs.h"
  45. #include "GameNetwork/GameSpy/PersistentStorageThread.h"
  46. #ifdef _INTERNAL
  47. // for occasional debugging...
  48. //#pragma optimize("", off)
  49. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  50. #endif
  51. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  52. // window ids ------------------------------------------------------------------------------
  53. static NameKeyType parentLocaleSelectID = NAMEKEY_INVALID;
  54. static NameKeyType buttonOkID = NAMEKEY_INVALID;
  55. static NameKeyType listboxLocaleID = NAMEKEY_INVALID;
  56. // Window Pointers ------------------------------------------------------------------------
  57. static GameWindow *parentLocaleSelect = NULL;
  58. static GameWindow *buttonOk = NULL;
  59. static GameWindow *listboxLocale = NULL;
  60. //-------------------------------------------------------------------------------------------------
  61. /** Initialize the WOL Status Menu */
  62. //-------------------------------------------------------------------------------------------------
  63. void WOLLocaleSelectInit( WindowLayout *layout, void *userData )
  64. {
  65. parentLocaleSelectID = TheNameKeyGenerator->nameToKey( AsciiString( "PopupLocaleSelect.wnd:ParentLocaleSelect" ) );
  66. buttonOkID = TheNameKeyGenerator->nameToKey( AsciiString( "PopupLocaleSelect.wnd:ButtonOk" ) );
  67. listboxLocaleID = TheNameKeyGenerator->nameToKey( AsciiString( "PopupLocaleSelect.wnd:ListBoxLocaleSelect" ) );
  68. parentLocaleSelect = TheWindowManager->winGetWindowFromId( NULL, parentLocaleSelectID );
  69. buttonOk = TheWindowManager->winGetWindowFromId( NULL, buttonOkID);
  70. listboxLocale = TheWindowManager->winGetWindowFromId( NULL, listboxLocaleID);
  71. for (int i=LOC_MIN; i<=LOC_MAX; ++i)
  72. {
  73. AsciiString id;
  74. id.format("WOL:Locale%2.2d", i);
  75. GadgetListBoxAddEntryText(listboxLocale, TheGameText->fetch(id.str()), GameSpyColor[GSCOLOR_DEFAULT], -1, -1);
  76. }
  77. GadgetListBoxSetSelected(listboxLocale, 0);
  78. // Show Menu
  79. layout->hide( FALSE );
  80. // Set Keyboard to Main Parent
  81. TheWindowManager->winSetFocus( parentLocaleSelect );
  82. TheWindowManager->winSetModal( parentLocaleSelect );
  83. } // WOLLocaleSelectInit
  84. //-------------------------------------------------------------------------------------------------
  85. /** WOL Status Menu shutdown method */
  86. //-------------------------------------------------------------------------------------------------
  87. void WOLLocaleSelectShutdown( WindowLayout *layout, void *userData )
  88. {
  89. // hide menu
  90. layout->hide( TRUE );
  91. // our shutdown is complete
  92. TheShell->shutdownComplete( layout );
  93. } // WOLLocaleSelectShutdown
  94. //-------------------------------------------------------------------------------------------------
  95. /** WOL Status Menu update method */
  96. //-------------------------------------------------------------------------------------------------
  97. void WOLLocaleSelectUpdate( WindowLayout * layout, void *userData)
  98. {
  99. }// WOLLocaleSelectUpdate
  100. //-------------------------------------------------------------------------------------------------
  101. /** WOL Status Menu input callback */
  102. //-------------------------------------------------------------------------------------------------
  103. WindowMsgHandledType WOLLocaleSelectInput( GameWindow *window, UnsignedInt msg,
  104. WindowMsgData mData1, WindowMsgData mData2 )
  105. {
  106. switch( msg )
  107. {
  108. // --------------------------------------------------------------------------------------------
  109. case GWM_CHAR:
  110. {
  111. // UnsignedByte key = mData1;
  112. // UnsignedByte state = mData2;
  113. // ----------------------------------------------------------------------------------------
  114. // don't let key fall through anywhere else
  115. return MSG_HANDLED;
  116. } // end char
  117. } // end switch( msg )
  118. return MSG_IGNORED;
  119. }// WOLLocaleSelectInput
  120. //Int getRegistryNicknameOffset(AsciiString nick); /// @todo: mdc remove this once we can save ini pref files
  121. //-------------------------------------------------------------------------------------------------
  122. /** WOL Status Menu window system callback */
  123. //-------------------------------------------------------------------------------------------------
  124. WindowMsgHandledType WOLLocaleSelectSystem( GameWindow *window, UnsignedInt msg,
  125. WindowMsgData mData1, WindowMsgData mData2 )
  126. {
  127. UnicodeString txtInput;
  128. switch( msg )
  129. {
  130. case GWM_CREATE:
  131. {
  132. break;
  133. } // case GWM_DESTROY:
  134. case GWM_DESTROY:
  135. {
  136. break;
  137. } // case GWM_DESTROY:
  138. case GWM_INPUT_FOCUS:
  139. {
  140. // if we're givin the opportunity to take the keyboard focus we must say we want it
  141. if( mData1 == TRUE )
  142. *(Bool *)mData2 = TRUE;
  143. return MSG_HANDLED;
  144. }//case GWM_INPUT_FOCUS:
  145. case GBM_SELECTED:
  146. {
  147. GameWindow *control = (GameWindow *)mData1;
  148. Int controlID = control->winGetWindowId();
  149. if ( controlID == buttonOkID )
  150. {
  151. int selected;
  152. GadgetListBoxGetSelected(listboxLocale, &selected);
  153. if (selected < 0)
  154. return MSG_HANDLED; // can't select nothing!
  155. PSRequest psReq;
  156. psReq.requestType = PSRequest::PSREQUEST_UPDATEPLAYERLOCALE;
  157. psReq.player.locale = selected + LOC_MIN;
  158. psReq.email = TheGameSpyInfo->getLocalEmail().str();
  159. psReq.nick = TheGameSpyInfo->getLocalBaseName().str();
  160. psReq.password = TheGameSpyInfo->getLocalPassword().str();
  161. psReq.player.id = TheGameSpyInfo->getLocalProfileID();
  162. TheGameSpyPSMessageQueue->addRequest(psReq);
  163. GameSpyCloseOverlay(GSOVERLAY_LOCALESELECT);
  164. GameSpyMiscPreferences cPref;
  165. cPref.setLocale(psReq.player.locale);
  166. cPref.write();
  167. PSPlayerStats stats = TheGameSpyPSMessageQueue->findPlayerStatsByID(TheGameSpyInfo->getLocalProfileID());
  168. stats.locale = psReq.player.locale;
  169. if (stats.id == TheGameSpyInfo->getLocalProfileID())
  170. TheGameSpyPSMessageQueue->trackPlayerStats(stats);
  171. if(stats.id == 0)
  172. {
  173. stats = TheGameSpyInfo->getCachedLocalPlayerStats();
  174. stats.locale = psReq.player.locale;
  175. TheGameSpyInfo->setCachedLocalPlayerStats(stats);
  176. }
  177. else
  178. {
  179. // force an update of our shtuff
  180. PSResponse newResp;
  181. newResp.responseType = PSResponse::PSRESPONSE_PLAYERSTATS;
  182. newResp.player = TheGameSpyPSMessageQueue->findPlayerStatsByID(TheGameSpyInfo->getLocalProfileID());
  183. TheGameSpyPSMessageQueue->addResponse(newResp);
  184. }
  185. CheckReOpenPlayerInfo();
  186. } //if ( controlID == buttonDisconnect )
  187. break;
  188. }// case GBM_SELECTED:
  189. case GEM_EDIT_DONE:
  190. {
  191. break;
  192. }
  193. default:
  194. return MSG_IGNORED;
  195. }//Switch
  196. return MSG_HANDLED;
  197. }// WOLLocaleSelectSystem