CPuzzleWindow.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "../widgets/GraphicalPrimitiveCanvas.h"
  24. #include "../../lib/callback/CCallback.h"
  25. #include "../../lib/entities/faction/CFaction.h"
  26. #include "../../lib/entities/faction/CTownHandler.h"
  27. #include "../../lib/texts/CGeneralTextHandler.h"
  28. #include "../../lib/StartInfo.h"
  29. #include "../../lib/GameLibrary.h"
  30. CPuzzleWindow::CPuzzleWindow(const int3 & GrailPos, double discoveredRatio)
  31. : CWindowObject(PLAYER_COLORED | BORDERED, ImagePath::builtin("PUZZLE")),
  32. grailPos(GrailPos),
  33. currentAlpha(ColorRGBA::ALPHA_OPAQUE)
  34. {
  35. OBJECT_CONSTRUCTION;
  36. ENGINE->sound().playSound(soundBase::OBELISK);
  37. 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);
  38. quitb->setBorderColor(Colors::METALLIC_GOLD);
  39. mapView = std::make_shared<PuzzleMapView>(Point(8,8), Point(592, 544), grailPos);
  40. mapView->needFullUpdate = true;
  41. logo = std::make_shared<CPicture>(ImagePath::builtin("PUZZLOGO"), 607, 3);
  42. title = std::make_shared<CLabel>(700, 95, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, LIBRARY->generaltexth->allTexts[463]);
  43. resDataBar = std::make_shared<CResDataBar>(ImagePath::builtin("ARESBAR.bmp"), 3, 575, 32, 2, 85, 85);
  44. FactionID faction = GAME->interface()->cb->getStartInfo()->playerInfos.find(GAME->interface()->playerID)->second.castle;
  45. auto & puzzleMap = faction.toFaction()->puzzleMap;
  46. for(auto & elem : puzzleMap)
  47. {
  48. const SPuzzleInfo & info = elem;
  49. auto piece = std::make_shared<CPicture>(info.filename, info.position.x + 1, info.position.y);
  50. piece->needRefresh = true;
  51. //piece that will slowly disappear
  52. if(info.whenUncovered <= GameConstants::PUZZLE_MAP_PIECES * discoveredRatio)
  53. {
  54. piecesToRemove.push_back(piece);
  55. piece->recActions = piece->recActions & ~SHOWALL;
  56. }
  57. else
  58. {
  59. visiblePieces.push_back(piece);
  60. }
  61. }
  62. border = std::make_shared<GraphicalPrimitiveCanvas>(Rect(Point(6,6), Point(596, 548)));
  63. for(int i = 0; i < 3; i++)
  64. border->addRectangle(Point(i, i), Point(border->pos.w - i * 2, border->pos.h - i * 2), Colors::BLACK);
  65. }
  66. void CPuzzleWindow::showAll(Canvas & to)
  67. {
  68. CWindowObject::showAll(to);
  69. }
  70. void CPuzzleWindow::show(Canvas & to)
  71. {
  72. constexpr int animSpeed = 2;
  73. if(currentAlpha < animSpeed)
  74. {
  75. piecesToRemove.clear();
  76. }
  77. else
  78. {
  79. //update disappearing puzzles
  80. for(auto & piece : piecesToRemove)
  81. piece->setAlpha(currentAlpha);
  82. currentAlpha -= animSpeed;
  83. }
  84. CWindowObject::show(to);
  85. if(mapView->needFullUpdate && piecesToRemove.empty())
  86. mapView->needFullUpdate = false;
  87. }