Version 0.4.0
- restructured files - extract functions and color codes - filter channels
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
local AddonName, _ = ...
|
||||
-- read namespace from global env
|
||||
local _G = _G
|
||||
local Grichelde = _G.Grichelde
|
||||
|
||||
local unpack, join, toString = Grichelde.functions.unpack, Grichelde.functions.join, Grichelde.functions.toString
|
||||
|
||||
function Grichelde:CreateOptionsUI()
|
||||
return {
|
||||
@@ -15,8 +19,6 @@ function Grichelde:CreateOptionsUI()
|
||||
type = "toggle",
|
||||
name = self.L.Options_Enabled_Name,
|
||||
desc = self:Format(self.L.Options_Enabled_Desc, self.L.AddonName),
|
||||
set = function(info, val) self.db.profile.enabled=val end,
|
||||
get = function(info) return self.db.profile.enabled end,
|
||||
disabled = false,
|
||||
},
|
||||
|
||||
@@ -80,20 +82,26 @@ function Grichelde:CreateOptionsUI()
|
||||
name = self.L.Options_Channels_ChannelRaidLeader_Name,
|
||||
desc = self:Format(self.L.Options_Channels_ChannelRaidLeader_Desc, self.L.AddonName),
|
||||
},
|
||||
instance = {
|
||||
raidWarning = {
|
||||
order = 9,
|
||||
type = "toggle",
|
||||
name = self.L.Options_Channels_ChannelRaidWarning_Name,
|
||||
desc = self:Format(self.L.Options_Channels_ChannelRaidWarning_Desc, self.L.AddonName),
|
||||
},
|
||||
instance = {
|
||||
order = 10,
|
||||
type = "toggle",
|
||||
name = self.L.Options_Channels_ChannelInstance_Name,
|
||||
desc = self:Format(self.L.Options_Channels_ChannelInstance_Desc, self.L.AddonName),
|
||||
},
|
||||
battleground = {
|
||||
order = 10,
|
||||
order = 11,
|
||||
type = "toggle",
|
||||
name = self.L.Options_Channels_ChannelBattleground_Name,
|
||||
desc = self:Format(self.L.Options_Channels_ChannelBattleground_Desc, self.L.AddonName),
|
||||
},
|
||||
whisper = {
|
||||
order = 11,
|
||||
order = 12,
|
||||
type = "toggle",
|
||||
name = self.L.Options_Channels_ChannelWhisper_Name,
|
||||
desc = self:Format(self.L.Options_Channels_ChannelWhisper_Desc, self.L.AddonName),
|
||||
@@ -167,51 +175,20 @@ function Grichelde:CreateOptionsUI()
|
||||
}
|
||||
end
|
||||
|
||||
local Grichelde_DefaultConfig = {
|
||||
global = {},
|
||||
profile = {
|
||||
enabled = true,
|
||||
channels = {
|
||||
["*"] = false,
|
||||
say = true,
|
||||
emote = false,
|
||||
yell = true,
|
||||
party = true,
|
||||
partyLeader = true,
|
||||
guild = true,
|
||||
officer = true,
|
||||
},
|
||||
replacements = {
|
||||
["**"] = {
|
||||
searchText = "",
|
||||
replaceText = "",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_0 = {
|
||||
order = 1,
|
||||
searchText = "s",
|
||||
replaceText = "ch",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_1 = {
|
||||
order = 2,
|
||||
searchText = "t",
|
||||
replaceText = "ck",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Grichelde:LoadDatabase()
|
||||
-- Called when the addon is loaded
|
||||
self.db = LibStub("AceDB-3.0"):New(AddonName .."DB", Grichelde_DefaultConfig, true)
|
||||
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
|
||||
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
|
||||
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
|
||||
self.db = LibStub("AceDB-3.0"):New(self.name .."DB", self.defaultConfig, true)
|
||||
|
||||
-- todo: is this really needed?
|
||||
self.db.RegisterCallback(self, "OnProfileChanged", function (event)
|
||||
self:PrefixedPrint(self.L.Profiles_Loaded, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
|
||||
end)
|
||||
self.db.RegisterCallback(self, "OnProfileCopied", function(event)
|
||||
self:PrefixedPrint(self.L.Profiles_Copied, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
|
||||
end)
|
||||
self.db.RegisterCallback(self, "OnProfileReset", function(event)
|
||||
self:PrefixedPrint(self.L.Profiles_Reset, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
|
||||
end)
|
||||
end
|
||||
|
||||
function Grichelde:SetupOptions()
|
||||
@@ -221,27 +198,12 @@ function Grichelde:SetupOptions()
|
||||
self.options.args.profiles.disabled = false
|
||||
|
||||
local activeProfile = self.db:GetCurrentProfile()
|
||||
self:PrefixedPrint(self.L.Profiles_Loaded, _G.GREEN_FONT_COLOR_CODE, activeProfile, "|r")
|
||||
self:PrefixedPrint(self.L.Profiles_Loaded, self.COLOR_CODES.GREEN .. activeProfile .. self.COLOR_CODES.CLOSE)
|
||||
self:tPrint(self.db.profile)
|
||||
|
||||
-- Adding options to blizzard frame
|
||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(AddonName, self.options)
|
||||
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)
|
||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(self.name, self.options)
|
||||
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.name, self.L.AddonName)
|
||||
end
|
||||
|
||||
function Grichelde:SyncToDatabase(info, val)
|
||||
@@ -251,8 +213,8 @@ function Grichelde:SyncToDatabase(info, val)
|
||||
option = option[info[path]] -- or nil
|
||||
path = path + 1
|
||||
end
|
||||
local optionPath = strjoin(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("change option \"%s\" from %s to %s", optionPath, tostring(option[info[path]]), tostring(val))
|
||||
local optionPath = join(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("change option \"%s\" from %s to %s", optionPath, toString(option[info[path]]), toString(val))
|
||||
option[info[path]] = val
|
||||
end
|
||||
|
||||
@@ -263,8 +225,8 @@ function Grichelde:ReadFromDatabase(info)
|
||||
option = option[info[path]] -- or nil
|
||||
path = path + 1
|
||||
end
|
||||
local optionPath = strjoin(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("read option \"%s\": %s", optionPath, tostring(option))
|
||||
local optionPath = join(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("read option \"%s\": %s", optionPath, toString(option))
|
||||
return option
|
||||
end
|
||||
|
||||
@@ -273,8 +235,4 @@ function Grichelde:IsDisabled(info)
|
||||
return false
|
||||
end
|
||||
return not self.db.profile.enabled
|
||||
end
|
||||
|
||||
function Grichelde:RefreshConfig(event)
|
||||
self:Print(self.L.Profiles_Refreshed, _G.GREEN_FONT_COLOR_CODE, self.db:GetCurrentProfile(), "|r")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user