CPuzzleWindow.cpp 2.7 KB

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