CArtifactsOfHeroMain.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(
  20. std::bind(&CArtifactsOfHeroBase::clickPrassedArtPlace, this, _1, _2),
  21. std::bind(&CArtifactsOfHeroBase::showPopupArtPlace, this, _1, _2),
  22. position,
  23. std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
  24. addGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2));
  25. }
  26. CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
  27. {
  28. CArtifactsOfHeroBase::putBackPickedArtifact();
  29. }
  30. void CArtifactsOfHeroMain::enableArtifactsCostumeSwitcher()
  31. {
  32. addUsedEvents(AEventsReceiver::KEYBOARD);
  33. }
  34. void CArtifactsOfHeroMain::keyPressed(EShortcut key)
  35. {
  36. if(!shortcutPressed)
  37. {
  38. int saveIdx = vstd::find_pos(costumeSaveShortcuts, key);
  39. int loadIdx = vstd::find_pos(costumeLoadShortcuts, key);
  40. if (saveIdx != -1)
  41. {
  42. shortcutPressed = true;
  43. LOCPLINT->cb->manageHeroCostume(getHero()->id, saveIdx, true);
  44. return;
  45. }
  46. if (loadIdx != -1)
  47. {
  48. shortcutPressed = true;
  49. LOCPLINT->cb->manageHeroCostume(getHero()->id, loadIdx, false);
  50. return;
  51. }
  52. }
  53. }
  54. void CArtifactsOfHeroMain::keyReleased(EShortcut key)
  55. {
  56. if(vstd::contains(costumeSaveShortcuts, key) || vstd::contains(costumeLoadShortcuts, key))
  57. shortcutPressed = false;
  58. }