ControlBarPopupDescription.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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: ControlBarPopupDescription.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Sep 2002
  34. //
  35. // Filename: ControlBarPopupDescription.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose:
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. //-----------------------------------------------------------------------------
  50. // DEFINES ////////////////////////////////////////////////////////////////////
  51. //-----------------------------------------------------------------------------
  52. //-----------------------------------------------------------------------------
  53. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  54. //-----------------------------------------------------------------------------
  55. //-----------------------------------------------------------------------------
  56. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  57. //-----------------------------------------------------------------------------
  58. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  59. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  60. #include "Common/GlobalData.h"
  61. #include "Common/BuildAssistant.h"
  62. #include "Common/Player.h"
  63. #include "Common/PlayerList.h"
  64. #include "Common/ProductionPrerequisite.h"
  65. #include "Common/ThingTemplate.h"
  66. #include "Common/Upgrade.h"
  67. #include "GameClient/AnimateWindowManager.h"
  68. #include "GameClient/DisconnectMenu.h"
  69. #include "GameClient/GameWindow.h"
  70. #include "GameClient/Gadget.h"
  71. #include "GameClient/GadgetTextEntry.h"
  72. #include "GameClient/GadgetPushButton.h"
  73. #include "GameClient/GadgetStaticText.h"
  74. #include "GameClient/GameClient.h"
  75. #include "GameClient/GameText.h"
  76. #include "GameClient/GUICallbacks.h"
  77. #include "GameClient/InGameUI.h"
  78. #include "GameClient/Controlbar.h"
  79. #include "GameClient/DisplayStringManager.h"
  80. #include "GameLogic/GameLogic.h"
  81. #include "GameLogic/Module/OverchargeBehavior.h"
  82. #include "GameLogic/Module/ProductionUpdate.h"
  83. #include "GameLogic/ScriptEngine.h"
  84. #include "GameNetwork/NetworkInterface.h"
  85. #ifdef _INTERNAL
  86. // for occasional debugging...
  87. //#pragma optimize("", off)
  88. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  89. #endif
  90. static WindowLayout *theLayout = NULL;
  91. static GameWindow *theWindow = NULL;
  92. static AnimateWindowManager *theAnimateWindowManager = NULL;
  93. static GameWindow *prevWindow = NULL;
  94. static Bool useAnimation = FALSE;
  95. void ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param )
  96. {
  97. if(TheScriptEngine->isGameEnding())
  98. TheControlBar->hideBuildTooltipLayout();
  99. if(theAnimateWindowManager && !TheControlBar->getShowBuildTooltipLayout() && !theAnimateWindowManager->isReversed())
  100. theAnimateWindowManager->reverseAnimateWindow();
  101. else if(!TheControlBar->getShowBuildTooltipLayout() && (!TheGlobalData->m_animateWindows || !useAnimation))
  102. TheControlBar->deleteBuildTooltipLayout();
  103. if ( useAnimation && theAnimateWindowManager && TheGlobalData->m_animateWindows)
  104. {
  105. Bool wasFinished = theAnimateWindowManager->isFinished();
  106. theAnimateWindowManager->update();
  107. if (theAnimateWindowManager && theAnimateWindowManager->isFinished() && !wasFinished && theAnimateWindowManager->isReversed())
  108. {
  109. delete theAnimateWindowManager;
  110. theAnimateWindowManager = NULL;
  111. TheControlBar->deleteBuildTooltipLayout();
  112. }
  113. }
  114. }
  115. // ---------------------------------------------------------------------------------------
  116. void ControlBar::showBuildTooltipLayout( GameWindow *cmdButton )
  117. {
  118. if (TheInGameUI->areTooltipsDisabled() || TheScriptEngine->isGameEnding())
  119. {
  120. return;
  121. }
  122. Bool passedWaitTime = FALSE;
  123. static Bool isInitialized = FALSE;
  124. static UnsignedInt beginWaitTime;
  125. if(prevWindow == cmdButton)
  126. {
  127. m_showBuildToolTipLayout = TRUE;
  128. if(!isInitialized && beginWaitTime + cmdButton->getTooltipDelay() < timeGetTime())
  129. {
  130. //DEBUG_LOG(("%d beginwaittime, %d tooltipdelay, %dtimegettime\n", beginWaitTime, cmdButton->getTooltipDelay(), timeGetTime()));
  131. passedWaitTime = TRUE;
  132. }
  133. if(!passedWaitTime)
  134. return;
  135. }
  136. else if( !m_buildToolTipLayout->isHidden() )
  137. {
  138. if(useAnimation && TheGlobalData->m_animateWindows && !theAnimateWindowManager->isReversed())
  139. theAnimateWindowManager->reverseAnimateWindow();
  140. else if( useAnimation && TheGlobalData->m_animateWindows && theAnimateWindowManager->isReversed())
  141. {
  142. return;
  143. }
  144. else
  145. {
  146. // m_buildToolTipLayout->destroyWindows();
  147. // m_buildToolTipLayout->deleteInstance();
  148. // m_buildToolTipLayout = NULL;
  149. m_buildToolTipLayout->hide(TRUE);
  150. prevWindow = NULL;
  151. }
  152. return;
  153. }
  154. // will only get here the firsttime through the function through this window
  155. if(!passedWaitTime)
  156. {
  157. prevWindow = cmdButton;
  158. beginWaitTime = timeGetTime();
  159. isInitialized = FALSE;
  160. return;
  161. }
  162. isInitialized = TRUE;
  163. if(!cmdButton)
  164. return;
  165. if(BitTest(cmdButton->winGetStyle(), GWS_PUSH_BUTTON))
  166. {
  167. const CommandButton *commandButton = (const CommandButton *)GadgetButtonGetData(cmdButton);
  168. if(!commandButton)
  169. return;
  170. // note that, in this branch, ENABLE_SOLO_PLAY is ***NEVER*** defined...
  171. // this is so that we have a multiplayer build that cannot possibly be hacked
  172. // to work as a solo game!
  173. if (TheGameLogic->isInReplayGame())
  174. return;
  175. if (TheInGameUI->isQuitMenuVisible())
  176. return;
  177. if (TheDisconnectMenu && TheDisconnectMenu->isScreenVisible())
  178. return;
  179. // if (m_buildToolTipLayout)
  180. // {
  181. // m_buildToolTipLayout->destroyWindows();
  182. // m_buildToolTipLayout->deleteInstance();
  183. //
  184. // }
  185. m_showBuildToolTipLayout = TRUE;
  186. // m_buildToolTipLayout = TheWindowManager->winCreateLayout( "ControlBarPopupDescription.wnd" );
  187. // m_buildToolTipLayout->setUpdate(ControlBarPopupDescriptionUpdateFunc);
  188. populateBuildTooltipLayout(commandButton);
  189. }
  190. else
  191. {
  192. // we're a generic window
  193. if(!BitTest(cmdButton->winGetStyle(), GWS_USER_WINDOW) && !BitTest(cmdButton->winGetStyle(), GWS_STATIC_TEXT))
  194. return;
  195. populateBuildTooltipLayout(NULL, cmdButton);
  196. }
  197. m_buildToolTipLayout->hide(FALSE);
  198. if (useAnimation && TheGlobalData->m_animateWindows)
  199. {
  200. theAnimateWindowManager = NEW AnimateWindowManager;
  201. theAnimateWindowManager->reset();
  202. theAnimateWindowManager->registerGameWindow( m_buildToolTipLayout->getFirstWindow(), WIN_ANIMATION_SLIDE_RIGHT_FAST, TRUE, 200 );
  203. }
  204. }
  205. void ControlBar::repopulateBuildTooltipLayout( void )
  206. {
  207. if(!prevWindow || !m_buildToolTipLayout)
  208. return;
  209. if(!BitTest(prevWindow->winGetStyle(), GWS_PUSH_BUTTON))
  210. return;
  211. const CommandButton *commandButton = (const CommandButton *)GadgetButtonGetData(prevWindow);
  212. populateBuildTooltipLayout(commandButton);
  213. }
  214. void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton, GameWindow *tooltipWin)
  215. {
  216. if(!m_buildToolTipLayout)
  217. return;
  218. Player *player = ThePlayerList->getLocalPlayer();
  219. UnicodeString name, cost, descrip;
  220. UnicodeString requires = UnicodeString::TheEmptyString, requiresList;
  221. Bool firstRequirement = true;
  222. const ProductionPrerequisite *prereq;
  223. Bool fireScienceButton = false;
  224. UnsignedInt costToBuild = 0;
  225. if(commandButton)
  226. {
  227. const ThingTemplate *thingTemplate = commandButton->getThingTemplate();
  228. const UpgradeTemplate *upgradeTemplate = commandButton->getUpgradeTemplate();
  229. ScienceType st = SCIENCE_INVALID;
  230. if( commandButton->getCommandType() != GUI_COMMAND_PLAYER_UPGRADE &&
  231. commandButton->getCommandType() != GUI_COMMAND_OBJECT_UPGRADE )
  232. {
  233. if( commandButton->getScienceVec().size() > 1 )
  234. {
  235. for(Int j = 0; j < commandButton->getScienceVec().size(); ++j)
  236. {
  237. st = commandButton->getScienceVec()[ j ];
  238. if( commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE )
  239. {
  240. if( !player->hasScience( st ) && j > 0 )
  241. {
  242. //If we're not looking at a command button that purchases a science, then
  243. //it means we are looking at a command button that can USE the science. This
  244. //means we want to get the description for the previous science -- the one
  245. //we can use, not purchase!
  246. st = commandButton->getScienceVec()[ j - 1 ];
  247. }
  248. //Now that we got the science for the button that executes the science, we need
  249. //to generate a simpler help text!
  250. fireScienceButton = TRUE;
  251. break;
  252. }
  253. else if( !player->hasScience( st ) )
  254. {
  255. //Purchase science case. The first science we run into that we don't have, that's the
  256. //one we'll want to show!
  257. break;
  258. }
  259. }
  260. }
  261. else if(commandButton->getScienceVec().size() == 1 )
  262. {
  263. st = commandButton->getScienceVec()[ 0 ];
  264. if( commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE )
  265. {
  266. //Now that we got the science for the button that executes the science, we need
  267. //to generate a simpler help text!
  268. fireScienceButton = TRUE;
  269. }
  270. }
  271. }
  272. if( commandButton->getDescriptionLabel().isNotEmpty() )
  273. {
  274. descrip = TheGameText->fetch(commandButton->getDescriptionLabel());
  275. Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
  276. Object *selectedObject = draw ? draw->getObject() : NULL;
  277. if( selectedObject )
  278. {
  279. //Special case: Append status of overcharge on China power plant.
  280. if( commandButton->getCommandType() == GUI_COMMAND_TOGGLE_OVERCHARGE )
  281. {
  282. {
  283. OverchargeBehaviorInterface *obi;
  284. for( BehaviorModule **bmi = selectedObject->getBehaviorModules(); *bmi; ++bmi )
  285. {
  286. obi = (*bmi)->getOverchargeBehaviorInterface();
  287. if( obi )
  288. {
  289. descrip.concat( L"\n" );
  290. if( obi->isOverchargeActive() )
  291. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNukeReactorOverChargeIsOn" ) );
  292. else
  293. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNukeReactorOverChargeIsOff" ) );
  294. }
  295. }
  296. }
  297. } //End overcharge special case
  298. //Special case: When building units & buildings, the CanMakeType determines reasons for not being able to buy stuff.
  299. else if( thingTemplate )
  300. {
  301. CanMakeType makeType = TheBuildAssistant->canMakeUnit( selectedObject, commandButton->getThingTemplate() );
  302. switch( makeType )
  303. {
  304. case CANMAKE_NO_MONEY:
  305. descrip.concat( L"\n\n" );
  306. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
  307. break;
  308. case CANMAKE_QUEUE_FULL:
  309. descrip.concat( L"\n\n" );
  310. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
  311. break;
  312. case CANMAKE_PARKING_PLACES_FULL:
  313. descrip.concat( L"\n\n" );
  314. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseParkingFull" ) );
  315. break;
  316. case CANMAKE_MAXED_OUT_FOR_PLAYER:
  317. descrip.concat( L"\n\n" );
  318. if ( thingTemplate->isKindOf( KINDOF_STRUCTURE ) )
  319. {
  320. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildBuildingBecauseMaximumNumber" ) );
  321. }
  322. else
  323. {
  324. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseMaximumNumber" ) );
  325. }
  326. break;
  327. //case CANMAKE_NO_PREREQ:
  328. // descrip.concat( L"\n\n" );
  329. // descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildDueToPrerequisites" ) );
  330. // break;
  331. }
  332. }
  333. //Special case: When building upgrades
  334. else if( upgradeTemplate && !player->hasUpgradeInProduction( upgradeTemplate ) )
  335. {
  336. if( commandButton->getCommandType() == GUI_COMMAND_PLAYER_UPGRADE ||
  337. commandButton->getCommandType() == GUI_COMMAND_OBJECT_UPGRADE )
  338. {
  339. ProductionUpdateInterface *pui = selectedObject->getProductionUpdateInterface();
  340. if( pui && pui->getProductionCount() == MAX_BUILD_QUEUE_BUTTONS )
  341. {
  342. descrip.concat( L"\n\n" );
  343. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
  344. }
  345. else if( !TheUpgradeCenter->canAffordUpgrade( ThePlayerList->getLocalPlayer(), upgradeTemplate, FALSE ) )
  346. {
  347. descrip.concat( L"\n\n" );
  348. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
  349. }
  350. }
  351. }
  352. }
  353. }
  354. name = TheGameText->fetch(commandButton->getTextLabel().str());
  355. if( thingTemplate && commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE )
  356. {
  357. //We are either looking at building a unit or a structure that may or may not have any
  358. //prerequisites.
  359. //Format the cost only when we have to pay for it.
  360. costToBuild = thingTemplate->calcCostToBuild( player );
  361. if( costToBuild > 0 )
  362. {
  363. cost.format( TheGameText->fetch("TOOLTIP:Cost"), costToBuild );
  364. }
  365. // ask each prerequisite to give us a list of the non satisfied prerequisites
  366. for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
  367. {
  368. prereq = thingTemplate->getNthPrereq(i);
  369. requiresList = prereq->getRequiresList(player);
  370. if( requiresList != UnicodeString::TheEmptyString )
  371. {
  372. // make sure to put in 'returns' to space things correctly
  373. if (firstRequirement)
  374. firstRequirement = false;
  375. else
  376. requires.concat(L", ");
  377. }
  378. requires.concat(requiresList);
  379. }
  380. if( !requires.isEmpty() )
  381. {
  382. UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
  383. requires.format(requireFormat.str(), requires.str());
  384. if(!descrip.isEmpty())
  385. descrip.concat(L"\n");
  386. descrip.concat(requires);
  387. }
  388. }
  389. else if( upgradeTemplate )
  390. {
  391. //We are looking at an upgrade purchase icon. Maybe we already purchased it?
  392. Bool hasUpgradeAlready = player->hasUpgradeComplete( upgradeTemplate );
  393. Bool hasConflictingUpgrade = FALSE;
  394. Bool missingScience = FALSE;
  395. Bool playerUpgradeButton = commandButton->getCommandType() == GUI_COMMAND_PLAYER_UPGRADE;
  396. Bool objectUpgradeButton = commandButton->getCommandType() == GUI_COMMAND_OBJECT_UPGRADE;
  397. if( !hasUpgradeAlready )
  398. {
  399. //Check if the first selected object has the specified upgrade.
  400. Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
  401. if( draw )
  402. {
  403. Object *object = draw->getObject();
  404. if( object )
  405. {
  406. hasUpgradeAlready = object->hasUpgrade( upgradeTemplate );
  407. if( objectUpgradeButton )
  408. {
  409. hasConflictingUpgrade = !object->affectedByUpgrade( upgradeTemplate );
  410. }
  411. }
  412. }
  413. }
  414. if( hasConflictingUpgrade && !hasUpgradeAlready )
  415. {
  416. if( commandButton->getConflictingLabel().isNotEmpty() )
  417. {
  418. descrip = TheGameText->fetch( commandButton->getConflictingLabel() );
  419. }
  420. else
  421. {
  422. descrip = TheGameText->fetch( "TOOLTIP:HasConflictingUpgradeDefault" );
  423. }
  424. }
  425. else if( hasUpgradeAlready && ( playerUpgradeButton || objectUpgradeButton ) )
  426. {
  427. //See if we can fetch the "already upgraded" text for this upgrade. If not.... use the default "fill me in".
  428. if( commandButton->getPurchasedLabel().isNotEmpty() )
  429. {
  430. descrip = TheGameText->fetch( commandButton->getPurchasedLabel() );
  431. }
  432. else
  433. {
  434. descrip = TheGameText->fetch( "TOOLTIP:AlreadyUpgradedDefault" );
  435. }
  436. }
  437. else if( !hasUpgradeAlready )
  438. {
  439. //Do we have a prerequisite science?
  440. for( Int i = 0; i < commandButton->getScienceVec().size(); i++ )
  441. {
  442. ScienceType st = commandButton->getScienceVec()[ i ];
  443. if( !player->hasScience( st ) )
  444. {
  445. missingScience = TRUE;
  446. break;
  447. }
  448. }
  449. //Determine the cost of the upgrade.
  450. costToBuild = upgradeTemplate->calcCostToBuild( player );
  451. if( costToBuild > 0 )
  452. {
  453. cost.format( TheGameText->fetch("TOOLTIP:Cost"), costToBuild );
  454. }
  455. if( missingScience )
  456. {
  457. if( !descrip.isEmpty() )
  458. descrip.concat(L"\n");
  459. requires.format( TheGameText->fetch( "CONTROLBAR:Requirements" ).str(), TheGameText->fetch( "CONTROLBAR:GeneralsPromotion" ).str() );
  460. descrip.concat( requires );
  461. }
  462. }
  463. }
  464. else if( st != SCIENCE_INVALID && !fireScienceButton )
  465. {
  466. TheScienceStore->getNameAndDescription(st, name, descrip);
  467. costToBuild = TheScienceStore->getSciencePurchaseCost( st );
  468. if( costToBuild > 0 )
  469. {
  470. cost.format( TheGameText->fetch("TOOLTIP:ScienceCost"), costToBuild );
  471. }
  472. // ask each prerequisite to give us a list of the non satisfied prerequisites
  473. if( thingTemplate )
  474. {
  475. for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
  476. {
  477. prereq = thingTemplate->getNthPrereq(i);
  478. requiresList = prereq->getRequiresList(player);
  479. if( requiresList != UnicodeString::TheEmptyString )
  480. {
  481. // make sure to put in 'returns' to space things correctly
  482. if (firstRequirement)
  483. firstRequirement = false;
  484. else
  485. requires.concat(L", ");
  486. }
  487. requires.concat(requiresList);
  488. }
  489. if( !requires.isEmpty() )
  490. {
  491. UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
  492. requires.format(requireFormat.str(), requires.str());
  493. if(!descrip.isEmpty())
  494. descrip.concat(L"\n");
  495. descrip.concat(requires);
  496. }
  497. }
  498. }
  499. }
  500. else if(tooltipWin)
  501. {
  502. if( tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:MoneyDisplay")))
  503. {
  504. name = TheGameText->fetch("CONTROLBAR:Money");
  505. descrip = TheGameText->fetch("CONTROLBAR:MoneyDescription");
  506. }
  507. else if(tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:PowerWindow")) )
  508. {
  509. name = TheGameText->fetch("CONTROLBAR:Power");
  510. descrip = TheGameText->fetch("CONTROLBAR:PowerDescription");
  511. Player *playerToDisplay = NULL;
  512. if(TheControlBar->isObserverControlBarOn())
  513. playerToDisplay = TheControlBar->getObserverLookAtPlayer();
  514. else
  515. playerToDisplay = ThePlayerList->getLocalPlayer();
  516. if( playerToDisplay && playerToDisplay->getEnergy() )
  517. {
  518. Energy *energy = playerToDisplay->getEnergy();
  519. descrip.format(descrip, energy->getProduction(), energy->getConsumption());
  520. }
  521. else
  522. {
  523. descrip.format(descrip, 0, 0);
  524. }
  525. }
  526. else if(tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:GeneralsExp")) )
  527. {
  528. name = TheGameText->fetch("CONTROLBAR:GeneralsExp");
  529. descrip = TheGameText->fetch("CONTROLBAR:GeneralsExpDescription");
  530. }
  531. else
  532. {
  533. DEBUG_ASSERTCRASH(FALSE, ("ControlBar::populateBuildTooltipLayout We attempted to call the popup tooltip on a game window that has yet to be hand coded in as this fuction was/is designed for only buttons but has been hacked to work with GameWindows."));
  534. return;
  535. }
  536. }
  537. GameWindow *win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextName"));
  538. if(win)
  539. {
  540. GadgetStaticTextSetText(win, name);
  541. }
  542. win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextCost"));
  543. if(win)
  544. {
  545. if( costToBuild > 0 )
  546. {
  547. win->winHide( FALSE );
  548. GadgetStaticTextSetText(win, cost);
  549. }
  550. else
  551. {
  552. win->winHide( TRUE );
  553. }
  554. }
  555. win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextDescription"));
  556. if(win)
  557. {
  558. static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
  559. static ICoord2D lastOffset = { 0, 0 };
  560. ICoord2D size, newSize, pos;
  561. Int diffSize;
  562. DisplayString *tempDString = TheDisplayStringManager->newDisplayString();
  563. win->winGetSize(&size.x, &size.y);
  564. tempDString->setFont(win->winGetFont());
  565. tempDString->setWordWrap(size.x - 10);
  566. tempDString->setText(descrip);
  567. tempDString->getSize(&newSize.x, &newSize.y);
  568. TheDisplayStringManager->freeDisplayString(tempDString);
  569. tempDString = NULL;
  570. diffSize = newSize.y - size.y;
  571. GameWindow *parent = m_buildToolTipLayout->getFirstWindow();
  572. if(!parent)
  573. return;
  574. parent->winGetSize(&size.x, &size.y);
  575. if(size.y + diffSize < 102) {
  576. diffSize = 102 - size.y;
  577. }
  578. parent->winSetSize(size.x, size.y + diffSize);
  579. parent->winGetPosition(&pos.x, &pos.y);
  580. // if(size.y + diffSize < 102)
  581. // {
  582. //
  583. // parent->winSetPosition(pos.x, pos.y - (102 - (newSize.y + size.y + diffSize) ));
  584. // }
  585. // else
  586. // heightChange = controlBarPos.y - m_defaultControlBarPosition.y;
  587. GameWindow *marker = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
  588. static ICoord2D basePos;
  589. if(!marker)
  590. {
  591. return;
  592. }
  593. TheControlBar->getBackgroundMarkerPos(&basePos.x, &basePos.y);
  594. ICoord2D curPos, offset;
  595. marker->winGetScreenPosition(&curPos.x,&curPos.y);
  596. offset.x = curPos.x - basePos.x;
  597. offset.y = curPos.y - basePos.y;
  598. parent->winSetPosition(pos.x, (pos.y - diffSize) + (offset.y - lastOffset.y));
  599. lastOffset.x = offset.x;
  600. lastOffset.y = offset.y;
  601. win->winGetSize(&size.x, &size.y);
  602. win->winSetSize(size.x, size.y + diffSize);
  603. GadgetStaticTextSetText(win, descrip);
  604. }
  605. m_buildToolTipLayout->hide(FALSE);
  606. }
  607. // ------------------------------------------------------------------------------------------------
  608. // ------------------------------------------------------------------------------------------------
  609. void ControlBar::hideBuildTooltipLayout()
  610. {
  611. if(theAnimateWindowManager && theAnimateWindowManager->isReversed())
  612. return;
  613. if(useAnimation && theAnimateWindowManager && TheGlobalData->m_animateWindows)
  614. theAnimateWindowManager->reverseAnimateWindow();
  615. else
  616. deleteBuildTooltipLayout();
  617. }
  618. void ControlBar::deleteBuildTooltipLayout( void )
  619. {
  620. m_showBuildToolTipLayout = FALSE;
  621. prevWindow= NULL;
  622. m_buildToolTipLayout->hide(TRUE);
  623. // if(!m_buildToolTipLayout)
  624. // return;
  625. //
  626. // m_buildToolTipLayout->destroyWindows();
  627. // m_buildToolTipLayout->deleteInstance();
  628. // m_buildToolTipLayout = NULL;
  629. if(theAnimateWindowManager)
  630. delete theAnimateWindowManager;
  631. theAnimateWindowManager = NULL;
  632. }