Added Search into the options panel

This commit is contained in:
Tercio Jose
2021-09-24 22:07:13 -03:00
parent e607f32edb
commit 1c20f166cb
14 changed files with 503 additions and 335 deletions
+92 -2
View File
@@ -190,6 +190,88 @@ function Details.options.InitializeOptionsWindow(instance)
changelog:SetTemplate (options_button_template)
changelog:SetIcon ("Interface\\AddOns\\Details\\images\\icons", nil, nil, nil, {367/512, 399/512, 43/512, 76/512}, {1, 1, 1, 0.8}, 4, 2)
--search field
local searchBox = DF:CreateTextEntry(f, function()end, 150, 20, _, _, _, options_dropdown_template)
searchBox:SetHook ("OnChar", f.OnSearchBoxTextChanged)
searchBox:SetHook ("OnTextChanged", f.OnSearchBoxTextChanged)
searchBox:SetPoint ("topright", f, "topright", -5, -30)
local searchLabel = DF:CreateLabel(f, "Search:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
searchLabel:SetPoint ("right", searchBox, "left", -2, 0)
searchBox:SetHook("OnChar", function()
if (searchBox.text ~= "") then
local searchSection = f.sectionFramesContainer[19]
searchSection.sectionButton:Enable()
searchSection.sectionButton:Click()
local searchingFor = searchBox.text
local allSectionFrames = f.sectionFramesContainer
local allSectionNames = {}
local allSectionOptions = {}
for i = 1, #allSectionFrames do
local sectionFrame = allSectionFrames[i]
local sectionOptionsTable = sectionFrame.sectionOptions
allSectionNames[#allSectionNames+1] = sectionFrame.name
allSectionOptions[#allSectionOptions+1] = sectionOptionsTable
end
--this table will hold all options
local allOptions = {}
--start the fill process filling 'allOptions' with each individual option from each tab
for i = 1, #allSectionOptions do
local sectionOptions = allSectionOptions[i]
local lastLabel = nil
for k, setting in pairs(sectionOptions) do
if (setting.type == "label") then
lastLabel = setting
end
if (setting.name) then
allOptions[#allOptions+1] = {setting = setting, label = lastLabel, header = allSectionNames[i]}
end
end
end
local searchingText = string.lower(searchingFor)
searchBox:SetFocus()
local options = {}
local lastTab = nil
local lastLabel = nil
for i = 1, #allOptions do
local optionData = allOptions[i]
local optionName = string.lower(optionData.setting.name)
if (optionName:find(searchingText)) then
if optionData.header ~= lastTab then
if lastTab ~= nil then
options[#options+1] = {type = "label", get = function() return "" end, text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")} -- blank
end
options[#options+1] = {type = "label", get = function() return optionData.header end, text_template = {color = "silver", size = 14, font = DF:GetBestFontForLanguage()}}
lastTab = optionData.header
lastLabel = nil
end
if optionData.label ~= lastLabel then
options[#options+1] = optionData.label
lastLabel = optionData.label
end
options[#options+1] = optionData.setting
end
end
local startX = 200
local startY = -40
DF:BuildMenuVolatile(searchSection, options, startX, startY, 500, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template, globalCallback)
else
f.sectionFramesContainer[19].sectionButton:Disable()
end
end)
local sectionsName = { --section names
[1] = Loc ["STRING_OPTIONSMENU_DISPLAY"],
[3] = Loc ["STRING_OPTIONSMENU_ROWSETTINGS"],
@@ -214,12 +296,15 @@ function Details.options.InitializeOptionsWindow(instance)
[18] = "Mythic Dungeon",
[19] = "Search Results",
}
local optionsSectionsOrder = {
1, "", 3, 4, "", 5, 6, 7, 12, 13, "", 9, 2, 8, 10, 11, 18, "", 14, 15, 16, 17--, 18, 19
1, "", 3, 4, "", 5, 6, 7, 12, 13, "", 9, 2, 8, 10, 11, 18, "", 14, 15, 16, 17, "", 19
}
local maxSectionIds = 18
local maxSectionIds = 19
Details.options.maxSectionIds = maxSectionIds
local buttonYPosition = -40
@@ -248,6 +333,7 @@ function Details.options.InitializeOptionsWindow(instance)
local sectionFrame = CreateFrame("frame", "$parentTab" .. sectionId, f, "BackdropTemplate")
sectionFrame:SetAllPoints()
sectionFrame:EnableMouse(false)
sectionFrame.name = sectionsName[sectionId]
--tinsert(f.sectionFramesContainer, sectionFrame)
f.sectionFramesContainer[sectionId] = sectionFrame
@@ -261,6 +347,10 @@ function Details.options.InitializeOptionsWindow(instance)
sectionButton:SetPoint("topleft", f, "topleft", 10, buttonYPosition)
buttonYPosition = buttonYPosition - (section_menu_button_height + 1)
sectionFrame.sectionButton = sectionButton
if (sectionId == 19) then --search results
sectionButton:Disable()
end
end
else
buttonYPosition = buttonYPosition - 15