TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 SetSenderGUID (ObjectGuid guid)
 
ObjectGuid GetSenderGUID () const
 
void SetLocale (LocaleConstant locale)
 
LocaleConstant GetLocale () const
 
uint32 GetMenuItemCount () const
 
bool Empty () const
 
GossipMenuItem constGetItem (uint32 id) const
 
GossipMenuItemData constGetItemData (uint32 indexId) const
 
GossipMenuItemContainer constGetMenuItems () 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.
void AddMenuItem (uint32 menuId, uint32 menuItemId, uint32 sender, uint32 action)
 
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
 
ObjectGuid _senderGUID
 
LocaleConstant _locale
 

Constructor & Destructor Documentation

GossipMenu::GossipMenu ( )
28 {
29  _menuId = 0;
32 }
uint32 _menuId
Definition: GossipDef.h:214
void Clear()
Definition: ObjectGuid.h:215
ObjectGuid _senderGUID
Definition: GossipDef.h:215
#define DEFAULT_LOCALE
Definition: Common.h:134
LocaleConstant _locale
Definition: GossipDef.h:216

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

Member Function Documentation

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

+ Here is the caller graph for this function:

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

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.

79 {
81  GossipMenuItemsMapBounds bounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId);
83  if (bounds.first == bounds.second)
84  return;
85 
87  for (GossipMenuItemsContainer::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
88  {
90  if (itr->second.OptionIndex != menuItemId)
91  continue;
92 
94  std::string strOptionText, strBoxText;
95  BroadcastTextEntry const* optionBroadcastText = sBroadcastTextStore.LookupEntry(itr->second.OptionBroadcastTextId);
96  BroadcastTextEntry const* boxBroadcastText = sBroadcastTextStore.LookupEntry(itr->second.BoxBroadcastTextId);
97 
99  if (optionBroadcastText)
100  strOptionText = DB2Manager::GetBroadcastTextValue(optionBroadcastText, GetLocale());
101  else
102  strOptionText = itr->second.OptionText;
103 
105  if (boxBroadcastText)
106  strBoxText = DB2Manager::GetBroadcastTextValue(boxBroadcastText, GetLocale());
107  else
108  strBoxText = itr->second.BoxText;
109 
111  if (GetLocale() != DEFAULT_LOCALE)
112  {
113  if (!optionBroadcastText)
114  {
116  if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
117  ObjectMgr::GetLocaleString(gossipMenuLocale->OptionText, GetLocale(), strOptionText);
118  }
119 
120  if (!boxBroadcastText)
121  {
123  if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
124  ObjectMgr::GetLocaleString(gossipMenuLocale->BoxText, GetLocale(), strBoxText);
125  }
126  }
127 
129  AddMenuItem(-1, itr->second.OptionIcon, strOptionText, sender, action, strBoxText, itr->second.BoxMoney, itr->second.BoxCoded);
130  }
131 }
Definition: Creature.h:266
DB2Storage< BroadcastTextEntry > sBroadcastTextStore("BroadcastText.db2", BroadcastTextFormat, HOTFIX_SEL_BROADCAST_TEXT)
static char const * GetBroadcastTextValue(BroadcastTextEntry const *broadcastText, LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false)
Definition: DB2Stores.cpp:610
Definition: DB2Structure.h:112
#define sObjectMgr
Definition: ObjectMgr.h:1567
LocaleConstant GetLocale() const
Definition: GossipDef.h:175
std::pair< GossipMenuItemsContainer::const_iterator, GossipMenuItemsContainer::const_iterator > GossipMenuItemsMapBounds
Definition: ObjectMgr.h:539
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:39
static void GetLocaleString(StringVector const &data, LocaleConstant localeConstant, std::string &value)
Definition: ObjectMgr.h:1345
#define DEFAULT_LOCALE
Definition: Common.h:134
uint32 MAKE_PAIR32(uint16 l, uint16 h)
Definition: ObjectDefines.h:54

