-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
135 lines (112 loc) · 5.07 KB
/
Copy pathOptions.lua
File metadata and controls
135 lines (112 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
-- VendorPricePlus options
--
-- This file owns saved preferences and the Blizzard AddOns settings panel.
-- Keeping configuration UI separate from tooltip behavior makes the core addon
-- easier to review and lets future contributors extend settings independently.
VendorPricePlus = VendorPricePlus or {}
local VP = VendorPricePlus
local Compat = VP.Compat
-- Every supported Forever tooltip surface is enabled on first install. These
-- switches are primarily here so players can opt out of a specific enhancement.
local CONTEXT_DEFAULTS = {
inventoryBank = true,
mail = true,
merchant = true,
professions = true,
questRewards = true,
}
function VP:EnsureSettingsDefaults()
VendorPricePlusDB = VendorPricePlusDB or {}
VendorPricePlusDB.contexts = VendorPricePlusDB.contexts or {}
for key, defaultValue in pairs(CONTEXT_DEFAULTS) do
if VendorPricePlusDB.contexts[key] == nil then
VendorPricePlusDB.contexts[key] = defaultValue
end
end
end
function VP:IsContextEnabled(key)
self:EnsureSettingsDefaults()
return VendorPricePlusDB.contexts[key] ~= false
end
function VP:SetContextEnabled(key, enabled)
self:EnsureSettingsDefaults()
VendorPricePlusDB.contexts[key] = enabled and true or false
end
-- The current context controls are Forever-specific because the older clients
-- use VendorPricePlus's established tooltip behavior. Shared display settings
-- can be added here later without mixing them into client compatibility code.
if not Compat.IsForever() then
return
end
VP:EnsureSettingsDefaults()
local panel = CreateFrame("Frame", "VendorPricePlusOptionsPanel")
panel.name = "VendorPricePlus"
local function CreateOptionsPanel(self)
if self.initialized then
return
end
self.initialized = true
local title = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText("VendorPricePlus")
local subtitle = self:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
subtitle:SetText("Choose where VendorPricePlus adds clearer vendor pricing.")
local heading = self:CreateFontString(nil, "ARTWORK", "GameFontNormal")
heading:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", 0, -22)
heading:SetText("Show Unit Price In")
local choices = {
{ key = "inventoryBank", label = "Inventory & Bank" },
{ key = "mail", label = "Mail" },
{ key = "merchant", label = "Merchant & Buyback" },
{ key = "professions", label = "Professions" },
{ key = "questRewards", label = "Quest Rewards" },
}
-- Anchor every checkbox to the panel, rather than to the previous checkbox.
-- This keeps the controls in a perfectly straight column and makes spacing
-- predictable if labels or rows are changed later.
local firstY = -118
local rowSpacing = 52
local lastCheck
for index, choice in ipairs(choices) do
local check = CreateFrame("CheckButton", nil, self, "UICheckButtonTemplate")
check:SetPoint("TOPLEFT", 12, firstY - ((index - 1) * rowSpacing))
check:SetChecked(VP:IsContextEnabled(choice.key))
local label = check:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
label:SetPoint("LEFT", check, "RIGHT", 2, 0)
label:SetText(choice.label)
check:SetScript("OnClick", function(button)
VP:SetContextEnabled(choice.key, button:GetChecked())
end)
lastCheck = check
end
local note = self:CreateFontString(nil, "ARTWORK", "GameFontDisableSmall")
note:SetPoint("TOPLEFT", lastCheck, "BOTTOMLEFT", 4, -18)
note:SetWidth(500)
note:SetJustifyH("LEFT")
note:SetText("All supported tooltip contexts are enabled by default. The Auction House already shows Blizzard's correct per-unit Sell Price, so VendorPricePlus leaves it unchanged.")
end
panel:SetScript("OnShow", CreateOptionsPanel)
-- Prefer the modern Settings API, while retaining the legacy registration path
-- for clients that still expose InterfaceOptions_AddCategory.
if Settings and Settings.RegisterCanvasLayoutCategory and Settings.RegisterAddOnCategory then
local category = Settings.RegisterCanvasLayoutCategory(panel, "VendorPricePlus")
Settings.RegisterAddOnCategory(category)
VP.OptionsCategory = category
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(panel)
end
-- /vpp is a convenience shortcut to the same panel available under AddOns.
SLASH_VENDORPRICEPLUS1 = "/vpp"
SlashCmdList.VENDORPRICEPLUS = function()
if Settings and Settings.OpenToCategory and VP.OptionsCategory then
Settings.OpenToCategory(VP.OptionsCategory:GetID())
elseif InterfaceOptionsFrame_OpenToCategory then
-- Older Blizzard clients sometimes require two calls to fully select an
-- addon category after opening the Interface Options window.
InterfaceOptionsFrame_OpenToCategory(panel)
InterfaceOptionsFrame_OpenToCategory(panel)
else
print("VendorPricePlus options are available from the AddOns settings.")
end
end