AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
GossipMenu Class Reference

#include "GossipDef.h"

Public Member Functions

 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 SetMenuId (uint32 menu_id)
 
uint32 GetMenuId () const
 
void SetLocale (LocaleConstant locale)
 
LocaleConstant GetLocale () const
 
uint32 GetMenuItemCount () const
 
bool Empty () const
 
GossipMenuItem const * GetItem (uint32 id) const
 
GossipMenuItemData const * GetItemData (uint32 indexId) const
 
GossipMenuItemContainer const & GetMenuItems () const
 
void SetSenderGUID (ObjectGuid guid)
 
ObjectGuid GetSenderGUID () const
 
AddMenuItem

Adds a localized gossip menu item from db by menu id and menu item id.

Parameters
menuIdGossip menu id.
menuItemIdGossip menu item id.
senderIdentifier of the current menu.
actionCustom action given to OnGossipHello.
boxMoneyCustom price for pop-up box. If > 0, it will replace DB value.
void AddMenuItem (uint32 menuId, uint32 menuItemId, uint32 sender, uint32 action, uint32 boxMoney)
 
void AddGossipMenuItemData (uint32 menuItemId, uint32 gossipActionMenuId, uint32 gossipActionPoi)
 
uint32 GetMenuItemSender (uint32 menuItemId) const
 
uint32 GetMenuItemAction (uint32 menuItemId) const
 
bool IsMenuItemCoded (uint32 menuItemId) const
 
void ClearMenu ()
 

Private Attributes

GossipMenuItemContainer _menuItems
 
GossipMenuItemDataContainer _menuItemData
 
uint32 _menuId
 
LocaleConstant _locale
 
ObjectGuid _senderGUID
 

Detailed Description

Constructor & Destructor Documentation

◆ GossipMenu()

GossipMenu::GossipMenu ( )
29{
30 _menuId = 0;
33}
#define DEFAULT_LOCALE
Definition: Common.h:88
LocaleConstant _locale
Definition: GossipDef.h:223
uint32 _menuId
Definition: GossipDef.h:222
ObjectGuid _senderGUID
Definition: GossipDef.h:224
void Clear()
Definition: ObjectGuid.h:140

References _locale, _menuId, _senderGUID, ObjectGuid::Clear(), and DEFAULT_LOCALE.

◆ ~GossipMenu()

GossipMenu::~GossipMenu ( )
36{
37 ClearMenu();
38}
void ClearMenu()
Definition: GossipDef.cpp:170

References ClearMenu().

Member Function Documentation

◆ AddGossipMenuItemData()

void GossipMenu::AddGossipMenuItemData ( uint32  menuItemId,
uint32  gossipActionMenuId,
uint32  gossipActionPoi 
)
136{
137 GossipMenuItemData& itemData = _menuItemData[menuItemId];
138
139 itemData.GossipActionMenuId = gossipActionMenuId;
140 itemData.GossipActionPoi = gossipActionPoi;
141}
Definition: GossipDef.h:145
uint32 GossipActionMenuId
Definition: GossipDef.h:146
uint32 GossipActionPoi
Definition: GossipDef.h:147
GossipMenuItemDataContainer _menuItemData
Definition: GossipDef.h:221

References _menuItemData, GossipMenuItemData::GossipActionMenuId, and GossipMenuItemData::GossipActionPoi.

Referenced by Player::PrepareGossipMenu().

◆ AddMenuItem() [1/2]

void GossipMenu::AddMenuItem ( int32  menuItemId,
uint8  icon,
std::string const &  message,
uint32  sender,
uint32  action,
std::string const &  boxMessage,
uint32  boxMoney,
bool  coded = false 
)
41{
43
44 // Find a free new id - script case
45 if (menuItemId == -1)
46 {
47 menuItemId = 0;
48 if (!_menuItems.empty())
49 {
50 for (GossipMenuItemContainer::const_iterator itr = _menuItems.begin(); itr != _menuItems.end(); ++itr)
51 {
52 if (int32(itr->first) > menuItemId)
53 break;
54
55 menuItemId = itr->first + 1;
56 }
57 }
58 }
59
60 GossipMenuItem& menuItem = _menuItems[menuItemId];
61
62 menuItem.MenuItemIcon = icon;
63 menuItem.Message = message;
64 menuItem.IsCoded = coded;
65 menuItem.Sender = sender;
66 menuItem.OptionType = action;
67 menuItem.BoxMessage = boxMessage;
68 menuItem.BoxMoney = boxMoney;
69}
#define ASSERT
Definition: Errors.h:68
std::int32_t int32
Definition: Define.h:104
#define GOSSIP_MAX_MENU_ITEMS
Definition: GossipDef.h:29
Definition: GossipDef.h:131
uint32 OptionType
Definition: GossipDef.h:136
std::string BoxMessage
Definition: GossipDef.h:137
uint32 BoxMoney
Definition: GossipDef.h:138
uint8 MenuItemIcon
Definition: GossipDef.h:132
uint32 Sender
Definition: GossipDef.h:135
bool IsCoded
Definition: GossipDef.h:133
std::string Message
Definition: GossipDef.h:134
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:220

