INICommandButton.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: INICommandButton.cpp /////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: Command buttons are the atomic units we can configure into command sets to then
  26. // display in the context sensitive user interface
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Common/INI.h"
  31. #include "Common/SpecialPower.h"
  32. #include "GameClient/ControlBar.h"
  33. //-------------------------------------------------------------------------------------------------
  34. /** Parse a command button */
  35. //-------------------------------------------------------------------------------------------------
  36. void INI::parseCommandButtonDefinition( INI *ini )
  37. {
  38. ControlBar::parseCommandButtonDefinition(ini);
  39. }
  40. //-------------------------------------------------------------------------------------------------
  41. /** Parse a command button */
  42. //-------------------------------------------------------------------------------------------------
  43. void ControlBar::parseCommandButtonDefinition( INI *ini )
  44. {
  45. // read the name
  46. AsciiString name = ini->getNextToken();
  47. // find existing item if present
  48. CommandButton *button = TheControlBar->findNonConstCommandButton( name );
  49. if( button == NULL )
  50. {
  51. // allocate a new item
  52. button = TheControlBar->newCommandButton( name );
  53. if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES)
  54. {
  55. button->markAsOverride();
  56. }
  57. } // end if
  58. else if( ini->getLoadType() != INI_LOAD_CREATE_OVERRIDES )
  59. {
  60. DEBUG_CRASH(( "[LINE: %d in '%s'] Duplicate commandbutton %s found!", ini->getLineNum(), ini->getFilename().str(), name.str() ));
  61. }
  62. else
  63. {
  64. button = TheControlBar->newCommandButtonOverride( button );
  65. }
  66. // parse the ini definition
  67. ini->initFromINI( button, button->getFieldParse() );
  68. //Make sure buttons with special power templates also have the appropriate option set.
  69. const SpecialPowerTemplate *spTemplate = button->getSpecialPowerTemplate();
  70. Bool needsTemplate = BitTest( button->getOptions(), NEED_SPECIAL_POWER_SCIENCE );
  71. if( spTemplate && !needsTemplate )
  72. {
  73. DEBUG_CRASH( ("[LINE: %d in '%s'] CommandButton %s has SpecialPower = %s but the button also requires Options = NEED_SPECIAL_POWER_SCIENCE. Failure to do so will cause bugs such as invisible side shortcut buttons",
  74. ini->getLineNum(), ini->getFilename().str(), name.str(), spTemplate->getName().str() ) );
  75. }
  76. else if( !spTemplate && needsTemplate )
  77. {
  78. DEBUG_CRASH( ("[LINE: %d in '%s'] CommandButton %s has Options = NEED_SPECIAL_POWER_SCIENCE but doesn't specify a SpecialPower = xxxx. Please evaluate INI.",
  79. ini->getLineNum(), ini->getFilename().str(), name.str() ) );
  80. }
  81. } // end parseCommandButtonDefinition