From 80257c868de9b0f758ad67e12c4e63c9a60d2766 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Fri, 29 Nov 2024 18:17:02 +0100 Subject: [PATCH] API update --- settings.lua | 61 +++++----------------------------------------------- storms.lua | 7 ++---- 2 files changed, 7 insertions(+), 61 deletions(-) diff --git a/settings.lua b/settings.lua index ee38ac7..c05b57a 100644 --- a/settings.lua +++ b/settings.lua @@ -58,65 +58,14 @@ local settings = { tooltip = L['Hold this key to temporarily hide all world quests'], default = 'ALT', options = { - NEVER = NEVER, - ALT = ALT_KEY, - CTRL = CTRL_KEY, - SHIFT = SHIFT_KEY, + {value='NEVER', label=NEVER}, + {value='ALT', label=ALT_KEY}, + {value='CTRL', label=CTRL_KEY}, + {value='SHIFT', label=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 - }) - - -- 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) - root:CreateDivider() - root:CreateTitle((addonName:gsub('(%l)(%u)', '%1 %2')) .. 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) +addon:RegisterMapSettings('BetterWorldQuestsDB', settings) diff --git a/storms.lua b/storms.lua index ade9d29..8df57d4 100644 --- a/storms.lua +++ b/storms.lua @@ -1,3 +1,4 @@ +local _, addon = ... local HBD = LibStub('HereBeDragons-2.0') local DRAGON_ISLES_MAPS = { @@ -7,10 +8,6 @@ local DRAGON_ISLES_MAPS = { [2025] = true, -- Thaldraszus } -local function startsWith(str, start) - return string.sub(str, 1, string.len(start)) == start -end - local function updatePOIs(self) local map = self:GetMap() local mapID = map:GetMapID() @@ -18,7 +15,7 @@ local function updatePOIs(self) for childMapID in next, DRAGON_ISLES_MAPS do for _, poiID in next, C_AreaPoiInfo.GetAreaPOIForMap(childMapID) do local info = C_AreaPoiInfo.GetAreaPOIInfo(childMapID, poiID) - if info and startsWith(info.atlasName, 'ElementalStorm') then + if info and addon:startswith(info.atlasName, 'ElementalStorm') then local x, y = info.position:GetXY() info.dataProvider = self info.position:SetXY(HBD:TranslateZoneCoordinates(x, y, childMapID, mapID))