References _menuItems, ASSERT, GossipMenuItem::BoxMessage, GossipMenuItem::BoxMoney, GOSSIP_MAX_MENU_ITEMS, GossipMenuItem::IsCoded, GossipMenuItem::MenuItemIcon, GossipMenuItem::Message, GossipMenuItem::OptionType, and GossipMenuItem::Sender.

Referenced by AddGossipItemFor(), AddMenuItem(), and Player::PrepareGossipMenu().

◆ AddMenuItem() [2/2]

void GossipMenu::AddMenuItem ( uint32  menuId,
uint32  menuItemId,
uint32  sender,
uint32  action,
uint32  boxMoney 
)

Find items for given menu id.

Return if there are none.

Iterate over each of them.

Find the one with the given menu item id.

Store texts for localization.

OptionText

BoxText

Check need of localization.

Find localizations from database.

Find localizations from database.

Add menu item with existing method. Menu item id -1 is also used in ADD_GOSSIP_ITEM macro.

81{
83 GossipMenuItemsMapBounds bounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId);
85 if (bounds.first == bounds.second)
86 return;
87
89 for (GossipMenuItemsContainer::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
90 {
92 if (itr->second.OptionID != menuItemId)
93 continue;
94
96 std::string strOptionText, strBoxText;
97 BroadcastText const* optionBroadcastText = sObjectMgr->GetBroadcastText(itr->second.OptionBroadcastTextID);
98 BroadcastText const* boxBroadcastText = sObjectMgr->GetBroadcastText(itr->second.BoxBroadcastTextID);
99
101 if (optionBroadcastText)
102 ObjectMgr::GetLocaleString(optionBroadcastText->MaleText, GetLocale(), strOptionText);
103 else
104 strOptionText = itr->second.OptionText;
105
107 if (boxBroadcastText)
108 ObjectMgr::GetLocaleString(boxBroadcastText->MaleText, GetLocale(), strBoxText);
109 else
110 strBoxText = itr->second.BoxText;
111
113 if (GetLocale() != DEFAULT_LOCALE)
114 {
115 if (!optionBroadcastText)
116 {
118 if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
119 ObjectMgr::GetLocaleString(gossipMenuLocale->OptionText, GetLocale(), strOptionText);
120 }
121
122 if (!boxBroadcastText)
123 {
125 if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
126 ObjectMgr::GetLocaleString(gossipMenuLocale->BoxText, GetLocale(), strBoxText);
127 }
128 }
129
131 AddMenuItem(-1, itr->second.OptionIcon, strOptionText, sender, action, strBoxText, boxMoney ? boxMoney : itr->second.BoxMoney, itr->second.BoxCoded);
132 }
133}
uint32 MAKE_PAIR32(uint16 l, uint16 h)
Definition: ObjectDefines.h:87
#define sObjectMgr
Definition: ObjectMgr.h:1612
std::pair< GossipMenuItemsContainer::const_iterator, GossipMenuItemsContainer::const_iterator > GossipMenuItemsMapBounds
Definition: ObjectMgr.h:645
Definition: CreatureData.h:338
LocaleConstant GetLocale() const
Definition: GossipDef.h:173
void AddMenuItem(int32 menuItemId, uint8 icon, std::string const &message, uint32 sender, uint32 action, std::string const &boxMessage, uint32 boxMoney, bool coded=false)
Definition: GossipDef.cpp:40
Definition: ObjectMgr.h:435
std::vector< std::string > MaleText
Definition: ObjectMgr.h:444
static std::string_view GetLocaleString(std::vector< std::string > const &data, size_t locale)
Definition: ObjectMgr.h:1396

