diff --git a/GuildChat.lua b/GuildChat.lua index e9335e4..d770f9f 100644 --- a/GuildChat.lua +++ b/GuildChat.lua @@ -1,19 +1,17 @@ GuildChat = {} local LC = LibStub('libChat-1.0') -LC:registerName(function(...) return GuildChat:GetName(...) end) - local LGI = LibStub("LibGuildInfo-1.0") local AllianceColours = { ["Aldmeri Dominion"] = "|cffff00", ["Daggerfall Convenant"]= "|c4169E1", ["Ebonhart Pact"] = "|c8B0000"} -local ClassColours = {["Dragon Knight"] = "ff0000", ["Sorcerer"] = "00ffff", ["Nightblade"] = "FF8C00", ["Templar"] = "FF00FF"} +local ClassColours = {["Dragon Knight"] = "ca0000", ["Sorcerer"] = "0096ff", ["Nightblade"] = "9900f1", ["Templar"] = "efefef"} function GuildChat:GetLevel(name) - return LGI:GetLevelByMemberName(name) + return LGI:GetLevelByMemberName(name) or 0 end function GuildChat:GetClassColour(name) - return ClassColours[LGI:GetClassNameByMemberName(name)] + return ClassColours[LGI:GetClassNameByMemberName(name)] or "ffffff" end function GuildChat:GetLevelColour(name) @@ -21,7 +19,15 @@ function GuildChat:GetLevelColour(name) end function GuildChat:GetAtColour(name) - return AllianceColours[LGI:GetAllianceNameByMemberName(name)] + return AllianceColours[LGI:GetAllianceNameByMemberName(name)] or "ffffff" +end + +function GuildChat:GetPrintName(name) + if GuildChat.settings.characterName then + local guildmember = LGI:GetGuildMemberByMemberName("@" ..name) + return guildmember and guildmember.characterName or name + end + return name end local ChanInfoArray = ZO_ChatSystem_GetChannelInfo() @@ -36,19 +42,30 @@ function GuildChat:GetName(channelId, fromName, text) local formattedName = nil - local colour, display, name = nameLink:match("^|H([^:]*):([^\[]*)%[@([^\]]*)%]|h") + local colour, display, charname, name = nameLink:match("^|H([^:]-):([^\[]-)%[([^@]-)@([^\]]-)%]|h") if colour then - formattedName = "[" .. GuildChat:GetLevelColour(fromName) .. GuildChat:GetLevel(fromName) .. "|c" .. baseColour:ToHex() .. "]" .. - "[" .. GuildChat:GetAtColour(fromName) .. "@" .. - "|H" .. GuildChat:GetClassColour(fromName) .. ":" .. display .. name .. "|h" .. + formattedName = "[" .. GuildChat:GetLevelColour("@" .. name) .. GuildChat:GetLevel("@" .. name) .. "|c" .. baseColour:ToHex() .. "]" .. + "[" .. (charname or "") .. GuildChat:GetAtColour("@" .. name) .."@" .. + "|H" .. GuildChat:GetClassColour("@" .. name) .. ":" .. display .. GuildChat:GetPrintName(name) .. "|h" .. "|c" .. baseColour:ToHex() .. "]" end return formattedName or nameLink end +function GuildChat:Register() + LC:registerName(function(...) return GuildChat:GetName(...) end) +end + function GuildChat:Loaded(...) local eventId, addonName = ... if addonName ~= "GuildChat" then return end + GuildChat.settings = ZO_SavedVars:NewAccountWide('GuildChat_Settings', 1, nil, {characterName = false}) + SLASH_COMMANDS["/gctogglecharname"] = + function() + GuildChat.settings.characterName = not GuildChat.settings.characterName + d("GuildChat toggled to " .. (GuildChat.settings.characterName and "show character names" or "show account names")) + end + zo_callLater(GuildChat.Register, 1000) end EVENT_MANAGER:RegisterForEvent("GuildChatLoaded", EVENT_ADD_ON_LOADED, function(...) GuildChat:Loaded(...) end) \ No newline at end of file diff --git a/GuildChat.txt b/GuildChat.txt index 1bf73eb..c9eae63 100644 --- a/GuildChat.txt +++ b/GuildChat.txt @@ -2,7 +2,7 @@ ## Author: Wobin ## Version: @project-version@ ## APIVersion: 100003 -## SavedVariables: ChatColour_Settings +## SavedVariables: GuildChat_Settings Libs/LibStub/LibStub.lua Libs/libChat/libChat.lua diff --git a/Libs/libChat/libChat.lua b/Libs/libChat/libChat.lua index c81b381..dae9398 100644 --- a/Libs/libChat/libChat.lua +++ b/Libs/libChat/libChat.lua @@ -5,15 +5,15 @@ Date: 2014-4-10 Version: 1.0.0 ]]-- -local MAJOR, MINOR = "libChat-1.0", 1 +local MAJOR, MINOR = "libChat-1.0", 2 local libchat, oldminor = LibStub:NewLibrary(MAJOR, MINOR) if not libchat then return end -local funcName = nil -local funcText = nil -local funcFormat = nil +libchat.funcName = {} +libchat.funcText = {} +libchat.funcFormat = {} -- Listens for EVENT_CHAT_MESSAGE_CHANNEL event from ZO_ChatSystem local function libChatReceiver(channelID, from, text) @@ -28,20 +28,26 @@ local function libChatReceiver(channelID, from, text) end -- Function to affect name - if funcName then - from = funcName(channelID, from, text) + if #libchat.funcName > 0 then + for _,func in ipairs(libchat.funcName) do + from = func(channelID, from, text) + end if not from then return end end -- Function to affect text message - if funcText then - text = funcText(channelID, from, text) + if #libchat.funcText > 0 then + for _,func in ipairs(libchat.funcText) do + text = func(channelID, from, text) + end if not text then return end end -- Function to format message - if funcFormat then - message = funcFormat(channelID, from, text) + if #libchat.funcFormat > 0 then + for _,func in ipairs(libchat.funcFormat) do + message = func(channelID, from, text) + end if not message then return end else -- No formatting addon, so do default stuff. @@ -74,22 +80,22 @@ end -- Register a function to be called to modify sender name function libchat:registerName(func) - if not funcName then - funcName = func + if type(func) == "function" then + table.insert(libchat.funcName, func) end end -- Register a function to be called to modify message text function libchat:registerText(func) - if not funcText then - funcText = func + if type(func) == "function" then + table.insert(libchat.funcText, func) end end -- Register a function to be called to format message function libchat:registerFormat(func) - if not funcFormat then - funcFormat = func + if type(func) == "function" then + table.insert(libchat.funcFormat, func) end end diff --git a/Libs/libGuildInfo/LibGuildInfo.lua b/Libs/libGuildInfo/LibGuildInfo.lua index 968c5bc..093a3c6 100644 --- a/Libs/libGuildInfo/LibGuildInfo.lua +++ b/Libs/libGuildInfo/LibGuildInfo.lua @@ -39,6 +39,9 @@ function LibGuildInfo:GetAllianceNameByMemberName(name) end -- Setup functions -- + +-- This is my deep table copy function, that bypasses previously copied tables +-- to avoid infinite loops when it comes to recursive copying. local visitedTables = {} function LibGuildInfo:DeepTableCopy(source, subCall)