DamageBrush.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #define DAMAGEBRUSH_CPP
  2. /*************************************************************************************************\
  3. DamageBrush.cpp : Implementation of the DamageBrush component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "DamageBrush.h"
  9. #include "EditorObjectMgr.h"
  10. bool DamageBrush::beginPaint()
  11. {
  12. if ( !pAction )
  13. pAction = new ModifyBuildingAction();
  14. return true;
  15. }
  16. Action* DamageBrush::endPaint()
  17. {
  18. Action* pRetAction = NULL;
  19. if (pAction)
  20. {
  21. if ( pAction->isNotNull() )
  22. pRetAction = pAction;
  23. else
  24. {
  25. delete pAction;
  26. }
  27. }
  28. pAction = NULL;
  29. return pRetAction;
  30. }
  31. bool DamageBrush::paint( Stuff::Vector3D& worldPos, int screenX, int screenY )
  32. {
  33. EditorObject* pObject = const_cast<EditorObject*>(EditorObjectMgr::instance()->getObjectAtPosition( worldPos ));
  34. if ( pObject )
  35. {
  36. pAction->addBuildingInfo( *pObject );
  37. pObject->setDamage( damage );
  38. }
  39. return true;
  40. }
  41. bool DamageBrush::canPaint( Stuff::Vector3D& worldPos, int screenX, int screenY, int flags )
  42. {
  43. const EditorObject* pObject = EditorObjectMgr::instance()->getObjectAtPosition( worldPos );
  44. return pObject ? true : false;
  45. }
  46. bool DamageBrush::canPaintSelection( )
  47. {
  48. return EditorObjectMgr::instance()->hasSelection();
  49. }
  50. Action* DamageBrush::applyToSelection()
  51. {
  52. ModifyBuildingAction* pRetAction = new ModifyBuildingAction;
  53. EditorObjectMgr::EDITOR_OBJECT_LIST selectedObjectsList = EditorObjectMgr::instance()->getSelectedObjectList();
  54. EditorObjectMgr::EDITOR_OBJECT_LIST::EIterator it = selectedObjectsList.Begin();
  55. while (!it.IsDone())
  56. {
  57. EditorObject* pInfo = (*it);
  58. if ( pInfo )
  59. {
  60. pRetAction->addBuildingInfo( *pInfo );
  61. pInfo->setDamage( damage );
  62. }
  63. it++;
  64. }
  65. if (!(pRetAction->isNotNull()))
  66. {
  67. delete pRetAction; pRetAction = NULL;
  68. }
  69. return pRetAction;
  70. }
  71. //*************************************************************************************************
  72. // end of file ( DamageBrush.cpp )