ControlBarOCLTimer.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: ControlBarOCLTimer.cpp //////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: Methods specific to the control bar OCL Timer context
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/NameKeyGenerator.h"
  30. #include "Common/ThingTemplate.h"
  31. #include "GameLogic/Object.h"
  32. #include "GameLogic/Module/OCLUpdate.h"
  33. #include "GameClient/Drawable.h"
  34. #include "GameClient/GameText.h"
  35. #include "GameClient/ControlBar.h"
  36. #include "GameClient/GameWindow.h"
  37. #include "GameClient/GameWindowManager.h"
  38. #include "GameClient/GadgetStaticText.h"
  39. #include "GameClient/GadgetProgressBar.h"
  40. //-------------------------------------------------------------------------------------------------
  41. //-------------------------------------------------------------------------------------------------
  42. void ControlBar::updateOCLTimerTextDisplay( UnsignedInt totalSeconds, Real percent )
  43. {
  44. UnicodeString text;
  45. static UnsignedInt descID = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:OCLTimerStaticText" );
  46. GameWindow *descWindow = TheWindowManager->winGetWindowFromId( NULL, descID );
  47. static UnsignedInt barID = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:OCLTimerProgressBar" );
  48. GameWindow *barWindow = TheWindowManager->winGetWindowFromId( NULL, barID );
  49. // santiy
  50. DEBUG_ASSERTCRASH( descWindow, ("Under construction window not found\n") );
  51. Int minutes = totalSeconds / 60;
  52. Int seconds = totalSeconds - (minutes * 60);
  53. // format the message
  54. if( seconds < 10 )
  55. text.format( TheGameText->fetch( "CONTROLBAR:OCLTimerDescWithPadding" ), minutes, seconds );
  56. else
  57. text.format( TheGameText->fetch( "CONTROLBAR:OCLTimerDesc" ), minutes, seconds );
  58. GadgetStaticTextSetText( descWindow, text );
  59. GadgetProgressBarSetProgress(barWindow, (percent * 100));
  60. // record this as the last time displayed
  61. m_displayedOCLTimerSeconds = totalSeconds;
  62. } // end updateOCLTimerTextDisplay
  63. //-------------------------------------------------------------------------------------------------
  64. /** Populate the interface for an OCL Timer context. */
  65. //-------------------------------------------------------------------------------------------------
  66. void ControlBar::populateOCLTimer( Object *creatorObject )
  67. {
  68. // sanity
  69. if( creatorObject == NULL )
  70. return;
  71. // get our parent window
  72. GameWindow *parent = m_contextParent[ CP_OCL_TIMER ];
  73. // set the sell button
  74. /// @todo srj -- remove hard-coding here, please
  75. const CommandButton *commandButton = findCommandButton( "Command_Sell" );
  76. NameKeyType id;
  77. id = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:OCLTimerSellButton" );
  78. GameWindow *win = TheWindowManager->winGetWindowFromId( parent, id );
  79. setControlCommand( win, commandButton );
  80. win->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES );
  81. // set the text percent and bar of our timer we are displaying
  82. updateContextOCLTimer( );
  83. // set the portrait for the thing being constructed
  84. setPortraitByObject( creatorObject );
  85. } // end populateUnderConstruction
  86. //-------------------------------------------------------------------------------------------------
  87. //-------------------------------------------------------------------------------------------------
  88. void ControlBar::updateContextOCLTimer( void )
  89. {
  90. Object *obj = m_currentSelectedDrawable->getObject();
  91. static const NameKeyType key_OCLUpdate = NAMEKEY( "OCLUpdate" );
  92. OCLUpdate *update = (OCLUpdate*)obj->findUpdateModule( key_OCLUpdate );
  93. UnsignedInt frames = update->getRemainingFrames();
  94. UnsignedInt seconds = frames / LOGICFRAMES_PER_SECOND;
  95. Real percent = update->getCountdownPercent();
  96. // if the time has changed since what was last shown to the user update the text
  97. if( m_displayedOCLTimerSeconds != seconds )
  98. updateOCLTimerTextDisplay( seconds, percent );
  99. } // end updatecontextUnderConstruction