From 597371aba1131b9a842736822e7c966bd40f2e1b Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Fri, 13 Oct 2023 18:04:13 -0300 Subject: [PATCH] Framework Update --- Libs/DF/auras.lua | 672 ++++++++++++----------------- Libs/DF/definitions.lua | 8 +- Libs/DF/fw.lua | 2 +- Libs/DF/label.lua | 2 +- Libs/DF/panel.lua | 2 +- Libs/DF/scrollbox.lua | 81 ++-- Libs/DF/textentry.lua | 2 + Libs/LibLuaServer/LibLuaServer.lua | 3 + 8 files changed, 331 insertions(+), 441 deletions(-) diff --git a/Libs/DF/auras.lua b/Libs/DF/auras.lua index 18c255fa4..9a6944899 100644 --- a/Libs/DF/auras.lua +++ b/Libs/DF/auras.lua @@ -13,6 +13,9 @@ local GetSpellInfo = GetSpellInfo local lower = string.lower local GetSpellBookItemInfo = GetSpellBookItemInfo local unpack = unpack +local CreateFrame = CreateFrame +local GameTooltip = GameTooltip +local tremove = tremove local CONST_MAX_SPELLS = 500000 @@ -31,7 +34,7 @@ function DF:GetAuraByName(unit, spellName, isDebuff) end end -local default_text_for_aura_frame = { +local defaultTextForAuraFrame = { AUTOMATIC = "Automatic", MANUAL = "Manual", METHOD = "Aura Tracking Method:", @@ -54,8 +57,11 @@ local spellsHashMap local spellsIndexTable local spellsWithSameName +function DF:GetSpellCaches() + return spellsHashMap, spellsIndexTable, spellsWithSameName +end + local lazyLoadAllSpells = function(payload, iterationCount, maxIterations) - payload.nextIndex = payload.nextIndex or 0 local startPoint = payload.nextIndex --the goal is iterate over 500000 spell ids over 200 frames local endPoint = startPoint + 2500 @@ -65,8 +71,10 @@ local lazyLoadAllSpells = function(payload, iterationCount, maxIterations) --make upvalues be closer local toLowerCase = string.lower local GetSpellInfo = GetSpellInfo - local hashMap = spellsHashMap - local indexTable = spellsIndexTable + + local hashMap = payload.hashMap + local indexTable = payload.indexTable + local allSpellsSameName = payload.allSpellsSameName while (i < endPoint) do local spellName = GetSpellInfo(i) @@ -76,107 +84,50 @@ local lazyLoadAllSpells = function(payload, iterationCount, maxIterations) hashMap[spellName] = i --[spellname] = spellId indexTable[#indexTable+1] = spellName --array with all spellnames - local sameNameTable = spellsWithSameName[spellName] - if (not sameNameTable) then - sameNameTable = {} - spellsWithSameName[spellName] = sameNameTable + local spellNameTable = allSpellsSameName[spellName] + if (not spellNameTable) then + spellNameTable = {} + allSpellsSameName[spellName] = spellNameTable end - sameNameTable[#sameNameTable+1] = i + spellNameTable[#spellNameTable+1] = i end i = i + 1 end end -function DF:LoadAllSpells(hashMap, indexTable, allSpellsSameName) +function DF:UnloadSpellCache() if (spellsHashMap) then + table.wipe(spellsHashMap) + table.wipe(spellsIndexTable) + table.wipe(spellsWithSameName) + end +end + +function DF:LoadSpellCache(hashMap, indexTable, allSpellsSameName) + if (spellsHashMap and next(spellsHashMap)) then + --return the already loaded cache return spellsHashMap, spellsIndexTable, spellsWithSameName end - assert(type(hashMap) == "table", "DetailsFramework:LoadAllSpells(): require a table on #1 parameter.") - assert(type(indexTable) == "table", "DetailsFramework:LoadAllSpells(): require a table on #2 parameter.") - assert(type(allSpellsSameName) == "table", "DetailsFramework:LoadAllSpells(): require a table on #3 parameter.") + assert(type(hashMap) == "table", "DetailsFramework:LoadSpellCache(): require a table on #1 parameter.") + assert(type(indexTable) == "table", "DetailsFramework:LoadSpellCache(): require a table on #2 parameter.") + assert(type(allSpellsSameName) == "table", "DetailsFramework:LoadSpellCache(): require a table on #3 parameter.") spellsHashMap = hashMap spellsIndexTable = indexTable spellsWithSameName = allSpellsSameName - detailsFramework.Schedules.LazyExecute(lazyLoadAllSpells, {}, 200) - - if 1 then return end - - --pre checking which tables to fill to avoid checking if the table exists during the gigantic loop for performance - if (not DF.LoadingAuraAlertFrame) then - DF.LoadingAuraAlertFrame = CreateFrame("frame", "DetailsFrameworkLoadingAurasAlert", UIParent, "BackdropTemplate") - DF.LoadingAuraAlertFrame:SetSize(340, 75) - DF.LoadingAuraAlertFrame:SetPoint("center") - DF.LoadingAuraAlertFrame:SetFrameStrata("TOOLTIP") - DF:ApplyStandardBackdrop(DF.LoadingAuraAlertFrame) - DF.LoadingAuraAlertFrame:SetBackdropBorderColor(1, 0.8, 0.1) - - DF.LoadingAuraAlertFrame.IsLoadingLabel1 = DF:CreateLabel(DF.LoadingAuraAlertFrame, "We are currently loading spell names and spell IDs") - DF.LoadingAuraAlertFrame.IsLoadingLabel2 = DF:CreateLabel(DF.LoadingAuraAlertFrame, "This may take only a few seconds") - DF.LoadingAuraAlertFrame.IsLoadingImage1 = DF:CreateImage(DF.LoadingAuraAlertFrame, [[Interface\DialogFrame\UI-Dialog-Icon-AlertOther]], 32, 32) - DF.LoadingAuraAlertFrame.IsLoadingLabel1.align = "center" - DF.LoadingAuraAlertFrame.IsLoadingLabel2.align = "center" - - DF.LoadingAuraAlertFrame.IsLoadingLabel1:SetPoint("center", 16, 10) - DF.LoadingAuraAlertFrame.IsLoadingLabel2:SetPoint("center", 16, -5) - DF.LoadingAuraAlertFrame.IsLoadingImage1:SetPoint("left", 10, 0) - end - - DF.LoadingAuraAlertFrame:Show() - - C_Timer.After(0, function() - if (hashMap and not indexTable) then - for i = 1, CONST_MAX_SPELLS do - local spellName = GetSpellInfo(i) - if (spellName) then - hashMap [lower(spellName)] = i - end - end - - elseif (not hashMap and indexTable) then - for i = 1, CONST_MAX_SPELLS do - local spellName = GetSpellInfo(i) - if (spellName) then - indexTable [#indexTable+1] = lower(spellName) - end - end - - elseif (hashMap and indexTable) then - if (allSpellsSameName) then - for i = 1, CONST_MAX_SPELLS do - local spellName = GetSpellInfo(i) - if (spellName) then - spellName = lower(spellName) - indexTable [#indexTable + 1] = spellName - hashMap [spellName] = i - - --same name table - local sameNameTable = allSpellsSameName [spellName] - if (not sameNameTable) then - sameNameTable = {} - allSpellsSameName [spellName] = sameNameTable - end - sameNameTable [#sameNameTable + 1] = i - end - end - else - for i = 1, CONST_MAX_SPELLS do - local spellName = GetSpellInfo(i) - if (spellName) then - spellName = lower(spellName) - indexTable [#indexTable + 1] = spellName - hashMap [spellName] = i - end - end - end - end - - DF.LoadingAuraAlertFrame:Hide() - end) + local iterations = 200 + local payload = { + nextIndex = 0, + hashMap = hashMap, + indexTable = indexTable, + allSpellsSameName = allSpellsSameName, + } + detailsFramework.Schedules.LazyExecute(lazyLoadAllSpells, payload, iterations) + return spellsHashMap, spellsIndexTable, spellsWithSameName end do @@ -207,20 +158,19 @@ local AuraTrackerMetaFunctions = _G[DF.GlobalWidgetControlNames["aura_tracker"]] DF:Mixin(AuraTrackerMetaFunctions, DF.ScriptHookMixin) --create panels -local on_profile_changed = function(self, newdb) - +local onProfileChangedCallback = function(self, newdb) self.db = newdb --automatic - self.buff_ignored:DoSetData(newdb.aura_tracker.buff_banned) - self.debuff_ignored:DoSetData(newdb.aura_tracker.debuff_banned) - self.buff_tracked:DoSetData(newdb.aura_tracker.buff_tracked) - self.debuff_tracked:DoSetData(newdb.aura_tracker.debuff_tracked) + self.buff_ignored:SetData(newdb.aura_tracker.buff_banned) + self.debuff_ignored:SetData(newdb.aura_tracker.debuff_banned) + self.buff_tracked:SetData(newdb.aura_tracker.buff_tracked) + self.debuff_tracked:SetData(newdb.aura_tracker.debuff_tracked) - self.buff_ignored:DoRefresh() - self.debuff_ignored:DoRefresh() - self.buff_tracked:DoRefresh() - self.debuff_tracked:DoRefresh() + self.buff_ignored:Refresh() + self.debuff_ignored:Refresh() + self.buff_tracked:Refresh() + self.debuff_tracked:Refresh() --manual self.buffs_added:SetData(newdb.aura_tracker.buff) @@ -263,7 +213,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex local newAuraPanel = CreateFrame("frame", name, parent, "BackdropTemplate") newAuraPanel.db = db - newAuraPanel.OnProfileChanged = on_profile_changed + newAuraPanel.OnProfileChanged = onProfileChangedCallback newAuraPanel.LocTexts = texts options = options or {} self.table.deploy(options, aura_panel_defaultoptions) @@ -278,10 +228,10 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.f_manual = auraPanel_Manual --check if the texts table is valid and also deploy default values into the table in case some value is nil - texts = (type(texts == "table") and texts) or default_text_for_aura_frame - DF.table.deploy(texts, default_text_for_aura_frame) + texts = (type(texts == "table") and texts) or defaultTextForAuraFrame + DF.table.deploy(texts, defaultTextForAuraFrame) - local on_switch_tracking_method = function(self) + local onSwitchTrackingMethod = function(self) local method = self.Method newAuraPanel.db.aura_tracker.track_method = method @@ -305,39 +255,39 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end end - local background_method_selection = CreateFrame("frame", nil, newAuraPanel, "BackdropTemplate") - background_method_selection:SetHeight(82) - background_method_selection:SetPoint("topleft", newAuraPanel, "topleft", 0, 0) - background_method_selection:SetPoint("topright", newAuraPanel, "topright", 0, 0) - DF:ApplyStandardBackdrop(background_method_selection) + local methodSelectionBackground = CreateFrame("frame", nil, newAuraPanel, "BackdropTemplate") + methodSelectionBackground:SetHeight(82) + methodSelectionBackground:SetPoint("topleft", newAuraPanel, "topleft", 0, 0) + methodSelectionBackground:SetPoint("topright", newAuraPanel, "topright", 0, 0) + DF:ApplyStandardBackdrop(methodSelectionBackground) - local tracking_method_label = self:CreateLabel(background_method_selection, texts.METHOD, 12, "orange") - tracking_method_label:SetPoint("topleft", background_method_selection, "topleft", 6, -4) + local trackingMethodLabel = self:CreateLabel(methodSelectionBackground, texts.METHOD, 12, "orange") + trackingMethodLabel:SetPoint("topleft", methodSelectionBackground, "topleft", 6, -4) - newAuraPanel.desc_label = self:CreateLabel(background_method_selection, "", 10, "silver") - newAuraPanel.desc_label:SetPoint("left", background_method_selection, "left", 130, 0) + newAuraPanel.desc_label = self:CreateLabel(methodSelectionBackground, "", 10, "silver") + newAuraPanel.desc_label:SetPoint("left", methodSelectionBackground, "left", 130, 0) newAuraPanel.desc_label:SetJustifyV("top") - local automatic_tracking_checkbox = DF:CreateSwitch(background_method_selection, on_switch_tracking_method, newAuraPanel.db.aura_tracker.track_method == 0x1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) - automatic_tracking_checkbox.Method = 0x1 - automatic_tracking_checkbox:SetAsCheckBox() - automatic_tracking_checkbox:SetSize(24, 24) - newAuraPanel.AutomaticTrackingCheckbox = automatic_tracking_checkbox + local automaticTrackingCheckbox = DF:CreateSwitch(methodSelectionBackground, onSwitchTrackingMethod, newAuraPanel.db.aura_tracker.track_method == 0x1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) + automaticTrackingCheckbox.Method = 0x1 + automaticTrackingCheckbox:SetAsCheckBox() + automaticTrackingCheckbox:SetSize(24, 24) + newAuraPanel.AutomaticTrackingCheckbox = automaticTrackingCheckbox - local automatic_tracking_label = DF:CreateLabel(background_method_selection, "Automatic") - automatic_tracking_label:SetPoint("left", automatic_tracking_checkbox, "right", 2, 0) + local automaticTrackingLabel = DF:CreateLabel(methodSelectionBackground, "Automatic") + automaticTrackingLabel:SetPoint("left", automaticTrackingCheckbox, "right", 2, 0) - local manual_tracking_checkbox = DF:CreateSwitch(background_method_selection, on_switch_tracking_method, newAuraPanel.db.aura_tracker.track_method == 0x2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) - manual_tracking_checkbox.Method = 0x2 - manual_tracking_checkbox:SetAsCheckBox() - manual_tracking_checkbox:SetSize(24, 24) - newAuraPanel.ManualTrackingCheckbox = manual_tracking_checkbox + local manualTrackingCheckbox = DF:CreateSwitch(methodSelectionBackground, onSwitchTrackingMethod, newAuraPanel.db.aura_tracker.track_method == 0x2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) + manualTrackingCheckbox.Method = 0x2 + manualTrackingCheckbox:SetAsCheckBox() + manualTrackingCheckbox:SetSize(24, 24) + newAuraPanel.ManualTrackingCheckbox = manualTrackingCheckbox - local manual_tracking_label = DF:CreateLabel(background_method_selection, "Manual") - manual_tracking_label:SetPoint("left", manual_tracking_checkbox, "right", 2, 0) + local manualTrackingLabel = DF:CreateLabel(methodSelectionBackground, "Manual") + manualTrackingLabel:SetPoint("left", manualTrackingCheckbox, "right", 2, 0) - automatic_tracking_checkbox:SetPoint("topleft", tracking_method_label, "bottomleft", 0, -6) - manual_tracking_checkbox:SetPoint("topleft", automatic_tracking_checkbox, "bottomleft", 0, -6) + automaticTrackingCheckbox:SetPoint("topleft", trackingMethodLabel, "bottomleft", 0, -6) + manualTrackingCheckbox:SetPoint("topleft", automaticTrackingCheckbox, "bottomleft", 0, -6) -------- anchors points @@ -346,26 +296,15 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex -------- automatic - --manual add the buff and ebuff names - local AllSpellsMap = {} - local AllSpellNames = {} + local setAutoCompleteWordList = function(self, capsule) + if (next(spellsHashMap)) then --this will error if the spell cache isn't loaded with DF:LoadSpellCache(hashMap, indexTable, allSpellsSameName) + auraPanel_Auto.AddBuffBlacklistTextBox.SpellAutoCompleteList = spellsIndexTable + auraPanel_Auto.AddDebuffBlacklistTextBox.SpellAutoCompleteList = spellsIndexTable + auraPanel_Auto.AddBuffTracklistTextBox.SpellAutoCompleteList = spellsIndexTable + auraPanel_Auto.AddDebuffTracklistTextBox.SpellAutoCompleteList = spellsIndexTable - --store a table with spell name as key and in the value an index table with spell IDs - local AllSpellsSameName = {} - - local load_all_spells = function(self, capsule) - if (not next(AllSpellsMap)) then - DF:LoadAllSpells(AllSpellsMap, AllSpellNames, AllSpellsSameName) - - auraPanel_Auto.AddBuffBlacklistTextBox.SpellAutoCompleteList = AllSpellNames - auraPanel_Auto.AddDebuffBlacklistTextBox.SpellAutoCompleteList = AllSpellNames - auraPanel_Auto.AddBuffTracklistTextBox.SpellAutoCompleteList = AllSpellNames - auraPanel_Auto.AddDebuffTracklistTextBox.SpellAutoCompleteList = AllSpellNames - - auraPanel_Manual.NewBuffTextBox.SpellAutoCompleteList = AllSpellNames - auraPanel_Manual.NewDebuffTextBox.SpellAutoCompleteList = AllSpellNames - - -- + auraPanel_Manual.NewBuffTextBox.SpellAutoCompleteList = spellsIndexTable + auraPanel_Manual.NewDebuffTextBox.SpellAutoCompleteList = spellsIndexTable auraPanel_Auto.AddBuffBlacklistTextBox:SetAsAutoComplete("SpellAutoCompleteList") auraPanel_Auto.AddDebuffBlacklistTextBox:SetAsAutoComplete("SpellAutoCompleteList") @@ -375,8 +314,6 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex auraPanel_Manual.NewBuffTextBox:SetAsAutoComplete("SpellAutoCompleteList") auraPanel_Manual.NewDebuffTextBox:SetAsAutoComplete("SpellAutoCompleteList") - -- - auraPanel_Auto.AddBuffBlacklistTextBox.ShouldOptimizeAutoComplete = true auraPanel_Auto.AddDebuffBlacklistTextBox.ShouldOptimizeAutoComplete = true auraPanel_Auto.AddBuffTracklistTextBox.ShouldOptimizeAutoComplete = true @@ -391,83 +328,61 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex local textEntryWidth = 120 --create the background - local background_add_blacklist = CreateFrame("frame", nil, auraPanel_Auto, "BackdropTemplate") - background_add_blacklist:SetSize(textEntryWidth + 10, 135) - DF:ApplyStandardBackdrop(background_add_blacklist) - background_add_blacklist.__background:SetVertexColor(0.47, 0.27, 0.27) + local blacklistAddBackground = CreateFrame("frame", nil, auraPanel_Auto, "BackdropTemplate") + blacklistAddBackground:SetSize(textEntryWidth + 10, 135) + DF:ApplyStandardBackdrop(blacklistAddBackground) + blacklistAddBackground.__background:SetVertexColor(0.47, 0.27, 0.27) - local background_add_tracklist = CreateFrame("frame", nil, auraPanel_Auto, "BackdropTemplate") - background_add_tracklist:SetSize(textEntryWidth + 10, 135) - DF:ApplyStandardBackdrop(background_add_tracklist) - background_add_tracklist.__background:SetVertexColor(0.27, 0.27, 0.47) + local tracklistAddBackground = CreateFrame("frame", nil, auraPanel_Auto, "BackdropTemplate") + tracklistAddBackground:SetSize(textEntryWidth + 10, 135) + DF:ApplyStandardBackdrop(tracklistAddBackground) + tracklistAddBackground.__background:SetVertexColor(0.27, 0.27, 0.47) --black list --create labels - local buff_blacklist_label = self:CreateLabel(background_add_blacklist, texts.MANUAL_ADD_BLACKLIST_BUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) - local debuff_blacklist_label = self:CreateLabel(background_add_blacklist, texts.MANUAL_ADD_BLACKLIST_DEBUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) - - local buff_name_blacklist_entry = self:CreateTextEntry(background_add_blacklist, function()end, textEntryWidth, 20, "AddBuffBlacklistTextBox", _, _, options_dropdown_template) - buff_name_blacklist_entry:SetHook("OnEditFocusGained", load_all_spells) - buff_name_blacklist_entry:SetJustifyH("left") - buff_name_blacklist_entry.tooltip = "Enter the buff name using lower case letters." - auraPanel_Auto.AddBuffBlacklistTextBox = buff_name_blacklist_entry - - local debuff_name_blacklist_entry = self:CreateTextEntry(background_add_blacklist, function()end, textEntryWidth, 20, "AddDebuffBlacklistTextBox", _, _, options_dropdown_template) - debuff_name_blacklist_entry:SetHook("OnEditFocusGained", load_all_spells) - debuff_name_blacklist_entry:SetJustifyH("left") - debuff_name_blacklist_entry.tooltip = "Enter the debuff name using lower case letters." - auraPanel_Auto.AddDebuffBlacklistTextBox = debuff_name_blacklist_entry - - local same_name_spells_add = function(spellID, t) - local spellName = GetSpellInfo(spellID) - if (spellName) then - if (not next(AllSpellsMap)) then - load_all_spells() - end - - spellName = lower(spellName) - local spellWithSameName = AllSpellsSameName [spellName] - if (spellWithSameName) then - if (t) then - t [spellName] = DF.table.copy({}, spellWithSameName) + local buffBlacklistLabel = self:CreateLabel(blacklistAddBackground, texts.MANUAL_ADD_BLACKLIST_BUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) + local debuffBlacklistLabel = self:CreateLabel(blacklistAddBackground, texts.MANUAL_ADD_BLACKLIST_DEBUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) + + local buffNameBlacklistEntry = self:CreateTextEntry(blacklistAddBackground, function()end, textEntryWidth, 20, "AddBuffBlacklistTextBox", _, _, options_dropdown_template) + buffNameBlacklistEntry:SetHook("OnEditFocusGained", setAutoCompleteWordList) + buffNameBlacklistEntry:SetJustifyH("left") + buffNameBlacklistEntry.tooltip = "Enter the buff name using lower case letters." + auraPanel_Auto.AddBuffBlacklistTextBox = buffNameBlacklistEntry + + local debuffNameBlacklistEntry = self:CreateTextEntry(blacklistAddBackground, function()end, textEntryWidth, 20, "AddDebuffBlacklistTextBox", _, _, options_dropdown_template) + debuffNameBlacklistEntry:SetHook("OnEditFocusGained", setAutoCompleteWordList) + debuffNameBlacklistEntry:SetJustifyH("left") + debuffNameBlacklistEntry.tooltip = "Enter the debuff name using lower case letters." + auraPanel_Auto.AddDebuffBlacklistTextBox = debuffNameBlacklistEntry + + local getSpellIDFromSpellName = function(spellName) + --check if the user entered a spell ID + local bIsSpellId = tonumber(spellName) + if (bIsSpellId) then + local spellId = tonumber(spellName) + if (spellId and spellId > 1 and spellId < 10000000) then + local isValidSpellID = GetSpellInfo(spellId) + if (isValidSpellID) then + return spellId else - db.aura_cache_by_name [spellName] = DF.table.copy({}, spellWithSameName) + return end end end - end - DF.AddSpellWithSameName = same_name_spells_add - - local get_spellID_from_string = function(text) - --check if the user entered a spell ID - local isSpellID = tonumber(text) - if (isSpellID and isSpellID > 1 and isSpellID < 10000000) then - local isValidSpellID = GetSpellInfo(isSpellID) - if (isValidSpellID) then - return isSpellID - else - return - end - end --get the spell ID from the spell name - text = lower(text) - local spellID = AllSpellsMap [text] - if (not spellID) then - return - end - - return spellID + spellName = lower(spellName) + return spellsHashMap[spellName] end - local add_blacklist_buff_button = self:CreateButton(background_add_blacklist, function() - local text = buff_name_blacklist_entry.text - buff_name_blacklist_entry:SetText("") - buff_name_blacklist_entry:ClearFocus() + local addBuffNameToBacklistButton = self:CreateButton(blacklistAddBackground, function() + local text = buffNameBlacklistEntry.text + buffNameBlacklistEntry:SetText("") + buffNameBlacklistEntry:ClearFocus() if (text ~= "") then --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -477,20 +392,17 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.buff_banned [spellId] = true --refresh the buff blacklist frame - newAuraPanel.buff_ignored:DoRefresh() + newAuraPanel.buff_ignored:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By Name", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_blacklist_buff_button_id = self:CreateButton(background_add_blacklist, function() - local text = buff_name_blacklist_entry.text - buff_name_blacklist_entry:SetText("") - buff_name_blacklist_entry:ClearFocus() + local addBuffIDToBacklistButton = self:CreateButton(blacklistAddBackground, function() + local text = buffNameBlacklistEntry.text + buffNameBlacklistEntry:SetText("") + buffNameBlacklistEntry:ClearFocus() if (text ~= "") then if (not tonumber(text)) then @@ -498,7 +410,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -508,24 +420,21 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.buff_banned [spellId] = false --refresh the buff blacklist frame - newAuraPanel.buff_ignored:DoRefresh() + newAuraPanel.buff_ignored:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By ID", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_blacklist_debuff_button = self:CreateButton(background_add_blacklist, function() - local text = debuff_name_blacklist_entry.text - debuff_name_blacklist_entry:SetText("") - debuff_name_blacklist_entry:ClearFocus() + local addDebuffNameToBacklistButton = self:CreateButton(blacklistAddBackground, function() + local text = debuffNameBlacklistEntry.text + debuffNameBlacklistEntry:SetText("") + debuffNameBlacklistEntry:ClearFocus() if (text ~= "") then --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -535,19 +444,16 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.debuff_banned [spellId] = true --refresh the buff blacklist frame - newAuraPanel.debuff_ignored:DoRefresh() + newAuraPanel.debuff_ignored:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By Name", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_blacklist_debuff_button_id = self:CreateButton(background_add_blacklist, function() - local text = debuff_name_blacklist_entry.text - debuff_name_blacklist_entry:SetText("") - debuff_name_blacklist_entry:ClearFocus() + local addDebuffIDToBacklistButton = self:CreateButton(blacklistAddBackground, function() + local text = debuffNameBlacklistEntry.text + debuffNameBlacklistEntry:SetText("") + debuffNameBlacklistEntry:ClearFocus() if (text ~= "") then if (not tonumber(text)) then @@ -555,7 +461,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -565,40 +471,37 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.debuff_banned [spellId] = false --refresh the buff blacklist frame - newAuraPanel.debuff_ignored:DoRefresh() + newAuraPanel.debuff_ignored:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By ID", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) --track list - local buff_tracklist_label = self:CreateLabel(background_add_tracklist, texts.MANUAL_ADD_TRACKLIST_BUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) - local debuff_tracklist_label = self:CreateLabel(background_add_tracklist, texts.MANUAL_ADD_TRACKLIST_DEBUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) - - local buff_name_tracklist_entry = self:CreateTextEntry(background_add_tracklist, function()end, textEntryWidth, 20, "AddBuffTracklistTextBox", _, _, options_dropdown_template) - buff_name_tracklist_entry:SetHook("OnEditFocusGained", load_all_spells) - buff_name_tracklist_entry:SetJustifyH("left") - buff_name_tracklist_entry.tooltip = "Enter the buff name using lower case letters." - auraPanel_Auto.AddBuffTracklistTextBox = buff_name_tracklist_entry - - local debuff_name_tracklist_entry = self:CreateTextEntry(background_add_tracklist, function()end, textEntryWidth, 20, "AddDebuffTracklistTextBox", _, _, options_dropdown_template) - debuff_name_tracklist_entry:SetHook("OnEditFocusGained", load_all_spells) - debuff_name_tracklist_entry:SetJustifyH("left") - debuff_name_tracklist_entry.tooltip = "Enter the debuff name using lower case letters." - auraPanel_Auto.AddDebuffTracklistTextBox = debuff_name_tracklist_entry - - local add_tracklist_debuff_button = self:CreateButton(background_add_tracklist, function() - local text = debuff_name_tracklist_entry.text - debuff_name_tracklist_entry:SetText("") - debuff_name_tracklist_entry:ClearFocus() + local buffTracklistLabel = self:CreateLabel(tracklistAddBackground, texts.MANUAL_ADD_TRACKLIST_BUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) + local debuffTracklistLabel = self:CreateLabel(tracklistAddBackground, texts.MANUAL_ADD_TRACKLIST_DEBUFF, DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")) + + local buffNameTracklistEntry = self:CreateTextEntry(tracklistAddBackground, function()end, textEntryWidth, 20, "AddBuffTracklistTextBox", _, _, options_dropdown_template) + buffNameTracklistEntry:SetHook("OnEditFocusGained", setAutoCompleteWordList) + buffNameTracklistEntry:SetJustifyH("left") + buffNameTracklistEntry.tooltip = "Enter the buff name using lower case letters." + auraPanel_Auto.AddBuffTracklistTextBox = buffNameTracklistEntry + + local debuffNameTracklistEntry = self:CreateTextEntry(tracklistAddBackground, function()end, textEntryWidth, 20, "AddDebuffTracklistTextBox", _, _, options_dropdown_template) + debuffNameTracklistEntry:SetHook("OnEditFocusGained", setAutoCompleteWordList) + debuffNameTracklistEntry:SetJustifyH("left") + debuffNameTracklistEntry.tooltip = "Enter the debuff name using lower case letters." + auraPanel_Auto.AddDebuffTracklistTextBox = debuffNameTracklistEntry + + local addDebuffNameToTracklistButton = self:CreateButton(tracklistAddBackground, function() + local text = debuffNameTracklistEntry.text + debuffNameTracklistEntry:SetText("") + debuffNameTracklistEntry:ClearFocus() if (text ~= "") then --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -608,19 +511,16 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.debuff_tracked [spellId] = true --refresh the buff blacklist frame - newAuraPanel.debuff_tracked:DoRefresh() + newAuraPanel.debuff_tracked:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By Name", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_tracklist_debuff_button_id = self:CreateButton(background_add_tracklist, function() - local text = debuff_name_tracklist_entry.text - debuff_name_tracklist_entry:SetText("") - debuff_name_tracklist_entry:ClearFocus() + local addDebuffIDToTracklistButton = self:CreateButton(tracklistAddBackground, function() + local text = debuffNameTracklistEntry.text + debuffNameTracklistEntry:SetText("") + debuffNameTracklistEntry:ClearFocus() if (text ~= "") then if (not tonumber(text)) then @@ -628,7 +528,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -637,23 +537,20 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.debuff_tracked [spellId] = false --refresh the buff blacklist frame - newAuraPanel.debuff_tracked:DoRefresh() + newAuraPanel.debuff_tracked:Refresh() DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By ID", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_tracklist_buff_button = self:CreateButton(background_add_tracklist, function() - local text = buff_name_tracklist_entry.text - buff_name_tracklist_entry:SetText("") - buff_name_tracklist_entry:ClearFocus() + local addBuffNameToTracklistButton = self:CreateButton(tracklistAddBackground, function() + local text = buffNameTracklistEntry.text + buffNameTracklistEntry:SetText("") + buffNameTracklistEntry:ClearFocus() if (text ~= "") then --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -663,21 +560,18 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.buff_tracked [spellId] = true --refresh the buff tracklist frame - newAuraPanel.buff_tracked:DoRefresh() + newAuraPanel.buff_tracked:Refresh() --callback the addon DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By Name", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) - local add_tracklist_buff_button_id = self:CreateButton(background_add_tracklist, function() - local text = buff_name_tracklist_entry.text - buff_name_tracklist_entry:SetText("") - buff_name_tracklist_entry:ClearFocus() + local addBuffIDToTracklistButton = self:CreateButton(tracklistAddBackground, function() + local text = buffNameTracklistEntry.text + buffNameTracklistEntry:SetText("") + buffNameTracklistEntry:ClearFocus() if (text ~= "") then if (not tonumber(text)) then @@ -685,7 +579,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end --get the spellId - local spellId = get_spellID_from_string(text) + local spellId = getSpellIDFromSpellName(text) if (not spellId) then DetailsFramework.Msg({__name = "DetailsFramework"}, "Spell not found!") return @@ -695,53 +589,61 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex newAuraPanel.db.aura_tracker.buff_tracked [spellId] = false --refresh the buff tracklist frame - newAuraPanel.buff_tracked:DoRefresh() + newAuraPanel.buff_tracked:Refresh() --callback the addon DF:QuickDispatch(changeCallback) - - --add to spells with the same name cache - same_name_spells_add(spellId) end end, textEntryWidth/2 -3, 20, "By ID", nil, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", options.button_text_template)) --anchors: - background_add_blacklist:SetPoint("topleft", auraPanel_Auto, "topleft", 0, y) - background_add_tracklist:SetPoint("topleft", background_add_blacklist, "bottomleft", 0, -10) + blacklistAddBackground:SetPoint("topleft", auraPanel_Auto, "topleft", 0, y) + tracklistAddBackground:SetPoint("topleft", blacklistAddBackground, "bottomleft", 0, -10) --debuff blacklist - debuff_name_blacklist_entry:SetPoint("topleft", background_add_blacklist, "topleft", 5, -20) - debuff_blacklist_label:SetPoint("bottomleft", debuff_name_blacklist_entry, "topleft", 0, 2) - add_blacklist_debuff_button:SetPoint("topleft", debuff_name_blacklist_entry, "bottomleft", 0, -2) - add_blacklist_debuff_button_id:SetPoint("left", add_blacklist_debuff_button, "right", 1, 0) + debuffNameBlacklistEntry:SetPoint("topleft", blacklistAddBackground, "topleft", 5, -20) + debuffBlacklistLabel:SetPoint("bottomleft", debuffNameBlacklistEntry, "topleft", 0, 2) + addDebuffNameToBacklistButton:SetPoint("topleft", debuffNameBlacklistEntry, "bottomleft", 0, -2) + addDebuffIDToBacklistButton:SetPoint("left", addDebuffNameToBacklistButton, "right", 1, 0) --buff blacklist - buff_blacklist_label:SetPoint("topleft", add_blacklist_debuff_button.widget, "bottomleft", 0, -10) - buff_name_blacklist_entry:SetPoint("topleft", buff_blacklist_label, "bottomleft", 0, -2) - add_blacklist_buff_button:SetPoint("topleft", buff_name_blacklist_entry, "bottomleft", 0, -2) - add_blacklist_buff_button_id:SetPoint("left", add_blacklist_buff_button, "right", 1, 0) - + buffBlacklistLabel:SetPoint("topleft", addDebuffNameToBacklistButton.widget, "bottomleft", 0, -10) + buffNameBlacklistEntry:SetPoint("topleft", buffBlacklistLabel, "bottomleft", 0, -2) + addBuffNameToBacklistButton:SetPoint("topleft", buffNameBlacklistEntry, "bottomleft", 0, -2) + addBuffIDToBacklistButton:SetPoint("left", addBuffNameToBacklistButton, "right", 1, 0) --debuff tracklist - debuff_name_tracklist_entry:SetPoint("topleft", background_add_tracklist, "topleft", 5, -20) - debuff_tracklist_label:SetPoint("bottomleft", debuff_name_tracklist_entry, "topleft", 0, 2) - add_tracklist_debuff_button:SetPoint("topleft", debuff_name_tracklist_entry, "bottomleft", 0, -2) - add_tracklist_debuff_button_id:SetPoint("left", add_tracklist_debuff_button, "right", 1, 0) + debuffNameTracklistEntry:SetPoint("topleft", tracklistAddBackground, "topleft", 5, -20) + debuffTracklistLabel:SetPoint("bottomleft", debuffNameTracklistEntry, "topleft", 0, 2) + addDebuffNameToTracklistButton:SetPoint("topleft", debuffNameTracklistEntry, "bottomleft", 0, -2) + addDebuffIDToTracklistButton:SetPoint("left", addDebuffNameToTracklistButton, "right", 1, 0) --buff tracklist - buff_tracklist_label:SetPoint("topleft", add_tracklist_debuff_button.widget, "bottomleft", 0, -10) - buff_name_tracklist_entry:SetPoint("topleft", buff_tracklist_label, "bottomleft", 0, -2) - add_tracklist_buff_button:SetPoint("topleft", buff_name_tracklist_entry, "bottomleft", 0, -2) - add_tracklist_buff_button_id:SetPoint("left", add_tracklist_buff_button, "right", 1, 0) - - local ALL_BUFFS = {} - local ALL_DEBUFFS = {} + buffTracklistLabel:SetPoint("topleft", addDebuffNameToTracklistButton.widget, "bottomleft", 0, -10) + buffNameTracklistEntry:SetPoint("topleft", buffTracklistLabel, "bottomleft", 0, -2) + addBuffNameToTracklistButton:SetPoint("topleft", buffNameTracklistEntry, "bottomleft", 0, -2) + addBuffIDToTracklistButton:SetPoint("left", addBuffNameToTracklistButton, "right", 1, 0) --options passed to the create aura panel local width, height, row_height = options.width, options.height, options.row_height - local autoTrackList_LineOnEnter = function(self, capsule, value) + local scrollWidth = 208 +do --deprecated, using a scrollbox tempate from scrollbox.lua + local scrollHeight = 343 + local lineAmount = 18 + local lineHeight = 18 + local backdropColor = {.8, .8, .8, 0.2} + local backdropColor_OnEnter = {.8, .8, .8, 0.4} + + --aura scroll box default settings + local auraScrollDefaultSettings = { + show_spell_tooltip = false, + line_height = 18, + line_amount = 18, + } + + local autoTrackList_LineOnEnter = function(self, capsule, value) local flag = self.Flag value = value or self.SpellID @@ -756,34 +658,26 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex GameCooltip2:AddIcon(spellIcon, 1, 1, 14, 14, .1, .9, .1, .9) end GameCooltip2:Show() - else - local spellName = GetSpellInfo(value) - if (spellName) then - - local spellsWithSameName = db.aura_cache_by_name [lower(spellName)] - if (not spellsWithSameName) then - same_name_spells_add(value) - spellsWithSameName = db.aura_cache_by_name [lower(spellName)] - end + else + local spellName, _, spellIcon = GetSpellInfo(value) + if (spellName and spellsWithSameName) then + local spellNameLower = spellName:lower() + local sameNameSpells = spellsWithSameName[spellNameLower] - if (spellsWithSameName) then + if (sameNameSpells) then GameCooltip2:Preset(2) GameCooltip2:SetOwner(self, "left", "right", 2, 0) GameCooltip2:SetOption("TextSize", 10) - for i, spellID in ipairs(spellsWithSameName) do - local spellName, _, spellIcon = GetSpellInfo(spellID) - if (spellName) then - GameCooltip2:AddLine(spellName .. "(" .. spellID .. ")") - GameCooltip2:AddIcon(spellIcon, 1, 1, 14, 14, .1, .9, .1, .9) - end + for i, spellId in ipairs(sameNameSpells) do + GameCooltip2:AddLine(spellName .. " (" .. spellId .. ")") + GameCooltip2:AddIcon(spellIcon, 1, 1, 14, 14, .1, .9, .1, .9) end GameCooltip2:Show() end end - end end @@ -791,19 +685,6 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex GameCooltip2:Hide() end - local scrollWidth = 208 - local scrollHeight = 343 - local lineAmount = 18 - local lineHeight = 18 - local backdropColor = {.8, .8, .8, 0.2} - local backdropColor_OnEnter = {.8, .8, .8, 0.4} - - --aura scroll box default settings - local auraScrollDefaultSettings = { - show_spell_tooltip = false, - line_height = 18, - line_amount = 18, - } local createAuraScrollBox = function(scrollBoxParent, scrollBoxName, scrollBoxParentKey, scrollBoxTitle, databaseTable, removeAuraFunc, options) local scrollOptions = {} @@ -855,7 +736,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex local spellId = self:GetParent().SpellID databaseTable[spellId] = nil databaseTable["" .. (spellId or "")] = nil -- cleanup... - scrollBoxParent[scrollBoxParentKey]:DoRefresh() + scrollBoxParent[scrollBoxParentKey]:Refresh() if (removeAuraFunc) then --upvalue detailsFramework:QuickDispatch(removeAuraFunc) end @@ -902,7 +783,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex scrollBoxParent[scrollBoxParentKey] = auraScrollBox auraScrollBox.OriginalData = databaseTable - function auraScrollBox:DoRefresh() + function auraScrollBox:Refresh() local t = {} local added = {} for spellID, flag in pairs(auraScrollBox.OriginalData) do @@ -922,8 +803,12 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex function auraScrollBox:DoSetData(newDB) self:SetData(newDB) - auraScrollBox.OriginalData = newDB - self:DoRefresh() + self.OriginalData = newDB + if (self.Refresh) then + self:Refresh() + else + self:Refresh() + end end local titleLabel = DF:CreateLabel(scrollBoxParent, scrollBoxTitle) @@ -935,62 +820,51 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex auraScrollBox:CreateLine(createLineFunc) end - auraScrollBox:DoRefresh() + auraScrollBox:Refresh() return auraScrollBox end +end - local buff_tracked = createAuraScrollBox(auraPanel_Auto, "$parentBuffTracked", "BuffTrackerScroll", newAuraPanel.LocTexts.BUFFS_TRACKED, newAuraPanel.db.aura_tracker.buff_tracked, function() + local onAuraRemoveCallback = function() if (changeCallback) then DF:QuickDispatch(changeCallback) end - end) - local debuff_tracked = createAuraScrollBox(auraPanel_Auto, "$parentDebuffTracked", "DebuffTrackerScroll", newAuraPanel.LocTexts.DEBUFFS_TRACKED, newAuraPanel.db.aura_tracker.debuff_tracked, function() - if (changeCallback) then - DF:QuickDispatch(changeCallback) - end - end) + end - local buff_ignored = createAuraScrollBox(auraPanel_Auto, "$parentBuffIgnored", "BuffIgnoredScroll", newAuraPanel.LocTexts.BUFFS_IGNORED, newAuraPanel.db.aura_tracker.buff_banned, function() - if (changeCallback) then - DF:QuickDispatch(changeCallback) - end - end) - local debuff_ignored = createAuraScrollBox(auraPanel_Auto, "$parentDebuffIgnored", "DebuffIgnoredScroll", newAuraPanel.LocTexts.DEBUFFS_IGNORED, newAuraPanel.db.aura_tracker.debuff_banned, function() - if (changeCallback) then - DF:QuickDispatch(changeCallback) - end - end) + options.title_text = texts.DEBUFFS_TRACKED or defaultTextForAuraFrame.DEBUFFS_TRACKED + local debuffTrackedAuraScrollBox = detailsFramework:CreateAuraScrollBox(auraPanel_Auto, "$parentDebuffTracked", newAuraPanel.db.aura_tracker.debuff_tracked, onAuraRemoveCallback, options) + auraPanel_Auto.DebuffTrackerScroll = debuffTrackedAuraScrollBox + + options.title_text = texts.BUFFS_IGNORED or defaultTextForAuraFrame.BUFFS_IGNORED + local buffIgnoredAuraScrollBox = detailsFramework:CreateAuraScrollBox(auraPanel_Auto, "$parentBuffIgnored", newAuraPanel.db.aura_tracker.buff_banned, onAuraRemoveCallback, options) + auraPanel_Auto.BuffIgnoredScroll = buffIgnoredAuraScrollBox + + options.title_text = texts.DEBUFFS_IGNORED or defaultTextForAuraFrame.DEBUFFS_IGNORED + local debuffIgnoredAuraScrollBox = detailsFramework:CreateAuraScrollBox(auraPanel_Auto, "$parentDebuffIgnored", newAuraPanel.db.aura_tracker.debuff_banned, onAuraRemoveCallback, options) + auraPanel_Auto.DebuffIgnoredScroll = debuffIgnoredAuraScrollBox + + options.title_text = texts.BUFFS_TRACKED or defaultTextForAuraFrame.BUFFS_TRACKED + local buffTrackedAuraScrollBox = detailsFramework:CreateAuraScrollBox(auraPanel_Auto, "$parentBuffTracked", newAuraPanel.db.aura_tracker.buff_tracked, onAuraRemoveCallback, options) + auraPanel_Auto.BuffTrackerScroll = buffTrackedAuraScrollBox local xLocation = 140 scrollWidth = scrollWidth + 20 - debuff_ignored:SetPoint("topleft", auraPanel_Auto, "topleft", 0 + xLocation, y) - buff_ignored:SetPoint("topleft", auraPanel_Auto, "topleft", 8 + scrollWidth + xLocation, y) - debuff_tracked:SetPoint("topleft", auraPanel_Auto, "topleft", 16 +(scrollWidth * 2) + xLocation, y) - buff_tracked:SetPoint("topleft", auraPanel_Auto, "topleft", 24 +(scrollWidth * 3) + xLocation, y) + debuffIgnoredAuraScrollBox:SetPoint("topleft", auraPanel_Auto, "topleft", 0 + xLocation, y) + buffIgnoredAuraScrollBox:SetPoint("topleft", auraPanel_Auto, "topleft", 8 + scrollWidth + xLocation, y) + debuffTrackedAuraScrollBox:SetPoint("topleft", auraPanel_Auto, "topleft", 16 +(scrollWidth * 2) + xLocation, y) + buffTrackedAuraScrollBox:SetPoint("topleft", auraPanel_Auto, "topleft", 24 +(scrollWidth * 3) + xLocation, y) - newAuraPanel.buff_ignored = buff_ignored - newAuraPanel.debuff_ignored = debuff_ignored - newAuraPanel.buff_tracked = buff_tracked - newAuraPanel.debuff_tracked = debuff_tracked + newAuraPanel.buff_ignored = buffIgnoredAuraScrollBox + newAuraPanel.debuff_ignored = debuffIgnoredAuraScrollBox + newAuraPanel.buff_tracked = buffTrackedAuraScrollBox + newAuraPanel.debuff_tracked = debuffTrackedAuraScrollBox auraPanel_Auto:SetScript("OnShow", function() - for i = 1, BUFF_MAX_DISPLAY do - local name, texture, count, debuffType, duration, expirationTime, caster, _, nameplateShowPersonal, spellId, _, _, _, nameplateShowAll = UnitAura("player", i, "HELPFUL") - if (name) then - ALL_BUFFS [spellId] = true - end - local name, texture, count, debuffType, duration, expirationTime, caster, _, nameplateShowPersonal, spellId, _, _, _, nameplateShowAll = UnitAura("player", i, "HARMFUL") - if (name) then - ALL_DEBUFFS [spellId] = true - end - end - - buff_tracked:DoRefresh() - debuff_tracked:DoRefresh() - buff_ignored:DoRefresh() - debuff_ignored:DoRefresh() - + buffTrackedAuraScrollBox:Refresh() + debuffTrackedAuraScrollBox:Refresh() + buffIgnoredAuraScrollBox:Refresh() + debuffIgnoredAuraScrollBox:Refresh() end) auraPanel_Auto:SetScript("OnHide", function() -- @@ -999,9 +873,9 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex --show the frame selecton on the f.db if (newAuraPanel.db.aura_tracker.track_method == 0x1) then - on_switch_tracking_method(automatic_tracking_checkbox) + onSwitchTrackingMethod(automaticTrackingCheckbox) elseif (newAuraPanel.db.aura_tracker.track_method == 0x2) then - on_switch_tracking_method(manual_tracking_checkbox) + onSwitchTrackingMethod(manualTrackingCheckbox) end -------manual @@ -1132,8 +1006,8 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex local new_buff_entry = self:CreateTextEntry(auraPanel_Manual, function()end, 200, 20, "NewBuffTextBox", _, _, options_dropdown_template) local new_debuff_entry = self:CreateTextEntry(auraPanel_Manual, function()end, 200, 20, "NewDebuffTextBox", _, _, options_dropdown_template) - new_buff_entry:SetHook("OnEditFocusGained", load_all_spells) - new_debuff_entry:SetHook("OnEditFocusGained", load_all_spells) + new_buff_entry:SetHook("OnEditFocusGained", setAutoCompleteWordList) + new_debuff_entry:SetHook("OnEditFocusGained", setAutoCompleteWordList) new_buff_entry.tooltip = "Enter the buff name using lower case letters.\n\nYou can add several spells at once using |cFFFFFF00;|r to separate each spell name." new_debuff_entry.tooltip = "Enter the debuff name using lower case letters.\n\nYou can add several spells at once using |cFFFFFF00;|r to separate each spell name." @@ -1151,7 +1025,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex if (text:find(";")) then for _, spellName in ipairs({strsplit(";", text)}) do spellName = self:trim(spellName) - local spellID = get_spellID_from_string(spellName) + local spellID = getSpellIDFromSpellName(spellName) if (spellID) then tinsert(newAuraPanel.db.aura_tracker.buff, spellID) @@ -1168,7 +1042,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end else --get the spellId - local spellID = get_spellID_from_string(text) + local spellID = getSpellIDFromSpellName(text) if (not spellID) then print("spellIs for spell ", text, "not found") return @@ -1198,7 +1072,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex if (text:find(";")) then for _, spellName in ipairs({strsplit(";", text)}) do spellName = self:trim(spellName) - local spellID = get_spellID_from_string(spellName) + local spellID = getSpellIDFromSpellName(spellName) if (spellID) then tinsert(newAuraPanel.db.aura_tracker.debuff, spellID) @@ -1215,7 +1089,7 @@ function DF:CreateAuraConfigPanel(parent, name, db, changeCallback, options, tex end else --get the spellId - local spellID = get_spellID_from_string(text) + local spellID = getSpellIDFromSpellName(text) if (not spellID) then print("spellIs for spell ", text, "not found") return diff --git a/Libs/DF/definitions.lua b/Libs/DF/definitions.lua index 940e0b440..3006e7b9d 100644 --- a/Libs/DF/definitions.lua +++ b/Libs/DF/definitions.lua @@ -19,13 +19,19 @@ ---| "slider" ---@class detailsframework +---@field dversion number ---@field OptionsFunctions df_optionsmixin +---@field GlobalWidgetControlNames table ---@field RoundedCornerPanelMixin df_roundedcornermixin ---@field Schedules df_schedule ---@field HeaderFunctions df_headerfunctions ---@field KeybindMixin df_keybindmixin +---@field ScriptHookMixin df_scripthookmixin ---@field Math df_math ---@field table df_table_functions +---@field LoadSpellCache fun(self:table, hashMap:table, indexTable:table, allSpellsSameName:table) : hashMap:table, indexTable:table, allSpellsSameName:table load all spells in the game and add them into the passed tables +---@field UnloadSpellCache fun(self:table) wipe the table contents filled with LoadSpellCache() +---@field GetSpellCaches fun(self:table) : table, table, table return the tables filled with LoadSpellCache() ---@field IsValidSpecId fun(self:table, specId:number):boolean check if the passed specId is valid for the player class, also return false for tutorial specs ---@field DebugVisibility fun(self:table, object:uiobject) print the reason why the frame isn't shown in the screen ---@field Dispatch fun(self:table, callback:function, ...) : any dispatch a function call using xpcall, print to chat if the function passed is invalid @@ -81,5 +87,5 @@ ---@field CreateSwitch fun(self:table, parent:frame, onSwitch:function, defaultValue:boolean, width:number?, height:number?, leftText:string?, rightText:string?, member:string?, name:string?, colorInverted:boolean?, switchFunc:function?, returnFunc:function?, withLabel:string?, switch_template:table?, label_template:table?) : df_checkbox, df_label? ---@field CreateCheckboxGroup fun(self:table, parent:frame, radioOptions:df_radiooptions[], name:string?, options:table?, anchorOptions:table?) : df_checkboxgroup ---@field CreateRadioGroup fun(self:table, parent:frame, radioOptions:df_radiooptions[], name:string?, options:table?, anchorOptions:table?) : df_radiogroup ----@field +---@field CreateAuraScrollBox fun(self:table, parent:frame, name:string?, data:table?, onRemoveCallback:function?, options:table?) : df_aurascrollbox ---@field diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index 214d61c4c..5583a59c8 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 475 +local dversion = 477 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary(major, minor) diff --git a/Libs/DF/label.lua b/Libs/DF/label.lua index 71de658f2..20aca3c1c 100644 --- a/Libs/DF/label.lua +++ b/Libs/DF/label.lua @@ -256,7 +256,7 @@ detailsFramework:Mixin(LabelMetaFunctions, detailsFramework.ScriptHookMixin) ------------------------------------------------------------------------------------------------------------ --object constructor ----@class df_label: uiobject +---@class df_label: fontstring ---@field widget fontstring widget and label points to the same fontstring ---@field label fontstring widget and label points to the same fontstring ---@field align justifyh diff --git a/Libs/DF/panel.lua b/Libs/DF/panel.lua index 7aebc5ac9..b2c16798c 100644 --- a/Libs/DF/panel.lua +++ b/Libs/DF/panel.lua @@ -3738,7 +3738,7 @@ end ---@field ReajustNumFrames boolean? ---@field DontHideChildrenOnPreRefresh boolean ---@field refresh_func fun(self:df_scrollbox, data:table, offset:number, numlines:number) ----@field Refresh fun(self:df_scrollbox, data:table, offset:number, numlines:number) +---@field Refresh fun(self:df_scrollbox) ---@field CreateLineFunc fun(self:df_scrollbox, index:number)? ---@field CreateLine fun(self:df_scrollbox, func:function) ---@field SetData fun(self:df_scrollbox, data:table) diff --git a/Libs/DF/scrollbox.lua b/Libs/DF/scrollbox.lua index 21bccb02c..585be656f 100644 --- a/Libs/DF/scrollbox.lua +++ b/Libs/DF/scrollbox.lua @@ -95,7 +95,7 @@ detailsFramework.ScrollBoxFunctions = { func = self.CreateLineFunc end - local okay, newLine = pcall(func, self, #self.Frames+1) + local okay, newLine = xpcall(func, geterrorhandler(), self, #self.Frames+1) if (okay) then if (not newLine) then error("ScrollFrame:CreateLine() function did not returned a line, use: 'return line'") @@ -103,9 +103,8 @@ detailsFramework.ScrollBoxFunctions = { table.insert(self.Frames, newLine) newLine.Index = #self.Frames return newLine - else - error("ScrollFrame:CreateLine() error on creating a line: " .. newLine) end + return newLine end, CreateLines = function(self, callback, lineAmount) @@ -431,6 +430,7 @@ end ---@field backdrop_onenter number[]? ---@field backdrop_onleave number[]? ---@field font_size number? +---@field title_text string? local auraScrollDefaultSettings = { line_height = 18, @@ -442,18 +442,18 @@ local auraScrollDefaultSettings = { remove_icon_border = true, no_scroll = false, no_backdrop = false, - backdrop_onenter = {.8, .8, .8, 0.2}, - backdrop_onleave = {.8, .8, .8, 0.4}, + backdrop_onenter = {.8, .8, .8, 0.4}, + backdrop_onleave = {.8, .8, .8, 0.2}, font_size = 12, + title_text = "", } ---@param parent frame ---@param name string? ---@param data table? --can be set later with :SetData() ----@param profile table? --can be set later with :SetProfile() ---@param onAuraRemoveCallback function? ---@param options df_aurascrollbox_options? -function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAuraRemoveCallback, options) +function detailsFramework:CreateAuraScrollBox(parent, name, data, onAuraRemoveCallback, options) --hack the construction of the options table here, as the scrollbox is created much later options = options or {} local scrollOptions = {} @@ -493,6 +493,7 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur local onLeaveAuraLine = function(self) self:SetBackdropColor(unpack(options.backdrop_onleave)) GameTooltip:Hide() + GameCooltip:Hide() end local onEnterAuraLine = function(line) @@ -504,36 +505,32 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur end line:SetBackdropColor(unpack(options.backdrop_onenter)) - local scrollBox = line:GetParent() - local bAddedBySpellName = line.Flag --the user entered the spell name to track the spell (and not a spellId) local spellId = line.SpellID if (bAddedBySpellName) then --the user entered the spell name to track the spell - local spellName = GetSpellInfo(spellId) - if (spellName) then - local spellsWithSameName = scrollBox.profile.aura_cache_by_name[string.lower(spellName)] - if (not spellsWithSameName) then - --same_name_spells_add(value) - --spellsWithSameName = scrollBox.profile.aura_cache_by_name[string.lower(spellName)] - end - - if (spellsWithSameName) then - GameCooltip:Preset(2) - GameCooltip:SetOwner(line, "left", "right", 2, 0) - GameCooltip:SetOption("TextSize", 10) - - for i, spellId in ipairs(spellsWithSameName) do - local spellName, _, spellIcon = GetSpellInfo(spellId) - if (spellName) then - GameCooltip:AddLine(spellName .. "(" .. spellId .. ")") + local spellsHashMap, spellsIndexTable, spellsWithSameName = detailsFramework:GetSpellCaches() + if (spellsWithSameName) then + local spellName, _, spellIcon = GetSpellInfo(spellId) + if (spellName) then + local spellNameLower = spellName:lower() + local sameNameSpells = spellsWithSameName[spellNameLower] + + if (sameNameSpells) then + GameCooltip:Preset(2) + GameCooltip:SetOwner(line, "left", "right", 2, 0) + GameCooltip:SetOption("TextSize", 10) + + for i, thisSpellId in ipairs(sameNameSpells) do + GameCooltip:AddLine(spellName .. " (" .. thisSpellId .. ")") GameCooltip:AddIcon(spellIcon, 1, 1, 14, 14, .1, .9, .1, .9) end - end - GameCooltip:Show() + GameCooltip:Show() + end end end + else --the user entered the spellId to track the spell GameCooltip:Preset(2) GameCooltip:SetOwner(line, "left", "right", 2, 0) @@ -577,7 +574,7 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur line:SetScript("OnLeave", onLeaveAuraLine) line:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) - line:SetBackdropColor(options.backdrop_onleave) + line:SetBackdropColor(unpack(options.backdrop_onleave)) local iconTexture = line:CreateTexture("$parentIcon", "overlay") iconTexture:SetSize(lineHeight - 2, lineHeight - 2) @@ -602,11 +599,9 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur end ---@class df_aurascrollbox : df_scrollbox - ---@field RefreshMe fun(self:df_aurascrollbox) ---@field TransformAuraData fun(self:df_aurascrollbox) - ---@field SetProfile fun(self:df_aurascrollbox, profile:table) ---@field data_original table - ---@field profile table + ---@field refresh_original function data = data or {} @@ -617,9 +612,16 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur local auraScrollBox = detailsFramework:CreateScrollBox(parent, name, refreshAuraLines, data, options.width, options.height, options.line_amount, options.line_height) detailsFramework:ReskinSlider(auraScrollBox) ---@cast auraScrollBox df_aurascrollbox - auraScrollBox.data_original = data - auraScrollBox.profile = profile or {} + + local titleLabel = detailsFramework:CreateLabel(auraScrollBox, options.title_text) + titleLabel.textcolor = "silver" + titleLabel.textsize = 10 + titleLabel:SetPoint("bottomleft", auraScrollBox, "topleft", 0, 2) + + for i = 1, options.line_amount do + auraScrollBox:CreateLine(createLineFunc) + end function auraScrollBox:TransformAuraData() local newData = {} @@ -638,10 +640,6 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur self.data = newData end - function auraScrollBox.SetProfile(self, profile) - self.profile = profile - end - auraScrollBox.SetData = function(self, data) self.data_original = data self.data = data @@ -652,6 +650,13 @@ function detailsFramework:CreateAuraScrollBox(parent, name, data, profile, onAur return self.data_original end + auraScrollBox.refresh_original = auraScrollBox.Refresh + + auraScrollBox.Refresh = function() + auraScrollBox:TransformAuraData() + auraScrollBox:refresh_original() + end + auraScrollBox:SetData(data) return auraScrollBox diff --git a/Libs/DF/textentry.lua b/Libs/DF/textentry.lua index 9fca9d279..799e4e388 100644 --- a/Libs/DF/textentry.lua +++ b/Libs/DF/textentry.lua @@ -541,6 +541,7 @@ end ---@field text any ---@field multiline any ---@field align any +---@field ShouldOptimizeAutoComplete boolean? ---@field SetTemplate fun(self:df_textentry, template:table) ---@field Disable fun(self:df_textentry) ---@field Enable fun(self:df_textentry) @@ -555,6 +556,7 @@ end ---@field SetEnterFunction fun(self:df_textentry, func:function, param1:any, param2:any) ---@field SetHook fun(self:df_textentry, hookName:string, func:function) ---@field SetAsSearchBox fun(self:df_textentry) +---@field SetAsAutoComplete fun(self:df_textentry, poolName:string, poolTable:table?, shouldOptimize:boolean?) poolName is the name of the member on textEntry that will be used to store the pool table, poolTable is an array with word to be used on the autocomplete, shouldOptimize is a boolean that will optimize the autocomplete by using a cache table, it's recommended to use it if the autocomplete array is too large. ---@param parent frame ---@param textChangedCallback function diff --git a/Libs/LibLuaServer/LibLuaServer.lua b/Libs/LibLuaServer/LibLuaServer.lua index ce846ed7d..6ac100c8f 100644 --- a/Libs/LibLuaServer/LibLuaServer.lua +++ b/Libs/LibLuaServer/LibLuaServer.lua @@ -607,3 +607,6 @@ ---@field SetTextColor fun(self: editbox, r: red|number, g: green|number, b: blue|number, a: alpha|number?) ---@field SetJustifyH fun(self:editbox, alignment:string) ---@field SetTextInsets fun(self:editbox, left:number, right:number, top:number, bottom:number) +---@field SetFocus fun(self:editbox, focus:boolean) +---@field HasFocus fun(self:editbox) : boolean return true if the editbox has focus +---@field HighlightText fun(self:editbox, start:number?, finish:number?) select a portion of the text, passing zero will select the entire text