CArtifactsOfHeroMain.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "../gui/CGuiHandler.h"
  13. #include "../CPlayerInterface.h"
  14. #include "../../lib/mapObjects/CGHeroInstance.h"
  15. #include "../../CCallback.h"
  16. #include "../../lib/networkPacks/ArtifactLocation.h"
  17. CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
  18. {
  19. init(position, std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
  20. enableGesture();
  21. }
  22. CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
  23. {
  24. CArtifactsOfHeroBase::putBackPickedArtifact();
  25. }
  26. void CArtifactsOfHeroMain::keyPressed(EShortcut key)
  27. {
  28. if(!shortcutPressed)
  29. {
  30. int saveIdx = vstd::find_pos(costumeSaveShortcuts, key);
  31. int loadIdx = vstd::find_pos(costumeLoadShortcuts, key);
  32. if (saveIdx != -1)
  33. {
  34. shortcutPressed = true;
  35. LOCPLINT->cb->manageHeroCostume(getHero()->id, saveIdx, true);
  36. return;
  37. }
  38. if (loadIdx != -1)
  39. {
  40. shortcutPressed = true;
  41. LOCPLINT->cb->manageHeroCostume(getHero()->id, loadIdx, false);
  42. return;
  43. }
  44. }
  45. }
  46. void CArtifactsOfHeroMain::keyReleased(EShortcut key)
  47. {
  48. if(vstd::contains(costumeSaveShortcuts, key) || vstd::contains(costumeLoadShortcuts, key))
  49. shortcutPressed = false;
  50. }