References AddMenuItem(), DEFAULT_LOCALE, GetLocale(), ObjectMgr::GetLocaleString(), MAKE_PAIR32(), BroadcastText::MaleText, and sObjectMgr.

◆ ClearMenu()

void GossipMenu::ClearMenu ( )
171{
172 _menuItems.clear();
173 _menuItemData.clear();
174}

References _menuItemData, and _menuItems.

Referenced by PlayerMenu::ClearMenus(), and ~GossipMenu().

◆ Empty()

bool GossipMenu::Empty ( ) const
inline
183 {
184 return _menuItems.empty();
185 }

References _menuItems.

Referenced by PlayerMenu::Empty().

◆ GetItem()

GossipMenuItem const * GossipMenu::GetItem ( uint32  id) const
inline
188 {
189 GossipMenuItemContainer::const_iterator itr = _menuItems.find(id);
190 if (itr != _menuItems.end())
191 return &itr->second;
192
193 return nullptr;
194 }

References _menuItems.

Referenced by Player::OnGossipSelect().

◆ GetItemData()

GossipMenuItemData const * GossipMenu::GetItemData ( uint32  indexId) const
inline
197 {
198 GossipMenuItemDataContainer::const_iterator itr = _menuItemData.find(indexId);
199 if (itr != _menuItemData.end())
200 return &itr->second;
201
202 return nullptr;
203 }

References _menuItemData.

Referenced by npc_thrall_old_hillsbrad::OnGossipSelect(), and Player::OnGossipSelect().

◆ GetLocale()

LocaleConstant GossipMenu::GetLocale ( ) const
inline
173{ return _locale; }

References _locale.

Referenced by AddMenuItem().

◆ GetMenuId()

◆ GetMenuItemAction()

uint32 GossipMenu::GetMenuItemAction ( uint32  menuItemId) const
153{
154 GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
155 if (itr == _menuItems.end())
156 return 0;
157
158 return itr->second.OptionType;
159}

References _menuItems.

Referenced by PlayerMenu::GetGossipOptionAction().

◆ GetMenuItemCount()

uint32 GossipMenu::GetMenuItemCount ( ) const
inline
178 {
179 return _menuItems.size();
180 }

References _menuItems.

Referenced by PlayerMenu::SendGossipMenu().

◆ GetMenuItems()

GossipMenuItemContainer const & GossipMenu::GetMenuItems ( ) const
inline
212 {
213 return _menuItems;
214 }

References _menuItems.

Referenced by PlayerMenu::SendGossipMenu().

◆ GetMenuItemSender()

uint32 GossipMenu::GetMenuItemSender ( uint32  menuItemId) const
144{
145 GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
146 if (itr == _menuItems.end())
147 return 0;
148
149 return itr->second.Sender;
150}

References _menuItems.

Referenced by PlayerMenu::GetGossipOptionSender().

◆ GetSenderGUID()

◆ IsMenuItemCoded()

bool GossipMenu::IsMenuItemCoded ( uint32  menuItemId) const
162{
163 GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
164 if (itr == _menuItems.end())
165 return false;
166
167 return itr->second.IsCoded;
168}

References _menuItems.

Referenced by PlayerMenu::IsGossipOptionCoded().

◆ SetLocale()

void GossipMenu::SetLocale ( LocaleConstant  locale)
inline
172{ _locale = locale; }

References _locale.

Referenced by PlayerMenu::PlayerMenu().

◆ SetMenuId()

void GossipMenu::SetMenuId ( uint32  menu_id)
inline
170{ _menuId = menu_id; }

References _menuId.

Referenced by Player::PrepareGossipMenu().

◆ SetSenderGUID()

void GossipMenu::SetSenderGUID ( ObjectGuid  guid)
inline

Member Data Documentation

◆ _locale

LocaleConstant GossipMenu::_locale
private

Referenced by GetLocale(), GossipMenu(), and SetLocale().

◆ _menuId

uint32 GossipMenu::_menuId
private

Referenced by GetMenuId(), GossipMenu(), and SetMenuId().

◆ _menuItemData

GossipMenuItemDataContainer GossipMenu::_menuItemData
private

◆ _menuItems

◆ _senderGUID

ObjectGuid GossipMenu::_senderGUID
private