[10305] Add additional AddMenuItem function for GossipMenu

This version allows using id of some text from database instead of text itself, and will then simplify locales especially from script side.

Thanks to Vladimir who woke up to hundreds of questions and lines of weird test code, helping me out with all the stuff i didn't understand (which was about 75% of the changes done in here :P )

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-08-01 16:41:12 +02:00
parent c138fbe902
commit 493ae9c2f5
3 changed files with 50 additions and 31 deletions

View file

@ -24,7 +24,7 @@
#include "WorldSession.h" #include "WorldSession.h"
#include "Formulas.h" #include "Formulas.h"
GossipMenu::GossipMenu() GossipMenu::GossipMenu(WorldSession* session) : m_session(session)
{ {
m_gItems.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use m_gItems.reserve(16); // can be set for max from most often sizes to speedup push_back and less memory use
m_gMenuId = 0; m_gMenuId = 0;
@ -78,6 +78,16 @@ void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, u
AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded); AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
} }
void GossipMenu::AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, uint32 BoxMoney, bool Coded)
{
uint32 loc_idx = m_session->GetSessionDbLocaleIndex();
char const* item_text = itemText ? sObjectMgr.GetMangosString(itemText, loc_idx) : "";
char const* box_text = boxText ? sObjectMgr.GetMangosString(boxText, loc_idx) : "";
AddMenuItem(Icon, std::string(item_text), dtSender, dtAction, std::string(box_text), BoxMoney, Coded);
}
uint32 GossipMenu::MenuItemSender( unsigned int ItemId ) uint32 GossipMenu::MenuItemSender( unsigned int ItemId )
{ {
if ( ItemId >= m_gItems.size() ) if ( ItemId >= m_gItems.size() )
@ -109,7 +119,7 @@ void GossipMenu::ClearMenu()
m_gMenuId = 0; m_gMenuId = 0;
} }
PlayerMenu::PlayerMenu( WorldSession *session ) : pSession(session) PlayerMenu::PlayerMenu(WorldSession *session) : mGossipMenu(session)
{ {
} }
@ -173,7 +183,7 @@ void PlayerMenu::SendGossipMenu(uint32 TitleTextId, uint64 objectGUID)
data << uint8(0); // 3.3.3 changes icon: blue question or yellow exclamation data << uint8(0); // 3.3.3 changes icon: blue question or yellow exclamation
std::string Title = pQuest->GetTitle(); std::string Title = pQuest->GetTitle();
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(questID)) if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(questID))
if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty()) if (ql->Title.size() > (size_t)loc_idx && !ql->Title[loc_idx].empty())
@ -181,14 +191,14 @@ void PlayerMenu::SendGossipMenu(uint32 TitleTextId, uint64 objectGUID)
data << Title; // max 0x200 data << Title; // max 0x200
} }
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
//DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_MESSAGE NPCGuid=%u",GUID_LOPART(npcGUID) ); //DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_MESSAGE NPCGuid=%u",GUID_LOPART(npcGUID) );
} }
void PlayerMenu::CloseGossip() void PlayerMenu::CloseGossip()
{ {
WorldPacket data( SMSG_GOSSIP_COMPLETE, 0 ); WorldPacket data( SMSG_GOSSIP_COMPLETE, 0 );
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
//DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_COMPLETE" ); //DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_COMPLETE" );
} }
@ -204,7 +214,7 @@ void PlayerMenu::SendPointOfInterest( float X, float Y, uint32 Icon, uint32 Flag
data << uint32(Data); data << uint32(Data);
data << locName; data << locName;
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
//DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI"); //DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI");
} }
@ -219,7 +229,7 @@ void PlayerMenu::SendPointOfInterest( uint32 poi_id )
std::string icon_name = poi->icon_name; std::string icon_name = poi->icon_name;
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
if (PointOfInterestLocale const *pl = sObjectMgr.GetPointOfInterestLocale(poi_id)) if (PointOfInterestLocale const *pl = sObjectMgr.GetPointOfInterestLocale(poi_id))
if (pl->IconName.size() > size_t(loc_idx) && !pl->IconName[loc_idx].empty()) if (pl->IconName.size() > size_t(loc_idx) && !pl->IconName[loc_idx].empty())
@ -233,7 +243,7 @@ void PlayerMenu::SendPointOfInterest( uint32 poi_id )
data << uint32(poi->data); data << uint32(poi->data);
data << icon_name; data << icon_name;
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
//DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI"); //DEBUG_LOG("WORLD: Sent SMSG_GOSSIP_POI");
} }
@ -268,7 +278,7 @@ void PlayerMenu::SendTalking( uint32 textID )
Text_0[i] = pGossip->Options[i].Text_0; Text_0[i] = pGossip->Options[i].Text_0;
Text_1[i] = pGossip->Options[i].Text_1; Text_1[i] = pGossip->Options[i].Text_1;
} }
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if (NpcTextLocale const *nl = sObjectMgr.GetNpcTextLocale(textID)) if (NpcTextLocale const *nl = sObjectMgr.GetNpcTextLocale(textID))
@ -305,7 +315,7 @@ void PlayerMenu::SendTalking( uint32 textID )
} }
} }
} }
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " ); DEBUG_LOG( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
} }
@ -328,7 +338,7 @@ void PlayerMenu::SendTalking( char const * title, char const * text )
data << uint32(0); data << uint32(0);
} }
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " ); DEBUG_LOG( "WORLD: Sent SMSG_NPC_TEXT_UPDATE " );
} }
@ -397,7 +407,7 @@ void PlayerMenu::SendQuestGiverQuestList( QEmote eEmote, const std::string& Titl
{ {
std::string title = pQuest->GetTitle(); std::string title = pQuest->GetTitle();
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if(QuestLocale const *ql = sObjectMgr.GetQuestLocale(questID)) if(QuestLocale const *ql = sObjectMgr.GetQuestLocale(questID))
@ -416,7 +426,7 @@ void PlayerMenu::SendQuestGiverQuestList( QEmote eEmote, const std::string& Titl
} }
} }
data.put<uint8>(count_pos, count); data.put<uint8>(count_pos, count);
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_LIST NPC Guid=%u", GUID_LOPART(npcGUID)); DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_LIST NPC Guid=%u", GUID_LOPART(npcGUID));
} }
@ -426,7 +436,7 @@ void PlayerMenu::SendQuestGiverStatus( uint8 questStatus, uint64 npcGUID )
data << uint64(npcGUID); data << uint64(npcGUID);
data << uint8(questStatus); data << uint8(questStatus);
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u", GUID_LOPART(npcGUID), questStatus); DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_STATUS NPC Guid=%u, status=%u", GUID_LOPART(npcGUID), questStatus);
} }
@ -436,7 +446,7 @@ void PlayerMenu::SendQuestGiverQuestDetails( Quest const *pQuest, uint64 npcGUID
std::string Details = pQuest->GetDetails(); std::string Details = pQuest->GetDetails();
std::string Objectives = pQuest->GetObjectives(); std::string Objectives = pQuest->GetObjectives();
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId()))
@ -510,12 +520,12 @@ void PlayerMenu::SendQuestGiverQuestDetails( Quest const *pQuest, uint64 npcGUID
} }
// send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney
if (pSession->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL))
data << uint32(pQuest->GetRewMoneyMaxLevel()); data << uint32(pQuest->GetRewMoneyMaxLevel());
else else
data << uint32(pQuest->GetRewOrReqMoney()); data << uint32(pQuest->GetRewOrReqMoney());
data << uint32(pQuest->XPValue(pSession->GetPlayer())); data << uint32(pQuest->XPValue(GetMenuSession()->GetPlayer()));
} }
// TODO: fixme. rewarded honor points // TODO: fixme. rewarded honor points
@ -547,7 +557,7 @@ void PlayerMenu::SendQuestGiverQuestDetails( Quest const *pQuest, uint64 npcGUID
data << uint32(pQuest->DetailsEmoteDelay[i]); // DetailsEmoteDelay (in ms) data << uint32(pQuest->DetailsEmoteDelay[i]); // DetailsEmoteDelay (in ms)
} }
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId()); DEBUG_LOG("WORLD: Sent SMSG_QUESTGIVER_QUEST_DETAILS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId());
} }
@ -566,7 +576,7 @@ void PlayerMenu::SendQuestQueryResponse( Quest const *pQuest )
for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i) for (int i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
ObjectiveText[i] = pQuest->ObjectiveText[i]; ObjectiveText[i] = pQuest->ObjectiveText[i];
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId()))
@ -698,7 +708,7 @@ void PlayerMenu::SendQuestQueryResponse( Quest const *pQuest )
for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; ++iI) for (iI = 0; iI < QUEST_OBJECTIVES_COUNT; ++iI)
data << ObjectiveText[iI]; data << ObjectiveText[iI];
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest->GetQuestId() ); DEBUG_LOG( "WORLD: Sent SMSG_QUEST_QUERY_RESPONSE questid=%u", pQuest->GetQuestId() );
} }
@ -707,7 +717,7 @@ void PlayerMenu::SendQuestGiverOfferReward( Quest const* pQuest, uint64 npcGUID,
std::string Title = pQuest->GetTitle(); std::string Title = pQuest->GetTitle();
std::string OfferRewardText = pQuest->GetOfferRewardText(); std::string OfferRewardText = pQuest->GetOfferRewardText();
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId()))
@ -775,15 +785,16 @@ void PlayerMenu::SendQuestGiverOfferReward( Quest const* pQuest, uint64 npcGUID,
} }
// send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney // send rewMoneyMaxLevel explicit for max player level, else send RewOrReqMoney
if (pSession->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) if (GetMenuSession()->GetPlayer()->getLevel() >= sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL))
data << uint32(pQuest->GetRewMoneyMaxLevel()); data << uint32(pQuest->GetRewMoneyMaxLevel());
else else
data << uint32(pQuest->GetRewOrReqMoney()); data << uint32(pQuest->GetRewOrReqMoney());
data << uint32(pQuest->XPValue(pSession->GetPlayer())); // xp // xp
data << uint32(pQuest->XPValue(GetMenuSession()->GetPlayer()));
// TODO: fixme. rewarded honor points. Multiply with 10 to satisfy client // TODO: fixme. rewarded honor points. Multiply with 10 to satisfy client
data << uint32(10*MaNGOS::Honor::hk_honor_at_level(pSession->GetPlayer()->getLevel(), pQuest->GetRewHonorAddition())); data << uint32(10*MaNGOS::Honor::hk_honor_at_level(GetMenuSession()->GetPlayer()->getLevel(), pQuest->GetRewHonorAddition()));
data << float(pQuest->GetRewHonorMultiplier()); data << float(pQuest->GetRewHonorMultiplier());
data << uint32(0x08); // unused by client? data << uint32(0x08); // unused by client?
@ -804,7 +815,7 @@ void PlayerMenu::SendQuestGiverOfferReward( Quest const* pQuest, uint64 npcGUID,
data << int32(0); data << int32(0);
//data << int32(pQuest->RewRepValue[i]); //data << int32(pQuest->RewRepValue[i]);
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() ); DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_OFFER_REWARD NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );
} }
@ -816,7 +827,7 @@ void PlayerMenu::SendQuestGiverRequestItems( Quest const *pQuest, uint64 npcGUID
std::string Title = pQuest->GetTitle(); std::string Title = pQuest->GetTitle();
std::string RequestItemsText = pQuest->GetRequestItemsText(); std::string RequestItemsText = pQuest->GetRequestItemsText();
int loc_idx = pSession->GetSessionDbLocaleIndex(); int loc_idx = GetMenuSession()->GetSessionDbLocaleIndex();
if (loc_idx >= 0) if (loc_idx >= 0)
{ {
if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId())) if (QuestLocale const *ql = sObjectMgr.GetQuestLocale(pQuest->GetQuestId()))
@ -884,6 +895,6 @@ void PlayerMenu::SendQuestGiverRequestItems( Quest const *pQuest, uint64 npcGUID
data << uint32(0x08); // flags3 data << uint32(0x08); // flags3
data << uint32(0x10); // flags4 data << uint32(0x10); // flags4
pSession->SendPacket( &data ); GetMenuSession()->SendPacket( &data );
DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() ); DEBUG_LOG( "WORLD: Sent SMSG_QUESTGIVER_REQUEST_ITEMS NPCGuid=%u, questid=%u", GUID_LOPART(npcGUID), pQuest->GetQuestId() );
} }

