CArtifactsOfHeroMain.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. uint32_t costumeIdx;
  39. switch(key)
  40. {
  41. case EShortcut::HERO_COSTUME_0:
  42. costumeIdx = 0;
  43. break;
  44. case EShortcut::HERO_COSTUME_1:
  45. costumeIdx = 1;
  46. break;
  47. case EShortcut::HERO_COSTUME_2:
  48. costumeIdx = 2;
  49. break;
  50. case EShortcut::HERO_COSTUME_3:
  51. costumeIdx = 3;
  52. break;
  53. case EShortcut::HERO_COSTUME_4:
  54. costumeIdx = 4;
  55. break;
  56. case EShortcut::HERO_COSTUME_5:
  57. costumeIdx = 5;
  58. break;
  59. case EShortcut::HERO_COSTUME_6:
  60. costumeIdx = 6;
  61. break;
  62. case EShortcut::HERO_COSTUME_7:
  63. costumeIdx = 7;
  64. break;
  65. case EShortcut::HERO_COSTUME_8:
  66. costumeIdx = 8;
  67. break;
  68. case EShortcut::HERO_COSTUME_9:
  69. costumeIdx = 9;
  70. break;
  71. default:
  72. return;
  73. }
  74. shortcutPressed = true;
  75. LOCPLINT->cb->manageHeroCostume(getHero()->id, costumeIdx, GH.isKeyboardCtrlDown());
  76. }
  77. }
  78. void CArtifactsOfHeroMain::keyReleased(EShortcut key)
  79. {
  80. if(vstd::contains(costumesSwitcherHotkeys, key))
  81. shortcutPressed = false;
  82. }