CPuzzleWindow.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * CPuzzleWindow.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 "CPuzzleWindow.h"
  12. #include "../CPlayerInterface.h"
  13. #include "../adventureMap/CResDataBar.h"
  14. #include "../GameEngine.h"
  15. #include "../GameInstance.h"
  16. #include "../gui/TextAlignment.h"
  17. #include "../gui/Shortcut.h"
  18. #include "../mapView/MapView.h"
  19. #include "../media/ISoundPlayer.h"
  20. #include "../widgets/Buttons.h"
  21. #include "../widgets/Images.h"
  22. #include "../widgets/TextControls.h"
  23. #include "../../CCallback.h"
  24. #include "../../lib/entities/faction/CFaction.h"
  25. #include "../../lib/entities/faction/CTownHandler.h"
  26. #include "../../lib/texts/CGeneralTextHandler.h"
  27. #include "../../lib/StartInfo.h"
  28. #include "../../lib/GameLibrary.h"
  29. CPuzzleWindow::CPuzzleWindow(const int3 & GrailPos, double discoveredRatio)
  30. : CWindowObject(PLAYER_COLORED | BORDERED, ImagePath::builtin("PUZZLE")),
  31. grailPos(GrailPos),
  32. currentAlpha(ColorRGBA::ALPHA_OPAQUE)
  33. {
  34. OBJECT_CONSTRUCTION;
  35. ENGINE->sound().playSound(soundBase::OBELISK);
  36. quitb = std::make_shared<CButton>(Point(670, 538), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(LIBRARY->generaltexth->allTexts[599]), std::bind(&CPuzzleWindow::close, this), EShortcut::GLOBAL_RETURN);
  37. quitb->setBorderColor(Colors::METALLIC_GOLD);
  38. mapView = std::make_shared<PuzzleMapView>(Point(8,9), Point(591, 544), grailPos);
  39. logo = std::make_shared<CPicture>(ImagePath::builtin("PUZZLOGO"), 607, 3);
  40. title = std::make_shared<CLabel>(700, 95, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, LIBRARY->generaltexth->allTexts[463]);
  41. resDataBar = std::make_shared<CResDataBar>(ImagePath::builtin("ARESBAR.bmp"), 3, 575, 32, 2, 85, 85);
  42. int faction = GAME->interface()->cb->getStartInfo()->playerInfos.find(GAME->interface()->playerID)->second.castle;
  43. auto & puzzleMap = (*LIBRARY->townh)[faction]->puzzleMap;
  44. for(auto & elem : puzzleMap)
  45. {
  46. const SPuzzleInfo & info = elem;
  47. auto piece = std::make_shared<CPicture>(info.filename, info.position.x, info.position.y);
  48. piece->needRefresh = true;
  49. //piece that will slowly disappear
  50. if(info.whenUncovered <= GameConstants::PUZZLE_MAP_PIECES * discoveredRatio)
  51. {
  52. piecesToRemove.push_back(piece);
  53. piece->recActions = piece->recActions & ~SHOWALL;
  54. }
  55. else
  56. {
  57. visiblePieces.push_back(piece);
  58. }
  59. }
  60. }
  61. void CPuzzleWindow::showAll(Canvas & to)
  62. {
  63. CWindowObject::showAll(to);
  64. }
  65. void CPuzzleWindow::show(Canvas & to)
  66. {
  67. constexpr int animSpeed = 2;
  68. if(currentAlpha < animSpeed)
  69. {
  70. piecesToRemove.clear();
  71. }
  72. else
  73. {
  74. //update disappearing puzzles
  75. for(auto & piece : piecesToRemove)
  76. piece->setAlpha(currentAlpha);
  77. currentAlpha -= animSpeed;
  78. }
  79. CWindowObject::show(to);
  80. }