CPuzzleWindow.cpp 2.7 KB

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