From f9dab14beb6c437e4babf91202a4ae5a8b2f3c21 Mon Sep 17 00:00:00 2001 From: Bunny67 Date: Thu, 16 Jul 2020 23:23:54 +0300 Subject: [PATCH] from retail --- WeakAuras/AuraEnvironment.lua | 8 +- WeakAuras/Transmission.lua | 2 +- WeakAuras/Types.lua | 24 +- .../AceGUIContainer-WeakAurasInlineGroup.lua | 75 + .../AceGUIWidget-WeakAurasDisplayButton.lua | 43 +- WeakAurasOptions/ActionOptions.lua | 45 +- WeakAurasOptions/AnimationOptions.lua | 61 +- WeakAurasOptions/AuthorOptions.lua | 107 +- WeakAurasOptions/BuffTrigger.lua | 134 +- WeakAurasOptions/BuffTrigger2.lua | 54 +- WeakAurasOptions/Cache.lua | 3 +- WeakAurasOptions/CommonOptions.lua | 1443 ++++++++ WeakAurasOptions/ConditionOptions.lua | 94 +- WeakAurasOptions/DisplayOptions.lua | 303 ++ WeakAurasOptions/ExternalAddons.lua | 6 +- WeakAurasOptions/GenericTrigger.lua | 226 +- WeakAurasOptions/GroupOptions.lua | 62 + WeakAurasOptions/LoadOptions.lua | 893 +++++ .../OptionsFrames/FrameChooser.lua | 4 +- WeakAurasOptions/OptionsFrames/IconPicker.lua | 5 +- .../OptionsFrames/ModelPicker.lua | 5 +- WeakAurasOptions/OptionsFrames/MoverSizer.lua | 8 +- .../OptionsFrames/OptionsFrame.lua | 268 +- WeakAurasOptions/OptionsFrames/TextEditor.lua | 12 +- .../OptionsFrames/TexturePicker.lua | 86 +- WeakAurasOptions/RegionOptions/AuraBar.lua | 9 +- .../RegionOptions/DynamicGroup.lua | 17 +- WeakAurasOptions/RegionOptions/Group.lua | 5 +- WeakAurasOptions/RegionOptions/Icon.lua | 5 +- WeakAurasOptions/RegionOptions/Model.lua | 4 +- .../RegionOptions/ProgressTexture.lua | 4 +- WeakAurasOptions/RegionOptions/Text.lua | 13 +- WeakAurasOptions/RegionOptions/Texture.lua | 2 +- .../SubRegionOptions/BarModel.lua | 8 +- WeakAurasOptions/SubRegionOptions/Border.lua | 8 +- WeakAurasOptions/SubRegionOptions/Glow.lua | 10 +- .../SubRegionOptions/SubRegionCommon.lua | 8 +- WeakAurasOptions/SubRegionOptions/SubText.lua | 64 +- WeakAurasOptions/TriggerOptions.lua | 282 ++ WeakAurasOptions/WeakAurasOptions.lua | 3292 +---------------- WeakAurasOptions/WeakAurasOptions.toc | 10 +- 41 files changed, 3843 insertions(+), 3869 deletions(-) create mode 100644 WeakAurasOptions/AceGUI-Widgets/AceGUIContainer-WeakAurasInlineGroup.lua create mode 100644 WeakAurasOptions/CommonOptions.lua create mode 100644 WeakAurasOptions/DisplayOptions.lua create mode 100644 WeakAurasOptions/GroupOptions.lua create mode 100644 WeakAurasOptions/LoadOptions.lua create mode 100644 WeakAurasOptions/TriggerOptions.lua diff --git a/WeakAuras/AuraEnvironment.lua b/WeakAuras/AuraEnvironment.lua index 8f29325..6540b0e 100644 --- a/WeakAuras/AuraEnvironment.lua +++ b/WeakAuras/AuraEnvironment.lua @@ -68,6 +68,9 @@ WeakAuras.WA_ClassColorName = WA_ClassColorName -- UTF-8 Sub is pretty commonly needed local WA_Utf8Sub = function(input, size) local output = "" + if not input then + return output + end local i = 1 while (size > 0) do local byte = input:byte(i) @@ -258,10 +261,7 @@ function WeakAuras.ActivateAuraEnvironment(id, cloneId, state, states, onlyConfi if(actions and actions.do_custom and actions.custom) then local func = WeakAuras.customActionsFunctions[id]["init"] if func then - local ok, ret = pcall(func) - if not ok then - geterrorhandler()(ret) - end + xpcall(func, geterrorhandler()) end end end diff --git a/WeakAuras/Transmission.lua b/WeakAuras/Transmission.lua index 9a27600..a0248ef 100644 --- a/WeakAuras/Transmission.lua +++ b/WeakAuras/Transmission.lua @@ -544,7 +544,7 @@ local function importPendingData() button.callbacks.UpdateExpandButton() WeakAuras.UpdateGroupOrders(parentData) WeakAuras.UpdateDisplayButton(parentData) - WeakAuras.ReloadGroupRegionOptions(parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) WeakAuras.SortDisplayButtons() end WeakAuras.SetImporting(false) diff --git a/WeakAuras/Types.lua b/WeakAuras/Types.lua index c25dc7f..2ebeb05 100644 --- a/WeakAuras/Types.lua +++ b/WeakAuras/Types.lua @@ -165,6 +165,12 @@ WeakAuras.format_types = { hidden = hidden }) end, + addOption(symbol .. "_big_number_space", { + type = "description", + name = "", + width = WeakAuras.normalWidth, + hidden = hidden + }) CreateFormatter = function(symbol, get) local format = get(symbol .. "_big_number_format", "AbbreviateNumbers") if (format == "AbbreviateNumbers") then @@ -255,7 +261,7 @@ WeakAuras.format_types = { local abbreviateFunc if color == "class" then colorFunc = function(unit, text) - if UnitPlayerControlled(unit) then + if unit and UnitPlayerControlled(unit) then return GetClassColoredTextForUnit(unit, text) end return text @@ -263,9 +269,14 @@ WeakAuras.format_types = { end if realm == "never" then - nameFunc = UnitName + nameFunc = function(unit) + return unit and UnitName(unit) + end elseif realm == "star" then nameFunc = function(unit) + if not unit then + return "" + end local name, realm = UnitName(unit) if realm then return name .. "*" @@ -274,6 +285,9 @@ WeakAuras.format_types = { end elseif realm == "differentServer" then nameFunc = function(unit) + if not unit then + return "" + end local name, realm = UnitName(unit) if realm then return name .. "-" .. realm @@ -282,6 +296,9 @@ WeakAuras.format_types = { end elseif realm == "always" then nameFunc = function(unit) + if not unit then + return "" + end local name, realm = WeakAuras.UnitNameWithRealm(unit) return name .. "-" .. realm end @@ -350,6 +367,7 @@ WeakAuras.format_types = { min = 1, max = 20, hidden = hidden, + step = 1, disabled = function() return not get(symbol .. "_abbreviate") end @@ -366,7 +384,7 @@ WeakAuras.format_types = { local abbreviateFunc if color == "class" then colorFunc = function(class, text) - local color = RAID_CLASS_COLORS[class] + local color = class and RAID_CLASS_COLORS[class] if color then return string.format("|c%s%s|r", string.format("ff%.2x%.2x%.2x", color.r * 255, color.g * 255, color.b * 255), text) else diff --git a/WeakAurasOptions/AceGUI-Widgets/AceGUIContainer-WeakAurasInlineGroup.lua b/WeakAurasOptions/AceGUI-Widgets/AceGUIContainer-WeakAurasInlineGroup.lua new file mode 100644 index 0000000..b2466b6 --- /dev/null +++ b/WeakAurasOptions/AceGUI-Widgets/AceGUIContainer-WeakAurasInlineGroup.lua @@ -0,0 +1,75 @@ +--[[----------------------------------------------------------------------------- +WeakAurasInlineGroup based on InlineGroup Container +Simple container widget that has the same API as a InlineGroup, without actually +showing any borders or a title. +-------------------------------------------------------------------------------]] +local Type, Version = "WeakAurasInlineGroup", 1 +local AceGUI = LibStub and LibStub("AceGUI-3.0", true) +if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end + +-- Lua APIs +local pairs = pairs + +-- WoW APIs +local CreateFrame, UIParent = CreateFrame, UIParent + +--[[----------------------------------------------------------------------------- +Methods +-------------------------------------------------------------------------------]] +local methods = { + ["OnAcquire"] = function(self) + self:SetWidth(300) + self:SetHeight(100) + self:SetTitle("") + end, + + -- ["OnRelease"] = nil, + + ["SetTitle"] = function(self) + -- Do nothing + end, + + + ["LayoutFinished"] = function(self, width, height) + if self.noAutoHeight then return end + self:SetHeight((height or 0) + 40) + end, + + ["OnWidthSet"] = function(self, width) + local content = self.content + content:SetWidth(width) + content.width = width + end, + + ["OnHeightSet"] = function(self, height) + local content = self.content + content:SetHeight(height) + content.height = height + end +} + +--[[----------------------------------------------------------------------------- +Constructor +-------------------------------------------------------------------------------]] +local function Constructor() + local frame = CreateFrame("Frame", nil, UIParent) + frame:SetFrameStrata("FULLSCREEN_DIALOG") + + --Container Support + local content = CreateFrame("Frame", nil, frame) + content:SetPoint("TOPLEFT", 0, 0) + content:SetPoint("BOTTOMRIGHT", 0, 0) + + local widget = { + frame = frame, + content = content, + type = Type + } + for method, func in pairs(methods) do + widget[method] = func + end + + return AceGUI:RegisterAsContainer(widget) +end + +AceGUI:RegisterWidgetType(Type, Constructor, Version) diff --git a/WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua b/WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua index 67052bd..4d3ae43 100644 --- a/WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua +++ b/WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua @@ -4,7 +4,7 @@ local tinsert, tconcat, tremove, wipe = table.insert, table.concat, table.remove local select, pairs, next, type, unpack = select, pairs, next, type, unpack local tostring, error = tostring, error -local Type, Version = "WeakAurasDisplayButton", 54 +local Type, Version = "WeakAurasDisplayButton", 55 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end @@ -95,18 +95,21 @@ clipboard.pasteMenuEntry = { for index, childId in pairs(clipboard.current.controlledChildren) do local childData = WeakAuras.GetData(childId); copyAuraPart(clipboard.source, childData, clipboard.part); - WeakAuras.Add(childData); + WeakAuras.Add(childData) + WeakAuras.ClearAndUpdateOptions(childData.id) end else copyAuraPart(clipboard.source, clipboard.current, clipboard.part); - WeakAuras.Add(clipboard.current); + WeakAuras.Add(clipboard.current) + WeakAuras.ClearAndUpdateOptions(clipboard.current.id) end + WeakAuras.FillOptions() WeakAuras.ScanForLoads({[clipboard.current.id] = true}); WeakAuras.SortDisplayButtons(); WeakAuras.PickDisplay(clipboard.current.id); WeakAuras.UpdateDisplayButton(clipboard.current.id); - WeakAuras.ReloadOptions2(clipboard.current.id, clipboard.current); + WeakAuras.ClearAndUpdateOptions(clipboard.current.id); end } @@ -304,16 +307,22 @@ local Actions = { WeakAuras.Add(source.data) WeakAuras.Add(group.data) WeakAuras.UpdateGroupOrders(group.data) - WeakAuras.ReloadGroupRegionOptions(group.data) + WeakAuras.ClearAndUpdateOptions(group.data.id) + WeakAuras.ClearAndUpdateOptions(source.data.id) WeakAuras.UpdateDisplayButton(group.data) + WeakAuras.FillOptions() group.callbacks.UpdateExpandButton(); group:ReloadTooltip() else WeakAuras.Add(source.data) + WeakAuras.ClearAndUpdateOptions(source.data.id) + WeakAuras.FillOptions() end else -- move source into the top-level list WeakAuras.Add(source.data) + WeakAuras.ClearAndUpdateOptions(source.data.id) + WeakAuras.FillOptions() end else error("Calling 'Group' with invalid source. Reload your UI to fix the display list.") @@ -331,7 +340,7 @@ local Actions = { source.data.parent = nil WeakAuras.Add(parent); WeakAuras.UpdateGroupOrders(parent); - WeakAuras.ReloadGroupRegionOptions(parent); + WeakAuras.ClearAndUpdateOptions(parent.id); WeakAuras.UpdateDisplayButton(parent); local group = WeakAuras.GetDisplayButton(parent.id) group.callbacks.UpdateExpandButton(); @@ -367,6 +376,8 @@ local Actions = { tinsert(children, 1, source.data.id) end WeakAuras.Add(parent) + WeakAuras.ClearAndUpdateOptions(parent.id) + WeakAuras.FillOptions() WeakAuras.UpdateGroupOrders(parent) WeakAuras.UpdateDisplayButton(parent) else @@ -572,6 +583,7 @@ local methods = { childButton:SetGroupOrder(#data.controlledChildren, #data.controlledChildren); childData.parent = data.id; WeakAuras.Add(childData); + WeakAuras.ClearAndUpdateOptions(childData.id) end else tinsert(data.controlledChildren, self.grouping.id); @@ -580,16 +592,19 @@ local methods = { childButton:SetGroupOrder(#data.controlledChildren, #data.controlledChildren); self.grouping.parent = data.id; WeakAuras.Add(self.grouping); + WeakAuras.ClearAndUpdateOptions(self.grouping.id); end if (data.regionType == "dynamicgroup") then self.grouping.xOffset = 0; self.grouping.yOffset = 0; end WeakAuras.Add(data); + WeakAuras.ClearAndUpdateOptions(data.id) self.callbacks.UpdateExpandButton(); WeakAuras.SetGrouping(); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadGroupRegionOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id); + WeakAuras.FillOptions(); WeakAuras.UpdateGroupOrders(data); WeakAuras.SortDisplayButtons(); self:ReloadTooltip(); @@ -670,6 +685,7 @@ local methods = { tremove(parentData.controlledChildren, index); tinsert(parentData.controlledChildren, index - 1, id); WeakAuras.Add(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id) self:SetGroupOrder(index - 1, #parentData.controlledChildren); local otherbutton = WeakAuras.GetDisplayButton(parentData.controlledChildren[index]); otherbutton:SetGroupOrder(index, #parentData.controlledChildren); @@ -679,6 +695,7 @@ local methods = { WeakAuras.Animate("button", WeakAuras.GetData(parentData.controlledChildren[index-1]), "main", updata, self.frame, true, function() WeakAuras.SortDisplayButtons() end); WeakAuras.Animate("button", WeakAuras.GetData(parentData.controlledChildren[index]), "main", downdata, otherbutton.frame, true, function() WeakAuras.SortDisplayButtons() end); WeakAuras.UpdateDisplayButton(parentData); + WeakAuras.FillOptions() end else error("Display thinks it is a member of a group which does not control it"); @@ -707,6 +724,7 @@ local methods = { tremove(parentData.controlledChildren, index); tinsert(parentData.controlledChildren, index + 1, id); WeakAuras.Add(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id) self:SetGroupOrder(index + 1, #parentData.controlledChildren); local otherbutton = WeakAuras.GetDisplayButton(parentData.controlledChildren[index]); otherbutton:SetGroupOrder(index, #parentData.controlledChildren); @@ -716,6 +734,7 @@ local methods = { WeakAuras.Animate("button", WeakAuras.GetData(parentData.controlledChildren[index+1]), "main", downdata, self.frame, true, function() WeakAuras.SortDisplayButtons() end); WeakAuras.Animate("button", WeakAuras.GetData(parentData.controlledChildren[index]), "main", updata, otherbutton.frame, true, function() WeakAuras.SortDisplayButtons() end); WeakAuras.UpdateDisplayButton(parentData); + WeakAuras.FillOptions() end else error("Display thinks it is a member of a group which does not control it"); @@ -788,13 +807,12 @@ local methods = { if not(newid == oldid) then WeakAuras.Rename(data, newid); - WeakAuras.Add(data); + WeakAuras.Add(data) WeakAuras.displayButtons[newid] = WeakAuras.displayButtons[oldid]; WeakAuras.displayButtons[newid]:SetData(data) WeakAuras.displayButtons[oldid] = nil; - WeakAuras.displayOptions[oldid] = nil; - WeakAuras.AddOption(newid, data); + WeakAuras.ClearOptions(oldid) WeakAuras.displayButtons[newid]:SetTitle(newid); @@ -1156,13 +1174,14 @@ local methods = { if(index) then tremove(parentData.controlledChildren, index); WeakAuras.Add(parentData); - WeakAuras.ReloadGroupRegionOptions(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id); else error("Display thinks it is a member of a group which does not control it"); end self:SetGroup(); self.data.parent = nil; WeakAuras.Add(self.data); + WeakAuras.ClearAndUpdateOptions(self.data.id); WeakAuras.UpdateGroupOrders(parentData); WeakAuras.UpdateDisplayButton(parentData); WeakAuras.SortDisplayButtons(); @@ -1521,13 +1540,11 @@ local methods = { -- no addon, or no data, or ignore flag return false, false, nil, nil end, - -- TODO: remove this once legacy aura trigger is removed ["RefreshBT2UpgradeIcon"] = function(self) if not self.data.controlledChildren and self.data.triggers then for index, t in ipairs(self.data.triggers) do if t.trigger and t.trigger.type == "aura" then self.bt2upgrade:SetScript("OnClick", function() - WeakAuras.optionTriggerChoices[self.data.id] = index WeakAuras.PickDisplay(self.data.id, "trigger") end) self.bt2upgrade:Show() diff --git a/WeakAurasOptions/ActionOptions.lua b/WeakAurasOptions/ActionOptions.lua index 8d01695..6e66051 100644 --- a/WeakAurasOptions/ActionOptions.lua +++ b/WeakAurasOptions/ActionOptions.lua @@ -2,11 +2,19 @@ if not WeakAuras.IsCorrectVersion() then return end local L = WeakAuras.L +local removeFuncs = WeakAuras.commonOptions.removeFuncs +local replaceNameDescFuncs = WeakAuras.commonOptions.replaceNameDescFuncs +local replaceImageFuncs = WeakAuras.commonOptions.replaceImageFuncs +local replaceValuesFuncs = WeakAuras.commonOptions.replaceValuesFuncs +local disabledAll = WeakAuras.commonOptions.CreateDisabledAll("action") +local hiddenAll = WeakAuras.commonOptions.CreateHiddenAll("action") +local getAll = WeakAuras.commonOptions.CreateGetAll("action") +local setAll = WeakAuras.commonOptions.CreateSetAll("action", getAll) local send_chat_message_types = WeakAuras.send_chat_message_types; local sound_types = WeakAuras.sound_types; -function WeakAuras.AddActionOption(id, data) +function WeakAuras.GetActionOptions(data) local action = { type = "group", name = L["Actions"], @@ -52,7 +60,7 @@ function WeakAuras.AddActionOption(id, data) end WeakAuras.Add(data); if(value == "message") then - WeakAuras.ReloadOptions(data.id) + WeakAuras.ClearAndUpdateOptions(data.id) end end, args = { @@ -801,10 +809,10 @@ function WeakAuras.AddActionOption(id, data) -- Text format option helpers - WeakAuras.AddCodeOption(action.args, data, L["Custom Code"], "init", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-init", + WeakAuras.commonOptions.AddCodeOption(action.args, data, L["Custom Code"], "init", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-init", 0.011, function() return not data.actions.init.do_custom end, {"actions", "init", "custom"}, true); - WeakAuras.AddCodeOption(action.args, data, L["Custom Code"], "start_message", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#chat-message---custom-code", + WeakAuras.commonOptions.AddCodeOption(action.args, data, L["Custom Code"], "start_message", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#chat-message---custom-code", 5, function() return not (data.actions.start.do_message and WeakAuras.ContainsCustomPlaceHolder(data.actions.start.message)) end, {"actions", "start", "message_custom"}, false); local startHidden = function() @@ -834,7 +842,7 @@ function WeakAuras.AddActionOption(id, data) data.actions.start["message_format_" .. key] = v WeakAuras.Add(data) if reload then - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) end end @@ -861,10 +869,10 @@ function WeakAuras.AddActionOption(id, data) end - WeakAuras.AddCodeOption(action.args, data, L["Custom Code"], "start", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-show", + WeakAuras.commonOptions.AddCodeOption(action.args, data, L["Custom Code"], "start", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-show", 13, function() return not data.actions.start.do_custom end, {"actions", "start", "custom"}, true); - WeakAuras.AddCodeOption(action.args, data, L["Custom Code"], "finish_message", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#chat-message---custom-code", + WeakAuras.commonOptions.AddCodeOption(action.args, data, L["Custom Code"], "finish_message", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#chat-message---custom-code", 25, function() return not (data.actions.finish.do_message and WeakAuras.ContainsCustomPlaceHolder(data.actions.finish.message)) end, {"actions", "finish", "message_custom"}, false); local finishHidden = function() @@ -893,7 +901,7 @@ function WeakAuras.AddActionOption(id, data) data.actions.finish["message_format_" .. key] = v WeakAuras.Add(data) if reload then - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) end end @@ -919,8 +927,27 @@ function WeakAuras.AddActionOption(id, data) WeakAuras.AddTextFormatOption(data.actions and data.actions.finish.message, true, finishGet, finishAddOption, finishHidden, finishSetHidden) end - WeakAuras.AddCodeOption(action.args, data, L["Custom Code"], "finish", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-hide", + WeakAuras.commonOptions.AddCodeOption(action.args, data, L["Custom Code"], "finish", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#on-hide", 32, function() return not data.actions.finish.do_custom end, {"actions", "finish", "custom"}, true); + if data.controlledChildren then + removeFuncs(action) + replaceNameDescFuncs(action, data, "action") + replaceImageFuncs(action, data, "action") + replaceValuesFuncs(action, data, "action") + + action.get = function(info, ...) return getAll(data, info, ...); end; + action.set = function(info, ...) + setAll(data, info, ...); + if(type(data.id) == "string") then + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + end + end + action.hidden = function(info, ...) return hiddenAll(data, info, ...); end; + action.disabled = function(info, ...) return disabledAll(data, info, ...); end; + end + return action; end diff --git a/WeakAurasOptions/AnimationOptions.lua b/WeakAurasOptions/AnimationOptions.lua index 109de67..f249a59 100644 --- a/WeakAurasOptions/AnimationOptions.lua +++ b/WeakAurasOptions/AnimationOptions.lua @@ -2,6 +2,15 @@ if not WeakAuras.IsCorrectVersion() then return end local L = WeakAuras.L +local removeFuncs = WeakAuras.commonOptions.removeFuncs +local replaceNameDescFuncs = WeakAuras.commonOptions.replaceNameDescFuncs +local replaceImageFuncs = WeakAuras.commonOptions.replaceImageFuncs +local replaceValuesFuncs = WeakAuras.commonOptions.replaceValuesFuncs +local disabledAll = WeakAuras.commonOptions.CreateDisabledAll("animation") +local hiddenAll = WeakAuras.commonOptions.CreateHiddenAll("animation") +local getAll = WeakAuras.commonOptions.CreateGetAll("animation") +local setAll = WeakAuras.commonOptions.CreateSetAll("animation", getAll) + local anim_types = WeakAuras.anim_types; local anim_translate_types = WeakAuras.anim_translate_types; local anim_scale_types = WeakAuras.anim_scale_types; @@ -46,7 +55,8 @@ local function filterAnimPresetTypes(intable, id) return ret; end -function WeakAuras.AddAnimationOption(id, data) +function WeakAuras.GetAnimationOptions(data) + local id = data.id local animation = { type = "group", name = L["Animations"], @@ -846,94 +856,113 @@ function WeakAuras.AddAnimationOption(id, data) local function hideStartAlphaFunc() return data.animation.start.type ~= "custom" or data.animation.start.alphaType ~= "custom" or not data.animation.start.use_alpha end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "start_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "start_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", 35.3, hideStartAlphaFunc, {"animation", "start", "alphaFunc"}, false); local function hideStartTranslate() return data.animation.start.type ~= "custom" or data.animation.start.translateType ~= "custom" or not data.animation.start.use_translate end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "start_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "start_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", 39.3, hideStartTranslate, {"animation", "start", "translateFunc"}, false); local function hideStartScale() return data.animation.start.type ~= "custom" or data.animation.start.scaleType ~= "custom" or not (data.animation.start.use_scale and WeakAuras.regions[id].region.Scale) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "start_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-size", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "start_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-size", 43.3, hideStartScale, {"animation", "start", "scaleFunc"}, false); local function hideStartRotateFunc() return data.animation.start.type ~= "custom" or data.animation.start.rotateType ~= "custom" or not (data.animation.start.use_rotate and WeakAuras.regions[id].region.Rotate) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "start_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "start_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", 47.3, hideStartRotateFunc, {"animation", "start", "rotateFunc"}, false); local function hideStartColorFunc() return data.animation.start.type ~= "custom" or data.animation.start.colorType ~= "custom" or not (data.animation.start.use_color and WeakAuras.regions[id].region.Color) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "start_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "start_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", 48.7, hideStartColorFunc, {"animation", "start", "colorFunc"}, false); -- Text Editors for "main" local function hideMainAlphaFunc() return data.animation.main.type ~= "custom" or data.animation.main.alphaType ~= "custom" or not data.animation.main.use_alpha end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "main_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "main_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", 55.3, hideMainAlphaFunc, {"animation", "main", "alphaFunc"}, false, nil, extraSetFunction); local function hideMainTranslate() return data.animation.main.type ~= "custom" or data.animation.main.translateType ~= "custom" or not data.animation.main.use_translate end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "main_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "main_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", 59.3, hideMainTranslate, {"animation", "main", "translateFunc"}, false, nil, extraSetFunction); local function hideMainScale() return data.animation.main.type ~= "custom" or data.animation.main.scaleType ~= "custom" or not (data.animation.main.use_scale and WeakAuras.regions[id].region.Scale) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "main_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-sizes", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "main_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-sizes", 63.3, hideMainScale, {"animation", "main", "scaleFunc"}, false, nil, extraSetFunction); local function hideMainRotateFunc() return data.animation.main.type ~= "custom" or data.animation.main.rotateType ~= "custom" or not (data.animation.main.use_rotate and WeakAuras.regions[id].region.Rotate) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "main_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "main_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", 67.3, hideMainRotateFunc, {"animation", "main", "rotateFunc"}, false, nil, extraSetFunction); local function hideMainColorFunc() return data.animation.main.type ~= "custom" or data.animation.main.colorType ~= "custom" or not (data.animation.main.use_color and WeakAuras.regions[id].region.Color) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "main_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "main_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", 68.7, hideMainColorFunc, {"animation", "main", "colorFunc"}, false, nil, extraSetFunction); -- Text Editors for "finish" local function hideFinishAlphaFunc() return data.animation.finish.type ~= "custom" or data.animation.finish.alphaType ~= "custom" or not data.animation.finish.use_alpha end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "finish_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "finish_alphaFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#alpha-opacity", 75.3, hideFinishAlphaFunc, {"animation", "finish", "alphaFunc"}, false); local function hideFinishTranslate() return data.animation.finish.type ~= "custom" or data.animation.finish.translateType ~= "custom" or not data.animation.finish.use_translate end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "finish_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "finish_translateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#translate-position", 79.3, hideFinishTranslate, {"animation", "finish", "translateFunc"}, false); local function hideFinishScale() return data.animation.finish.type ~= "custom" or data.animation.finish.scaleType ~= "custom" or not (data.animation.finish.use_scale and WeakAuras.regions[id].region.Scale) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "finish_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-size", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "finish_scaleFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#scale-size", 83.3, hideFinishScale, {"animation", "finish", "scaleFunc"}, false); local function hideFinishRotateFunc() return data.animation.finish.type ~= "custom" or data.animation.finish.rotateType ~= "custom" or not (data.animation.finish.use_rotate and WeakAuras.regions[id].region.Rotate) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "finish_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "finish_rotateFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#rotate", 87.3, hideFinishRotateFunc, {"animation", "finish", "rotateFunc"}, false); local function hideFinishColorFunc() return data.animation.finish.type ~= "custom" or data.animation.finish.colorType ~= "custom" or not (data.animation.finish.use_color and WeakAuras.regions[id].region.Color) end - WeakAuras.AddCodeOption(animation.args, data, L["Custom Function"], "finish_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", + WeakAuras.commonOptions.AddCodeOption(animation.args, data, L["Custom Function"], "finish_colorFunc", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#color", 88.7, hideFinishColorFunc, {"animation", "finish", "colorFunc"}, false); + if(data.controlledChildren) then + removeFuncs(animation); + replaceNameDescFuncs(animation, data, "animation"); + replaceImageFuncs(animation, data, "animation"); + replaceValuesFuncs(animation, data, "animation"); + + animation.get = function(info, ...) return getAll(data, info, ...); end; + animation.set = function(info, ...) + setAll(data, info, ...); + if(type(data.id) == "string") then + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + end + end + animation.hidden = function(info, ...) return hiddenAll(data, info, ...); end; + animation.disabled = function(info, ...) return disabledAll(data, info, ...); end; + end + return animation; end diff --git a/WeakAurasOptions/AuthorOptions.lua b/WeakAurasOptions/AuthorOptions.lua index 540295b..7c08444 100644 --- a/WeakAurasOptions/AuthorOptions.lua +++ b/WeakAurasOptions/AuthorOptions.lua @@ -407,7 +407,7 @@ local function set(data, option, key) childOption[key] = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -419,7 +419,7 @@ local function setUser(data, option) childConfig[option.key] = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -432,7 +432,7 @@ local function setStr(data, option, key) childOption[key] = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -457,7 +457,7 @@ local function setNum(data, option, key, required) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -472,7 +472,7 @@ local function setUserNum(data, option) childConfig[option.key] = num WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end end @@ -486,7 +486,7 @@ local function setColor(data, option, key) childOption[key] = color WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -499,7 +499,7 @@ local function setUserColor(data, option) childConfig[option.key] = color WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -511,7 +511,7 @@ local function setSelectDefault(data, option, key) childOption.default = min(value, #childOption.values) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -524,7 +524,7 @@ local function setArrayStr(data, option, array, index) childOption[array][index] = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -553,7 +553,7 @@ typeControlAdders = { childOption.default = val WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } end, @@ -827,7 +827,7 @@ typeControlAdders = { end WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } args[prefix .. "valdelete" .. j] = { @@ -842,7 +842,7 @@ typeControlAdders = { tremove(childOption.values, j) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", imageWidth = 24, @@ -880,7 +880,7 @@ typeControlAdders = { childOption.values[#childOption.values + 1] = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } end, @@ -963,7 +963,7 @@ typeControlAdders = { childOption.default[k] = v WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } for j, value in ipairs(values) do @@ -1006,7 +1006,7 @@ typeControlAdders = { end WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } args[prefix .. "valdelete" .. j] = { @@ -1022,7 +1022,7 @@ typeControlAdders = { tremove(childOption.default, j) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", imageWidth = 24, @@ -1060,7 +1060,7 @@ typeControlAdders = { childOption.default[#childOption.default + 1] = false WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } end, @@ -1119,7 +1119,7 @@ typeControlAdders = { childOption.groupType = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } args[prefix .. "useCollapse"] = { @@ -1146,7 +1146,7 @@ typeControlAdders = { WeakAuras.SetCollapsed(id, "config", optionData.path, value) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() return not option.useCollapse end } @@ -1170,7 +1170,7 @@ typeControlAdders = { childOption.limitType = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, } args[prefix .. "size"] = { @@ -1201,7 +1201,7 @@ typeControlAdders = { childOption.size = value WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() return option.limitType == "none" end, } @@ -1270,7 +1270,7 @@ typeControlAdders = { end WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, } if option.nameSource == -1 then @@ -1322,7 +1322,7 @@ typeControlAdders = { WeakAuras.SetCollapsed(id, "author", path, false) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } args[prefix .. "groupEnd"] = { @@ -1352,7 +1352,7 @@ local function up(data, options, index) childOptions[optionID], childOptions[optionID - 1] = childOptions[optionID - 1], childOptions[optionID] WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -1375,7 +1375,7 @@ local function down(data, options, index) childOptions[optionID], childOptions[optionID + 1] = childOptions[optionID + 1], childOptions[optionID] WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -1407,7 +1407,7 @@ local function duplicate(data, options, index) tinsert(childOptions, optionID + 1, newOption) WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end @@ -1472,7 +1472,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) for id, optionData in pairs(option.references) do WeakAuras.SetCollapsed(id, "author", optionData.path, not collapsed) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = collapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\expand" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\collapse", @@ -1503,7 +1503,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\upright", imageWidth = 24, @@ -1532,7 +1532,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\downright", imageWidth = 24, @@ -1559,7 +1559,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) WeakAuras.InsertCollapsed(id, "author", path) WeakAuras.Add(optionData.data) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\upleft", imageWidth = 24, @@ -1586,7 +1586,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) WeakAuras.InsertCollapsed(id, "author", path) WeakAuras.Add(optionData.data) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\downleft", imageWidth = 24, @@ -1654,7 +1654,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) end WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", imageWidth = 24, @@ -1730,7 +1730,7 @@ function addAuthorModeOption(options, args, data, order, prefix, i) end WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } @@ -1880,7 +1880,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) for id, optionData in pairs(option.references) do WeakAuras.SetCollapsed(id, "config", optionData.path, not collapsed) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = collapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\expand" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\collapse", @@ -1977,7 +1977,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) for id, optionData in pairs(option.references) do setPage(id, optionData.path, value) -- XXX: mergeOptions will reset this to the maximum value if it's too big end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, } args[prefix .. "resetEntry"] = { @@ -1993,7 +1993,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) childConfigList[childPage] = {} WeakAuras.Add(childData) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, width = 0.15, image = "Interface\\Addons\\WeakAuras\\Media\\Textures\\reset", @@ -2018,7 +2018,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() if option.limitType == "none" then @@ -2055,7 +2055,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() return skipSubOptions @@ -2084,7 +2084,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() for id, optionData in pairs(option.references) do @@ -2115,7 +2115,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) WeakAuras.Add(childData) end end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() for id, optionData in pairs(option.references) do @@ -2189,7 +2189,7 @@ local function addUserModeOption(options, args, data, order, prefix, i) optionData.config[option.key][k] = v WeakAuras.Add(optionData.data) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end end elseif optionClass == "noninteractive" then @@ -2448,11 +2448,18 @@ local function createorder(startorder) end end -function WeakAuras.GetAuthorOptions(data, args, startorder) +function WeakAuras.GetAuthorOptions(data) -- initialize the process + local authorOptions = { + type = "group", + name = L["Custom Options"], + order = 100, + args = {} + } + local args = authorOptions.args local isAuthorMode = true local options = {} - local order = createorder(startorder) + local order = createorder(1) if data.controlledChildren then -- merge options together for i = 1, #data.controlledChildren do @@ -2477,12 +2484,12 @@ function WeakAuras.GetAuthorOptions(data, args, startorder) for _, id in ipairs(data.controlledChildren) do local childData = WeakAuras.GetData(id) childData.authorMode = nil - -- no need to add, author mode is picked up by ReloadTriggerOptions + -- no need to add, author mode is picked up by ClearAndUpdateOptions end else data.authorMode = nil end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } args["enterUserModeSpacer"] = { @@ -2527,7 +2534,7 @@ function WeakAuras.GetAuthorOptions(data, args, startorder) WeakAuras.SetCollapsed(data.id, "author", i, false) WeakAuras.Add(data) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } else @@ -2558,7 +2565,7 @@ function WeakAuras.GetAuthorOptions(data, args, startorder) WeakAuras.ResetCollapsed(data.id, "config") WeakAuras.Add(data) end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end, disabled = function() local path = {} @@ -2598,14 +2605,14 @@ function WeakAuras.GetAuthorOptions(data, args, startorder) for _, id in ipairs(data.controlledChildren) do local childData = WeakAuras.GetData(id) childData.authorMode = true - -- no need to add, author mode is picked up by ReloadTriggerOptions + -- no need to add, author mode is picked up by ClearAndUpdateOptions end else data.authorMode = true end - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id, true) end } end - return args + return authorOptions end diff --git a/WeakAurasOptions/BuffTrigger.lua b/WeakAurasOptions/BuffTrigger.lua index 1e4c1a5..1056355 100644 --- a/WeakAurasOptions/BuffTrigger.lua +++ b/WeakAurasOptions/BuffTrigger.lua @@ -55,15 +55,35 @@ local function getAuraMatchesList(name) end end -function WeakAuras.GetBuffConversionOptions(data, optionTriggerChoices) - local trigger; - if (not data.controlledChildren) then - local triggernum = optionTriggerChoices[data.id]; - if (triggernum) then - trigger = data.triggers[triggernum].trigger; - end - end +local function GetBuffTriggerOptions(data, triggernum) + local trigger= data.triggers[triggernum].trigger + local spellCache = WeakAuras.spellCache; + local ValidateNumeric = WeakAuras.ValidateNumeric; local aura_options = { + convertToBuffTrigger2SpaceBeforeDesc = { + type = "description", + width = 0.4, + order = 8.1, + name = "", + }, + convertToBuffTrigger2Desc = { + type = "description", + width = WeakAuras.doubleWidth - 0.8, + order = 8.2, + name = function() + if (not WeakAuras.CanConvertBuffTrigger2) then + return ""; + end + local _, err = WeakAuras.CanConvertBuffTrigger2(trigger); + return err or ""; + end, + }, + convertToBuffTrigger2SpaceAfterDesc = { + type = "description", + width = 0.4, + order = 8.3, + name = "", + }, convertToBuffTrigger2SpaceBefore = { type = "description", width = 0.3, @@ -97,23 +117,10 @@ function WeakAuras.GetBuffConversionOptions(data, optionTriggerChoices) return err or "" end, func = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - local trigger = childData.triggers[optionTriggerChoices[childId]] and childData.triggers[optionTriggerChoices[childId]].trigger; - if (trigger) then - WeakAuras.ConvertBuffTrigger2(trigger); - WeakAuras.Add(childData); - WeakAuras.ReloadTriggerOptions(childData); - end - end - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - else - WeakAuras.ConvertBuffTrigger2(trigger); - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - end + WeakAuras.ConvertBuffTrigger2(trigger); + WeakAuras.Add(data); + WeakAuras.UpdateDisplayButton(data) + WeakAuras.ClearAndUpdateOptions(data.id); end }, convertToBuffTrigger2SpaceAfter = { @@ -121,63 +128,8 @@ function WeakAuras.GetBuffConversionOptions(data, optionTriggerChoices) width = 0.3, order = 8.6, name = "", - hidden = function() - -- For those that update without restarting - return not WeakAuras.CanConvertBuffTrigger2 - end, }, - convertToBuffTrigger2SpaceBeforeDesc = { - type = "description", - width = 0.4, - order = 8.1, - name = "", - hidden = function() - -- For those that update without restarting - return not WeakAuras.CanConvertBuffTrigger2 - end, - }, - convertToBuffTrigger2Desc = { - type = "description", - width = WeakAuras.doubleWidth - 0.8, - order = 8.2, - name = function() - if (not WeakAuras.CanConvertBuffTrigger2) then - return ""; - end - local _, err = WeakAuras.CanConvertBuffTrigger2(trigger); - return err or ""; - end, - hidden = function() - -- For those that update without restarting - return not WeakAuras.CanConvertBuffTrigger2 - end, - }, - convertToBuffTrigger2SpaceAfterDesc = { - type = "description", - width = 0.4, - order = 8.3, - name = "", - hidden = function() - -- For those that update without restarting - return not WeakAuras.CanConvertBuffTrigger2 - end, - }, - } - return aura_options; -end -local function GetBuffTriggerOptions(data, optionTriggerChoices) - local trigger; - if (not data.controlledChildren) then - local triggernum = optionTriggerChoices[data.id]; - if (triggernum) then - trigger = data.triggers[triggernum].trigger; - end - end - - local spellCache = WeakAuras.spellCache; - local ValidateNumeric = WeakAuras.ValidateNumeric; - local aura_options = { fullscan = { type = "toggle", name = L["Use Full Scan (High CPU)"], @@ -240,7 +192,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -294,7 +245,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) else trigger.use_stealable = false end end WeakAuras.Add(data); - WeakAuras.SetIconNames(data); end }, use_spellId = { @@ -366,7 +316,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -402,7 +351,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -445,7 +393,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -488,7 +435,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -530,7 +476,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -573,7 +518,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -616,7 +560,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -659,7 +602,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -702,7 +644,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -745,7 +686,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end, }, @@ -839,7 +779,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) trigger.group_count = ""; end WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -1070,7 +1009,14 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) }, }; - return aura_options; + + WeakAuras.commonOptions.AddCommonTriggerOptions(aura_options, data, triggernum) + WeakAuras.commonOptions.AddTriggerGetterSetter(aura_options, data, triggernum) + WeakAuras.AddTriggerMetaFunctions(aura_options, data, triggernum) + + return { + ["trigger." .. triggernum .. ".legacy_aura_options"] = aura_options + } end WeakAuras.RegisterTriggerSystemOptions({"aura"}, GetBuffTriggerOptions); diff --git a/WeakAurasOptions/BuffTrigger2.lua b/WeakAurasOptions/BuffTrigger2.lua index 18ff90d..19e7bf5 100644 --- a/WeakAurasOptions/BuffTrigger2.lua +++ b/WeakAurasOptions/BuffTrigger2.lua @@ -8,7 +8,6 @@ local debuff_types = WeakAuras.debuff_types local function getAuraMatchesLabel(name) local ids = WeakAuras.spellCache.GetSpellsMatching(name) if ids then - local descText = "" local numMatches = 0 for id, _ in pairs(ids) do numMatches = numMatches + 1 @@ -47,21 +46,11 @@ local function shiftTable(tbl, pos) end -- Counts the Names or SpellIds in a aura, recursively. -local function CountNames(data, optionTriggerChoices, name) +local function CountNames(data, triggernum, name) local result = 0 - if data.controlledChildren then - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId) - local trigger = optionTriggerChoices[childId] and childData.triggers[optionTriggerChoices[childId]].trigger - if trigger and trigger[name] then - result = max(result, #trigger[name]) - end - end - else - local trigger = optionTriggerChoices[data.id] and data.triggers[optionTriggerChoices[data.id]].trigger - if trigger[name] then - result = #trigger[name] - end + local trigger = data.triggers[triggernum].trigger + if trigger[name] then + result = #trigger[name] end return result end @@ -190,9 +179,8 @@ local function CreateNameOptions(aura_options, data, trigger, size, isExactSpell WeakAuras.Add(data) WeakAuras.UpdateThumbnail(data) - WeakAuras.SetIconNames(data) WeakAuras.UpdateDisplayButton(data) - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id) end, validate = isExactSpellId and WeakAuras.ValidateNumeric or nil } @@ -200,16 +188,8 @@ local function CreateNameOptions(aura_options, data, trigger, size, isExactSpell -- VALIDATE ? end -local function GetBuffTriggerOptions(data, optionTriggerChoices) - local trigger - if not data.controlledChildren then - local triggernum = optionTriggerChoices[data.id] - if triggernum then - trigger = data.triggers[triggernum].trigger - end - end - - +local function GetBuffTriggerOptions(data, triggernum) + local trigger = data.triggers[triggernum].trigger local function HasMatchCount(trigger) if IsGroupTrigger(trigger) then @@ -601,7 +581,6 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) else trigger.use_stealable = false end end WeakAuras.Add(data) - WeakAuras.SetIconNames(data) end }, useAffected = { @@ -695,7 +674,7 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) }, ignoreInvisible = { type = "toggle", - name = WeakAuras.newFeatureString .. L["Ignore out of checking range."], + name = WeakAuras.newFeatureString .. L["Ignore out of checking range"], desc = L["Uses UnitIsVisible() to check if in range. This is polled every second."], order = 68.9, width = WeakAuras.doubleWidth, @@ -733,6 +712,7 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) end }, + useGroup_count = { type = "toggle", width = WeakAuras.normalWidth, @@ -943,10 +923,10 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) } -- Names - local nameOptionSize = CountNames(data, optionTriggerChoices, "auranames") + 1 - local spellOptionsSize = CountNames(data, optionTriggerChoices, "auraspellids") + 1 - local ignoreNameOptionSize = CountNames(data, optionTriggerChoices, "ignoreAuraNames") + 1 - local ignoreSpellOptionsSize = CountNames(data, optionTriggerChoices, "ignoreAuraSpellids") + 1 + local nameOptionSize = CountNames(data, triggernum, "auranames") + 1 + local spellOptionsSize = CountNames(data, triggernum, "auraspellids") + 1 + local ignoreNameOptionSize = CountNames(data, triggernum, "ignoreAuraNames") + 1 + local ignoreSpellOptionsSize = CountNames(data, triggernum, "ignoreAuraSpellids") + 1 CreateNameOptions(aura_options, data, trigger, nameOptionSize, false, false, "name", 12, "useName", "auranames", @@ -967,8 +947,14 @@ local function GetBuffTriggerOptions(data, optionTriggerChoices) true, true, "ignorespellid", 42, "useIgnoreExactSpellId", "ignoreAuraSpellids", L["Ignored Spell ID"], L["Enter a Spell ID"]) + WeakAuras.commonOptions.AddCommonTriggerOptions(aura_options, data, triggernum) + WeakAuras.commonOptions.AddTriggerGetterSetter(aura_options, data, triggernum) + WeakAuras.AddTriggerMetaFunctions(aura_options, data, triggernum) - return aura_options + + return { + ["trigger." .. triggernum .. ".aura_options"] = aura_options + } end WeakAuras.RegisterTriggerSystemOptions({"aura2"}, GetBuffTriggerOptions) diff --git a/WeakAurasOptions/Cache.lua b/WeakAurasOptions/Cache.lua index 711db1e..ee9d6a1 100644 --- a/WeakAurasOptions/Cache.lua +++ b/WeakAurasOptions/Cache.lua @@ -118,8 +118,9 @@ function spellCache.AddIcon(name, id, icon) if cache then if name then cache[name] = cache[name] or {} + cache[name].spells = cache[name].spells or {} if id and icon then - cache[name][id] = icon + cache[name].spells[id] = icon end end else diff --git a/WeakAurasOptions/CommonOptions.lua b/WeakAurasOptions/CommonOptions.lua new file mode 100644 index 0000000..d31dc43 --- /dev/null +++ b/WeakAurasOptions/CommonOptions.lua @@ -0,0 +1,1443 @@ +-- Nothing here + +local L = WeakAuras.L +local regionOptions = WeakAuras.regionOptions +local point_types = WeakAuras.point_types; + +local parsePrefix = function(input, data, create) + local subRegionIndex, property = string.match(input, "^sub%.(%d+)%..-%.(.+)") + subRegionIndex = tonumber(subRegionIndex) + if subRegionIndex then + if create then + data.subRegions = data.subRegions or {} + data.subRegions[subRegionIndex] = data.subRegions[subRegionIndex] or {} + else + if not data.subRegions or not data.subRegions[subRegionIndex] then + return nil + end + end + return data.subRegions[subRegionIndex], property + end + local index = string.find(input, ".", 1, true); + if (index) then + return data, string.sub(input, index + 1); + end + return data, input +end + +local function setFuncs(option, input) + if type(input) == "function" then + option.func = input + else + option.func = input.func + option.disabled = input.disabled + end +end + +local function addCollapsibleHeader(options, key, input, order, isGroupTab) + if input.__noHeader then + return + end + local title = input.__title + local hasAdd = input.__add + local hasDelete = input.__delete + local hasUp = input.__up + local hasDown = input.__down + local hasDuplicate = input.__duplicate + local hasApplyTemplate = input.__applyTemplate + local hiddenFunc = input.__hidden + local nooptions = input.__nooptions + local marginTop = input.__topLine + + local titleWidth = WeakAuras.doubleWidth - (hasAdd and 0.15 or 0) - (hasDelete and 0.15 or 0) - (hasUp and 0.15 or 0) + - (hasDown and 0.15 or 0) - (hasDuplicate and 0.15 or 0) - (hasApplyTemplate and 0.15 or 0) + + options[key .. "collapseSpacer"] = { + type = marginTop and "header" or "description", + name = "", + order = order, + width = "full", + hidden = hiddenFunc, + } + options[key .. "collapseButton"] = { + type = "execute", + name = title, + order = order + 0.1, + width = titleWidth, + func = function(info, button, secondCall) + if not nooptions and not secondCall then + local isCollapsed = WeakAuras.IsCollapsed("collapse", "region", key, false) + WeakAuras.SetCollapsed("collapse", "region", key, not isCollapsed) + end + end, + image = function() + if nooptions then + return "Interface\\AddOns\\WeakAuras\\Media\\Textures\\bullet1", 18, 18 + else + local isCollapsed = WeakAuras.IsCollapsed("collapse", "region", key, false) + return isCollapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\expand" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\collapse", 18, 18 + end + end, + control = "WeakAurasExpand", + hidden = hiddenFunc + } + + if hasAdd then + options[key .. "addButton"] = { + type = "execute", + name = L["Add"], + order = order + 0.2, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\add", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "addButton"], input.__add) + end + + if hasUp then + options[key .. "upButton"] = { + type = "execute", + name = L["Move Up"], + order = order + 0.3, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\moveup", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "upButton"], input.__up) + end + + if hasDown then + options[key .. "downButton"] = { + type = "execute", + name = L["Move Down"], + order = order + 0.4, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\movedown", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "downButton"], input.__down) + end + + if hasDuplicate then + options[key .. "duplicateButton"] = { + type = "execute", + name = L["Duplicate"], + order = order + 0.5, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\duplicate", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "duplicateButton"], input.__duplicate) + end + + if hasDelete then + options[key .. "deleteButton"] = { + type = "execute", + name = L["Delete"], + order = order + 0.6, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "deleteButton"], input.__delete) + end + + if hasApplyTemplate then + options[key .. "applyTemplate"] = { + type = "execute", + name = L["Apply Template"], + order = order + 0.7, + width = 0.15, + image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\template", + imageWidth = 24, + imageHeight = 24, + control = "WeakAurasIcon", + hidden = hiddenFunc + } + setFuncs(options[key .. "applyTemplate"], input.__applyTemplate) + end + + if hiddenFunc then + return function() + return hiddenFunc() or WeakAuras.IsCollapsed("collapse", "region", key, false) + end + else + return function() + return WeakAuras.IsCollapsed("collapse", "region", key, false) + end + end +end + +local function copyOptionTable(input, orderAdjustment, collapsedFunc) + local resultOption = {}; + WeakAuras.DeepCopy(input, resultOption); + resultOption.order = orderAdjustment + resultOption.order; + if collapsedFunc then + local oldHidden = resultOption.hidden; + if oldHidden ~= nil then + local oldFunc + if type(oldHidden) ~= "function" then + oldFunc = function(...) return oldHidden end + else + oldFunc = oldHidden + end + resultOption.hidden = function(...) + if collapsedFunc() then + return true + else + return oldFunc(...) + end + end + else + resultOption.hidden = collapsedFunc; + end + end + return resultOption; +end + +local flattenRegionOptions = function(allOptions, isGroupTab) + local result = {}; + local base = 1000; + + for optionGroup, options in pairs(allOptions) do + local groupBase = base * options.__order + + local collapsedFunc = addCollapsibleHeader(result, optionGroup, options, groupBase, isGroupTab) + + for optionName, option in pairs(options) do + if not optionName:find("^__") then + result[optionGroup .. "." .. optionName] = copyOptionTable(option, groupBase, collapsedFunc); + end + end + end + + return result; +end + +local function fixMetaOrders(allOptions) + -- assumes that the results from create methods are contiguous in __order fields + -- shifts __order fields such that each optionGroup is ordered correctly relative + -- to its peers, but has a unique __order number in the combined option table. + local groupOrders = {} + local maxGroupOrder = 0 + for optionGroup, options in pairs(allOptions) do + local metaOrder = options.__order + groupOrders[metaOrder] = groupOrders[metaOrder] or {} + maxGroupOrder = max(maxGroupOrder, metaOrder) + tinsert(groupOrders[metaOrder], optionGroup) + end + + local index = 0 + local newOrder = 1 + while index <= maxGroupOrder do + index = index + 1 + if groupOrders[index] then + table.sort(groupOrders[index]) + for _, optionGroup in ipairs(groupOrders[index]) do + allOptions[optionGroup].__order = newOrder + newOrder = newOrder + 1 + end + end + end +end + +local function removeFuncs(intable, removeFunc) + for i,v in pairs(intable) do + if(i == "get" or i == "set" or i == "hidden" or i == "disabled") then + intable[i] = nil; + elseif (i == "func" and removeFunc) then + intable[i] = nil + elseif(type(v) == "table" and i ~= "values") then + removeFuncs(v, removeFunc) + end + end +end + +local function getChildOption(options, info) + for i=1,#info do + options = options.args[info[i]]; + if not(options) then + return nil; + end + + if (options.hidden) then + local type = type(options.hidden); + if (type == "bool") then + if (options.hidden) then + return nil; + end + elseif (type == "function") then + if (options.hidden(info)) then + return nil; + end + end + end + + end + return options +end + +local function hiddenChild(childOptionTable, info) + for i=#childOptionTable,0,-1 do + if(childOptionTable[i].hidden ~= nil) then + if(type(childOptionTable[i].hidden) == "boolean") then + return childOptionTable[i].hidden; + elseif(type(childOptionTable[i].hidden) == "function") then + return childOptionTable[i].hidden(info); + end + end + end + return false; +end + +local function CreateHiddenAll(subOption) + return function(data, info) + if(#data.controlledChildren == 0) then + return true; + end + + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + if (childOption) then + if (not hiddenChild(childOptionTable, info)) then + return false; + end + end + end + end + + return true; + end +end + +local function disabledChild(childOptionTable, info) + for i=#childOptionTable,0,-1 do + if(childOptionTable[i].disabled ~= nil) then + if(type(childOptionTable[i].disabled) == "boolean") then + return childOptionTable[i].disabled; + elseif(type(childOptionTable[i].disabled) == "function") then + return childOptionTable[i].disabled(info); + end + end + end + return false; +end + +local function CreateDisabledAll(subOption) + return function(data, info) + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption); + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + if (childOption) then + if (not disabledChild(childOptionTable, info)) then + return false; + end + end + end + end + + return true; + end +end + +local function disabeldOrHiddenChild(childOptionTable, info) + return hiddenChild(childOptionTable, info) or disabledChild(childOptionTable, info); +end + +local function replaceNameDescFuncs(intable, data, subOption) + local function compareTables(tableA, tableB) + if(#tableA == #tableB) then + for j=1,#tableA do + if(type(tableA[j]) == "number" and type(tableB[j]) == "number") then + if((math.floor(tableA[j] * 100) / 100) ~= (math.floor(tableB[j] * 100) / 100)) then + return false; + end + else + if(tableA[j] ~= tableB[j]) then + return false; + end + end + end + else + return false; + end + return true; + end + + local function getValueFor(options, info, key) + local childOptionTable = {[0] = options}; + for i=1,#info do + options = options.args[info[i]]; + if (not options) then + return nil; + end + childOptionTable[i] = options; + end + + if (hiddenChild(childOptionTable, info)) then + return nil; + end + + for i=#childOptionTable,0,-1 do + if(childOptionTable[i][key]) then + return childOptionTable[i][key]; + end + end + return nil; + end + + local function combineKeys(info) + local combinedKeys = nil; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local values = getValueFor(WeakAuras.EnsureOptions(childData, subOption), info, "values"); + if (values) then + if (type(values) == "function") then + values = values(info); + end + if (type(values) == "table") then + combinedKeys = combinedKeys or {}; + for k, v in pairs(values) do + combinedKeys[k] = v; + end + end + end + end + end + return combinedKeys; + end + + local function regionPrefix(input) + local index = string.find(input, ".", 1, true); + if (index) then + local regionType = string.sub(input, 1, index - 1); + return regionOptions[regionType] and regionType; + end + return nil; + end + + local function sameAll(info) + local combinedValues = {}; + local first = true; + local combinedKeys = combineKeys(info); + + local isToggle = nil + + for index, childId in ipairs(data.controlledChildren) do + if isToggle == nil then + local childData = WeakAuras.GetData(childId) + local childOption = getChildOption(WeakAuras.EnsureOptions(childData, subOption), info) + isToggle = childOption and childOption.type == "toggle" + end + + local childData = WeakAuras.GetData(childId); + + local regionType = regionPrefix(info[#info]); + if(childData and (not regionType or childData.regionType == regionType or regionType == "sub")) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local get = getValueFor(childOptions, info, "get"); + if (combinedKeys) then + for key, _ in pairs(combinedKeys) do + local values = {}; + if (get) then + values = { get(info, key) }; + end + if (combinedValues[key] == nil) then + combinedValues[key] = values; + else + if (not compareTables(combinedValues[key], values)) then + return nil; + end + end + end + else + local values = {}; + if (get) then + values = { get(info) }; + local childOption = getChildOption(childOptions, info) + if isToggle and values[1] == nil then + values[1] = false + end + end + if(first) then + combinedValues = values; + first = false; + else + if (not compareTables(combinedValues, values)) then + return nil; + end + end + end + end + end + + return true; + end + + local function nameAll(info) + local combinedName; + local first = true; + local foundNames = {}; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOption = getChildOption(WeakAuras.EnsureOptions(childData, subOption), info); + if (childOption) then + local name; + if(type(childOption.name) == "function") then + name = childOption.name(info); + else + name = childOption.name; + end + if (not name) then + -- Do nothing + elseif(first) then + if (combinedName ~= "") then + combinedName = name; + first = false; + end + foundNames[name] = true; + elseif not(foundNames[name]) then + if (name ~= "") then + if (childOption.type == "description") then + combinedName = combinedName .. "\n\n" .. name; + else + combinedName = combinedName .. " / " .. name; + end + end + foundNames[name] = true; + end + end + end + end + + return combinedName; + end + + local function descAll(info) + local combinedDesc; + local first = true; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOption = getChildOption(WeakAuras.EnsureOptions(childData, subOption), info); + if (childOption) then + local desc; + if(type(childOption.desc) == "function") then + desc = childOption.desc(info); + else + desc = childOption.desc; + end + if(first) then + combinedDesc = desc; + first = false; + elseif not(combinedDesc == desc) then + return L["Not all children have the same value for this option"]; + end + end + end + end + return combinedDesc; + end + + local function recurse(intable) + for i,v in pairs(intable) do + if(i == "name" and type(v) ~= "table") then + intable.name = function(info) + local name = nameAll(info); + if(sameAll(info)) then + return name; + else + if(name == "") then + return name; + else + return "|cFF4080FF"..(name or "error"); + end + end + end + intable.desc = function(info) + if(sameAll(info)) then + return descAll(info); + else + local combinedKeys = nil; + if (intable.type == "multiselect") then + combinedKeys = combineKeys(info) + end + + local values = {}; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + if (childOption and not hiddenChild(childOptionTable, info)) then + for i=#childOptionTable,0,-1 do + if(childOptionTable[i].get) then + if(intable.type == "toggle") then + local name, tri; + if(type(childOption.name) == "function") then + name = childOption.name(info); + tri = true; + else + name = childOption.name; + end + if(tri and childOptionTable[i].get(info)) then + tinsert(values, "|cFFE0E000"..childId..": |r"..name); + elseif(tri) then + tinsert(values, "|cFFE0E000"..childId..": |r"..L["Ignored"]); + elseif(childOptionTable[i].get(info)) then + tinsert(values, "|cFFE0E000"..childId..": |r|cFF00FF00"..L["Enabled"]); + else + tinsert(values, "|cFFE0E000"..childId..": |r|cFFFF0000"..L["Disabled"]); + end + elseif(intable.type == "color") then + local r, g, b = childOptionTable[i].get(info); + r, g, b = r or 1, g or 1, b or 1; + tinsert(values, ("|cFF%2x%2x%2x%s"):format(r * 220 + 35, g * 220 + 35, b * 220 + 35, childId)); + elseif(intable.type == "select") then + local selectValues = type(intable.values) == "table" and intable.values or intable.values(info); + local key = childOptionTable[i].get(info); + local display = key and selectValues[key] or L["None"]; + if intable.dialogControl == "LSM30_Font" then + tinsert(values, "|cFFE0E000"..childId..": |r" .. key); + else + tinsert(values, "|cFFE0E000"..childId..": |r"..display); + end + elseif(intable.type == "multiselect") then + local selectedValues = {}; + for k, v in pairs(combinedKeys) do + if (childOptionTable[i].get(info, k)) then + tinsert(selectedValues, tostring(v)) + end + end + tinsert(values, "|cFFE0E000"..childId..": |r"..table.concat(selectedValues, ",")); + else + local display = childOptionTable[i].get(info) or L["None"]; + if(type(display) == "number") then + display = math.floor(display * 100) / 100; + else + if #display > 50 then + display = display:sub(1, 50) .. "..." + end + end + tinsert(values, "|cFFE0E000"..childId..": |r"..display); + end + break; + end + end + end + end + end + return table.concat(values, "\n"); + end + end + elseif(type(v) == "table" and i ~= "values") then + recurse(v); + end + end + end + recurse(intable); +end + +local function replaceImageFuncs(intable, data, subOption) + local function imageAll(info) + local combinedImage = {}; + local first = true; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOption = WeakAuras.EnsureOptions(childData, subOption) + if not(childOption) then + return "error" + end + childOption = getChildOption(childOption, info); + if childOption and childOption.image then + local image = {childOption.image(info)}; + if(first) then + combinedImage = image; + first = false; + else + if not(combinedImage[1] == image[1]) then + return "", 0, 0; + end + end + end + end + end + + return unpack(combinedImage); + end + + local function recurse(intable) + for i,v in pairs(intable) do + if(i == "image" and type(v) == "function") then + intable[i] = imageAll; + elseif(type(v) == "table" and i ~= "values") then + recurse(v); + end + end + end + recurse(intable); +end + +local function replaceValuesFuncs(intable, data, subOption) + local function valuesAll(info) + local combinedValues = {}; + local handledValues = {}; + local first = true; + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOption = WeakAuras.EnsureOptions(childData, subOption) + if not(childOption) then + return "error" + end + + childOption = getChildOption(childOption, info); + if (childOption) then + local values = childOption.values; + if (type(values) == "function") then + values = values(info); + end + if(first) then + for k, v in pairs(values) do + handledValues[k] = handledValues[k] or {}; + handledValues[k][v] = true; + combinedValues[k] = v; + end + first = false; + else + for k, v in pairs(values) do + if (handledValues[k] and handledValues[k][v]) then + -- Already known key/value pair + else + if (combinedValues[k]) then + combinedValues[k] = combinedValues[k] .. "/" .. v; + else + combinedValues[k] = v; + end + handledValues[k] = handledValues[k] or {}; + handledValues[k][v] = true; + end + end + end + end + end + end + + return combinedValues; + end + + local function recurse(intable) + for i,v in pairs(intable) do + if(i == "values" and type(v) == "function") then + intable[i] = valuesAll; + elseif(type(v) == "table" and i ~= "values") then + recurse(v); + end + end + end + recurse(intable); +end + +local function CreateGetAll(subOption) + return function(data, info, ...) + local combinedValues = {}; + local first = true; + local debug = false; + local isToggle = nil + for index, childId in ipairs(data.controlledChildren) do + if isToggle == nil then + local childData = WeakAuras.GetData(childId) + local childOptions = getChildOption(WeakAuras.EnsureOptions(childData, subOption), info) + isToggle = childOptions and childOptions.type == "toggle" + end + + local childData = WeakAuras.GetData(childId); + + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + + if (childOption and not hiddenChild(childOptionTable, info)) then + for i=#childOptionTable,0,-1 do + if(childOptionTable[i].get) then + local values = {childOptionTable[i].get(info, ...)}; + if isToggle and values[1] == nil then + values[1] = false + end + if(first) then + combinedValues = values; + first = false; + else + local same = true; + if(#combinedValues == #values) then + for j=1,#combinedValues do + if(type(combinedValues[j]) == "number" and type(values[j]) == "number") then + if((math.floor(combinedValues[j] * 100) / 100) ~= (math.floor(values[j] * 100) / 100)) then + same = false; + break; + end + else + if(combinedValues[j] ~= values[j]) then + same = false; + break; + end + end + end + else + same = false; + end + if not(same) then + return nil; + end + end + break; + end + end + end + end + end + return unpack(combinedValues); + end +end + +local function CreateSetAll(subOption, getAll) + return function(data, info, ...) + WeakAuras.pauseOptionsProcessing(true); + WeakAuras.PauseAllDynamicGroups() + local before = getAll(data, info, ...) + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + + if (childOption and not disabeldOrHiddenChild(childOptionTable, info)) then + for i=#childOptionTable,0,-1 do + if(childOptionTable[i].set) then + if (childOptionTable[i].type == "multiselect") then + childOptionTable[i].set(info, ..., not before); + else + childOptionTable[i].set(info, ...); + end + break; + end + end + end + end + end + + WeakAuras.ResumeAllDynamicGroups() + WeakAuras.pauseOptionsProcessing(false); + WeakAuras.ScanForLoads(); + WeakAuras.SortDisplayButtons(); + WeakAuras.UpdateOptions() + end +end + +local function CreateExecuteAll(subOption) + return function(data, info, button) + local secondCall = nil + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if(childData) then + local childOptions = WeakAuras.EnsureOptions(childData, subOption) + local childOption = childOptions; + local childOptionTable = {[0] = childOption}; + for i=1,#info do + childOption = childOption.args[info[i]]; + childOptionTable[i] = childOption; + end + + if (childOption and not disabeldOrHiddenChild(childOptionTable, info)) then + -- Some functions, that is the expand/collapse functions need to be + -- effectively called only once. Passing in the secondCall parameter allows + -- them to distinguish between the first and every other call + childOption.func(info, button, secondCall) + secondCall = true + end + end + end + WeakAuras.ClearAndUpdateOptions(data.id) + end +end + +local function PositionOptions(id, data, _, hideWidthHeight, disableSelfPoint) + local metaOrder = 99 + local function IsParentDynamicGroup() + if data.parent then + local parentData = WeakAuras.GetData(data.parent) + return parentData and parentData.regionType == "dynamicgroup" + end + end + + local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20; + local positionOptions = { + __title = L["Position Settings"], + __order = metaOrder, + width = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Width"], + order = 60, + min = 1, + softMax = screenWidth, + bigStep = 1, + hidden = hideWidthHeight, + }, + height = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Height"], + order = 61, + min = 1, + softMax = screenHeight, + bigStep = 1, + hidden = hideWidthHeight, + }, + xOffset = { + type = "range", + width = WeakAuras.normalWidth, + name = L["X Offset"], + order = 62, + softMin = (-1 * screenWidth), + softMax = screenWidth, + bigStep = 10, + get = function() return data.xOffset end, + set = function(info, v) + data.xOffset = v; + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + if(data.parent) then + local parentData = WeakAuras.GetData(data.parent); + if(parentData) then + WeakAuras.Add(parentData); + end + end + end + }, + yOffset = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Y Offset"], + order = 63, + softMin = (-1 * screenHeight), + softMax = screenHeight, + bigStep = 10, + get = function() return data.yOffset end, + set = function(info, v) + data.yOffset = v; + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + if(data.parent) then + local parentData = WeakAuras.GetData(data.parent); + if(parentData) then + WeakAuras.Add(parentData); + end + end + end + }, + selfPoint = { + type = "select", + width = WeakAuras.normalWidth, + name = L["Anchor"], + order = 70, + hidden = IsParentDynamicGroup, + values = point_types, + disabled = disableSelfPoint, + }, + anchorFrameType = { + type = "select", + width = WeakAuras.normalWidth, + name = L["Anchored To"], + order = 72, + hidden = IsParentDynamicGroup, + values = (data.regionType == "group" or data.regionType == "dynamicgroup") and WeakAuras.anchor_frame_types_group or WeakAuras.anchor_frame_types, + }, + -- Input field to select frame to anchor on + anchorFrameFrame = { + type = "input", + width = WeakAuras.normalWidth, + name = L["Frame"], + order = 72.2, + hidden = function() + if (IsParentDynamicGroup()) then + return true; + end + return not (data.anchorFrameType == "SELECTFRAME") + end + }, + -- Button to select frame to anchor on + chooseAnchorFrameFrame = { + type = "execute", + width = WeakAuras.normalWidth, + name = L["Choose"], + order = 72.4, + hidden = function() + if (IsParentDynamicGroup()) then + return true; + end + return not (data.anchorFrameType == "SELECTFRAME") + end, + func = function() + WeakAuras.StartFrameChooser(data, {"anchorFrameFrame"}); + end + }, + anchorPoint = { + type = "select", + width = WeakAuras.normalWidth, + name = function() + if (data.anchorFrameType == "SCREEN") then + return L["To Screen's"] + elseif (data.anchorFrameType == "PRD") then + return L["To Personal Ressource Display's"]; + else + return L["To Frame's"]; + end + end, + order = 75, + hidden = function() + if (data.parent) then + --if (IsParentDynamicGroup()) then + -- return true; + --end + return data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE"; + else + return data.anchorFrameType == "MOUSE"; + end + end, + values = point_types + }, + anchorPointGroup = { + type = "select", + width = WeakAuras.normalWidth, + name = L["To Group's"], + order = 76, + hidden = function() + if (data.anchorFrameType ~= "SCREEN") then + return true; + end + if (data.parent) then + return IsParentDynamicGroup(); + end + return true; + end, + disabled = true, + values = {["CENTER"] = L["Anchor Point"]}, + get = function() return "CENTER"; end + }, + anchorFrameParent = { + type = "toggle", + width = WeakAuras.normalWidth, + name = L["Set Parent to Anchor"], + desc = L["Sets the anchored frame as the aura's parent, causing the aura to inherit attributes such as visibility and scale."], + order = 77, + get = function() + return data.anchorFrameParent or data.anchorFrameParent == nil; + end, + hidden = function() + return (data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE" or IsParentDynamicGroup()); + end, + }, + frameStrata = { + type = "select", + width = WeakAuras.normalWidth, + name = L["Frame Strata"], + order = 78, + values = WeakAuras.frame_strata_types + }, + anchorFrameSpace = { + type = "execute", + width = WeakAuras.normalWidth, + name = "", + order = 79, + image = function() return "", 0, 0 end, + hidden = function() + return not (data.anchorFrameType ~= "SCREEN" or IsParentDynamicGroup()); + end + }, + }; + WeakAuras.commonOptions.AddCodeOption(positionOptions, data, L["Custom Anchor"], "custom_anchor", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-anchor-function", + 72.1, function() return not(data.anchorFrameType == "CUSTOM" and not IsParentDynamicGroup()) end, {"customAnchor"}, nil, nil, nil, nil, nil, true) + return positionOptions; +end + +local function BorderOptions(id, data, showBackDropOptions, hiddenFunc, order) + local borderOptions = { + borderHeader = { + type = "header", + order = order, + name = L["Border Settings"], + hidden = hiddenFunc, + }, + border = { + type = "toggle", + width = WeakAuras.doubleWidth, + name = L["Show Border"], + order = order + 0.1, + hidden = hiddenFunc, + }, + borderEdge = { + type = "select", + width = WeakAuras.normalWidth, + dialogControl = "LSM30_Border", + name = L["Border Style"], + order = order + 0.2, + values = AceGUIWidgetLSMlists.border, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + borderBackdrop = { + type = "select", + width = WeakAuras.normalWidth, + dialogControl = "LSM30_Background", + name = L["Backdrop Style"], + order = order + 0.3, + values = AceGUIWidgetLSMlists.background, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + borderOffset = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Border Offset"], + order = order + 0.3, + softMin = 0, + softMax = 32, + bigStep = 1, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + borderSize = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Border Size"], + order = order + 0.4, + softMin = 1, + softMax = 64, + bigStep = 1, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + borderInset = { + type = "range", + width = WeakAuras.normalWidth, + name = L["Border Inset"], + order = order + 0.5, + softMin = 1, + softMax = 32, + bigStep = 1, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + border_spacer = { + type = "description", + name = "", + width = WeakAuras.normalWidth, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + order = order + 0.6 + }, + borderColor = { + type = "color", + width = WeakAuras.normalWidth, + name = L["Border Color"], + hasAlpha = true, + order = order + 0.7, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + borderInFront = { + type = "toggle", + width = WeakAuras.normalWidth, + name = L["Border in Front"], + order = order + 0.8, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border or not showBackDropOptions end, + }, + backdropColor = { + type = "color", + width = WeakAuras.normalWidth, + name = L["Backdrop Color"], + hasAlpha = true, + order = order + 0.9, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, + }, + backdropInFront = { + type = "toggle", + width = WeakAuras.normalWidth, + name = L["Backdrop in Front"], + order = order + 1, + hidden = function() return hiddenFunc and hiddenFunc() or not data.border or not showBackDropOptions end, + }, + } + + return borderOptions; +end + +local function GetCustomCode(data, path) + for _, key in ipairs(path) do + if (not data or not data[key]) then + return nil; + end + data = data[key]; + end + return data; +end + +-- TODO: find a paradigm which doesn't have five million flags for AddCodeOption so that calls to it don't always go off the screen +-- a table of settings is the obvious option to pack the flags. +-- alternatively, we could create a "code" type option which then gets processed before sending to AceConfig +local function AddCodeOption(args, data, name, prefix, url, order, hiddenFunc, path, encloseInFunction, multipath, extraSetFunction, extraFunctions, reloadOptions, setOnParent) + extraFunctions = extraFunctions or {}; + tinsert(extraFunctions, 1, { + buttonLabel = L["Expand"], + func = function() + WeakAuras.OpenTextEditor(data, path, encloseInFunction, multipath, reloadOptions, setOnParent, url) + end + }); + + args[prefix .. "_custom"] = { + type = "input", + width = WeakAuras.doubleWidth, + name = name, + order = order, + multiline = true, + hidden = hiddenFunc, + control = "WeakAurasMultiLineEditBox", + arg = { + extraFunctions = extraFunctions, + }, + set = function(info, v) + local subdata = data; + for i = 1, #path -1 do + local key = path[i]; + subdata[key] = subdata[key] or {}; + subdata = subdata[key]; + end + + subdata[path[#path]] = v; + WeakAuras.Add(data); + if (extraSetFunction) then + extraSetFunction(); + end + if (reloadOptions) then + WeakAuras.ClearOptions(data.id) + end + end, + get = function(info) + return GetCustomCode(data, path); + end + }; + + args[prefix .. "_customError"] = { + type = "description", + name = function() + if hiddenFunc() then + return ""; + end + + local code = GetCustomCode(data, path); + + if (not code) then + return "" + end + + if (encloseInFunction) then + code = "function() "..code.."\n end"; + end + + code = "return " .. code; + + local _, errorString = loadstring(code); + return errorString and "|cFFFF0000"..errorString or ""; + end, + width = WeakAuras.doubleWidth, + order = order + 0.002, + hidden = function() + if (hiddenFunc()) then + return true; + end + + local code = GetCustomCode(data, path); + if (not code) then + return true; + end + + if (encloseInFunction) then + code = "function() "..code.."\n end"; + end + + code = "return " .. code; + + local loadedFunction, errorString = loadstring(code); + if(errorString and not loadedFunction) then + return false; + else + return true; + end + end + }; +end + +local function AddCommonTriggerOptions(options, data, triggernum) + local trigger= data.triggers[triggernum].trigger + + local trigger_types = {}; + for type, triggerSystem in pairs(WeakAuras.triggerTypes) do + trigger_types[type] = triggerSystem.GetName(type); + end + + options.typedesc = { + type = "description", + width = WeakAuras.normalWidth, + name = L["Type"], + order = 1, + disabled = true, + get = function() return true end + } + options.type = { + type = "select", + width = WeakAuras.normalWidth, + name = L["Type"], + desc = L["The type of trigger"], + order = 1.1, + values = trigger_types, + get = function(info) + return trigger.type + end, + set = function(info, v) + trigger.type = v; + if(trigger.event) then + local prototype = WeakAuras.event_prototypes[trigger.event]; + if(prototype) then + if(v == "status" and prototype.type == "event") then + trigger.event = "Cooldown Progress (Spell)" + elseif(v == "event" and prototype.type == "status") then + trigger.event = "Combat Log" + end + end + end + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.ClearAndUpdateOptions(data.id); + end + } +end + +-- Adds setters/getters to trigger options +-- This is used by both aura triggers +local function AddTriggerGetterSetter(options, data, triggernum) + local trigger = data.triggers[triggernum].trigger + for key, option in pairs(options) do + if type(option) == "table" and not option.get then + if option.type == "multiselect" then + option.get = function(info, index) + return trigger[key] and trigger[key][index] + end + else + option.get = function(info) + return trigger[key] + end + end + end + if type(option) == "table" and not option.set then + if option.type == "multiselect" then + option.set = function(info, index, value) + if type(trigger[key]) ~= "table" then + trigger[key] = {} + end + if value ~= nil then + if value then + trigger[key][index] = true + else + trigger[key][index] = nil + end + else + if trigger[key][index] then + trigger[key][index] = nil + else + trigger[key][index] = true + end + end + if next(trigger[key]) == nil then + trigger[key] = nil + end + + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + else + option.set = function(info, v) + trigger[key] = v + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + end + end + end +end + + +WeakAuras.commonOptions = {} +WeakAuras.commonOptions.parsePrefix = parsePrefix +WeakAuras.commonOptions.flattenRegionOptions = flattenRegionOptions +WeakAuras.commonOptions.fixMetaOrders = fixMetaOrders +WeakAuras.commonOptions.removeFuncs = removeFuncs +WeakAuras.commonOptions.CreateHiddenAll = CreateHiddenAll +WeakAuras.commonOptions.CreateDisabledAll = CreateDisabledAll +WeakAuras.commonOptions.replaceNameDescFuncs = replaceNameDescFuncs +WeakAuras.commonOptions.replaceImageFuncs = replaceImageFuncs +WeakAuras.commonOptions.replaceValuesFuncs = replaceValuesFuncs +WeakAuras.commonOptions.CreateGetAll = CreateGetAll +WeakAuras.commonOptions.CreateSetAll = CreateSetAll +WeakAuras.commonOptions.CreateExecuteAll = CreateExecuteAll + +WeakAuras.commonOptions.PositionOptions = PositionOptions +WeakAuras.commonOptions.BorderOptions = BorderOptions +WeakAuras.commonOptions.AddCodeOption = AddCodeOption + +WeakAuras.commonOptions.AddCommonTriggerOptions = AddCommonTriggerOptions +WeakAuras.commonOptions.AddTriggerGetterSetter = AddTriggerGetterSetter diff --git a/WeakAurasOptions/ConditionOptions.lua b/WeakAurasOptions/ConditionOptions.lua index 2221ac1..ffbb00b 100644 --- a/WeakAurasOptions/ConditionOptions.lua +++ b/WeakAurasOptions/ConditionOptions.lua @@ -257,7 +257,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; elseif (property == "DELETE") then if (data.controlledChildren) then @@ -267,11 +267,11 @@ local function addControlsForChange(args, order, data, conditionVariable, condit tremove(auraData[conditionVariable][conditionIndex].changes, reference.changeIndex); WeakAuras.Add(auraData); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else tremove(conditions[i].changes, j); WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end return; end @@ -286,12 +286,12 @@ local function addControlsForChange(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end conditions[i].changes[j].property = property; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else conditions[i].changes[j].property = property; conditions[i].changes[j].value = default; WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end } @@ -310,7 +310,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end conditions[i].changes[j].value = v; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end setValueColor = function(info, r, g, b, a) for id, reference in pairs(conditions[i].changes[j].references) do @@ -328,7 +328,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit conditions[i].changes[j].value[2] = g; conditions[i].changes[j].value[3] = b; conditions[i].changes[j].value[4] = a; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end setValueComplex = function(property, reloadOptions) @@ -346,10 +346,9 @@ local function addControlsForChange(args, order, data, conditionVariable, condit conditions[i].changes[j].value = {}; end conditions[i].changes[j].value[property] = v; + if reloadOptions then - WeakAuras.ReloadOptions2(data.id, data) - else - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id) end end end @@ -381,7 +380,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit conditions[i].changes[j].value[property][2] = g; conditions[i].changes[j].value[property][3] = b; conditions[i].changes[j].value[property][4] = a; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end else @@ -406,7 +405,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit conditions[i].changes[j].value[property] = v; WeakAuras.Add(data); if reloadOptions then - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) end end end @@ -696,6 +695,7 @@ local function addControlsForChange(args, order, data, conditionVariable, condit } order = order + 1; + local formatGet = function(key) return type(conditions[i].changes[j].value) == "table" and conditions[i].changes[j].value["message_format_" .. key] end @@ -713,8 +713,10 @@ local function addControlsForChange(args, order, data, conditionVariable, condit return type(conditions[i].changes[j].value) == "table" and conditions[i].changes[j].value["message_format_" .. key]; end local originalName = option.name - option.name = blueIfNoValue2(data, conditions[i].changes[j], "value", "message_format_" .. key, originalName, originalName) - option.desc = descIfNoValue2(data, conditions[i].changes[j], "value", "message_format_" .. key, nil, option.values) + if option.type ~= "header" then + option.name = blueIfNoValue2(data, conditions[i].changes[j], "value", "message_format_" .. key, originalName, originalName) + option.desc = descIfNoValue2(data, conditions[i].changes[j], "value", "message_format_" .. key, nil, option.values) + end option.set = setValueComplex("message_format_" .. key, option.reloadOptions) option.reloadOptions = nil @@ -722,14 +724,24 @@ local function addControlsForChange(args, order, data, conditionVariable, condit args[fullKey] = option end + local hasTextFormatOption if data.controlledChildren then for id, reference in pairs(conditions[i].changes[j].references) do local input = reference.value and reference.value.message - WeakAuras.AddTextFormatOption(input, false, formatGet, addOption) + hasTextFormatOption = WeakAuras.AddTextFormatOption(input, true, formatGet, addOption) end else local input = type(conditions[i].changes[j].value) == "table" and conditions[i].changes[j].value["message"] - WeakAuras.AddTextFormatOption(input, false, formatGet, addOption) + hasTextFormatOption = WeakAuras.AddTextFormatOption(input, true, formatGet, addOption) + end + + if hasTextFormatOption then + local footerOption = { + type = "header", + name = "", + width = WeakAuras.doubleWidth + } + addOption("footer", footerOption) end local function customHidden() @@ -1355,7 +1367,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; end @@ -1368,7 +1380,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit else removeSubCheck(conditions[i].check, path); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; end @@ -1387,7 +1399,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit childCheck.value = nil; WeakAuras.Add(auraData); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else local oldType; check = getOrCreateSubCheck(conditions[i].check, path); @@ -1403,7 +1415,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit check.value = nil; end WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end, get = function() @@ -1454,7 +1466,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end check.op = v; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end setValue = function(info, v) check = getOrCreateSubCheck(conditions[i].check, path); @@ -1465,7 +1477,7 @@ local function addControlsForIfLine(args, order, data, conditionVariable, condit WeakAuras.Add(auraData); end check.value = v; - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end else setOp = function(info, v) @@ -1667,7 +1679,7 @@ local function addControlsForCondition(args, order, data, conditionVariable, con else WeakAuras.SetCollapsed(data.id, "condition", i, not collapsed); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end, image = collapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\expand" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\collapse" , imageWidth = 18, @@ -1705,14 +1717,14 @@ local function addControlsForCondition(args, order, data, conditionVariable, con WeakAuras.Add(auraData); end end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else if (i > 1) then local tmp = conditions[i]; tremove(conditions, i); tinsert(conditions, i - 1, tmp); WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end end, @@ -1754,7 +1766,7 @@ local function addControlsForCondition(args, order, data, conditionVariable, con WeakAuras.Add(auraData); end end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; else if (i < #conditions) then @@ -1762,7 +1774,7 @@ local function addControlsForCondition(args, order, data, conditionVariable, con tremove(conditions, i); tinsert(conditions, i + 1, tmp); WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; end end @@ -1786,12 +1798,12 @@ local function addControlsForCondition(args, order, data, conditionVariable, con tremove(auraData[conditionVariable], reference.conditionIndex); WeakAuras.Add(auraData); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; else tremove(conditions, i); WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) return; end end, @@ -1836,12 +1848,12 @@ local function addControlsForCondition(args, order, data, conditionVariable, con tinsert(auradata[conditionVariable][reference.conditionIndex].changes, {}) WeakAuras.Add(auradata); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else conditions[i].changes = conditions[i].changes or {}; conditions[i].changes[#conditions[i].changes + 1] = {}; WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end } @@ -2313,7 +2325,19 @@ local function mergeConditions(all, aura, id, allConditionTemplates, propertyTyp end end -function WeakAuras.GetConditionOptions(data, args, conditionVariable, startorder, category) +function WeakAuras.GetConditionOptions(data) + local options = { + type = "group", + name = L["Conditions"], + order = 25, + args = {} + } + + local args = options.args + + local conditionVariable = "conditions" + local startorder = 0 + local category = nil -- Build potential Conditions Templates structure local conditionTemplates, conditionTemplateWithoutCombinations = createConditionTemplates(data); @@ -2357,7 +2381,7 @@ function WeakAuras.GetConditionOptions(data, args, conditionVariable, startorder WeakAuras.SetCollapsed(id, "condition", #aura[conditionVariable], false); WeakAuras.Add(aura); end - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) else conditions[#conditions + 1] = {}; conditions[#conditions].check = {}; @@ -2366,11 +2390,11 @@ function WeakAuras.GetConditionOptions(data, args, conditionVariable, startorder conditions[#conditions].category = category; WeakAuras.SetCollapsed(data.id, "condition", #conditions, false); WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id, true) end end } order = order + 1; - return args; + return options; end diff --git a/WeakAurasOptions/DisplayOptions.lua b/WeakAurasOptions/DisplayOptions.lua new file mode 100644 index 0000000..283a77d --- /dev/null +++ b/WeakAurasOptions/DisplayOptions.lua @@ -0,0 +1,303 @@ +local L = WeakAuras.L +local regionOptions = WeakAuras.regionOptions + +local flattenRegionOptions = WeakAuras.commonOptions.flattenRegionOptions +local fixMetaOrders = WeakAuras.commonOptions.fixMetaOrders +local parsePrefix = WeakAuras.commonOptions.parsePrefix +local removeFuncs = WeakAuras.commonOptions.removeFuncs +local replaceNameDescFuncs = WeakAuras.commonOptions.replaceNameDescFuncs +local replaceImageFuncs = WeakAuras.commonOptions.replaceImageFuncs +local replaceValuesFuncs = WeakAuras.commonOptions.replaceValuesFuncs +local disabledAll = WeakAuras.commonOptions.CreateDisabledAll("region") +local hiddenAll = WeakAuras.commonOptions.CreateHiddenAll("region") +local getAll = WeakAuras.commonOptions.CreateGetAll("region") +local setAll = WeakAuras.commonOptions.CreateSetAll("region", getAll) + +local function AddSubRegionImpl(data, subRegionName) + data.subRegions = data.subRegions or {} + if WeakAuras.subRegionTypes[subRegionName] and WeakAuras.subRegionTypes[subRegionName] then + if WeakAuras.subRegionTypes[subRegionName].supports(data.regionType) then + local default = WeakAuras.subRegionTypes[subRegionName].default + local subRegionData = type(default) == "function" and default(data.regionType) or CopyTable(default) + subRegionData.type = subRegionName + tinsert(data.subRegions, subRegionData) + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + end +end + +local function AddSubRegion(data, subRegionName) + if (WeakAuras.ApplyToDataOrChildData(data, AddSubRegionImpl, subRegionName)) then + WeakAuras.ClearAndUpdateOptions(data.id) + end +end + +local function AddOptionsForSupportedSubRegion(regionOption, data, supported) + if not next(supported) then + return + end + local hasSubRegions = false + + local result = {} + local order = 1 + result.__order = 300 + result.__title = L["Add Extra Elements"] + result.__topLine = true + for subRegionType in pairs(supported) do + if WeakAuras.subRegionTypes[subRegionType].supportsAdd then + hasSubRegions = true + result[subRegionType .. "space"] = { + type = "description", + width = WeakAuras.doubleWidth, + name = "", + order = order, + } + order = order + 1 + result[subRegionType] = { + type = "execute", + width = WeakAuras.normalWidth, + name = string.format(L["Add %s"], WeakAuras.subRegionTypes[subRegionType].displayName), + order = order, + func = function() + AddSubRegion(data, subRegionType) + end, + } + order = order + 1 + end + end + regionOption["sub"] = result; + return hasSubRegions +end + +local function union(table1, table2) + local meta = {}; + for i,v in pairs(table1) do + meta[i] = v; + end + for i,v in pairs(table2) do + meta[i] = v; + end + return meta; +end + +function WeakAuras.GetDisplayOptions(data) + local id = data.id + + if not data.controlledChildren then + local regionOption; + local commonOption = {}; + + local hasSubElements = false + + if(regionOptions[data.regionType]) then + regionOption = regionOptions[data.regionType].create(id, data); + + if data.subRegions then + local subIndex = {} + for index, subRegionData in ipairs(data.subRegions) do + local subRegionType = subRegionData.type + if WeakAuras.subRegionOptions[subRegionType] then + hasSubElements = true + subIndex[subRegionType] = subIndex[subRegionType] and subIndex[subRegionType] + 1 or 1 + local options, common = WeakAuras.subRegionOptions[subRegionType].create(data, subRegionData, index, subIndex[subRegionType]) + options.__order = 200 + index + regionOption["sub." .. index .. "." .. subRegionType] = options + commonOption[subRegionType] = common + end + end + end + + local commonOptionIndex = 0 + for option, optionData in pairs(commonOption) do + commonOptionIndex = commonOptionIndex + 1 + optionData.__order = 100 + commonOptionIndex + regionOption[option] = optionData + end + + local supported = {} + for subRegionName, subRegionType in pairs(WeakAuras.subRegionTypes) do + if subRegionType.supports(data.regionType) then + supported[subRegionName] = true + end + end + hasSubElements = AddOptionsForSupportedSubRegion(regionOption, data, supported) or hasSubElements + else + regionOption = { + [data.regionType] = { + __title = "|cFFFFFF00" .. data.regionType, + __order = 1, + unsupported = { + type = "description", + name = L["This region of type \"%s\" is not supported."]:format(data.regionType), + order = 2, + } + } + }; + end + + if hasSubElements then + regionOption["SubElementsHeader"] = { + __order = 100, + __noHeader = true, + header = { + type = "header", + name = L["Sub Elements"], + order = 1 + } + } + end + + local options = flattenRegionOptions(regionOption, true) + + local region = { + type = "group", + name = L["Display"], + order = 10, + get = function(info) + local base, property = parsePrefix(info[#info], data); + if not base then + return nil + end + if(info.type == "color") then + base[property] = base[property] or {}; + local c = base[property]; + return c[1], c[2], c[3], c[4]; + else + return base[property]; + end + end, + set = function(info, v, g, b, a) + local base, property = parsePrefix(info[#info], data, true); + if(info.type == "color") then + base[property] = base[property] or {}; + local c = base[property]; + c[1], c[2], c[3], c[4] = v, g, b, a; + elseif(info.type == "toggle") then + base[property] = v; + else + base[property] = (v ~= "" and v) or nil; + end + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + if(data.parent) then + local parentData = WeakAuras.GetData(data.parent); + if(parentData) then + WeakAuras.Add(parentData); + end + end + WeakAuras.ResetMoverSizer(); + end, + args = options + }; + return region + else + -- Multiple Auras + -- We call the create functions of the relevant region types with + -- the parentData once per region type + -- For sub regions, the relevant create function is called with the parentData + -- once per index/sub region type + local handledRegionTypes = {} + local handledSubRegionTypes = {} + + local allOptions = {}; + local commonOption = {}; + local unsupportedCount = 0 + local supportedSubRegions = {} + local hasSubElements = false + + for index, childId in ipairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId); + if childData and not handledRegionTypes[childData.regionType] then + handledRegionTypes[childData.regionType] = true; + if regionOptions[childData.regionType] then + allOptions = union(allOptions, regionOptions[childData.regionType].create(id, data)); + else + unsupportedCount = unsupportedCount + 1 + allOptions["__unsupported" .. unsupportedCount] = { + __title = "|cFFFFFF00" .. childData.regionType, + __order = 1, + warning = { + type = "description", + name = L["Regions of type \"%s\" are not supported."]:format(childData.regionType), + order = 1 + }, + } + end + for subRegionName, subRegionType in pairs(WeakAuras.subRegionTypes) do + if subRegionType.supports(childData.regionType) then + supportedSubRegions[subRegionName] = true + end + end + end + if childData.subRegions then + local subIndex = {} + for index, subRegionData in ipairs(childData.subRegions) do + local subRegionType = subRegionData.type + local alreadyHandled = handledSubRegionTypes[index] and handledSubRegionTypes[index][subRegionType] + if WeakAuras.subRegionOptions[subRegionType] and not alreadyHandled then + handledSubRegionTypes[index] = handledSubRegionTypes[index] or {} + handledSubRegionTypes[index][subRegionType] = true + hasSubElements = true + subIndex[subRegionType] = subIndex[subRegionType] and subIndex[subRegionType] + 1 or 1 + + local options, common = WeakAuras.subRegionOptions[subRegionType].create(data, nil, index, subIndex[subRegionType]) + options.__order = 200 + index + + allOptions["sub." .. index .. "." .. subRegionType] = options + commonOption[subRegionType] = common + end + end + end + end + + local commonOptionIndex = 0 + for option, optionData in pairs(commonOption) do + commonOptionIndex = commonOptionIndex + 1 + optionData.__order = 100 + commonOptionIndex + allOptions[option] = optionData + end + + hasSubElements = AddOptionsForSupportedSubRegion(allOptions, data, supportedSubRegions) or hasSubElements + + if hasSubElements then + allOptions["SubElementsHeader"] = { + __order = 100, + __noHeader = true, + header = { + order = 1, + type = "header", + name = L["Sub Elements"], + } + } + end + + fixMetaOrders(allOptions); + + local region = { + type = "group", + name = L["Display"], + order = 10, + args = flattenRegionOptions(allOptions, false); + }; + + removeFuncs(region); + replaceNameDescFuncs(region, data, "region"); + replaceImageFuncs(region, data, "region"); + replaceValuesFuncs(region, data, "region"); + + region.get = function(info, ...) return getAll(data, info, ...); end; + region.set = function(info, ...) + setAll(data, info, ...); + if(type(data.id) == "string") then + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + end + end + region.hidden = function(info, ...) return hiddenAll(data, info, ...); end; + region.disabled = function(info, ...) return disabledAll(data, info, ...); end; + return region + end + +end diff --git a/WeakAurasOptions/ExternalAddons.lua b/WeakAurasOptions/ExternalAddons.lua index 9e87e52..b398bd3 100644 --- a/WeakAurasOptions/ExternalAddons.lua +++ b/WeakAurasOptions/ExternalAddons.lua @@ -69,7 +69,7 @@ function WeakAuras.CreateImportButtons() local button = WeakAuras.GetDisplayButton(groupId); button.callbacks.UpdateExpandButton(); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadGroupRegionOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id); end end end @@ -171,7 +171,7 @@ function WeakAuras.CreateImportButtons() local button = WeakAuras.GetDisplayButton(id); button.callbacks.UpdateExpandButton(); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadGroupRegionOptions(data); + WeakAuras.ClearAndUpdateOptions(data.id); end WeakAuras.ScanForLoads(); @@ -331,7 +331,7 @@ function WeakAuras.DisableAddonDisplay(id) end end WeakAuras.Add(parentData); - WeakAuras.ReloadGroupRegionOptions(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id); WeakAuras.UpdateDisplayButton(parentData); end end diff --git a/WeakAurasOptions/GenericTrigger.lua b/WeakAurasOptions/GenericTrigger.lua index ffd47f1..51f03d9 100644 --- a/WeakAurasOptions/GenericTrigger.lua +++ b/WeakAurasOptions/GenericTrigger.lua @@ -11,58 +11,23 @@ local subevent_suffix_types = WeakAuras.subevent_suffix_types; local custom_trigger_types = WeakAuras.custom_trigger_types; local eventend_types = WeakAuras.eventend_types; -local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) +local function GetCustomTriggerOptions(data, triggernum) local id = data.id; + local trigger = data.triggers[triggernum].trigger + local function appendToTriggerPath(...) + local ret = {...}; + tinsert(ret, 1, "trigger"); + tinsert(ret, 1, triggernum); + tinsert(ret, 1, "triggers"); + return ret; + end - local appendToTriggerPath, appendToUntriggerPath; - - if (data.controlledChildren) then - function appendToTriggerPath(...) - local baseRet = {...}; - local result = {}; - - for index, childId in pairs(data.controlledChildren) do - local ret = {}; - WeakAuras.DeepCopy(baseRet, ret); - local optionTriggerChoice = optionTriggerChoices[childId]; - tinsert(ret, 1, "trigger"); - tinsert(ret, 1, optionTriggerChoice) - tinsert(ret, 1, "triggers") - result[childId] = ret; - end - return result; - end - function appendToUntriggerPath(...) - local baseRet = {...}; - local result = {}; - - for index, childId in pairs(data.controlledChildren) do - local ret = {}; - WeakAuras.DeepCopy(baseRet, ret); - local optionTriggerChoice = optionTriggerChoices[childId]; - tinsert(ret, 1, "untrigger"); - tinsert(ret, 1, optionTriggerChoice); - tinsert(ret, 1, "triggers"); - result[childId] = ret; - end - return result; - end - else - function appendToTriggerPath(...) - local ret = {...}; - tinsert(ret, 1, "trigger"); - tinsert(ret, 1, optionTriggerChoices[id]); - tinsert(ret, 1, "triggers"); - return ret; - end - - function appendToUntriggerPath(...) - local ret = {...}; - tinsert(ret, 1, "untrigger"); - tinsert(ret, 1, optionTriggerChoices[id]); - tinsert(ret, 1, "triggers"); - return ret; - end + local function appendToUntriggerPath(...) + local ret = {...}; + tinsert(ret, 1, "untrigger"); + tinsert(ret, 1, triggernum); + tinsert(ret, 1, "triggers"); + return ret; end local customOptions = @@ -74,12 +39,14 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) width = WeakAuras.doubleWidth, values = custom_trigger_types, hidden = function() return not (trigger.type == "custom") end, + get = function(info) + return trigger.custom_type + end, set = function(info, v) trigger.custom_type = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadOptions(data.id); + WeakAuras.ClearAndUpdateOptions(data.id); end }, check = { @@ -96,7 +63,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.check = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -114,7 +80,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.check = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -131,7 +96,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.events = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -146,7 +110,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.events = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -218,7 +181,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.custom_hide = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -233,7 +195,6 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.custom_hide = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end }, @@ -246,9 +207,8 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) set = function(info, v) trigger.dynamicDuration = v; WeakAuras.Add(data); - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadOptions(data.id); + WeakAuras.ClearAndUpdateOptions(data.id); end }, duration = { @@ -279,57 +239,45 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) return true; end, func = function() - if (data.controlledChildren) then - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - for i = 1, 7 do - if (childData.trigger["customOverlay" .. i] == nil) then - childData.trigger["customOverlay" .. i] = ""; - break; - end - end - end - else - for i = 1, 7 do - if (trigger["customOverlay" .. i] == nil) then - trigger["customOverlay" .. i] = ""; - break; - end + for i = 1, 7 do + if (trigger["customOverlay" .. i] == nil) then + trigger["customOverlay" .. i] = ""; + break; end end WeakAuras.Add(data); + WeakAuras.ClearAndUpdateOptions(data.id) end } }; local function extraSetFunction() - WeakAuras.SetIconNames(data); WeakAuras.UpdateDisplayButton(data); end local function extraSetFunctionReload() extraSetFunction(); - WeakAuras.ReloadOptions(data.id); + WeakAuras.ClearAndUpdateOptions(data.id); end local function hideCustomTrigger() return not (trigger.type == "custom") end - WeakAuras.AddCodeOption(customOptions, data, L["Custom Trigger"], "custom_trigger", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-trigger", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Custom Trigger"], "custom_trigger", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-trigger", 10, hideCustomTrigger, appendToTriggerPath("custom"), false, true, extraSetFunction, nil, true); local function hideCustomVariables() return not (trigger.type == "custom" and trigger.custom_type == "stateupdate"); end - WeakAuras.AddCodeOption(customOptions, data, L["Custom Variables"], "custom_variables", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-variables", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Custom Variables"], "custom_variables", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-variables", 11, hideCustomVariables, appendToTriggerPath("customVariables"), false, true, extraSetFunctionReload, nil, true); local function hideCustomUntrigger() return not (trigger.type == "custom" and (trigger.custom_type == "status" or (trigger.custom_type == "event" and trigger.custom_hide == "custom"))) end - WeakAuras.AddCodeOption(customOptions, data, L["Custom Untrigger"], "custom_untrigger", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-untrigger", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Custom Untrigger"], "custom_untrigger", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-untrigger", 14, hideCustomUntrigger, appendToUntriggerPath("custom"), false, true, extraSetFunction); local function hideCustomDuration() @@ -337,7 +285,7 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) and (trigger.custom_type == "status" or (trigger.custom_type == "event" and (trigger.custom_hide ~= "timed" or trigger.dynamicDuration)))) end - WeakAuras.AddCodeOption(customOptions, data, L["Duration Info"], "custom_duration", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#duration-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Duration Info"], "custom_duration", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#duration-info", 16, hideCustomDuration, appendToTriggerPath("customDuration"), false, true, extraSetFunctionReload); local function hideIfTriggerStateUpdate() @@ -353,23 +301,11 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) end local function removeOverlay() - if (data.controlledChildren) then - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - for j = i, 7 do - childData.trigger["customOverlay" .. j] = childData.trigger["customOverlay" .. (j +1)]; - end - WeakAuras.ScheduleReloadOptions(childData); - end - WeakAuras.Add(data); - WeakAuras.ScheduleReloadOptions(data); - else - for j = i, 7 do - trigger["customOverlay" .. j] = trigger["customOverlay" .. (j +1)]; - end - WeakAuras.Add(data); - WeakAuras.ScheduleReloadOptions(data); + for j = i, 7 do + trigger["customOverlay" .. j] = trigger["customOverlay" .. (j +1)]; end + WeakAuras.Add(data); + WeakAuras.ClearAndUpdateOptions(data.id) end local extraFunctions = { @@ -379,34 +315,27 @@ local function GetCustomTriggerOptions(data, optionTriggerChoices, trigger) } } - WeakAuras.AddCodeOption(customOptions, data, string.format(L["Overlay %s Info"], i), "custom_overlay" .. i, "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#overlay-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, string.format(L["Overlay %s Info"], i), "custom_overlay" .. i, "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#overlay-info", 17 + i / 10, hideOverlay, appendToTriggerPath("customOverlay" .. i), false, true, extraSetFunctionReload, extraFunctions); end - WeakAuras.AddCodeOption(customOptions, data, L["Name Info"], "custom_name", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#name-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Name Info"], "custom_name", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#name-info", 18, hideIfTriggerStateUpdate, appendToTriggerPath("customName"), false, true, extraSetFunctionReload); - WeakAuras.AddCodeOption(customOptions, data, L["Icon Info"], "custom_icon", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#icon-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Icon Info"], "custom_icon", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#icon-info", 20, hideIfTriggerStateUpdate, appendToTriggerPath("customIcon"), false, true, extraSetFunction); - WeakAuras.AddCodeOption(customOptions, data, L["Texture Info"], "custom_texture", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#texture-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Texture Info"], "custom_texture", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#texture-info", 22, hideIfTriggerStateUpdate, appendToTriggerPath("customTexture"), false, true, extraSetFunction); - WeakAuras.AddCodeOption(customOptions, data, L["Stack Info"], "custom_stacks", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#stack-info", + WeakAuras.commonOptions.AddCodeOption(customOptions, data, L["Stack Info"], "custom_stacks", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#stack-info", 23, hideIfTriggerStateUpdate, appendToTriggerPath("customStacks"), false, true, extraSetFunctionReload); return customOptions; end -local function GetGenericTriggerOptions(data, optionTriggerChoices) +local function GetGenericTriggerOptions(data, triggernum) local id = data.id; - local trigger; - local triggerType; - if (data.controlledChildren) then - triggerType = WeakAuras.getAll(data, {"trigger", "type"}); - else - local triggernum = optionTriggerChoices[id]; - trigger = data.triggers[triggernum].trigger; - triggerType = trigger.type; - end + local trigger = data.triggers[triggernum].trigger; + local triggerType = trigger.type; local options = { event = { @@ -421,23 +350,37 @@ local function GetGenericTriggerOptions(data, optionTriggerChoices) order = 7, width = WeakAuras.doubleWidth, values = function() - local type; - if (data.controlledChildren) then - type = WeakAuras.getAll(data, {"trigger", "type"}); - else - type = trigger.type; - end + local type= trigger.type; if(type == "event") then return event_types; elseif(type == "status") then return status_types; end end, + get = function(info) + return trigger.event + end, + set = function(info, v) + trigger.event = v + local prototype = WeakAuras.event_prototypes[v]; + if(prototype) then + if(prototype.automaticrequired) then + trigger.unevent = "auto"; + else + trigger.unevent = "timed"; + end + end + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end, control = "WeakAurasSortedDropdown", hidden = function() return not (trigger.type == "event" or trigger.type == "status"); end }, } + WeakAuras.commonOptions.AddCommonTriggerOptions(options, data, triggernum) + WeakAuras.AddTriggerMetaFunctions(options, data, triggernum) + local combatLogOptions = { subeventPrefix = { @@ -447,7 +390,14 @@ local function GetGenericTriggerOptions(data, optionTriggerChoices) order = 8, values = subevent_prefix_types, control = "WeakAurasSortedDropdown", - hidden = function() return not (trigger.type == "event" and trigger.event == "Combat Log"); end + hidden = function() return not (trigger.type == "event" and trigger.event == "Combat Log"); end, + get = function(info) + return trigger.subeventPrefix + end, + set = function(info, v) + trigger.subeventPrefix = v + WeakAuras.Add(data) + end }, subeventSuffix = { type = "select", @@ -456,7 +406,10 @@ local function GetGenericTriggerOptions(data, optionTriggerChoices) order = 9, values = subevent_suffix_types, control = "WeakAurasSortedDropdown", - hidden = function() return not (trigger.type == "event" and trigger.event == "Combat Log" and subevent_actual_prefix_types[trigger.subeventPrefix]); end + hidden = function() return not (trigger.type == "event" and trigger.event == "Combat Log" and subevent_actual_prefix_types[trigger.subeventPrefix]); end, + get = function(info) + return trigger.subevent + end }, spacer_suffix = { type = "description", @@ -467,36 +420,27 @@ local function GetGenericTriggerOptions(data, optionTriggerChoices) } if (triggerType == "custom") then - WeakAuras:Mixin(options, GetCustomTriggerOptions(data, optionTriggerChoices, trigger)); + WeakAuras:Mixin(options, GetCustomTriggerOptions(data, triggernum, trigger)); elseif (triggerType == "status" or triggerType == "event") then local prototypeOptions; - if (data.controlledChildren) then - local event = WeakAuras.getAll(data, {"trigger", "event"}); - local unevent = WeakAuras.getAll(data, {"trigger", "unevent"}); - if(event and WeakAuras.event_prototypes[event]) then - prototypeOptions = WeakAuras.ConstructOptions(WeakAuras.event_prototypes[event], data, 10, optionTriggerChoices[id], nil, unevent); - if (event == "Combat Log") then - WeakAuras:Mixin(prototypeOptions, combatLogOptions); - end + local trigger, untrigger = data.triggers[triggernum].trigger, data.triggers[triggernum].untrigger; + if(WeakAuras.event_prototypes[trigger.event]) then + prototypeOptions = WeakAuras.ConstructOptions(WeakAuras.event_prototypes[trigger.event], data, 10, triggernum); + if (trigger.event == "Combat Log") then + WeakAuras:Mixin(prototypeOptions, combatLogOptions); end else - local triggerNum = optionTriggerChoices[id]; - local trigger, untrigger = data.triggers[triggerNum].trigger, data.triggers[triggerNum].untrigger; - if(WeakAuras.event_prototypes[trigger.event]) then - prototypeOptions = WeakAuras.ConstructOptions(WeakAuras.event_prototypes[trigger.event], data, 10, optionTriggerChoices[id]); - if (trigger.event == "Combat Log") then - WeakAuras:Mixin(prototypeOptions, combatLogOptions); - end - else - print("|cFF8800FFWeakAuras|r: No prototype for", trigger.event); - end + print("|cFF8800FFWeakAuras|r: No prototype for", trigger.event); end if (prototypeOptions) then WeakAuras:Mixin(options, prototypeOptions); end end - return options; + + return { + ["trigger." .. triggernum .. "." .. (trigger.event or "unknown")] = options + } end WeakAuras.RegisterTriggerSystemOptions({"event", "status", "custom"}, GetGenericTriggerOptions); diff --git a/WeakAurasOptions/GroupOptions.lua b/WeakAurasOptions/GroupOptions.lua new file mode 100644 index 0000000..d56889e --- /dev/null +++ b/WeakAurasOptions/GroupOptions.lua @@ -0,0 +1,62 @@ +local L = WeakAuras.L +local regionOptions = WeakAuras.regionOptions; +local parsePrefix = WeakAuras.commonOptions.parsePrefix +local flattenRegionOptions = WeakAuras.commonOptions.flattenRegionOptions + +function WeakAuras.GetGroupOptions(data) + local regionOption; + local id = data.id + if (regionOptions[data.regionType]) then + regionOption = regionOptions[data.regionType].create(id, data); + else + regionOption = { + [data.regionType] = { + __title = "|cFFFFFF00" .. data.regionType, + __order = 1, + unsupported = { + type = "description", + name = L["This region of type \"%s\" is not supported."]:format(data.regionType) + } + }; + }; + end + + local groupOptions = { + type = "group", + name = L["Group Options"], + order = 0, + get = function(info) + local base, property = parsePrefix(info[#info], data); + if not base then + return nil + end + if(info.type == "color") then + base[property] = base[property] or {}; + local c = base[property]; + return c[1], c[2], c[3], c[4]; + else + return base[property]; + end + end, + set = function(info, v, g, b, a) + local base, property = parsePrefix(info[#info], data, true); + if(info.type == "color") then + base[property] = base[property] or {}; + local c = base[property]; + c[1], c[2], c[3], c[4] = v, g, b, a; + elseif(info.type == "toggle") then + base[property] = v; + else + base[property] = (v ~= "" and v) or nil; + end + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + end, + hidden = function() return false end, + disabled = function() return false end, + args = flattenRegionOptions(regionOption, true); + } + + return groupOptions +end diff --git a/WeakAurasOptions/LoadOptions.lua b/WeakAurasOptions/LoadOptions.lua new file mode 100644 index 0000000..0fa97b2 --- /dev/null +++ b/WeakAurasOptions/LoadOptions.lua @@ -0,0 +1,893 @@ +local L = WeakAuras.L + +local removeFuncs = WeakAuras.commonOptions.removeFuncs +local replaceNameDescFuncs = WeakAuras.commonOptions.replaceNameDescFuncs +local replaceImageFuncs = WeakAuras.commonOptions.replaceImageFuncs +local replaceValuesFuncs = WeakAuras.commonOptions.replaceValuesFuncs +local disabledAll = WeakAuras.commonOptions.CreateDisabledAll("load") +local hiddenAll = WeakAuras.commonOptions.CreateHiddenAll("load") +local getAll = WeakAuras.commonOptions.CreateGetAll("load") +local setAll = WeakAuras.commonOptions.CreateSetAll("load", getAll) + +local operator_types = WeakAuras.operator_types; +local operator_types_without_equal = WeakAuras.operator_types_without_equal; +local string_operator_types = WeakAuras.string_operator_types; +local ValidateNumeric = WeakAuras.ValidateNumeric; +local eventend_types = WeakAuras.eventend_types; +local timedeventend_types = WeakAuras.timedeventend_types; +local autoeventend_types = WeakAuras.autoeventend_types; + + +local spellCache = WeakAuras.spellCache; + +local function union(table1, table2) + local meta = {}; + for i,v in pairs(table1) do + meta[i] = v; + end + for i,v in pairs(table2) do + meta[i] = v; + end + return meta; +end + +-- Also used by the GenericTrigger +function WeakAuras.ConstructOptions(prototype, data, startorder, triggernum, triggertype, unevent) + local trigger, untrigger; + if(data.controlledChildren) then + trigger, untrigger = {}, {}; + elseif(triggertype == "load") then + trigger = data.load; + elseif data.triggers[triggernum] then + if(triggertype == "untrigger") then + trigger = data.triggers[triggernum].untrigger + else + trigger, untrigger = data.triggers[triggernum].trigger, data.triggers[triggernum].untrigger + end + else + error("Improper argument to WeakAuras.ConstructOptions - trigger number not in range"); + end + unevent = unevent or trigger.unevent; + local options = {}; + local order = startorder or 10; + + local isCollapsedFunctions; + for index, arg in pairs(prototype.args) do + local hidden = nil; + if(arg.collapse and isCollapsedFunctions[arg.collapse] and type(arg.enable) == "function") then + local isCollapsed = isCollapsedFunctions[arg.collapse] + hidden = function() + return isCollapsed() or not arg.enable(trigger) + end + elseif(type(arg.enable) == "function") then + hidden = function() return not arg.enable(trigger) end; + elseif(arg.collapse and isCollapsedFunctions[arg.collapse]) then + hidden = isCollapsedFunctions[arg.collapse] + end + local name = arg.name; + local validate = arg.validate; + local reloadOptions = arg.reloadOptions; + if (name and arg.type == "collapse") then + options["summary_" .. arg.name] = { + type = "execute", + control = "WeakAurasExpandSmall", + width = WeakAuras.doubleWidth, + name = type(arg.display) == "function" and arg.display(trigger) or arg.display, + order = order, + image = function() + local collapsed = WeakAuras.IsCollapsed("trigger", name, "", true) + return collapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\edit" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\editdown" + end, + imageWidth = 24, + imageHeight = 24, + func = function(info, button, secondCall) + if not secondCall then + local collapsed = WeakAuras.IsCollapsed("trigger", name, "", true) + WeakAuras.SetCollapsed("trigger", name, "", not collapsed) + end + end, + } + order = order + 1; + + isCollapsedFunctions = isCollapsedFunctions or {}; + isCollapsedFunctions[name] = function() + return WeakAuras.IsCollapsed("trigger", name, "", true); + end + elseif(name and not arg.hidden) then + local realname = name; + if(triggertype == "untrigger") then + name = "untrigger_"..name; + end + if (arg.type == "multiselect") then + -- Ensure new line for non-toggle options + options["spacer_"..name] = { + type = "description", + width = WeakAuras.doubleWidth, + name = "", + order = order, + hidden = hidden, + } + order = order + 1; + end + if(arg.type == "tristate" or arg.type == "tristatestring") then + options["use_"..name] = { + type = "toggle", + width = WeakAuras.normalWidth, + name = function(input) + local value = trigger["use_"..realname]; + if(value == nil) then return arg.display; + elseif(value == false) then return "|cFFFF0000 "..L["Negator"].." "..arg.display; + else return "|cFF00FF00"..arg.display; end + end, + desc = arg.desc, + get = function() + local value = trigger["use_"..realname]; + if(value == nil) then return false; + elseif(value == false) then return "false"; + else return "true"; end + end, + set = function(info, v) + if(v) then + trigger["use_"..realname] = true; + else + local value = trigger["use_"..realname]; + if(value == false) then + trigger["use_"..realname] = nil; + else + trigger["use_"..realname] = false + end + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end, + hidden = hidden, + order = order + }; + elseif(arg.type == "multiselect") then + options["use_"..name] = { + type = "toggle", + width = WeakAuras.normalWidth, + name = arg.display, + desc = function() + local v = trigger["use_"..realname]; + if(v == true) then + return L["Multiselect single tooltip"]; + elseif(v == false) then + return L["Multiselect multiple tooltip"]; + else + return L["Multiselect ignored tooltip"]; + end + end, + get = function() + local value = trigger["use_"..realname]; + if(value == nil) then return false; + elseif(value == false) then return "false"; + else return "true"; end + end, + set = function(info, v) + if(v) then + trigger["use_"..realname] = true; + else + local value = trigger["use_"..realname]; + if(value == false) then + trigger["use_"..realname] = nil; + else + trigger["use_"..realname] = false + trigger[realname] = trigger[realname] or {}; + if(trigger[realname].single) then + trigger[realname].multi = trigger[realname].multi or {}; + trigger[realname].multi[trigger[realname].single] = true; + end + end + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end, + hidden = hidden, + order = order + }; + elseif (arg.type == "description") then + options["description_space_"..name] = { + type = "description", + width = WeakAuras.doubleWidth, + name = "", + order = order, + hidden = hidden, + } + options["description_title_"..name] = { + type = "description", + width = WeakAuras.doubleWidth, + name = arg.display, + order = order, + hidden = hidden, + fontSize = "large", + } + order = order + 1; + options["description_"..name] = { + type = "description", + width = WeakAuras.doubleWidth, + name = arg.text, + order = order, + hidden = hidden, + } + order = order + 1; + else + options["use_"..name] = { + type = "toggle", + width = arg.width or WeakAuras.normalWidth, + name = arg.display, + order = order, + hidden = hidden, + desc = arg.desc, + get = function() return trigger["use_"..realname]; end, + set = function(info, v) + trigger["use_"..realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + end + if(arg.type == "toggle" or arg.type == "tristate") then + options["use_"..name].width = arg.width or WeakAuras.doubleWidth; + end + if(arg.type == "toggle") then + options["use_"..name].desc = arg.desc; + end + if(arg.required) then + trigger["use_"..realname] = true; + if not(triggertype) then + options["use_"..name].disabled = true; + else + options["use_"..name] = nil; + order = order - 1; + end + end + order = order + 1; + if(arg.type == "number") then + if (not arg.noOperator) then + options[name.."_operator"] = { + type = "select", + width = WeakAuras.halfWidth, + name = L["Operator"], + order = order, + hidden = hidden, + values = arg.operator_types_without_equal and operator_types_without_equal or operator_types, + disabled = function() return not trigger["use_"..realname]; end, + get = function() return trigger["use_"..realname] and trigger[realname.."_operator"] or nil; end, + set = function(info, v) + trigger[realname.."_operator"] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name.."_operator"].set = function(info, v) + trigger[realname.."_operator"] = v; + untrigger[realname.."_operator"] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name.."_operator"] = nil; + order = order - 1; + end + order = order + 1; + end + options[name] = { + type = "input", + width = arg.noOperator and WeakAuras.normalWidth or WeakAuras.halfWidth, + validate = ValidateNumeric, + name = arg.display, + order = order, + hidden = hidden, + desc = arg.desc, + disabled = function() return not trigger["use_"..realname]; end, + get = function() return trigger["use_"..realname] and trigger[realname] or nil; end, + set = function(info, v) + trigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name].set = function(info, v) + trigger[realname] = v; + untrigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name] = nil; + order = order - 1; + end + order = order + 1; + elseif(arg.type == "string" or arg.type == "tristatestring") then + options[name] = { + type = "input", + width = WeakAuras.normalWidth, + name = arg.display, + order = order, + hidden = hidden, + validate = validate, + desc = arg.desc, + set = function(info, v) + trigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + + if arg.type == "string" then + options[name].disabled = function() return not trigger["use_"..realname] end + options[name].get = function() return trigger["use_"..realname] and trigger[realname] or nil; end + else + options[name].disabled = function() return trigger["use_"..realname] == nil end + options[name].get = function() return trigger["use_"..realname] ~= nil and trigger[realname] or nil; end + end + + if(arg.required and not triggertype) then + options[name].set = function(info, v) + trigger[realname] = v; + untrigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name] = nil; + order = order - 1; + end + order = order + 1; + elseif(arg.type == "longstring") then + options[name.."_operator"] = { + type = "select", + width = WeakAuras.normalWidth, + name = L["Operator"], + order = order, + hidden = hidden, + values = string_operator_types, + disabled = function() return not trigger["use_"..realname]; end, + get = function() return trigger["use_"..realname] and trigger[realname.."_operator"] or nil; end, + set = function(info, v) + trigger[realname.."_operator"] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name.."_operator"].set = function(info, v) + trigger[realname.."_operator"] = v; + untrigger[realname.."_operator"] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name.."_operator"] = nil; + order = order - 1; + end + order = order + 1; + options[name] = { + type = "input", + width = WeakAuras.doubleWidth, + name = arg.display, + order = order, + hidden = hidden, + validate = validate, + disabled = function() return not trigger["use_"..realname]; end, + get = function() return trigger["use_"..realname] and trigger[realname] or nil; end, + set = function(info, v) + trigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name].set = function(info, v) + trigger[realname] = v; + untrigger[realname] = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name] = nil; + order = order - 1; + end + order = order + 1; + elseif(arg.type == "spell" or arg.type == "aura" or arg.type == "item") then + if(not arg.required or triggertype ~= "untrigger") then + if (arg.showExactOption) then + options["exact"..name] = { + type = "toggle", + width = WeakAuras.normalWidth - 0.1, + name = L["Exact Spell Match"], + order = order, + hidden = hidden, + get = function() + return trigger["use_exact_"..realname]; + end, + set = function(info, v) + trigger["use_exact_"..realname] = v; + WeakAuras.Add(data); + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end, + }; + order = order + 1; + end + options["icon"..name] = { + type = "execute", + width = 0.1, + name = "", + order = order, + hidden = hidden, + image = function() + if(trigger["use_"..realname] and trigger[realname]) then + if(arg.type == "aura") then + local icon = spellCache.GetIcon(trigger[realname]); + return icon and tostring(icon) or "", 18, 18; + elseif(arg.type == "spell") then + local _, _, icon = GetSpellInfo(trigger[realname]); + return icon and tostring(icon) or "", 18, 18; + elseif(arg.type == "item") then + local _, _, _, _, _, _, _, _, _, icon = GetItemInfo(trigger[realname]); + return icon and tostring(icon) or "", 18, 18; + end + else + return "", 18, 18; + end + end, + disabled = function() return not ((arg.type == "aura" and trigger[realname] and spellCache.GetIcon(trigger[realname])) or (arg.type == "spell" and trigger[realname] and GetSpellInfo(trigger[realname])) or (arg.type == "item" and trigger[realname] and GetItemIcon(trigger[realname]))) end + }; + order = order + 1; + options[name] = { + type = "input", + width = WeakAuras.doubleWidth, + name = arg.display, + order = order, + hidden = hidden, + validate = validate, + disabled = function() return not trigger["use_"..realname]; end, + get = function() + if(arg.type == "item") then + if(trigger["use_"..realname] and trigger[realname] and trigger[realname] ~= "") then + local name = GetItemInfo(trigger[realname]); + if(name) then + return name; + else + local itemId = tonumber(trigger[realname]) + if itemId and itemId ~= 0 then + return tostring(trigger[realname]) + end + return L["Invalid Item Name/ID/Link"]; + end + else + return nil; + end + elseif(arg.type == "spell") then + local useExactSpellId = (arg.showExactOption and trigger["use_exact_"..realname]) or arg.forceExactOption + if(trigger["use_"..realname]) then + if (trigger[realname] and trigger[realname] ~= "") then + if useExactSpellId then + local spellId = tonumber(trigger[realname]) + if (spellId and spellId ~= 0) then + return tostring(spellId); + end + else + local name = GetSpellInfo(trigger[realname]); + if(name) then + return name; + end + end + end + return useExactSpellId and L["Invalid Spell ID"] or L["Invalid Spell Name/ID/Link"]; + else + return nil; + end + else + return trigger["use_"..realname] and trigger[realname] or nil; + end + end, + set = function(info, v) + local fixedInput = v; + if(arg.type == "aura") then + fixedInput = WeakAuras.spellCache.CorrectAuraName(v); + elseif(arg.type == "spell") then + fixedInput = WeakAuras.CorrectSpellName(v); + elseif(arg.type == "item") then + fixedInput = WeakAuras.CorrectItemName(v); + end + trigger[realname] = fixedInput; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + order = order + 1; + end + elseif(arg.type == "select" or arg.type == "unit") then + local values; + if(type(arg.values) == "function") then + values = arg.values(trigger); + else + values = WeakAuras[arg.values]; + end + options[name] = { + type = "select", + width = WeakAuras.normalWidth, + name = arg.display, + order = order, + hidden = hidden, + values = values, + disabled = function() return not trigger["use_"..realname]; end, + get = function() + if(arg.type == "unit" and trigger["use_specific_"..realname]) then + return "member"; + end + + if (not trigger["use_"..realname]) then + return nil; + end + + if (arg.default and (not trigger[realname] or not values[trigger[realname]])) then + trigger[realname] = arg.default; + return arg.default; + end + + return trigger[realname] or nil; + end, + set = function(info, v) + trigger[realname] = v; + if(arg.type == "unit" and v == "member") then + trigger["use_specific_"..realname] = true; + trigger[realname] = UnitName("player"); + else + trigger["use_specific_"..realname] = nil; + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name].set = function(info, v) + trigger[realname] = v; + if(arg.type == "unit" and v == "member") then + trigger["use_specific_"..realname] = true; + else + trigger["use_specific_"..realname] = nil; + end + untrigger[realname] = v; + if(arg.type == "unit" and v == "member") then + untrigger["use_specific_"..realname] = true; + else + untrigger["use_specific_"..realname] = nil; + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + elseif(arg.required and triggertype == "untrigger") then + options[name] = nil; + order = order - 1; + end + if (arg.control) then + options[name].control = arg.control; + end + order = order + 1; + if(arg.type == "unit" and not (arg.required and triggertype == "untrigger")) then + options["use_specific_"..name] = { + type = "toggle", + width = WeakAuras.normalWidth, + name = L["Specific Unit"], + order = order, + hidden = function() return (not trigger["use_specific_"..realname] and trigger[realname] ~= "member") or (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) end, + get = function() return true end, + set = function(info, v) + trigger["use_specific_"..realname] = nil; + options[name].set(info, "player"); + end + } + order = order + 1; + options["specific_"..name] = { + type = "input", + width = WeakAuras.normalWidth, + name = L["Specific Unit"], + desc = L["Can be a UID (e.g., party1)."], + order = order, + hidden = function() return (not trigger["use_specific_"..realname] and trigger[realname] ~= "member") or (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) end, + get = function() return trigger[realname] end, + set = function(info, v) + trigger[realname] = v; + if(arg.required and not triggertype) then + untrigger[realname] = v; + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + end + }; + order = order + 1; + end + elseif(arg.type == "multiselect") then + local values; + if(type(arg.values) == "function") then + values = arg.values(trigger); + else + values = WeakAuras[arg.values]; + end + options[name] = { + type = "select", + width = WeakAuras.normalWidth, + name = arg.display, + order = order, + values = values, + control = arg.control, + hidden = function() + return (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) or trigger["use_"..realname] == false; + end, + disabled = function() return not trigger["use_"..realname]; end, + get = function() return trigger["use_"..realname] and trigger[realname] and trigger[realname].single or nil; end, + set = function(info, v) + trigger[realname] = trigger[realname] or {}; + trigger[realname].single = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name].set = function(info, v) + trigger[realname].single = v; + untrigger[realname].single = v; + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + end + + options["multiselect_"..name] = { + type = "multiselect", + name = arg.display, + width = WeakAuras.doubleWidth, + order = order, + hidden = function() return (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) or trigger["use_"..realname] ~= false; end, + values = values, + get = function(info, v) + if(trigger["use_"..realname] == false and trigger[realname] and trigger[realname].multi) then + return trigger[realname].multi[v]; + end + end, + set = function(info, v, calledFromSetAll) + trigger[realname].multi = trigger[realname].multi or {}; + if (calledFromSetAll) then + trigger[realname].multi[v] = calledFromSetAll; + elseif(trigger[realname].multi[v]) then + trigger[realname].multi[v] = nil; + else + trigger[realname].multi[v] = true; + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + }; + if(arg.required and not triggertype) then + options[name].set = function(info, v) + if(trigger[realname].multi[v]) then + trigger[realname].multi[v] = nil; + else + trigger[realname].multi[v] = true; + end + if(untrigger[realname].multi[v]) then + untrigger[realname].multi[v] = nil; + else + untrigger[realname].multi[v] = true; + end + WeakAuras.Add(data); + if (reloadOptions) then + WeakAuras.ClearAndUpdateOptions(data.id) + end + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + WeakAuras.SortDisplayButtons(); + end + end + + if(arg.required and triggertype == "untrigger") then + options[name] = nil; + options["multiselect_"..name] = nil; + else + order = order + 1; + end + end + end + end + + if not(triggertype or prototype.automaticrequired) then + options.unevent = { + type = "select", + width = WeakAuras.doubleWidth, + name = L["Hide"], + order = order + }; + order = order + 1; + if(unevent == "timed") then + options.unevent.width = WeakAuras.normalWidth; + options.duration = { + type = "input", + width = WeakAuras.normalWidth, + name = L["Duration (s)"], + order = order + } + order = order + 1; + else + options.unevent.width = WeakAuras.doubleWidth; + end + + if(unevent == "custom") then + local unevent_options = WeakAuras.ConstructOptions(prototype, data, order, triggernum, "untrigger"); + options = union(options, unevent_options); + end + if (prototype.timedrequired) then + if (type(prototype.timedrequired) == "function") then + local func = prototype.timedrequired + options.unevent.values = function() + if func(trigger) then + return timedeventend_types + else + return eventend_types + end + end + else + options.unevent.values = timedeventend_types; + end + elseif (prototype.automatic) then + options.unevent.values = autoeventend_types; + else + options.unevent.values = eventend_types; + end + end + + WeakAuras.option = options; + return options; +end + +function WeakAuras.GetLoadOptions(data) + local load = { + type = "group", + name = L["Load"], + order = 0, + get = function(info) return data.load[info[#info]] end, + set = function(info, v) + data.load[info[#info]] = (v ~= "" and v) or nil; + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ScanForLoads({[data.id] = true}); + WeakAuras.SortDisplayButtons(); + end, + args = {} + } + + load.args = WeakAuras.ConstructOptions(WeakAuras.load_prototype, data, 10, nil, "load"); + + if(data.controlledChildren) then + removeFuncs(load); + replaceNameDescFuncs(load, data, "load"); + replaceImageFuncs(load, data, "load"); + replaceValuesFuncs(load, data, "load"); + + load.get = function(info, ...) return getAll(data, info, ...); end; + load.set = function(info, ...) + setAll(data, info, ...); + if(type(data.id) == "string") then + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.ResetMoverSizer(); + end + end + load.hidden = function(info, ...) return hiddenAll(data, info, ...); end; + load.disabled = function(info, ...) return disabledAll(data, info, ...); end; + end + return load +end diff --git a/WeakAurasOptions/OptionsFrames/FrameChooser.lua b/WeakAurasOptions/OptionsFrames/FrameChooser.lua index 24edd35..c6e23c2 100644 --- a/WeakAurasOptions/OptionsFrames/FrameChooser.lua +++ b/WeakAurasOptions/OptionsFrames/FrameChooser.lua @@ -39,8 +39,8 @@ function WeakAuras.StartFrameChooser(data, path) frameChooserFrame:SetScript("OnUpdate", function() if(IsMouseButtonDown("RightButton")) then valueToPath(data, path, givenValue); - AceConfigDialog:Open("WeakAuras", frame.container); WeakAuras.StopFrameChooser(data); + WeakAuras.FillOptions() elseif(IsMouseButtonDown("LeftButton") and oldFocusName) then WeakAuras.StopFrameChooser(data); else @@ -76,7 +76,7 @@ function WeakAuras.StartFrameChooser(data, path) if(focusName ~= oldFocusName) then valueToPath(data, path, focusName); oldFocusName = focusName; - AceConfigDialog:Open("WeakAuras", frame.container); + WeakAuras.FillOptions() end oldFocus = focus; end diff --git a/WeakAurasOptions/OptionsFrames/IconPicker.lua b/WeakAurasOptions/OptionsFrames/IconPicker.lua index 3bd65e1..0032ece 100644 --- a/WeakAurasOptions/OptionsFrames/IconPicker.lua +++ b/WeakAurasOptions/OptionsFrames/IconPicker.lua @@ -126,14 +126,12 @@ local function ConstructIconPicker(frame) childData[self.field] = texturePath; WeakAuras.Add(childData); WeakAuras.UpdateThumbnail(childData); - WeakAuras.SetIconNames(childData); end end else self.data[self.field] = texturePath; WeakAuras.Add(self.data); WeakAuras.UpdateThumbnail(self.data); - WeakAuras.SetIconNames(self.data); end local success = icon:SetTexture(texturePath) and texturePath; if(success) then @@ -167,7 +165,7 @@ local function ConstructIconPicker(frame) function group.Close() frame.window = "default"; frame:UpdateFrameVisible() - AceConfigDialog:Open("WeakAuras", frame.container); + WeakAuras.FillOptions() end function group.CancelClose() @@ -178,7 +176,6 @@ local function ConstructIconPicker(frame) childData[group.field] = group.givenPath[childId] or childData[group.field]; WeakAuras.Add(childData); WeakAuras.UpdateThumbnail(childData); - WeakAuras.SetIconNames(childData); end end else diff --git a/WeakAurasOptions/OptionsFrames/ModelPicker.lua b/WeakAurasOptions/OptionsFrames/ModelPicker.lua index 503983f..c3fee51 100644 --- a/WeakAurasOptions/OptionsFrames/ModelPicker.lua +++ b/WeakAurasOptions/OptionsFrames/ModelPicker.lua @@ -101,7 +101,6 @@ local function ConstructModelPicker(frame) childData.model_y = model_y; WeakAuras.Add(childData); WeakAuras.UpdateThumbnail(childData); - WeakAuras.SetIconNames(childData); end end else @@ -115,7 +114,6 @@ local function ConstructModelPicker(frame) else WeakAuras.Add(self.data); WeakAuras.UpdateThumbnail(self.data); - WeakAuras.SetIconNames(self.data); end end end @@ -166,7 +164,7 @@ local function ConstructModelPicker(frame) function group.Close() frame.window = "default" frame:UpdateFrameVisible() - AceConfigDialog:Open("WeakAuras", frame.container); + WeakAuras.FillOptions() end function group.CancelClose(self) @@ -180,7 +178,6 @@ local function ConstructModelPicker(frame) childData.model_y = group.givenY[childId]; WeakAuras.Add(childData); WeakAuras.UpdateThumbnail(childData); - WeakAuras.SetIconNames(childData); end end else diff --git a/WeakAurasOptions/OptionsFrames/MoverSizer.lua b/WeakAurasOptions/OptionsFrames/MoverSizer.lua index e4ea56e..b81afb8 100644 --- a/WeakAurasOptions/OptionsFrames/MoverSizer.lua +++ b/WeakAurasOptions/OptionsFrames/MoverSizer.lua @@ -51,7 +51,7 @@ local function moveOnePxl(direction) WeakAuras.Add(parentData) end end - WeakAuras.ReloadOptions(data.id) + WeakAuras.FillOptions() end end end @@ -614,7 +614,7 @@ local function ConstructMoverSizer(parent) WeakAuras.Add(parentData) end end - AceConfigDialog:Open("WeakAuras", parent.container) + WeakAuras.FillOptions() WeakAuras.Animate("display", data, "main", data.animation.main, WeakAuras.regions[data.id].region, false, nil, true) -- hide alignment lines frame.lineY:Hide() @@ -669,7 +669,7 @@ local function ConstructMoverSizer(parent) region:ResetPosition() WeakAuras.Add(data, nil, true) frame:ScaleCorners(region:GetWidth(), region:GetHeight()) - AceConfigDialog:Open("WeakAuras", parent.container) + WeakAuras.FillOptions() end) mover.align = BuildAlignLines(mover) @@ -734,7 +734,7 @@ local function ConstructMoverSizer(parent) end frame.text:Hide() frame:SetScript("OnUpdate", nil) - AceConfigDialog:Open("WeakAuras", parent.container) + WeakAuras.FillOptions() WeakAuras.Animate("display", data, "main", data.animation.main, WeakAuras.regions[data.id].region, false, nil, true) -- hide alignment lines frame.lineY:Hide() diff --git a/WeakAurasOptions/OptionsFrames/OptionsFrame.lua b/WeakAurasOptions/OptionsFrames/OptionsFrame.lua index 4b1da58..94ad565 100644 --- a/WeakAurasOptions/OptionsFrames/OptionsFrame.lua +++ b/WeakAurasOptions/OptionsFrames/OptionsFrame.lua @@ -17,12 +17,12 @@ local WeakAuras = WeakAuras local L = WeakAuras.L local displayButtons = WeakAuras.displayButtons -local displayOptions = WeakAuras.displayOptions local loaded = WeakAuras.loaded local regionOptions = WeakAuras.regionOptions local savedVars = WeakAuras.savedVars local tempGroup = WeakAuras.tempGroup local prettyPrint = WeakAuras.prettyPrint +local aceOptions = WeakAuras.aceOptions local function CreateDecoration(frame) local deco = CreateFrame("Frame", nil, frame) @@ -726,14 +726,144 @@ function WeakAuras.CreateFrame() unloadedButton:SetViewDescription(L["Toggle the visibility of all non-loaded displays"]) frame.unloadedButton = unloadedButton - frame.FillOptions = function(self, optionTable, selected) - AceConfig:RegisterOptionsTable("WeakAuras", optionTable) - AceConfigDialog:Open("WeakAuras", container) - -- TODO: remove this once legacy aura trigger is removed - if selected then - container.content.obj.children[1]:SelectTab(selected) + + frame.ClearOptions = function(self, id) + aceOptions[id] = nil + if type(id) == "string" then + local data = WeakAuras.GetData(id) + if data and data.parent then + frame:ClearOptions(data.parent) + end + for _, tmpId in ipairs(tempGroup.controlledChildren) do + if (id == tmpId) then + frame:ClearOptions(tempGroup.id) + end + end end - container:SetTitle("") + end + + frame.ClearAndUpdateOptions = function(self, id, clearChildren) + frame:ClearOptions(id) + + if clearChildren then + local data + if type(id) == "string" then + data = WeakAuras.GetData(id) + elseif self.pickedDisplay then + data = tempGroup + end + + if data.controlledChildren then + for _, id in ipairs(data.controlledChildren) do + frame:ClearOptions(id) + end + end + end + if (type(self.pickedDisplay) == "string" and self.pickedDisplay == id) + or (type(self.pickedDisplay == "table") and id == tempGroup.id) + then + frame:UpdateOptions() + end + end + + frame.UpdateOptions = function(self) + self.selectedTab = self.selectedTab or "region" + local data + if type(self.pickedDisplay) == "string" then + data = WeakAuras.GetData(frame.pickedDisplay) + elseif self.pickedDisplay then + data = tempGroup + end + + if not data.controlledChildren or data == tempGroup then + if self.selectedTab == "group" then + self.selectedTab = "region" + end + end + + local optionTable = self:EnsureOptions(data, self.selectedTab) + if optionTable then + AceConfig:RegisterOptionsTable("WeakAuras", optionTable) + end + end + + frame.GetSubOptions = function(self, id, tab) + return aceOptions[id] and aceOptions[id][tab] + end + + frame.EnsureOptions = function(self, data, tab) + local id = data.id + aceOptions[id] = aceOptions[id] or {} + if not aceOptions[id][tab] then + local optionsGenerator = + { + group = WeakAuras.GetGroupOptions, + region = WeakAuras.GetDisplayOptions, + trigger = WeakAuras.GetTriggerOptions, + conditions = WeakAuras.GetConditionOptions, + load = WeakAuras.GetLoadOptions, + action = WeakAuras.GetActionOptions, + animation = WeakAuras.GetAnimationOptions, + authorOptions = WeakAuras.GetAuthorOptions + } + if optionsGenerator[tab] then + aceOptions[id][tab] = optionsGenerator[tab](data) + end + end + return aceOptions[id][tab] + end + + -- This function refills the options pane + -- This is ONLY necessary if AceOptions doesn't know that it should do + -- that automatically. That is any change that goes through the AceOptions + -- doesn't need to call this + -- Any changes to the options that go around that, e.g. drag/drop, group, + -- texture pick, etc should call this + frame.FillOptions = function(self) + frame:UpdateOptions() + + local data + if type(self.pickedDisplay) == "string" then + data = WeakAuras.GetData(frame.pickedDisplay) + elseif self.pickedDisplay then + data = tempGroup + end + + local tabsWidget + + container:ReleaseChildren() + container:SetLayout("Fill") + tabsWidget = AceGUI:Create("TabGroup") + + local tabs = { + { value = "region", text = L["Display"]}, + { value = "trigger", text = L["Trigger"]}, + { value = "conditions", text = L["Conditions"]}, + { value = "load", text = L["Load"]}, + { value = "action", text = L["Actions"]}, + { value = "animation", text = L["Animations"]}, + { value = "authorOptions", text = L["Custom Options"]} + } + -- Check if group and not the temp group + if data.controlledChildren and type(data.id) == "string" then + tinsert(tabs, 1, { value = "group", text = L["Group"]}) + end + + tabsWidget:SetTabs(tabs) + tabsWidget:SelectTab(self.selectedTab) + tabsWidget:SetLayout("Fill") + container:AddChild(tabsWidget) + + local group = AceGUI:Create("WeakAurasInlineGroup") + tabsWidget:AddChild(group) + + tabsWidget:SetCallback("OnGroupSelected", function(self, event, tab) + frame.selectedTab = tab + frame:FillOptions() + end) + + AceConfigDialog:Open("WeakAuras", group) + tabsWidget:SetTitle("") end frame.ClearPick = function(self, id) @@ -748,8 +878,8 @@ function WeakAuras.CreateFrame() tremove(tempGroup.controlledChildren, index) displayButtons[id]:ClearPick() - WeakAuras.AddOption(tempGroup.id, tempGroup) - self:FillOptions(displayOptions[tempGroup.id]) + self:ClearOptions(tempGroup.id) + self:FillOptions() end frame.ClearPicks = function(self, noHide) @@ -936,73 +1066,55 @@ function WeakAuras.CreateFrame() end end - frame.PickDisplay = function(self, id, tab, noHide) -- TODO: remove tab parametter once legacy aura trigger is removed + frame.PickDisplay = function(self, id, tab, noHide) + if self.pickedDisplay == id then + return + end self:ClearPicks(noHide) local data = WeakAuras.GetData(id) - local function finishPicking() - displayButtons[id]:Pick() - self.pickedDisplay = id - local data = db.displays[id] - -- Expand parent + loaded/unloaded if needed - if data.parent then - if not displayButtons[data.parent]:GetExpanded() then - displayButtons[data.parent]:Expand() - end - end - if loaded[id] ~= nil then - -- Under loaded - if not loadedButton:GetExpanded() then - loadedButton:Expand() - end - else - -- Under Unloaded - if not unloadedButton:GetExpanded() then - unloadedButton:Expand() - end - end + displayButtons[id]:Pick() + self.pickedDisplay = id - WeakAuras.AddOption(data.id, data) - self:FillOptions(displayOptions[id], tab) -- TODO: remove tab parametter once legacy aura trigger is removed - - WeakAuras.SetMoverSizer(id) - - local _, _, _, _, yOffset = displayButtons[id].frame:GetPoint(1) - if not yOffset then - yOffset = displayButtons[id].frame.yOffset + if data.parent then + if not displayButtons[data.parent]:GetExpanded() then + displayButtons[data.parent]:Expand() end - if yOffset then - self.buttonsScroll:SetScrollPos(yOffset, yOffset - 32) + end + if loaded[id] ~= nil then + -- Under loaded + if not loadedButton:GetExpanded() then + loadedButton:Expand() end - if data.controlledChildren then - for index, childId in pairs(data.controlledChildren) do - displayButtons[childId]:PriorityShow(1) - end + else + -- Under Unloaded + if not unloadedButton:GetExpanded() then + unloadedButton:Expand() end - - WeakAuras.ResumeAllDynamicGroups() end - local list = {} - local num = 0 + if tab then + self.selectedTab = tab + end + self:FillOptions() + + WeakAuras.SetMoverSizer(id) + + local _, _, _, _, yOffset = displayButtons[id].frame:GetPoint(1) + if not yOffset then + yOffset = displayButtons[id].frame.yOffset + end + if yOffset then + self.buttonsScroll:SetScrollPos(yOffset, yOffset - 32) + end if data.controlledChildren then for index, childId in pairs(data.controlledChildren) do - if not displayOptions[childId] then - list[childId] = WeakAuras.GetData(childId) - num = num + 1 - end + displayButtons[childId]:PriorityShow(1) end end - WeakAuras.EnsureOptions(id) - if num > 1 then - WeakAuras.PauseAllDynamicGroups() - WeakAuras.BuildOptions(list, finishPicking) - else - WeakAuras.PauseAllDynamicGroups() - finishPicking() - if data.controlledChildren and #data.controlledChildren == 0 then - WeakAurasOptions:NewAura(true) - end + + if data.controlledChildren and #data.controlledChildren == 0 then + WeakAurasOptions:NewAura(true) end end @@ -1038,11 +1150,10 @@ function WeakAuras.CreateFrame() self:PickDisplay(id) elseif not WeakAuras.IsDisplayPicked(id) then self.pickedDisplay = tempGroup - WeakAuras.EnsureOptions(id) displayButtons[id]:Pick() tinsert(tempGroup.controlledChildren, id) - WeakAuras.AddOption(tempGroup.id, tempGroup) - self:FillOptions(displayOptions[tempGroup.id]) + WeakAuras.ClearOptions(tempGroup.id) + self:FillOptions() end end end @@ -1057,32 +1168,13 @@ function WeakAuras.CreateFrame() end end if not alreadySelected then - WeakAuras.EnsureOptions(id) displayButtons[id]:Pick() tinsert(tempGroup.controlledChildren, id) end end - WeakAuras.AddOption(tempGroup.id, tempGroup) - self:FillOptions(displayOptions[tempGroup.id]) + frame:ClearOptions(tempGroup.id) self.pickedDisplay = tempGroup - end - - frame.RefreshPick = function(self) - if type(self.pickedDisplay) == "string" then - WeakAuras.EnsureOptions(self.pickedDisplay) - self:FillOptions(displayOptions[self.pickedDisplay]) - else - WeakAuras.EnsureOptions(tempGroup.id) - self:FillOptions(displayOptions[tempGroup.id]) - end - end - - frame.RefillOptions = function(self) - if type(self.pickedDisplay) == "string" then - self:FillOptions(displayOptions[frame.pickedDisplay]) - elseif self.pickedDisplay then - self:FillOptions(displayOptions[frame.pickedDisplay.id]) - end + self:FillOptions() end frame:SetClampedToScreen(true) diff --git a/WeakAurasOptions/OptionsFrames/TextEditor.lua b/WeakAurasOptions/OptionsFrames/TextEditor.lua index b62b9e1..b8d90ec 100644 --- a/WeakAurasOptions/OptionsFrames/TextEditor.lua +++ b/WeakAurasOptions/OptionsFrames/TextEditor.lua @@ -727,22 +727,20 @@ local function ConstructTextEditor(frame) if (self.reloadOptions) then if (self.data.controlledChildren) then for index, childId in pairs(self.data.controlledChildren) do - WeakAuras.ScheduleReloadOptions(WeakAuras.GetData(childId)) + WeakAuras.ClearAndUpdateOptions(childId) end - WeakAuras.ScheduleReloadOptions(self.data) + WeakAuras.ClearAndUpdateOptions(self.data.id) else - WeakAuras.ScheduleReloadOptions(self.data) + WeakAuras.ClearAndUpdateOptions(self.data.id) end else - WeakAuras.ScheduleReloadOptions(self.data) + WeakAuras.ClearAndUpdateOptions(self.data.id) end editor.editBox:SetScript("OnTextChanged", self.oldOnTextChanged) editor:ClearFocus() frame.window = "default" frame:UpdateFrameVisible() - - frame:RefreshPick() end WeakAuras.editor = editor @@ -752,4 +750,4 @@ end function WeakAuras.TextEditor(frame) textEditor = textEditor or ConstructTextEditor(frame) return textEditor -end \ No newline at end of file +end diff --git a/WeakAurasOptions/OptionsFrames/TexturePicker.lua b/WeakAurasOptions/OptionsFrames/TexturePicker.lua index 19dc0d5..15c0f64 100644 --- a/WeakAurasOptions/OptionsFrames/TexturePicker.lua +++ b/WeakAurasOptions/OptionsFrames/TexturePicker.lua @@ -12,8 +12,68 @@ local AceConfigDialog = LibStub("AceConfigDialog-3.0") local WeakAuras = WeakAuras local L = WeakAuras.L -local getAll = WeakAuras.getAll -local setAll = WeakAuras.setAll + +local function CompareValues(a, b) + if type(a) ~= type(b) then + return false + end + if type(a) == "table" then + for k, v in pairs(a) do + if v ~= b[k] then + return false + end + end + + for k, v in pairs(b) do + if v ~= a[k] then + return false + end + end + + return true + else + return a == b + end +end + +local function GetAll(data, property, default) + if data.controlledChildren then + local result + local first = true + for index, childId in pairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId) + if childData[property] ~= nil then + if first then + result = childData[property] + first = false + else + if not CompareValues(result, childData[property]) then + return default + end + end + end + end + return result + else + if data[property] ~= nil then + return data[property] + end + return default + end + +end + +local function SetAll(data, property, value) + if data.controlledChildren then + for index, childId in pairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId) + childData[property] = value + WeakAuras.Add(childData) + end + else + data[property] = value + end +end local texturePicker @@ -100,14 +160,9 @@ local function ConstructTexturePicker(frame) pickedwidget:Pick(); end - if(self.data.controlledChildren) then - setAll(self.data, {"region", self.field}, texturePath); - else - self.data[self.field] = texturePath; - end + SetAll(self.data, self.field, texturePath); if(type(self.data.id) == "string") then WeakAuras.Add(self.data); - WeakAuras.SetIconNames(self.data); WeakAuras.UpdateThumbnail(self.data); end group:UpdateList(); @@ -128,17 +183,17 @@ local function ConstructTexturePicker(frame) self.givenPath[childId] = childData[field]; end end - local colorAll = getAll(data, {"region", "color"}) or {1, 1, 1, 1}; + local colorAll = GetAll(data, "color", {1, 1, 1, 1}); self.textureData = { r = colorAll[1] or 1, g = colorAll[2] or 1, b = colorAll[3] or 1, a = colorAll[4] or 1, - rotate = getAll(data, {"region", "rotate"}), - discrete_rotation = getAll(data, {"region", "discrete_rotation"}) or 0, - rotation = getAll(data, {"region", "rotation"}) or 0, - mirror = getAll(data, {"region", "mirror"}), - blendMode = getAll(data, {"region", "blendMode"}) or "ADD" + rotate = GetAll(data, "rotate", false), + discrete_rotation = GetAll(data, "discrete_rotation", 0), + rotation = GetAll(data, "rotation", 0), + mirror = GetAll(data, "mirror", false), + blendMode = GetAll(data, "blendMode", "ADD") }; else self.givenPath = data[field]; @@ -188,7 +243,7 @@ local function ConstructTexturePicker(frame) function group.Close() frame.window = "default"; frame:UpdateFrameVisible() - AceConfigDialog:Open("WeakAuras", frame.container); + WeakAuras.FillOptions() end function group.CancelClose() @@ -199,7 +254,6 @@ local function ConstructTexturePicker(frame) childData[group.field] = group.givenPath[childId]; WeakAuras.Add(childData); WeakAuras.UpdateThumbnail(childData); - WeakAuras.SetIconNames(childData); end end else diff --git a/WeakAurasOptions/RegionOptions/AuraBar.lua b/WeakAurasOptions/RegionOptions/AuraBar.lua index e70d0ca..b701b22 100644 --- a/WeakAurasOptions/RegionOptions/AuraBar.lua +++ b/WeakAurasOptions/RegionOptions/AuraBar.lua @@ -63,7 +63,6 @@ local function createOptions(id, data) data.orientation = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.ResetMoverSizer(); end }, @@ -144,7 +143,6 @@ local function createOptions(id, data) data.displayIcon = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); end }, chooseIcon = { @@ -178,7 +176,6 @@ local function createOptions(id, data) data.icon_side = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); end }, desaturate = { @@ -405,7 +402,7 @@ local function createOptions(id, data) return { aurabar = options, - position = WeakAuras.PositionOptions(id, data), + position = WeakAuras.commonOptions.PositionOptions(id, data), }; end @@ -744,12 +741,12 @@ local function subCreateOptions(parentData, data, index, subIndex) __order = 1, __up = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionUp, index, "aurabar_bar")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __down = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionDown, index, "aurabar_bar")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id, parentData) end end, __nooptions = true diff --git a/WeakAurasOptions/RegionOptions/DynamicGroup.lua b/WeakAurasOptions/RegionOptions/DynamicGroup.lua index 781db60..e4a4291 100644 --- a/WeakAurasOptions/RegionOptions/DynamicGroup.lua +++ b/WeakAurasOptions/RegionOptions/DynamicGroup.lua @@ -90,7 +90,6 @@ local function createOptions(id, data) data.groupIcon = v WeakAuras.Add(data) WeakAuras.UpdateThumbnail(data) - WeakAuras.SetIconNames(data) end }, chooseIcon = { @@ -115,7 +114,7 @@ local function createOptions(id, data) end data.selfPoint = selfPoint WeakAuras.Add(data) - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id) WeakAuras.ResetMoverSizer() end, }, @@ -159,7 +158,7 @@ local function createOptions(id, data) end data.selfPoint = selfPoint WeakAuras.Add(data) - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id) WeakAuras.ResetMoverSizer() end, hidden = function() return (data.grow == "CUSTOM" or data.grow == "LEFT" or data.grow == "RIGHT" or data.grow == "HORIZONTAL" or data.grow == "CIRCLE" or data.grow == "COUNTERCIRCLE" or data.grow == "GRID") end, @@ -181,7 +180,7 @@ local function createOptions(id, data) end data.selfPoint = selfPoint WeakAuras.Add(data) - WeakAuras.ReloadTriggerOptions(data) + WeakAuras.ClearAndUpdateOptions(data.id) WeakAuras.ResetMoverSizer() end, }, @@ -411,23 +410,23 @@ local function createOptions(id, data) }, }; - WeakAuras.AddCodeOption(options, data, L["Custom Grow"], "custom_grow", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Dynamic-Group", + WeakAuras.commonOptions.AddCodeOption(options, data, L["Custom Grow"], "custom_grow", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#grow", 2, function() return data.grow ~= "CUSTOM" end, {"customGrow"}, nil, nil, nil, nil, nil, true) - WeakAuras.AddCodeOption(options, data, L["Custom Sort"], "custom_sort", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Dynamic-Group", + WeakAuras.commonOptions.AddCodeOption(options, data, L["Custom Sort"], "custom_sort", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-sort", 21, function() return data.sort ~= "custom" end, {"customSort"}, nil, nil, nil, nil, nil, true) - WeakAuras.AddCodeOption(options, data, L["Custom Anchor"], "custom_anchor_per_unit", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Dynamic-Group", + WeakAuras.commonOptions.AddCodeOption(options, data, L["Custom Anchor"], "custom_anchor_per_unit", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#group-by-frame", 1.7, function() return not(data.grow ~= "CUSTOM" and data.useAnchorPerUnit and data.anchorPerUnit == "CUSTOM") end, {"customAnchorPerUnit"}, nil, nil, nil, nil, nil, true) local borderHideFunc = function() return data.useAnchorPerUnit or data.grow == "CUSTOM" end local disableSelfPoint = function() return data.grow ~= "CUSTOM" and data.grow ~= "GRID" and not data.useAnchorPerUnit end - for k, v in pairs(WeakAuras.BorderOptions(id, data, nil, borderHideFunc, 70)) do + for k, v in pairs(WeakAuras.commonOptions.BorderOptions(id, data, nil, borderHideFunc, 70)) do options[k] = v end return { dynamicgroup = options, - position = WeakAuras.PositionOptions(id, data, nil, true, disableSelfPoint), + position = WeakAuras.commonOptions.PositionOptions(id, data, nil, true, disableSelfPoint), }; end diff --git a/WeakAurasOptions/RegionOptions/Group.lua b/WeakAurasOptions/RegionOptions/Group.lua index 6fb2117..54be449 100644 --- a/WeakAurasOptions/RegionOptions/Group.lua +++ b/WeakAurasOptions/RegionOptions/Group.lua @@ -55,7 +55,6 @@ local function createOptions(id, data) data.groupIcon = v WeakAuras.Add(data) WeakAuras.UpdateThumbnail(data) - WeakAuras.SetIconNames(data) end }, chooseIcon = { @@ -557,13 +556,13 @@ local function createOptions(id, data) }, }; - for k, v in pairs(WeakAuras.BorderOptions(id, data, nil, nil, 70)) do + for k, v in pairs(WeakAuras.commonOptions.BorderOptions(id, data, nil, nil, 70)) do options[k] = v end return { group = options, - position = WeakAuras.PositionOptions(id, data, nil, true, true), + position = WeakAuras.commonOptions.PositionOptions(id, data, nil, true, true), }; end diff --git a/WeakAurasOptions/RegionOptions/Icon.lua b/WeakAurasOptions/RegionOptions/Icon.lua index fd51103..d05e65e 100644 --- a/WeakAurasOptions/RegionOptions/Icon.lua +++ b/WeakAurasOptions/RegionOptions/Icon.lua @@ -40,7 +40,6 @@ local function createOptions(id, data) data.displayIcon = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); end }, chooseIcon = { @@ -99,7 +98,7 @@ local function createOptions(id, data) end, imageWidth = 24, imageHeight = 24, - func = function() + func = function(info, button) local collapsed = WeakAuras.IsCollapsed("icon", "icon", "iconextra", true); WeakAuras.SetCollapsed("icon", "icon", "iconextra", not collapsed); end, @@ -199,7 +198,7 @@ local function createOptions(id, data) return { icon = options, - position = WeakAuras.PositionOptions(id, data), + position = WeakAuras.commonOptions.PositionOptions(id, data), }; end diff --git a/WeakAurasOptions/RegionOptions/Model.lua b/WeakAurasOptions/RegionOptions/Model.lua index 50b5b4e..054239f 100644 --- a/WeakAurasOptions/RegionOptions/Model.lua +++ b/WeakAurasOptions/RegionOptions/Model.lua @@ -115,13 +115,13 @@ local function createOptions(id, data) } end - for k, v in pairs(WeakAuras.BorderOptions(id, data, nil, nil, 70)) do + for k, v in pairs(WeakAuras.commonOptions.BorderOptions(id, data, nil, nil, 70)) do options[k] = v end return { model = options, - position = WeakAuras.PositionOptions(id, data, nil, nil, nil), + position = WeakAuras.commonOptions.PositionOptions(id, data, nil, nil, nil), }; end diff --git a/WeakAurasOptions/RegionOptions/ProgressTexture.lua b/WeakAurasOptions/RegionOptions/ProgressTexture.lua index 3be29d4..6e21770 100644 --- a/WeakAurasOptions/RegionOptions/ProgressTexture.lua +++ b/WeakAurasOptions/RegionOptions/ProgressTexture.lua @@ -168,7 +168,6 @@ local function createOptions(id, data) data.crop_x = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); if(data.parent) then local parentData = WeakAuras.GetData(data.parent); if(parentData) then @@ -192,7 +191,6 @@ local function createOptions(id, data) data.crop_y = v; WeakAuras.Add(data); WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); if(data.parent) then local parentData = WeakAuras.GetData(data.parent); if(parentData) then @@ -315,7 +313,7 @@ local function createOptions(id, data) return { progresstexture = options, - position = WeakAuras.PositionOptions(id, data), + position = WeakAuras.commonOptions.PositionOptions(id, data), }; end diff --git a/WeakAurasOptions/RegionOptions/Text.lua b/WeakAurasOptions/RegionOptions/Text.lua index 6aa25d8..3991950 100644 --- a/WeakAurasOptions/RegionOptions/Text.lua +++ b/WeakAurasOptions/RegionOptions/Text.lua @@ -29,9 +29,8 @@ local function createOptions(id, data) set = function(info, v) data.displayText = WeakAuras.ReplaceLocalizedRaidMarkers(v); WeakAuras.Add(data); - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); WeakAuras.ResetMoverSizer(); end, }, @@ -105,7 +104,7 @@ local function createOptions(id, data) return secondline end, - func = function() + func = function(info, button) local collapsed = WeakAuras.IsCollapsed("text", "text", "fontflags", true) WeakAuras.SetCollapsed("text", "text", "fontflags", not collapsed) end, @@ -240,7 +239,7 @@ local function createOptions(id, data) }, }; - WeakAuras.AddCodeOption(options, data, L["Custom Function"], "customText", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-text", + WeakAuras.commonOptions.AddCodeOption(options, data, L["Custom Function"], "customText", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-text", 37, function() return not WeakAuras.ContainsCustomPlaceHolder(data.displayText) end, {"customText"}, false); -- Add Text Format Options @@ -266,7 +265,7 @@ local function createOptions(id, data) option.set = function(info, v) data["displayText_format_" .. key] = v WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) end end options["displayText_format_" .. key] = option @@ -282,7 +281,7 @@ local function createOptions(id, data) return { text = options; - position = WeakAuras.PositionOptions(id, data, nil, true); + position = WeakAuras.commonOptions.PositionOptions(id, data, nil, true); }; end @@ -394,4 +393,4 @@ local templates = { } } -WeakAuras.RegisterRegionOptions("text", createOptions, createIcon, L["Text"], createThumbnail, modifyThumbnail, L["Shows one or more lines of text, which can include dynamic information such as progress or stacks"], templates); \ No newline at end of file +WeakAuras.RegisterRegionOptions("text", createOptions, createIcon, L["Text"], createThumbnail, modifyThumbnail, L["Shows one or more lines of text, which can include dynamic information such as progress or stacks"], templates); diff --git a/WeakAurasOptions/RegionOptions/Texture.lua b/WeakAurasOptions/RegionOptions/Texture.lua index d471d5e..2f78cad 100644 --- a/WeakAurasOptions/RegionOptions/Texture.lua +++ b/WeakAurasOptions/RegionOptions/Texture.lua @@ -100,7 +100,7 @@ local function createOptions(id, data) return { texture = options, - position = WeakAuras.PositionOptions(id, data), + position = WeakAuras.commonOptions.PositionOptions(id, data), }; end diff --git a/WeakAurasOptions/SubRegionOptions/BarModel.lua b/WeakAurasOptions/SubRegionOptions/BarModel.lua index 12bb7c0..0d4cf60 100644 --- a/WeakAurasOptions/SubRegionOptions/BarModel.lua +++ b/WeakAurasOptions/SubRegionOptions/BarModel.lua @@ -9,22 +9,22 @@ local function createOptions(parentData, data, index, subIndex) __order = 1, __up = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionUp, index, "subbarmodel")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __down = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionDown, index, "subbarmodel")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __duplicate = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DuplicateSubRegion, index, "subbarmodel")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __delete = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DeleteSubRegion, index, "subbarmodel")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, bar_model_visible = { diff --git a/WeakAurasOptions/SubRegionOptions/Border.lua b/WeakAurasOptions/SubRegionOptions/Border.lua index 180e7e0..1a5e6f8 100644 --- a/WeakAurasOptions/SubRegionOptions/Border.lua +++ b/WeakAurasOptions/SubRegionOptions/Border.lua @@ -11,22 +11,22 @@ local function createOptions(parentData, data, index, subIndex) __order = 1, __up = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionUp, index, "subborder")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __down = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionDown, index, "subborder")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __duplicate = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DuplicateSubRegion, index, "subtext")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __delete = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DeleteSubRegion, index, "subborder")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, border_visible = { diff --git a/WeakAurasOptions/SubRegionOptions/Glow.lua b/WeakAurasOptions/SubRegionOptions/Glow.lua index af327a7..0e7417f 100644 --- a/WeakAurasOptions/SubRegionOptions/Glow.lua +++ b/WeakAurasOptions/SubRegionOptions/Glow.lua @@ -20,22 +20,22 @@ local function createOptions(parentData, data, index, subIndex) __order = 1, __up = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionUp, index, "subglow")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __down = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionDown, index, "subglow")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __duplicate = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DuplicateSubRegion, index, "subglow")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __delete = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DeleteSubRegion, index, "subglow")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, glow = { @@ -112,7 +112,7 @@ local function createOptions(parentData, data, index, subIndex) end, imageWidth = 24, imageHeight = 24, - func = function() + func = function(info, button) local collapsed = WeakAuras.IsCollapsed("glow", "glow", "glowextra" .. index, true); WeakAuras.SetCollapsed("glow", "glow", "glowextra" .. index, not collapsed); end, diff --git a/WeakAurasOptions/SubRegionOptions/SubRegionCommon.lua b/WeakAurasOptions/SubRegionOptions/SubRegionCommon.lua index 95aa497..5cf7636 100644 --- a/WeakAurasOptions/SubRegionOptions/SubRegionCommon.lua +++ b/WeakAurasOptions/SubRegionOptions/SubRegionCommon.lua @@ -29,7 +29,7 @@ function WeakAuras.DeleteSubRegion(data, index, regionType) if data.subRegions[index] and data.subRegions[index].type == regionType then tremove(data.subRegions, index) WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) local replacements = { ["sub." .. index .. "."] = deleteCondition @@ -50,7 +50,7 @@ function WeakAuras.MoveSubRegionUp(data, index, regionType) if data.subRegions[index] and data.subRegions[index].type == regionType then data.subRegions[index - 1], data.subRegions[index] = data.subRegions[index], data.subRegions[index - 1] WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) local replacements = { ["sub." .. (index -1) .. "."] = "sub." .. index .. ".", @@ -68,7 +68,7 @@ function WeakAuras.MoveSubRegionDown(data, index, regionType) if data.subRegions[index] and data.subRegions[index].type == regionType and data.subRegions[index + 1] then data.subRegions[index], data.subRegions[index + 1] = data.subRegions[index + 1], data.subRegions[index] WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) local replacements = { ["sub." .. index .. "."] = "sub." .. (index + 1) .. ".", @@ -86,7 +86,7 @@ function WeakAuras.DuplicateSubRegion(data, index, regionType) if data.subRegions[index] and data.subRegions[index].type == regionType then tinsert(data.subRegions, index, CopyTable(data.subRegions[index])) WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) + WeakAuras.ClearAndUpdateOptions(data.id) local replacements = {} for i = index + 1, #data.subRegions do diff --git a/WeakAurasOptions/SubRegionOptions/SubText.lua b/WeakAurasOptions/SubRegionOptions/SubText.lua index 0aa5d26..28fce9b 100644 --- a/WeakAurasOptions/SubRegionOptions/SubText.lua +++ b/WeakAurasOptions/SubRegionOptions/SubText.lua @@ -32,22 +32,22 @@ local function createOptions(parentData, data, index, subIndex) __order = 1, __up = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionUp, index, "subtext")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __down = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.MoveSubRegionDown, index, "subtext")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __duplicate = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DuplicateSubRegion, index, "subtext")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, __delete = function() if (WeakAuras.ApplyToDataOrChildData(parentData, WeakAuras.DeleteSubRegion, index, "subtext")) then - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end end, text_visible = { @@ -74,7 +74,7 @@ local function createOptions(parentData, data, index, subIndex) set = function(info, v) data.text_text = WeakAuras.ReplaceLocalizedRaidMarkers(v) WeakAuras.Add(parentData) - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end }, text_font = { @@ -136,7 +136,7 @@ local function createOptions(parentData, data, index, subIndex) end, width = WeakAuras.doubleWidth, order = 44, - func = function() + func = function(info, button) local collapsed = WeakAuras.IsCollapsed("subtext", "subtext", "fontflags" .. index, true) WeakAuras.SetCollapsed("subtext", "subtext", "fontflags" .. index, not collapsed) end, @@ -325,7 +325,7 @@ local function createOptions(parentData, data, index, subIndex) end, imageWidth = 24, imageHeight = 24, - func = function() + func = function(info, button) local collapsed = WeakAuras.IsCollapsed("subregion", "text_anchors", tostring(index), true) WeakAuras.SetCollapsed("subregion", "text_anchors", tostring(index), not collapsed) end @@ -408,21 +408,6 @@ local function createOptions(parentData, data, index, subIndex) return true end - local function CheckTextOptions(placeholders) - return function() - if not parentData.subRegions then - return true - end - - for index, subRegion in ipairs(parentData.subRegions) do - if subRegion.type == "subtext" and WeakAuras.ContainsPlaceHolders(subRegion.text_text, placeholders) then - return false - end - end - return true - end - end - local commonTextOptions = { __title = L["Common Text"], __hidden = function() return hideCustomTextOption() end, @@ -437,16 +422,15 @@ local function createOptions(parentData, data, index, subIndex) set = function(info, v) parentData.customTextUpdate = v WeakAuras.Add(parentData) - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) end }, } - WeakAuras.AddCodeOption(commonTextOptions, parentData, L["Custom Function"], "customText", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-text", + WeakAuras.commonOptions.AddCodeOption(commonTextOptions, parentData, L["Custom Function"], "customText", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-text", 4, hideCustomTextOption, {"customText"}, false) -- Add Text Format Options - local input = data["text_text"] local hidden = function() return WeakAuras.IsCollapsed("format_option", "text", "text_text", true) end @@ -455,10 +439,6 @@ local function createOptions(parentData, data, index, subIndex) WeakAuras.SetCollapsed("format_option", "text", "text_text", hidden) end - local get = function(key) - return data["text_text_format_" .. key] - end - local order = 12 local function addOption(key, option) option.order = order @@ -468,13 +448,35 @@ local function createOptions(parentData, data, index, subIndex) option.set = function(info, v) data["text_text_format_" .. key] = v WeakAuras.Add(parentData) - WeakAuras.ReloadOptions2(parentData.id, parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id, true) end end options["text_text_format_" .. key] = option end - WeakAuras.AddTextFormatOption(input, true, get, addOption, hidden, setHidden) + if parentData.controlledChildren then + for _, childId in pairs(parentData.controlledChildren) do + local parentChildData = WeakAuras.GetData(childId) + + if parentChildData.subRegions then + local childData = parentChildData.subRegions[index] + if childData then + local get = function(key) + return childData["text_text_format_" .. key] + end + local input = childData["text_text"] + WeakAuras.AddTextFormatOption(input, true, get, addOption, hidden, setHidden) + end + end + end + else + local get = function(key) + return data["text_text_format_" .. key] + end + local input = data["text_text"] + WeakAuras.AddTextFormatOption(input, true, get, addOption, hidden, setHidden) + end + addOption("footer", { type = "description", name = "", diff --git a/WeakAurasOptions/TriggerOptions.lua b/WeakAurasOptions/TriggerOptions.lua new file mode 100644 index 0000000..e1a2a82 --- /dev/null +++ b/WeakAurasOptions/TriggerOptions.lua @@ -0,0 +1,282 @@ + +local L = WeakAuras.L + +local removeFuncs = WeakAuras.commonOptions.removeFuncs +local replaceNameDescFuncs = WeakAuras.commonOptions.replaceNameDescFuncs +local replaceImageFuncs = WeakAuras.commonOptions.replaceImageFuncs +local replaceValuesFuncs = WeakAuras.commonOptions.replaceValuesFuncs +local disabledAll = WeakAuras.commonOptions.CreateDisabledAll("trigger") +local hiddenAll = WeakAuras.commonOptions.CreateHiddenAll("trigger") +local getAll = WeakAuras.commonOptions.CreateGetAll("trigger") +local setAll = WeakAuras.commonOptions.CreateSetAll("trigger", getAll) +local executeAll = WeakAuras.commonOptions.CreateExecuteAll("trigger") + +local flattenRegionOptions = WeakAuras.commonOptions.flattenRegionOptions +local fixMetaOrders = WeakAuras.commonOptions.fixMetaOrders + +local subevent_actual_prefix_types = WeakAuras.subevent_actual_prefix_types; +local spellCache = WeakAuras.spellCache + +local function union(table1, table2) + local meta = {}; + for i,v in pairs(table1) do + meta[i] = v; + end + for i,v in pairs(table2) do + meta[i] = v; + end + return meta; +end + +local function GetGlobalOptions(data) + + local triggerCount = 0 + local globalTriggerOptions = { + __title = L["Trigger Combination"], + __order = 1, + disjunctive = { + type = "select", + name = L["Required for Activation"], + width = WeakAuras.doubleWidth, + order = 2, + values = function() + if #data.triggers > 1 then + return WeakAuras.trigger_require_types; + else + return WeakAuras.trigger_require_types_one; + end + end, + get = function() + if #data.triggers > 1 then + return data.triggers.disjunctive or "all"; + else + return (data.triggers.disjunctive and data.triggers.disjunctive ~= "all") and data.triggers.disjunctive or "any"; + end + end, + set = function(info, v) + data.triggers.disjunctive = v; + WeakAuras.Add(data); + end + }, + -- custom trigger combiner text editor added below + activeTriggerMode = { + type = "select", + name = L["Dynamic Information"], + width = WeakAuras.doubleWidth, + order = 2.3, + values = function() + local vals = {}; + vals[WeakAuras.trigger_modes.first_active] = L["Dynamic information from first active trigger"]; + for i = 1, #data.triggers do + vals[i] = L["Dynamic information from Trigger %i"]:format(i); + end + return vals; + end, + get = function() + return data.triggers.activeTriggerMode or WeakAuras.trigger_modes.first_active; + end, + set = function(info, v) + data.triggers.activeTriggerMode = v; + WeakAuras.Add(data); + WeakAuras.UpdateThumbnail(data); + WeakAuras.UpdateDisplayButton(data); + end, + hidden = function() return #data.triggers <= 1 end + } + } + + local function hideTriggerCombiner() + return not (data.triggers.disjunctive == "custom") + end + WeakAuras.commonOptions.AddCodeOption(globalTriggerOptions, data, L["Custom"], "custom_trigger_combination", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-activation", + 2.4, hideTriggerCombiner, {"triggers", "customTriggerLogic"}, false); + + return { + global = globalTriggerOptions + } +end + +local function AddOptions(allOptions, data) + allOptions = union(allOptions, GetGlobalOptions(data)) + + local triggerOptions = {} + for index, trigger in ipairs(data.triggers) do + local triggerSystemOptionsFunction = trigger.trigger.type and WeakAuras.triggerTypesOptions[trigger.trigger.type] + if (triggerSystemOptionsFunction) then + triggerOptions = union(triggerOptions, triggerSystemOptionsFunction(data, index)) + end + end + + return union(allOptions, triggerOptions) +end + +function WeakAuras.GetTriggerOptions(data) + local allOptions = {} + if data.controlledChildren then + for index, childId in pairs(data.controlledChildren) do + local childData = WeakAuras.GetData(childId) + allOptions = AddOptions(allOptions, childData) + end + else + allOptions = AddOptions(allOptions, data) + end + + fixMetaOrders(allOptions) + + local triggerOptions = { + type = "group", + name = L["Trigger"], + order = 20, + args = flattenRegionOptions(allOptions, false) + } + + if data.controlledChildren then + removeFuncs(triggerOptions, true); + replaceNameDescFuncs(triggerOptions, data, "trigger"); + replaceImageFuncs(triggerOptions, data, "trigger"); + replaceValuesFuncs(triggerOptions, data, "trigger"); + + triggerOptions.get = function(info, ...) + return getAll(data, info, ...) + end + triggerOptions.set = function(info, ...) + setAll(data, info, ...) + end + triggerOptions.hidden = function(info, ...) + return hiddenAll(data, info, ...) + end + triggerOptions.disabled = function(info, ...) + return disabledAll(data, info, ...) + end + + triggerOptions.func = function(info, ...) + return executeAll(data, info, ...) + end + end + + return triggerOptions +end + +local function DeleteConditionsForTriggerHandleSubChecks(checks, triggernum) + for _, check in ipairs(checks) do + if (check.trigger == triggernum) then + check.trigger = nil; + end + + if (check.trigger and check.trigger > triggernum) then + check.trigger = check.trigger - 1; + end + + if (checks.checks) then + DeleteConditionsForTriggerHandleSubChecks(checks.checks, triggernum); + end + end +end + +local function DeleteConditionsForTrigger(data, triggernum) + for _, condition in ipairs(data.conditions) do + if (condition.check and condition.check.trigger == triggernum) then + condition.check.trigger = nil; + end + + if (condition.check and condition.check.trigger and condition.check.trigger > triggernum) then + condition.check.trigger = condition.check.trigger - 1; + end + + if (condition.check and condition.check.checks) then + DeleteConditionsForTriggerHandleSubChecks(condition.check.checks, triggernum) + end + end +end + +local function moveTriggerDownConditionCheck(check, i) + if (check.trigger == i) then + check.trigger = i + 1; + elseif (check.trigger == i + 1) then + check.trigger = i; + end + if (check.checks) then + for _, subCheck in ipairs(check.checks) do + moveTriggerDownConditionCheck(subCheck, i); + end + end +end + +local function moveTriggerDownImpl(data, i) + if (i < 1 or i >= #data.triggers) then + return false; + end + data.triggers[i], data.triggers[i + 1] = data.triggers[i + 1], data.triggers[i] + for _, condition in ipairs(data.conditions) do + moveTriggerDownConditionCheck(condition.check, i); + end + + return true; +end + +function WeakAuras.AddTriggerMetaFunctions(options, data, triggernum) + options.__title = L["Trigger %s"]:format(triggernum) + options.__order = triggernum * 10 + options.__add = function() + tinsert(data.triggers, + { + trigger = + { + type = "aura2" + }, + untrigger = { + } + }) + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + options.__up = + { + disabled = function() + return triggernum < 2 + end, + func = function() + if (moveTriggerDownImpl(data, triggernum - 1)) then + WeakAuras.Add(data); + WeakAuras.ClearAndUpdateOptions(data.id); + end + end + } + options.__down = + { + disabled = function() + return triggernum == #data.triggers + end, + func = function() + if (moveTriggerDownImpl(data, triggernum)) then + WeakAuras.Add(data); + WeakAuras.ClearAndUpdateOptions(data.id); + end + end + } + options.__duplicate = function() + local trigger = CopyTable(data.triggers[triggernum]) + tinsert(data.triggers, trigger) + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + options.__delete = { + disabled = function() + return #data.triggers == 1 + end, + func = function() + if #data.triggers > 1 then + tremove(data.triggers, triggernum) + DeleteConditionsForTrigger(data, triggernum); + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) + end + end + } + local _, _, _, enabled = GetAddOnInfo("WeakAurasTemplates") + if enabled then + options.__applyTemplate = function() + WeakAuras.OpenTriggerTemplate(data) + end + end +end diff --git a/WeakAurasOptions/WeakAurasOptions.lua b/WeakAurasOptions/WeakAurasOptions.lua index a79745e..2c419d7 100644 --- a/WeakAurasOptions/WeakAurasOptions.lua +++ b/WeakAurasOptions/WeakAurasOptions.lua @@ -2,7 +2,6 @@ if not WeakAuras.IsCorrectVersion() then return end -- Lua APIs local tinsert, tremove, wipe = table.insert, table.remove, wipe -local fmt, tostring = string.format, tostring local pairs, type, unpack = pairs, type, unpack local loadstring, error = loadstring, error local coroutine = coroutine @@ -10,29 +9,23 @@ local _G = _G -- WoW APIs local InCombatLockdown = InCombatLockdown -local GetSpellInfo, GetItemInfo, GetItemIcon, UnitName = GetSpellInfo, GetItemInfo, GetItemIcon, UnitName -local GetScreenWidth, GetScreenHeight, GetBuildInfo, GetLocale, GetTime, CreateFrame, IsAddOnLoaded, LoadAddOn - = GetScreenWidth, GetScreenHeight, GetBuildInfo, GetLocale, GetTime, CreateFrame, IsAddOnLoaded, LoadAddOn +local CreateFrame, IsAddOnLoaded, LoadAddOn = CreateFrame, IsAddOnLoaded, LoadAddOn local AceGUI = LibStub("AceGUI-3.0") local WeakAuras = WeakAuras local L = WeakAuras.L local ADDON_NAME = "WeakAurasOptions"; -local prettyPrint = WeakAuras.prettyPrint -local ValidateNumeric = WeakAuras.ValidateNumeric; local dynFrame = WeakAuras.dynFrame; WeakAuras.transmitCache = {}; -local regionOptions = WeakAuras.regionOptions; local displayButtons = {}; WeakAuras.displayButtons = displayButtons; -local optionReloads = {}; -local optionTriggerChoices = {}; -WeakAuras.optionTriggerChoices = optionTriggerChoices; -local displayOptions = {}; -WeakAuras.displayOptions = displayOptions; + +local aceOptions = {} +WeakAuras.aceOptions = aceOptions + local loaded = WeakAuras.loaded; local spellCache = WeakAuras.spellCache; local savedVars = {}; @@ -105,33 +98,12 @@ function WeakAuras.DuplicateAura(data, newParent) local button = WeakAuras.GetDisplayButton(parentData.id) button.callbacks.UpdateExpandButton() WeakAuras.UpdateDisplayButton(parentData) - WeakAuras.ReloadGroupRegionOptions(parentData) + WeakAuras.ClearOptions(parentData.id) end end return newData.id end -local point_types = WeakAuras.point_types; -local operator_types = WeakAuras.operator_types; -local operator_types_without_equal = WeakAuras.operator_types_without_equal; -local string_operator_types = WeakAuras.string_operator_types; -local eventend_types = WeakAuras.eventend_types; -local autoeventend_types = WeakAuras.autoeventend_types; -local timedeventend_types = WeakAuras.timedeventend_types; -local subevent_actual_prefix_types = WeakAuras.subevent_actual_prefix_types; - - -local function union(table1, table2) - local meta = {}; - for i,v in pairs(table1) do - meta[i] = v; - end - for i,v in pairs(table2) do - meta[i] = v; - end - return meta; -end - AceGUI:RegisterLayout("AbsoluteList", function(content, children) local yOffset = 0; for i = 1, #children do @@ -200,849 +172,9 @@ function WeakAuras.MultipleDisplayTooltipDesc() return desc; end -function WeakAuras.ConstructOptions(prototype, data, startorder, triggernum, triggertype, unevent) - local trigger, untrigger; - if(data.controlledChildren) then - trigger, untrigger = {}, {}; - elseif(triggertype == "load") then - trigger = data.load; - elseif data.triggers[triggernum] then - if(triggertype == "untrigger") then - trigger = data.triggers[triggernum].untrigger - else - trigger, untrigger = data.triggers[triggernum].trigger, data.triggers[triggernum].untrigger - end - else - error("Improper argument to WeakAuras.ConstructOptions - trigger number not in range"); - end - unevent = unevent or trigger.unevent; - local options = {}; - local order = startorder or 10; - - local isCollapsedFunctions; - for index, arg in pairs(prototype.args) do - local hidden = nil; - if(arg.collapse and isCollapsedFunctions[arg.collapse] and type(arg.enable) == "function") then - local isCollapsed = isCollapsedFunctions[arg.collapse] - hidden = function() - return isCollapsed() or not arg.enable(trigger) - end - elseif(type(arg.enable) == "function") then - hidden = function() return not arg.enable(trigger) end; - elseif(arg.collapse and isCollapsedFunctions[arg.collapse]) then - hidden = isCollapsedFunctions[arg.collapse] - end - local name = arg.name; - local validate = arg.validate; - local reloadOptions = arg.reloadOptions; - if (name and arg.type == "collapse") then - options["summary_" .. arg.name] = { - type = "execute", - control = "WeakAurasExpandSmall", - width = WeakAuras.doubleWidth, - name = type(arg.display) == "function" and arg.display(trigger) or arg.display, - order = order, - image = function() - local collapsed = WeakAuras.IsCollapsed("trigger", name, "", true) - return collapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\edit" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\editdown" - end, - imageWidth = 24, - imageHeight = 24, - func = function() - local collapsed = WeakAuras.IsCollapsed("trigger", name, "", true) - WeakAuras.SetCollapsed("trigger", name, "", not collapsed) - WeakAuras.ReloadTriggerOptions(data); - end, - } - order = order + 1; - - isCollapsedFunctions = isCollapsedFunctions or {}; - isCollapsedFunctions[name] = function() - return WeakAuras.IsCollapsed("trigger", name, "", true); - end - elseif(name and not arg.hidden) then - local realname = name; - if(triggertype == "untrigger") then - name = "untrigger_"..name; - end - if (arg.type == "multiselect") then - -- Ensure new line for non-toggle options - options["spacer_"..name] = { - type = "description", - width = WeakAuras.doubleWidth, - name = "", - order = order, - hidden = hidden, - } - order = order + 1; - end - if(arg.type == "tristate" or arg.type == "tristatestring") then - options["use_"..name] = { - type = "toggle", - width = WeakAuras.normalWidth, - name = function(input) - local value = trigger["use_"..realname]; - if(value == nil) then return arg.display; - elseif(value == false) then return "|cFFFF0000 "..L["Negator"].." "..arg.display; - else return "|cFF00FF00"..arg.display; end - end, - desc = arg.desc, - get = function() - local value = trigger["use_"..realname]; - if(value == nil) then return false; - elseif(value == false) then return "false"; - else return "true"; end - end, - set = function(info, v) - if(v) then - trigger["use_"..realname] = true; - else - local value = trigger["use_"..realname]; - if(value == false) then - trigger["use_"..realname] = nil; - else - trigger["use_"..realname] = false - end - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end, - hidden = hidden, - order = order - }; - elseif(arg.type == "multiselect") then - options["use_"..name] = { - type = "toggle", - width = WeakAuras.normalWidth, - name = arg.display, - desc = function() - local v = trigger["use_"..realname]; - if(v == true) then - return L["Multiselect single tooltip"]; - elseif(v == false) then - return L["Multiselect multiple tooltip"]; - else - return L["Multiselect ignored tooltip"]; - end - end, - get = function() - local value = trigger["use_"..realname]; - if(value == nil) then return false; - elseif(value == false) then return "false"; - else return "true"; end - end, - set = function(info, v) - if(v) then - trigger["use_"..realname] = true; - else - local value = trigger["use_"..realname]; - if(value == false) then - trigger["use_"..realname] = nil; - else - trigger["use_"..realname] = false - trigger[realname] = trigger[realname] or {}; - if(trigger[realname].single) then - trigger[realname].multi = trigger[realname].multi or {}; - trigger[realname].multi[trigger[realname].single] = true; - end - end - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end, - hidden = hidden, - order = order - }; - elseif (arg.type == "description") then - options["description_space_"..name] = { - type = "description", - width = WeakAuras.doubleWidth, - name = "", - order = order, - hidden = hidden, - } - options["description_title_"..name] = { - type = "description", - width = WeakAuras.doubleWidth, - name = arg.display, - order = order, - hidden = hidden, - fontSize = "large", - } - order = order + 1; - options["description_"..name] = { - type = "description", - width = WeakAuras.doubleWidth, - name = arg.text, - order = order, - hidden = hidden, - } - order = order + 1; - else - options["use_"..name] = { - type = "toggle", - width = arg.width or WeakAuras.normalWidth, - name = arg.display, - order = order, - hidden = hidden, - desc = arg.desc, - get = function() return trigger["use_"..realname]; end, - set = function(info, v) - trigger["use_"..realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - end - if(arg.type == "toggle" or arg.type == "tristate") then - options["use_"..name].width = arg.width or WeakAuras.doubleWidth; - end - if(arg.type == "toggle") then - options["use_"..name].desc = arg.desc; - end - if(arg.required) then - trigger["use_"..realname] = true; - if not(triggertype) then - options["use_"..name].disabled = true; - else - options["use_"..name] = nil; - order = order - 1; - end - end - order = order + 1; - if(arg.type == "number") then - if (not arg.noOperator) then - options[name.."_operator"] = { - type = "select", - width = WeakAuras.halfWidth, - name = L["Operator"], - order = order, - hidden = hidden, - values = arg.operator_types_without_equal and operator_types_without_equal or operator_types, - disabled = function() return not trigger["use_"..realname]; end, - get = function() return trigger["use_"..realname] and trigger[realname.."_operator"] or nil; end, - set = function(info, v) - trigger[realname.."_operator"] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name.."_operator"].set = function(info, v) - trigger[realname.."_operator"] = v; - untrigger[realname.."_operator"] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name.."_operator"] = nil; - order = order - 1; - end - order = order + 1; - end - options[name] = { - type = "input", - width = arg.noOperator and WeakAuras.normalWidth or WeakAuras.halfWidth, - validate = ValidateNumeric, - name = arg.display, - order = order, - hidden = hidden, - desc = arg.desc, - disabled = function() return not trigger["use_"..realname]; end, - get = function() return trigger["use_"..realname] and trigger[realname] or nil; end, - set = function(info, v) - trigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name].set = function(info, v) - trigger[realname] = v; - untrigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name] = nil; - order = order - 1; - end - order = order + 1; - elseif(arg.type == "string" or arg.type == "tristatestring") then - options[name] = { - type = "input", - width = WeakAuras.normalWidth, - name = arg.display, - order = order, - hidden = hidden, - validate = validate, - desc = arg.desc, - set = function(info, v) - trigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - - if arg.type == "string" then - options[name].disabled = function() return not trigger["use_"..realname] end - options[name].get = function() return trigger["use_"..realname] and trigger[realname] or nil; end - else - options[name].disabled = function() return trigger["use_"..realname] == nil end - options[name].get = function() return trigger["use_"..realname] ~= nil and trigger[realname] or nil; end - end - - if(arg.required and not triggertype) then - options[name].set = function(info, v) - trigger[realname] = v; - untrigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name] = nil; - order = order - 1; - end - order = order + 1; - elseif(arg.type == "longstring") then - options[name.."_operator"] = { - type = "select", - width = WeakAuras.normalWidth, - name = L["Operator"], - order = order, - hidden = hidden, - values = string_operator_types, - disabled = function() return not trigger["use_"..realname]; end, - get = function() return trigger["use_"..realname] and trigger[realname.."_operator"] or nil; end, - set = function(info, v) - trigger[realname.."_operator"] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name.."_operator"].set = function(info, v) - trigger[realname.."_operator"] = v; - untrigger[realname.."_operator"] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name.."_operator"] = nil; - order = order - 1; - end - order = order + 1; - options[name] = { - type = "input", - width = WeakAuras.doubleWidth, - name = arg.display, - order = order, - hidden = hidden, - validate = validate, - disabled = function() return not trigger["use_"..realname]; end, - get = function() return trigger["use_"..realname] and trigger[realname] or nil; end, - set = function(info, v) - trigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name].set = function(info, v) - trigger[realname] = v; - untrigger[realname] = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name] = nil; - order = order - 1; - end - order = order + 1; - elseif(arg.type == "spell" or arg.type == "aura" or arg.type == "item") then - if(not arg.required or triggertype ~= "untrigger") then - if (arg.showExactOption) then - options["exact"..name] = { - type = "toggle", - width = WeakAuras.normalWidth - 0.1, - name = L["Exact Spell Match"], - order = order, - hidden = hidden, - get = function() - return trigger["use_exact_"..realname]; - end, - set = function(info, v) - trigger["use_exact_"..realname] = v; - WeakAuras.Add(data); - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end, - }; - order = order + 1; - end - options["icon"..name] = { - type = "execute", - width = 0.1, - name = "", - order = order, - hidden = hidden, - image = function() - if(trigger["use_"..realname] and trigger[realname]) then - if(arg.type == "aura") then - local icon = spellCache.GetIcon(trigger[realname]); - return icon and tostring(icon) or "", 18, 18; - elseif(arg.type == "spell") then - local _, _, icon = GetSpellInfo(trigger[realname] or 0); - return icon and tostring(icon) or "", 18, 18; - elseif(arg.type == "item") then - local _, _, _, _, _, _, _, _, _, icon = GetItemInfo(trigger[realname]); - return icon and tostring(icon) or "", 18, 18; - end - else - return "", 18, 18; - end - end, - disabled = function() return not ((arg.type == "aura" and trigger[realname] and spellCache.GetIcon(trigger[realname])) or (arg.type == "spell" and trigger[realname] and GetSpellInfo(trigger[realname] or 0)) or (arg.type == "item" and trigger[realname] and GetItemIcon(trigger[realname]))) end - }; - order = order + 1; - options[name] = { - type = "input", - width = WeakAuras.doubleWidth, - name = arg.display, - order = order, - hidden = hidden, - validate = validate, - disabled = function() return not trigger["use_"..realname]; end, - get = function() - if(arg.type == "item") then - if(trigger["use_"..realname] and trigger[realname] and trigger[realname] ~= "") then - local name = GetItemInfo(trigger[realname]); - if(name) then - return name; - else - local itemId = tonumber(trigger[realname]) - if itemId and itemId ~= 0 then - return tostring(trigger[realname]) - end - return L["Invalid Item Name/ID/Link"]; - end - else - return nil; - end - elseif(arg.type == "spell") then - local useExactSpellId = (arg.showExactOption and trigger["use_exact_"..realname]) or arg.forceExactOption - if(trigger["use_"..realname]) then - if (trigger[realname] and trigger[realname] ~= "") then - if useExactSpellId then - local spellId = tonumber(trigger[realname]) - if (spellId and spellId ~= 0) then - return tostring(spellId); - end - else - local name = GetSpellInfo(trigger[realname] or 0); - if(name) then - return name; - end - end - end - return useExactSpellId and L["Invalid Spell ID"] or (arg.conditionType == "string" and L["Invalid Spell Name/Link"] or L["Invalid Spell Name/ID/Link"]); - else - return nil; - end - else - return trigger["use_"..realname] and trigger[realname] or nil; - end - end, - set = function(info, v) - local fixedInput = v; - if(arg.type == "aura") then - fixedInput = WeakAuras.spellCache.CorrectAuraName(v); - elseif(arg.type == "spell") then - fixedInput = WeakAuras.CorrectSpellName(v); - elseif(arg.type == "item") then - fixedInput = WeakAuras.CorrectItemName(v); - end - trigger[realname] = fixedInput; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - order = order + 1; - end - elseif(arg.type == "select" or arg.type == "unit") then - local values; - if(type(arg.values) == "function") then - values = arg.values(trigger); - else - values = WeakAuras[arg.values]; - end - options[name] = { - type = "select", - width = WeakAuras.normalWidth, - name = arg.display, - order = order, - hidden = hidden, - values = values, - disabled = function() return not trigger["use_"..realname]; end, - get = function() - if(arg.type == "unit" and trigger["use_specific_"..realname]) then - return "member"; - end - - if (not trigger["use_"..realname]) then - return nil; - end - - if (arg.default and (not trigger[realname] or not values[trigger[realname]])) then - trigger[realname] = arg.default; - return arg.default; - end - - return trigger[realname] or nil; - end, - set = function(info, v) - trigger[realname] = v; - if(arg.type == "unit" and v == "member") then - trigger["use_specific_"..realname] = true; - trigger[realname] = UnitName("player"); - else - trigger["use_specific_"..realname] = nil; - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name].set = function(info, v) - trigger[realname] = v; - if(arg.type == "unit" and v == "member") then - trigger["use_specific_"..realname] = true; - else - trigger["use_specific_"..realname] = nil; - end - untrigger[realname] = v; - if(arg.type == "unit" and v == "member") then - untrigger["use_specific_"..realname] = true; - else - untrigger["use_specific_"..realname] = nil; - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - elseif(arg.required and triggertype == "untrigger") then - options[name] = nil; - order = order - 1; - end - if (arg.control) then - options[name].control = arg.control; - end - order = order + 1; - if(arg.type == "unit" and not (arg.required and triggertype == "untrigger")) then - options["use_specific_"..name] = { - type = "toggle", - width = WeakAuras.normalWidth, - name = L["Specific Unit"], - order = order, - hidden = function() return (not trigger["use_specific_"..realname] and trigger[realname] ~= "member") or (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) end, - get = function() return true end, - set = function(info, v) - trigger["use_specific_"..realname] = nil; - options[name].set(info, "player"); - end - } - order = order + 1; - options["specific_"..name] = { - type = "input", - width = WeakAuras.normalWidth, - name = L["Specific Unit"], - desc = L["Can be a UID (e.g., party1)."], - order = order, - hidden = function() return (not trigger["use_specific_"..realname] and trigger[realname] ~= "member") or (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) end, - get = function() return trigger[realname] end, - set = function(info, v) - trigger[realname] = v; - if(arg.required and not triggertype) then - untrigger[realname] = v; - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - end - }; - order = order + 1; - end - elseif(arg.type == "multiselect") then - local values; - if(type(arg.values) == "function") then - values = arg.values(trigger); - else - values = WeakAuras[arg.values]; - end - options[name] = { - type = "select", - width = WeakAuras.normalWidth, - name = arg.display, - order = order, - values = values, - control = arg.control, - hidden = function() - return (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) or trigger["use_"..realname] == false; - end, - disabled = function() return not trigger["use_"..realname]; end, - get = function() return trigger["use_"..realname] and trigger[realname] and trigger[realname].single or nil; end, - set = function(info, v) - trigger[realname] = trigger[realname] or {}; - trigger[realname].single = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name].set = function(info, v) - trigger[realname].single = v; - untrigger[realname].single = v; - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - end - - options["multiselect_"..name] = { - type = "multiselect", - name = arg.display, - width = WeakAuras.doubleWidth, - order = order, - hidden = function() return (type(hidden) == "function" and hidden(trigger)) or (type(hidden) ~= "function" and hidden) or trigger["use_"..realname] ~= false; end, - values = values, - get = function(info, v) - if(trigger["use_"..realname] == false and trigger[realname] and trigger[realname].multi) then - return trigger[realname].multi[v]; - end - end, - set = function(info, v, calledFromSetAll) - trigger[realname].multi = trigger[realname].multi or {}; - if (calledFromSetAll) then - trigger[realname].multi[v] = calledFromSetAll; - elseif(trigger[realname].multi[v]) then - trigger[realname].multi[v] = nil; - else - trigger[realname].multi[v] = true; - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - }; - if(arg.required and not triggertype) then - options[name].set = function(info, v) - if(trigger[realname].multi[v]) then - trigger[realname].multi[v] = nil; - else - trigger[realname].multi[v] = true; - end - if(untrigger[realname].multi[v]) then - untrigger[realname].multi[v] = nil; - else - untrigger[realname].multi[v] = true; - end - WeakAuras.Add(data); - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.SortDisplayButtons(); - end - end - - if(arg.required and triggertype == "untrigger") then - options[name] = nil; - options["multiselect_"..name] = nil; - else - order = order + 1; - end - end - end - end - - if not(triggertype or prototype.automaticrequired) then - options.unevent = { - type = "select", - width = WeakAuras.doubleWidth, - name = L["Hide"], - order = order - }; - order = order + 1; - if(unevent == "timed") then - options.unevent.width = WeakAuras.normalWidth; - options.duration = { - type = "input", - width = WeakAuras.normalWidth, - name = L["Duration (s)"], - order = order - } - order = order + 1; - else - options.unevent.width = WeakAuras.doubleWidth; - end - - if(unevent == "custom") then - local unevent_options = WeakAuras.ConstructOptions(prototype, data, order, triggernum, "untrigger"); - options = union(options, unevent_options); - end - if (prototype.timedrequired) then - if (type(prototype.timedrequired) == "function") then - local func = prototype.timedrequired - options.unevent.values = function() - if func(trigger) then - return timedeventend_types - else - return eventend_types - end - end - else - options.unevent.values = timedeventend_types; - end - elseif (prototype.automatic) then - options.unevent.values = autoeventend_types; - else - options.unevent.values = eventend_types; - end - end - - WeakAuras.option = options; - return options; -end - local frame; local db; local odb; -local options; -local newOptions; -local loadedOptions; -local unloadedOptions; local reopenAfterCombat = false; local loadedFrame = CreateFrame("FRAME"); loadedFrame:RegisterEvent("ADDON_LOADED"); @@ -1110,6 +242,7 @@ function WeakAuras.MultipleDisplayTooltipMenu() childData.parent = data.id; WeakAuras.Add(data); WeakAuras.Add(childData); + WeakAuras.ClearOptions(childData.id) end for index, id in pairs(data.controlledChildren) do @@ -1121,7 +254,6 @@ function WeakAuras.MultipleDisplayTooltipMenu() local button = WeakAuras.GetDisplayButton(data.id); button.callbacks.UpdateExpandButton(); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadGroupRegionOptions(data); WeakAuras.SortDisplayButtons(); button:Expand(); end @@ -1157,7 +289,6 @@ function WeakAuras.MultipleDisplayTooltipMenu() local button = WeakAuras.GetDisplayButton(data.id); button.callbacks.UpdateExpandButton(); WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadGroupRegionOptions(data); WeakAuras.SortDisplayButtons(); button:Expand(); WeakAuras.PickDisplay(data.id); @@ -1253,6 +384,7 @@ function WeakAuras.DeleteOption(data, massDelete) end WeakAuras.CollapseAllClones(id); + WeakAuras.ClearOptions(id) frame:ClearPicks(); WeakAuras.Delete(data); @@ -1270,7 +402,7 @@ function WeakAuras.DeleteOption(data, massDelete) end end WeakAuras.Add(parentData); - WeakAuras.ReloadOptions2(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id); WeakAuras.UpdateDisplayButton(parentData); end end @@ -1296,7 +428,7 @@ StaticPopupDialogs["WEAKAURAS_CONFIRM_DELETE"] = { end parentButton:SetNormalTooltip() WeakAuras.Add(parentData) - WeakAuras.ReloadOptions2(parentData) + WeakAuras.ClearAndUpdateOptions(parentData.id) WeakAuras.UpdateDisplayButton(parentData) end end @@ -1340,7 +472,7 @@ function WeakAuras.ToggleOptions(msg) if(frame and frame:IsVisible()) then WeakAuras.HideOptions(); elseif (InCombatLockdown()) then - prettyPrint(L["Options will open after combat ends."]) + WeakAuras.prettyPrint(L["Options will open after combat ends."]) reopenAfterCombat = true; else WeakAuras.ShowOptions(msg); @@ -1354,8 +486,6 @@ function WeakAuras.UpdateCloneConfig(data) cloneRegion = WeakAuras.EnsureClone(data.id, 2); cloneRegion:Expand(); - - WeakAuras.SetIconNames(data); end end @@ -1369,7 +499,6 @@ function WeakAuras.ShowOptions(msg) if (firstLoad) then frame = WeakAuras.CreateFrame(); frame.buttonsScroll.frame:Show(); - WeakAuras.AddOption(tempGroup.id, tempGroup); WeakAuras.LayoutDisplayButtons(msg); end frame.buttonsScroll.frame:Show(); @@ -1429,28 +558,6 @@ function WeakAuras.IsOptionsOpen() end end -function WeakAuras.SetIconNames(data) - WeakAuras.SetIconName(data, WeakAuras.regions[data.id].region); - - if(WeakAuras.clones[data.id]) then - for index, cloneRegion in pairs(WeakAuras.clones[data.id]) do - WeakAuras.SetIconName(data, cloneRegion); - end - end -end - -function WeakAuras.SetIconName(data, region) - local name, icon = WeakAuras.GetNameAndIcon(data); - WeakAuras.transmitCache[data.id] = icon; - - if(region.SetIcon) then - region:SetIcon(icon); - end - if(region.SetName) then - region:SetName(name); - end -end - function WeakAuras.GetSortedOptionsLists() local loadedSorted, unloadedSorted = {}, {}; local to_sort = {}; @@ -1496,36 +603,6 @@ function WeakAuras.GetSortedOptionsLists() return loadedSorted, unloadedSorted; end -function WeakAuras.BuildOptions(list, callback) - frame:SetLoadProgressVisible(true) - - local total = 0; - for _,_ in pairs(list) do - total = total + 1; - end - - local func = function() - local num = 0; - for id, data in pairs(list) do - if(data) then - if not(data.regionType == "group" or data.regionType == "dynamicgroup") then - WeakAuras.AddOption(id, data); - num = num + 1; - end - end - frame.loadProgress:SetText(L["Creating options: "]..num.."/"..total); - - coroutine.yield(); - end - - callback(); - frame:SetLoadProgressVisible(false) - end - - local co = coroutine.create(func); - dynFrame:AddAction("BuildOptions", co); -end - function WeakAuras.LayoutDisplayButtons(msg) local total = 0; for _,_ in pairs(db.displays) do @@ -1551,7 +628,6 @@ function WeakAuras.LayoutDisplayButtons(msg) WeakAuras.UpdateDisplayButton(data); frame.buttonsScroll:AddChild(displayButtons[data.id]); - WeakAuras.SetIconNames(data); if(WeakAuras.regions[data.id].region.SetStacks) then WeakAuras.regions[data.id].region:SetStacks(1); end @@ -1601,7 +677,6 @@ function WeakAuras.LayoutDisplayButtons(msg) local button = displayButtons[data.id] frame.buttonsScroll:AddChild(button); - WeakAuras.SetIconNames(data); if(WeakAuras.regions[data.id].region.SetStacks) then WeakAuras.regions[data.id].region:SetStacks(1); end @@ -1628,1194 +703,29 @@ function WeakAuras.LayoutDisplayButtons(msg) dynFrame:AddAction("LayoutDisplayButtons1", co1); end - -local function removeFuncs(intable) - for i,v in pairs(intable) do - if(i == "get" or i == "set" or i == "hidden" or i == "disabled") then - intable[i] = nil; - elseif(type(v) == "table" and i ~= "values") then - removeFuncs(v); - end - end +function WeakAuras.UpdateOptions() + frame:UpdateOptions() end -local function hiddenChild(childOptionTable, info) - for i=#childOptionTable,0,-1 do - if(childOptionTable[i].hidden ~= nil) then - if(type(childOptionTable[i].hidden) == "boolean") then - return childOptionTable[i].hidden; - elseif(type(childOptionTable[i].hidden) == "function") then - return childOptionTable[i].hidden(info); - end - end - end - return false; +function WeakAuras.ClearAndUpdateOptions(id, clearChildren) + frame:ClearAndUpdateOptions(id, clearChildren) end -local function disabledChild(childOptionTable, info) - for i=#childOptionTable,0,-1 do - if(childOptionTable[i].disabled ~= nil) then - if(type(childOptionTable[i].disabled) == "boolean") then - return childOptionTable[i].disabled; - elseif(type(childOptionTable[i].disabled) == "function") then - return childOptionTable[i].disabled(info); - end - end - end - return false; +function WeakAuras.ClearOptions(id) + frame:ClearOptions(id) end -local function disabeldOrHiddenChild(childOptionTable, info) - return hiddenChild(childOptionTable, info) or disabledChild(childOptionTable, info); +function WeakAuras.FillOptions() + frame:FillOptions() end -local function getChildOption(displayOptions, info) - for i=1,#info do - displayOptions = displayOptions.args[info[i]]; - if not(displayOptions) then - return nil; - end - - if (displayOptions.hidden) then - local type = type(displayOptions.hidden); - if (type == "bool") then - if (displayOptions.hidden) then - return nil; - end - elseif (type == "function") then - if (displayOptions.hidden(info)) then - return nil; - end - end - end - - end - return displayOptions +function WeakAuras.GetSubOptions(id, subOption) + return frame:GetSubOptions(id, subOption) end -local function getAll(data, info, ...) - local combinedValues = {}; - local first = true; - local debug = false; - local isToggle = nil - for index, childId in ipairs(data.controlledChildren) do - if isToggle == nil then - local childOptions = getChildOption(displayOptions[childId], info) - isToggle = childOptions and childOptions.type == "toggle" - end - - local childData = WeakAuras.GetData(childId); - - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - local childOption = childOptions; - local childOptionTable = {[0] = childOption}; - for i=1,#info do - childOption = childOption.args[info[i]]; - childOptionTable[i] = childOption; - end - - if (childOption and not hiddenChild(childOptionTable, info)) then - for i=#childOptionTable,0,-1 do - if(childOptionTable[i].get) then - local values = {childOptionTable[i].get(info, ...)}; - if isToggle and values[1] == nil then - values[1] = false - end - if(first) then - combinedValues = values; - first = false; - else - local same = true; - if(#combinedValues == #values) then - for j=1,#combinedValues do - if(type(combinedValues[j]) == "number" and type(values[j]) == "number") then - if((math.floor(combinedValues[j] * 100) / 100) ~= (math.floor(values[j] * 100) / 100)) then - same = false; - break; - end - else - if(combinedValues[j] ~= values[j]) then - same = false; - break; - end - end - end - else - same = false; - end - if not(same) then - return nil; - end - end - break; - end - end - end - end - if (debug) then print(" \n") end - end - return unpack(combinedValues); +function WeakAuras.EnsureOptions(data, subOption) + return frame:EnsureOptions(data, subOption) end -WeakAuras.getAll = getAll - -local function setAll(data, info, ...) - WeakAuras.pauseOptionsProcessing(true); - WeakAuras.PauseAllDynamicGroups() - local before = getAll(data, info, ...) - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - local childOption = childOptions; - local childOptionTable = {[0] = childOption}; - for i=1,#info do - childOption = childOption.args[info[i]]; - childOptionTable[i] = childOption; - end - - if (childOption and not disabeldOrHiddenChild(childOptionTable, info)) then - for i=#childOptionTable,0,-1 do - if(childOptionTable[i].set) then - if (childOptionTable[i].type == "multiselect") then - childOptionTable[i].set(info, ..., not before); - else - childOptionTable[i].set(info, ...); - end - break; - end - end - end - end - end - - WeakAuras.ResumeAllDynamicGroups() - WeakAuras.pauseOptionsProcessing(false); - WeakAuras.ScanForLoads(); - WeakAuras.SortDisplayButtons(); -end -WeakAuras.setAll = setAll - -local function hiddenAll(data, info) - if(#data.controlledChildren == 0 and info[1] ~= "group") then - return true; - end - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - local childOption = childOptions; - local childOptionTable = {[0] = childOption}; - for i=1,#info do - childOption = childOption.args[info[i]]; - childOptionTable[i] = childOption; - end - if (childOption) then - if (not hiddenChild(childOptionTable, info)) then - return false; - end - end - end - end - - return true; -end - - - -local function disabledAll(data, info) - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - local childOption = childOptions; - local childOptionTable = {[0] = childOption}; - for i=1,#info do - childOption = childOption.args[info[i]]; - childOptionTable[i] = childOption; - end - if (childOption) then - if (not disabledChild(childOptionTable, info)) then - return false; - end - end - end - end - - return true; -end - -local function replaceNameDescFuncs(intable, data) - - local function compareTables(tableA, tableB) - if(#tableA == #tableB) then - for j=1,#tableA do - if(type(tableA[j]) == "number" and type(tableB[j]) == "number") then - if((math.floor(tableA[j] * 100) / 100) ~= (math.floor(tableB[j] * 100) / 100)) then - return false; - end - else - if(tableA[j] ~= tableB[j]) then - return false; - end - end - end - else - return false; - end - return true; - end - - local function getValueFor(displayOptions, info, key) - local childOptionTable = {[0] = displayOptions}; - for i=1,#info do - displayOptions = displayOptions.args[info[i]]; - if (not displayOptions) then - return nil; - end - childOptionTable[i] = displayOptions; - end - - if (hiddenChild(childOptionTable, info)) then - return nil; - end - - for i=#childOptionTable,0,-1 do - if(childOptionTable[i][key]) then - return childOptionTable[i][key]; - end - end - return nil; - end - - local function combineKeys(info) - local combinedKeys = nil; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - - local values = getValueFor(displayOptions[childId], info, "values"); - if (values) then - if (type(values) == "function") then - values = values(info); - end - if (type(values) == "table") then - combinedKeys = combinedKeys or {}; - for k, v in pairs(values) do - combinedKeys[k] = v; - end - end - end - end - end - return combinedKeys; - end - - local function regionPrefix(input) - local index = string.find(input, ".", 1, true); - if (index) then - local regionType = string.sub(input, 1, index - 1); - return regionOptions[regionType] and regionType; - end - return nil; - end - - local function sameAll(info) - local combinedValues = {}; - local first = true; - local combinedKeys = combineKeys(info); - - local isToggle = nil - - for index, childId in ipairs(data.controlledChildren) do - if isToggle == nil then - local childOption = getChildOption(displayOptions[childId], info) - isToggle = childOption and childOption.type == "toggle" - end - - local childData = WeakAuras.GetData(childId); - - local regionType = regionPrefix(info[#info]); - if(childData and (not regionType or childData.regionType == regionType or regionType == "sub")) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - - local get = getValueFor(displayOptions[childId], info, "get"); - if (combinedKeys) then - for key, _ in pairs(combinedKeys) do - local values = {}; - if (get) then - values = { get(info, key) }; - end - if (combinedValues[key] == nil) then - combinedValues[key] = values; - else - if (not compareTables(combinedValues[key], values)) then - return nil; - end - end - end - else - local values = {}; - if (get) then - values = { get(info) }; - local childOption = getChildOption(displayOptions[childId], info) - if isToggle and values[1] == nil then - values[1] = false - end - end - if(first) then - combinedValues = values; - first = false; - else - if (not compareTables(combinedValues, values)) then - return nil; - end - end - end - end - end - - return true; - end - - local function nameAll(info) - local combinedName; - local first = true; - local foundNames = {}; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOption = getChildOption(displayOptions[childId], info); - if (childOption) then - local name; - if(type(childOption.name) == "function") then - name = childOption.name(info); - else - name = childOption.name; - end - if (not name) then - -- Do nothing - elseif(first) then - if (combinedName ~= "") then - combinedName = name; - first = false; - end - foundNames[name] = true; - elseif not(foundNames[name]) then - if (name ~= "") then - if (childOption.type == "description") then - combinedName = combinedName .. "\n\n" .. name; - else - combinedName = combinedName .. " / " .. name; - end - end - foundNames[name] = true; - end - end - end - end - - return combinedName; - end - - local function descAll(info) - local combinedDesc; - local first = true; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOption = getChildOption(displayOptions[childId], info); - if (childOption) then - local desc; - if(type(childOption.desc) == "function") then - desc = childOption.desc(info); - else - desc = childOption.desc; - end - if(first) then - combinedDesc = desc; - first = false; - elseif not(combinedDesc == desc) then - return L["Not all children have the same value for this option"]; - end - end - end - end - return combinedDesc; - end - - local function recurse(intable) - for i,v in pairs(intable) do - if(i == "name" and type(v) ~= "table") then - intable.name = function(info) - local name = nameAll(info); - if(sameAll(info)) then - return name; - else - if(name == "") then - return name; - else - return "|cFF4080FF"..(name or "error"); - end - end - end - intable.desc = function(info) - if(sameAll(info)) then - return descAll(info); - else - local combinedKeys = nil; - if (intable.type == "multiselect") then - combinedKeys = combineKeys(info) - end - - local values = {}; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOptions = displayOptions[childId]; - local childOption = childOptions; - local childOptionTable = {[0] = childOption}; - for i=1,#info do - childOption = childOption.args[info[i]]; - childOptionTable[i] = childOption; - end - if (childOption and not hiddenChild(childOptionTable, info)) then - for i=#childOptionTable,0,-1 do - if(childOptionTable[i].get) then - if(intable.type == "toggle") then - local name, tri; - if(type(childOption.name) == "function") then - name = childOption.name(info); - tri = true; - else - name = childOption.name; - end - if(tri and childOptionTable[i].get(info)) then - tinsert(values, "|cFFE0E000"..childId..": |r"..name); - elseif(tri) then - tinsert(values, "|cFFE0E000"..childId..": |r"..L["Ignored"]); - elseif(childOptionTable[i].get(info)) then - tinsert(values, "|cFFE0E000"..childId..": |r|cFF00FF00"..L["Enabled"]); - else - tinsert(values, "|cFFE0E000"..childId..": |r|cFFFF0000"..L["Disabled"]); - end - elseif(intable.type == "color") then - local r, g, b = childOptionTable[i].get(info); - r, g, b = r or 1, g or 1, b or 1; - tinsert(values, ("|cFF%2x%2x%2x%s"):format(r * 220 + 35, g * 220 + 35, b * 220 + 35, childId)); - elseif(intable.type == "select") then - local selectValues = type(intable.values) == "table" and intable.values or intable.values(info); - local key = childOptionTable[i].get(info); - local display = key and selectValues[key] or L["None"]; - if intable.dialogControl == "LSM30_Font" then - tinsert(values, "|cFFE0E000"..childId..": |r" .. key); - else - tinsert(values, "|cFFE0E000"..childId..": |r"..display); - end - elseif(intable.type == "multiselect") then - local selectedValues = {}; - for k, v in pairs(combinedKeys) do - if (childOptionTable[i].get(info, k)) then - tinsert(selectedValues, tostring(v)) - end - end - tinsert(values, "|cFFE0E000"..childId..": |r"..table.concat(selectedValues, ",")); - else - local display = childOptionTable[i].get(info) or L["None"]; - if(type(display) == "number") then - display = math.floor(display * 100) / 100; - else - if #display > 50 then - display = display:sub(1, 50) .. "..." - end - end - tinsert(values, "|cFFE0E000"..childId..": |r"..display); - end - break; - end - end - end - end - end - return table.concat(values, "\n"); - end - end - elseif(type(v) == "table" and i ~= "values") then - recurse(v); - end - end - end - recurse(intable); -end - -local function replaceImageFuncs(intable, data) - local function imageAll(info) - local combinedImage = {}; - local first = true; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOption = displayOptions[childId]; - if not(childOption) then - return "error" - end - childOption = getChildOption(childOption, info); - if childOption and childOption.image then - local image = {childOption.image(info)}; - if(first) then - combinedImage = image; - first = false; - else - if not(combinedImage[1] == image[1]) then - return "", 0, 0; - end - end - end - end - end - - return unpack(combinedImage); - end - - local function recurse(intable) - for i,v in pairs(intable) do - if(i == "image" and type(v) == "function") then - intable[i] = imageAll; - elseif(type(v) == "table" and i ~= "values") then - recurse(v); - end - end - end - recurse(intable); -end - -local function replaceValuesFuncs(intable, data) - local function valuesAll(info) - local combinedValues = {}; - local handledValues = {}; - local first = true; - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - WeakAuras.EnsureOptions(childId); - local childOption = displayOptions[childId]; - if not(childOption) then - return "error" - end - - childOption = getChildOption(childOption, info); - if (childOption) then - local values = childOption.values; - if (type(values) == "function") then - values = values(info); - end - if(first) then - for k, v in pairs(values) do - handledValues[k] = handledValues[k] or {}; - handledValues[k][v] = true; - combinedValues[k] = v; - end - first = false; - else - for k, v in pairs(values) do - if (handledValues[k] and handledValues[k][v]) then - -- Already known key/value pair - else - if (combinedValues[k]) then - combinedValues[k] = combinedValues[k] .. "/" .. v; - else - combinedValues[k] = v; - end - handledValues[k] = handledValues[k] or {}; - handledValues[k][v] = true; - end - end - end - end - end - end - - return combinedValues; - end - - local function recurse(intable) - for i,v in pairs(intable) do - if(i == "values" and type(v) == "function") then - intable[i] = valuesAll; - elseif(type(v) == "table" and i ~= "values") then - recurse(v); - end - end - end - recurse(intable); -end - -local function GetCustomCode(data, path) - for _, key in ipairs(path) do - if (not data or not data[key]) then - return nil; - end - data = data[key]; - end - return data; -end - --- TODO: find a paradigm which doesn't have five million flags for AddCodeOption so that calls to it don't always go off the screen --- a table of settings is the obvious option to pack the flags. --- alternatively, we could create a "code" type option which then gets processed before sending to AceConfig -function WeakAuras.AddCodeOption(args, data, name, prefix, url, order, hiddenFunc, path, encloseInFunction, multipath, extraSetFunction, extraFunctions, reloadOptions, setOnParent) - extraFunctions = extraFunctions or {}; - tinsert(extraFunctions, 1, { - buttonLabel = L["Expand"], - func = function() - WeakAuras.OpenTextEditor(data, path, encloseInFunction, multipath, reloadOptions, setOnParent, url) - end - }); - - args[prefix .. "_custom"] = { - type = "input", - width = WeakAuras.doubleWidth, - name = name, - order = order, - multiline = true, - hidden = hiddenFunc, - control = "WeakAurasMultiLineEditBox", - arg = { - extraFunctions = extraFunctions, - }, - set = function(info, v) - local subdata = data; - for i = 1, #path -1 do - local key = path[i]; - subdata[key] = subdata[key] or {}; - subdata = subdata[key]; - end - - subdata[path[#path]] = v; - WeakAuras.Add(data); - if (extraSetFunction) then - extraSetFunction(); - end - if (reloadOptions) then - WeakAuras.ScheduleReloadOptions(data); - end - end, - get = function(info) - return GetCustomCode(data, path); - end - }; - - args[prefix .. "_customError"] = { - type = "description", - name = function() - if hiddenFunc() then - return ""; - end - - local code = GetCustomCode(data, path); - - if (not code) then - return "" - end - - if (encloseInFunction) then - code = "function() "..code.."\n end"; - end - - code = "return " .. code; - - local _, errorString = loadstring(code); - return errorString and "|cFFFF0000"..errorString or ""; - end, - width = WeakAuras.doubleWidth, - order = order + 0.002, - hidden = function() - if (hiddenFunc()) then - return true; - end - - local code = GetCustomCode(data, path); - if (not code) then - return true; - end - - if (encloseInFunction) then - code = "function() "..code.."\n end"; - end - - code = "return " .. code; - - local loadedFunction, errorString = loadstring(code); - if(errorString and not loadedFunction) then - return false; - else - return true; - end - end - }; -end - -local function addCollapsibleHeader(options, key, input, order, isGroupTab) - if input.__noHeader then - return - end - local title = input.__title - local hasDelete = input.__delete - local hasUp = input.__up - local hasDown = input.__down - local hasDuplicate = input.__duplicate - local hiddenFunc = input.__hidden - local nooptions = input.__nooptions - local marginTop = input.__topLine - - local titleWidth = WeakAuras.doubleWidth - (hasDelete and 0.15 or 0) - (hasUp and 0.15 or 0) - (hasDown and 0.15 or 0) - (hasDuplicate and 0.15 or 0) - - options[key .. "collapseSpacer"] = { - type = marginTop and "header" or "description", - name = "", - order = order, - width = "full", - hidden = hiddenFunc, - } - options[key .. "collapseButton"] = { - type = "execute", - name = title, - order = order + 0.1, - width = titleWidth, - func = function(info) - if not nooptions then - local isCollapsed = WeakAuras.IsCollapsed("collapse", "region", key, false) - WeakAuras.SetCollapsed("collapse", "region", key, not isCollapsed) - WeakAuras.RefillOptions() - end - end, - image = function() - if nooptions then - return "Interface\\AddOns\\WeakAuras\\Media\\Textures\\bullet1", 18, 18 - else - local isCollapsed = WeakAuras.IsCollapsed("collapse", "region", key, false) - return isCollapsed and "Interface\\AddOns\\WeakAuras\\Media\\Textures\\expand" or "Interface\\AddOns\\WeakAuras\\Media\\Textures\\collapse", 18, 18 - end - end, - control = "WeakAurasExpand", - hidden = hiddenFunc - } - - if hasUp then - options[key .. "upButton"] = { - type = "execute", - name = "", - order = order + 0.3, - width = 0.15, - func = input.__up, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\moveup", - imageWidth = 24, - imageHeight = 24, - hidden = hiddenFunc, - } - end - - if hasDown then - options[key .. "downButton"] = { - type = "execute", - name = "", - order = order + 0.4, - width = 0.15, - func = input.__down, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\movedown", - imageWidth = 24, - imageHeight = 24, - hidden = hiddenFunc - } - end - - if hasDuplicate then - options[key .. "duplicateButton"] = { - type = "execute", - name = "", - order = order + 0.5, - width = 0.15, - func = input.__duplicate, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\duplicate", - imageWidth = 24, - imageHeight = 24, - hidden = hiddenFunc - } - end - - if hasDelete then - options[key .. "deleteButton"] = { - type = "execute", - name = "", - order = order + 0.6, - width = 0.15, - func = input.__delete, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", - imageWidth = 24, - imageHeight = 24, - hidden = hiddenFunc - } - end - - if hiddenFunc then - return function() - return hiddenFunc() or WeakAuras.IsCollapsed("collapse", "region", key, false) - end - else - return function() - return WeakAuras.IsCollapsed("collapse", "region", key, false) - end - end -end - -local function copyOptionTable(input, orderAdjustment, collapsedFunc) - local resultOption = {}; - WeakAuras.DeepCopy(input, resultOption); - resultOption.order = orderAdjustment + resultOption.order; - if collapsedFunc then - local oldHidden = resultOption.hidden; - if oldHidden ~= nil then - local oldFunc - if type(oldHidden) ~= "function" then - oldFunc = function(...) return oldHidden end - else - oldFunc = oldHidden - end - resultOption.hidden = function(...) - if collapsedFunc() then - return true - else - return oldFunc(...) - end - end - else - resultOption.hidden = collapsedFunc; - end - end - return resultOption; -end - -local function flattenRegionOptions(allOptions, isGroupTab) - local result = {}; - local base = 1000; - - for optionGroup, options in pairs(allOptions) do - local groupBase = base * options.__order - - local collapsedFunc = addCollapsibleHeader(result, optionGroup, options, groupBase, isGroupTab) - - for optionName, option in pairs(options) do - if not optionName:find("^__") then - result[optionGroup .. "." .. optionName] = copyOptionTable(option, groupBase, collapsedFunc); - end - end - end - - return result; -end - -local function parsePrefix(input, data, create) - local subRegionIndex, property = string.match(input, "^sub%.(%d+)%..-%.(.+)") - subRegionIndex = tonumber(subRegionIndex) - if subRegionIndex then - if create then - data.subRegions = data.subRegions or {} - data.subRegions[subRegionIndex] = data.subRegions[subRegionIndex] or {} - else - if not data.subRegions or not data.subRegions[subRegionIndex] then - return nil - end - end - return data.subRegions[subRegionIndex], property - end - local index = string.find(input, ".", 1, true); - if (index) then - return data, string.sub(input, index + 1); - end - return data, input -end - -local function AddSubRegionImpl(data, subRegionName) - data.subRegions = data.subRegions or {} - if WeakAuras.subRegionTypes[subRegionName] and WeakAuras.subRegionTypes[subRegionName] then - if WeakAuras.subRegionTypes[subRegionName].supports(data.regionType) then - local default = WeakAuras.subRegionTypes[subRegionName].default - local subRegionData = type(default) == "function" and default(data.regionType) or CopyTable(default) - subRegionData.type = subRegionName - tinsert(data.subRegions, subRegionData) - WeakAuras.Add(data) - WeakAuras.ReloadOptions2(data.id, data) - end - end -end - -local function AddSubRegion(data, subRegionName) - WeakAuras.ApplyToDataOrChildData(data, AddSubRegionImpl, subRegionName) - WeakAuras.ReloadOptions2(data.id, data) -end - -local function AddOptionsForSupportedSubRegion(regionOption, data, supported) - if not next(supported) then - return - end - local hasSubRegions = false - - local result = {} - local order = 1 - result.__order = 300 - result.__title = L["Add Extra Elements"] - result.__topLine = true - for subRegionType in pairs(supported) do - if WeakAuras.subRegionTypes[subRegionType].supportsAdd then - hasSubRegions = true - result[subRegionType .. "space"] = { - type = "description", - width = WeakAuras.doubleWidth, - name = "", - order = order, - } - order = order + 1 - result[subRegionType] = { - type = "execute", - width = WeakAuras.normalWidth, - name = string.format(L["Add %s"], WeakAuras.subRegionTypes[subRegionType].displayName), - order = order, - func = function() - AddSubRegion(data, subRegionType) - end, - } - order = order + 1 - end - end - regionOption["sub"] = result; - return hasSubRegions -end - -function WeakAuras.AddOption(id, data) - local regionOption; - local commonOption = {}; - - local hasSubElements = false - - if(regionOptions[data.regionType]) then - regionOption = regionOptions[data.regionType].create(id, data); - - if data.subRegions then - local subIndex = {} - for index, subRegionData in ipairs(data.subRegions) do - local subRegionType = subRegionData.type - if WeakAuras.subRegionOptions[subRegionType] then - hasSubElements = true - subIndex[subRegionType] = subIndex[subRegionType] and subIndex[subRegionType] + 1 or 1 - local options, common = WeakAuras.subRegionOptions[subRegionType].create(data, subRegionData, index, subIndex[subRegionType]) - options.__order = 200 + index - regionOption["sub." .. index .. "." .. subRegionType] = options - commonOption[subRegionType] = common - end - end - end - - local commonOptionIndex = 0 - for option, optionData in pairs(commonOption) do - commonOptionIndex = commonOptionIndex + 1 - optionData.__order = 100 + commonOptionIndex - regionOption[option] = optionData - end - - local supported = {} - for subRegionName, subRegionType in pairs(WeakAuras.subRegionTypes) do - if subRegionType.supports(data.regionType) then - supported[subRegionName] = true - end - end - hasSubElements = AddOptionsForSupportedSubRegion(regionOption, data, supported) or hasSubElements - else - regionOption = { - [data.regionType] = { - __title = "|cFFFFFF00" .. data.regionType, - __order = 1, - unsupported = { - type = "description", - name = L["This region of type \"%s\" is not supported."]:format(data.regionType), - order = 2, - } - } - }; - end - - if hasSubElements then - regionOption["SubElementsHeader"] = { - __order = 100, - __noHeader = true, - header = { - type = "header", - name = L["Sub Elements"], - order = 1 - } - } - end - - local options = flattenRegionOptions(regionOption, true) - displayOptions[id] = { - type = "group", - childGroups = "tab", - args = { - region = { - type = "group", - name = L["Display"], - order = 10, - get = function(info) - local base, property = parsePrefix(info[#info], data); - if not base then - return nil - end - if(info.type == "color") then - base[property] = base[property] or {}; - local c = base[property]; - return c[1], c[2], c[3], c[4]; - else - return base[property]; - end - end, - set = function(info, v, g, b, a) - local base, property = parsePrefix(info[#info], data, true); - if(info.type == "color") then - base[property] = base[property] or {}; - local c = base[property]; - c[1], c[2], c[3], c[4] = v, g, b, a; - elseif(info.type == "toggle") then - base[property] = v; - else - base[property] = (v ~= "" and v) or nil; - end - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - if(data.parent) then - local parentData = WeakAuras.GetData(data.parent); - if(parentData) then - WeakAuras.Add(parentData); - end - end - WeakAuras.ResetMoverSizer(); - end, - args = options - }, - trigger = { - type = "group", - name = L["Trigger"], - order = 20, - args = {} - }, - conditions = { - type = "group", - name = L["Conditions"], - order = 25, - args = {} - }, - load = { - type = "group", - name = L["Load"], - order = 30, - get = function(info) return data.load[info[#info]] end, - set = function(info, v) - data.load[info[#info]] = (v ~= "" and v) or nil; - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.ScanForLoads({[data.id] = true}); - WeakAuras.SortDisplayButtons(); - end, - args = {} - }, - authorOptions = { - type = "group", - name = L["Custom Options"], - order = 100 - } - } - }; - - displayOptions[id].args.action = WeakAuras.AddActionOption(id, data); - displayOptions[id].args.animation = WeakAuras.AddAnimationOption(id, data); - - WeakAuras.ReloadTriggerOptions(data); -end - --- This is a hack... --- Some options change which options are available, for example toggling the "inverse" --- option of some triggers changes whether "remaining time" is available in the Conditions --- We can't call ReloadOptions from the set call, since that removes the widgets immediately --- which AceConfig doesn't like. --- Thus Reload the options after a very small delay. -function WeakAuras.ScheduleReloadOptions(data) - if (type(data.id) ~= "table") then - WeakAuras.timer:ScheduleTimer(function() - WeakAuras.ReloadOptions(data.id) - end, 0.1); - end -end - -function WeakAuras.ReloadOptions(id) - displayOptions[id] = nil; - WeakAuras.EnsureOptions(id); - WeakAuras.RefillOptions() -end - -function WeakAuras.EnsureOptions(id) - if not(displayOptions[id]) then - WeakAuras.AddOption(id, WeakAuras.GetData(id)); - end -end - -local scheduleRefillFrame = CreateFrame("FRAME", "", UIParent) -scheduleRefillFrame.OnUpdate = function() - for id, data in pairs(scheduleRefillFrame.ids) do - if not(displayOptions[id]) then - WeakAuras.AddOption(id, data); - end - end - wipe(scheduleRefillFrame.ids) - - frame:RefillOptions() - frame:SetScript("OnUpdate", nil) -end - -scheduleRefillFrame.ScheduleRefillOnly = function() - frame:SetScript("OnUpdate", scheduleRefillFrame.OnUpdate) -end -scheduleRefillFrame.ScheduleReload = function(self, id, data) - scheduleRefillFrame.ids[id] = data - scheduleRefillFrame:ScheduleRefillOnly() -end - -scheduleRefillFrame.ids = {} - - --- TODO replace older ReloadOptions, ScheduleReloadOptions, ReloadTriggerOptions, ReloadGroupRegionOptions --- automatically clear parent/tempGroup ? -function WeakAuras.ReloadOptions2(id, data) - displayOptions[id] = nil - scheduleRefillFrame:ScheduleReload(id, data) -end - -function WeakAuras.RefillOptions() - frame:RefillOptions() -end - -function WeakAuras.ScheduleRefillOptions() - scheduleRefillFrame:ScheduleRefillOnly() -end - function WeakAuras.GetSpellTooltipText(id) local tooltip = WeakAuras.GetHiddenTooltip(); @@ -2839,1127 +749,6 @@ function WeakAuras.GetSpellTooltipText(id) return tooltipText; end -local function DeleteConditionsForTriggerHandleSubChecks(checks, triggernum) - for _, check in ipairs(checks) do - if (check.trigger == triggernum) then - check.trigger = nil; - end - - if (check.trigger and check.trigger > triggernum) then - check.trigger = check.trigger - 1; - end - - if (checks.checks) then - DeleteConditionsForTriggerHandleSubChecks(checks.checks, triggernum); - end - end -end - -function WeakAuras.DeleteConditionsForTrigger(data, triggernum) - for _, condition in ipairs(data.conditions) do - if (condition.check and condition.check.trigger == triggernum) then - condition.check.trigger = nil; - end - - if (condition.check and condition.check.trigger and condition.check.trigger > triggernum) then - condition.check.trigger = condition.check.trigger - 1; - end - - if (condition.check and condition.check.checks) then - DeleteConditionsForTriggerHandleSubChecks(condition.check.checks, triggernum) - end - end -end - -function WeakAuras.ReloadTriggerOptions(data) - local id = data.id; - local iconCache = spellCache.Get(); - WeakAuras.EnsureOptions(id); - - local appendToTriggerPath, appendToUntriggerPath; - if(data.controlledChildren) then - optionTriggerChoices[id] = nil; - for index, childId in pairs(data.controlledChildren) do - if not(optionTriggerChoices[id]) then - optionTriggerChoices[id] = optionTriggerChoices[childId]; - else - if(optionTriggerChoices[id] ~= optionTriggerChoices[childId]) then - optionTriggerChoices[id] = -1; - break; - end - end - end - - optionTriggerChoices[id] = optionTriggerChoices[id] or 1; - - local commonOptionTriggerChoice = optionTriggerChoices[id] >= 1 and optionTriggerChoices[id]; - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - optionTriggerChoices[childId] = commonOptionTriggerChoice or optionTriggerChoices[childId] or 1; - WeakAuras.ReloadTriggerOptions(childData); - end - end - else - optionTriggerChoices[id] = min(optionTriggerChoices[id] or 1, #data.triggers); - local triggerChoice = optionTriggerChoices[id] - -- TODO: remove this once legacy aura trigger is removed - local button = displayButtons[id] - if (button) then - button:RefreshBT2UpgradeIcon() - end - end - - local function deleteTrigger() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - if #childData.triggers > 1 then - tremove(childData.triggers, optionTriggerChoices[childId]) - WeakAuras.DeleteConditionsForTrigger(childData, optionTriggerChoices[childId]); - optionTriggerChoices[childId] = max(1, optionTriggerChoices[childId] - 1) - WeakAuras.ReloadTriggerOptions(childData); - end - end - end - else - tremove(data.triggers, optionTriggerChoices[id]) - WeakAuras.DeleteConditionsForTrigger(data, optionTriggerChoices[id]); - optionTriggerChoices[id] = max(1, optionTriggerChoices[id] - 1) - end - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - end - - local function moveTriggerDownConditionCheck(check, i) - if (check.trigger == i) then - check.trigger = i + 1; - elseif (check.trigger == i + 1) then - check.trigger = i; - end - if (check.checks) then - for _, subCheck in ipairs(check.checks) do - moveTriggerDownConditionCheck(subCheck, i); - end - end - end - - local function moveTriggerDownImpl(data, i) - if (i < 1 or i >= #data.triggers) then - return false; - end - data.triggers[i], data.triggers[i + 1] = data.triggers[i + 1], data.triggers[i] - for _, condition in ipairs(data.conditions) do - moveTriggerDownConditionCheck(condition.check, i); - end - - return true; - end - - local function moveTriggerDown(data, i) - if (moveTriggerDownImpl(data, i)) then - optionTriggerChoices[data.id] = optionTriggerChoices[data.id] + 1; - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - end - end - - local function moveTriggerUp(data, i) - if (moveTriggerDownImpl(data, i - 1)) then - optionTriggerChoices[data.id] = optionTriggerChoices[data.id] - 1; - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - end - end - - - local chooseTriggerWidth = 1.2; - if (data.controlledChildren) then - local hasMultipleTriggers = false; - for index, id in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(id); - if (#childData.triggers ~=1) then - hasMultipleTriggers = true; - break; - end - end - if (not hasMultipleTriggers) then - chooseTriggerWidth = chooseTriggerWidth + 0.45; - end - else - if (#data.triggers == 1) then - chooseTriggerWidth = chooseTriggerWidth + 0.45; - end - end - - local _, _, _, enabled = GetAddOnInfo("WeakAurasTemplates") - if (not enabled) then - chooseTriggerWidth = chooseTriggerWidth + 0.15; - end - - local trigger; - if (not data.controlledChildren) then - local triggerNum = optionTriggerChoices[id]; - trigger = data.triggers[triggerNum].trigger; - end - - local trigger_types = {}; - for type, triggerSystem in pairs(WeakAuras.triggerTypes) do - trigger_types[type] = triggerSystem.GetName(type); - end - local trigger_options = { - disjunctive = { - type = "select", - name = L["Required for Activation"], - width = WeakAuras.doubleWidth, - order = 0, - values = function() - if #data.triggers > 1 then - return WeakAuras.trigger_require_types; - else - return WeakAuras.trigger_require_types_one; - end - end, - get = function() - if #data.triggers > 1 then - return data.triggers.disjunctive or "all"; - else - return (data.triggers.disjunctive and data.triggers.disjunctive ~= "all") and data.triggers.disjunctive or "any"; - end - end, - set = function(info, v) - data.triggers.disjunctive = v; - WeakAuras.Add(data); - end - }, - -- custom trigger combiner text editor added below - activeTriggerMode = { - type = "select", - name = L["Dynamic Information"], - width = WeakAuras.doubleWidth, - order = 0.3, - values = function() - local vals = {}; - vals[WeakAuras.trigger_modes.first_active] = L["Dynamic information from first active trigger"]; - for i = 1, #data.triggers do - vals[i] = L["Dynamic information from Trigger %i"]:format(i); - end - return vals; - end, - get = function() - return data.triggers.activeTriggerMode or WeakAuras.trigger_modes.first_active; - end, - set = function(info, v) - data.triggers.activeTriggerMode = v; - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - end, - hidden = function() return #data.triggers <= 1 end - }, - chooseTrigger = { - type = "select", - name = L["Choose Trigger"], - order = 0.5, - values = function() - local ret = {}; - if(data.controlledChildren) then - for index = 1, #data.triggers do - local all, none, any = true, true, false; - for _, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - none = false; - if childData.triggers[index] then - any = true; - else - all = false; - end - end - end - if not(none) then - if(all) then - ret[index] = L["Trigger %d"]:format(index); - elseif(any) then - ret[index] = "|cFF777777"..L["Trigger %d"]:format(index); - end - end - end - else - for i = 1, #data.triggers do - ret[i] = L["Trigger %d"]:format(i); - end - end - return ret; - end, - get = function() return optionTriggerChoices[id]; end, - set = function(info, v) - if data.triggers[v] then - optionTriggerChoices[id] = v; - WeakAuras.ReloadTriggerOptions(data); - end - end, - width = chooseTriggerWidth - }, - chooseTriggerSpace = { - type = "description", - name = "", - order = 0.75, - width = 0.04 - }, - addTrigger = { - type = "execute", - name = L["Add Trigger"], - order = 1, - func = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - tinsert(childData.triggers, {trigger = {}, untrigger = {}}); - optionTriggerChoices[childId] = #childData.triggers; - WeakAuras.ReloadTriggerOptions(childData); - end - end - else - tinsert(data.triggers, {trigger = {}, untrigger = {}}); - optionTriggerChoices[id] = #data.triggers; - end - WeakAuras.ReloadTriggerOptions(data); - end, - width = 0.15, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\add", - imageWidth = 24, - imageHeight = 24, - control = "WeakAurasIcon" - }, - deleteTrigger = { - type = "execute", - name = L["Delete Trigger"], - order = 1.1, - func = deleteTrigger, - hidden = function() - return #data.triggers < 2 - end, - width = 0.15, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\delete", - imageWidth = 24, - imageHeight = 24, - control = "WeakAurasIcon" - }, - triggerUp = { - type = "execute", - name = L["Up"], - order = 1.2, - func = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - moveTriggerUp(childData, optionTriggerChoices[childId]) - end - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - else - moveTriggerUp(data, optionTriggerChoices[id]) - end - end, - disabled = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - if (optionTriggerChoices[childId] ~= 1) then - return false; - end - end - end - return true; - else - if (optionTriggerChoices[id] == 1) then - return true; - else - return false; - end - end - end, - hidden = function() - return #data.triggers < 2 - end, - width = 0.15, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\moveup", - imageWidth = 24, - imageHeight = 24, - control = "WeakAurasIcon" - }, - triggerDown = { - type = "execute", - name = L["Down"], - order = 1.3, - func = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - moveTriggerDown(childData, optionTriggerChoices[childId]); - end - WeakAuras.Add(data); - WeakAuras.ReloadTriggerOptions(data); - else - moveTriggerDown(data, optionTriggerChoices[id]); - end - end, - disabled = function() - if(data.controlledChildren) then - for index, childId in pairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if(childData) then - if (optionTriggerChoices[childId] ~= #childData.triggers) then - return false; - end - end - end - return true; - else - if (optionTriggerChoices[id] ~= #data.triggers) then - return false; - else - return true; - end - end - end, - hidden = function() - return #data.triggers < 2 - end, - width = 0.15, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\movedown", - imageWidth = 24, - imageHeight = 24, - control = "WeakAurasIcon" - }, - applyTemplate = { - type = "execute", - name = L["Apply Template"], - order = 1.4, - func = function() - WeakAuras.OpenTriggerTemplate(data); - end, - hidden = function() - return not select(4, GetAddOnInfo("WeakAurasTemplates")) - end, - width = 0.15, - image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\template", - imageWidth = 24, - imageHeight = 24, - control = "WeakAurasIcon" - }, - triggerHeader = { - type = "header", - name = function(info) - if(info == "default") then - return L["Multiple Triggers"]; - else - return L["Trigger %d"]:format(optionTriggerChoices[id]); - end - end, - order = 2 - }, - typedesc = { - type = "toggle", - width = WeakAuras.normalWidth, - name = L["Type"], - order = 5, - disabled = true, - get = function() return true end - }, - type = { - type = "select", - width = WeakAuras.normalWidth, - name = L["Type"], - desc = L["The type of trigger"], - order = 6, - values = trigger_types, - set = function(info, v) - trigger.type = v; - if(trigger.event) then - local prototype = WeakAuras.event_prototypes[trigger.event]; - if(prototype) then - if(v == "status" and prototype.type == "event") then - trigger.event = "Health"; - elseif(v == "event" and prototype.type == "status") then - trigger.event = "Chat Message"; - end - end - end - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadTriggerOptions(data); - end - }, - }; - - local function hideTriggerCombiner() - return not (data.triggers.disjunctive == "custom") - end - WeakAuras.AddCodeOption(trigger_options, data, L["Custom"], "custom_trigger_combination", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-activation", - 0.1, hideTriggerCombiner, {"triggers", "customTriggerLogic"}, false); - - local order = 81; - - if(data.controlledChildren) then - local function options_set(info, ...) - setAll(data, info, ...); - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadTriggerOptions(data); - end - - local commontriggerSystemOptionsFunction = nil; - local first = true; - - local anyOldAuraTriggers = false; - for index, childId in ipairs(data.controlledChildren) do - local triggerChoice = optionTriggerChoices[childId]; - local childData = WeakAuras.GetData(childId); - local trigger = triggerChoice and childData.triggers[triggerChoice].trigger; - local triggerSystemOptionsFunction = trigger.type and WeakAuras.triggerTypesOptions[trigger.type]; - if (trigger.type == "aura") then - anyOldAuraTriggers = true; - end - if (triggerSystemOptionsFunction) then - if (first) then - commontriggerSystemOptionsFunction = triggerSystemOptionsFunction - first = false; - elseif(commontriggerSystemOptionsFunction ~= triggerSystemOptionsFunction) then - commontriggerSystemOptionsFunction = nil; - end - end - end - - if (commontriggerSystemOptionsFunction) then - trigger_options = union(trigger_options, commontriggerSystemOptionsFunction(data, optionTriggerChoices)); - end - if (anyOldAuraTriggers) then - trigger_options = union(trigger_options, WeakAuras.GetBuffConversionOptions(data, optionTriggerChoices)); - end - displayOptions[id].args.trigger.args = trigger_options; - - removeFuncs(displayOptions[id]); - replaceNameDescFuncs(displayOptions[id], data); - replaceImageFuncs(displayOptions[id], data); - replaceValuesFuncs(displayOptions[id], data); - - displayOptions[id].get = function(info, ...) return getAll(data, info, ...); end; - displayOptions[id].set = function(info, ...) - setAll(data, info, ...); - if(type(id) == "string") then - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.ResetMoverSizer(); - end - end - displayOptions[id].hidden = function(info, ...) return hiddenAll(data, info, ...); end; - displayOptions[id].disabled = function(info, ...) return disabledAll(data, info, ...); end; - - displayOptions[id].args.trigger.args.chooseTrigger.set = options_set; - if (displayOptions[id].args.trigger.args.type) then - displayOptions[id].args.trigger.args.type.set = options_set; - end - if (displayOptions[id].args.trigger.args.event) then - displayOptions[id].args.trigger.args.event.set = options_set; - end - - local regionOption; - if (regionOptions[data.regionType]) then - regionOption = regionOptions[data.regionType].create(id, data); - else - regionOption = { - [data.regionType] = { - __title = "|cFFFFFF00" .. data.regionType, - __order = 1, - unsupported = { - type = "description", - name = L["This region of type \"%s\" is not supported."]:format(data.regionType) - } - }; - }; - end - displayOptions[id].args.group = { - type = "group", - name = L["Group"], - order = 0, - get = function(info) - local base, property = parsePrefix(info[#info], data); - if not base then - return nil - end - if(info.type == "color") then - base[property] = base[property] or {}; - local c = base[property]; - return c[1], c[2], c[3], c[4]; - else - return base[property]; - end - end, - set = function(info, v, g, b, a) - local base, property = parsePrefix(info[#info], data, true); - if(info.type == "color") then - base[property] = base[property] or {}; - local c = base[property]; - c[1], c[2], c[3], c[4] = v, g, b, a; - elseif(info.type == "toggle") then - base[property] = v; - else - base[property] = (v ~= "" and v) or nil; - end - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.ResetMoverSizer(); - end, - hidden = function() return false end, - disabled = function() return false end, - args = flattenRegionOptions(regionOption, true); - }; - - data.load.use_class = getAll(data, {"load", "use_class"}); - local single_class = getAll(data, {"load", "class"}); - data.load.class = { - single = single_class, - multi = {}, - } - - displayOptions[id].args.load.args = WeakAuras.ConstructOptions(WeakAuras.load_prototype, data, 10, optionTriggerChoices[id], "load"); - removeFuncs(displayOptions[id].args.load); - replaceNameDescFuncs(displayOptions[id].args.load, data); - replaceImageFuncs(displayOptions[id].args.load, data); - replaceValuesFuncs(displayOptions[id].args.load, data); - - WeakAuras.ReloadGroupRegionOptions(data); - else -- One aura selected - local triggerChoice = optionTriggerChoices[id]; - local trigger, untrigger = data.triggers[triggerChoice].trigger, data.triggers[triggerChoice].untrigger; - local function options_set(info, v) - trigger[info[#info]] = v; - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadTriggerOptions(data); - end - local triggerSystemOptionsFunction = trigger.type and WeakAuras.triggerTypesOptions[trigger.type]; - if (triggerSystemOptionsFunction) then - trigger_options = union(trigger_options, triggerSystemOptionsFunction(data, optionTriggerChoices)); - end - if (trigger.type == "aura") then - trigger_options = union(trigger_options, WeakAuras.GetBuffConversionOptions(data, optionTriggerChoices)); - end - - displayOptions[id].args.trigger.args = trigger_options; - displayOptions[id].args.load.args = WeakAuras.ConstructOptions(WeakAuras.load_prototype, data, 10, optionTriggerChoices[id], "load"); - - if (displayOptions[id].args.trigger.args.event) then - displayOptions[id].args.trigger.args.event.set = function(info, v, ...) - local prototype = WeakAuras.event_prototypes[v]; - if(prototype) then - if(prototype.automatic or prototype.automaticrequired) then - trigger.unevent = "auto"; - else - trigger.unevent = "timed"; - end - end - options_set(info, v, ...); - end - end - trigger.event = trigger.event or "Health"; - trigger.subeventPrefix = trigger.subeventPrefix or "SPELL" - trigger.subeventSuffix = trigger.subeventSuffix or "_CAST_START"; - - displayOptions[id].args.trigger.get = function(info, index) - local childOption = getChildOption(displayOptions[id], info) - if childOption.type == "multiselect" then - return trigger[info[#info]] and trigger[info[#info]][index] - else - return trigger[info[#info]] - end - end; - displayOptions[id].args.trigger.set = function(info, arg1, arg2) - local childOption = getChildOption(displayOptions[id], info) - if childOption.type == "multiselect" then - local index, value = arg1, arg2 - if type(trigger[info[#info]]) ~= "table" then - trigger[info[#info]] = {} - end - if value ~= nil then - if value then - trigger[info[#info]][index] = true - else - trigger[info[#info]][index] = nil - end - else - if trigger[info[#info]][index] then - trigger[info[#info]][index] = nil - else - trigger[info[#info]][index] = true - end - end - local next = next - if next(trigger[info[#info]]) == nil then - trigger[info[#info]] = nil - end - else - trigger[info[#info]] = (arg1 ~= "" and arg1) or nil; - end - - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.SetIconNames(data); - WeakAuras.UpdateDisplayButton(data); - WeakAuras.ReloadTriggerOptions(data); - end; - end - - displayOptions[id].args.authorOptions.args = {} - displayOptions[id].args.authorOptions.hidden = function() - return false; - end - displayOptions[id].args.authorOptions.disabled = function() - return false; - end - WeakAuras.GetAuthorOptions(data, displayOptions[id].args.authorOptions.args, 0) - - displayOptions[id].args.conditions.args = {}; - -- We never want the condition options to use the hiddenAll, disabledAll functions - displayOptions[id].args.conditions.hidden = function() - return false; - end - displayOptions[id].args.conditions.disabled = function() - return false; - end - WeakAuras.GetConditionOptions(data, displayOptions[id].args.conditions.args, "conditions", 0, nil); - - if(type(id) ~= "string") then - displayOptions[id].args.group = nil; - end -end - -local function fixMetaOrders(allOptions) - -- assumes that the results from create methods are contiguous in __order fields - -- shifts __order fields such that each optionGroup is ordered correctly relative - -- to its peers, but has a unique __order number in the combined option table. - local groupOrders = {} - local maxGroupOrder = 0 - for optionGroup, options in pairs(allOptions) do - local metaOrder = options.__order - groupOrders[metaOrder] = groupOrders[metaOrder] or {} - maxGroupOrder = max(maxGroupOrder, metaOrder) - tinsert(groupOrders[metaOrder], optionGroup) - end - - local index = 0 - local newOrder = 1 - while index <= maxGroupOrder do - index = index + 1 - if groupOrders[index] then - table.sort(groupOrders[index]) - for _, optionGroup in ipairs(groupOrders[index]) do - allOptions[optionGroup].__order = newOrder - newOrder = newOrder + 1 - end - end - end -end - -function WeakAuras.ReloadGroupRegionOptions(data) - local regionTypes = {}; - local id = data.id; - WeakAuras.EnsureOptions(id); - local options = displayOptions[id]; - local allOptions = {}; - local commonOption = {}; - local unsupportedCount = 0 - local supportedSubRegions = {} - local hasSubElements = false - for index, childId in ipairs(data.controlledChildren) do - local childData = WeakAuras.GetData(childId); - if childData and not regionTypes[childData.regionType] then - regionTypes[childData.regionType] = true; - if regionOptions[childData.regionType] then - allOptions = union(allOptions, regionOptions[childData.regionType].create(id, data)); - else - unsupportedCount = unsupportedCount + 1 - allOptions["__unsupported" .. unsupportedCount] = { - __title = "|cFFFFFF00" .. childData.regionType, - __order = 1, - warning = { - type = "description", - name = L["Regions of type \"%s\" are not supported."]:format(childData.regionType), - order = 1 - }, - } - end - for subRegionName, subRegionType in pairs(WeakAuras.subRegionTypes) do - if subRegionType.supports(childData.regionType) then - supportedSubRegions[subRegionName] = true - end - end - end - if childData.subRegions then - local subIndex = {} - for index, subRegionData in ipairs(childData.subRegions) do - local subRegionType = subRegionData.type - if WeakAuras.subRegionOptions[subRegionType] then - hasSubElements = true - subIndex[subRegionType] = subIndex[subRegionType] and subIndex[subRegionType] + 1 or 1 - local options, common = WeakAuras.subRegionOptions[subRegionType].create(data, subRegionData, index, subIndex[subRegionType]) - options.__order = 200 + index - allOptions["sub." .. index .. "." .. subRegionType] = options - commonOption[subRegionType] = common - end - end - end - end - - local commonOptionIndex = 0 - for option, optionData in pairs(commonOption) do - commonOptionIndex = commonOptionIndex + 1 - optionData.__order = 100 + commonOptionIndex - allOptions[option] = optionData - end - - hasSubElements = AddOptionsForSupportedSubRegion(allOptions, data, supportedSubRegions) or hasSubElements - - if hasSubElements then - allOptions["SubElementsHeader"] = { - __order = 100, - __noHeader = true, - header = { - order = 1, - type = "header", - name = L["Sub Elements"], - } - } - end - - fixMetaOrders(allOptions); - - local regionOption = flattenRegionOptions(allOptions, false); - - replaceNameDescFuncs(regionOption, data); - replaceImageFuncs(regionOption, data); - replaceValuesFuncs(regionOption, data); - removeFuncs(regionOption); - - options.args.region.args = regionOption; -end - -function WeakAuras.PositionOptions(id, data, _, hideWidthHeight, disableSelfPoint) - local metaOrder = 99 - local function IsParentDynamicGroup() - return data.parent and db.displays[data.parent] and db.displays[data.parent].regionType == "dynamicgroup"; - end - - local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20; - local positionOptions = { - __title = L["Position Settings"], - __order = metaOrder, - width = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Width"], - order = 60, - min = 1, - softMax = screenWidth, - bigStep = 1, - hidden = hideWidthHeight, - }, - height = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Height"], - order = 61, - min = 1, - softMax = screenHeight, - bigStep = 1, - hidden = hideWidthHeight, - }, - xOffset = { - type = "range", - width = WeakAuras.normalWidth, - name = L["X Offset"], - order = 62, - softMin = (-1 * screenWidth), - softMax = screenWidth, - bigStep = 10, - get = function() return data.xOffset end, - set = function(info, v) - data.xOffset = v; - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.ResetMoverSizer(); - if(data.parent) then - local parentData = WeakAuras.GetData(data.parent); - if(parentData) then - WeakAuras.Add(parentData); - end - end - end - }, - yOffset = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Y Offset"], - order = 63, - softMin = (-1 * screenHeight), - softMax = screenHeight, - bigStep = 10, - get = function() return data.yOffset end, - set = function(info, v) - data.yOffset = v; - WeakAuras.Add(data); - WeakAuras.UpdateThumbnail(data); - WeakAuras.ResetMoverSizer(); - if(data.parent) then - local parentData = WeakAuras.GetData(data.parent); - if(parentData) then - WeakAuras.Add(parentData); - end - end - end - }, - selfPoint = { - type = "select", - width = WeakAuras.normalWidth, - name = L["Anchor"], - order = 70, - hidden = IsParentDynamicGroup, - values = point_types, - disabled = disableSelfPoint, - }, - anchorFrameType = { - type = "select", - width = WeakAuras.normalWidth, - name = L["Anchored To"], - order = 72, - hidden = IsParentDynamicGroup, - values = (data.regionType == "group" or data.regionType == "dynamicgroup") and WeakAuras.anchor_frame_types_group or WeakAuras.anchor_frame_types, - }, - -- Input field to select frame to anchor on - anchorFrameFrame = { - type = "input", - width = WeakAuras.normalWidth, - name = L["Frame"], - order = 72.2, - hidden = function() - if (IsParentDynamicGroup()) then - return true; - end - return not (data.anchorFrameType == "SELECTFRAME") - end - }, - -- Button to select frame to anchor on - chooseAnchorFrameFrame = { - type = "execute", - width = WeakAuras.normalWidth, - name = L["Choose"], - order = 72.4, - hidden = function() - if (IsParentDynamicGroup()) then - return true; - end - return not (data.anchorFrameType == "SELECTFRAME") - end, - func = function() - WeakAuras.StartFrameChooser(data, {"anchorFrameFrame"}); - end - }, - anchorPoint = { - type = "select", - width = WeakAuras.normalWidth, - name = function() - if (data.anchorFrameType == "SCREEN") then - return L["To Screen's"] - else - return L["To Frame's"]; - end - end, - order = 75, - hidden = function() - if (data.parent) then - --if (IsParentDynamicGroup()) then - -- return true; - --end - return data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE"; - else - return data.anchorFrameType == "MOUSE"; - end - end, - values = point_types - }, - anchorPointGroup = { - type = "select", - width = WeakAuras.normalWidth, - name = L["To Group's"], - order = 76, - hidden = function() - if (data.anchorFrameType ~= "SCREEN") then - return true; - end - if (data.parent) then - return IsParentDynamicGroup(); - end - return true; - end, - disabled = true, - values = {["CENTER"] = L["Anchor Point"]}, - get = function() return "CENTER"; end - }, - anchorFrameParent = { - type = "toggle", - width = WeakAuras.normalWidth, - name = L["Set Parent to Anchor"], - desc = L["Sets the anchored frame as the aura's parent, causing the aura to inherit attributes such as visibility and scale."], - order = 77, - get = function() - return data.anchorFrameParent or data.anchorFrameParent == nil; - end, - hidden = function() - return (data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE" or IsParentDynamicGroup()); - end, - }, - frameStrata = { - type = "select", - width = WeakAuras.normalWidth, - name = L["Frame Strata"], - order = 78, - values = WeakAuras.frame_strata_types - }, - anchorFrameSpace = { - type = "execute", - width = WeakAuras.normalWidth, - name = "", - order = 79, - image = function() return "", 0, 0 end, - hidden = function() - return not (data.anchorFrameType ~= "SCREEN" or IsParentDynamicGroup()); - end - }, - }; - WeakAuras.AddCodeOption(positionOptions, data, L["Custom Anchor"], "custom_anchor", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-anchor-function", - 72.1, function() return not(data.anchorFrameType == "CUSTOM" and not IsParentDynamicGroup()) end, {"customAnchor"}, nil, nil, nil, nil, nil, true) - return positionOptions; -end - --- TODO: update this function to not have an unused parameter -function WeakAuras.BorderOptions(id, data, showBackDropOptions, hiddenFunc, order) - local borderOptions = { - borderHeader = { - type = "header", - order = order, - name = L["Border Settings"], - hidden = hiddenFunc, - }, - border = { - type = "toggle", - width = WeakAuras.doubleWidth, - name = L["Show Border"], - order = order + 0.1, - hidden = hiddenFunc, - }, - borderEdge = { - type = "select", - width = WeakAuras.normalWidth, - dialogControl = "LSM30_Border", - name = L["Border Style"], - order = order + 0.2, - values = AceGUIWidgetLSMlists.border, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - borderBackdrop = { - type = "select", - width = WeakAuras.normalWidth, - dialogControl = "LSM30_Background", - name = L["Backdrop Style"], - order = order + 0.3, - values = AceGUIWidgetLSMlists.background, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - borderOffset = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Border Offset"], - order = order + 0.3, - softMin = 0, - softMax = 32, - bigStep = 1, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - borderSize = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Border Size"], - order = order + 0.4, - softMin = 1, - softMax = 64, - bigStep = 1, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - borderInset = { - type = "range", - width = WeakAuras.normalWidth, - name = L["Border Inset"], - order = order + 0.5, - softMin = 1, - softMax = 32, - bigStep = 1, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - border_spacer = { - type = "description", - name = "", - width = WeakAuras.normalWidth, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - order = order + 0.6 - }, - borderColor = { - type = "color", - width = WeakAuras.normalWidth, - name = L["Border Color"], - hasAlpha = true, - order = order + 0.7, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - borderInFront = { - type = "toggle", - width = WeakAuras.normalWidth, - name = L["Border in Front"], - order = order + 0.8, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border or not showBackDropOptions end, - }, - backdropColor = { - type = "color", - width = WeakAuras.normalWidth, - name = L["Backdrop Color"], - hasAlpha = true, - order = order + 0.9, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border end, - }, - backdropInFront = { - type = "toggle", - width = WeakAuras.normalWidth, - name = L["Backdrop in Front"], - order = order + 1, - hidden = function() return hiddenFunc and hiddenFunc() or not data.border or not showBackDropOptions end, - }, - } - - return borderOptions; -end - function WeakAuras.OpenTextEditor(...) frame.texteditor:Open(...); end @@ -3993,9 +782,8 @@ function WeakAuras.ConvertDisplay(data, newType) displayButtons[id]:SetViewRegion(WeakAuras.regions[id].region); displayButtons[id]:Initialize(); displayButtons[id]:PriorityShow(visibility); - displayOptions[id] = nil; - WeakAuras.AddOption(id, data); - frame:FillOptions(displayOptions[id]); + frame:ClearOptions(id) + frame:FillOptions(); WeakAuras.UpdateDisplayButton(data); WeakAuras.SetMoverSizer(id) WeakAuras.ResetMoverSizer(); @@ -4008,8 +796,6 @@ function WeakAuras.NewDisplayButton(data) WeakAuras.EnsureDisplayButton(db.displays[id]); WeakAuras.UpdateDisplayButton(db.displays[id]); frame.buttonsScroll:AddChild(displayButtons[id]); - WeakAuras.AddOption(id, data); - WeakAuras.SetIconNames(data); WeakAuras.SortDisplayButtons(); end @@ -4241,7 +1027,7 @@ function WeakAuras.IsDisplayPicked(id) end end -function WeakAuras.PickDisplay(id, tab, noHide) -- TODO: remove tab parametter once legacy aura trigger is removed +function WeakAuras.PickDisplay(id, tab, noHide) frame:PickDisplay(id, tab, noHide) WeakAuras.UpdateButtonsScroll() end @@ -4339,8 +1125,6 @@ function WeakAuras.AddDisplayButton(data) WeakAuras.EnsureDisplayButton(data); WeakAuras.UpdateDisplayButton(data); frame.buttonsScroll:AddChild(displayButtons[data.id]); - WeakAuras.AddOption(data.id, data); - WeakAuras.SetIconNames(data); if(WeakAuras.regions[data.id] and WeakAuras.regions[data.id].region.SetStacks) then WeakAuras.regions[data.id].region:SetStacks(1); end @@ -4391,6 +1175,7 @@ function WeakAuras.Ungroup(data) local button = WeakAuras.GetDisplayButton(data.id); button:Ungroup(data); end + WeakAuras.FillOptions() end function WeakAuras.SetDragging(data, drop) @@ -4564,7 +1349,7 @@ function WeakAuras.ShowCloneDialog(data) local parentButton = WeakAuras.GetDisplayButton(parentData.id); parentButton.callbacks.UpdateExpandButton(); WeakAuras.UpdateDisplayButton(parentData); - WeakAuras.ReloadGroupRegionOptions(parentData); + WeakAuras.ClearAndUpdateOptions(parentData.id); WeakAuras.SortDisplayButtons(); parentButton:Expand(); end, @@ -4633,7 +1418,7 @@ function WeakAuras.NewAura(sourceData, regionType, targetId) WeakAuras.Add(group.data); WeakAuras.NewDisplayButton(data); WeakAuras.UpdateGroupOrders(group.data); - WeakAuras.ReloadGroupRegionOptions(group.data); + WeakAuras.ClearOptions(group.data.id); WeakAuras.UpdateDisplayButton(group.data); group.callbacks.UpdateExpandButton(); group:Expand(); @@ -4822,7 +1607,7 @@ function WeakAuras.AddTextFormatOption(input, withHeader, get, addOption, hidden return L["|cFFffcc00Format Options|r"] end, width = WeakAuras.doubleWidth, - func = function() + func = function(info, button) setHidden(not hidden()) end, image = function() @@ -4843,16 +1628,15 @@ function WeakAuras.AddTextFormatOption(input, withHeader, get, addOption, hidden local triggerNum, sym = string.match(symbol, "(.+)%.(.+)") sym = sym or symbol + if sym == "c" or sym == "i" then + -- No special options for these + else addOption(symbol .. "desc", { type = "description", name = L["Format for %s"]:format("%" .. symbol), width = WeakAuras.normalWidth, hidden = hidden }) - - if sym == "c" or sym == "i" then - -- No special options for these - else addOption(symbol .. "_format", { type = "select", name = L["Format"], @@ -4872,15 +1656,9 @@ function WeakAuras.AddTextFormatOption(input, withHeader, get, addOption, hidden seenSymbols[symbol] = true end) - if next(seenSymbols) then - local footerOption = { - type = "header", - name = "", - } - addOption("footer", footerOption) - end - if not next(seenSymbols) and withHeader then headerOption.hidden = true end + + return next(seenSymbols) ~= nil end diff --git a/WeakAurasOptions/WeakAurasOptions.toc b/WeakAurasOptions/WeakAurasOptions.toc index 261f087..f90232e 100644 --- a/WeakAurasOptions/WeakAurasOptions.toc +++ b/WeakAurasOptions/WeakAurasOptions.toc @@ -31,13 +31,19 @@ SubRegionOptions\SubRegionCommon.lua SubRegionOptions\SubText.lua SubRegionOptions\Border.lua SubRegionOptions\Glow.lua -SubRegionOptions\BarModel.lua SubRegionOptions\Tick.lua +SubRegionOptions\BarModel.lua Cache.lua +CommonOptions.lua +GroupOptions.lua +DisplayOptions.lua +TriggerOptions.lua +LoadOptions.lua ActionOptions.lua AnimationOptions.lua + BuffTrigger.lua BuffTrigger2.lua GenericTrigger.lua @@ -73,5 +79,7 @@ AceGUI-Widgets\AceGUIWidget-WeakAurasImportButton.lua AceGUI-Widgets\AceGUIWidget-WeakAurasSortedDropDown.lua AceGUI-Widgets\AceGUIWidget-WeakAurasToolbarButton.lua AceGUI-Widgets\AceGUIWidget-WeakAurasTwoColumnDropDown.lua +AceGUI-Widgets\AceGUIWidget-WeakAurasSnippetButton.lua AceGUI-Widgets\AceGUIContainer-WeakAurasTreeGroup.lua AceGUI-Widgets\AceGUIWidget-WeakAurasSnippetButton.lua +AceGUI-Widgets\AceGUIContainer-WeakAurasInlineGroup.lua