InGamePopupMessage.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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: InGamePopupMessage.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: InGamePopupMessage.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Init, input, and system for the in game message 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 "Common/Version.h"
  53. #include "Common/MessageStream.h"
  54. #include "GameClient/WindowLayout.h"
  55. #include "GameClient/Gadget.h"
  56. #include "GameClient/GadgetStaticText.h"
  57. #include "GameClient/KeyDefs.h"
  58. #include "GameClient/GameWindowManager.h"
  59. #include "GameClient/InGameUI.h"
  60. #include "GameClient/DisplayStringManager.h"
  61. //-----------------------------------------------------------------------------
  62. // DEFINES ////////////////////////////////////////////////////////////////////
  63. //-----------------------------------------------------------------------------
  64. static NameKeyType parentID = NAMEKEY_INVALID;
  65. static NameKeyType staticTextMessageID = NAMEKEY_INVALID;
  66. static NameKeyType buttonOkID = NAMEKEY_INVALID;
  67. static GameWindow *parent = NULL;
  68. static GameWindow *staticTextMessage = NULL;
  69. static GameWindow *buttonOk = NULL;
  70. static Bool pause = FALSE;
  71. //-----------------------------------------------------------------------------
  72. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  73. //-----------------------------------------------------------------------------
  74. //-------------------------------------------------------------------------------------------------
  75. /** Initialize the InGamePopupMessageInit menu */
  76. //-------------------------------------------------------------------------------------------------
  77. void InGamePopupMessageInit( WindowLayout *layout, void *userData )
  78. {
  79. parentID = TheNameKeyGenerator->nameToKey(AsciiString("InGamePopupMessage.wnd:InGamePopupMessageParent"));
  80. parent = TheWindowManager->winGetWindowFromId(NULL, parentID);
  81. staticTextMessageID = TheNameKeyGenerator->nameToKey(AsciiString("InGamePopupMessage.wnd:StaticTextMessage"));
  82. staticTextMessage = TheWindowManager->winGetWindowFromId(parent, staticTextMessageID);
  83. buttonOkID = TheNameKeyGenerator->nameToKey(AsciiString("InGamePopupMessage.wnd:ButtonOk"));
  84. buttonOk = TheWindowManager->winGetWindowFromId(parent, buttonOkID);
  85. PopupMessageData *pMData = TheInGameUI->getPopupMessageData();
  86. if(!pMData)
  87. {
  88. DEBUG_ASSERTCRASH(pMData, ("We're in InGamePopupMessage without a pointer to pMData\n") );
  89. ///< @todo: add a call to the close this bitch method when I implement it CLH
  90. return;
  91. }
  92. DisplayString *tempString = TheDisplayStringManager->newDisplayString();
  93. tempString->setText(pMData->message);
  94. tempString->setFont(staticTextMessage->winGetFont());
  95. tempString->setWordWrap(pMData->width - 14);
  96. Int width, height;
  97. tempString->getSize(&width, &height);
  98. TheDisplayStringManager->freeDisplayString(tempString);
  99. GadgetStaticTextSetText(staticTextMessage, pMData->message);
  100. // set the positions/sizes
  101. Int widthOk, heightOk;
  102. buttonOk->winGetSize(&widthOk, &heightOk);
  103. parent->winSetPosition( pMData->x, pMData->y);
  104. parent->winSetSize( pMData->width, height + 7 + 2 + 2 + heightOk + 2 );
  105. staticTextMessage->winSetPosition( 2, 2);
  106. staticTextMessage->winSetSize( pMData->width - 4, height + 7);
  107. buttonOk->winSetPosition(pMData->width - widthOk - 2, height + 7 + 2 + 2);
  108. staticTextMessage->winSetEnabledTextColors(pMData->textColor, 0);
  109. pause = pMData->pause;
  110. if(pMData->pause)
  111. TheWindowManager->winSetModal( parent );
  112. TheWindowManager->winSetFocus( parent );
  113. parent->winHide(FALSE);
  114. parent->winBringToTop();
  115. }
  116. //-------------------------------------------------------------------------------------------------
  117. /** InGamePopupMessageInput callback */
  118. //-------------------------------------------------------------------------------------------------
  119. WindowMsgHandledType InGamePopupMessageInput( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  120. {
  121. switch( msg )
  122. {
  123. // --------------------------------------------------------------------------------------------
  124. case GWM_CHAR:
  125. {
  126. UnsignedByte key = mData1;
  127. UnsignedByte state = mData2;
  128. // if (buttonPushed)
  129. // break;
  130. switch( key )
  131. {
  132. // ----------------------------------------------------------------------------------------
  133. case KEY_ENTER:
  134. case KEY_ESC:
  135. {
  136. //
  137. // send a simulated selected event to the parent window of the
  138. // back/exit button
  139. //
  140. if( BitTest( state, KEY_STATE_UP ) )
  141. {
  142. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  143. (WindowMsgData)buttonOk, buttonOkID );
  144. } // end if
  145. // don't let key fall through anywhere else
  146. return MSG_HANDLED;
  147. } // end escape
  148. } // end switch( key )
  149. } // end char
  150. } // end switch( msg )
  151. return MSG_IGNORED;
  152. }
  153. //-------------------------------------------------------------------------------------------------
  154. /** InGamePopupMessageSystem callback */
  155. //-------------------------------------------------------------------------------------------------
  156. WindowMsgHandledType InGamePopupMessageSystem( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  157. {
  158. switch( msg )
  159. {
  160. // --------------------------------------------------------------------------------------------
  161. case GWM_CREATE:
  162. {
  163. break;
  164. } // end create
  165. //---------------------------------------------------------------------------------------------
  166. case GWM_DESTROY:
  167. {
  168. break;
  169. } // end case
  170. //----------------------------------------------------------------------------------------------
  171. case GWM_INPUT_FOCUS:
  172. {
  173. // if we're givin the opportunity to take the keyboard focus we must say we want it
  174. if( mData1 == TRUE )
  175. *(Bool *)mData2 = TRUE;
  176. break;
  177. } // end input
  178. //---------------------------------------------------------------------------------------------
  179. case GBM_SELECTED:
  180. {
  181. GameWindow *control = (GameWindow *)mData1;
  182. Int controlID = control->winGetWindowId();
  183. if( controlID == buttonOkID )
  184. {
  185. if(!pause)
  186. TheMessageStream->appendMessage( GameMessage::MSG_CLEAR_INGAME_POPUP_MESSAGE );
  187. else
  188. TheInGameUI->clearPopupMessageData();
  189. }
  190. break;
  191. }
  192. default:
  193. return MSG_IGNORED;
  194. } // end switch
  195. return MSG_HANDLED;
  196. }
  197. //-----------------------------------------------------------------------------
  198. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  199. //-----------------------------------------------------------------------------