From d06bba422a012f367b71a2ad65dd57778cdc215f Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Sat, 14 Feb 2015 04:21:31 +0300 Subject: [PATCH] Quest Log: display components under quest description This commit add CComponentBox under text. If quest have components description height will be changed to avoid conflicts. Though it's would be much better if VCMI had something like QScrollArea in Qt so both text and components was using shared slider. --- client/windows/CQuestLog.cpp | 61 ++++++++++++++++++++++++++++++++++-- client/windows/CQuestLog.h | 3 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/client/windows/CQuestLog.cpp b/client/windows/CQuestLog.cpp index 28067332a..b36076366 100644 --- a/client/windows/CQuestLog.cpp +++ b/client/windows/CQuestLog.cpp @@ -11,6 +11,7 @@ #include "../gui/CGuiHandler.h" #include "../gui/SDL_Extensions.h" +#include "../widgets/CComponent.h" #include "../../CCallback.h" #include "../../lib/CArtHandler.h" @@ -123,6 +124,7 @@ CQuestLog::CQuestLog (const std::vector & Quests) : CWindowObject(PLAYER_COLORED | BORDERED, "questDialog.pcx"), questIndex(0), currentQuest(nullptr), + componentsBox(nullptr), quests (Quests), slider(nullptr) { @@ -207,11 +209,66 @@ void CQuestLog::selectQuest (int which, int labelId) minimap->currentQuest = currentQuest; MetaString text; - std::vector components; //TODO: display them - currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true); + std::vector components; + currentQuest->quest->getVisitText (text, components, currentQuest->quest->isCustomFirst, true); if (description->slider) description->slider->moveToMin(); // scroll text to start position description->setText (text.toString()); //TODO: use special log entry text + + 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 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)); + minimap->update(); redraw(); } diff --git a/client/windows/CQuestLog.h b/client/windows/CQuestLog.h index 19d7e1a55..9031179fa 100644 --- a/client/windows/CQuestLog.h +++ b/client/windows/CQuestLog.h @@ -20,7 +20,7 @@ class CCreature; class CStackInstance; class CButton; class CGHeroInstance; -class CComponent; +class CComponentBox; class LRClickableAreaWText; class CButton; class CPicture; @@ -79,6 +79,7 @@ class CQuestLog : public CWindowObject { int questIndex; const QuestInfo * currentQuest; + CComponentBox * componentsBox; const std::vector quests; std::vector labels;