2023-02-20 22:16:50 +02:00
|
|
|
/*
|
|
|
|
* CPuzzleWindow.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CPuzzleWindow.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CMusicHandler.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../adventureMap/CResDataBar.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/TextAlignment.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-03-01 12:31:23 +02:00
|
|
|
#include "../mapView/MapView.h"
|
2023-02-20 22:16:50 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../widgets/Images.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CTownHandler.h"
|
|
|
|
#include "../../lib/StartInfo.h"
|
|
|
|
|
|
|
|
CPuzzleWindow::CPuzzleWindow(const int3 & GrailPos, double discoveredRatio)
|
2023-08-23 14:07:50 +02:00
|
|
|
: CWindowObject(PLAYER_COLORED | BORDERED, ImagePath::builtin("PUZZLE")),
|
2023-02-20 22:16:50 +02:00
|
|
|
grailPos(GrailPos),
|
2023-07-31 18:50:55 +02:00
|
|
|
currentAlpha(ColorRGBA::ALPHA_OPAQUE)
|
2023-02-20 22:16:50 +02:00
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
CCS->soundh->playSound(soundBase::OBELISK);
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
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);
|
2023-02-20 22:16:50 +02:00
|
|
|
quitb->setBorderColor(Colors::METALLIC_GOLD);
|
|
|
|
|
2023-02-26 18:17:53 +02:00
|
|
|
mapView = std::make_shared<PuzzleMapView>(Point(8,9), Point(591, 544), grailPos);
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
logo = std::make_shared<CPicture>(ImagePath::builtin("PUZZLOGO"), 607, 3);
|
2023-02-20 22:16:50 +02:00
|
|
|
title = std::make_shared<CLabel>(700, 95, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[463]);
|
2023-09-04 13:29:02 +02:00
|
|
|
resDataBar = std::make_shared<CResDataBar>(ImagePath::builtin("ARESBAR.bmp"), 3, 575, 32, 2, 85, 85);
|
2023-02-20 22:16:50 +02:00
|
|
|
|
|
|
|
int faction = LOCPLINT->cb->getStartInfo()->playerInfos.find(LOCPLINT->playerID)->second.castle;
|
|
|
|
|
|
|
|
auto & puzzleMap = (*CGI->townh)[faction]->puzzleMap;
|
|
|
|
|
|
|
|
for(auto & elem : puzzleMap)
|
|
|
|
{
|
|
|
|
const SPuzzleInfo & info = elem;
|
|
|
|
|
|
|
|
auto piece = std::make_shared<CPicture>(info.filename, info.x, info.y);
|
|
|
|
|
|
|
|
//piece that will slowly disappear
|
|
|
|
if(info.whenUncovered <= GameConstants::PUZZLE_MAP_PIECES * discoveredRatio)
|
|
|
|
{
|
|
|
|
piecesToRemove.push_back(piece);
|
|
|
|
piece->needRefresh = true;
|
|
|
|
piece->recActions = piece->recActions & ~SHOWALL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
visiblePieces.push_back(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void CPuzzleWindow::showAll(Canvas & to)
|
2023-02-20 22:16:50 +02:00
|
|
|
{
|
|
|
|
CWindowObject::showAll(to);
|
|
|
|
}
|
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void CPuzzleWindow::show(Canvas & to)
|
2023-02-20 22:16:50 +02:00
|
|
|
{
|
2024-02-12 13:22:54 +02:00
|
|
|
constexpr int animSpeed = 2;
|
2023-02-20 22:16:50 +02:00
|
|
|
|
|
|
|
if(currentAlpha < animSpeed)
|
|
|
|
{
|
|
|
|
piecesToRemove.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//update disappearing puzzles
|
|
|
|
for(auto & piece : piecesToRemove)
|
|
|
|
piece->setAlpha(currentAlpha);
|
|
|
|
currentAlpha -= animSpeed;
|
|
|
|
}
|
|
|
|
CWindowObject::show(to);
|
|
|
|
}
|