2012-07-06 22:12:04 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CQuestLog.h"
|
|
|
|
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../CCallback.h"
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
#include "UIFramework/SDL_Extensions.h"
|
|
|
|
#include "CBitmapHandler.h"
|
|
|
|
#include "CDefHandler.h"
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "CPlayerInterface.h"
|
|
|
|
#include "CConfigHandler.h"
|
|
|
|
|
|
|
|
#include "../lib/CGameState.h"
|
|
|
|
#include "../lib/CArtHandler.h"
|
|
|
|
#include "../lib/NetPacks.h"
|
2012-07-07 11:45:45 +03:00
|
|
|
#include "../lib/CObjectHandler.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
|
|
|
#include "UIFramework/CGuiHandler.h"
|
|
|
|
#include "UIFramework/CIntObjectClasses.h"
|
|
|
|
|
2012-07-08 09:33:41 +03:00
|
|
|
/*
|
|
|
|
* CQuestLog.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-07-06 22:12:04 +03:00
|
|
|
struct QuestInfo;
|
2012-07-07 11:45:45 +03:00
|
|
|
class CAdvmapInterface;
|
|
|
|
|
|
|
|
void CQuestLabel::clickLeft(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2012-07-08 09:33:41 +03:00
|
|
|
void CQuestLabel::showAll(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
CBoundedLabel::showAll (to);
|
|
|
|
}
|
|
|
|
|
2012-07-07 11:45:45 +03:00
|
|
|
void CQuestMinimap::clickLeft(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
{
|
|
|
|
moveAdvMapSelection();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestMinimap::update()
|
|
|
|
{
|
|
|
|
CMinimap::update();
|
|
|
|
if (currentQuest)
|
|
|
|
addQuestMarks (currentQuest);
|
|
|
|
}
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2012-07-06 23:19:54 +03:00
|
|
|
CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
|
2012-07-06 22:12:04 +03:00
|
|
|
CWindowObject(PLAYER_COLORED, "QuestLog.pcx"),
|
2012-07-07 11:45:45 +03:00
|
|
|
quests (Quests), slider (NULL),
|
|
|
|
questIndex(0), currentQuest(NULL)
|
2012-07-06 22:12:04 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::init()
|
|
|
|
{
|
|
|
|
minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
|
2012-07-08 09:33:41 +03:00
|
|
|
description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk);
|
2012-07-06 22:12:04 +03:00
|
|
|
ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CQuestLog::close,this), 547, 401, "IOKAY.DEF", SDLK_RETURN);
|
2012-07-07 11:45:45 +03:00
|
|
|
|
|
|
|
if (quests.size() > QUEST_COUNT)
|
2012-07-08 09:33:41 +03:00
|
|
|
slider = new CSlider(203, 199, 230, boost::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, 0);
|
2012-07-07 11:45:45 +03:00
|
|
|
|
|
|
|
auto map = LOCPLINT->cb->getVisibilityMap(); //TODO: another function to get all tiles?
|
|
|
|
|
|
|
|
for (int g = 0; g < map.size(); ++g)
|
|
|
|
for (int h = 0; h < map[g].size(); ++h)
|
|
|
|
for (int y = 0; y < map[g][h].size(); ++y)
|
|
|
|
minimap->showTile (int3 (g, h, y));
|
|
|
|
|
|
|
|
for (int i = 0; i < quests.size(); ++i)
|
|
|
|
{
|
2012-07-08 09:33:41 +03:00
|
|
|
MetaString text;
|
2012-07-08 11:42:03 +03:00
|
|
|
quests[i].quest->getRolloverText (text, false);
|
2012-07-08 09:33:41 +03:00
|
|
|
if (quests[i].obj)
|
|
|
|
text.addReplacement (quests[i].obj->getHoverText()); //get name of the object
|
|
|
|
CQuestLabel * label = new CQuestLabel (28, 199 + i * 24, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text.toString());
|
2012-07-07 11:45:45 +03:00
|
|
|
label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
|
2012-07-08 09:33:41 +03:00
|
|
|
label->setBounds (172, 30);
|
2012-07-07 11:45:45 +03:00
|
|
|
labels.push_back(label);
|
|
|
|
}
|
|
|
|
|
2012-07-08 09:33:41 +03:00
|
|
|
recreateQuestList (0);
|
2012-07-07 11:45:45 +03:00
|
|
|
showAll (screen2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::showAll(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
CIntObject::showAll (to);
|
|
|
|
BOOST_FOREACH (auto label, labels)
|
|
|
|
{
|
2012-07-08 09:33:41 +03:00
|
|
|
label->show(to); //shows only if active
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
2012-07-08 09:33:41 +03:00
|
|
|
if (labels.size() && labels[questIndex]->active)
|
|
|
|
{
|
2012-07-07 11:45:45 +03:00
|
|
|
CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::MetallicGold.r, Colors::MetallicGold.g, Colors::MetallicGold.b));
|
2012-07-08 09:33:41 +03:00
|
|
|
}
|
2012-07-07 11:45:45 +03:00
|
|
|
description->show(to);
|
|
|
|
minimap->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::recreateQuestList (int newpos)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < labels.size(); ++i)
|
|
|
|
{
|
2012-07-08 09:33:41 +03:00
|
|
|
labels[i]->pos = Rect (pos.x + 28, pos.y + 207 + (i-newpos) * 25, 173, 23);
|
2012-07-07 11:45:45 +03:00
|
|
|
if (i >= newpos && i < newpos + QUEST_COUNT)
|
|
|
|
{
|
|
|
|
labels[i]->activate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labels[i]->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::selectQuest (int which)
|
|
|
|
{
|
|
|
|
questIndex = which;
|
|
|
|
currentQuest = &quests[which];
|
|
|
|
minimap->currentQuest = currentQuest;
|
|
|
|
if (currentQuest->obj)
|
|
|
|
{
|
|
|
|
adventureInt->centerOn (currentQuest->obj->pos);
|
|
|
|
}
|
2012-07-08 09:33:41 +03:00
|
|
|
MetaString text;
|
|
|
|
std::vector<Component> components; //TODO: display them
|
2012-07-08 11:42:03 +03:00
|
|
|
currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
|
2012-07-08 09:33:41 +03:00
|
|
|
description->setTxt (text.toString()); //TODO: use special log entry text
|
2012-07-07 11:45:45 +03:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::sliderMoved (int newpos)
|
|
|
|
{
|
|
|
|
recreateQuestList (newpos); //move components
|
|
|
|
redraw();
|
2012-07-06 22:12:04 +03:00
|
|
|
}
|