From db3db1659440dcbf9d2b23f75bb8a7eec18c7923 Mon Sep 17 00:00:00 2001 From: Lothar Buchholz Date: Tue, 26 May 2020 00:51:59 +0200 Subject: [PATCH] Version 0.2.2 - added Options UI under Interface Options - store settings in profiles - added more translations --- CHANGELOG.md | 22 +- Grichelde.lua | 76 +- Grichelde.toc | 9 +- GricheldeOptions.lua | 332 +++ libs.xml | 3 + libs/AceConfig-3.0/AceConfig-3.0.lua | 58 + libs/AceConfig-3.0/AceConfig-3.0.xml | 8 + .../AceConfigCmd-3.0/AceConfigCmd-3.0.lua | 794 +++++++ .../AceConfigCmd-3.0/AceConfigCmd-3.0.xml | 4 + .../AceConfigDialog-3.0.lua | 1983 +++++++++++++++++ .../AceConfigDialog-3.0.xml | 4 + .../AceConfigRegistry-3.0.lua | 350 +++ .../AceConfigRegistry-3.0.xml | 4 + libs/AceDB-3.0/AceDB-3.0.lua | 746 +++++++ libs/AceDB-3.0/AceDB-3.0.xml | 4 + libs/AceDBOptions-3.0/AceDBOptions-3.0.lua | 460 ++++ libs/AceDBOptions-3.0/AceDBOptions-3.0.xml | 4 + localisation/deDE.lua | 58 +- localisation/enUS.lua | 55 +- 19 files changed, 4922 insertions(+), 52 deletions(-) create mode 100644 GricheldeOptions.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/AceDB-3.0/AceDB-3.0.lua create mode 100644 libs/AceDB-3.0/AceDB-3.0.xml create mode 100644 libs/AceDBOptions-3.0/AceDBOptions-3.0.lua create mode 100644 libs/AceDBOptions-3.0/AceDBOptions-3.0.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index a2c97c8..586c2c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] Version 1.0 - 2020-05-27 First version to be released ### Added -- slash commands -- Options GUI -- store settings globally or per character -- added translations +- add replacements via options UI +- handle replacement via slash command +- case sensitivity +- consolidate consecutive matches + +## Version 0.2.2 - 2020-05-26 +### Added +- added Options UI under Interface Options +- store settings in profiles +- added more translations + +## Version 0.2.1 - 2020-05-25 +### Added +- support automatic packaging for curseforge via .pkgmeta +- include project logo +- auto-update the project description via .docmeta ## Version 0.2 - 2020-05-25 ### Added @@ -20,4 +32,4 @@ First version to be released ## Version 0.1 - 2020-05-24 ### Added -- bootstrap addon with Ace3 from [Misspelled](https://www.curseforge.com/wow/addons/misspelled) \ No newline at end of file +- bootstrap addon with Ace3 based on [Misspelled](https://www.curseforge.com/wow/addons/misspelled) \ No newline at end of file diff --git a/Grichelde.lua b/Grichelde.lua index 3a4faa6..bff87ea 100644 --- a/Grichelde.lua +++ b/Grichelde.lua @@ -15,15 +15,14 @@ --------------------------------------------------------------------------]] -- +-- initialize addon local AddonName, AddonTable = ... - -local Grichelde = LibStub("AceAddon-3.0"):NewAddon("Grichelde", "AceEvent-3.0", "AceHook-3.0") +Grichelde = LibStub("AceAddon-3.0"):NewAddon(AddonName, "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0") +Grichelde.L = LibStub("AceLocale-3.0"):GetLocale("Grichelde", true) Grichelde.version = GetAddOnMetadata(AddonName, "Version") -Grichelde.build = GetAddOnMetadata(AddonName, "X-Build") or "UNKNOWN" - -local L = LibStub("AceLocale-3.0"):GetLocale("Grichelde", true) - -local Grichelde_Debug = false +Grichelde.build = GetAddOnMetadata(AddonName, "X-Build") or "Experimental" +Grichelde.hooks = {} +Grichelde.debug = false -- faster function lookups by mapping to local refs local string_find = string.find @@ -39,34 +38,15 @@ local tContains = tContains local pairs = pairs local ipairs = ipairs -local Grichelde_Hooks = {} - ---local Grichelde_ChatTypes = { "SAY", "EMOTE", "YELL", "PARTY", "GUILD", "OFFICER", "RAID", "RAID_WARNING", "INSTANCE_CHAT", "BATTLEGROUND", "WHISPER" } local Grichelde_ChatTypes = { "SAY", "EMOTE", "YELL", "PARTY", "GUILD" } local Grichelde_ChatCommands = { "/s", "/e", "/me", "/y", "/p", "/pl", "/g", "/o", "/raid", "/rl", "/rw", "/i", "bg", "/w", "/r", "/tt" } --- do not replace these patterns -local Grichelde_IgnorePatterns = { - "|[Cc]%x%x%x%x%x%x%x%x.-|r", -- colored items (or links) - "|H.-|h", -- item links (http://www.wowwiki.com/ItemLink) - "|T.-|t", -- textures - "|n", -- newline - "{rt[1-8]}", -- rumbered raid target icons - "{Star}", -- named raid target icon 1 - "{Circle}", -- named raid target icon 2 - "{Coin}", -- named raid target icon 2 - "{Diamond}", -- named raid target icon 3 - "{Triangle}", -- named raid target icon 4 - "{Moon}", -- named raid target icon 5 - "{Square}", -- named raid target icon 6 - "{Cross}", -- named raid target icon 7 - "{X}", -- named raid target icon 7 - "{Skull}" -- named raid target icon 8 -} - +-- Ace3 callbacks function Grichelde:OnInitialize() -- Build Interface Options window - --self:CreateInterfaceOptions() + self:LoadDatabase() + self:SetupOptions() + self:SetupSlashCommands() -- Watch for WIM and Prat to Load, then integrate self:RegisterEvent("ADDON_LOADED", "HookIntoForOtherChatAddons") @@ -81,7 +61,7 @@ function Grichelde:OnEnable() end -- tell the world we are listening - print(L.AddonLoaded) + print(self.L.AddonLoaded) end function Grichelde:OnDisable() @@ -106,12 +86,12 @@ function Grichelde:HookIntoForOtherChatAddons(event, addonName) -- into ChatThrottleLib to be on the safe side. if (ChatThrottleLib) then - Grichelde_Hooks["ChatThrottleLib"] = ChatThrottleLib.SendChatMessage + Grichelde.hooks["ChatThrottleLib"] = ChatThrottleLib.SendChatMessage function ChatThrottleLib:SendChatMessage(prio, prefix, text, ...) Grichelde:DebugPrint("ChatThrottleLib:SendChatMessage : Hook called") local replacedText = Grichelde:CheckAndReplace(text) - return Grichelde_Hooks["ChatThrottleLib"](ChatThrottleLib, prio, prefix, replacedText, ...) + return Grichelde.hooks["ChatThrottleLib"](ChatThrottleLib, prio, prefix, replacedText, ...) end end end @@ -180,6 +160,26 @@ end --- @return number function Grichelde:CheckForPreversableText(text) self:DebugPrint("CheckForPreversableText : text is " .. text) + + -- do not replace these patterns + local Grichelde_IgnorePatterns = { + "|[Cc]%x%x%x%x%x%x%x%x.-|r", -- colored items (or links) + "|H.-|h", -- item links (http://www.wowwiki.com/ItemLink) + "|T.-|t", -- textures + "|n", -- newline + "{rt[1-8]}", -- rumbered raid target icons + "{Star}", -- named raid target icon 1 + "{Circle}", -- named raid target icon 2 + "{Coin}", -- named raid target icon 2 + "{Diamond}", -- named raid target icon 3 + "{Triangle}", -- named raid target icon 4 + "{Moon}", -- named raid target icon 5 + "{Square}", -- named raid target icon 6 + "{Cross}", -- named raid target icon 7 + "{X}", -- named raid target icon 7 + "{Skull}" -- named raid target icon 8 + } + -- Calling find on ever pattern might be inefficient but its way less code. for _, pattern in ipairs(Grichelde_IgnorePatterns) do local pos1, pos2 = string_find(text, pattern) @@ -257,6 +257,8 @@ end function Grichelde:ReplaceCharacters(text) -- todo: read from options -- todo: case (in)sensitivity + -- todo: consolidate consecutive + -- todo: prevent infinite loops - is that even possible? local replacement = text replacement = string_gsub(replacement, "s", "ch") replacement = string_gsub(replacement, "S", "Ch") @@ -324,11 +326,15 @@ function Grichelde:SplitOnLastMatch(text, start) end function Grichelde:DebugPrint(message) - if (Grichelde_Debug) then - print(GRAY_FONT_COLOR_CODE .. "Grichelde:" .. FONT_COLOR_CODE_CLOSE .. " " .. message) + if (self.debug) then + self:Print(message) end end +function Grichelde:Print(message) + print(GRAY_FONT_COLOR_CODE .. self.L.AddonName .. FONT_COLOR_CODE_CLOSE .. ": " .. message) +end + function Grichelde:EmptyIfNil(value) if value == nil then return "" end return tostring(value) diff --git a/Grichelde.toc b/Grichelde.toc index dd720eb..3a2ea12 100644 --- a/Grichelde.toc +++ b/Grichelde.toc @@ -3,7 +3,7 @@ ## Title: Grichelde ## Notes: Replaces characters you type in the chat box ## Notes-de: Ersetzt eingegebene Zeichen in der Chat-Zeile -## Version: 1.0 +## Version: 0.2.2 ## Author: Teilzeit-Jedi ## eMail: tj@teilzeit-jedi.de @@ -14,10 +14,11 @@ ## X-Embeds: Ace3 ## OptionalDeps: Ace3 -## SavedVariables: GrichseldeOptions -## SavedVariablesPerCharacter: GrichseldeCharOptions +## SavedVariables: GrichseldeDB +## SavedVariablesPerCharacter: GrichseldePerCharDB libs.xml localisation.xml -Grichelde.lua \ No newline at end of file +Grichelde.lua +GricheldeOptions.lua diff --git a/GricheldeOptions.lua b/GricheldeOptions.lua new file mode 100644 index 0000000..43e9c62 --- /dev/null +++ b/GricheldeOptions.lua @@ -0,0 +1,332 @@ +local AddonName, AddonTable = ... +local Grichelde = LibStub("AceAddon-3.0"):GetAddon(AddonName) + +Grichelde.options = { + name = Grichelde.L.AddonName, + type = "group", + cmdHidden = true, + childGroups = "tab", + args = { + enabled = { + order = 0, + type = "toggle", + name = Grichelde.L.Options_Enabled_Name, + desc = Grichelde.L.Options_Enabled_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end, + }, + + channels = { + order = 2, + type = "group", + name = Grichelde.L.Options_Channels_Group_Name, + desc = Grichelde.L.Options_Channels_Group_Desc, + args = { + say = { + order = 0, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelSay_Name, + desc = Grichelde.L.Options_Channels_ChannelSay_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + emote = { + order = 1, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelEmote_Name, + desc = Grichelde.L.Options_Channels_ChannelEmote_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + yell = { + order = 2, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelYell_Name, + desc = Grichelde.L.Options_Channels_ChannelYell_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + party = { + order = 3, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelParty_Name, + desc = Grichelde.L.Options_Channels_ChannelParty_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + partyLeader = { + order = 4, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelPartyLeader_Name, + desc = Grichelde.L.Options_Channels_ChannelPartyLeader_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + guild = { + order = 5, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelGuild_Name, + desc = Grichelde.L.Options_Channels_ChannelGuild_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + officer = { + order = 6, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelOfficer_Name, + desc = Grichelde.L.Options_Channels_ChannelOfficer_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + raid = { + order = 7, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelRaid_Name, + desc = Grichelde.L.Options_Channels_ChannelRaid_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + raidLeader = { + order = 8, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelRaidLeader_Name, + desc = Grichelde.L.Options_Channels_ChannelRaidLeader_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + instance = { + order = 9, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelInstance_Name, + desc = Grichelde.L.Options_Channels_ChannelInstance_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + battleground = { + order = 10, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelBattleground_Name, + desc = Grichelde.L.Options_Channels_ChannelBattleground_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + whisper = { + order = 11, + type = "toggle", + name = Grichelde.L.Options_Channels_ChannelWhisper_Name, + desc = Grichelde.L.Options_Channels_ChannelWhisper_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + } + }, + + replacements = { + order = 3, + type = "group", + name = Grichelde.L.Options_Replacements_Group_Name, + desc = Grichelde.L.Options_Replacements_Group_Desc, + childGroups = "tree", + args = { + searchText = { + order = 0, + type = "input", + name = Grichelde.L.Options_Replacements_SearchText_Name, + desc = Grichelde.L.Options_Replacements_SearchText_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + replacetext = { + order = 1, + type = "input", + name = Grichelde.L.Options_Replacements_ReplaceText_Name, + desc = Grichelde.L.Options_Replacements_ReplaceText_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + }, + caseSensitive = { + order = 2, + type = "toggle", + name = Grichelde.L.Options_Replacements_CaseSensitive_Name, + desc = Grichelde.L.Options_Replacements_CaseSensitive_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end }, + consolidate = { + order = 3, + type = "toggle", + name = Grichelde.L.Options_Replacements_Consolidate_Name, + desc = Grichelde.L.Options_Replacements_Consolidate_Desc, + set = function(info, val) Grichelde.enabled = val end, + get = function(info) return Grichelde.enabled end + } + } + } + }, +} + +local Grichelde_DB_Defaults = { + profile = { + enabled = true, + channels = { + "SAY", "EMOTE", "YELL", "PARTY", "GUILD" + }, + replacements = { + ["**"] = { + left = "", + right = "", + caseSensitive = false, + consolidate = true, + }, + replacement = { + left = "s", + right = "ch", + caseSensitive = false, + consolidate = true, + }, + replacement = { + left = "t", + right = "ck", + caseSensitive = false, + consolidate = true, + } + } + } +} + +function Grichelde:LoadDatabase() + -- Called when the addon is loaded + self.DB = LibStub("AceDB-3.0"):New(AddonName .."DB", Grichelde_DB_Defaults, true) + self.DB.RegisterCallback(self, "OnProfileChanged", "RefreshConfig") + self.DB.RegisterCallback(self, "OnProfileCopied", "RefreshConfig") + self.DB.RegisterCallback(self, "OnProfileReset", "RefreshConfig") + + local activeProfile = self.DB:GetCurrentProfile() + self:Print("current profile " .. activeProfile) +end + +function Grichelde:SetupOptions() + -- add DB-backed profiles to UI options + self.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.DB) +-- self.options.args.profile.order = 1 + + -- Adding options to blizzard frame + self.Config = LibStub("AceConfig-3.0"):RegisterOptionsTable(AddonName, self.options) + self.Dialog = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddonName, self.L.AddonName) +end + +function Grichelde:SetupSlashCommands() + local function HandleSlashCommand(input) + -- Show the GUI if no input is supplied, otherwise handle the chat input. + if not input or input:trim() == "" then + LibStub("AceConfigDialog-3.0"):Open(AddonName) + else + -- handle slash ourselves + self:Print("Handle slash command: " .. input) + end + end + + self:RegisterChatCommand("grichelde", HandleSlashCommand) + self:RegisterChatCommand("gri", HandleSlashCommand) +end + +function Grichelde:RefreshConfig(name) + self:Print("Refreshed: " .. name) +end + +--[[ +-- profile actions +function Grichelde:SaveProfile(name) + local toCopy = self.db:GetCurrentProfile() + if name and name ~= toCopy then + self.db:SetProfile(name) + self.db:CopyProfile(toCopy) + end +end + +function Grichelde:SetProfile(name) + local profile = self:MatchProfile(name) + if profile and profile ~= self.db:GetCurrentProfile() then + self.db:SetProfile(profile) + else + self:Printf(L.Options_Profile_Invalid, name or "null") + end +end + +function Grichelde:DeleteProfile(name) + local profile = self:MatchProfile(name) + if profile and profile ~= self.db:GetCurrentProfile() then + self.db:DeleteProfile(profile) + else + self:Print(L.Options_Profile_DeleteError) + end +end + +function Grichelde:CopyProfile(name) + if name and name ~= self.db:GetCurrentProfile() then + self.db:CopyProfile(name) + end +end + +function Grichelde:ResetProfile() + self.db:ResetProfile() +end + +function Grichelde:ListProfiles() + self:Print(L.Options_Profile_Available) + + local current = self.db:GetCurrentProfile() + for _, k in ipairs(self.db:GetProfiles()) do + if k == current then + print(" - " .. k, 1, 1, 0) + else + print(" - " .. k) + end + end +end + +function Grichelde:MatchProfile(name) + name = name:lower() + + local nameRealm = name .. " - " .. GetRealmName():lower() + local match + + for _, k in ipairs(self.db:GetProfiles()) do + local key = k:lower() + if key == name then + return k + elseif key == nameRealm then + match = k + end + end + return match +end + +-- profile events +function Grichelde:OnNewProfile(msg, db, name) + self:Printf(L.Options_Profile_Created, name) +end + +function Grichelde:OnProfileDeleted(msg, db, name) + self:Printf(L.Options_Profile_Deleted, name) +end + +function Grichelde:OnProfileChanged(msg, db, name) + self:Printf(L.Options_Profile_Loaded, name) + self:Load() +end + +function Grichelde:OnProfileCopied(msg, db, name) + self:Printf(L.Options_Profile_Copied, name) + self:Reload() +end + +function Grichelde:OnProfileReset(msg, db) + self:Printf(L.Options_Profile_Reset, db:GetCurrentProfile()) + self:Reload() +end + +function Grichelde:OnProfileShutdown(msg, db, name) + self:Unload() +end +]]-- + diff --git a/libs.xml b/libs.xml index 4c9df75..9c38394 100644 --- a/libs.xml +++ b/libs.xml @@ -4,7 +4,10 @@