ControlBarPopupDescription.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. ** Command & Conquer Generals(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 !defined(_PLAYTEST)
  174. if (TheGameLogic->isInReplayGame())
  175. return;
  176. #endif
  177. if (TheInGameUI->isQuitMenuVisible())
  178. return;
  179. if (TheDisconnectMenu && TheDisconnectMenu->isScreenVisible())
  180. return;
  181. // if (m_buildToolTipLayout)
  182. // {
  183. // m_buildToolTipLayout->destroyWindows();
  184. // m_buildToolTipLayout->deleteInstance();
  185. //
  186. // }
  187. m_showBuildToolTipLayout = TRUE;
  188. // m_buildToolTipLayout = TheWindowManager->winCreateLayout( "ControlBarPopupDescription.wnd" );
  189. // m_buildToolTipLayout->setUpdate(ControlBarPopupDescriptionUpdateFunc);
  190. populateBuildTooltipLayout(commandButton);
  191. }
  192. else
  193. {
  194. // we're a generic window
  195. if(!BitTest(cmdButton->winGetStyle(), GWS_USER_WINDOW) && !BitTest(cmdButton->winGetStyle(), GWS_STATIC_TEXT))
  196. return;
  197. populateBuildTooltipLayout(NULL, cmdButton);
  198. }
  199. m_buildToolTipLayout->hide(FALSE);
  200. if (useAnimation && TheGlobalData->m_animateWindows)
  201. {
  202. theAnimateWindowManager = NEW AnimateWindowManager;
  203. theAnimateWindowManager->reset();
  204. theAnimateWindowManager->registerGameWindow( m_buildToolTipLayout->getFirstWindow(), WIN_ANIMATION_SLIDE_RIGHT_FAST, TRUE, 200 );
  205. }
  206. }
  207. void ControlBar::repopulateBuildTooltipLayout( void )
  208. {
  209. if(!prevWindow || !m_buildToolTipLayout)
  210. return;
  211. if(!BitTest(prevWindow->winGetStyle(), GWS_PUSH_BUTTON))
  212. return;
  213. const CommandButton *commandButton = (const CommandButton *)GadgetButtonGetData(prevWindow);
  214. populateBuildTooltipLayout(commandButton);
  215. }
  216. void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton, GameWindow *tooltipWin)
  217. {
  218. if(!m_buildToolTipLayout)
  219. return;
  220. Player *player = ThePlayerList->getLocalPlayer();
  221. UnicodeString name, cost, descrip;
  222. UnicodeString requires = UnicodeString::TheEmptyString, requiresList;
  223. Bool firstRequirement = true;
  224. const ProductionPrerequisite *prereq;
  225. Bool fireScienceButton = false;
  226. if(commandButton)
  227. {
  228. const ThingTemplate *thingTemplate = commandButton->getThingTemplate();
  229. const UpgradeTemplate *upgradeTemplate = commandButton->getUpgradeTemplate();
  230. ScienceType st = SCIENCE_INVALID;
  231. if(commandButton->getScienceVec().size() > 1)
  232. {
  233. for(Int j = 0; j < commandButton->getScienceVec().size(); ++j)
  234. {
  235. st = commandButton->getScienceVec()[ j ];
  236. if( commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE )
  237. {
  238. if( !player->hasScience( st ) && j > 0 )
  239. {
  240. //If we're not looking at a command button that purchases a science, then
  241. //it means we are looking at a command button that can USE the science. This
  242. //means we want to get the description for the previous science -- the one
  243. //we can use, not purchase!
  244. st = commandButton->getScienceVec()[ j - 1 ];
  245. }
  246. //Now that we got the science for the button that executes the science, we need
  247. //to generate a simpler help text!
  248. fireScienceButton = true;
  249. break;
  250. }
  251. else if( !player->hasScience( st ) )
  252. {
  253. //Purchase science case. The first science we run into that we don't have, that's the
  254. //one we'll want to show!
  255. break;
  256. }
  257. }
  258. }
  259. else if(commandButton->getScienceVec().size() == 1 )
  260. {
  261. st = commandButton->getScienceVec()[ 0 ];
  262. }
  263. if( commandButton->getDescriptionLabel().isNotEmpty() )
  264. {
  265. descrip = TheGameText->fetch(commandButton->getDescriptionLabel());
  266. Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
  267. Object *selectedObject = draw ? draw->getObject() : NULL;
  268. if( selectedObject )
  269. {
  270. //Special case: Append status of overcharge on China power plant.
  271. if( commandButton->getCommandType() == GUI_COMMAND_TOGGLE_OVERCHARGE )
  272. {
  273. {
  274. OverchargeBehaviorInterface *obi;
  275. for( BehaviorModule **bmi = selectedObject->getBehaviorModules(); *bmi; ++bmi )
  276. {
  277. obi = (*bmi)->getOverchargeBehaviorInterface();
  278. if( obi )
  279. {
  280. descrip.concat( L"\n" );
  281. if( obi->isOverchargeActive() )
  282. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNukeReactorOverChargeIsOn" ) );
  283. else
  284. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNukeReactorOverChargeIsOff" ) );
  285. }
  286. }
  287. }
  288. } //End overcharge special case
  289. //Special case: When building units, the CanMakeType determines reasons for not being able to buy stuff.
  290. else if( thingTemplate )
  291. {
  292. CanMakeType makeType = TheBuildAssistant->canMakeUnit( selectedObject, commandButton->getThingTemplate() );
  293. switch( makeType )
  294. {
  295. case CANMAKE_NO_MONEY:
  296. descrip.concat( L"\n\n" );
  297. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
  298. break;
  299. case CANMAKE_QUEUE_FULL:
  300. descrip.concat( L"\n\n" );
  301. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
  302. break;
  303. case CANMAKE_PARKING_PLACES_FULL:
  304. descrip.concat( L"\n\n" );
  305. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseParkingFull" ) );
  306. break;
  307. case CANMAKE_MAXED_OUT_FOR_PLAYER:
  308. descrip.concat( L"\n\n" );
  309. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildUnitBecauseMaximumNumber" ) );
  310. break;
  311. //case CANMAKE_NO_PREREQ:
  312. // descrip.concat( L"\n\n" );
  313. // descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotBuildDueToPrerequisites" ) );
  314. // break;
  315. }
  316. }
  317. //Special case: When building upgrades
  318. else if( upgradeTemplate && !player->hasUpgradeInProduction( upgradeTemplate ) )
  319. {
  320. if( commandButton->getCommandType() == GUI_COMMAND_PLAYER_UPGRADE ||
  321. commandButton->getCommandType() == GUI_COMMAND_OBJECT_UPGRADE )
  322. {
  323. ProductionUpdateInterface *pui = selectedObject->getProductionUpdateInterface();
  324. if( pui && pui->getProductionCount() == MAX_BUILD_QUEUE_BUTTONS )
  325. {
  326. descrip.concat( L"\n\n" );
  327. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );
  328. }
  329. else if( !TheUpgradeCenter->canAffordUpgrade( ThePlayerList->getLocalPlayer(), upgradeTemplate, FALSE ) )
  330. {
  331. descrip.concat( L"\n\n" );
  332. descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipNotEnoughMoneyToBuild" ) );
  333. }
  334. }
  335. }
  336. }
  337. }
  338. name = TheGameText->fetch(commandButton->getTextLabel().str());
  339. if( thingTemplate && commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE )
  340. {
  341. //We are either looking at building a unit or a structure that may or may not have any
  342. //prerequisites.
  343. //Format the cost only when we have to pay for it.
  344. cost.format(TheGameText->fetch("TOOLTIP:Cost"), thingTemplate->calcCostToBuild(player));
  345. // ask each prerequisite to give us a list of the non satisfied prerequisites
  346. for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
  347. {
  348. prereq = thingTemplate->getNthPrereq(i);
  349. requiresList = prereq->getRequiresList(player);
  350. if( requiresList != UnicodeString::TheEmptyString )
  351. {
  352. // make sure to put in 'returns' to space things correctly
  353. if (firstRequirement)
  354. firstRequirement = false;
  355. else
  356. requires.concat(L", ");
  357. }
  358. requires.concat(requiresList);
  359. }
  360. if( !requires.isEmpty() )
  361. {
  362. UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
  363. requires.format(requireFormat.str(), requires.str());
  364. if(!descrip.isEmpty())
  365. descrip.concat(L"\n");
  366. descrip.concat(requires);
  367. }
  368. }
  369. else if( upgradeTemplate )
  370. {
  371. //We are looking at an upgrade purchase icon. Maybe we already purchased it?
  372. Bool hasUpgradeAlready = false;
  373. Bool hasConflictingUpgrade = false;
  374. Bool playerUpgradeButton = commandButton->getCommandType() == GUI_COMMAND_PLAYER_UPGRADE;
  375. Bool objectUpgradeButton = commandButton->getCommandType() == GUI_COMMAND_OBJECT_UPGRADE;
  376. //Check if the local player has the specified upgrade
  377. hasUpgradeAlready = player->hasUpgradeComplete( upgradeTemplate );
  378. if( !hasUpgradeAlready )
  379. {
  380. //Check if the first selected object has the specified upgrade.
  381. Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
  382. if( draw )
  383. {
  384. Object *object = draw->getObject();
  385. if( object )
  386. {
  387. hasUpgradeAlready = object->hasUpgrade( upgradeTemplate );
  388. if( objectUpgradeButton )
  389. {
  390. hasConflictingUpgrade = !object->affectedByUpgrade( upgradeTemplate );
  391. }
  392. }
  393. }
  394. }
  395. if( hasConflictingUpgrade && !hasUpgradeAlready )
  396. {
  397. if( commandButton->getConflictingLabel().isNotEmpty() )
  398. {
  399. descrip = TheGameText->fetch( commandButton->getConflictingLabel() );
  400. }
  401. else
  402. {
  403. descrip = TheGameText->fetch( "TOOLTIP:HasConflictingUpgradeDefault" );
  404. }
  405. }
  406. else if( hasUpgradeAlready && ( playerUpgradeButton || objectUpgradeButton ) )
  407. {
  408. //See if we can fetch the "already upgraded" text for this upgrade. If not.... use the default "fill me in".
  409. if( commandButton->getPurchasedLabel().isNotEmpty() )
  410. {
  411. descrip = TheGameText->fetch( commandButton->getPurchasedLabel() );
  412. }
  413. else
  414. {
  415. descrip = TheGameText->fetch( "TOOLTIP:AlreadyUpgradedDefault" );
  416. }
  417. }
  418. else if( !hasUpgradeAlready )
  419. {
  420. //Determine the cost of the upgrade.
  421. cost.format(TheGameText->fetch("TOOLTIP:Cost"),upgradeTemplate->calcCostToBuild(player));
  422. }
  423. }
  424. else if( st != SCIENCE_INVALID && !fireScienceButton )
  425. {
  426. TheScienceStore->getNameAndDescription(st, name, descrip);
  427. cost.format(TheGameText->fetch("TOOLTIP:ScienceCost"),TheScienceStore->getSciencePurchaseCost(st));
  428. // ask each prerequisite to give us a list of the non satisfied prerequisites
  429. if( thingTemplate )
  430. {
  431. for( Int i=0; i<thingTemplate->getPrereqCount(); i++ )
  432. {
  433. prereq = thingTemplate->getNthPrereq(i);
  434. requiresList = prereq->getRequiresList(player);
  435. if( requiresList != UnicodeString::TheEmptyString )
  436. {
  437. // make sure to put in 'returns' to space things correctly
  438. if (firstRequirement)
  439. firstRequirement = false;
  440. else
  441. requires.concat(L", ");
  442. }
  443. requires.concat(requiresList);
  444. }
  445. if( !requires.isEmpty() )
  446. {
  447. UnicodeString requireFormat = TheGameText->fetch("CONTROLBAR:Requirements");
  448. requires.format(requireFormat.str(), requires.str());
  449. if(!descrip.isEmpty())
  450. descrip.concat(L"\n");
  451. descrip.concat(requires);
  452. }
  453. }
  454. }
  455. }
  456. else if(tooltipWin)
  457. {
  458. if( tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:MoneyDisplay")))
  459. {
  460. name = TheGameText->fetch("CONTROLBAR:Money");
  461. descrip = TheGameText->fetch("CONTROLBAR:MoneyDescription");
  462. }
  463. else if(tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:PowerWindow")) )
  464. {
  465. name = TheGameText->fetch("CONTROLBAR:Power");
  466. descrip = TheGameText->fetch("CONTROLBAR:PowerDescription");
  467. Player *playerToDisplay = NULL;
  468. if(TheControlBar->isObserverControlBarOn())
  469. playerToDisplay = TheControlBar->getObserverLookAtPlayer();
  470. else
  471. playerToDisplay = ThePlayerList->getLocalPlayer();
  472. if( playerToDisplay && playerToDisplay->getEnergy() )
  473. {
  474. Energy *energy = playerToDisplay->getEnergy();
  475. descrip.format(descrip, energy->getProduction(), energy->getConsumption());
  476. }
  477. else
  478. {
  479. descrip.format(descrip, 0, 0);
  480. }
  481. }
  482. else if(tooltipWin == TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBar.wnd:GeneralsExp")) )
  483. {
  484. name = TheGameText->fetch("CONTROLBAR:GeneralsExp");
  485. descrip = TheGameText->fetch("CONTROLBAR:GeneralsExpDescription");
  486. }
  487. else
  488. {
  489. 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."));
  490. return;
  491. }
  492. }
  493. GameWindow *win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextName"));
  494. if(win)
  495. {
  496. GadgetStaticTextSetText(win, name);
  497. }
  498. win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextCost"));
  499. if(win)
  500. {
  501. GadgetStaticTextSetText(win, cost);
  502. }
  503. win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextDescription"));
  504. if(win)
  505. {
  506. static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
  507. static ICoord2D lastOffset = { 0, 0 };
  508. ICoord2D size, newSize, pos;
  509. Int diffSize;
  510. DisplayString *tempDString = TheDisplayStringManager->newDisplayString();
  511. win->winGetSize(&size.x, &size.y);
  512. tempDString->setFont(win->winGetFont());
  513. tempDString->setWordWrap(size.x - 10);
  514. tempDString->setText(descrip);
  515. tempDString->getSize(&newSize.x, &newSize.y);
  516. TheDisplayStringManager->freeDisplayString(tempDString);
  517. tempDString = NULL;
  518. diffSize = newSize.y - size.y;
  519. GameWindow *parent = m_buildToolTipLayout->getFirstWindow();
  520. if(!parent)
  521. return;
  522. parent->winGetSize(&size.x, &size.y);
  523. if(size.y + diffSize < 102) {
  524. diffSize = 102 - size.y;
  525. }
  526. parent->winSetSize(size.x, size.y + diffSize);
  527. parent->winGetPosition(&pos.x, &pos.y);
  528. // if(size.y + diffSize < 102)
  529. // {
  530. //
  531. // parent->winSetPosition(pos.x, pos.y - (102 - (newSize.y + size.y + diffSize) ));
  532. // }
  533. // else
  534. // heightChange = controlBarPos.y - m_defaultControlBarPosition.y;
  535. GameWindow *marker = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
  536. static ICoord2D basePos;
  537. if(!marker)
  538. {
  539. return;
  540. }
  541. TheControlBar->getBackgroundMarkerPos(&basePos.x, &basePos.y);
  542. ICoord2D curPos, offset;
  543. marker->winGetScreenPosition(&curPos.x,&curPos.y);
  544. offset.x = curPos.x - basePos.x;
  545. offset.y = curPos.y - basePos.y;
  546. parent->winSetPosition(pos.x, (pos.y - diffSize) + (offset.y - lastOffset.y));
  547. lastOffset.x = offset.x;
  548. lastOffset.y = offset.y;
  549. win->winGetSize(&size.x, &size.y);
  550. win->winSetSize(size.x, size.y + diffSize);
  551. GadgetStaticTextSetText(win, descrip);
  552. }
  553. m_buildToolTipLayout->hide(FALSE);
  554. }
  555. // ------------------------------------------------------------------------------------------------
  556. // ------------------------------------------------------------------------------------------------
  557. void ControlBar::hideBuildTooltipLayout()
  558. {
  559. if(theAnimateWindowManager && theAnimateWindowManager->isReversed())
  560. return;
  561. if(useAnimation && theAnimateWindowManager && TheGlobalData->m_animateWindows)
  562. theAnimateWindowManager->reverseAnimateWindow();
  563. else
  564. deleteBuildTooltipLayout();
  565. }
  566. void ControlBar::deleteBuildTooltipLayout( void )
  567. {
  568. m_showBuildToolTipLayout = FALSE;
  569. prevWindow= NULL;
  570. m_buildToolTipLayout->hide(TRUE);
  571. // if(!m_buildToolTipLayout)
  572. // return;
  573. //
  574. // m_buildToolTipLayout->destroyWindows();
  575. // m_buildToolTipLayout->deleteInstance();
  576. // m_buildToolTipLayout = NULL;
  577. if(theAnimateWindowManager)
  578. delete theAnimateWindowManager;
  579. theAnimateWindowManager = NULL;
  580. }