瀏覽代碼

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.
ArseniyShestakov 10 年之前
父節點
當前提交
d06bba422a
共有 2 個文件被更改,包括 61 次插入3 次删除
  1. 59 2
      client/windows/CQuestLog.cpp
  2. 2 1
      client/windows/CQuestLog.h

+ 59 - 2
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<QuestInfo> & 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<Component> components; //TODO: display them
-	currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
+	std::vector<Component> 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<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));
+
 	minimap->update();
 	redraw();
 }

+ 2 - 1
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<QuestInfo> quests;
 	std::vector<CQuestLabel *> labels;