From d7864988b63eaa9c4704fd65852e58efa87c0673 Mon Sep 17 00:00:00 2001 From: Christopher Rosell Date: Wed, 14 Jul 2010 21:28:44 +0200 Subject: [PATCH] Add option to use notes as nicknames. --- Moniker.lua | 201 --- Moniker.toc | 16 +- config.lua | 27 + hooks.lua | 176 ++ libs/AceConfig-3.0/AceConfig-3.0.lua | 57 + libs/AceConfig-3.0/AceConfig-3.0.xml | 8 + .../AceConfigCmd-3.0/AceConfigCmd-3.0.lua | 787 ++++++++ .../AceConfigCmd-3.0/AceConfigCmd-3.0.xml | 4 + .../AceConfigDialog-3.0/AceConfigDialog-3.0.lua | 1895 ++++++++++++++++++++ .../AceConfigDialog-3.0/AceConfigDialog-3.0.xml | 4 + .../AceConfigRegistry-3.0.lua | 344 ++++ .../AceConfigRegistry-3.0.xml | 4 + libs/AceGUI-3.0/AceGUI-3.0.lua | 863 +++++++++ libs/AceGUI-3.0/AceGUI-3.0.xml | 26 + .../widgets/AceGUIWidget-BlizOptionsGroup.lua | 153 ++ libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua | 104 ++ libs/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua | 301 ++++ .../widgets/AceGUIWidget-ColorPicker.lua | 181 ++ .../widgets/AceGUIWidget-DropDown-Items.lua | 459 +++++ libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua | 705 ++++++++ .../widgets/AceGUIWidget-DropDownGroup.lua | 178 ++ libs/AceGUI-3.0/widgets/AceGUIWidget-EditBox.lua | 233 +++ libs/AceGUI-3.0/widgets/AceGUIWidget-Frame.lua | 305 ++++ libs/AceGUI-3.0/widgets/AceGUIWidget-Heading.lua | 76 + libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua | 149 ++ .../widgets/AceGUIWidget-InlineGroup.lua | 138 ++ .../widgets/AceGUIWidget-InteractiveLabel.lua | 219 +++ .../AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua | 230 +++ libs/AceGUI-3.0/widgets/AceGUIWidget-Label.lua | 158 ++ .../widgets/AceGUIWidget-MultiLineEditBox.lua | 309 ++++ .../widgets/AceGUIWidget-ScrollFrame.lua | 241 +++ .../widgets/AceGUIWidget-SimpleGroup.lua | 99 + libs/AceGUI-3.0/widgets/AceGUIWidget-Slider.lua | 282 +++ libs/AceGUI-3.0/widgets/AceGUIWidget-TabGroup.lua | 387 ++++ libs/AceGUI-3.0/widgets/AceGUIWidget-TreeGroup.lua | 746 ++++++++ libs/AceGUI-3.0/widgets/AceGUIWidget-Window.lua | 328 ++++ libs/CallbackHandler-1.0/CallbackHandler-1.0.lua | 240 +++ libs/CallbackHandler-1.0/CallbackHandler-1.0.xml | 4 + libs/LibStub-1.0/LibStub-1.0.lua | 30 + libs/LibStub-1.0/LibStub-1.0.xml | 4 + libs/tekKonfigAboutPanel.lua | 115 ++ locale/enGB.lua | 4 + moniker.lua | 136 ++ 43 files changed, 10722 insertions(+), 204 deletions(-) delete mode 100644 Moniker.lua create mode 100644 config.lua create mode 100644 hooks.lua create mode 100644 libs/AceConfig-3.0/AceConfig-3.0.lua create mode 100644 libs/AceConfig-3.0/AceConfig-3.0.xml create mode 100644 libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.lua create mode 100644 libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml create mode 100644 libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua create mode 100644 libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml create mode 100644 libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua create mode 100644 libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml create mode 100644 libs/AceGUI-3.0/AceGUI-3.0.lua create mode 100644 libs/AceGUI-3.0/AceGUI-3.0.xml create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-BlizOptionsGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown-Items.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-DropDownGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-EditBox.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Frame.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Heading.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-InlineGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Label.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-MultiLineEditBox.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-ScrollFrame.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-SimpleGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Slider.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-TabGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-TreeGroup.lua create mode 100644 libs/AceGUI-3.0/widgets/AceGUIWidget-Window.lua create mode 100644 libs/CallbackHandler-1.0/CallbackHandler-1.0.lua create mode 100644 libs/CallbackHandler-1.0/CallbackHandler-1.0.xml create mode 100644 libs/LibStub-1.0/LibStub-1.0.lua create mode 100644 libs/LibStub-1.0/LibStub-1.0.xml create mode 100644 libs/tekKonfigAboutPanel.lua create mode 100644 locale/enGB.lua create mode 100644 moniker.lua diff --git a/Moniker.lua b/Moniker.lua deleted file mode 100644 index 8a56db4..0000000 --- a/Moniker.lua +++ /dev/null @@ -1,201 +0,0 @@ -local addon = CreateFrame"Frame" -local addonname = ... - -local loaddelay = 1.5 -local origs = {} - -UnitPopupButtons["BN_RENAME"] = { text = PET_RENAME, dist = 0 } -table.insert(UnitPopupMenus["BN_FRIEND"], 7, "BN_RENAME") -table.insert(UnitPopupMenus["BN_FRIEND_OFFLINE"], 2, "BN_RENAME") - -local function UpdateName(origname, name) - if name == origname or #name == 0 then - MonikerDB[origname] = nil - else - MonikerDB[origname] = name - end - - FriendsFrame_Update() -end - -local function GetNickname(origname) - return MonikerDB[origname] or origname -end - -local function ConvertLink(text) - return text:gsub("|HBNplayer:(.-):(.-):(.-):(.-):(.-)|h%[(.+)%]|h", function(a1, a2, a3, a4, a5, a6) - return ("|HBNplayer:%s:%s:%s:%s:%s|h[%s]|h"):format(a1, a2, a3, a4, a5, GetNickname(a6)) - end) -end - -local function ReplaceText(frame) - if frame and frame.GetText and frame.SetText then - local text = frame:GetText() - if not text then return end - - for orig, nick in pairs(MonikerDB) do - if text:find(orig, nil, true) then - return frame:SetText(text:replace(orig, nick)) - end - end - end -end - -local function AddMessage(self, text, ...) - if text:find"You are now in a conversation with" then - for orig, nick in pairs(MonikerDB) do - if text:find(orig, nil, true) then - text = text:replace(orig, nick) - end - end - end - - return origs[self](self, ConvertLink(text), ...) -end - -local function HookChatFrame(cf) - if not origs[cf] then - origs[cf] = cf.AddMessage - cf.AddMessage = AddMessage - end -end - -local function HookFunctions() - -- Hook tooltips - FriendsTooltip:HookScript("OnShow", function(self) - ReplaceText(FriendsTooltipHeader) - end) - - BNToastFrame:HookScript("OnShow", function(self) - ReplaceText(BNToastFrameTopLine) - end) - - hooksecurefunc("FriendsFrameTooltip_Show", function(self) - ReplaceText(FriendsTooltipHeader) - end) - - - -- Hook friends frame and it's subframes - hooksecurefunc("FriendsFrame_SetButton", function(button, index, firstbutton) - if button.buttonType == FRIENDS_BUTTON_TYPE_BNET then - ReplaceText(button.name) - end - end) - - hooksecurefunc(FriendsFrameFriendsScrollFrame, "buttonFunc", function(button, index, firstbutton) - if button.buttonType == FRIENDS_BUTTON_TYPE_BNET then - ReplaceText(button.name) - end - end) - - hooksecurefunc("FriendsFriendsList_Update", function() - ReplaceText(FriendsFriendsFrameTitle) - - for i = 1, FRIENDS_FRIENDS_TO_DISPLAY do - local frame = _G["FriendsFriendsButton"..i] - if frame then - ReplaceText(frame.name) - end - end - end) - - hooksecurefunc("BNConversationInvite_Update", function() - for i = 1, BN_CONVERSATION_INVITE_NUM_DISPLAYED do - local frame = _G["BNConversationInviteDialogListFriend"..i] - if frame then - ReplaceText(frame.name) - end - end - end) - - hooksecurefunc(StaticPopupDialogs["SET_BNFRIENDNOTE"], "OnShow", function(self) - ReplaceText(self.text) - end) - - - -- Chat related hooks - hooksecurefunc("FCF_SetWindowName", function(frame, name, ...) - HookChatFrame(frame) - ReplaceText(_G[frame:GetName().."Tab"]) - end) - - hooksecurefunc("ChatEdit_UpdateHeader", function(editbox) - local event = editbox:GetAttribute"chatType" - local header = _G[editbox:GetName().."Header"] - - if event == "BN_WHISPER" then - header:SetFormattedText(CHAT_BN_WHISPER_SEND, GetNickname(editbox:GetAttribute"tellTarget")) - editbox:SetTextInsets(15 + header:GetWidth(), 13, 0, 0) - end - end) - - for i = 1, NUM_CHAT_WINDOWS do - HookChatFrame(_G["ChatFrame"..i]) - end - - -- Handle right click menu - hooksecurefunc("UnitPopup_OnClick", function(self) - local dropdown = UIDROPDOWNMENU_INIT_MENU - local button = self.value - - if button == "BN_RENAME" then - local pid, firstname, lastname = BNGetFriendInfoByID(dropdown.presenceID) - local name = firstname.." "..lastname - - StaticPopup_Show("BN_RENAME_FRIEND", name, nil, name) - end - end) - - FriendsFrame_Update() -end - -StaticPopupDialogs["BN_RENAME_FRIEND"] = { - text = "Set a nickname for %s", - button1 = ACCEPT, - button2 = CANCEL, - hasEditBox = 1, - hideOnEscape = 1, - timeout = 0, - exclusive = 1, - whileDead = 1, - - OnAccept = function(self) - local name = self.editBox:GetText() - UpdateName(self.data, name) - end, - - OnShow = function(self) - local name = MonikerDB[self.data] or "" - self.editBox:SetText(name) - self.editBox:SetFocus() - end, - - EditBoxOnEnterPressed = function(self) - local parent = self:GetParent() - local name = parent.editBox:GetText() - - UpdateName(parent.data, name) - parent:Hide() - end, - - EditBoxOnEscapePressed = function(self) - self:GetParent():Hide() - end, -} - - -addon:RegisterEvent"ADDON_LOADED" -addon:SetScript("OnEvent", function(self, ev, addon) - if addon ~= addonname then return end - - MonikerDB = MonikerDB or {} - - local elapsed = 0 - self:SetScript("OnUpdate", function(self, e) - elapsed = elapsed + e - if elapsed > loaddelay then - HookFunctions() - self:SetScript("OnUpdate", nil) - end - end) -end) diff --git a/Moniker.toc b/Moniker.toc index c31b781..43d7abd 100644 --- a/Moniker.toc +++ b/Moniker.toc @@ -1,7 +1,7 @@ ## Interface: 30300 ## Title: Moniker ## Notes: Give your RealID friends nicknames -## Version: 1.4 +## Version: 1.5 ## Author: Christopher Rosell ## X-Email: chrippa@gmail.com ## X-Category: Social @@ -9,6 +9,16 @@ ## LoadManagers: AddonLoader ## X-LoadOn-Always: delayed -## SavedVariables: MonikerDB +## SavedVariables: MonikerDB, MonikerConfig -Moniker.lua +libs\LibStub-1.0\LibStub-1.0.xml +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\AceGUI-3.0\AceGUI-3.0.xml +libs\AceConfig-3.0\AceConfig-3.0.xml +libs\tekKonfigAboutPanel.lua + +locale\enGB.lua + +config.lua +hooks.lua +moniker.lua diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..d746c59 --- /dev/null +++ b/config.lua @@ -0,0 +1,27 @@ +local addonname, addon = ... +local L = addon.L + +local options = { + type = "group", + name = addonname, + + + args = { + backends = { + name = "Nickname source", + type = 'multiselect', + + values = { [1] = L["Saved variables"], [2] = L["Notes"] }, + get = function(info, key) return addon.config.dbbackend == key end, + set = function(info, key, val) addon.config.dbbackend = key end + } + } +} + + +function addon:CreateConfig() + LibStub("AceConfig-3.0"):RegisterOptionsTable("Moniker-General", options) + LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Moniker-General", addonname) + + LibStub("tekKonfig-AboutPanel").new(addonname, addonname) +end diff --git a/hooks.lua b/hooks.lua new file mode 100644 index 0000000..af58fa7 --- /dev/null +++ b/hooks.lua @@ -0,0 +1,176 @@ +local addonname, addon = ... +local L = addon.L + +addon.hooks = {} + +local function ReplaceText(frame) + if frame and frame.GetText and frame.SetText then + local text = frame:GetText() + if not text then return end + + for orig, nick in addon:IterNicknames() do + if text:find(orig, nil, true) then + return frame:SetText(text:replace(orig, nick)) + end + end + end +end + +local function ReplaceLink(text) + return text:gsub("|HBNplayer:(.-):(.-):(.-):(.-):(.-)|h%[(.+)%]|h", function(a1, a2, a3, a4, a5, a6) + return ("|HBNplayer:%s:%s:%s:%s:%s|h[%s]|h"):format(a1, a2, a3, a4, a5, addon:GetNickname(a6) or a6) + end) +end + +function addon.hooks.chat() + local origs = {} + + local function AddMessage(self, text, ...) + if text:find"You are now in a conversation with" then + for orig, nick in addon:IterNicknames() do + if text:find(orig, nil, true) then + text = text:replace(orig, nick) + end + end + end + + return origs[self](self, ReplaceLink(text), ...) + end + + local function HookChatFrame(cf) + if not origs[cf] then + origs[cf] = cf.AddMessage + cf.AddMessage = AddMessage + end + end + + hooksecurefunc("FCF_SetWindowName", function(frame, name, ...) + HookChatFrame(frame) + ReplaceText(_G[frame:GetName().."Tab"]) + end) + + hooksecurefunc("ChatEdit_UpdateHeader", function(editbox) + local event = editbox:GetAttribute"chatType" + local header = _G[editbox:GetName().."Header"] + local target = editbox:GetAttribute"tellTarget" + + if event == "BN_WHISPER" then + header:SetFormattedText(CHAT_BN_WHISPER_SEND, addon:GetNickname(target) or target) + editbox:SetTextInsets(15 + header:GetWidth(), 13, 0, 0) + end + end) + + for i = 1, NUM_CHAT_WINDOWS do + HookChatFrame(_G["ChatFrame"..i]) + end +end + +function addon.hooks.friendsframe() + -- Hook tooltips + FriendsTooltip:HookScript("OnShow", function(self) + ReplaceText(FriendsTooltipHeader) + end) + + BNToastFrame:HookScript("OnShow", function(self) + ReplaceText(BNToastFrameTopLine) + end) + + hooksecurefunc("FriendsFrameTooltip_Show", function(self) + ReplaceText(FriendsTooltipHeader) + end) + + -- Hook friends frame and it's subframes + hooksecurefunc("FriendsFrame_SetButton", function(button, index, firstbutton) + if button.buttonType == FRIENDS_BUTTON_TYPE_BNET then + ReplaceText(button.name) + end + end) + + hooksecurefunc("FriendsFrame_ShowBNDropdown", function(...) + ReplaceText(DropDownList1Button1) + end) + + hooksecurefunc(FriendsFrameFriendsScrollFrame, "buttonFunc", function(button, index, firstbutton) + if button.buttonType == FRIENDS_BUTTON_TYPE_BNET then + ReplaceText(button.name) + end + end) + + hooksecurefunc("FriendsFriendsList_Update", function() + ReplaceText(FriendsFriendsFrameTitle) + + for i = 1, FRIENDS_FRIENDS_TO_DISPLAY do + local frame = _G["FriendsFriendsButton"..i] + if frame then + ReplaceText(frame.name) + end + end + end) + + hooksecurefunc("BNConversationInvite_Update", function() + for i = 1, BN_CONVERSATION_INVITE_NUM_DISPLAYED do + local frame = _G["BNConversationInviteDialogListFriend"..i] + if frame then + ReplaceText(frame.name) + end + end + end) + + hooksecurefunc(StaticPopupDialogs["SET_BNFRIENDNOTE"], "OnShow", function(self) + ReplaceText(self.text) + end) + + addon:Update() +end + +function addon.hooks.popup() + StaticPopupDialogs["BN_RENAME_FRIEND"] = { + text = L["Set a nickname for %s"], + button1 = ACCEPT, + button2 = CANCEL, + hasEditBox = 1, + hideOnEscape = 1, + timeout = 0, + exclusive = 1, + whileDead = 1, + + OnAccept = function(self) + local name = self.editBox:GetText() + addon:SetNickname(self.data, name) + end, + + OnShow = function(self) + local name = addon:GetNickname(self.data) or "" + + self.editBox:SetText(name) + self.editBox:SetFocus() + end, + + EditBoxOnEnterPressed = function(self) + local parent = self:GetParent() + local name = parent.editBox:GetText() + + addon:SetNickname(parent.data, name) + parent:Hide() + end, + + EditBoxOnEscapePressed = function(self) + self:GetParent():Hide() + end, + } + + UnitPopupButtons["BN_RENAME"] = { text = PET_RENAME, dist = 0 } + + -- Handle right click menu + hooksecurefunc("UnitPopup_OnClick", function(self) + local dropdown = UIDROPDOWNMENU_INIT_MENU + local button = self.value + + if button == "BN_RENAME" then + local pid, firstname, lastname = BNGetFriendInfoByID(dropdown.presenceID) + local name = firstname.." "..lastname + + StaticPopup_Show("BN_RENAME_FRIEND", name, nil, name) + end + end) +end diff --git a/libs/AceConfig-3.0/AceConfig-3.0.lua b/libs/AceConfig-3.0/AceConfig-3.0.lua new file mode 100644 index 0000000..b66022d --- /dev/null +++ b/libs/AceConfig-3.0/AceConfig-3.0.lua @@ -0,0 +1,57 @@ +--- AceConfig-3.0 wrapper library. +-- Provides an API to register an options table with the config registry, +-- as well as associate it with a slash command. +-- @class file +-- @name AceConfig-3.0 +-- @release $Id: AceConfig-3.0.lua 877 2009-11-02 15:56:50Z nevcairiel $ + +--[[ +AceConfig-3.0 + +Very light wrapper library that combines all the AceConfig subcomponents into one more easily used whole. + +]] + +local MAJOR, MINOR = "AceConfig-3.0", 2 +local AceConfig = LibStub:NewLibrary(MAJOR, MINOR) + +if not AceConfig then return end + +local cfgreg = LibStub("AceConfigRegistry-3.0") +local cfgcmd = LibStub("AceConfigCmd-3.0") +local cfgdlg = LibStub("AceConfigDialog-3.0") +--TODO: local cfgdrp = LibStub("AceConfigDropdown-3.0") + +-- Lua APIs +local pcall, error, type, pairs = pcall, error, type, pairs + +-- ------------------------------------------------------------------- +-- :RegisterOptionsTable(appName, options, slashcmd, persist) +-- +-- - appName - (string) application name +-- - options - table or function ref, see AceConfigRegistry +-- - slashcmd - slash command (string) or table with commands, or nil to NOT create a slash command + +--- Register a option table with the AceConfig registry. +-- You can supply a slash command (or a table of slash commands) to register with AceConfigCmd directly. +-- @paramsig appName, options [, slashcmd] +-- @param appName The application name for the config table. +-- @param options The option table (or a function to generate one on demand) +-- @param slashcmd A slash command to register for the option table, or a table of slash commands. +-- @usage +-- local AceConfig = LibStub("AceConfig-3.0") +-- AceConfig:RegisterOptionsTable("MyAddon", myOptions, {"/myslash", "/my"}) +function AceConfig:RegisterOptionsTable(appName, options, slashcmd) + local ok,msg = pcall(cfgreg.RegisterOptionsTable, self, appName, options) + if not ok then error(msg, 2) end + + if slashcmd then + if type(slashcmd) == "table" then + for _,cmd in pairs(slashcmd) do + cfgcmd:CreateChatCommand(cmd, appName) + end + else + cfgcmd:CreateChatCommand(slashcmd, appName) + end + end +end diff --git a/libs/AceConfig-3.0/AceConfig-3.0.xml b/libs/AceConfig-3.0/AceConfig-3.0.xml new file mode 100644 index 0000000..d9eb96a --- /dev/null +++ b/libs/AceConfig-3.0/AceConfig-3.0.xml @@ -0,0 +1,8 @@ + + + + + +