CArtifactsOfHeroMain.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * CArtifactsOfHeroMain.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CArtifactsOfHeroMain.h"
  12. #include "../GameEngine.h"
  13. #include "../GameInstance.h"
  14. #include "../CPlayerInterface.h"
  15. #include "../../lib/callback/CCallback.h"
  16. #include "../../lib/mapObjects/CGHeroInstance.h"
  17. #include "../../lib/networkPacks/ArtifactLocation.h"
  18. CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
  19. {
  20. init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
  21. setClickPressedArtPlacesCallback(std::bind(&CArtifactsOfHeroBase::clickPressedArtPlace, this, _1, _2));
  22. setShowPopupArtPlacesCallback(std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2));
  23. enableGesture();
  24. }
  25. CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
  26. {
  27. if(curHero)
  28. CArtifactsOfHeroBase::putBackPickedArtifact();
  29. }
  30. void CArtifactsOfHeroMain::keyPressed(EShortcut key)
  31. {
  32. if(!shortcutPressed)
  33. {
  34. int saveIdx = vstd::find_pos(costumeSaveShortcuts, key);
  35. int loadIdx = vstd::find_pos(costumeLoadShortcuts, key);
  36. if (saveIdx != -1)
  37. {
  38. shortcutPressed = true;
  39. GAME->interface()->cb->manageHeroCostume(getHero()->id, saveIdx, true);
  40. return;
  41. }
  42. if (loadIdx != -1)
  43. {
  44. shortcutPressed = true;
  45. GAME->interface()->cb->manageHeroCostume(getHero()->id, loadIdx, false);
  46. return;
  47. }
  48. }
  49. }
  50. void CArtifactsOfHeroMain::keyReleased(EShortcut key)
  51. {
  52. if(vstd::contains(costumeSaveShortcuts, key) || vstd::contains(costumeLoadShortcuts, key))
  53. shortcutPressed = false;
  54. }