AzerothCore 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 ( )
30{
31 _menuId = 0;
34}
#define DEFAULT_LOCALE
Definition: Common.h:79
LocaleConstant _locale
Definition: GossipDef.h:223
uint32 _menuId
Definition: GossipDef.h:222
ObjectGuid _senderGUID
Definition: GossipDef.h:224
void Clear()
Definition: ObjectGuid.h:138

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

◆ ~GossipMenu()

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

References ClearMenu().

Member Function Documentation

◆ AddGossipMenuItemData()

void GossipMenu::AddGossipMenuItemData ( uint32  menuItemId,
uint32  gossipActionMenuId,
uint32  gossipActionPoi 
)
137{
138 GossipMenuItemData& itemData = _menuItemData[menuItemId];
139
140 itemData.GossipActionMenuId = gossipActionMenuId;
141 itemData.GossipActionPoi = gossipActionPoi;
142}
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 
)
42{
44
45 // Find a free new id - script case
46 if (menuItemId == -1)
47 {
48 menuItemId = 0;
49 if (!_menuItems.empty())
50 {
51 for (GossipMenuItemContainer::const_iterator itr = _menuItems.begin(); itr != _menuItems.end(); ++itr)
52 {
53 if (int32(itr->first) > menuItemId)
54 break;
55
56 menuItemId = itr->first + 1;
57 }
58 }
59 }
60
61 GossipMenuItem& menuItem = _menuItems[menuItemId];
62
63 menuItem.MenuItemIcon = icon;
64 menuItem.Message = message;
65 menuItem.IsCoded = coded;
66 menuItem.Sender = sender;
67 menuItem.OptionType = action;
68 menuItem.BoxMessage = boxMessage;
69 menuItem.BoxMoney = boxMoney;
70}
std::int32_t int32
Definition: Define.h:103
#define ASSERT
Definition: Errors.h:68
#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.

82{
84 GossipMenuItemsMapBounds bounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId);
86 if (bounds.first == bounds.second)
87 return;
88
90 for (GossipMenuItemsContainer::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
91 {
93 if (itr->second.OptionID != menuItemId)
94 continue;
95
97 std::string strOptionText, strBoxText;
98 BroadcastText const* optionBroadcastText = sObjectMgr->GetBroadcastText(itr->second.OptionBroadcastTextID);
99 BroadcastText const* boxBroadcastText = sObjectMgr->GetBroadcastText(itr->second.BoxBroadcastTextID);
100
102 if (optionBroadcastText)
103 ObjectMgr::GetLocaleString(optionBroadcastText->MaleText, GetLocale(), strOptionText);
104 else
105 strOptionText = itr->second.OptionText;
106
108 if (boxBroadcastText)
109 ObjectMgr::GetLocaleString(boxBroadcastText->MaleText, GetLocale(), strBoxText);
110 else
111 strBoxText = itr->second.BoxText;
112
114 if (GetLocale() != DEFAULT_LOCALE)
115 {
116 if (!optionBroadcastText)
117 {
119 if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
120 ObjectMgr::GetLocaleString(gossipMenuLocale->OptionText, GetLocale(), strOptionText);
121 }
122
123 if (!boxBroadcastText)
124 {
126 if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
127 ObjectMgr::GetLocaleString(gossipMenuLocale->BoxText, GetLocale(), strBoxText);
128 }
129 }
130
132 AddMenuItem(-1, itr->second.OptionIcon, strOptionText, sender, action, strBoxText, boxMoney ? boxMoney : itr->second.BoxMoney, itr->second.BoxCoded);
133 }
134}
#define sObjectMgr
Definition: ObjectMgr.h:1623
std::pair< GossipMenuItemsContainer::const_iterator, GossipMenuItemsContainer::const_iterator > GossipMenuItemsMapBounds
Definition: ObjectMgr.h:634
uint32 MAKE_PAIR32(uint16 l, uint16 h)
Definition: ObjectDefines.h:87
Definition: CreatureData.h:352
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:41
Definition: ObjectMgr.h:435
std::vector< std::string > MaleText
Definition: ObjectMgr.h:444
static std::string_view GetLocaleString(std::vector< std::string > const &data, std::size_t locale)
Definition: ObjectMgr.h:1405

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

◆ ClearMenu()

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

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
154{
155 GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
156 if (itr == _menuItems.end())
157 return 0;
158
159 return itr->second.OptionType;
160}

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
145{
146 GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
147 if (itr == _menuItems.end())
148 return 0;
149
150 return itr->second.Sender;
151}

References _menuItems.

Referenced by PlayerMenu::GetGossipOptionSender().

◆ GetSenderGUID()

ObjectGuid GossipMenu::GetSenderGUID ( ) const
inline

◆ IsMenuItemCoded()

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

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