Permalink
Browse files

Core/Gossip: New AddMenuItem method for using DB texts

Many thanks to @Erimioa
  • Loading branch information...
1 parent 199f8b7 commit 8cbad9466ddd096b120ae3c3fdc9cfc841fb9b8c @Gacko Gacko committed Apr 8, 2013
@@ -78,7 +78,11 @@ enum eTradeskill
// d - Action (identifys this Menu Item)
// e - Text to be displayed 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_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)
// This fuction Sends the current menu to show to client, a - NPCTEXTID(uint32), b - npc guid(uint64)
@@ -65,6 +65,48 @@ void GossipMenu::AddMenuItem(int32 menuItemId, uint8 icon, std::string const& me
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)
{
GossipMenuItemData& itemData = _menuItemData[menuItemId];
@@ -108,6 +150,8 @@ void GossipMenu::ClearMenu()
PlayerMenu::PlayerMenu(WorldSession* session) : _session(session)
{
+ if (_session)
+ _gossipMenu.SetLocale(_session->GetSessionDbLocaleIndex());
}
PlayerMenu::~PlayerMenu()
@@ -163,9 +163,12 @@ class 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(uint32 menuId, uint32 menuItemId, uint32 sender, uint32 action);
void SetMenuId(uint32 menu_id) { _menuId = menu_id; }
uint32 GetMenuId() const { return _menuId; }
+ void SetLocale(LocaleConstant locale) { _locale = locale; }
+ LocaleConstant GetLocale() const { return _locale; }
void AddGossipMenuItemData(uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi);
@@ -212,6 +215,7 @@ class GossipMenu
GossipMenuItemContainer _menuItems;
GossipMenuItemDataContainer _menuItemData;
uint32 _menuId;
+ LocaleConstant _locale;
};
class QuestMenu

0 comments on commit 8cbad94

Please sign in to comment.