CPuzzleWindow.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. mapView->needFullUpdate = true;
  40. logo = std::make_shared<CPicture>(ImagePath::builtin("PUZZLOGO"), 607, 3);
  41. title = std::make_shared<CLabel>(700, 95, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, LIBRARY->generaltexth->allTexts[463]);
  42. resDataBar = std::make_shared<CResDataBar>(ImagePath::builtin("ARESBAR.bmp"), 3, 575, 32, 2, 85, 85);
  43. FactionID faction = GAME->interface()->cb->getStartInfo()->playerInfos.find(GAME->interface()->playerID)->second.castle;
  44. auto & puzzleMap = faction.toFaction()->puzzleMap;
  45. for(auto & elem : puzzleMap)
  46. {
  47. const SPuzzleInfo & info = elem;
  48. auto piece = std::make_shared<CPicture>(info.filename, info.position.x, info.position.y);
  49. piece->needRefresh = true;
  50. //piece that will slowly disappear
  51. if(info.whenUncovered <= GameConstants::PUZZLE_MAP_PIECES * discoveredRatio)
  52. {
  53. piecesToRemove.push_back(piece);
  54. piece->recActions = piece->recActions & ~SHOWALL;
  55. }
  56. else
  57. {
  58. visiblePieces.push_back(piece);
  59. }
  60. }
  61. }
  62. void CPuzzleWindow::showAll(Canvas & to)
  63. {
  64. CWindowObject::showAll(to);
  65. }
  66. void CPuzzleWindow::show(Canvas & to)
  67. {
  68. constexpr int animSpeed = 2;
  69. if(currentAlpha < animSpeed)
  70. {
  71. piecesToRemove.clear();
  72. }
  73. else
  74. {
  75. //update disappearing puzzles
  76. for(auto & piece : piecesToRemove)
  77. piece->setAlpha(currentAlpha);
  78. currentAlpha -= animSpeed;
  79. }
  80. CWindowObject::show(to);
  81. if(mapView->needFullUpdate && piecesToRemove.empty())
  82. mapView->needFullUpdate = false;
  83. }