1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Quest Log: implement option to hide complete quests

This commit is contained in:
ArseniyShestakov 2015-02-17 05:47:49 +03:00
parent c865055803
commit ae20499854
3 changed files with 48 additions and 6 deletions

View File

@ -121,6 +121,7 @@ CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
currentQuest(nullptr),
componentsBox(nullptr),
quests (Quests),
hideComplete(false),
slider(nullptr)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
@ -129,16 +130,32 @@ CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
void CQuestLog::init()
{
const JsonNode & texts = CGI->generaltexth->localizedTexts["questLog"];
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);
// 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();
int currentLabel = 0;
for (int i = 0; i < quests.size(); ++i)
{
// Quests with MISSION_NONE type don't have text for them and can't be displayed
if (quests[i].quest->missionType == CQuest::MISSION_NONE)
if (quests[i].quest->missionType == CQuest::MISSION_NONE
|| (hideComplete && quests[i].quest->progress == CQuest::COMPLETE))
continue;
MetaString text;
@ -155,23 +172,25 @@ void CQuestLog::init()
else
text.addReplacement(quests[i].obj->getObjectName()); //get name of the object
}
CQuestLabel * label = new CQuestLabel (Rect(13, 195, 149,31), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
auto label = make_shared<CQuestLabel>(Rect(13, 195, 149,31), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
label->disable();
label->callback = boost::bind(&CQuestLog::selectQuest, this, i, currentLabel);
labels.push_back(label);
// Select latest active quest
if (quests[i].quest->progress != CQuest::COMPLETE) // TODO: there need to be difference between active and completed quests
if (quests[i].quest->progress != CQuest::COMPLETE)
selectQuest(i, currentLabel);
currentLabel = labels.size();
}
recreateQuestList (0);
slider = new CSlider(Point(166, 195), 191, std::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, currentLabel, false, CSlider::BROWN);
slider->setAmount(currentLabel);
if (currentLabel > QUEST_COUNT)
{
slider->block(false);
slider->moveToMax();
}
else
slider->block(true);
}
@ -277,3 +296,12 @@ void CQuestLog::sliderMoved (int newpos)
recreateQuestList (newpos); //move components
redraw();
}
void CQuestLog::toggleComplete(bool on)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
hideComplete = on;
recreateLabelList();
recreateQuestList(0);
redraw();
}

View File

@ -19,6 +19,7 @@
class CCreature;
class CStackInstance;
class CButton;
class CToggleButton;
class CGHeroInstance;
class CComponentBox;
class LRClickableAreaWText;
@ -80,9 +81,12 @@ class CQuestLog : public CWindowObject
int questIndex;
const QuestInfo * currentQuest;
CComponentBox * componentsBox;
bool hideComplete;
CToggleButton * hideCompleteButton;
CLabel * hideCompleteLabel;
const std::vector<QuestInfo> quests;
std::vector<CQuestLabel *> labels;
std::vector <shared_ptr<CQuestLabel>> labels;
CTextBox * description;
CQuestMinimap * minimap;
CSlider * slider; //scrolls quests
@ -99,6 +103,8 @@ public:
void updateMinimap (int which){};
void printDescription (int which){};
void sliderMoved (int newpos);
void recreateLabelList();
void recreateQuestList (int pos);
void toggleComplete(bool on);
void showAll (SDL_Surface * to);
};

View File

@ -74,5 +74,13 @@
"label" : "Give back artifact",
"help" : "Use this button to return stack artifact back into hero backpack"
}
},
"questLog" :
{
"hideComplete" :
{
"label" : "Hide complete quests",
"help" : "Hide all quests that already completed"
}
}
}