Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to War Within #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to War Within
Updating InterfaceOptionsFrame to War Within
  • Loading branch information
Thrumbar committed Jun 2, 2024
commit 08e1aa8c52943394ec93c0052410f93376df9d93
297 changes: 157 additions & 140 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,152 +1,169 @@

local addonName, addon = ...
if not addon.healthCheck then return end
local L = addon.L

-- Ensure addon.db and BugSackLDBIconDB are initialized
addon.db = addon.db or {}
BugSackLDBIconDB = BugSackLDBIconDB or {}

local frame = addon.frame
frame.name = addonName
frame:Hide()
local ldbi = LibStub("LibDBIcon-1.0")

frame:SetScript("OnShow", function(frame)
local function newCheckbox(label, description, onClick)
local check = CreateFrame("CheckButton", "BugSackCheck" .. label, frame, "InterfaceOptionsCheckButtonTemplate")
check:SetScript("OnClick", function(self)
local tick = self:GetChecked()
onClick(self, tick and true or false)
if tick then
PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
else
PlaySound(857) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end)
check.label = _G[check:GetName() .. "Text"]
check.label:SetText(label)
check.tooltipText = label
check.tooltipRequirement = description
return check
end

local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText(addonName)

local autoPopup = newCheckbox(
L["Auto popup"],
L.autoDesc,
function(self, value) addon.db.auto = value end)
autoPopup:SetChecked(addon.db.auto)
autoPopup:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -2, -16)

local chatFrame = newCheckbox(
L["Chatframe output"],
L.chatFrameDesc,
function(self, value) addon.db.chatframe = value end)
chatFrame:SetChecked(addon.db.chatframe)
chatFrame:SetPoint("TOPLEFT", autoPopup, "BOTTOMLEFT", 0, -8)

local minimap = newCheckbox(
L["Minimap icon"],
L.minimapDesc,
function(self, value)
BugSackLDBIconDB.hide = not value
if BugSackLDBIconDB.hide then
ldbi:Hide(addonName)
else
ldbi:Show(addonName)
end
end)
minimap:SetPoint("TOPLEFT", chatFrame, "BOTTOMLEFT", 0, -8)
minimap:SetChecked(not BugSackLDBIconDB.hide)

if ldbi:IsButtonCompartmentAvailable() then
local addonCompartment = newCheckbox(
L.addonCompartment,
L.addonCompartment_desc,
function(self, value)
if value then
ldbi:AddButtonToCompartment("BugSack")
else
ldbi:RemoveButtonFromCompartment("BugSack")
end
end)
addonCompartment:SetPoint("LEFT", minimap, "RIGHT", 150, 0)
addonCompartment:SetChecked(ldbi:IsButtonInCompartment("BugSack"))
end

local mute = newCheckbox(
L["Mute"],
L.muteDesc,
function(self, value) addon.db.mute = value end)
mute:SetChecked(addon.db.mute)
mute:SetPoint("TOPLEFT", minimap, "BOTTOMLEFT", 0, -8)

local info = {}
local fontSizeDropdown = CreateFrame("Frame", "BugSackFontSize", frame, "UIDropDownMenuTemplate")
fontSizeDropdown:SetPoint("TOPLEFT", mute, "BOTTOMLEFT", -15, -10)
fontSizeDropdown.initialize = function()
wipe(info)
local fonts = {"GameFontHighlightSmall", "GameFontHighlight", "GameFontHighlightMedium", "GameFontHighlightLarge"}
local names = {L["Small"], L["Medium"], L["Large"], L["X-Large"]}
for i, font in next, fonts do
info.text = names[i]
info.value = font
info.func = function(self)
addon.db.fontSize = self.value
if _G.BugSackFrameScrollText then
_G.BugSackFrameScrollText:SetFontObject(_G[self.value])
end
BugSackFontSizeText:SetText(self:GetText())
end
info.checked = font == addon.db.fontSize
UIDropDownMenu_AddButton(info)
end
end
BugSackFontSizeText:SetText(L["Font size"])

