Skip to content

Commit

Permalink
Add settings to the map tracker menu for easy adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Sep 9, 2024
1 parent 972311d commit 1f4a3e3
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions settings.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local _, addon = ...
local addonName, addon = ...
local L = addon.L

local function formatPercentage(value)
return PERCENTAGE_STRING:format(math.floor((value * 100) + 0.5))
end

addon:RegisterSettings('BetterWorldQuestsDB', {
local settings = {
{
key = 'mapScale',
type = 'slider',
Expand Down Expand Up @@ -64,6 +64,59 @@ addon:RegisterSettings('BetterWorldQuestsDB', {
SHIFT = SHIFT_KEY,
},
},
})
}

addon:RegisterSettings('BetterWorldQuestsDB', settings)
addon:RegisterSettingsSlash('/betterworldquests', '/bwq')

-- custom menu element for a slider
-- since the slider needs to be quite wide in order to be functional it's added to a sub-menu
local function createSlider(root, name, getter, setter, minValue, maxValue, steps, formatter)
local element = root:CreateButton(name):CreateFrame()
element:AddInitializer(function(frame)
local slider = frame:AttachTemplate('MinimalSliderWithSteppersTemplate')
slider:SetPoint('TOPLEFT', 0, -1)
slider:SetSize(150, 25)
slider:RegisterCallback('OnValueChanged', setter, frame)
slider:Init(getter(), minValue, maxValue, (maxValue - minValue) / steps, {
[MinimalSliderWithSteppersMixin.Label.Right] = formatter

Check warning on line 82 in settings.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'MinimalSliderWithSteppersMixin'
})

-- there's no way to properly reset an element from the menu, so we'll need to use
-- a dummy element we can hook OnHide onto, and also to increase the total width
-- of the element so the right label doesn't go out of the bounds of the menu.
-- see https://github.com/Stanzilla/WoWUIBugs/issues/652
local dummy = frame:AttachFrame('Frame')
dummy:SetPoint('TOPLEFT', slider)
dummy:SetPoint('BOTTOMLEFT', slider)
dummy:SetWidth(180)
dummy:SetScript('OnHide', function()
slider:UnregisterCallback('OnValueChanged', frame)
slider:Release()
end)
end)

return element
end

-- inject some of the settings into the tracking menu
Menu.ModifyMenu('MENU_WORLD_MAP_TRACKING', function(_, root, data)

Check warning on line 103 in settings.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'Menu'

Check warning on line 103 in settings.lua

View workflow job for this annotation

GitHub Actions / lint

unused argument 'data'
root:CreateDivider()
root:CreateTitle((addonName:gsub('(%l)(%u)', '%1 %2')) .. HEADER_COLON)

Check warning on line 105 in settings.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'HEADER_COLON'

for _, setting in next, settings do
if setting.type == 'toggle' then
root:CreateCheckbox(setting.title, function()
return addon:GetOption(setting.key)
end, function()
addon:SetOption(setting.key, not addon:GetOption(setting.key))
end)
elseif setting.type == 'slider' then
createSlider(root, setting.title, function()
return addon:GetOption(setting.key)
end, function(_, value)
addon:SetOption(setting.key, value)
end, setting.minValue, setting.maxValue, setting.valueStep, setting.valueFormat)
end
end
end)

0 comments on commit 1f4a3e3

Please sign in to comment.