|
|
|
local AddonName, _ = ...
|
|
|
|
|
|
|
|
function Grichelde:CreateOptionsUI()
|
|
|
|
return {
|
|
|
|
name = self:Format(self.L.Options_Title, self.L.AddonName),
|
|
|
|
type = "group",
|
|
|
|
childGroups = "tab",
|
|
|
|
set = function(info, val) self:SyncToDatabase(info, val) end,
|
|
|
|
get = function(info) return self:ReadFromDatabase(info) end,
|
|
|
|
hidden = false,
|
|
|
|
disabled = function(info) return self:IsDisabled(info) end,
|
|
|
|
args = {
|
|
|
|
enabled = {
|
|
|
|
order = 0,
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
|
|
|
|
channels = {
|
|
|
|
order = 2,
|
|
|
|
type = "group",
|
|
|
|
name = self.L.Options_Channels_Group_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_Group_Desc, self.L.AddonName),
|
|
|
|
args = {
|
|
|
|
say = {
|
|
|
|
order = 0,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelSay_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelSay_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
emote = {
|
|
|
|
order = 1,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelEmote_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelEmote_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
yell = {
|
|
|
|
order = 2,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelYell_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelYell_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
party = {
|
|
|
|
order = 3,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelParty_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelParty_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
partyLeader = {
|
|
|
|
order = 4,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelPartyLeader_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelPartyLeader_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
guild = {
|
|
|
|
order = 5,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelGuild_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelGuild_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
officer = {
|
|
|
|
order = 6,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelOfficer_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelOfficer_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
raid = {
|
|
|
|
order = 7,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelRaid_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelRaid_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
raidLeader = {
|
|
|
|
order = 8,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelRaidLeader_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelRaidLeader_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
instance = {
|
|
|
|
order = 9,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelInstance_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelInstance_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
battleground = {
|
|
|
|
order = 10,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelBattleground_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelBattleground_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
whisper = {
|
|
|
|
order = 11,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Channels_ChannelWhisper_Name,
|
|
|
|
desc = self:Format(self.L.Options_Channels_ChannelWhisper_Desc, self.L.AddonName),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
replacements = {
|
|
|
|
order = 3,
|
|
|
|
type = "group",
|
|
|
|
name = self.L.Options_Replacements_Group_Name,
|
|
|
|
desc = self.L.Options_Replacements_Group_Desc,
|
|
|
|
args = {
|
|
|
|
add = {
|
|
|
|
order = 0,
|
|
|
|
type = "execute",
|
|
|
|
name = self.L.Options_Replacements_Add_Name,
|
|
|
|
desc = self.L.Options_Replacements_Add_Desc,
|
|
|
|
},
|
|
|
|
deleteAll = {
|
|
|
|
order = 0,
|
|
|
|
type = "execute",
|
|
|
|
confirm = "",
|
|
|
|
name = self.L.Options_Replacements_DeleteAll_Name,
|
|
|
|
desc = self.L.Options_Replacements_DeleteAll_Desc,
|
|
|
|
},
|
|
|
|
replacement_0 = {
|
|
|
|
order = 0,
|
|
|
|
type = "group",
|
|
|
|
name = self.L.Options_Replacement_Group_Name,
|
|
|
|
desc = self.L.Options_Replacement_Group_Desc,
|
|
|
|
childGroups = "tree",
|
|
|
|
args = {
|
|
|
|
searchText = {
|
|
|
|
order = 0,
|
|
|
|
type = "input",
|
|
|
|
name = self.L.Options_Replacement_SearchText_Name,
|
|
|
|
desc = self.L.Options_Replacement_SearchText_Desc,
|
|
|
|
},
|
|
|
|
replaceText = {
|
|
|
|
order = 1,
|
|
|
|
type = "input",
|
|
|
|
name = self.L.Options_Replacement_ReplaceText_Name,
|
|
|
|
desc = self.L.Options_Replacement_ReplaceText_Desc,
|
|
|
|
},
|
|
|
|
caseSensitive = {
|
|
|
|
order = 2,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Replacement_CaseSensitive_Name,
|
|
|
|
desc = self.L.Options_Replacement_CaseSensitive_Desc,
|
|
|
|
},
|
|
|
|
consolidate = {
|
|
|
|
order = 3,
|
|
|
|
type = "toggle",
|
|
|
|
name = self.L.Options_Replacement_Consolidate_Name,
|
|
|
|
desc = self.L.Options_Replacement_Consolidate_Desc,
|
|
|
|
width = 2
|
|
|
|
},
|
|
|
|
deleteAll = {
|
|
|
|
order = 4,
|
|
|
|
type = "execute",
|
|
|
|
confirm = "",
|
|
|
|
name = self.L.Options_Replacement_Delete_Name,
|
|
|
|
desc = self.L.Options_Replacement_Delete_Desc,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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")
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grichelde:SetupOptions()
|
|
|
|
-- add DB-backed profiles to UI options
|
|
|
|
self.options = self:CreateOptionsUI()
|
|
|
|
self.options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
|
|
|
|
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: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)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grichelde:SyncToDatabase(info, val)
|
|
|
|
local option = self.db.profile
|
|
|
|
local path = 1
|
|
|
|
while ( path < #info) do
|
|
|
|
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))
|
|
|
|
option[info[path]] = val
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grichelde:ReadFromDatabase(info)
|
|
|
|
local option = self.db.profile
|
|
|
|
local path = 1
|
|
|
|
while (path <= #info) do
|
|
|
|
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))
|
|
|
|
return option
|
|
|
|
end
|
|
|
|
|
|
|
|
function Grichelde:IsDisabled(info)
|
|
|
|
if info.option.type == "group" then
|
|
|
|
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
|