local soundDropdown = CreateFrame("Frame", "BugSackSoundDropdown", frame, "UIDropDownMenuTemplate")
soundDropdown:SetPoint("LEFT", fontSizeDropdown, "RIGHT", 150, 0)
soundDropdown.initialize = function()
wipe(info)
for _, sound in next, LibStub("LibSharedMedia-3.0"):List("sound") do
info.text = sound
info.value = sound
info.func = function(self)
addon.db.soundMedia = self.value
soundDropdown.Text:SetText(self:GetText())
end
info.checked = sound == addon.db.soundMedia
UIDropDownMenu_AddButton(info)
end
end
soundDropdown.Text:SetText(L["Sound"])

local master = newCheckbox(
L.useMaster,
L.useMasterDesc,
function(self, value) addon.db.useMaster = value end)
master:SetChecked(addon.db.useMaster)
master:SetPoint("LEFT", soundDropdown, "RIGHT", 140, 0)

local clear = CreateFrame("Button", "BugSackSaveButton", frame, "UIPanelButtonTemplate")
clear:SetText(L["Wipe saved bugs"])
clear:SetWidth(177)
clear:SetHeight(24)
clear:SetPoint("TOPLEFT", fontSizeDropdown, "BOTTOMLEFT", 17, -25)
clear:SetScript("OnClick", function()
addon:Reset()
end)
clear.tooltipText = L["Wipe saved bugs"]
clear.newbieText = L.wipeDesc

local altWipe = newCheckbox(
L["Minimap icon alt-click wipe"],
L.altWipeDesc,
function(self, value) addon.db.altwipe = value end)
altWipe:SetChecked(addon.db.altwipe)
altWipe:SetPoint("LEFT", clear, "RIGHT", 10, 0)

frame:SetScript("OnShow", nil)
local function newCheckbox(label, description, onClick)
local check = CreateFrame("CheckButton", "BugSackCheck" .. label, frame, "InterfaceOptionsCheckButtonTemplate")
check:SetScript("OnClick", function(self)
local tick = self:GetChecked()
onClick(self, tick and true or false)
if tick then
PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
else
PlaySound(857) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF
end
end)
check.label = _G[check:GetName() .. "Text"]
check.label:SetText(label)
check.tooltipText = label
check.tooltipRequirement = description
return check
end

local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText(addonName)

local autoPopup = newCheckbox(
L["Auto popup"],
L.autoDesc,
function(self, value) addon.db.auto = value end)
autoPopup:SetChecked(addon.db.auto)
autoPopup:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -2, -16)

local chatFrame = newCheckbox(
L["Chatframe output"],
L.chatFrameDesc,
function(self, value) addon.db.chatframe = value end)
chatFrame:SetChecked(addon.db.chatframe)
chatFrame:SetPoint("TOPLEFT", autoPopup, "BOTTOMLEFT", 0, -8)

local minimap = newCheckbox(
L["Minimap icon"],
L.minimapDesc,
function(self, value)
BugSackLDBIconDB.hide = not value
if BugSackLDBIconDB.hide then
ldbi:Hide(addonName)
else
ldbi:Show(addonName)
end
end)
minimap:SetPoint("TOPLEFT", chatFrame, "BOTTOMLEFT", 0, -8)
minimap:SetChecked(not BugSackLDBIconDB.hide)

if ldbi.IsButtonCompartmentAvailable and ldbi:IsButtonCompartmentAvailable() then
local addonCompartment = newCheckbox(
L.addonCompartment,
L.addonCompartment_desc,
function(self, value)
if value then
ldbi:AddButtonToCompartment("BugSack")
else
ldbi:RemoveButtonFromCompartment("BugSack")
end
end)
addonCompartment:SetPoint("LEFT", minimap, "RIGHT", 150, 0)
addonCompartment:SetChecked(ldbi.IsButtonInCompartment and ldbi:IsButtonInCompartment("BugSack"))
end

local mute = newCheckbox(
L["Mute"],
L.muteDesc,
function(self, value) addon.db.mute = value end)
mute:SetChecked(addon.db.mute)
mute:SetPoint("TOPLEFT", minimap, "BOTTOMLEFT", 0, -8)

