My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes  
Changes to /trunk/rActionButtonStyler/func/functions.lua
r788 vs. r789 Compare: vs.  Format:
Revision r789
Go to: 
/trunk/rActionButtonStyler/func/functions.lua   r788 /trunk/rActionButtonStyler/func/functions.lua   r789
1  1 
2 --get the addon namespace 2 --get the addon namespace
3 local addon, ns = ... 3 local addon, ns = ...
4 4
5 --get the config values 5 --get the config values
6 local cfg = ns.cfg 6 local cfg = ns.cfg
7 7
8 local _G = _G 8 local _G = _G
9 9
10 local nomoreplay = function() end
11
12 local classcolor = RAID_CLASS_COLORS[select(2, UnitClass("player"))] 10 local classcolor = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
13 11
14 if cfg.color.classcolored then 12 if cfg.color.classcolored then
15 cfg.color.normal = classcolor 13 cfg.color.normal = classcolor
16 end 14 end
17 15
18 --backdrop settings 16 --backdrop settings
19 local bgfile, edgefile = "", "" 17 local bgfile, edgefile = "", ""
20 if cfg.background.showshadow then edgefile = cfg.textures.outer_shadow end 18 if cfg.background.showshadow then edgefile = cfg.textures.outer_shadow end
21 if cfg.background.useflatbackground and cfg.background.showbg then bgfile = cfg.textures.buttonbackflat end 19 if cfg.background.useflatbackground and cfg.background.showbg then bgfile = cfg.textures.buttonbackflat end
22 20
23 --backdrop 21 --backdrop
24 local backdrop = { 22 local backdrop = {
25 bgFile = bgfile, 23 bgFile = bgfile,
26 edgeFile = edgefile, 24 edgeFile = edgefile,
27 tile = false, 25 tile = false,
28 tileSize = 32, 26 tileSize = 32,
29 edgeSize = cfg.background.inset, 27 edgeSize = cfg.background.inset,
30 insets = { 28 insets = {
31 left = cfg.background.inset, 29 left = cfg.background.inset,
32 right = cfg.background.inset, 30 right = cfg.background.inset,
33 top = cfg.background.inset, 31 top = cfg.background.inset,
34 bottom = cfg.background.inset, 32 bottom = cfg.background.inset,
35 }, 33 },
36 } 34 }
37 35
38 local function applyBackground(bu) 36 local function applyBackground(bu)
39 --shadows+background 37 --shadows+background
40 if bu:GetFrameLevel() < 1 then bu:SetFrameLevel(1) end 38 if bu:GetFrameLevel() < 1 then bu:SetFrameLevel(1) end
41 --if bu:GetFrameLevel() > 0 and (cfg.background.showbg or cfg.background.showshadow) then 39 --if bu:GetFrameLevel() > 0 and (cfg.background.showbg or cfg.background.showshadow) then
42 if cfg.background.showbg or cfg.background.showshadow then 40 if cfg.background.showbg or cfg.background.showshadow then
43 bu.bg = CreateFrame("Frame", nil, bu) 41 bu.bg = CreateFrame("Frame", nil, bu)
44 bu.bg:SetAllPoints(bu) 42 bu.bg:SetAllPoints(bu)
45 bu.bg:SetPoint("TOPLEFT", bu, "TOPLEFT", -4, 4) 43 bu.bg:SetPoint("TOPLEFT", bu, "TOPLEFT", -4, 4)
46 bu.bg:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", 4, -4) 44 bu.bg:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", 4, -4)
47 bu.bg:SetFrameLevel(bu:GetFrameLevel()-1) 45 bu.bg:SetFrameLevel(bu:GetFrameLevel()-1)
48 46
49 if cfg.background.classcolored then 47 if cfg.background.classcolored then
50 cfg.background.backgroundcolor = classcolor 48 cfg.background.backgroundcolor = classcolor
51 cfg.background.shadowcolor = classcolor 49 cfg.background.shadowcolor = classcolor
52 end 50 end
53 51
54 if cfg.background.showbg and not cfg.background.useflatbackground then 52 if cfg.background.showbg and not cfg.background.useflatbackground then
55 local t = bu.bg:CreateTexture(nil,"BACKGROUND",-8) 53 local t = bu.bg:CreateTexture(nil,"BACKGROUND",-8)
56 t:SetTexture(cfg.textures.buttonback) 54 t:SetTexture(cfg.textures.buttonback)
57 t:SetAllPoints(bu) 55 t:SetAllPoints(bu)
58 t:SetVertexColor(cfg.background.backgroundcolor.r,cfg.background.backgroundcolor.g,cfg.background.backgroundcolor.b,cfg.background.backgroundcolor.a) 56 t:SetVertexColor(cfg.background.backgroundcolor.r,cfg.background.backgroundcolor.g,cfg.background.backgroundcolor.b,cfg.background.backgroundcolor.a)
59 end 57 end
60 58
61 bu.bg:SetBackdrop(backdrop) 59 bu.bg:SetBackdrop(backdrop)
62 if cfg.background.useflatbackground then 60 if cfg.background.useflatbackground then
63 bu.bg:SetBackdropColor(cfg.background.backgroundcolor.r,cfg.background.backgroundcolor.g,cfg.background.backgroundcolor.b,cfg.background.backgroundcolor.a) 61 bu.bg:SetBackdropColor(cfg.background.backgroundcolor.r,cfg.background.backgroundcolor.g,cfg.background.backgroundcolor.b,cfg.background.backgroundcolor.a)
64 end 62 end
65 if cfg.background.showshadow then 63 if cfg.background.showshadow then
66 bu.bg:SetBackdropBorderColor(cfg.background.shadowcolor.r,cfg.background.shadowcolor.g,cfg.background.shadowcolor.b,cfg.background.shadowcolor.a) 64 bu.bg:SetBackdropBorderColor(cfg.background.shadowcolor.r,cfg.background.shadowcolor.g,cfg.background.shadowcolor.b,cfg.background.shadowcolor.a)
67 end 65 end
68 end 66 end
69 end 67 end
70 68
71 local function ntSetVertexColorFunc(nt, r, g, b, a) 69 local function ntSetVertexColorFunc(nt, r, g, b, a)
72 --do stuff 70 --do stuff
73 if nt then 71 if nt then
74 local self = nt:GetParent() 72 local self = nt:GetParent()
75 --print(self:GetName()..": r"..r.."g"..g.."b"..b)--debug 73 --print(self:GetName()..": r"..r.."g"..g.."b"..b)--debug
76 local action = self.action 74 local action = self.action
77 if r==1 and g==1 and b==1 and action and (IsEquippedAction(action)) then 75 if r==1 and g==1 and b==1 and action and (IsEquippedAction(action)) then
78 nt:SetVertexColor(cfg.color.equipped.r,cfg.color.equipped.g,cfg.color.equipped.b,1) 76 nt:SetVertexColor(cfg.color.equipped.r,cfg.color.equipped.g,cfg.color.equipped.b,1)
79 elseif r==0.5 and g==0.5 and b==1 then 77 elseif r==0.5 and g==0.5 and b==1 then
80 --blizzard oom color 78 --blizzard oom color
81 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1) 79 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1)
82 elseif r==1 and g==1 and b==1 then 80 elseif r==1 and g==1 and b==1 then
83 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1) 81 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1)
84 end 82 end
85 end 83 end
86 end 84 end
87 85
88 --initial style func 86 --initial style func
89 local function rActionButtonStyler_AB_style(self) 87 local function styleActionButton(self)
90 if self.rABS_Styled then 88 if self.rABS_Styled then return end
91 --print(self:GetName().." is styled already, pass by")
92 return
93 end
94
95 --print("styling: "..self:GetName())
96
97 local action = self.action 89 local action = self.action
98 local name = self:GetName() 90 local name = self:GetName()
99 local bu = _G[name] 91 local bu = _G[name]
100 local ic = _G[name.."Icon"] 92 local ic = _G[name.."Icon"]
101 local co = _G[name.."Count"] 93 local co = _G[name.."Count"]
102 local bo = _G[name.."Border"] 94 local bo = _G[name.."Border"]
103 local ho = _G[name.."HotKey"] 95 local ho = _G[name.."HotKey"]
104 local cd = _G[name.."Cooldown"] 96 local cd = _G[name.."Cooldown"]
105 local na = _G[name.."Name"] 97 local na = _G[name.."Name"]
106 local fl = _G[name.."Flash"] 98 local fl = _G[name.."Flash"]
107 local nt = _G[name.."NormalTexture"] 99 local nt = _G[name.."NormalTexture"]
108 local fbg = _G[name.."FloatingBG"] 100 local fbg = _G[name.."FloatingBG"]
109
110 if not nt then 101 if not nt then
111 --error no button to style found, get out asap
112 self.rABS_Styled = true 102 self.rABS_Styled = true
113 --print(name)
114 return 103 return
115 end 104 end
116
117 if fbg then 105 if fbg then
118 fbg:Hide() 106 fbg:Hide() --floating background
119 fbg.Show = nomoreplay
120 end 107 end
121
122 --hide the border (plain ugly, sry blizz) 108 --hide the border (plain ugly, sry blizz)
123 bo:Hide() 109 bo:SetTexture(nil)
124 bo.Show = nomoreplay 110 --hotkey
125 111 ho:SetFont(cfg.font, cfg.hotkeys.fontsize, "OUTLINE")
126 if cfg.hotkeys.show then 112 ho:ClearAllPoints()
127 ho:SetFont(cfg.font, cfg.hotkeys.fontsize, "OUTLINE") 113 ho:SetPoint(cfg.hotkeys.pos1.a1,bu,cfg.hotkeys.pos1.x,cfg.hotkeys.pos1.y)
128 ho:ClearAllPoints() 114 ho:SetPoint(cfg.hotkeys.pos2.a1,bu,cfg.hotkeys.pos2.x,cfg.hotkeys.pos2.y)
129 ho:SetPoint(cfg.hotkeys.pos1.a1,bu,cfg.hotkeys.pos1.x,cfg.hotkeys.pos1.y) 115 if not cfg.hotkeys.show then
130 ho:SetPoint(cfg.hotkeys.pos2.a1,bu,cfg.hotkeys.pos2.x,cfg.hotkeys.pos2.y)
131 else
132 ho:Hide() 116 ho:Hide()
133 ho.Show = nomoreplay
134 end 117 end
135
136 if cfg.macroname.show then 118 if cfg.macroname.show then
137 na:SetFont(cfg.font, cfg.macroname.fontsize, "OUTLINE") 119 na:SetFont(cfg.font, cfg.macroname.fontsize, "OUTLINE")
138 na:ClearAllPoints() 120 na:ClearAllPoints()
139 na:SetPoint(cfg.macroname.pos1.a1,bu,cfg.macroname.pos1.x,cfg.macroname.pos1.y) 121 na:SetPoint(cfg.macroname.pos1.a1,bu,cfg.macroname.pos1.x,cfg.macroname.pos1.y)
140 na:SetPoint(cfg.macroname.pos2.a1,bu,cfg.macroname.pos2.x,cfg.macroname.pos2.y) 122 na:SetPoint(cfg.macroname.pos2.a1,bu,cfg.macroname.pos2.x,cfg.macroname.pos2.y)
141 else 123 else
142 na:Hide() 124 na:Hide()
143 end 125 end
144
145 if cfg.itemcount.show then 126 if cfg.itemcount.show then
146 co:SetFont(cfg.font, cfg.itemcount.fontsize, "OUTLINE") 127 co:SetFont(cfg.font, cfg.itemcount.fontsize, "OUTLINE")
147 co:ClearAllPoints() 128 co:ClearAllPoints()
148 co:SetPoint(cfg.itemcount.pos1.a1,bu,cfg.itemcount.pos1.x,cfg.itemcount.pos1.y) 129 co:SetPoint(cfg.itemcount.pos1.a1,bu,cfg.itemcount.pos1.x,cfg.itemcount.pos1.y)
149 else 130 else
150 co:Hide() 131 co:Hide()
151 end 132 end
152
153 --applying the textures 133 --applying the textures
154 fl:SetTexture(cfg.textures.flash) 134 fl:SetTexture(cfg.textures.flash)
155 bu:SetHighlightTexture(cfg.textures.hover) 135 bu:SetHighlightTexture(cfg.textures.hover)
156 bu:SetPushedTexture(cfg.textures.pushed) 136 bu:SetPushedTexture(cfg.textures.pushed)
157 bu:SetCheckedTexture(cfg.textures.checked) 137 bu:SetCheckedTexture(cfg.textures.checked)
158 bu:SetNormalTexture(cfg.textures.normal) 138 bu:SetNormalTexture(cfg.textures.normal)
159
160 --cut the default border of the icons and make them shiny 139 --cut the default border of the icons and make them shiny
161 ic:SetTexCoord(0.1,0.9,0.1,0.9) 140 ic:SetTexCoord(0.1,0.9,0.1,0.9)
162 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2) 141 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2)
163 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2) 142 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2)
164
165 --adjust the cooldown frame 143 --adjust the cooldown frame
166 cd:SetPoint("TOPLEFT", bu, "TOPLEFT", cfg.cooldown.spacing, -cfg.cooldown.spacing) 144 cd:SetPoint("TOPLEFT", bu, "TOPLEFT", cfg.cooldown.spacing, -cfg.cooldown.spacing)
167 cd:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -cfg.cooldown.spacing, cfg.cooldown.spacing) 145 cd:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -cfg.cooldown.spacing, cfg.cooldown.spacing)
168
169 --apply the normaltexture 146 --apply the normaltexture
170 if ( IsEquippedAction(action) ) then 147 if ( IsEquippedAction(action) ) then
171 bu:SetNormalTexture(cfg.textures.equipped) 148 bu:SetNormalTexture(cfg.textures.equipped)
172 nt:SetVertexColor(cfg.color.equipped.r,cfg.color.equipped.g,cfg.color.equipped.b,1) 149 nt:SetVertexColor(cfg.color.equipped.r,cfg.color.equipped.g,cfg.color.equipped.b,1)
173 else 150 else
174 bu:SetNormalTexture(cfg.textures.normal) 151 bu:SetNormalTexture(cfg.textures.normal)
175 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1) 152 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1)
176 end 153 end
177
178 --make the normaltexture match the buttonsize 154 --make the normaltexture match the buttonsize
179 nt:SetAllPoints(bu) 155 nt:SetAllPoints(bu)
180
181 --disable resetting of textures
182 fl.SetTexture = nomoreplay
183 bu.SetHighlightTexture = nomoreplay
184 bu.SetPushedTexture = nomoreplay
185 bu.SetCheckedTexture = nomoreplay
186 bu.SetNormalTexture = nomoreplay
187
188 --hook to prevent Blizzard from reseting our colors 156 --hook to prevent Blizzard from reseting our colors
189 hooksecurefunc(nt, "SetVertexColor", ntSetVertexColorFunc) 157 hooksecurefunc(nt, "SetVertexColor", ntSetVertexColorFunc)
190
191 --shadows+background 158 --shadows+background
192 if not bu.bg then applyBackground(bu) end 159 if not bu.bg then applyBackground(bu) end
160 self.rABS_Styled = true
161 end
162
193 163
194 self.rABS_Styled = true 164 local function updateHotkey(self, actionButtonType)
165 local ho = _G[self:GetName() .. "HotKey"]
166 if not cfg.hotkeys.show then
167 ho:Hide()
168 end
169 end
195 170
171 local function ntFixPet(bu,texture)
172 --make sure the normaltexture stays the way we want it
173 if texture ~= cfg.textures.normal then
174 bu:SetNormalTexture(cfg.textures.normal)
175 end
196 end 176 end
197 177
198 --style pet buttons 178 --style pet buttons
199 local function rActionButtonStyler_AB_stylepet() 179 local function stylePetButton()
200
201 for i=1, NUM_PET_ACTION_SLOTS do 180 for i=1, NUM_PET_ACTION_SLOTS do
202 local name = "PetActionButton"..i 181 local name = "PetActionButton"..i
203 local bu = _G[name] 182 local bu = _G[name]
183 if bu.rABS_Styled then return end
204 local ic = _G[name.."Icon"] 184 local ic = _G[name.."Icon"]
205 local fl = _G[name.."Flash"] 185 local fl = _G[name.."Flash"]
206 local nt = _G[name.."NormalTexture2"] 186 local nt = _G[name.."NormalTexture2"]
207
208 nt:SetAllPoints(bu) 187 nt:SetAllPoints(bu)
209
210 --applying color 188 --applying color
211 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1) 189 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1)
212
213 --setting the textures 190 --setting the textures
214 fl:SetTexture(cfg.textures.flash) 191 fl:SetTexture(cfg.textures.flash)
215 bu:SetHighlightTexture(cfg.textures.hover) 192 bu:SetHighlightTexture(cfg.textures.hover)
216 bu:SetPushedTexture(cfg.textures.pushed) 193 bu:SetPushedTexture(cfg.textures.pushed)
217 bu:SetCheckedTexture(cfg.textures.checked) 194 bu:SetCheckedTexture(cfg.textures.checked)
218 bu:SetNormalTexture(cfg.textures.normal) 195 bu:SetNormalTexture(cfg.textures.normal)
219 196 hooksecurefunc(bu, "SetNormalTexture", ntFixPet)
220 --cut the default border of the icons and make them shiny 197 --cut the default border of the icons and make them shiny
221 ic:SetTexCoord(0.1,0.9,0.1,0.9) 198 ic:SetTexCoord(0.1,0.9,0.1,0.9)
222 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2) 199 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2)
223 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2) 200 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2)
224
225 --shadows+background 201 --shadows+background
226 if not bu.bg then applyBackground(bu) end 202 if not bu.bg then applyBackground(bu) end
227 203 bu.rABS_Styled = true
228 end 204 end
229 end 205 end
230 206
231 --style shapeshift buttons 207 --style shapeshift buttons
232 local function rActionButtonStyler_AB_styleshapeshift() 208 local function styleShapeShiftButton()
233 for i=1, NUM_SHAPESHIFT_SLOTS do 209 for i=1, NUM_SHAPESHIFT_SLOTS do
234 local name = "ShapeshiftButton"..i 210 local name = "ShapeshiftButton"..i
235 local bu = _G[name] 211 local bu = _G[name]
212 if bu.rABS_Styled then return end
236 local ic = _G[name.."Icon"] 213 local ic = _G[name.."Icon"]
237 local fl = _G[name.."Flash"] 214 local fl = _G[name.."Flash"]
238 local nt = _G[name.."NormalTexture2"] 215 local nt = _G[name.."NormalTexture2"]
239
240 nt:SetAllPoints(bu) 216 nt:SetAllPoints(bu)
241
242 --applying color 217 --applying color
243 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1) 218 nt:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b,1)
244
245 --setting the textures 219 --setting the textures
246 fl:SetTexture(cfg.textures.flash) 220 fl:SetTexture(cfg.textures.flash)
247 bu:SetHighlightTexture(cfg.textures.hover) 221 bu:SetHighlightTexture(cfg.textures.hover)
248 bu:SetPushedTexture(cfg.textures.pushed) 222 bu:SetPushedTexture(cfg.textures.pushed)
249 bu:SetCheckedTexture(cfg.textures.checked) 223 bu:SetCheckedTexture(cfg.textures.checked)
250 bu:SetNormalTexture(cfg.textures.normal) 224 bu:SetNormalTexture(cfg.textures.normal)
251
252 --cut the default border of the icons and make them shiny 225 --cut the default border of the icons and make them shiny
253 ic:SetTexCoord(0.1,0.9,0.1,0.9) 226 ic:SetTexCoord(0.1,0.9,0.1,0.9)
254 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2) 227 ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2)
255 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2) 228 ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2)
256
257 --shadows+background 229 --shadows+background
258 if not bu.bg then applyBackground(bu) end 230 if not bu.bg then applyBackground(bu) end
259 231 bu.rABS_Styled = true
260 end 232 end
261 end 233 end
262 234
263 --------------------------------------- 235 ---------------------------------------
264 -- CALLS // HOOKS 236 -- CALLS // HOOKS
265 --------------------------------------- 237 ---------------------------------------
266 238
267 hooksecurefunc("ActionButton_Update", rActionButtonStyler_AB_style) 239 hooksecurefunc("ActionButton_Update", styleActionButton)
268 hooksecurefunc("ShapeshiftBar_Update", rActionButtonStyler_AB_styleshapeshift) 240 hooksecurefunc("ActionButton_UpdateHotkeys", updateHotkey)
269 hooksecurefunc("ShapeshiftBar_UpdateState", rActionButtonStyler_AB_styleshapeshift) 241 hooksecurefunc("ShapeshiftBar_Update", styleShapeShiftButton)
270 hooksecurefunc("PetActionBar_Update", rActionButtonStyler_AB_stylepet) 242 hooksecurefunc("ShapeshiftBar_UpdateState", styleShapeShiftButton)
243 hooksecurefunc("PetActionBar_Update", stylePetButton)
Powered by Google Project Hosting