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>
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
#include "CBitmapHandler.h"
|
|
|
|
#include "CDefHandler.h"
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2012-09-29 13:59:43 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
|
|
|
#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
|
|
|
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
#include "gui/CIntObjectClasses.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
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-21 23:16:54 +03:00
|
|
|
CQuestIcon::CQuestIcon (const std::string &defname, int index, int x, int y) :
|
|
|
|
CAnimImage(defname, index, 0, x, y)
|
2012-07-08 19:36:20 +03:00
|
|
|
{
|
|
|
|
addUsedEvents(LCLICK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestIcon::clickLeft(tribool down, bool previousState)
|
2012-07-07 11:45:45 +03:00
|
|
|
{
|
|
|
|
if (down)
|
2012-07-08 19:36:20 +03:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestIcon::showAll(SDL_Surface * to)
|
|
|
|
{
|
2012-07-21 23:16:54 +03:00
|
|
|
CSDL_Ext::CClipRectGuard guard(to, parent->pos);
|
|
|
|
CAnimImage::showAll(to);
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
2012-07-08 19:36:20 +03:00
|
|
|
CQuestMinimap::CQuestMinimap (const Rect & position) :
|
|
|
|
CMinimap (position),
|
|
|
|
currentQuest (NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestMinimap::addQuestMarks (const QuestInfo * q)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
icons.clear();
|
|
|
|
|
|
|
|
int3 tile;
|
|
|
|
if (q->obj)
|
|
|
|
{
|
|
|
|
tile = q->obj->pos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tile = q->tile;
|
|
|
|
}
|
2012-07-21 23:16:54 +03:00
|
|
|
int x,y;
|
2012-07-08 19:36:20 +03:00
|
|
|
minimap->tileToPixels (tile, x, y);
|
|
|
|
|
2012-07-21 23:16:54 +03:00
|
|
|
CQuestIcon * pic = new CQuestIcon ("VwSymbol.def", 3, x, y);
|
|
|
|
|
|
|
|
pic->moveBy (Point ( -pic->pos.w/2, -pic->pos.h/2));
|
2012-07-08 19:36:20 +03:00
|
|
|
pic->callback = boost::bind (&CQuestMinimap::iconClicked, this);
|
2012-07-21 23:16:54 +03:00
|
|
|
|
2012-07-08 19:36:20 +03:00
|
|
|
icons.push_back(pic);
|
|
|
|
}
|
|
|
|
|
2012-07-07 11:45:45 +03:00
|
|
|
void CQuestMinimap::update()
|
|
|
|
{
|
|
|
|
CMinimap::update();
|
|
|
|
if (currentQuest)
|
|
|
|
addQuestMarks (currentQuest);
|
|
|
|
}
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2012-07-08 19:36:20 +03:00
|
|
|
void CQuestMinimap::iconClicked()
|
|
|
|
{
|
|
|
|
if (currentQuest->obj)
|
|
|
|
adventureInt->centerOn (currentQuest->obj->pos);
|
|
|
|
moveAdvMapSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestMinimap::showAll(SDL_Surface * to)
|
|
|
|
{
|
2012-07-21 23:16:54 +03:00
|
|
|
CIntObject::showAll(to); // blitting IntObject directly to hide radar
|
2012-07-08 19:36:20 +03:00
|
|
|
BOOST_FOREACH (auto pic, icons)
|
|
|
|
pic->showAll(to);
|
|
|
|
}
|
|
|
|
|
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-19 21:52:44 +03:00
|
|
|
questIndex(0),
|
|
|
|
currentQuest(NULL),
|
|
|
|
quests (Quests),
|
|
|
|
slider(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-11-11 15:23:31 +03:00
|
|
|
description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
|
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
|
|
|
|
|
|
|
for (int i = 0; i < quests.size(); ++i)
|
|
|
|
{
|
2012-07-08 09:33:41 +03:00
|
|
|
MetaString text;
|
2012-10-03 17:49:29 +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
|
2012-11-11 15:23:31 +03:00
|
|
|
CQuestLabel * label = new CQuestLabel (28, 199 + i * 24, FONT_SMALL, TOPLEFT, Colors::WHITE, 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
|
|
|
}
|
|
|
|
|
|
|
|
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-11-20 20:53:45 +03:00
|
|
|
CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
|
2012-07-08 09:33:41 +03:00
|
|
|
}
|
2012-07-07 11:45:45 +03:00
|
|
|
description->show(to);
|
|
|
|
minimap->update();
|
2012-07-08 19:36:20 +03:00
|
|
|
minimap->show(to);
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-07-08 19:36:20 +03:00
|
|
|
|
2012-07-08 09:33:41 +03:00
|
|
|
MetaString text;
|
|
|
|
std::vector<Component> components; //TODO: display them
|
2012-10-03 17:49:29 +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-19 21:52:44 +03:00
|
|
|
}
|