Skip to content

Commit

Permalink
Core/Gossip: New AddMenuItem method for using DB texts
Browse files Browse the repository at this point in the history
Many thanks to @Erimioa
  • Loading branch information
Gacko committed Apr 8, 2013
1 parent 199f8b7 commit 8cbad94
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/server/game/AI/ScriptedAI/ScriptedGossip.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ enum eTradeskill
// d - Action (identifys this Menu Item) // d - Action (identifys this Menu Item)
// e - Text to be displayed in pop up box // e - Text to be displayed in pop up box
// f - Money value in pop up box // f - Money value in pop up box
// g - Coded
// h - Menu ID from DB
// i - Menu item ID from DB
#define ADD_GOSSIP_ITEM(a, b, c, d) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, "", 0) #define ADD_GOSSIP_ITEM(a, b, c, d) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, "", 0)
#define ADD_GOSSIP_ITEM_DB(h, i, c, d) PlayerTalkClass->GetGossipMenu().AddMenuItem(h, i, c, d)
#define ADD_GOSSIP_ITEM_EXTENDED(a, b, c, d, e, f, g) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, e, f, g) #define ADD_GOSSIP_ITEM_EXTENDED(a, b, c, d, e, f, g) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, e, f, g)


// This fuction Sends the current menu to show to client, a - NPCTEXTID(uint32), b - npc guid(uint64) // This fuction Sends the current menu to show to client, a - NPCTEXTID(uint32), b - npc guid(uint64)
Expand Down
44 changes: 44 additions & 0 deletions src/server/game/Entities/Creature/GossipDef.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,6 +65,48 @@ void GossipMenu::AddMenuItem(int32 menuItemId, uint8 icon, std::string const& me
menuItem.BoxMoney = boxMoney; menuItem.BoxMoney = boxMoney;
} }


/**
* @name AddMenuItem
* @brief Adds a localized gossip menu item from db by menu id and menu item id.
* @param menuId Gossip menu id.
* @param menuItemId Gossip menu item id.
* @param sender Identifier of the current menu.
* @param action Custom action given to OnGossipHello.
*/
void GossipMenu::AddMenuItem(uint32 menuId, uint32 menuItemId, uint32 sender, uint32 action)
{
/// Find items for given menu id.
GossipMenuItemsMapBounds bounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId);
/// Return if there are none.
if (bounds.first == bounds.second)
return;

/// Iterate over each of them.
for (GossipMenuItemsContainer::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
/// Find the one with the given menu item id.
if (itr->second.OptionIndex != menuItemId)
continue;

/// Store texts for localization.
std::string strOptionText = itr->second.OptionText;
std::string strBoxText = itr->second.BoxText;

/// Check need of localization.
if (GetLocale() > LOCALE_enUS)
/// Find localizations from database.
if (GossipMenuItemsLocale const* no = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
{
/// Translate texts if there are any.
ObjectMgr::GetLocaleString(no->OptionText, GetLocale(), strOptionText);
ObjectMgr::GetLocaleString(no->BoxText, GetLocale(), strBoxText);
}

/// Add menu item with existing method. Menu item id -1 is also used in ADD_GOSSIP_ITEM macro.
AddMenuItem(-1, itr->second.OptionIcon, strOptionText, sender, action, strBoxText, itr->second.BoxMoney, itr->second.BoxCoded);
}
}

void GossipMenu::AddGossipMenuItemData(uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi) void GossipMenu::AddGossipMenuItemData(uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi)
{ {
GossipMenuItemData& itemData = _menuItemData[menuItemId]; GossipMenuItemData& itemData = _menuItemData[menuItemId];
Expand Down Expand Up @@ -108,6 +150,8 @@ void GossipMenu::ClearMenu()


PlayerMenu::PlayerMenu(WorldSession* session) : _session(session) PlayerMenu::PlayerMenu(WorldSession* session) : _session(session)
{ {
if (_session)
_gossipMenu.SetLocale(_session->GetSessionDbLocaleIndex());
} }


PlayerMenu::~PlayerMenu() PlayerMenu::~PlayerMenu()
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/Entities/Creature/GossipDef.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ class GossipMenu
~GossipMenu(); ~GossipMenu();


void AddMenuItem(int32 menuItemId, uint8 icon, std::string const& message, uint32 sender, uint32 action, std::string const& boxMessage, uint32 boxMoney, bool coded = false); void AddMenuItem(int32 menuItemId, uint8 icon, std::string const& message, uint32 sender, uint32 action, std::string const& boxMessage, uint32 boxMoney, bool coded = false);
void AddMenuItem(uint32 menuId, uint32 menuItemId, uint32 sender, uint32 action);


void SetMenuId(uint32 menu_id) { _menuId = menu_id; } void SetMenuId(uint32 menu_id) { _menuId = menu_id; }
uint32 GetMenuId() const { return _menuId; } uint32 GetMenuId() const { return _menuId; }
void SetLocale(LocaleConstant locale) { _locale = locale; }
LocaleConstant GetLocale() const { return _locale; }


void AddGossipMenuItemData(uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi); void AddGossipMenuItemData(uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi);


Expand Down Expand Up @@ -212,6 +215,7 @@ class GossipMenu
GossipMenuItemContainer _menuItems; GossipMenuItemContainer _menuItems;
GossipMenuItemDataContainer _menuItemData; GossipMenuItemDataContainer _menuItemData;
uint32 _menuId; uint32 _menuId;
LocaleConstant _locale;
}; };


class QuestMenu class QuestMenu
Expand Down

0 comments on commit 8cbad94

Please sign in to comment.