浏览代码

First part of new Quest Log, including common quest interface.

DjWarmonger 13 年之前
父节点
当前提交
12511d8fee

+ 1 - 0
client/CAdvmapInterface.cpp

@@ -459,6 +459,7 @@ void CAdvMapInt::fswitchLevel()
 }
 void CAdvMapInt::fshowQuestlog()
 {
+	LOCPLINT->showQuestLog();
 }
 void CAdvMapInt::fsleepWake()
 {

+ 8 - 0
client/CPlayerInterface.cpp

@@ -10,6 +10,7 @@
 #include "CGameInfo.h"
 #include "CHeroWindow.h"
 #include "CCreatureWindow.h"
+#include "CQuestLog.h"
 #include "CMessage.h"
 #include "CPlayerInterface.h"
 //#include "UIFramework/SDL_Extensions.h"
@@ -2248,6 +2249,13 @@ void CPlayerInterface::showThievesGuildWindow (const CGObjectInstance * obj)
 	GH.pushInt(tgw);
 }
 
+void CPlayerInterface::showQuestLog()
+{
+	EVENT_HANDLER_CALLED_BY_CLIENT;
+	CQuestLog * ql = new CQuestLog (LOCPLINT->cb->getMyQuests());
+	GH.pushInt (ql);
+}
+
 void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
 {
 	if(obj->state())

+ 1 - 0
client/CPlayerInterface.h

@@ -161,6 +161,7 @@ public:
 	void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor) OVERRIDE;
 	void showTavernWindow(const CGObjectInstance *townOrTavern) OVERRIDE;
 	void showThievesGuildWindow (const CGObjectInstance * obj) OVERRIDE;
+	void showQuestLog() OVERRIDE;
 	void advmapSpellCast(const CGHeroInstance * caster, int spellID) OVERRIDE; //called when a hero casts a spell
 	void tileHidden(const boost::unordered_set<int3, ShashInt3> &pos) OVERRIDE; //called when given tiles become hidden under fog of war
 	void tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos) OVERRIDE; //called when fog of war disappears from given tiles

+ 38 - 0
client/CQuestLog.cpp

@@ -0,0 +1,38 @@
+#include "StdInc.h"
+#include "CQuestLog.h"
+
+#include "CGameInfo.h"
+#include "../lib/CGeneralTextHandler.h"
+#include "../CCallback.h"
+
+#include <SDL.h>
+#include "UIFramework/SDL_Extensions.h"
+#include "CBitmapHandler.h"
+#include "CDefHandler.h"
+#include "Graphics.h"
+#include "CPlayerInterface.h"
+#include "CConfigHandler.h"
+
+#include "../lib/CGameState.h"
+#include "../lib/CArtHandler.h"
+#include "../lib/NetPacks.h"
+
+#include "UIFramework/CGuiHandler.h"
+#include "UIFramework/CIntObjectClasses.h"
+
+struct QuestInfo;
+
+CQuestLog::CQuestLog (std::vector<const QuestInfo> & Quests) :
+	CWindowObject(PLAYER_COLORED, "QuestLog.pcx"),
+	quests (Quests), slider (NULL)
+{
+	OBJ_CONSTRUCTION_CAPTURING_ALL;
+	init();
+}
+
+void CQuestLog::init()
+{
+	minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
+	description = new CTextBox ("", Rect(244, 36, 355, 350), 1);
+	ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CQuestLog::close,this), 547, 401, "IOKAY.DEF", SDLK_RETURN);
+}

+ 66 - 0
client/CQuestLog.h

@@ -0,0 +1,66 @@
+#include "UIFramework/CIntObject.h"
+#include "AdventureMapClasses.h"
+#include "GUIClasses.h"
+
+#include "../lib/CGameState.h"
+
+/*
+ * CCreatureWindow.h, 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
+ *
+ */
+
+class CCreature;
+class CStackInstance;
+class CAdventureMapButton;
+class CGHeroInstance;
+class CComponent;
+class LRClickableAreaWText;
+class CAdventureMapButton;
+class CPicture;
+class CCreaturePic;
+class LRClickableAreaWTextComp;
+class CSlider;
+class CLabel;
+struct QuestInfo;
+
+class CQuestMinimap : public CMinimap
+{
+	void clickLeft(tribool down, bool previousState){};
+	void mouseMoved (const SDL_MouseMotionEvent & sEvent){};
+
+public:
+
+	CQuestMinimap (const Rect & position) : CMinimap (position){};
+	//should be called to invalidate whole map - different player or level
+	void update(){};
+	void setLevel(int level){};
+	void addQuestMarks (QuestInfo q){};
+
+	void showAll(SDL_Surface * to){};
+};
+
+class CQuestLog : public CWindowObject
+{
+	std::vector<const QuestInfo> & quests;
+	CTextBox * description;
+	CQuestMinimap * minimap;
+	CSlider * slider; //scrolls quests
+	CAdventureMapButton *ok;
+
+public:
+
+	CQuestLog (std::vector<const QuestInfo> & Quests);
+
+	~CQuestLog(){};
+
+	void init ();
+	void selectQuest (int which){};
+	void updateMinimap (int which){};
+	void printDescription (int which){};
+	void sliderMoved(int newpos){};
+};

