2017-07-13 10:26:03 +02: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
|
|
|
#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 "../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"
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "../../lib/mapObjects/CQuest.h"
|
2012-07-08 09:33:41 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2012-07-06 22:12:04 +03:00
|
|
|
struct QuestInfo;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
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)
|
|
|
|
{
|
2018-07-25 00:36:48 +02: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
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CQuestMinimap::CQuestMinimap(const Rect & position)
|
|
|
|
: CMinimap(position),
|
|
|
|
currentQuest(nullptr)
|
2012-07-08 19:36:20 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestMinimap::addQuestMarks (const QuestInfo * q)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2012-07-08 19:36:20 +03:00
|
|
|
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-12-29 04:43:33 +02:00
|
|
|
auto pic = std::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();
|
2018-04-07 13:34:11 +02:00
|
|
|
if(currentQuest)
|
|
|
|
addQuestMarks(currentQuest);
|
2012-07-07 11:45:45 +03:00
|
|
|
}
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2012-07-08 19:36:20 +03:00
|
|
|
void CQuestMinimap::iconClicked()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(currentQuest->obj)
|
2012-07-08 19:36:20 +03:00
|
|
|
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
|
2018-04-07 13:34:11 +02:00
|
|
|
// for (auto pic : icons)
|
|
|
|
// pic->showAll(to);
|
2012-07-08 19:36:20 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests)
|
|
|
|
: 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-17 04:47:49 +02:00
|
|
|
hideComplete(false),
|
2018-04-07 13:34:11 +02:00
|
|
|
quests(Quests)
|
2012-07-06 22:12:04 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2012-07-06 22:12:04 +03:00
|
|
|
|
2015-02-17 04:47:49 +02:00
|
|
|
const JsonNode & texts = CGI->generaltexth->localizedTexts["questLog"];
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
minimap = std::make_shared<CQuestMinimap>(Rect(12, 12, 169, 169));
|
2015-02-14 02:38:28 +02:00
|
|
|
// 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
|
2022-11-26 23:12:20 +02:00
|
|
|
description = std::make_shared<CTextBox>("", Rect(205, 18, 385, DESCRIPTION_HEIGHT_MAX), CSlider::BROWN, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2018-04-07 13:34:11 +02:00
|
|
|
ok = std::make_shared<CButton>(Point(539, 398), "IOKAY.DEF", CGI->generaltexth->zelp[445], std::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
|
2018-04-07 13:34:11 +02:00
|
|
|
hideCompleteButton = std::make_shared<CToggleButton>(Point(10, 396), "sysopchk.def", CButton::tooltip(texts["hideComplete"]), std::bind(&CQuestLog::toggleComplete, this, _1));
|
2022-11-26 23:12:20 +02:00
|
|
|
hideCompleteLabel = std::make_shared<CLabel>(46, 398, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, texts["hideComplete"]["label"].String());
|
2018-04-07 13:34:11 +02:00
|
|
|
slider = std::make_shared<CSlider>(Point(166, 195), 191, std::bind(&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, 0, false, CSlider::BROWN);
|
2015-02-17 04:47:49 +02:00
|
|
|
|
|
|
|
recreateLabelList();
|
2018-04-07 13:34:11 +02:00
|
|
|
recreateQuestList(0);
|
2015-02-17 04:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuestLog::recreateLabelList()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
|
|
|
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
|
|
|
|
}
|
2022-11-26 23:12:20 +02:00
|
|
|
auto label = std::make_shared<CQuestLabel>(Rect(13, 195, 149,31), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, text.toString());
|
2015-02-14 02:38:28 +02:00
|
|
|
label->disable();
|
|
|
|
|
2015-09-02 19:00:56 +02:00
|
|
|
label->callback = std::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);
|
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
currentLabel = static_cast<int>(labels.size());
|
2015-02-14 02:38:28 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
CWindowObject::showAll(to);
|
2018-07-25 00:36:48 +02:00
|
|
|
if(questIndex >= 0 && questIndex < labels.size())
|
2012-07-08 09:33:41 +03:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
//TODO: use child object to selection rect
|
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
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +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);
|
2018-04-07 13:34:11 +02:00
|
|
|
if(description->slider)
|
2015-02-14 02:38:28 +02:00
|
|
|
description->slider->moveToMin(); // scroll text to start position
|
2018-04-07 13:34:11 +02:00
|
|
|
description->setText(text.toString()); //TODO: use special log entry text
|
|
|
|
|
|
|
|
componentsBox.reset();
|
2015-02-14 03:21:31 +02:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
int componentsSize = static_cast<int>(components.size());
|
2015-02-14 03:21:31 +02:00
|
|
|
int descriptionHeight = DESCRIPTION_HEIGHT_MAX;
|
2018-04-07 13:34:11 +02:00
|
|
|
if(componentsSize)
|
2015-02-14 03:21:31 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<CComponent>> comps;
|
|
|
|
for(auto & component : components)
|
|
|
|
{
|
|
|
|
auto c = std::make_shared<CComponent>(component, imageSize);
|
|
|
|
comps.push_back(c);
|
|
|
|
}
|
2015-02-14 03:21:31 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
componentsBox = std::make_shared<CComponentBox>(comps, Rect(202, 20+descriptionHeight+15, 391, DESCRIPTION_HEIGHT_MAX-(20+descriptionHeight)));
|
2015-02-14 03:21:31 +02:00
|
|
|
}
|
|
|
|
description->resize(Point(385, descriptionHeight));
|
|
|
|
|
2014-09-18 17:46:35 +03:00
|
|
|
minimap->update();
|
2012-07-07 11:45:45 +03:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CQuestLog::sliderMoved(int newpos)
|
2012-07-07 11:45:45 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
recreateQuestList(newpos); //move components
|
2012-07-07 11:45:45 +03:00
|
|
|
redraw();
|
2012-07-19 21:52:44 +03:00
|
|
|
}
|
2015-02-17 04:47:49 +02:00
|
|
|
|
|
|
|
void CQuestLog::toggleComplete(bool on)
|
|
|
|
{
|
|
|
|
hideComplete = on;
|
|
|
|
recreateLabelList();
|
|
|
|
recreateQuestList(0);
|
|
|
|
redraw();
|
|
|
|
}
|