local info = {}
local fontSizeDropdown = CreateFrame("Frame", "BugSackFontSize", frame, "UIDropDownMenuTemplate")
fontSizeDropdown:SetPoint("TOPLEFT", mute, "BOTTOMLEFT", -15, -10)
fontSizeDropdown.initialize = function()
wipe(info)
local fonts = {"GameFontHighlightSmall", "GameFontHighlight", "GameFontHighlightMedium", "GameFontHighlightLarge"}
local names = {L["Small"], L["Medium"], L["Large"], L["X-Large"]}
for i, font in next, fonts do
info.text = names[i]
info.value = font
info.func = function(self)
addon.db.fontSize = self.value
if _G.BugSackFrameScrollText then
_G.BugSackFrameScrollText:SetFontObject(_G[self.value])
end
BugSackFontSizeText:SetText(self:GetText())
end
info.checked = font == addon.db.fontSize
UIDropDownMenu_AddButton(info)
end
end
BugSackFontSizeText:SetText(L["Font size"])

local soundDropdown = CreateFrame("Frame", "BugSackSoundDropdown", frame, "UIDropDownMenuTemplate")
soundDropdown:SetPoint("LEFT", fontSizeDropdown, "RIGHT", 150, 0)
soundDropdown.initialize = function()
wipe(info)
for _, sound in next, LibStub("LibSharedMedia-3.0"):List("sound") do
info.text = sound
info.value = sound
info.func = function(self)
addon.db.soundMedia = self.value
soundDropdown.Text:SetText(self:GetText())
end
info.checked = sound == addon.db.soundMedia
UIDropDownMenu_AddButton(info)
end
end
soundDropdown.Text:SetText(L["Sound"])

local master = newCheckbox(
L.useMaster,
L.useMasterDesc,
function(self, value) addon.db.useMaster = value end)
master:SetChecked(addon.db.useMaster)
master:SetPoint("LEFT", soundDropdown, "RIGHT", 140, 0)

local clear = CreateFrame("Button", "BugSackSaveButton", frame, "UIPanelButtonTemplate")
clear:SetText(L["Wipe saved bugs"])
clear:SetWidth(177)
clear:SetHeight(24)
clear:SetPoint("TOPLEFT", fontSizeDropdown, "BOTTOMLEFT", 17, -25)
clear:SetScript("OnClick", function()
addon:Reset()
end)
clear.tooltipText = L["Wipe saved bugs"]
clear.newbieText = L.wipeDesc

local altWipe = newCheckbox(
L["Minimap icon alt-click wipe"],
L.altWipeDesc,
function(self, value) addon.db.altwipe = value end)
altWipe:SetChecked(addon.db.altwipe)
altWipe:SetPoint("LEFT", clear, "RIGHT", 10, 0)

frame:SetScript("OnShow", nil)
end)
InterfaceOptions_AddCategory(frame)

local category
if frame.parent then
local parentCategory = Settings.GetCategory(frame.parent)
category, _ = Settings.RegisterCanvasLayoutSubcategory(parentCategory, frame, frame.name, frame.name)
else
category, _ = Settings.RegisterCanvasLayoutCategory(frame, frame.name, frame.name)
end

if category then
category.ID = frame.name
Settings.RegisterAddOnCategory(category)
Settings.OpenToCategory(category)
else
print("Error: Unable to register the settings category for", addonName)
end
16 changes: 13 additions & 3 deletions ldb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ local plugin = ldb:NewDataObject(addonName, {

local BugGrabber = BugGrabber

-- Function to open the Interface Options to a specific category
local function openInterfaceOptionsToCategory(category)
if Settings and Settings.OpenToCategory then
-- New API in Dragonflight and beyond
Settings.OpenToCategory(category)
else
-- Fallback for older versions
InterfaceOptionsFrame_OpenToCategory(category)
end
end

function plugin.OnClick(self, button)
if button == "RightButton" then
InterfaceOptionsFrame_OpenToCategory(addonName)
InterfaceOptionsFrame_OpenToCategory(addonName)
openInterfaceOptionsToCategory(addonName)
openInterfaceOptionsToCategory(addonName)
else
if IsShiftKeyDown() then
ReloadUI()
Expand Down Expand Up @@ -62,4 +73,3 @@ f:SetScript("OnEvent", function()
icon:Register(addonName, plugin, BugSackLDBIconDB)
end)
f:RegisterEvent("PLAYER_LOGIN")