+ 6 - 2
lib/CGameState.h

@@ -443,10 +443,14 @@ public:
  
 struct DLL_LINKAGE QuestInfo //universal interface for human and AI
 {
-	CQuest * quest;
-	CGObjectInstance * obj; //related object, most likely Seer Hut
+	const CQuest * quest;
+	const CGObjectInstance * obj; //related object, most likely Seer Hut
 	int3 tile;
 
+	QuestInfo(){};
+	QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
+		quest (Quest), obj (obj), tile (tile){}
+
 	//std::vector<std::string> > texts //allow additional info for quest log?
 
 	template <typename Handler> void serialize(Handler &h, const int version)

+ 7 - 0
lib/CObjectHandler.cpp

@@ -4278,6 +4278,11 @@ void CGSeerHut::onHeroVisit( const CGHeroInstance * h ) const
 			isCustom = isCustomFirst;
 			text = firstVisitText;
 			cb->setObjProperty (id, 10, 1);
+
+			AddQuest aq;
+			aq.quest = QuestInfo (this, this, pos);
+			aq.player = h->tempOwner;
+			cb->sendAndApply (&aq); //TODO: merge with setObjProperty?
 		}
 		else if (failRequirements)
 		{
@@ -6262,6 +6267,8 @@ void CGBorderGuard::onHeroVisit( const CGHeroInstance * h ) const
 		iw.soundID = soundBase::CAVEHEAD;
 		iw.text << std::pair<ui8,ui32>(11,18);
 		cb->showInfoDialog (&iw);
+
+		//TODO: implement QuestInfo
 	}
 }
 

+ 10 - 0
lib/IGameCallback.cpp

@@ -1217,6 +1217,16 @@ std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings()
 	return ret;
 }
 
+std::vector <const QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
+{
+	std::vector <const QuestInfo> ret;
+	BOOST_FOREACH (auto quest, gs->getPlayer(player)->quests)
+	{
+		ret.push_back (quest);
+	}
+	return ret;
+}
+
 int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
 {
 	//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);

+ 1 - 0
lib/IGameEventsReceiver.h

@@ -102,6 +102,7 @@ public:
 	virtual void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor){};
 	virtual void showTavernWindow(const CGObjectInstance *townOrTavern){};
 	virtual void showThievesGuildWindow (const CGObjectInstance * obj){};
+	virtual void showQuestLog(){};
 	virtual void advmapSpellCast(const CGHeroInstance * caster, int spellID){}; //called when a hero casts a spell
 	virtual void tileHidden(const boost::unordered_set<int3, ShashInt3> &pos){};
 	virtual void tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos){};

+ 1 - 0
lib/NetPacks.h

@@ -547,6 +547,7 @@ struct AddQuest : public CPackForClient //121
 {
 	AddQuest(){type = 121;};
 	void applyCl(CClient *cl){};
+	DLL_LINKAGE void applyGs(CGameState *gs);
 
 	ui8 player;
 	QuestInfo quest;

+ 7 - 0
lib/NetPacksLib.cpp

@@ -105,6 +105,13 @@ DLL_LINKAGE void SetCommanderProperty::applyGs(CGameState *gs)
 	}
 }
 
+DLL_LINKAGE void AddQuest::applyGs(CGameState *gs)
+{
+	assert (vstd::contains(gs->players, player));
+	//TODO: check for duplicates?
+	gs->players[player].quests.push_back (quest);
+}
+
 DLL_LINKAGE void HeroVisitCastle::applyGs( CGameState *gs )
 {
 	CGHeroInstance *h = gs->getHero(hid);