addon/Addon/Code/Options.lua

135 lines
4.5 KiB
Lua
Raw Normal View History

local _, addon = ...
local Options = {}
addon.Options = Options
local function RegisterAddOnSettings(name, title)
return Settings.RegisterAddOnSetting(
Options.category,
"CzechQuestsAddon__" .. name,
name,
CzechQuestsAddon_Store.config,
type(CzechQuestsAddon_Store.config[name]),
title,
CzechQuestsAddon_Store.config[name]
)
end
local function RegisterProxySettings(name, title, setter)
return Settings.RegisterProxySetting(
Options.category,
"CzechQuestsAddon__" .. name,
type(CzechQuestsAddon_Store.config[name]),
title,
CzechQuestsAddon_Store.config[name],
function()
return CzechQuestsAddon_Store.config[name]
end,
function(value) setter(name, value) end
)
end
2025-03-07 13:57:47 +01:00
local function CreateCheckbox(name, title, setter)
local register = RegisterAddOnSettings(name, title)
register:SetValueChangedCallback(function(_, value) setter(name, value) end)
2025-03-07 13:57:47 +01:00
Settings.CreateCheckbox(Options.category, register)
end
local function CreateDropdown(name, title, items, setter)
2025-03-07 13:57:47 +01:00
Settings.CreateDropdown(Options.category, RegisterProxySettings(name, title, setter), items)
end
local function CreateSlider(name, title, min, max, step, setter)
local options = Settings.CreateSliderOptions(min, max, step)
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right);
2025-03-07 13:57:47 +01:00
Settings.CreateSlider(Options.category, RegisterProxySettings(name, title, setter), options)
end
local function CreateButton(title, label, setter)
Options.layout:AddInitializer(
CreateSettingsButtonInitializer(title, label, function(value) setter(name, value) end, nil, title)
)
end
local function InitQuests()
2025-03-07 13:57:47 +01:00
local function Update(name, value)
CzechQuestsAddon_Store.config[name] = value
addon.QuestFrame:UpdateSettings()
end
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Questy"))
CreateCheckbox("QUEST_ENABLED", "Zapnout", Update)
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
CreateCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim", Update)
end
CreateDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer, Update)
CreateDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer, Update)
CreateSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1, Update)
CreateSlider("QUEST_TEXT_FONT_SIZE", "Velikost textu", 10, 30, 1, Update)
2025-03-07 13:57:47 +01:00
CreateSlider("QUEST_TEXTURE_ALPHA", "Pruhlednost pozadi", 10, 100, 10, Update)
CreateCheckbox("QUEST_TEXTURE_ALPHA_ONLY_MOVING", "Pruhlednost pouze pri chuzi", Update)
end
local function InitSpeeches()
local function Update(name, value)
CzechQuestsAddon_Store.config[name] = value
addon.SpeechFrame:UpdateSettings()
end
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Bubliny"))
CreateCheckbox("SPEECH_ENABLED", "Zapnout", Update)
CreateDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update)
CreateSlider("SPEECH_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1, Update)
CreateSlider("SPEECH_FRAME_WIDTH", "Sirka okna", 200, 1000, 10, Update)
CreateCheckbox("SPEECH_ORIGINAL_WHEN_MISSING", "Original pokud není preklad", Update)
CreateSlider("SPEECH_MESSAGE_TEXTURE_ALPHA", "Pruhlednost pozadi zpravy", 0, 100, 10, Update)
CreateSlider("SPEECH_FRAME_POSITION_X", "Pozice okna X", 0, math.floor(GetScreenWidth()), 1, Update)
CreateSlider("SPEECH_FRAME_POSITION_Y", "Pozice okna Y", 0, math.floor(GetScreenHeight()), 1, Update)
CreateButton('Resetovat pozici okna', "RESET", function()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = 0
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = 0
addon.SpeechFrame:UpdateSettings()
end)
end
local function InitOthers()
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Ostatni"))
CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG", function()
end)
end
local function InitOptions()
local category, layout = Settings.RegisterVerticalLayoutCategory("CzechQuests")
Options.category = category
Options.layout = layout
InitQuests()
InitSpeeches()
InitOthers()
Settings.RegisterAddOnCategory(category)
end
addon.API.InitOptions = InitOptions