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:
parent
c865055803
commit
ae20499854
@ -121,6 +121,7 @@ CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
|
|||||||
currentQuest(nullptr),
|
currentQuest(nullptr),
|
||||||
componentsBox(nullptr),
|
componentsBox(nullptr),
|
||||||
quests (Quests),
|
quests (Quests),
|
||||||
|
hideComplete(false),
|
||||||
slider(nullptr)
|
slider(nullptr)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
@ -129,16 +130,32 @@ CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
|
|||||||
|
|
||||||
void CQuestLog::init()
|
void CQuestLog::init()
|
||||||
{
|
{
|
||||||
|
const JsonNode & texts = CGI->generaltexth->localizedTexts["questLog"];
|
||||||
|
|
||||||
minimap = new CQuestMinimap (Rect (12, 12, 169, 169));
|
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
|
// 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);
|
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);
|
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;
|
int currentLabel = 0;
|
||||||
for (int i = 0; i < quests.size(); ++i)
|
for (int i = 0; i < quests.size(); ++i)
|
||||||
{
|
{
|
||||||
// Quests with MISSION_NONE type don't have text for them and can't be displayed
|
// 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;
|
continue;
|
||||||
|
|
||||||
MetaString text;
|
MetaString text;
|
||||||
@ -155,23 +172,25 @@ void CQuestLog::init()
|
|||||||
else
|
else
|
||||||
text.addReplacement(quests[i].obj->getObjectName()); //get name of the object
|
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->disable();
|
||||||
|
|
||||||
label->callback = boost::bind(&CQuestLog::selectQuest, this, i, currentLabel);
|
label->callback = boost::bind(&CQuestLog::selectQuest, this, i, currentLabel);
|
||||||
labels.push_back(label);
|
labels.push_back(label);
|
||||||
|
|
||||||
// Select latest active quest
|
// 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);
|
selectQuest(i, currentLabel);
|
||||||
|
|
||||||
currentLabel = labels.size();
|
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)
|
if (currentLabel > QUEST_COUNT)
|
||||||
|
{
|
||||||
|
slider->block(false);
|
||||||
slider->moveToMax();
|
slider->moveToMax();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
slider->block(true);
|
slider->block(true);
|
||||||
}
|
}
|
||||||
@ -277,3 +296,12 @@ void CQuestLog::sliderMoved (int newpos)
|
|||||||
recreateQuestList (newpos); //move components
|
recreateQuestList (newpos); //move components
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CQuestLog::toggleComplete(bool on)
|
||||||
|
{
|
||||||
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
|
hideComplete = on;
|
||||||
|
recreateLabelList();
|
||||||
|
recreateQuestList(0);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
class CCreature;
|
class CCreature;
|
||||||
class CStackInstance;
|
class CStackInstance;
|
||||||
class CButton;
|
class CButton;
|
||||||
|
class CToggleButton;
|
||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
class CComponentBox;
|
class CComponentBox;
|
||||||
class LRClickableAreaWText;
|
class LRClickableAreaWText;
|
||||||
@ -80,9 +81,12 @@ class CQuestLog : public CWindowObject
|
|||||||
int questIndex;
|
int questIndex;
|
||||||
const QuestInfo * currentQuest;
|
const QuestInfo * currentQuest;
|
||||||
CComponentBox * componentsBox;
|
CComponentBox * componentsBox;
|
||||||
|
bool hideComplete;
|
||||||
|
CToggleButton * hideCompleteButton;
|
||||||
|
CLabel * hideCompleteLabel;
|
||||||
|
|
||||||
const std::vector<QuestInfo> quests;
|
const std::vector<QuestInfo> quests;
|
||||||
std::vector<CQuestLabel *> labels;
|
std::vector <shared_ptr<CQuestLabel>> labels;
|
||||||
CTextBox * description;
|
CTextBox * description;
|
||||||
CQuestMinimap * minimap;
|
CQuestMinimap * minimap;
|
||||||
CSlider * slider; //scrolls quests
|
CSlider * slider; //scrolls quests
|
||||||
@ -99,6 +103,8 @@ public:
|
|||||||
void updateMinimap (int which){};
|
void updateMinimap (int which){};
|
||||||
void printDescription (int which){};
|
void printDescription (int which){};
|
||||||
void sliderMoved (int newpos);
|
void sliderMoved (int newpos);
|
||||||
|
void recreateLabelList();
|
||||||
void recreateQuestList (int pos);
|
void recreateQuestList (int pos);
|
||||||
|
void toggleComplete(bool on);
|
||||||
void showAll (SDL_Surface * to);
|
void showAll (SDL_Surface * to);
|
||||||
};
|
};
|
||||||
|
@ -74,5 +74,13 @@
|
|||||||
"label" : "Give back artifact",
|
"label" : "Give back artifact",
|
||||||
"help" : "Use this button to return stack artifact back into hero backpack"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user