You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Grichelde/GricheldeOptions.lua

333 lines
12 KiB
Lua

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
]]--