-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpfUI-CustomMedia-buttons.lua
187 lines (165 loc) · 7.34 KB
/
pfUI-CustomMedia-buttons.lua
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
pfUI:RegisterModule("CustomMedia", "vanilla:tbc", function()
if not C.CustomMedia then C.CustomMedia = {} end
C.CustomMedia.selectimg = C.CustomMedia.selectimg or "Default"
C.CustomMedia.color = C.CustomMedia.color or "1,1,1,0.5"
pfUI.gui.dropdowns.CustomMedia_selectimg = {
"Default:" .. T["Default"],
"Sword:" .. T["Sword"],
"Lion:" .. T["Lion"],
"Eagle:" .. T["Eagle"]
}
local function GetTexture(selection)
if selection == "Default" then return nil
elseif selection == "Sword" then return "Interface\\AddOns\\pfUI-CustomMedia\\media\\sword"
elseif selection == "Lion" then return "Interface\\AddOns\\pfUI-CustomMedia\\media\\lion"
elseif selection == "Eagle" then return "Interface\\AddOns\\pfUI-CustomMedia\\media\\eagle"
end
end
local function ApplyBackgroundToButtons(texture, color)
local buttonGroups = {
"pfActionBarMainButton",
"pfActionBarRightButton",
"pfActionBarVerticalButton",
"pfActionBarLeftButton",
"pfActionBarTopButton",
"pfActionBarStanceBar1Button",
"pfActionBarStanceBar2Button",
"pfActionBarStanceBar3Button",
"pfActionBarStanceBar4Button",
"pfActionBarPetButton",
"pfActionBarStancesButton",
"pfActionBarPagingButton",
}
for _, group in ipairs(buttonGroups) do
local buttonCount = (group == "pfActionBarPetButton" or group == "pfActionBarStancesButton") and 10 or 12
local r, g, b, a = GetStringColor(color)
for i = 1, buttonCount do
local button = _G[group .. i]
if button then
if button.bg then
button.bg:Hide()
button.bg = nil
end
if texture then
local bg = button:CreateTexture(nil, "BACKGROUND")
bg:SetDrawLayer("BACKGROUND", -8)
bg:SetAllPoints(button)
bg:SetTexture(texture)
bg:SetTexCoord(0, 1, 0, 1)
bg:SetVertexColor(r, g, b, a)
button.bg = bg
end
local icon = button.icon or button:GetNormalTexture()
if icon then icon:SetDrawLayer("ARTWORK", 1) end
end
end
end
end
local function ApplyBackgroundToBags(texture, color)
local r, g, b, a = GetStringColor(color)
for bagIndex = 0, 4 do
local bag = _G["pfBag" .. bagIndex]
if bag then
for slotIndex = 1, 36 do
local button = _G["pfBag" .. bagIndex .. "item" .. slotIndex]
if button then
if button.bg then
button.bg:Hide()
button.bg = nil
end
if texture then
local bg = button:CreateTexture(nil, "BACKGROUND")
bg:SetDrawLayer("BACKGROUND", -8)
bg:SetAllPoints(button)
bg:SetTexture(texture)
bg:SetTexCoord(0, 1, 0, 1)
bg:SetVertexColor(r, g, b, a)
button.bg = bg
end
local icon = button.icon or button:GetNormalTexture()
if icon then icon:SetDrawLayer("ARTWORK", 1) end
end
end
end
end
end
local function ApplyBackgroundToBank(texture, color)
local r, g, b, a = GetStringColor(color)
-- Main bank slots (bag -1, 24 slots in vanilla/TBC)
for slotIndex = 1, 24 do
local button = _G["pfBag-1item" .. slotIndex]
if button then
if button.bg then
button.bg:Hide()
button.bg = nil
end
if texture then
local bg = button:CreateTexture(nil, "BACKGROUND")
bg:SetDrawLayer("BACKGROUND", -8)
bg:SetAllPoints(button)
bg:SetTexture(texture)
bg:SetTexCoord(0, 1, 0, 1)
bg:SetVertexColor(r, g, b, a)
button.bg = bg
end
local icon = button.icon or button:GetNormalTexture()
if icon then icon:SetDrawLayer("ARTWORK", 1) end
end
end
-- Bank bags (bags 5-10)
for bagIndex = 5, 10 do
local bankBag = _G["pfBag" .. bagIndex]
if bankBag then
for slotIndex = 1, 36 do
local button = _G["pfBag" .. bagIndex .. "item" .. slotIndex]
if button then
if button.bg then
button.bg:Hide()
button.bg = nil
end
if texture then
local bg = button:CreateTexture(nil, "BACKGROUND")
bg:SetDrawLayer("BACKGROUND", -8)
bg:SetAllPoints(button)
bg:SetTexture(texture)
bg:SetTexCoord(0, 1, 0, 1)
bg:SetVertexColor(r, g, b, a)
button.bg = bg
end
local icon = button.icon or button:GetNormalTexture()
if icon then icon:SetDrawLayer("ARTWORK", 1) end
end
end
end
end
end
local function UpdateTextures()
local texture = GetTexture(C.CustomMedia.selectimg)
local color = C.CustomMedia.color
ApplyBackgroundToButtons(texture, color)
ApplyBackgroundToBags(texture, color)
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function()
UpdateTextures()
frame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
local bankFrame = CreateFrame("Frame")
bankFrame:RegisterEvent("BANKFRAME_OPENED")
bankFrame:SetScript("OnEvent", function()
local texture = GetTexture(C.CustomMedia.selectimg)
local color = C.CustomMedia.color
ApplyBackgroundToBank(texture, color)
end)
if pfUI.gui.CreateGUIEntry then
pfUI.gui.CreateGUIEntry(T["Thirdparty"], T["CustomMedia"], function()
pfUI.gui.CreateConfig(pfUI.gui.UpdaterFunctions["CustomMedia"], T["Bar buttons background"], nil, nil, "header")
pfUI.gui.CreateConfig(pfUI.gui.UpdaterFunctions["CustomMedia"], T["Select button texture"], C.CustomMedia, "selectimg", "dropdown", pfUI.gui.dropdowns.CustomMedia_selectimg)
pfUI.gui.CreateConfig(pfUI.gui.UpdaterFunctions["CustomMedia"], T["Pick Color"], C.CustomMedia, "color", "color")
end)
else
pfUI.gui.tabs.thirdparty.tabs.CustomMedia = pfUI.gui.tabs.thirdparty.tabs:CreateTabChild("CustomMedia", true)
pfUI.gui.tabs.thirdparty.tabs.CustomMedia:SetScript("OnShow", function() if not this.setup then this.setup = true end end)
end
end)