From 0551c6ea620128af75becceed9f92ef885cc3235 Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Thu, 18 Aug 2022 10:11:27 -0300 Subject: [PATCH] Framework update --- Libs/DF/fw.lua | 9 ++- Libs/DF/panel.lua | 186 +++++++++++++++++++++++++++------------------- 2 files changed, 114 insertions(+), 81 deletions(-) diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index ba33bafd..cf3b999a 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 328 +local dversion = 329 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -933,11 +933,12 @@ end --return a list of spells from the player spellbook function DF:GetSpellBookSpells() local spellNamesInSpellBook = {} + local spellIdsInSpellBook = {} for i = 1, GetNumSpellTabs() do local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(i) - if (offspecId == 0) then + if (offspecId == 0 and tabTexture ~= 136830) then --don't add spells found in the General tab offset = offset + 1 local tabEnd = offset + numSpells @@ -949,6 +950,7 @@ function DF:GetSpellBookSpells() local spellName = GetSpellInfo(spellId) if (spellName) then spellNamesInSpellBook[spellName] = true + spellIdsInSpellBook[#spellIdsInSpellBook+1] = spellId end else local _, _, numSlots, isKnown = GetFlyoutInfo(spellId) @@ -958,6 +960,7 @@ function DF:GetSpellBookSpells() if (isKnown) then local spellName = GetSpellInfo(spellID) spellNamesInSpellBook[spellName] = true + spellIdsInSpellBook[#spellIdsInSpellBook+1] = spellID end end end @@ -967,7 +970,7 @@ function DF:GetSpellBookSpells() end end - return spellNamesInSpellBook + return spellNamesInSpellBook, spellIdsInSpellBook end ------------------------------ diff --git a/Libs/DF/panel.lua b/Libs/DF/panel.lua index abfcb63e..56fe5374 100644 --- a/Libs/DF/panel.lua +++ b/Libs/DF/panel.lua @@ -6066,131 +6066,151 @@ local default_radiogroup_options = { } DF.RadioGroupCoreFunctions = { - RadioOnClick = function (self, fixedParam, value) - --turn off all checkboxes - local frameList = {self:GetParent():GetChildren()} - for _, checkbox in ipairs (frameList) do - checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox - checkbox:SetValue (false) - end - - --turn on the clicked checkbox - self:SetValue (true) - - --callback - DF:QuickDispatch (self._set, fixedParam) - end, - Disable = function (self) - local frameList = {self:GetChildren()} - for _, checkbox in ipairs (frameList) do + local frameList = self:GetAllCheckboxes() + for _, checkbox in ipairs(frameList) do checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox checkbox:Disable() end end, Enable = function (self) - local frameList = {self:GetChildren()} - for _, checkbox in ipairs (frameList) do + local frameList = self:GetAllCheckboxes() + for _, checkbox in ipairs(frameList) do checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox checkbox:Enable() end end, - DeselectAll = function (self) - local frameList = {self:GetChildren()} - for _, checkbox in ipairs (frameList) do + DeselectAll = function(self) + local frameList = self:GetAllCheckboxes() + for _, checkbox in ipairs(frameList) do checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox - checkbox:SetValue (false) + checkbox:SetValue(false) end end, - FadeIn = function (self) - local frameList = {self:GetChildren()} - for _, checkbox in ipairs (frameList) do - checkbox:SetAlpha (1) + FadeIn = function(self) + local frameList = self:GetAllCheckboxes() + for _, checkbox in ipairs(frameList) do + checkbox:SetAlpha(1) end end, - FadeOut = function (self) - local frameList = {self:GetChildren()} - for _, checkbox in ipairs (frameList) do - checkbox:SetAlpha (.7) + FadeOut = function(self) + local frameList = self:GetAllCheckboxes() + for _, checkbox in ipairs(frameList) do + checkbox:SetAlpha(.7) end end, - SetFadeState = function (self, state) + SetFadeState = function(self, state) if (state) then self:FadeIn() else self:FadeOut() end end, - - CreateCheckbox = function (self) - local checkbox = DF:CreateSwitch (self, function()end, false, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) - checkbox:SetAsCheckBox() - checkbox.Icon = DF:CreateImage (checkbox, "", 16, 16) - checkbox.Label = DF:CreateLabel (checkbox, "") - + + GetAllCheckboxes = function(self) + return {self:GetChildren()} + end, + + GetCheckbox = function(self, checkboxId) + local allCheckboxes = self:GetAllCheckboxes() + local checkbox = allCheckboxes[checkboxId] + if (not checkbox) then + checkbox = self:CreateCheckbox() + end return checkbox end, - RefreshCheckbox = function (self, checkbox, optionTable) - checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox + CreateCheckbox = function(self) + local checkbox = DF:CreateSwitch(self, function()end, false, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) + checkbox:SetAsCheckBox() + checkbox.Icon = DF:CreateImage(checkbox, "", 16, 16) + checkbox.Label = DF:CreateLabel(checkbox, "") - local setFunc = self.options.is_radio and self.RadioOnClick or optionTable.set - checkbox:SetSwitchFunction (setFunc) - checkbox._set = setFunc - checkbox:SetFixedParameter (optionTable.param) - - local isChecked = DF:Dispatch (optionTable.get) - checkbox:SetValue (isChecked) - - checkbox.Label:SetText (optionTable.name) - - if (optionTable.texture) then - checkbox.Icon:SetTexture (optionTable.texture) - checkbox.Icon:SetPoint ("left", checkbox, "right", 2, 0) - checkbox.Label:SetPoint ("left", checkbox.Icon, "right", 2, 0) - - if (optionTable.texcoord) then - checkbox.Icon:SetTexCoord (unpack (optionTable.texcoord)) - else - checkbox.Icon:SetTexCoord (0, 1, 0, 1) - end - else - checkbox.Icon:SetTexture ("") - checkbox.Label:SetPoint ("left", checkbox, "right", 2, 0) + return checkbox + end, + + ResetAllCheckboxes = function(self) + local radioCheckboxes = self:GetAllCheckboxes() + for i = 1, #radioCheckboxes do + local checkBox = radioCheckboxes[i] + checkBox:Hide() end end, - Refresh = function (self) - local radioOptions = self.RadioOptionsTable - local radioCheckboxes = {self:GetChildren()} + --if the list of checkboxes are a radio group + RadioOnClick = function(checkbox, fixedParam, value) + --turn off all checkboxes + checkbox:GetParent():DeselectAll() - for _, checkbox in ipairs (radioCheckboxes) do - checkbox:Hide() + --turn on the clicked checkbox + checkbox:SetValue(true) + + --callback + if (checkbox._callback) then + DF:QuickDispatch(checkbox._callback, fixedParam, checkbox._optionid) end + end, + + RefreshCheckbox = function(self, checkbox, optionTable, optionId) + checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox - for radioIndex, optionsTable in ipairs (radioOptions) do - local checkbox = radioCheckboxes [radioIndex] - if (not checkbox) then - checkbox = self:CreateCheckbox() + local setFunc = self.options.is_radio and self.RadioOnClick or optionTable.set + checkbox:SetSwitchFunction(setFunc) + checkbox._callback = optionTable.callback + checkbox._set = self.options.is_radio and optionTable.callback or optionTable.set + checkbox._optionid = optionId + checkbox:SetFixedParameter(optionTable.param or optionId) + + local isChecked = type(optionTable.get) == "function" and DF:Dispatch(optionTable.get) or false + checkbox:SetValue(isChecked) + + checkbox.Label:SetText(optionTable.name) + + if (optionTable.texture) then + checkbox.Icon:SetTexture(optionTable.texture) + checkbox.Icon:SetPoint("left", checkbox, "right", 2, 0) + checkbox.Label:SetPoint("left", checkbox.Icon, "right", 2, 0) + + if (optionTable.texcoord) then + checkbox.Icon:SetTexCoord(unpack(optionTable.texcoord)) + else + checkbox.Icon:SetTexCoord(0, 1, 0, 1) end - checkbox.OptionID = radioIndex + else + checkbox.Icon:SetTexture("") + checkbox.Label:SetPoint("left", checkbox, "right", 2, 0) + end + end, + + Refresh = function(self) + self:ResetAllCheckboxes() + local radioOptions = self:GetOptions() + local radioCheckboxes = self:GetAllCheckboxes() + + for optionId, optionsTable in ipairs(radioOptions) do + local checkbox = self:GetCheckbox(optionId) + checkbox.OptionID = optionId checkbox:Show() - self:RefreshCheckbox (checkbox, optionsTable) + self:RefreshCheckbox(checkbox, optionsTable, optionId) end --sending false to automatically use the radio group children - self:ArrangeFrames (false, self.AnchorOptions) + self:ArrangeFrames(false, self.AnchorOptions) end, - SetOptions = function (self, radioOptions) + SetOptions = function(self, radioOptions) self.RadioOptionsTable = radioOptions self:Refresh() end, + + GetOptions = function(self) + return self.RadioOptionsTable + end, } --[=[ @@ -6201,7 +6221,7 @@ DF.RadioGroupCoreFunctions = { options: override options for default_radiogroup_options table anchorOptions: override options for default_framelayout_options table --]=] -function DF:CreateRadionGroup (parent, radioOptions, name, options, anchorOptions) +function DF:CreateCheckboxGroup(parent, radioOptions, name, options, anchorOptions) local f = CreateFrame ("frame", name, parent, "BackdropTemplate") DF:Mixin (f, DF.OptionsFunctions) @@ -6228,6 +6248,16 @@ function DF:CreateRadionGroup (parent, radioOptions, name, options, anchorOption return f end +function DF:CreateRadionGroup(parent, radioOptions, name, options, anchorOptions) --alias for miss spelled old function + return DF:CreateRadioGroup(parent, radioOptions, name, options, anchorOptions) +end + +function DF:CreateRadioGroup(parent, radioOptions, name, options, anchorOptions) + options = options or {} + options.is_radio = true + return DF:CreateCheckboxGroup(parent, radioOptions, name, options, anchorOptions) +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --> load conditions panel