addon/Quests/Frames/OptionsFrame.lua

54 lines
1.8 KiB
Lua
Executable file

local defaultOptions = {
DEBUG_MODE = false,
SELECTED_INTERACTION = 'hover',
SELECTED_HOTKEY = nil
}
local addonName = ...
local optionsFrame = CreateFrame("Frame")
local function CreateCheckBox(parent, optionsPanel, text, onClick)
local checkbox = CreateFrame("CheckButton", nil, optionsPanel, "InterfaceOptionsCheckButtonTemplate")
checkbox.Text:SetText(text)
checkbox:SetScript("OnClick", onClick)
return checkbox
end
local function createOptionCheckbox(parent, optionsPanel, text, optionKey)
local checkbox = CreateCheckBox(parent, optionsPanel, text, function(self)
local checked = self:GetChecked()
CzechQuestsOptions[optionKey] = checked
end)
checkbox:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -8)
checkbox:SetChecked(CzechQuestsOptions[optionKey])
return checkbox
end
local function InitializeOptions()
local optionsPanel = CreateFrame("Frame", "CzechQuestsOptionsPanel", UIParent)
optionsPanel.name = "CzechQuests"
local title = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText("CzechQuests")
local enableDebugModeCheckbox = createOptionCheckbox(title, optionsPanel,"Enable DEBUG mode", "DEBUG_MODE")
enableDebugModeCheckbox:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 16, -8)
InterfaceOptions_AddCategory(optionsPanel)
end
local function addonLoaded(self, event, addonLoadedName)
if addonLoadedName == addonName then
CzechQuestsOptions = CzechQuestsOptions or defaultOptions
for key, value in pairs(defaultOptions) do
if CzechQuestsOptions[key] == nil then
CzechQuestsOptions[key] = value
end
end
InitializeOptions()
end
end
optionsFrame:RegisterEvent("ADDON_LOADED")
optionsFrame:SetScript("OnEvent", addonLoaded)