+ Here is the call graph for this function:

void GossipMenu::ClearMenu ( )
169 {
170  _menuItems.clear();
171  _menuItemData.clear();
172 }
GossipMenuItemDataContainer _menuItemData
Definition: GossipDef.h:213
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212

+ Here is the caller graph for this function:

bool GossipMenu::Empty ( ) const
inline
180 { return _menuItems.empty(); }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
GossipMenuItem const* GossipMenu::GetItem ( uint32  id) const
inline
183  {
184  GossipMenuItemContainer::const_iterator itr = _menuItems.find(id);
185  if (itr != _menuItems.end())
186  return &itr->second;
187 
188  return NULL;
189  }
arena_t NULL
Definition: jemalloc_internal.h:624
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
GossipMenuItemData const* GossipMenu::GetItemData ( uint32  indexId) const
inline
192  {
193  GossipMenuItemDataContainer::const_iterator itr = _menuItemData.find(indexId);
194  if (itr != _menuItemData.end())
195  return &itr->second;
196 
197  return NULL;
198  }
GossipMenuItemDataContainer _menuItemData
Definition: GossipDef.h:213
arena_t NULL
Definition: jemalloc_internal.h:624
LocaleConstant GossipMenu::GetLocale ( ) const
inline
175 { return _locale; }
LocaleConstant _locale
Definition: GossipDef.h:216

+ Here is the caller graph for this function:

uint32 GossipMenu::GetMenuId ( ) const
inline
171 { return _menuId; }
uint32 _menuId
Definition: GossipDef.h:214

+ Here is the caller graph for this function:

uint32 GossipMenu::GetMenuItemAction ( uint32  menuItemId) const
151 {
152  GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
153  if (itr == _menuItems.end())
154  return 0;
155 
156  return itr->second.OptionType;
157 }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
uint32 GossipMenu::GetMenuItemCount ( ) const
inline
179 { return uint32(_menuItems.size()); }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
uint32_t uint32
Definition: g3dmath.h:168
GossipMenuItemContainer const& GossipMenu::GetMenuItems ( ) const
inline
207  {
208  return _menuItems;
209  }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212

+ Here is the caller graph for this function:

uint32 GossipMenu::GetMenuItemSender ( uint32  menuItemId) const
142 {
143  GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
144  if (itr == _menuItems.end())
145  return 0;
146 
147  return itr->second.Sender;
148 }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
ObjectGuid GossipMenu::GetSenderGUID ( ) const
inline
173 { return _senderGUID; }
ObjectGuid _senderGUID
Definition: GossipDef.h:215
bool GossipMenu::IsMenuItemCoded ( uint32  menuItemId) const
160 {
161  GossipMenuItemContainer::const_iterator itr = _menuItems.find(menuItemId);
162  if (itr == _menuItems.end())
163  return false;
164 
165  return itr->second.IsCoded;
166 }
GossipMenuItemContainer _menuItems
Definition: GossipDef.h:212
void GossipMenu::SetLocale ( LocaleConstant  locale)
inline
174 { _locale = locale; }
LocaleConstant _locale
Definition: GossipDef.h:216

+ Here is the caller graph for this function:

void GossipMenu::SetMenuId ( uint32  menu_id)
inline
170 { _menuId = menu_id; }
uint32 _menuId
Definition: GossipDef.h:214
void GossipMenu::SetSenderGUID ( ObjectGuid  guid)
inline
172 { _senderGUID = guid; }
ObjectGuid _senderGUID
Definition: GossipDef.h:215

+ Here is the caller graph for this function:

Member Data Documentation

LocaleConstant GossipMenu::_locale
private
uint32 GossipMenu::_menuId
private
GossipMenuItemDataContainer GossipMenu::_menuItemData
private
GossipMenuItemContainer GossipMenu::_menuItems
private
ObjectGuid GossipMenu::_senderGUID
private

The documentation for this class was generated from the following files: