Refactor code structure for improved readability and maintainability
This commit is contained in:
414
Modules/EncounterAlerts/EncounterAlertsOptions.lua
Normal file
414
Modules/EncounterAlerts/EncounterAlertsOptions.lua
Normal file
@@ -0,0 +1,414 @@
|
||||
local ADDON_NAME = "HailMaryGuildTools"
|
||||
local HMGT = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME)
|
||||
if not HMGT then return end
|
||||
if not HMGT_Config or not HMGT_Config.RegisterOptionsProvider then return end
|
||||
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME, true) or {}
|
||||
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0", true)
|
||||
|
||||
local function NotifyOptionsChanged()
|
||||
if AceConfigRegistry and type(AceConfigRegistry.NotifyChange) == "function" then
|
||||
AceConfigRegistry:NotifyChange(ADDON_NAME)
|
||||
end
|
||||
end
|
||||
|
||||
local function GetSettings()
|
||||
local profile = HMGT.db and HMGT.db.profile
|
||||
if not profile then
|
||||
return {}
|
||||
end
|
||||
profile.encounterAlerts = type(profile.encounterAlerts) == "table" and profile.encounterAlerts or {}
|
||||
return profile.encounterAlerts
|
||||
end
|
||||
|
||||
local function GetLuraSettings()
|
||||
local settings = GetSettings()
|
||||
settings.luraRunes = type(settings.luraRunes) == "table" and settings.luraRunes or {}
|
||||
settings.luraRunes.slots = type(settings.luraRunes.slots) == "table" and settings.luraRunes.slots or {}
|
||||
settings.luraRunes.actionBar = type(settings.luraRunes.actionBar) == "table" and settings.luraRunes.actionBar or {}
|
||||
return settings.luraRunes
|
||||
end
|
||||
|
||||
local function GetLuraActionBarSettings()
|
||||
local settings = GetLuraSettings()
|
||||
settings.actionBar.shown = settings.actionBar.shown == true
|
||||
settings.actionBar.autoShow = settings.actionBar.autoShow ~= false
|
||||
settings.actionBar.unlocked = settings.actionBar.unlocked == true
|
||||
settings.actionBar.iconSize = tonumber(settings.actionBar.iconSize) or 42
|
||||
settings.actionBar.iconSpacing = tonumber(settings.actionBar.iconSpacing) or 8
|
||||
settings.actionBar.orientation = tostring(settings.actionBar.orientation or "horizontal")
|
||||
if settings.actionBar.orientation ~= "vertical" then
|
||||
settings.actionBar.orientation = "horizontal"
|
||||
end
|
||||
settings.actionBar.border = type(settings.actionBar.border) == "table" and settings.actionBar.border or {}
|
||||
return settings.actionBar
|
||||
end
|
||||
|
||||
local function GetLuraBorderSettings()
|
||||
local actionBar = GetLuraActionBarSettings()
|
||||
actionBar.border.enabled = actionBar.border.enabled == true
|
||||
actionBar.border.width = tonumber(actionBar.border.width) or 2
|
||||
actionBar.border.color = type(actionBar.border.color) == "table" and actionBar.border.color or {}
|
||||
actionBar.border.color.r = tonumber(actionBar.border.color.r) or 1
|
||||
actionBar.border.color.g = tonumber(actionBar.border.color.g) or 0.82
|
||||
actionBar.border.color.b = tonumber(actionBar.border.color.b) or 0.1
|
||||
actionBar.border.color.a = tonumber(actionBar.border.color.a) or 0.9
|
||||
return actionBar.border
|
||||
end
|
||||
|
||||
local function GetActionBarOrientationValues()
|
||||
return {
|
||||
horizontal = L["OPT_EA_LURA_ACTIONBAR_HORIZONTAL"] or "Horizontal",
|
||||
vertical = L["OPT_EA_LURA_ACTIONBAR_VERTICAL"] or "Vertical",
|
||||
}
|
||||
end
|
||||
|
||||
local function GetLuraRunes()
|
||||
return HMGT.EncounterAlerts and HMGT.EncounterAlerts.LuraRunes or nil
|
||||
end
|
||||
|
||||
local function RefreshEncounterAlerts()
|
||||
if HMGT.EncounterAlerts then
|
||||
local settings = GetSettings()
|
||||
HMGT.EncounterAlerts.runtimeEnabled = settings.enabled == true
|
||||
if HMGT.EncounterAlerts.LuraRunes and HMGT.EncounterAlerts.LuraRunes.Refresh then
|
||||
HMGT.EncounterAlerts.LuraRunes:Refresh()
|
||||
end
|
||||
end
|
||||
NotifyOptionsChanged()
|
||||
end
|
||||
|
||||
local function BuildRuneWindowOptions()
|
||||
return {
|
||||
type = "group",
|
||||
inline = true,
|
||||
order = 2,
|
||||
name = L["OPT_EA_LURA_RUNE_WINDOW"] or "Rune window",
|
||||
args = {
|
||||
unlocked = {
|
||||
type = "toggle",
|
||||
order = 1,
|
||||
width = "double",
|
||||
name = L["OPT_EA_LURA_UNLOCK"] or "Unlock rune frame",
|
||||
get = function()
|
||||
return GetLuraSettings().unlocked == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetSettings().enabled = true
|
||||
local settings = GetLuraSettings()
|
||||
settings.enabled = true
|
||||
settings.unlocked = value == true
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
hint = {
|
||||
type = "description",
|
||||
order = 2,
|
||||
width = "full",
|
||||
name = L["OPT_EA_LURA_HINT"] or "First version: normal/heroic layout only. Tank reference is placed bottom-center between slot 1 and 5.",
|
||||
},
|
||||
show = {
|
||||
type = "execute",
|
||||
order = 3,
|
||||
width = 0.8,
|
||||
name = L["OPT_EA_LURA_SHOW"] or "Show",
|
||||
func = function()
|
||||
local lura = GetLuraRunes()
|
||||
if lura and lura.Show then
|
||||
lura:Show()
|
||||
end
|
||||
end,
|
||||
},
|
||||
test = {
|
||||
type = "execute",
|
||||
order = 4,
|
||||
width = 0.9,
|
||||
name = L["OPT_EA_LURA_TEST"] or "Test pattern",
|
||||
func = function()
|
||||
local lura = GetLuraRunes()
|
||||
if lura and lura.Show and lura.ApplyTestPattern then
|
||||
lura:Show()
|
||||
lura:ApplyTestPattern()
|
||||
end
|
||||
end,
|
||||
},
|
||||
clear = {
|
||||
type = "execute",
|
||||
order = 5,
|
||||
width = 0.8,
|
||||
name = L["OPT_EA_LURA_CLEAR"] or "Clear",
|
||||
func = function()
|
||||
local lura = GetLuraRunes()
|
||||
if lura and lura.ClearAssignments then
|
||||
lura:ClearAssignments(false)
|
||||
end
|
||||
end,
|
||||
},
|
||||
broadcast = {
|
||||
type = "execute",
|
||||
order = 6,
|
||||
width = 1.2,
|
||||
name = L["OPT_EA_LURA_BROADCAST"] or "Broadcast",
|
||||
disabled = function()
|
||||
local lura = GetLuraRunes()
|
||||
return lura and lura.CanBroadcastSequence and not lura:CanBroadcastSequence() or false
|
||||
end,
|
||||
func = function()
|
||||
local lura = GetLuraRunes()
|
||||
if lura and lura.BroadcastAssignments then
|
||||
lura:BroadcastAssignments()
|
||||
end
|
||||
end,
|
||||
},
|
||||
iconSize = {
|
||||
type = "range",
|
||||
order = 7,
|
||||
width = 1.1,
|
||||
min = 28,
|
||||
max = 80,
|
||||
step = 1,
|
||||
name = L["OPT_EA_LURA_ICON_SIZE"] or "Icon size",
|
||||
get = function()
|
||||
return tonumber(GetLuraSettings().iconSize) or 44
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraSettings().iconSize = tonumber(value) or 44
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
backgroundAlpha = {
|
||||
type = "range",
|
||||
order = 8,
|
||||
width = 1.1,
|
||||
min = 0,
|
||||
max = 0.8,
|
||||
step = 0.01,
|
||||
name = L["OPT_EA_LURA_BACKGROUND_ALPHA"] or "Background alpha",
|
||||
get = function()
|
||||
return tonumber(GetLuraSettings().backgroundAlpha) or 0.14
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraSettings().backgroundAlpha = tonumber(value) or 0.14
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
local function BuildRuneActionBarOptions()
|
||||
return {
|
||||
type = "group",
|
||||
inline = true,
|
||||
order = 3,
|
||||
name = L["OPT_EA_LURA_ACTIONBAR"] or "Rune action bar",
|
||||
args = {
|
||||
shown = {
|
||||
type = "toggle",
|
||||
order = 1,
|
||||
width = 1.1,
|
||||
name = L["OPT_EA_LURA_ACTIONBAR_SHOW"] or "Show bar",
|
||||
get = function()
|
||||
return GetLuraActionBarSettings().shown == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetSettings().enabled = true
|
||||
local settings = GetLuraSettings()
|
||||
settings.enabled = true
|
||||
GetLuraActionBarSettings().shown = value == true
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
unlocked = {
|
||||
type = "toggle",
|
||||
order = 2,
|
||||
width = 1.2,
|
||||
name = L["OPT_EA_LURA_ACTIONBAR_UNLOCK"] or "Unlock bar",
|
||||
get = function()
|
||||
return GetLuraActionBarSettings().unlocked == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetSettings().enabled = true
|
||||
local settings = GetLuraSettings()
|
||||
settings.enabled = true
|
||||
local actionBar = GetLuraActionBarSettings()
|
||||
actionBar.shown = true
|
||||
actionBar.unlocked = value == true
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
autoShow = {
|
||||
type = "toggle",
|
||||
order = 2.5,
|
||||
width = 1.4,
|
||||
name = L["OPT_EA_LURA_ACTIONBAR_AUTO_SHOW"] or "Auto show in boss room",
|
||||
get = function()
|
||||
return GetLuraActionBarSettings().autoShow == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraActionBarSettings().autoShow = value == true
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
orientation = {
|
||||
type = "select",
|
||||
order = 3,
|
||||
width = 1.2,
|
||||
name = L["OPT_EA_LURA_ACTIONBAR_ORIENTATION"] or "Orientation",
|
||||
values = GetActionBarOrientationValues,
|
||||
get = function()
|
||||
return GetLuraActionBarSettings().orientation
|
||||
end,
|
||||
set = function(_, value)
|
||||
local actionBar = GetLuraActionBarSettings()
|
||||
actionBar.orientation = tostring(value or "horizontal")
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
iconSize = {
|
||||
type = "range",
|
||||
order = 5,
|
||||
width = 1.1,
|
||||
min = 28,
|
||||
max = 80,
|
||||
step = 1,
|
||||
name = L["OPT_EA_LURA_ICON_SIZE"] or "Icon size",
|
||||
get = function()
|
||||
return tonumber(GetLuraActionBarSettings().iconSize) or 42
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraActionBarSettings().iconSize = tonumber(value) or 42
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
iconSpacing = {
|
||||
type = "range",
|
||||
order = 6,
|
||||
width = 1.1,
|
||||
min = 0,
|
||||
max = 80,
|
||||
step = 1,
|
||||
name = L["OPT_EA_LURA_ICON_SPACING"] or "Icon spacing",
|
||||
get = function()
|
||||
return tonumber(GetLuraActionBarSettings().iconSpacing) or 8
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraActionBarSettings().iconSpacing = tonumber(value) or 8
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
borderEnabled = {
|
||||
type = "toggle",
|
||||
order = 7,
|
||||
width = 1.1,
|
||||
name = L["OPT_EA_LURA_BORDER_ENABLED"] or "Show border",
|
||||
get = function()
|
||||
return GetLuraBorderSettings().enabled == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraBorderSettings().enabled = value == true
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
borderWidth = {
|
||||
type = "range",
|
||||
order = 8,
|
||||
width = 1.1,
|
||||
min = 1,
|
||||
max = 12,
|
||||
step = 1,
|
||||
name = L["OPT_EA_LURA_BORDER_WIDTH"] or "Border width",
|
||||
disabled = function()
|
||||
return GetLuraBorderSettings().enabled ~= true
|
||||
end,
|
||||
get = function()
|
||||
return tonumber(GetLuraBorderSettings().width) or 2
|
||||
end,
|
||||
set = function(_, value)
|
||||
GetLuraBorderSettings().width = tonumber(value) or 2
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
borderColor = {
|
||||
type = "color",
|
||||
order = 9,
|
||||
width = 1.1,
|
||||
hasAlpha = true,
|
||||
name = L["OPT_EA_LURA_BORDER_COLOR"] or "Border color",
|
||||
disabled = function()
|
||||
return GetLuraBorderSettings().enabled ~= true
|
||||
end,
|
||||
get = function()
|
||||
local color = GetLuraBorderSettings().color
|
||||
return color.r or 1, color.g or 0.82, color.b or 0.1, color.a or 0.9
|
||||
end,
|
||||
set = function(_, r, g, b, a)
|
||||
local color = GetLuraBorderSettings().color
|
||||
color.r = tonumber(r) or 1
|
||||
color.g = tonumber(g) or 0.82
|
||||
color.b = tonumber(b) or 0.1
|
||||
color.a = tonumber(a) or 0.9
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
hint = {
|
||||
type = "description",
|
||||
order = 10,
|
||||
width = "full",
|
||||
name = L["OPT_EA_LURA_ACTIONBAR_HINT"] or "Click rune buttons in the observed order. Slot 5 sends the sequence automatically.",
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
HMGT_Config:RegisterOptionsProvider("encounterAlerts", function()
|
||||
return {
|
||||
path = "encounterAlerts",
|
||||
order = 50,
|
||||
group = {
|
||||
type = "group",
|
||||
name = L["OPT_MODULE_ENCOUNTER_ALERTS"] or "Encounter Alerts",
|
||||
order = 50,
|
||||
childGroups = "tab",
|
||||
args = {
|
||||
general = {
|
||||
type = "group",
|
||||
name = L["OPT_GENERAL"] or "General",
|
||||
order = 1,
|
||||
args = {
|
||||
description = {
|
||||
type = "description",
|
||||
order = 1,
|
||||
width = "full",
|
||||
name = L["OPT_ENCOUNTER_ALERTS_PLACEHOLDER"] or "Encounter-specific helper frames and alerts.",
|
||||
},
|
||||
},
|
||||
},
|
||||
luraRunes = {
|
||||
type = "group",
|
||||
name = L["OPT_EA_LURA_TITLE"] or "L'ura Runes",
|
||||
order = 2,
|
||||
args = {
|
||||
enabled = {
|
||||
type = "toggle",
|
||||
order = 1,
|
||||
width = "double",
|
||||
name = L["OPT_EA_LURA_ENABLED"] or "Enable L'ura runes",
|
||||
get = function()
|
||||
return GetLuraSettings().enabled == true
|
||||
end,
|
||||
set = function(_, value)
|
||||
local enabled = value == true
|
||||
GetSettings().enabled = enabled
|
||||
GetLuraSettings().enabled = enabled
|
||||
RefreshEncounterAlerts()
|
||||
end,
|
||||
},
|
||||
runeWindow = BuildRuneWindowOptions(),
|
||||
actionBar = BuildRuneActionBarOptions(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
end)
|
||||
Reference in New Issue
Block a user