pauseWindow.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. #define PAUSEWINDOW_CPP
  2. /*************************************************************************************************\
  3. PauseWindow.cpp : Implementation of the PauseWindow component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "PauseWindow.h"
  9. #include "controlGui.h"
  10. #include "..\resource.h"
  11. #include "userInput.h"
  12. #include "missiongui.h"
  13. #include "LogisticsDialog.h"
  14. #include "gamesound.h"
  15. #include "mission.h"
  16. #include "LogisticsData.h"
  17. #include "Multplyr.h"
  18. extern float frameLength;
  19. extern bool bInvokeOptionsScreenFlag;
  20. extern long helpTextHeaderID;
  21. extern long helpTextID;
  22. extern unsigned long scenarioResult;
  23. extern bool loadInMissionSave;
  24. extern bool saveInMissionSave;
  25. bool aborted = false;
  26. MoveInfo PauseWindow::moveInfo[8] =
  27. {
  28. 0.0f, 820.f,
  29. 0.04f, 820.f,
  30. 0.28f, 661.f,
  31. .36f, 678.f,
  32. .44f, 661.f,
  33. .52f, 666.f,
  34. .60f, 661.f,
  35. 3.00f, 661.f
  36. };
  37. PauseWindow::PauseWindow()
  38. {
  39. buttons = 0;
  40. buttonData = 0;
  41. buttonCount = 0;
  42. statics = 0;
  43. staticCount = 0;
  44. finalReference = 0;
  45. currentTime = 0;
  46. wasDragging = 0;
  47. objectivesAlreadyOn = 0;
  48. bPromptToQuit = bPromptToAbort = 0;
  49. }
  50. //-------------------------------------------------------------------------------------------------
  51. PauseWindow::~PauseWindow()
  52. {
  53. if ( buttons )
  54. delete [] buttons;
  55. if ( buttonData )
  56. delete [] buttonData;
  57. if ( statics )
  58. delete [] statics;
  59. }
  60. void PauseWindow::update()
  61. {
  62. if ( bPromptToQuit || bPromptToAbort )
  63. {
  64. LogisticsOKDialog::instance()->update();
  65. if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::YES )
  66. {
  67. if ( bPromptToQuit )
  68. gos_TerminateApplication();
  69. else {
  70. //if (MPlayer) {
  71. // MPlayer->leaveSession();
  72. // }
  73. //else
  74. scenarioResult = mis_PLAYER_LOST_BIG;
  75. aborted = true;
  76. }
  77. bPromptToQuit = bPromptToAbort = 0;
  78. }
  79. else if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::NO )
  80. {
  81. if ( LogisticsOKDialog::instance()->isDone() )
  82. bPromptToQuit = bPromptToAbort = 0;
  83. }
  84. }
  85. long mouseX = userInput->getMouseX();
  86. long mouseY = userInput->getMouseY();
  87. gosEnum_KeyIndex key;
  88. bool bShift, bCtrl, bAlt;
  89. MissionInterfaceManager::instance()->getHotKey( OBJECTVIES_COMMAND_KEY, key, bShift, bCtrl, bAlt );
  90. // hack, mission gui message isn't getting here...
  91. if ( gos_GetKeyStatus( key ) != KEY_HELD
  92. && gos_GetKeyStatus( key ) == KEY_PRESSED )
  93. {
  94. buttons[OBJECTIVES].toggle(); // big big hack.
  95. }
  96. if ( currentTime != 0 )
  97. {
  98. currentTime += frameLength;
  99. float p0 = 0.f;
  100. float p1 = 0.f;
  101. float t0 = 0.f;
  102. float t1 = 0.f;
  103. // figure out position based on time
  104. for ( int j = 0; j < 7; j++ )
  105. {
  106. if ( moveInfo[j].time <= currentTime && moveInfo[j+1].time > currentTime )
  107. {
  108. t0 = moveInfo[j].time;
  109. t1 = moveInfo[j + 1].time;
  110. p0 = -(800.f - moveInfo[j].position) + ((float)Environment.screenWidth);
  111. p1 = -(800.f - moveInfo[j + 1].position) + ((float)Environment.screenWidth);
  112. break;
  113. }
  114. }
  115. if ( p1 )
  116. {
  117. float dT = currentTime - t0;
  118. float currentPosition = p0 + dT * ( (p1 - p0)/(t1 -t0) );
  119. float delta = currentPosition - currentPos;
  120. currentPos += delta;
  121. for ( int i = 0; i < buttonCount; i++ )
  122. {
  123. buttons[i].move( delta, 0 );
  124. }
  125. for ( i = 0; i < staticCount; i++ )
  126. {
  127. statics[i].move( delta, 0 );
  128. }
  129. for ( i = 0; i < 2; i++ )
  130. {
  131. float dif = backgrounds[i].right - backgrounds[i].left;
  132. backgrounds[i].left = .5 + currentPos;
  133. backgrounds[i].right = .5 + currentPos + dif;
  134. }
  135. }
  136. }
  137. for ( int i = 0; i < buttonCount; i++ )
  138. {
  139. if ( buttons[i].location[0].x <= mouseX && mouseX <= buttons[i].location[2].x
  140. && mouseY >= buttons[i].location[0].y && mouseY <= buttons[i].location[1].y )
  141. {
  142. if ( buttons[i].isEnabled() )
  143. {
  144. helpTextHeaderID = buttonData[i].helpTextHeader;
  145. helpTextID = buttonData[i].helpTextID;
  146. long lastX = mouseX - userInput->getMouseXDelta();
  147. long lastY = mouseY - userInput->getMouseYDelta();
  148. if ( buttons[i].location[0].x >= lastX || lastX >= buttons[i].location[2].x
  149. || lastY <= buttons[i].location[0].y || lastY >= buttons[i].location[1].y )
  150. {
  151. soundSystem->playDigitalSample( LOG_HIGHLIGHTBUTTONS );
  152. }
  153. if ( buttons[i].state != ControlButton::PRESSED )
  154. buttons[i].makeAmbiguous( true );
  155. }
  156. else
  157. {
  158. helpTextHeaderID = 0;
  159. helpTextID = 0;
  160. continue;
  161. }
  162. if ( userInput->leftMouseReleased() && !wasDragging )
  163. {
  164. {
  165. handleClick( buttons[i].ID );
  166. }
  167. }
  168. }
  169. else if ( buttons[i].isEnabled() && buttons[i].state != ControlButton::PRESSED )
  170. buttons[i].makeAmbiguous( 0 );
  171. }
  172. if ( currentTime == 0 )
  173. {
  174. currentTime = .0001f;
  175. currentPos = -(800 - PauseWindow::moveInfo[0].position) + ((float)Environment.screenWidth);
  176. float delta = backgrounds[0].left - currentPos;
  177. for ( int i = 0; i < buttonCount; i++ )
  178. {
  179. for ( int j = 0; j < 4; j++ )
  180. {
  181. buttons[i].location[j].x -= delta;
  182. }
  183. }
  184. for ( i = 0; i < staticCount; i++ )
  185. {
  186. for ( int j = 0; j < 4; j++ )
  187. {
  188. statics[i].location[j].x -= delta;
  189. }
  190. }
  191. for ( i = 0; i < 2; i++ )
  192. {
  193. float dif = backgrounds[i].right - backgrounds[i].left;
  194. backgrounds[i].left = .5 + currentPos;
  195. backgrounds[i].right = .5 + currentPos + dif;
  196. }
  197. }
  198. wasDragging = userInput->wasLeftDrag();
  199. const char * campaignName = LogisticsData::instance->getCampaignName().Data();
  200. char campName[1024];
  201. _splitpath(campaignName,NULL,NULL,campName,NULL);
  202. if ( MPlayer ||
  203. LogisticsData::instance->isSingleMission() ||
  204. (stricmp("tutorial",campName) == 0))
  205. {
  206. buttons[ SAVE ].disable( true );
  207. buttons[ LOAD ].disable( true );
  208. }
  209. if ( MPlayer )
  210. {
  211. buttons[OPTIONS].disable( true );
  212. }
  213. }
  214. void PauseWindow::render()
  215. {
  216. if ( !currentTime )
  217. return;
  218. drawRect( backgrounds[0], 0xff000000 );
  219. drawRect( backgrounds[1], 0xff000000 );
  220. for ( int i = 0; i < buttonCount; i++ )
  221. {
  222. buttons[i].render();
  223. }
  224. for ( i = 0; i < staticCount; i++ )
  225. {
  226. statics[i].render();
  227. }
  228. char buffer[256];
  229. cLoadString( IDS_GAMEPAUSED, buffer, 256 );
  230. headerFont.render( buffer, backgrounds[1].left, backgrounds[1].top,
  231. backgrounds[1].right - backgrounds[1].left,
  232. backgrounds[1].bottom - backgrounds[1].top,
  233. 0xff5c96c2, 0, 3 );
  234. if ( bPromptToQuit || bPromptToAbort )
  235. {
  236. LogisticsOKDialog::instance()->render();
  237. }
  238. }
  239. void PauseWindow::init( FitIniFile& file )
  240. {
  241. file.seekBlock( "PauseWindow" );
  242. file.readIdLong( "ButtonCount", buttonCount );
  243. file.readIdLong( "staticCount", staticCount );
  244. if ( buttons )
  245. delete [] buttons;
  246. if ( buttonData )
  247. delete [] buttonData;
  248. if ( statics )
  249. delete [] statics;
  250. buttonData = 0;
  251. buttons = 0;
  252. statics = 0;
  253. if ( buttonCount )
  254. {
  255. buttons = new ControlButton[buttonCount];
  256. buttonData = new ButtonData[buttonCount];
  257. font.init( IDS_PAUSEBUTTON800 );
  258. headerFont.init( IDS_PAUSEDFONT_800 );
  259. ControlButton::initButtons( file, buttonCount, buttons, buttonData, "PauseButton", &font );
  260. for ( int i = 0; i < buttonCount; i++ )
  261. {
  262. buttons[i].move( 0, -ControlGui::hiResOffsetY );
  263. }
  264. }
  265. if ( staticCount )
  266. {
  267. statics = new StaticInfo[staticCount];
  268. char buffer[256];
  269. for ( int i = 0; i < staticCount; i++ )
  270. {
  271. sprintf( buffer, "PauseStatic%ld", i );
  272. statics[i].init( file, buffer, ControlGui::hiResOffsetX, 0);
  273. }
  274. }
  275. if ( NO_ERR == file.seekBlock( "PauseBackRect" ) )
  276. {
  277. file.readIdLong( "left", backgrounds[0].left );
  278. file.readIdLong( "right", backgrounds[0].right );
  279. file.readIdLong( "top", backgrounds[0].top );
  280. file.readIdLong( "bottom", backgrounds[0].bottom );
  281. backgrounds[0].left += ControlGui::hiResOffsetX;
  282. backgrounds[0].right += ControlGui::hiResOffsetX;
  283. // backgrounds[0].top += ControlGui::hiResOffsetY;
  284. // backgrounds[0].bottom += ControlGui::hiResOffsetY;
  285. }
  286. if ( NO_ERR == file.seekBlock( "PauseText" ) )
  287. {
  288. file.readIdLong( "left", backgrounds[1].left );
  289. file.readIdLong( "right", backgrounds[1].right );
  290. file.readIdLong( "top", backgrounds[1].top );
  291. file.readIdLong( "bottom", backgrounds[1].bottom );
  292. backgrounds[1].left += ControlGui::hiResOffsetX;
  293. backgrounds[1].right += ControlGui::hiResOffsetX;
  294. // backgrounds[1].top += ControlGui::hiResOffsetY;
  295. // backgrounds[1].bottom += ControlGui::hiResOffsetY;
  296. }
  297. }
  298. void PauseWindow::handleClick( int id )
  299. {
  300. int sound = LOG_SELECT;
  301. switch ( id )
  302. {
  303. case OBJECTIVES:
  304. if ( buttons[OBJECTIVES].state == ControlButton::PRESSED )
  305. {
  306. ControlGui::instance->startObjectives( 0 );
  307. buttons[OBJECTIVES].press( 0 );
  308. objectivesAlreadyOn = 0;
  309. }
  310. else
  311. {
  312. ControlGui::instance->startObjectives( 1 );
  313. buttons[OBJECTIVES].press( 1 );
  314. }
  315. break;
  316. case SAVE:
  317. if (!MPlayer && !LogisticsData::instance->isSingleMission())
  318. saveInMissionSave = true;
  319. else
  320. sound = INVALID_GUI;
  321. break;
  322. case LOAD:
  323. if (!MPlayer && !LogisticsData::instance->isSingleMission())
  324. loadInMissionSave = true;
  325. else
  326. sound = INVALID_GUI;
  327. break;
  328. case RESTART:
  329. bPromptToAbort = true;
  330. LogisticsOKDialog::instance()->setText( IDS_DIALOG_ABORT_PROMPT,
  331. IDS_DIALOG_NO, IDS_DIALOG_YES );
  332. LogisticsOKDialog::instance()->begin();
  333. sound = LOG_MAINMENUBUTTON;
  334. break;
  335. case EXIT:
  336. // i suppose I should put a do you really mean it dialog here
  337. bPromptToQuit = true;
  338. LogisticsOKDialog::instance()->setText( IDS_DIALOG_QUIT_PROMPT,
  339. IDS_DIALOG_NO, IDS_DIALOG_YES );
  340. LogisticsOKDialog::instance()->begin();
  341. sound = LOG_MAINMENUBUTTON;
  342. break;
  343. case OPTIONS:
  344. if (!MPlayer)
  345. {
  346. sound = LOG_CLICKONBUTTON;
  347. bInvokeOptionsScreenFlag = true;
  348. }
  349. else
  350. {
  351. sound = INVALID_GUI;
  352. }
  353. //break;
  354. //fallthrough
  355. case RETURN:
  356. MissionInterfaceManager::instance()->togglePause();
  357. if ( buttons[OBJECTIVES].state & ControlButton::PRESSED && !objectivesAlreadyOn )
  358. {
  359. ControlGui::instance->startObjectives( 0 );
  360. buttons[OBJECTIVES].press( 0 );
  361. }
  362. break;
  363. }
  364. soundSystem->playDigitalSample( sound );
  365. }
  366. bool PauseWindow::inRect( int mouseX, int mouseY )
  367. {
  368. return ( mouseX >= backgrounds[0].left && mouseX <= backgrounds[0].right &&
  369. mouseY >= backgrounds[0].top && mouseY <= backgrounds[0].bottom );
  370. }
  371. void PauseWindow::end()
  372. {
  373. currentTime = 5.f;
  374. if ( buttons[OBJECTIVES].state & ControlButton::PRESSED && !objectivesAlreadyOn )
  375. {
  376. ControlGui::instance->startObjectives( 0 );
  377. buttons[OBJECTIVES].press( 0 );
  378. }
  379. }
  380. void PauseWindow::begin(bool objectivesOn)
  381. {
  382. currentTime = 0.f;
  383. objectivesAlreadyOn = objectivesOn;
  384. if ( !objectivesAlreadyOn )
  385. buttons[OBJECTIVES].press( 0 );
  386. else
  387. buttons[OBJECTIVES].press( 1 );
  388. }
  389. //*************************************************************************************************
  390. // end of file ( PauseWindow.cpp )