View file

@ -156,7 +156,7 @@ typedef std::vector<QuestMenuItem> QuestMenuItemList;
class MANGOS_DLL_SPEC GossipMenu class MANGOS_DLL_SPEC GossipMenu
{ {
public: public:
GossipMenu(); explicit GossipMenu(WorldSession* session);
~GossipMenu(); ~GossipMenu();
void AddMenuItem(uint8 Icon, const std::string& Message, bool Coded = false); void AddMenuItem(uint8 Icon, const std::string& Message, bool Coded = false);
@ -166,6 +166,8 @@ class MANGOS_DLL_SPEC GossipMenu
void AddMenuItem(uint8 Icon, char const* Message, bool Coded = false); void AddMenuItem(uint8 Icon, char const* Message, bool Coded = false);
void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded = false); void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded = false);
void AddMenuItem(uint8 Icon, int32 itemText, uint32 dtSender, uint32 dtAction, int32 boxText, uint32 BoxMoney, bool Coded = false);
void SetMenuId(uint32 menu_id) { m_gMenuId = menu_id; } void SetMenuId(uint32 menu_id) { m_gMenuId = menu_id; }
uint32 GetMenuId() { return m_gMenuId; } uint32 GetMenuId() { return m_gMenuId; }
@ -197,11 +199,16 @@ class MANGOS_DLL_SPEC GossipMenu
void ClearMenu(); void ClearMenu();
WorldSession* GetMenuSession() const { return m_session; }
protected: protected:
GossipMenuItemList m_gItems; GossipMenuItemList m_gItems;
GossipMenuItemDataList m_gItemsData; GossipMenuItemDataList m_gItemsData;
uint32 m_gMenuId; uint32 m_gMenuId;
private:
WorldSession* m_session;
}; };
class QuestMenu class QuestMenu
@ -239,15 +246,16 @@ class MANGOS_DLL_SPEC PlayerMenu
private: private:
GossipMenu mGossipMenu; GossipMenu mGossipMenu;
QuestMenu mQuestMenu; QuestMenu mQuestMenu;
WorldSession* pSession;
public: public:
PlayerMenu( WorldSession *Session ); explicit PlayerMenu(WorldSession *Session);
~PlayerMenu(); ~PlayerMenu();
GossipMenu& GetGossipMenu() { return mGossipMenu; } GossipMenu& GetGossipMenu() { return mGossipMenu; }
QuestMenu& GetQuestMenu() { return mQuestMenu; } QuestMenu& GetQuestMenu() { return mQuestMenu; }
WorldSession* GetMenuSession() const { return mGossipMenu.GetMenuSession(); }
bool Empty() const { return mGossipMenu.Empty() && mQuestMenu.Empty(); } bool Empty() const { return mGossipMenu.Empty() && mQuestMenu.Empty(); }
void ClearMenus(); void ClearMenus();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10304" #define REVISION_NR "10305"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__