@ -1,191 +1,204 @@
local AddonName , AddonTable = ...
local AddonName , _ = ...
local Grichelde = LibStub ( " AceAddon-3.0 " ) : GetAddon ( AddonName )
Grichelde.options = {
function Grichelde : CreateOptionsUI ( )
name = Grichelde.L . AddonName ,
return {
type = " group " ,
name = self : Format ( self.L . Options_Title , self.L . AddonName ) ,
cmdHidden = true ,
type = " group " ,
childGroups = " tab " ,
childGroups = " tab " ,
args = {
set = function ( info , val ) self : SyncToDatabase ( info , val ) end ,
enabled = {
get = function ( info ) return self : ReadFromDatabase ( info ) end ,
order = 0 ,
hidden = false ,
type = " toggle " ,
disabled = function ( info ) return self : IsDisabled ( info ) end ,
name = Grichelde.L . Options_Enabled_Name ,
args = {
desc = Grichelde.L . Options_Enabled_Desc ,
enabled = {
set = function ( info , val ) Grichelde.enabled = val end ,
order = 0 ,
get = function ( info ) return Grichelde.enabled end ,
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 = {
channels = {
order = 2 ,
order = 2 ,
type = " group " ,
type = " group " ,
name = Grichelde.L . Options_Channels_Group_Name ,
name = self.L . Options_Channels_Group_Name ,
desc = Grichelde.L . Options_Channels_Group_Desc ,
desc = self : Format ( self.L . Options_Channels_Group_Desc , self.L . AddonName ) ,
args = {
args = {
say = {
say = {
order = 0 ,
order = 0 ,
type = " toggle " ,
type = " toggle " ,
name = Grichelde.L . Options_Channels_ChannelSay_Name ,
name = self.L . Options_Channels_ChannelSay_Name ,
desc = Grichelde.L . Options_Channels_ChannelSay_Desc ,
desc = self : Format ( self.L . Options_Channels_ChannelSay_Desc , self.L . AddonName ) ,
set = function ( info , val ) Grichelde.enabled = val end ,
} ,
get = function ( info ) return Grichelde.enabled end
emote = {
} ,
order = 1 ,
emote = {
type = " toggle " ,
order = 1 ,
name = self.L . Options_Channels_ChannelEmote_Name ,
type = " toggle " ,
desc = self : Format ( self.L . Options_Channels_ChannelEmote_Desc , self.L . AddonName ) ,
name = Grichelde.L . Options_Channels_ChannelEmote_Name ,
} ,
desc = Grichelde.L . Options_Channels_ChannelEmote_Desc ,
yell = {
set = function ( info , val ) Grichelde.enabled = val end ,
order = 2 ,
get = function ( info ) return Grichelde.enabled end
type = " toggle " ,
} ,
name = self.L . Options_Channels_ChannelYell_Name ,
yell = {
desc = self : Format ( self.L . Options_Channels_ChannelYell_Desc , self.L . AddonName ) ,
order = 2 ,
} ,
type = " toggle " ,
party = {
name = Grichelde.L . Options_Channels_ChannelYell_Name ,
order = 3 ,
desc = Grichelde.L . Options_Channels_ChannelYell_Desc ,
type = " toggle " ,
set = function ( info , val ) Grichelde.enabled = val end ,
name = self.L . Options_Channels_ChannelParty_Name ,
get = function ( info ) return Grichelde.enabled end
desc = self : Format ( self.L . Options_Channels_ChannelParty_Desc , self.L . AddonName ) ,
} ,
} ,
party = {
partyLeader = {
order = 3 ,
order = 4 ,
type = " toggle " ,
type = " toggle " ,
name = Grichelde.L . Options_Channels_ChannelParty_Name ,
name = self.L . Options_Channels_ChannelPartyLeader_Name ,
desc = Grichelde.L . Options_Channels_ChannelParty_Desc ,
desc = self : Format ( self.L . Options_Channels_ChannelPartyLeader_Desc , self.L . AddonName ) ,
set = function ( info , val ) Grichelde.enabled = val end ,
} ,
get = function ( info ) return Grichelde.enabled end
guild = {
} ,
order = 5 ,
partyLeader = {
type = " toggle " ,
order = 4 ,
name = self.L . Options_Channels_ChannelGuild_Name ,
type = " toggle " ,
desc = self : Format ( self.L . Options_Channels_ChannelGuild_Desc , self.L . AddonName ) ,
name = Grichelde.L . Options_Channels_ChannelPartyLeader_Name ,
} ,
desc = Grichelde.L . Options_Channels_ChannelPartyLeader_Desc ,
officer = {
set = function ( info , val ) Grichelde.enabled = val end ,
order = 6 ,
get = function ( info ) return Grichelde.enabled end
type = " toggle " ,
} ,
name = self.L . Options_Channels_ChannelOfficer_Name ,
guild = {
desc = self : Format ( self.L . Options_Channels_ChannelOfficer_Desc , self.L . AddonName ) ,
order = 5 ,
} ,
type = " toggle " ,
raid = {
name = Grichelde.L . Options_Channels_ChannelGuild_Name ,
order = 7 ,
desc = Grichelde.L . Options_Channels_ChannelGuild_Desc ,
type = " toggle " ,
set = function ( info , val ) Grichelde.enabled = val end ,
name = self.L . Options_Channels_ChannelRaid_Name ,
get = function ( info ) return Grichelde.enabled end
desc = self : Format ( self.L . Options_Channels_ChannelRaid_Desc , self.L . AddonName ) ,
} ,
} ,
officer = {
raidLeader = {
order = 6 ,
order = 8 ,
type = " toggle " ,
type = " toggle " ,
name = Grichelde.L . Options_Channels_ChannelOfficer_Name ,
name = self.L . Options_Channels_ChannelRaidLeader_Name ,
desc = Grichelde.L . Options_Channels_ChannelOfficer_Desc ,
desc = self : Format ( self.L . Options_Channels_ChannelRaidLeader_Desc , self.L . AddonName ) ,
set = function ( info , val ) Grichelde.enabled = val end ,
} ,
get = function ( info ) return Grichelde.enabled end
instance = {
} ,
order = 9 ,
raid = {
type = " toggle " ,
order = 7 ,
name = self.L . Options_Channels_ChannelInstance_Name ,
type = " toggle " ,
desc = self : Format ( self.L . Options_Channels_ChannelInstance_Desc , self.L . AddonName ) ,
name = Grichelde.L . Options_Channels_ChannelRaid_Name ,
} ,
desc = Grichelde.L . Options_Channels_ChannelRaid_Desc ,
battleground = {
set = function ( info , val ) Grichelde.enabled = val end ,
order = 10 ,
get = function ( info ) return Grichelde.enabled end
type = " toggle " ,
} ,
name = self.L . Options_Channels_ChannelBattleground_Name ,
raidLeader = {
desc = self : Format ( self.L . Options_Channels_ChannelBattleground_Desc , self.L . AddonName ) ,
order = 8 ,
} ,
type = " toggle " ,
whisper = {
name = Grichelde.L . Options_Channels_ChannelRaidLeader_Name ,
order = 11 ,
desc = Grichelde.L . Options_Channels_ChannelRaidLeader_Desc ,
type = " toggle " ,
set = function ( info , val ) Grichelde.enabled = val end ,
name = self.L . Options_Channels_ChannelWhisper_Name ,
get = function ( info ) return Grichelde.enabled end
desc = self : Format ( self.L . Options_Channels_ChannelWhisper_Desc , self.L . AddonName ) ,
} ,
} ,
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 = {
replacements = {
order = 3 ,
order = 3 ,
type = " group " ,
type = " group " ,
name = Grichelde.L . Options_Replacements_Group_Name ,
name = self.L . Options_Replacements_Group_Name ,
desc = Grichelde.L . Options_Replacements_Group_Desc ,
desc = self.L . Options_Replacements_Group_Desc ,
childGroups = " tree " ,
args = {
args = {
add = {
searchText = {
order = 0 ,
order = 0 ,
type = " execute " ,
type = " input " ,
name = self.L . Options_Replacements_Add_Name ,
name = Grichelde.L . Options_Replacements_SearchText_Name ,
desc = self.L . Options_Replacements_Add_Desc ,
desc = Grichelde.L . Options_Replacements_SearchText_Desc ,
} ,
set = function ( info , val ) Grichelde.enabled = val end ,
deleteAll = {
get = function ( info ) return Grichelde.enabled end
order = 0 ,
} ,
type = " execute " ,
replacetext = {
confirm = " " ,
order = 1 ,
name = self.L . Options_Replacements_DeleteAll_Name ,
type = " input " ,
desc = self.L . Options_Replacements_DeleteAll_Desc ,
name = Grichelde.L . Options_Replacements_ReplaceText_Name ,
} ,
desc = Grichelde.L . Options_Replacements_ReplaceText_Desc ,
replacement_0 = {
set = function ( info , val ) Grichelde.enabled = val end ,
order = 0 ,
get = function ( info ) return Grichelde.enabled end
type = " group " ,
} ,
name = self.L . Options_Replacement_Group_Name ,
caseSensitive = {
desc = self.L . Options_Replacement_Group_Desc ,
order = 2 ,
childGroups = " tree " ,
type = " toggle " ,
args = {
name = Grichelde.L . Options_Replacements_CaseSensitive_Name ,
searchText = {
desc = Grichelde.L . Options_Replacements_CaseSensitive_Desc ,
order = 0 ,
set = function ( info , val ) Grichelde.enabled = val end ,
type = " input " ,
get = function ( info ) return Grichelde.enabled end } ,
name = self.L . Options_Replacement_SearchText_Name ,
consolidate = {
desc = self.L . Options_Replacement_SearchText_Desc ,
order = 3 ,
} ,
type = " toggle " ,
replaceText = {
name = Grichelde.L . Options_Replacements_Consolidate_Name ,
order = 1 ,
desc = Grichelde.L . Options_Replacements_Consolidate_Desc ,
type = " input " ,
set = function ( info , val ) Grichelde.enabled = val end ,
name = self.L . Options_Replacement_ReplaceText_Name ,
get = function ( info ) return Grichelde.enabled end
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_DB_Defaults = {
local Grichelde_DefaultConfig = {
global = { } ,
profile = {
profile = {
enabled = true ,
enabled = true ,
channels = {
channels = {
" SAY " , " EMOTE " , " YELL " , " PARTY " , " GUILD "
[ " * " ] = false ,
say = true ,
emote = false ,
yell = true ,
party = true ,
partyLeader = true ,
guild = true ,
officer = true ,
} ,
} ,
replacements = {
replacements = {
[ " ** " ] = {
[ " ** " ] = {
left = " " ,
searchTex t = " " ,
right = " " ,
r eplaceTex t = " " ,
caseSensitive = false ,
caseSensitive = false ,
consolidate = true ,
consolidate = true ,
} ,
} ,
replacement = {
replacement_0 = {
left = " s " ,
order = 1 ,
right = " ch " ,
searchText = " s " ,
replaceText = " ch " ,
caseSensitive = false ,
caseSensitive = false ,
consolidate = true ,
consolidate = true ,
} ,
} ,
replacement = {
replacement_1 = {
left = " t " ,
order = 2 ,
right = " ck " ,
searchText = " t " ,
replaceText = " ck " ,
caseSensitive = false ,
caseSensitive = false ,
consolidate = true ,
consolidate = true ,
}
}
@ -195,23 +208,25 @@ local Grichelde_DB_Defaults = {
function Grichelde : LoadDatabase ( )
function Grichelde : LoadDatabase ( )
-- Called when the addon is loaded
-- Called when the addon is loaded
self.DB = LibStub ( " AceDB-3.0 " ) : New ( AddonName .. " DB " , Grichelde_DB_Defaults , true )
self.db = LibStub ( " AceDB-3.0 " ) : New ( AddonName .. " DB " , Grichelde_DefaultConfig , true )
self.DB . RegisterCallback ( self , " OnProfileChanged " , " RefreshConfig " )
self.db . RegisterCallback ( self , " OnProfileChanged " , " RefreshConfig " )
self.DB . RegisterCallback ( self , " OnProfileCopied " , " RefreshConfig " )
self.db . RegisterCallback ( self , " OnProfileCopied " , " RefreshConfig " )
self.DB . RegisterCallback ( self , " OnProfileReset " , " RefreshConfig " )
self.db . RegisterCallback ( self , " OnProfileReset " , " RefreshConfig " )
local activeProfile = self.DB : GetCurrentProfile ( )
self : Print ( " current profile " .. activeProfile )
end
end
function Grichelde : SetupOptions ( )
function Grichelde : SetupOptions ( )
-- add DB-backed profiles to UI options
-- add DB-backed profiles to UI options
self.options . args.profile = LibStub ( " AceDBOptions-3.0 " ) : GetOptionsTable ( self.DB )
self.options = self : CreateOptionsUI ( )
-- self.options.args.profile.order = 1
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
-- Adding options to blizzard frame
self.Config = LibStub ( " AceConfig-3.0 " ) : RegisterOptionsTable ( AddonName , self.options )
LibStub( " AceConfig-3.0 " ) : RegisterOptionsTable ( AddonName , self.options )
self.Dialog = LibStub ( " AceConfigDialog-3.0 " ) : AddToBlizOptions ( AddonName , self.L . AddonName )
LibStub( " AceConfigDialog-3.0 " ) : AddToBlizOptions ( AddonName , self.L . AddonName )
end
end
function Grichelde : SetupSlashCommands ( )
function Grichelde : SetupSlashCommands ( )
@ -229,104 +244,37 @@ function Grichelde:SetupSlashCommands()
self : RegisterChatCommand ( " gri " , HandleSlashCommand )
self : RegisterChatCommand ( " gri " , HandleSlashCommand )
end
end
function Grichelde : RefreshConfig ( name )
function Grichelde : SyncToDatabase ( info , val )
self : Print ( " Refreshed: " .. name )
local option = self.db . profile
end
local path = 1
while ( path < # info ) do
--[[
option = option [ info [ path ] ] -- or nil
-- profile actions
path = path + 1
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
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
end
function Grichelde : SetProfile ( name )
function Grichelde : ReadFromDatabase( info )
local profile = self : MatchProfile ( name )
local option = self.db . profile
if profile and profile ~= self.db : GetCurrentProfile ( ) then
local path = 1
self.db : SetProfile ( profile )
while ( path <= # info ) do
else
option = option [ info [ path ] ] -- or nil
self: Printf ( L.Options_Profile_Invalid , name or " null " )
path = path + 1
end
end
local optionPath = strjoin ( " . " , unpack ( info , 1 , # info ) )
self : DebugPrint ( " read option \" %s \" : %s " , optionPath , tostring ( option ) )
return option
end
end
function Grichelde : DeleteProfile ( name )
function Grichelde : IsDisabled ( info )
local profile = self : MatchProfile ( name )
if info.option . type == " group " then
if profile and profile ~= self.db : GetCurrentProfile ( ) then
return false
self.db : DeleteProfile ( profile )
else
self : Print ( L.Options_Profile_DeleteError )
end
end
return not self.db . profile.enabled
end
end
function Grichelde : CopyProfile ( name )
function Grichelde : RefreshConfig ( event )
if name and name ~= self.db : GetCurrentProfile ( ) then
self : Print ( self.L . Profiles_Refreshed , _G.GREEN_FONT_COLOR_CODE , self.db : GetCurrentProfile ( ) , " |r " )
self.db : CopyProfile ( name )
end
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
] ] --