LogisticsMechDisplay.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #define LOGISTICSMECHDISPLAY_CPP
  2. /*************************************************************************************************\
  3. LogisticsMechDisplay.cpp : Implementation of the LogisticsMechDisplay component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "LogisticsMechDisplay.h"
  9. #include "LogisticsMech.h"
  10. #include "mclib.h"
  11. #include "..\resource.h"
  12. #include "Prefs.h"
  13. LogisticsMechDisplay::LogisticsMechDisplay( )
  14. {
  15. pCurMech = NULL;
  16. helpTextArrayID = 7;
  17. }
  18. //-------------------------------------------------------------------------------------------------
  19. //-------------------------------------------------------------------------------------------------
  20. //-------------------------------------------------------------------------------------------------
  21. void LogisticsMechDisplay::update()
  22. {
  23. componentListBox.update();
  24. LogisticsScreen::update();
  25. mechCamera.update();
  26. }
  27. //-------------------------------------------------------------------------------------------------
  28. LogisticsMechDisplay::~LogisticsMechDisplay()
  29. {
  30. }
  31. //-------------------------------------------------------------------------------------------------
  32. void LogisticsMechDisplay::render(int xOffset, int yOffset)
  33. {
  34. componentListBox.move(xOffset, yOffset);
  35. componentListBox.render();
  36. componentListBox.move(-xOffset, -yOffset);
  37. if ( xOffset == 0 && yOffset == 0 ) // don't draw until we're done animating in or out
  38. mechCamera.render();
  39. for ( int i = 0; i < 3; i++ )
  40. {
  41. attributeMeters[i].render( xOffset, yOffset );
  42. }
  43. LogisticsScreen::render( xOffset, yOffset );
  44. }
  45. //-------------------------------------------------------------------------------------------------
  46. int LogisticsMechDisplay::init( )
  47. {
  48. FitIniFile file;
  49. FullPathFileName path;
  50. path.init( artPath, "mcl_mechinfo", ".fit" );
  51. if ( NO_ERR != file.open( path ) )
  52. {
  53. Assert( 0, 0, "Couldn't open mcl_mechinfo.fit" );
  54. return 0;
  55. }
  56. LogisticsScreen::init( file, "Static", "Text", "Rect", "Button" );
  57. mechCamera.init( rects[1].left(), rects[2].top(),
  58. rects[2].left(), rects[2].bottom() );
  59. char blockName[64];
  60. for ( int i = 0; i < 3; i++ )
  61. {
  62. sprintf( blockName, "AttributeMeter%ld", i );
  63. attributeMeters[i].init( &file, blockName );
  64. }
  65. componentListBox.init( rects[0].left(), rects[0].top(),
  66. rects[0].width(), rects[0].height() );
  67. return 1;
  68. }
  69. //-------------------------------------------------------------------------------------------------
  70. void LogisticsMechDisplay::setMech( LogisticsMech* pMech, bool bFromLB )
  71. {
  72. if ( pMech != pCurMech )
  73. {
  74. pCurMech = pMech;
  75. if ( pCurMech )
  76. {
  77. textObjects[0].setText( pCurMech->getChassisName() );
  78. textObjects[1].setText( pCurMech->getName() );
  79. char text[64];
  80. char tmpStr[64];
  81. cLoadString( IDS_MB_MECH_WEIGHT, tmpStr, 63 );
  82. sprintf( text, tmpStr, pCurMech->getMaxWeight(), (const char*)pCurMech->getMechClass() );
  83. textObjects[3].setText( text );
  84. long tmpColor;
  85. textObjects[2].setText( pCurMech->getVariant()->getOptimalRangeString( tmpColor ) );
  86. textObjects[2].setColor( tmpColor );
  87. sprintf( text, "%ld", pCurMech->getArmor() );
  88. textObjects[4].setText( text );
  89. sprintf( text, "%ld", pCurMech->getDisplaySpeed() );
  90. textObjects[5].setText( text );
  91. sprintf( text, "%ld", pCurMech->getJumpRange() * 25);
  92. textObjects[6].setText( text );
  93. attributeMeters[0].setValue( pCurMech->getArmor()/MAX_ARMOR_RANGE);
  94. attributeMeters[1].setValue( pCurMech->getSpeed()/MAX_SPEED_RANGE);
  95. attributeMeters[2].setValue( pCurMech->getJumpRange() * 25 / MAX_JUMP_RANGE);
  96. EString fileName = pMech->getFileName();
  97. int index = fileName.Find( '.' );
  98. fileName = fileName.Left( index );
  99. index = fileName.ReverseFind( '\\' );
  100. fileName = fileName.Right( fileName.Length() - index - 1 );
  101. mechCamera.setMech( fileName, prefs.baseColor, prefs.highlightColor, prefs.highlightColor );
  102. mechCamera.setScale( pMech->getVariant()->getChassis()->getScale() );
  103. componentListBox.setMech( pCurMech->getVariant() );
  104. }
  105. else
  106. {
  107. for ( int i = 0; i < 6; i++ )
  108. textObjects[i].setText( "" );
  109. attributeMeters[0].setValue( 0 );
  110. attributeMeters[1].setValue( 0 );
  111. attributeMeters[2].setValue( 0 );
  112. componentListBox.setMech( 0 );
  113. mechCamera.setMech( NULL );
  114. }
  115. }
  116. }
  117. //*************************************************************************************************
  118. // end of file ( LogisticsMechDisplay.cpp )