SimpleComponentListBox.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #define SIMPLECOMPONENTLISTBOX_CPP
  2. /*************************************************************************************************\
  3. SimpleComponentListBox.cpp : Implementation of the SimpleComponentListBox component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "SimpleComponentListBox.h"
  9. #include "..\resource.h"
  10. #include "LogisticsVariant.h"
  11. #include "LogisticsComponent.h"
  12. #include "LogisticsData.h"
  13. #include "cmponent.h"
  14. //-------------------------------------------------------------------------------------------------
  15. ComponentListBox::ComponentListBox()
  16. {
  17. clickSFX = -1;
  18. highlightSFX = -1;
  19. disabledSFX = -1;
  20. helpID = IDS_HELP_WEAPONS;
  21. }
  22. ComponentListBox::~ComponentListBox()
  23. {
  24. aListBox::destroy();
  25. }
  26. void ComponentListBox::setMech( LogisticsVariant* pMech )
  27. {
  28. removeAllItems( true );
  29. if ( pMech )
  30. {
  31. LogisticsComponent* components[256];
  32. long componentCount = 256;
  33. pMech->getComponents( componentCount, components );
  34. setComponents( componentCount, components );
  35. int sensor = pMech->getSensorID();
  36. int ECM = pMech->getECM();
  37. if ( sensor > 0 )
  38. {
  39. aTextListItem* textItem = new aTextListItem( IDS_SALVAGE_AREA_COMPONENTS );
  40. textItem->setText( 32000 + sensor );
  41. textItem->setColor( 0xffc29b00 );
  42. textItem->setHelpID( IDS_HELP_COMP0 + sensor );
  43. AddItem( textItem );
  44. }
  45. if ( ECM > 0 )
  46. {
  47. aTextListItem* textItem = new aTextListItem( IDS_SALVAGE_AREA_COMPONENTS );
  48. textItem->setText( 32000 + ECM );
  49. textItem->setColor( 0xffc29b00 );
  50. textItem->setHelpID( IDS_HELP_COMP0 + ECM );
  51. AddItem( textItem );
  52. }
  53. }
  54. }
  55. void ComponentListBox::setVehicle( LogisticsVehicle* pVeh )
  56. {
  57. removeAllItems( true );
  58. if ( pVeh )
  59. {
  60. LogisticsComponent* components[256];
  61. long componentCount = 256;
  62. pVeh->getComponents( componentCount, components );
  63. setComponents( componentCount, components );
  64. }
  65. }
  66. void ComponentListBox::setComponents( long componentCount, LogisticsComponent** components )
  67. {
  68. LogisticsComponent* finalList[64];
  69. long finalListCount[64];
  70. // long stringIDs[4] = { IDS_SHORT, IDS_MEDIUM, IDS_LONG, IDS_COMPONENT};
  71. long colors[4] = { 0xff6E7C00, 0xff005392, 0xffA21600, 0xffc29b00};
  72. // long headerColors[4] = { 0xFFC8E100, 0xff0091FF, 0xFFFF0000, 0xffFF8A00 };
  73. for ( int i = 0; i < 4; i++ ) // do short, medium long
  74. {
  75. memset( finalList, 0, sizeof( long ) * 64 );
  76. memset( finalListCount, 0, sizeof( long ) * 64 );
  77. for ( int j = 0; j < componentCount; j++ )
  78. {
  79. if ( components[j]->getRangeType() == (LogisticsComponent::WEAPON_RANGE)i ) // short, med, long
  80. {
  81. bool bFound = 0;
  82. for ( int k = 0; k < 64; k++ )
  83. {
  84. if ( finalList[k] == components[j])
  85. {
  86. finalListCount[k]++;
  87. bFound = true;
  88. break;
  89. }
  90. else if ( !finalList[k] )
  91. break;
  92. }
  93. if ( !bFound )
  94. {
  95. finalList[k] = components[j];
  96. finalListCount[k]++;
  97. }
  98. }
  99. }
  100. if ( finalList[0] )
  101. {
  102. EString str;
  103. // add the header
  104. // no more headers, keeping code just in case
  105. // aTextListItem* textItem = new aTextListItem( IDS_SALVAGE_AREA_COMPONENTS );
  106. // textItem->setText( stringIDs[i] );
  107. // textItem->setColor( headerColors[i] );
  108. // AddItem( textItem );
  109. // add each componet
  110. for( int j = 0; j < 64; j++ )
  111. {
  112. if ( !finalList[j] )
  113. break;
  114. aTextListItem* textItem = new aTextListItem( IDS_SALVAGE_AREA_COMPONENTS );
  115. if ( finalList[j]->getType() != COMPONENT_FORM_JUMPJET )
  116. {
  117. str.Format( "%ld/%ld %s", finalListCount[j], finalListCount[j], finalList[j]->getName() );
  118. textItem->setText( str );
  119. }
  120. else
  121. textItem->setText( finalList[j]->getName() );
  122. textItem->setColor( colors[i] );
  123. textItem->setHelpID( IDS_HELP_COMP0 + finalList[j]->getID() );
  124. AddItem( textItem );
  125. }
  126. }
  127. }
  128. }
  129. //*************************************************************************************************
  130. // end of file ( SimpleComponentListBox.cpp )