Jump to content

[PATCH] Add new GossipMenu::AddMenuItem functions with int32 textID params


daveh

Recommended Posts

* What bug does the patch fix? What features does the patch add?

No mangos bug fix.

Add new GossipMenu::AddMenuItem functions with int32 textID params, so scriptdev can localize gossip text easily.

eg:

Orig code:

#define GOSSIP_TEXT_BANK                "The bank"

player->ADD_GOSSIP_ITEM( 0, GOSSIP_TEXT_BANK, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);

With this patch, we can move #define string to DB and localize it:

INSERT INTO script_texts (entry,content_default,sound,type,language,emote,comment) VALUES
(-1000100,'The bank',0,0,0,0,'guard GOSSIP_TEXT_BANK');

And change the #define to

#define GOSSIP_TEXT_BANK -1000100

No need to touch any existing code:

player->ADD_GOSSIP_ITEM( 0, GOSSIP_TEXT_BANK , GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1); 

* For which repository revision was the patch created?

[7670]

* Is there a thread in the bug report section or at lighthouse? If yes, please add a link to the thread.

No

* Who has been writing this patch? Please include either forum user names or email addresses.

Me.

Patch URL.

Patch:

diff --git a/src/game/GossipDef.cpp b/src/game/GossipDef.cpp
index 2eefba6..5b324e6 100644
--- a/src/game/GossipDef.cpp
+++ b/src/game/GossipDef.cpp
@@ -27,6 +27,7 @@
GossipMenu::GossipMenu()
{
    m_gItems.reserve(16);                                   // can be set for max from most often sizes to speedup push_back and less memory use
+    m_pSession = NULL;
}

GossipMenu::~GossipMenu()
@@ -66,6 +67,25 @@ void GossipMenu::AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, u
    AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
}

+void GossipMenu::AddMenuItem(uint8 Icon, int32 MessageID, bool Coded)
+{
+    char const* Message = m_pSession ? m_pSession->GetMangosString(MessageID) : objmgr.GetMangosStringForDBCLocale(MessageID);
+    AddMenuItem(Icon, std::string(Message ? Message : ""),Coded);
+}
+
+void GossipMenu::AddMenuItem(uint8 Icon, int32 MessageID, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded)
+{
+    char const* Message = m_pSession ? m_pSession->GetMangosString(MessageID)  : objmgr.GetMangosStringForDBCLocale(MessageID);
+    AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
+}
+
+void GossipMenu::AddMenuItem(uint8 Icon, int32 MessageID, uint32 dtSender, uint32 dtAction, int32 BoxMessageID, uint32 BoxMoney, bool Coded)
+{
+    char const* Message = m_pSession ? m_pSession->GetMangosString(MessageID)  : objmgr.GetMangosStringForDBCLocale(MessageID);
+    char const* BoxMessage = m_pSession ? m_pSession->GetMangosString(MessageID) : objmgr.GetMangosStringForDBCLocale(BoxMessageID);
+    AddMenuItem(Icon, std::string(Message ? Message : ""), dtSender, dtAction, std::string(BoxMessage ? BoxMessage : ""), BoxMoney, Coded);
+}
+
uint32 GossipMenu::MenuItemSender( unsigned int ItemId )
{
    if ( ItemId >= m_gItems.size() ) return 0;
@@ -94,6 +114,7 @@ void GossipMenu::ClearMenu()

PlayerMenu::PlayerMenu( WorldSession *session ) : pSession(session)
{
+    mGossipMenu.SetWorldSession(pSession);
}

PlayerMenu::~PlayerMenu()
diff --git a/src/game/GossipDef.h b/src/game/GossipDef.h
index ea31b4c..e9839b8 100644
--- a/src/game/GossipDef.h
+++ b/src/game/GossipDef.h
@@ -108,6 +108,10 @@ class MANGOS_DLL_SPEC GossipMenu
        void AddMenuItem(uint8 Icon, char const* Message, bool Coded = false);
        void AddMenuItem(uint8 Icon, char const* Message, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded = false);

+        void AddMenuItem(uint8 Icon, int32 MessageID, bool Coded = false);
+        void AddMenuItem(uint8 Icon, int32 MessageID, uint32 dtSender, uint32 dtAction, char const* BoxMessage, uint32 BoxMoney, bool Coded = false);
+        void AddMenuItem(uint8 Icon, int32 MessageID, uint32 dtSender, uint32 dtAction, int32 BoxMessageID, uint32 BoxMoney, bool Coded = false);
+
        unsigned int MenuItemCount() const
        {
            return m_gItems.size();
@@ -129,8 +133,11 @@ class MANGOS_DLL_SPEC GossipMenu

        void ClearMenu();

+        void SetWorldSession(WorldSession* session) { m_pSession = session; }
+
    protected:
        GossipMenuItemList m_gItems;
+        WorldSession* m_pSession;
};

class QuestMenu

Link to comment
Share on other sites

* What bug does the patch fix? What features does the patch add?

No mangos bug fix.

Add new GossipMenu::AddMenuItem functions with int32 textID params, so scriptdev can localize gossip text easily.

Hi, any comments? Can we have this patch for localisation gossip text?

Link to comment
Share on other sites

  • 1 year later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use