ControlBarUnderConstruction.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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: ControlBarUnderConstruction.cpp //////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: Methods specific to the control bar under construction 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/UpdateModule.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. //-------------------------------------------------------------------------------------------------
  40. //-------------------------------------------------------------------------------------------------
  41. void ControlBar::updateConstructionTextDisplay( Object *obj )
  42. {
  43. UnicodeString text;
  44. static UnsignedInt descID = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:UnderConstructionDesc" );
  45. GameWindow *descWindow = TheWindowManager->winGetWindowFromId( NULL, descID );
  46. // santiy
  47. DEBUG_ASSERTCRASH( descWindow, ("Under construction window not found\n") );
  48. // format the message
  49. text.format( TheGameText->fetch( "CONTROLBAR:UnderConstructionDesc" ),
  50. obj->getConstructionPercent() );
  51. GadgetStaticTextSetText( descWindow, text );
  52. // record this as the last percentage displayed
  53. m_displayedConstructPercent = obj->getConstructionPercent();
  54. } // end updateConstructionTextDisplay
  55. //-------------------------------------------------------------------------------------------------
  56. /** Populate the interface for an under construction context. */
  57. //-------------------------------------------------------------------------------------------------
  58. void ControlBar::populateUnderConstruction( Object *objectUnderConstruction )
  59. {
  60. // sanity
  61. if( objectUnderConstruction == NULL )
  62. return;
  63. // get our parent window
  64. GameWindow *parent = m_contextParent[ CP_UNDER_CONSTRUCTION ];
  65. // set the cancel construction button
  66. /// @todo srj -- remove hard-coding here, please
  67. const CommandButton *commandButton = findCommandButton( "Command_CancelConstruction" );
  68. NameKeyType id;
  69. id = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonCancelConstruction" );
  70. GameWindow *win = TheWindowManager->winGetWindowFromId( parent, id );
  71. setControlCommand( win, commandButton );
  72. win->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES );
  73. // set the text description of what is building
  74. updateConstructionTextDisplay( objectUnderConstruction );
  75. // set the portrait for the thing being constructed
  76. setPortraitByObject( objectUnderConstruction );
  77. // and show the rally point, if it should have one,
  78. ExitInterface *exit = objectUnderConstruction->getObjectExitInterface();
  79. if( exit )
  80. showRallyPoint( exit->getRallyPoint() );
  81. } // end populateUnderConstruction
  82. //-------------------------------------------------------------------------------------------------
  83. //-------------------------------------------------------------------------------------------------
  84. void ControlBar::updateContextUnderConstruction( void )
  85. {
  86. Object *obj = m_currentSelectedDrawable->getObject();
  87. // if the object is no longer under construction switch to a new appropriate context
  88. if( !obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  89. {
  90. evaluateContextUI();
  91. return;
  92. } // end if
  93. // if the construction percent has changed since what was last shown to the user update the text
  94. if( m_displayedConstructPercent != obj->getConstructionPercent() )
  95. updateConstructionTextDisplay( obj );
  96. } // end updatecontextUnderConstruction