2012-07-06 22:12:04 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CQuestLog.h"
|
|
|
|
|
2014-07-13 18:39:45 +03:00
|
|
|
#include "CAdvmapInterface.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CBitmapHandler.h"
|
|
|
|
#include "../CDefHandler.h"
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../Graphics.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/SDL_Extensions.h"
|
2015-02-14 03:21:31 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CArtHandler.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGameState.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/NetPacksBase.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)
|
2013-08-29 16:46:27 +03:00
|
|
|
CMultiLineLabel::showAll (to);
|
2012-07-08 09:33:41 +03:00
|
|
|
}
|
|
|
|
|
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),
|
2013-06-26 14:18:27 +03:00
|
|
|
currentQuest (nullptr)
|
2012-07-08 19:36:20 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-02-14 20:31:56 +02:00
|
|
|
|
2012-07-21 23:16:54 +03:00
|
|
|
int x,y;
|
2012-07-08 19:36:20 +03:00
|
|
|
minimap->tileToPixels (tile, x, y);
|
|
|
|
|
2015-02-14 01:13:17 +02:00
|
|
|
if (level != tile.z)
|
|
|
|
setLevel(tile.z);
|
|
|
|
|
2015-02-14 20:31:56 +02:00
|
|
|
auto pic = make_shared<CQuestIcon>("VwSymbol.def", 3, x, y);
|
2012-07-21 23:16:54 +03:00
|
|
|
|
|
|
|
pic->moveBy (Point ( -pic->pos.w/2, -pic->pos.h/2));
|
2014-08-04 21:33:59 +03:00
|
|
|
pic->callback = std::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);
|
2014-09-18 17:46:35 +03:00
|
|
|
//moveAdvMapSelection();
|
2012-07-08 19:36:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestMinimap::showAll(SDL_Surface * to)
|
|
|
|
{
|
2012-07-21 23:16:54 +03:00
|
|
|
CIntObject::showAll(to); // blitting IntObject directly to hide radar
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto pic : icons)
|
2012-07-08 19:36:20 +03:00
|
|
|
pic->showAll(to);
|
|
|
|
}
|
|
|
|
|
2012-07-06 23:19:54 +03:00
|
|
|
CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
|
2015-02-14 19:39:53 +02:00
|
|
|
CWindowObject(PLAYER_COLORED | BORDERED, "questDialog"),
|
2012-07-19 21:52:44 +03:00
|
|
|
questIndex(0),
|
2013-06-26 14:18:27 +03:00
|
|
|
currentQuest(nullptr),
|
2015-02-14 03:21:31 +02:00
|
|
|
componentsBox(nullptr),
|
2012-07-19 21:52:44 +03:00
|
|
|
quests (Quests),
|
2015-02-17 04:47:49 +02:00
|
|
|
hideComplete(false),
|
2013-06-26 14:18:27 +03:00
|
|
|
slider(nullptr)
|
2012-07-06 22:12:04 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::init()
|
|
|
|
{
|
2015-02-17 04:47:49 +02:00
|
|
|
const JsonNode & texts = CGI->generaltexth->localizedTexts["questLog"];
|
|
|
|
|
2015-02-14 02:38:28 +02:00
|
|
|
minimap = new CQuestMinimap (Rect (12, 12, 169, 169));
|
|
|
|
// TextBox have it's own 4 pixel padding from top at least for English. To achieve 10px from both left and top only add 6px margin
|
|
|
|
description = new CTextBox ("", Rect(205, 18, 385, DESCRIPTION_HEIGHT_MAX), CSlider::BROWN, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
|
|
|
|
ok = new CButton(Point(539, 398), "IOKAY.DEF", CGI->generaltexth->zelp[445], boost::bind(&CQuestLog::close,this), SDLK_RETURN);
|
2015-02-17 04:47:49 +02:00
|
|
|
// Both button and lable are shifted to -2px by x and y to not make them actually look like they're on same line with quests list and ok button
|
|
|
|
hideCompleteButton = new CToggleButton(Point(10, 396), "sysopchk.def", CButton::tooltip(texts["hideComplete"]), std::bind(&CQuestLog::toggleComplete, this, _1));
|
|
|
|
hideCompleteLabel = new CLabel(46, 398, FONT_MEDIUM, TOPLEFT, Colors::WHITE, texts["hideComplete"]["label"].String());
|
|
|
|
slider = new CSlider(Point(166, 195), 191, std::bind(&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, 0, false, CSlider::BROWN);
|
|
|
|
|
|
|
|
recreateLabelList();
|
|
|
|
recreateQuestList (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::recreateLabelList()
|
|
|
|
{
|
|
|
|
if (labels.size())
|
|
|
|
labels.clear();
|
2012-07-07 11:45:45 +03:00
|
|
|
|
2015-02-17 05:08:35 +02:00
|
|
|
bool completeMissing = true;
|
2015-02-14 02:38:28 +02:00
|
|
|
int currentLabel = 0;
|
2012-07-07 11:45:45 +03:00
|
|
|
for (int i = 0; i < quests.size(); ++i)
|
|
|
|
{
|
2015-02-14 02:38:28 +02:00
|
|
|
// Quests with MISSION_NONE type don't have text for them and can't be displayed
|
2015-02-17 05:08:35 +02:00
|
|
|
if (quests[i].quest->missionType == CQuest::MISSION_NONE)
|
2015-02-14 02:38:28 +02:00
|
|
|
continue;
|
|
|
|
|
2015-02-17 05:08:35 +02:00
|
|
|
if (quests[i].quest->progress == CQuest::COMPLETE)
|
|
|
|
{
|
|
|
|
completeMissing = false;
|
|
|
|
if (hideComplete)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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)
|
2015-02-15 23:44:48 +02:00
|
|
|
{
|
|
|
|
if (auto seersHut = dynamic_cast<const CGSeerHut *>(quests[i].obj))
|
|
|
|
{
|
|
|
|
MetaString toSeer;
|
|
|
|
toSeer << VLC->generaltexth->allTexts[347];
|
|
|
|
toSeer.addReplacement(seersHut->seerName);
|
|
|
|
text.addReplacement(toSeer.toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
text.addReplacement(quests[i].obj->getObjectName()); //get name of the object
|
|
|
|
}
|
2015-02-17 04:47:49 +02:00
|
|
|
auto label = make_shared<CQuestLabel>(Rect(13, 195, 149,31), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
|
2015-02-14 02:38:28 +02:00
|
|
|
label->disable();
|
|
|
|
|
|
|
|
label->callback = boost::bind(&CQuestLog::selectQuest, this, i, currentLabel);
|
2012-07-07 11:45:45 +03:00
|
|
|
labels.push_back(label);
|
|
|
|
|
2015-02-14 02:38:28 +02:00
|
|
|
// Select latest active quest
|
2015-02-17 04:47:49 +02:00
|
|
|
if (quests[i].quest->progress != CQuest::COMPLETE)
|
2015-02-14 02:38:28 +02:00
|
|
|
selectQuest(i, currentLabel);
|
|
|
|
|
|
|
|
currentLabel = labels.size();
|
|
|
|
}
|
|
|
|
|
2015-02-17 05:08:35 +02:00
|
|
|
if (completeMissing) // We can't use block(completeMissing) because if false button state reset to NORMAL
|
|
|
|
hideCompleteButton->block(true);
|
|
|
|
|
2015-02-17 04:47:49 +02:00
|
|
|
slider->setAmount(currentLabel);
|
2015-02-14 02:38:28 +02:00
|
|
|
if (currentLabel > QUEST_COUNT)
|
2015-02-17 04:47:49 +02:00
|
|
|
{
|
|
|
|
slider->block(false);
|
2015-02-14 02:38:28 +02:00
|
|
|
slider->moveToMax();
|
2015-02-17 04:47:49 +02:00
|
|
|
}
|
2015-02-14 02:38:28 +02:00
|
|
|
else
|
2015-02-17 23:07:03 +02:00
|
|
|
{
|
2015-02-14 02:38:28 +02:00
|
|
|
slider->block(true);
|
2015-02-17 23:07:03 +02:00
|
|
|
slider->moveToMin();
|
|
|
|
}
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::showAll(SDL_Surface * to)
|
|
|
|
{
|
2014-07-14 18:07:57 +03:00
|
|
|
CWindowObject::showAll (to);
|
2012-07-08 09:33:41 +03:00
|
|
|
if (labels.size() && labels[questIndex]->active)
|
|
|
|
{
|
2015-02-14 02:47:31 +02:00
|
|
|
Rect rect = Rect::around(labels[questIndex]->pos);
|
|
|
|
rect.x -= 2; // Adjustment needed as we want selection box on top of border in graphics
|
|
|
|
rect.w += 2;
|
|
|
|
CSDL_Ext::drawBorder(to, rect, 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
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::recreateQuestList (int newpos)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < labels.size(); ++i)
|
|
|
|
{
|
2015-02-14 02:38:28 +02:00
|
|
|
labels[i]->pos = Rect (pos.x + 14, pos.y + 195 + (i-newpos) * 32, 151, 31);
|
2012-07-07 11:45:45 +03:00
|
|
|
if (i >= newpos && i < newpos + QUEST_COUNT)
|
2015-02-14 02:38:28 +02:00
|
|
|
labels[i]->enable();
|
2012-07-07 11:45:45 +03:00
|
|
|
else
|
2015-02-14 02:38:28 +02:00
|
|
|
labels[i]->disable();
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
2014-09-18 17:46:35 +03:00
|
|
|
minimap->update();
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
|
|
|
|
2015-02-14 02:38:28 +02:00
|
|
|
void CQuestLog::selectQuest (int which, int labelId)
|
2012-07-07 11:45:45 +03:00
|
|
|
{
|
2015-02-14 02:38:28 +02:00
|
|
|
questIndex = labelId;
|
2012-07-07 11:45:45 +03:00
|
|
|
currentQuest = &quests[which];
|
|
|
|
minimap->currentQuest = currentQuest;
|
2012-07-08 19:36:20 +03:00
|
|
|
|
2012-07-08 09:33:41 +03:00
|
|
|
MetaString text;
|
2015-02-14 03:21:31 +02:00
|
|
|
std::vector<Component> components;
|
|
|
|
currentQuest->quest->getVisitText (text, components, currentQuest->quest->isCustomFirst, true);
|
2015-02-14 02:38:28 +02:00
|
|
|
if (description->slider)
|
|
|
|
description->slider->moveToMin(); // scroll text to start position
|
2013-08-29 16:46:27 +03:00
|
|
|
description->setText (text.toString()); //TODO: use special log entry text
|
2015-02-14 03:21:31 +02:00
|
|
|
|
|
|
|
vstd::clear_pointer(componentsBox);
|
|
|
|
int componentsSize = components.size();
|
|
|
|
int descriptionHeight = DESCRIPTION_HEIGHT_MAX;
|
|
|
|
if (componentsSize)
|
|
|
|
{
|
|
|
|
descriptionHeight -= 15;
|
|
|
|
CComponent::ESize imageSize = CComponent::large;
|
|
|
|
switch (currentQuest->quest->missionType)
|
|
|
|
{
|
|
|
|
case CQuest::MISSION_ARMY:
|
|
|
|
{
|
|
|
|
if (componentsSize > 4)
|
|
|
|
descriptionHeight -= 195;
|
|
|
|
else
|
|
|
|
descriptionHeight -= 100;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CQuest::MISSION_ART:
|
|
|
|
{
|
|
|
|
if (componentsSize > 4)
|
|
|
|
descriptionHeight -= 190;
|
|
|
|
else
|
|
|
|
descriptionHeight -= 90;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CQuest::MISSION_PRIMARY_STAT:
|
|
|
|
case CQuest::MISSION_RESOURCES:
|
|
|
|
{
|
|
|
|
if (componentsSize > 4)
|
|
|
|
{
|
|
|
|
imageSize = CComponent::small; // Only small icons can be used for resources as 4+ icons take too much space
|
|
|
|
descriptionHeight -= 140;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
descriptionHeight -= 125;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
descriptionHeight -= 115;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
std::vector<CComponent *> comps;
|
|
|
|
for (auto & component : components)
|
|
|
|
comps.push_back(new CComponent(component, imageSize));
|
|
|
|
|
|
|
|
componentsBox = new CComponentBox(comps, Rect(202, 20+descriptionHeight+15, 391, DESCRIPTION_HEIGHT_MAX-(20+descriptionHeight)));
|
|
|
|
}
|
|
|
|
description->resize(Point(385, descriptionHeight));
|
|
|
|
|
2014-09-18 17:46:35 +03:00
|
|
|
minimap->update();
|
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
|
|
|
}
|
2015-02-17 04:47:49 +02:00
|
|
|
|
|
|
|
void CQuestLog::toggleComplete(bool on)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
hideComplete = on;
|
|
|
|
recreateLabelList();
|
|
|
|
recreateQuestList(0);
|
|
|
|
redraw();
|
|
|
|
}
|