Version 0.8.0-beta

- handle replacement via slash command
- emote and ooc detection
- de-/activate single mappings
- move buttons and mappings are disabled when already at top/bottom or deactivated
- minimap button is darkened when addon is disabled
- help tab with examples

- right-click on minimap button quickly de-/activates replacements

- fixed mapping to raid warning, instance and battleground chats
- localized raid target markers
- capital % substitutions
- incorrect consolidation
- Umlaut and accent replacements
This commit is contained in:
2020-06-09 02:28:31 +02:00
parent 5b72ad3b78
commit 44dd7ac8eb
26 changed files with 1389 additions and 406 deletions

View File

@@ -2,8 +2,10 @@
local _G = _G
local Grichelde = _G.Grichelde
local nilOrEmpty, pairs, find, match, toString, toNumber
= Grichelde.functions.nilOrEmpty, Grichelde.functions.pairs, Grichelde.functions.find, Grichelde.functions.match, Grichelde.functions.toString, Grichelde.functions.toNumber
local nilOrEmpty, pairs, tContains, tWipe, find, match, color, toString, toNumber
= Grichelde.functions.nilOrEmpty, Grichelde.functions.pairs, Grichelde.functions.tContains, Grichelde.functions.tWipe, Grichelde.functions.find, Grichelde.functions.match, Grichelde.functions.color, Grichelde.functions.toString, Grichelde.functions.toNumber
local selectedExample = 1
function Grichelde:CreateOptionsUI()
return {
@@ -20,6 +22,7 @@ function Grichelde:CreateOptionsUI()
type = "toggle",
name = self.L.Options_Enabled_Name,
desc = self:Format(self.L.Options_Enabled_Desc, self.L.AddonName),
set = function() self:ToggleActivation() end,
disabled = false,
},
minimapButton = {
@@ -27,25 +30,62 @@ function Grichelde:CreateOptionsUI()
type = "toggle",
name = self.L.Options_Minimap_Button_Name,
desc = self.L.Options_Minimap_Button_Desc,
set = function(info, val) self:ToogleMinimapButton(info, val) end,
get = function(info) return not self.db.profile.minimapButton.hide end,
set = function(_, _) self:ToggleMinimapButton() end,
get = function(_) return not self.db.profile.minimapButton.hide end,
disabled = false,
},
channels = {
replacements = {
order = 2,
type = "group",
name = self.L.Options_Replacements_Group_Name,
desc = self.L.Options_Replacements_Group_Desc,
args = {
add = {
order = 0,
type = "execute",
confirm = false,
name = self.L.Options_Replacements_Add_Name,
desc = self.L.Options_Replacements_Add_Desc,
func = function(info) self:AddEmptyMapping(info) end,
},
deleteAll = {
order = 1,
type = "execute",
confirm = true,
confirmText = self.L.Options_Replacements_DeleteAll_ConfirmText,
name = self.L.Options_Replacements_DeleteAll_Name,
desc = self.L.Options_Replacements_DeleteAll_Desc,
func = function(info) self:DeleteAllMappings(info) end,
},
header = {
order = 3,
type = "description",
name = self.L.Options_Replacements_Header,
},
spacer1 = {
order = 4,
type = "header",
name = "",
},
},
},
channels = {
order = 3,
type = "group",
name = self.L.Options_Channels_Group_Name,
desc = self:Format(self.L.Options_Channels_Group_Desc, self.L.AddonName),
args = {
header = {
order = 1,
type = "description",
name = self.L.Options_Channels_Header
name = self.L.Options_Channels_Header,
},
spacer = {
spacer2 = {
order = 2,
type = "header",
name = ""
name = "",
},
say = {
order = 10,
@@ -113,45 +153,106 @@ function Grichelde:CreateOptionsUI()
name = self.L.Options_Channel_Whisper_Name,
desc = self:Format(self.L.Options_Channel_Whisper_Desc, self.L.AddonName),
},
}
},
},
replacements = {
order = 3,
help = {
order = -1,
type = "group",
name = self.L.Options_Replacements_Group_Name,
desc = self.L.Options_Replacements_Group_Desc,
childGroups = "tab",
name = self.L.Options_Help_Group_Name,
desc = self.L.Options_Help_Group_Desc,
disabled = false,
args = {
add = {
order = 0,
type = "execute",
confirm = false,
name = self.L.Options_Replacements_Add_Name,
desc = self.L.Options_Replacements_Add_Desc,
func = function(info) self:AddEmptyMapping(info) end
basics = {
order = 10,
type = "group",
name = self.L.Options_Help_Tab_Basics_Name,
desc = self.L.Options_Help_Tab_Basics_Desc,
args = {
paragraph1 = {
order = 1,
type = "description",
name = self.L.Options_Help_Basics,
fontSize = "medium",
},
},
},
deleteAll = {
order = 1,
type = "execute",
confirm = true,
confirmText = self.L.Options_Replacements_DeleteAll_ConfirmText,
name = self.L.Options_Replacements_DeleteAll_Name,
desc = self.L.Options_Replacements_DeleteAll_Desc,
func = function(info) self:DeleteAllMappings(info) end
expert = {
order = 11,
type = "group",
name = self.L.Options_Help_Tab_Expert_Name,
desc = self.L.Options_Help_Tab_Expert_Desc,
args = {
paragraph4 = {
order = 1,
type = "description",
name = self.L.Options_Help_Expert,
fontSize = "medium",
},
},
},
header = {
order = 3,
examples = {
order = 12,
type = "group",
name = self.L.Options_Help_Tab_Examples_Name,
desc = self.L.Options_Help_Tab_Examples_Desc,
args = {
note = {
order = 1,
type = "description",
name = self.L.Options_Help_Examples_Note,
},
header = {
order = 2,
type = "description",
name = self.L.Options_Help_Examples0_Header,
fontSize = "medium",
width = 2.5,
},
dropDown = {
order = 3,
type = "select",
name = "",
--width = 1,
values = {
self.L.Options_Help_Examples1_Select,
self.L.Options_Help_Examples2_Select,
self.L.Options_Help_Examples3_Select,
self.L.Options_Help_Examples4_Select,
self.L.Options_Help_Examples5_Select,
self.L.Options_Help_Examples6_Select,
-- self.L.Options_Help_Examples7_Select,
},
set = function(info, val) selectedExample = val end,
get = function(_)
self.options.args.help.args.examples.args.header.name = self.L["Options_Help_Examples" .. selectedExample .. "_Header"]
self.options.args.help.args.examples.args.example.name = self.L["Options_Help_Examples" .. selectedExample .. "_Text"]
self.dialog:SelectGroup(self.name, "help", "examples", "header.name")
return selectedExample
end,
},
spacer3 = {
order = 4,
type = "header",
name = "",
},
example = {
order = 5,
type = "description",
name = self.L.Options_Help_Examples0_Text,
fontSize = "medium",
},
},
},
disclaimer = {
order = 20,
type = "description",
name = self.L.Options_Replacements_Header
name = self.L.Options_Help_Disclaimer,
},
spacer = {
order = 4,
type = "header",
name = ""
},
}
}
}
},
},
},
}
end
@@ -162,69 +263,89 @@ function Grichelde:CreateMapping(offset)
name = function(info) return self:MappingName(info) end,
desc = self.L.Options_Mapping_Group_Desc,
childGroups = "tree",
disabled = function(info) return not self:IsMappingActive(info) end,
args = {
searchText = {
moveUp = {
order = 0,
type = "execute",
name = "",
desc = self.L.Options_Mapping_MoveUp_Desc,
image = function(info) return self:GetMoveUpImage(info) end,
width = 0.15,
func = function(info) self:MoveUp(info) end,
},
moveDown = {
order = 1,
type = "execute",
name = "",
desc = self.L.Options_Mapping_MoveDown_Desc,
image = function(info) return self:GetMoveDownImage(info) end,
width = 0.15,
func = function(info) self:MoveDown(info) end,
},
--[[
spacer4 = {
order = 2,
type = "description",
name = "",
width = 0.1,
},
]]
active = {
order = 3,
type = "toggle",
name = self.L.Options_Mapping_Enabled_Name,
desc = self.L.Options_Mapping_Enabled_Desc,
width = 2.2,
},
delete = {
order = 4,
type = "execute",
confirm = true,
confirmText = self.L.Options_Mapping_Delete_ConfirmText,
name = "",
desc = self.L.Options_Mapping_Delete_Desc,
image = function(info) return self:GetDeleteImage(info) end,
width = 0.1,
func = function(info) self:DeleteMapping(info) end,
},
searchText = {
order = 10,
type = "input",
name = self.L.Options_Mapping_SearchText_Name,
desc = self.L.Options_Mapping_SearchText_Desc,
},
replaceText = {
order = 1,
order = 11,
type = "input",
name = self.L.Options_Mapping_ReplaceText_Name,
desc = self.L.Options_Mapping_ReplaceText_Desc,
},
exactCase = {
order = 2,
order = 20,
type = "toggle",
name = self.L.Options_Mapping_ExactCase_Name,
desc = self.L.Options_Mapping_ExactCase_Desc,
width = "full",
},
consolidate = {
order = 3,
order = 21,
type = "toggle",
name = self.L.Options_Mapping_Consolidate_Name,
desc = self.L.Options_Mapping_Consolidate_Desc,
width = "full"
},
moveUp = {
order = 10,
type = "execute",
-- name = self.L.Options_Mapping_MoveUp_Name,
name = "",
desc = self.L.Options_Mapping_MoveUp_Desc,
image = Grichelde.ICONS.MOVE_UP,
width = 0.15,
func = function(info) self:MoveUp(info) end
},
moveDown = {
order = 11,
type = "execute",
-- name = self.L.Options_Mapping_MoveDown_Name,
name = "",
desc = self.L.Options_Mapping_MoveDown_Desc,
image = Grichelde.ICONS.MOVE_DOWN,
width = 0.15,
func = function(info) self:MoveDown(info) end
},
spacer = {
order = 18,
type = "description",
name = "",
width = 1.2,
},
delete = {
order = 19,
type = "execute",
confirm = true,
confirmText = self.L.Options_Mapping_Delete_ConfirmText,
name = self.L.Options_Mapping_Delete_Name,
desc = self.L.Options_Mapping_Delete_Desc,
width = 0.5,
func = function(info) self:DeleteMapping(info) end
width = "full",
},
--[[
stopOnMatch = {
order = 22,
type = "toggle",
name = self.L.Options_Mapping_StopOnMatch_Name,
desc = self.L.Options_Mapping_StopOnMatch_Desc,
width = "full",
}
]]
}
}
end
@@ -233,6 +354,7 @@ function Grichelde:SetupOptions()
-- add DB-backed profiles to UI options
local options = self:CreateOptionsUI()
options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
options.args.profiles.order = 8
options.args.profiles.disabled = false
-- Adding options to blizzard frame
@@ -245,16 +367,17 @@ end
function Grichelde:RefreshOptions(event)
self:DebugPrint("RefreshOptions : event:", event)
local currentProfile = color(Grichelde.COLOR_CODES.GREEN, self.db:GetCurrentProfile())
if event == "OnNewProfile" then
self:PrefixedPrint(self.L.Profiles_Created, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
self:PrefixedPrint(self.L.Profiles_Created, currentProfile)
elseif event == "OnProfileChanged" then
self:PrefixedPrint(self.L.Profiles_Loaded, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
self:PrefixedPrint(self.L.Profiles_Loaded, currentProfile)
elseif event == "OnProfileDeleted" then
self:PrefixedPrint(self.L.Profiles_Deleted, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
self:PrefixedPrint(self.L.Profiles_Deleted, currentProfile)
elseif event == "OnProfileCopied" then
self:PrefixedPrint(self.L.Profiles_Copied, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
self:PrefixedPrint(self.L.Profiles_Copied, currentProfile)
elseif event == "OnProfileReset" then
self:PrefixedPrint(self.L.Profiles_Reset, self.COLOR_CODES.GREEN .. self.db:GetCurrentProfile() .. self.COLOR_CODES.CLOSE)
self:PrefixedPrint(self.L.Profiles_Reset, currentProfile)
else
self:DebugPrint("Refreshing Profile %s on options change: %s", self.db:GetCurrentProfile(), event)
end
@@ -263,53 +386,9 @@ function Grichelde:RefreshOptions(event)
self:RefreshReplacements(self.db.profile.replacements)
end
--- add Minimap button
function Grichelde:MinimapButton()
local function toggleOptionsUI(_, button)
if button == 'LeftButton' then
self:ToggleOptions()
elseif button == 'RightButton' then
self:ToogleMappings()
end
end
local function tooltip(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:SetText(self.L.AddonName,
Grichelde.COLORS.HIGHLIGHT.r, Grichelde.COLORS.HIGHLIGHT.g, Grichelde.COLORS.HIGHLIGHT.b, Grichelde.COLORS.HIGHLIGHT.a
)
tooltip:AddDoubleLine(self.L.Options_Minimap_Tooltip_Options_Left, self.L.Options_Minimap_Tooltip_Options_Right,
Grichelde.COLORS.GREEN.r, Grichelde.COLORS.GREEN.g, Grichelde.COLORS.GREEN.b, Grichelde.COLORS.GREEN.a,
Grichelde.COLORS.NORMAL.r, Grichelde.COLORS.NORMAL.g, Grichelde.COLORS.NORMAL.b, Grichelde.COLORS.NORMAL.a
)
tooltip:AddDoubleLine(self.L.Options_Minimap_Tooltip_Mappings_Left, self.L.Options_Minimap_Tooltip_Mappings_Right,
Grichelde.COLORS.GREEN.r, Grichelde.COLORS.GREEN.g, Grichelde.COLORS.GREEN.b, Grichelde.COLORS.GREEN.a,
Grichelde.COLORS.NORMAL.r, Grichelde.COLORS.NORMAL.g, Grichelde.COLORS.NORMAL.b, Grichelde.COLORS.NORMAL.a
)
end
local ldb = LibStub("LibDataBroker-1.1"):NewDataObject(self.name, {
type = "launcher",
text = self.AddonName,
icon = "Interface\\Icons\\Spell_Holy_Silence",
--icon = ([[Interface\Addons\%s\%s]]):format(self.name, self.name),
OnClick = toggleOptionsUI,
OnRightClick = function() self:ShowMappings() end,
OnTooltipShow = tooltip,
})
local icon = LibStub("LibDBIcon-1.0")
self:DebugPrint("MinimapButton : hidden: ", self.db.profile.minimapButton.hide)
icon:Register(self.name, ldb, self.db.profile.minimapButton)
return ldb, icon
end
function Grichelde:ToggleOptions()
self:DebugPrint("MinimapButton : options open: ", self.dialog.OpenFrames[self.name])
if self.dialog.OpenFrames[self.name] then
self:DebugPrint("ToggleOptions : options open: ", not not self.dialog.OpenFrames[self.name])
if self.dialog ~= nil and self.dialog.OpenFrames[self.name] ~= nil then
self:CloseOptions()
else
self:OpenOptions()
@@ -317,29 +396,78 @@ function Grichelde:ToggleOptions()
end
function Grichelde:OpenOptions()
self.dialog:Open(self.name)
if self.dialog ~= nil then
self.dialog:Open(self.name)
local formatString = self.L.AddonLoaded
if not self.db.profile.enabled then
formatString = self.L.AddonUnloaded
end
local namePlusVersion = self:Format(self.L.AddonNamePlusVersion, self.L.AddonName, self.version)
local statusText = self:Format(formatString, namePlusVersion)
self.dialog.OpenFrames[self.name]:SetStatusText(statusText)
end
end
function Grichelde:CloseOptions()
self.dialog:Close(self.name)
if self.dialog ~= nil then
self.dialog:Close(self.name)
end
end
--- If all replacements were disabled
-- @return (boolean)
function Grichelde:IsDisabled(info)
if info.option.type == "group" then
if info and info.option.type == "group" then
return false
end
return not self.db.profile.enabled
end
--- If all replacements were disabled
-- @return (boolean)
function Grichelde:IsMappingActive(info)
self:TracePrint("IsMappingActive : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
if info and info.option.type == "group" then
return true
end
if not self.db.profile.enabled then
return false
end
local replacements = self.db.profile.replacements or {}
local currentName = info[2]
local uiElem = info[3]
self:DebugPrint("IsMappingActive : \"%s\"", currentName)
self:DebugPrint(replacements[currentName])
if (tContains({"moveUp", "moveDown", "active", "delete"}, uiElem)) then
return true
else
return not not replacements[currentName].active
end
end
function Grichelde:MappingName(info)
-- self:TracePrint("MappingName : info")
-- self:TracePrint(info)
local option = self.db.profile.replacements[info[2]]
if nilOrEmpty(option.searchText) and nilOrEmpty(option.replaceText) then
return self.L.Options_Mapping_EmptyMapping
return color(Grichelde.COLOR_CODES.GRAY, self.L.Options_Mapping_EmptyMapping)
else
return self:Format(self.L.Options_Mapping_Group_Name, option.searchText or "", option.replaceText or "")
local name = self:Format(self.L.Options_Mapping_Group_Name, option.searchText or "", option.replaceText or "")
if option.active == true then
return name
else
return color(Grichelde.COLOR_CODES.GRAY, name)
end
end
end
@@ -473,6 +601,66 @@ function Grichelde:MoveDown(info)
end
end
function Grichelde:GetMoveUpImage(info)
self:TracePrint("GetMoveUpImage : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
local currentName = info[2]
self:DebugPrint("GetMoveUpImage : \"%s\"", currentName)
local _, replNumber = self:SplitOnFirstMatch(currentName, "_")
local currentOrder = toNumber(replNumber)
if (self:IsMappingActive(info) and currentOrder > Grichelde.MAPPING_OFFSET ) then
return Grichelde.ICONS.MOVE_UP
else
return Grichelde.ICONS.MOVE_UP_DISABLED
end
end
function Grichelde:GetMoveDownImage(info)
self:TracePrint("GetMoveDownImage : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
local currentName = info[2]
self:DebugPrint("GetMoveDownImage : \"%s\"", currentName)
local _, replNumber = self:SplitOnFirstMatch(currentName, "_")
local currentOrder = toNumber(replNumber)
local maxRepl = Grichelde.MAPPING_OFFSET
local replacements = self.db.profile.replacements or {}
for replName, _ in pairs(replacements) do
local num = match(replName, "^replacement_(%d+)")
if num and maxRepl < toNumber(num) then
maxRepl = toNumber(num)
end
end
if (self:IsMappingActive(info) and currentOrder < maxRepl) then
return Grichelde.ICONS.MOVE_DOWN
else
return Grichelde.ICONS.MOVE_DOWN_DISABLED
end
end
function Grichelde:GetDeleteImage(info)
self:TracePrint("GetDeleteImage : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
if (self:IsMappingActive(info)) then
return Grichelde.ICONS.DELETE
else
return Grichelde.ICONS.DELETE_DISABLED
end
end
function Grichelde:DeleteMapping(info)
self:TracePrint("DeleteMapping : info")
for i = 0, #info do
@@ -495,28 +683,8 @@ function Grichelde:DeleteAllMappings()
self:DebugPrint("DeleteAllMappings")
-- do NOT set self.db.profile.replacements = {} it will break defaults
for replName, _ in pairs(self.db.profile.replacements or {}) do
self.db.profile.replacements[replName] = nil
end
tWipe(self.db.profile.replacements)
self:AddEmptyMapping()
self:RefreshOptions("DeleteAllMappings")
end
function Grichelde:ToogleMinimapButton(info, val)
self:TracePrint("ToogleMinimapButton : info")
for i = 0, #info do
self:TracePrint("%d = %s", i, info[i])
end
self.db.profile.minimapButton.hide = not val
self:DebugPrint("ToogleMinimapButton : hidden: ", self.db.profile.minimapButton.hide)
if self.db.profile.minimapButton.hide then
self.icon:Hide(self.name);
else
self.icon:Show(self.name);
end
end