-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFrames.lua
334 lines (269 loc) · 12.7 KB
/
Frames.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
local L = LibStub("AceLocale-3.0"):GetLocale("ArcHUD_Core")
---------------------------------------------------------------------------------------------------
-- Local functions to assist with widget creation
local function AH_CreateFrame(type, name, parent, size, point, strata)
local f = CreateFrame(type, name, parent)
local width, height = unpack(size)
f:SetWidth(width)
f:SetHeight(height)
f:SetPoint(unpack(point))
if(strata) then
f:SetFrameStrata(strata)
end
f:Show()
return f
end
local function AH_CreateFontString(parent, layer, size, fontsize, justify, color, point, name)
local fs = parent:CreateFontString(name, layer)
if(size) then
local width, height = unpack(size)
fs:SetWidth(width)
fs:SetHeight(height)
end
fs:SetFont("Fonts\\"..L["FONT"], fontsize, "OUTLINE")
if(color) then
fs:SetTextColor(unpack(color))
end
fs:SetJustifyH(justify)
fs:SetPoint(unpack(point))
fs:Show()
return fs
end
local function AH_CreateTexture(parent, layer, size, texture, point)
local t = parent:CreateTexture(nil, layer)
if(size) then
local width, height = unpack(size)
t:SetWidth(width)
t:SetHeight(height)
end
if(texture) then
t:SetTexture(texture)
end
if(point) then
t:SetPoint(unpack(point))
end
t:Show()
return t
end
-- Frame creation for specific purposes
local function AH_CreateBuffButton(parent, id, point)
local f = CreateFrame("Button", nil, parent)
f:SetPoint(unpack(point))
f:SetID(id)
local buffIconSize = ArcHUD.db.profile.BuffIconSize
f:SetWidth(buffIconSize)
f:SetHeight(buffIconSize)
f.Icon = AH_CreateTexture(f, "ARTWORK", nil, "Interface\\Icons\\INV_Misc_Ear_Human_02")
f.Icon:SetAllPoints(true)
f.Icon:Show()
f.Border = AH_CreateTexture(f, "OVERLAY", {buffIconSize+1, buffIconSize+1}, "Interface\\Buttons\\UI-Debuff-Overlays", {"CENTER", f, "CENTER"})
f.Border:SetTexCoord(0.296875, 0.5703125, 0, 0.515625)
f.Border:Hide()
f.Count = f:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmall")
f.Count:SetPoint("CENTER", f)
f.Count:Show()
f.Cooldown = CreateFrame("Cooldown", nil, f, "CooldownFrameTemplate")
f.Cooldown:SetPoint("CENTER", 0, -1)
f:SetScript("OnEnter", function(this) ArcHUD:SetAuraTooltip(this) end)
f:SetScript("OnLeave", function() GameTooltip:Hide() end)
f:Hide()
return f
end
local function AH_CreateNameplate(parent, unit, size, point)
local name
if parent and parent:GetName() then
name = parent:GetName() .. "_"
else
name = "ArcHUD_"
end
name = name .. unit
-- be sure we don't create a frame with an existing name (should not happen)
assert(not _G[name])
ArcHUD:LevelDebug(1, "Creating unit frame "..name)
local f = CreateFrame("Button", name, parent, "SecureUnitButtonTemplate")
local width, height = unpack(size)
f:SetWidth(width)
f:SetHeight(height)
f:SetPoint(unpack(point))
ArcHUD:InitNameplate(f, unit)
return f
end
local function AH_CreateMoverFrame(parent, name, size, point, origpoint)
local f = CreateFrame("Button", nil, parent, BackdropTemplateMixin and "BackdropTemplate")
local width, height = unpack(size)
f:SetWidth(width)
f:SetHeight(height)
f:SetPoint(unpack(point))
f:SetToplevel(true)
f:GetParent():SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function(self)
if(not self:GetParent().locked) then
self:GetParent():ClearAllPoints()
self:GetParent():StartMoving()
end
end)
f:SetScript("OnDragStop", function(self)
self:GetParent():StopMovingOrSizing()
self:GetParent().moved = true
--ArcHUD:LevelDebug(1, "Sending ARCHUD_FRAME_MOVED")
ArcHUD:SendMessage("ARCHUD_FRAME_MOVED")
end)
parent.ResetPos = function(self, newpoint)
self:ClearAllPoints()
if(newpoint) then
self:SetPoint(unpack(newpoint))
else
self:SetPoint(unpack(self.origpoint))
end
self:Lock()
self.reset = true
ArcHUD:SendMessage("ARCHUD_FRAME_MOVED")
end
parent.Lock = function(self)
if(self.locked) then return end
self.locked = true
self.mover:Hide()
if(self.prevAlpha) then
self:SetAlpha(self.prevAlpha)
self.prevAlpha = nil
end
end
parent.Unlock = function(self)
if(not self.locked) then return end
self.locked = false
self.moved = false
self.mover:Show()
if(self:GetAlpha() < 0.5) then
self.prevAlpha = self:GetAlpha()
self:SetAlpha(1)
else
self.prevAlpha = nil
end
end
f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
tile = true, tileSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }})
f:SetBackdropColor(0,0,0,0.5)
f:Hide()
parent.locked = true
parent.moved = false
parent.origpoint = origpoint
parent.mover = f
-- Add to moveableFrames table
ArcHUD.movableFrames[name] = parent
end
---------------------------------------------------------------------------------------------------
-- Main frame creation function
function ArcHUD:CreateHUDFrames()
-- Main frame (defined in Frames.xml)
local main = ArcHUDFrame
local targethud = ArcHUDFrame.TargetHUD
AH_CreateMoverFrame(targethud, "targethud", {320, 120}, {"TOPLEFT", -10, 10}, {"TOP", main, "BOTTOM", 0, -60})
-- Set up font strings
targethud.Combo = AH_CreateFontString(main, "BACKGROUND", {40, 30}, 30, "CENTER", {1, 1, 0}, {"BOTTOM", main, "BOTTOM"}, "ArcHUDFrameCombo")
targethud.Name = AH_CreateFontString(targethud, "OVERLAY", {400, 16}, 15, "CENTER", {1, 1, 1}, {"TOP", targethud, "TOP"})
targethud.HPText = AH_CreateFontString(targethud, "OVERLAY", {200, 14}, 13, "RIGHT", {1, 1, 1}, {"TOPLEFT", targethud.Name, "BOTTOMLEFT", -50, 0})
targethud.MPText = AH_CreateFontString(targethud, "OVERLAY", {200, 14}, 13, "LEFT", {1, 1, 1}, {"TOPRIGHT", targethud.Name, "BOTTOMRIGHT", 50 , 0})
targethud.Level = AH_CreateFontString(targethud, "OVERLAY", {100, 13}, 11, "CENTER", {1, 1, 1}, {"BOTTOMLEFT", targethud.HPText, "BOTTOMRIGHT", 0, 1})
targethud.LeaderIcon = AH_CreateTexture(targethud, "OVERLAY", {16, 16}, "Interface\\GroupFrame\\UI-Group-LeaderIcon", {"TOPRIGHT", targethud.Level, "BOTTOMRIGHT", -5, 0})
targethud.LeaderIcon:Hide()
targethud.PVPFrame = AH_CreateFrame("Frame", nil, targethud, {64, 64}, {"TOPLEFT", targethud.Level, "BOTTOMLEFT", 3, 0})
targethud.PVPFrame:SetScale(0.6)
targethud.PVPIcon = AH_CreateTexture(targethud.PVPFrame, "OVERLAY", {64, 64}, nil, {"TOPLEFT", targethud.PVPFrame, "TOPLEFT"})
targethud.PVPIcon:Hide()
targethud.RaidTargetFrame = AH_CreateFrame("Frame", nil, targethud, {26, 26}, {"TOPLEFT", targethud.Level, "BOTTOMLEFT", 35, -3})
targethud.RaidTargetFrame:SetScale(0.75)
targethud.RaidTargetIcon = AH_CreateTexture(targethud.RaidTargetFrame, "OVERLAY", {26, 26}, "Interface\\TargetingFrame\\UI-RaidTargetingIcons", {"TOPLEFT", targethud.RaidTargetFrame, "TOPLEFT"})
targethud.RaidTargetIcon:Hide()
targethud.MLFrame = nil
targethud.MLIcon = nil
targethud.Target = AH_CreateFrame("Frame", targethud:GetName().."TT", targethud, {100, 30}, {"TOPLEFT", targethud, "TOPLEFT", 0, -70})
AH_CreateMoverFrame(targethud.Target, "targettarget", {120, 50}, {"TOPLEFT", -10, 10}, {"TOPLEFT", targethud, "TOPLEFT", 0, -70})
targethud.Target.Name = AH_CreateFontString(targethud.Target, "ARTWORK", {100, 14}, 13, "RIGHT", {1, 1, 1}, {"TOPLEFT", targethud.Target, "TOPLEFT"})
targethud.Target.HPText = AH_CreateFontString(targethud.Target, "ARTWORK", {50, 11}, 10, "RIGHT", {1, 1, 1}, {"TOPRIGHT", targethud.Target.Name, "BOTTOMRIGHT", 0, -5})
targethud.Target.MPText = AH_CreateFontString(targethud.Target, "ARTWORK", {50, 11}, 10, "LEFT", {1, 1, 1}, {"TOPLEFT", targethud.Target.Name, "BOTTOMLEFT", 0, -5})
targethud.TargetTarget = AH_CreateFrame("Frame", targethud:GetName().."TTT", targethud, {100, 30}, {"TOPRIGHT", targethud, "TOPRIGHT", 0, -70})
AH_CreateMoverFrame(targethud.TargetTarget, "targettargettarget", {120, 50}, {"TOPLEFT", -10, 10}, {"TOPRIGHT", targethud, "TOPRIGHT", 0, -70})
targethud.TargetTarget.Name = AH_CreateFontString(targethud.TargetTarget, "ARTWORK", {100, 14}, 13, "LEFT", {1, 1, 1}, {"TOPLEFT", targethud.TargetTarget, "TOPLEFT"})
targethud.TargetTarget.HPText = AH_CreateFontString(targethud.TargetTarget, "ARTWORK", {50, 11}, 10, "LEFT", {1, 1, 1}, {"TOPLEFT", targethud.TargetTarget.Name, "BOTTOMLEFT", 0, -5})
targethud.TargetTarget.MPText = AH_CreateFontString(targethud.TargetTarget, "ARTWORK", {50, 11}, 10, "RIGHT", {1, 1, 1}, {"TOPRIGHT", targethud.TargetTarget.Name, "BOTTOMRIGHT", 0, -5})
-- 3d model
targethud.Model = AH_CreateFrame("PlayerModel", nil, targethud, {100, 100}, {"TOP", targethud.Name, "BOTTOM"}, "BACKGROUND")
targethud.Model:RegisterEvent("DISPLAY_SIZE_CHANGED")
targethud.Model:RegisterEvent("UNIT_MODEL_CHANGED")
targethud.Model:SetScript("OnEvent", self.Refresh3dUnitModel)
-- Create nameplates
local np = AH_CreateNameplate(main, "player", {50, 14}, {"BOTTOM", main, "BOTTOM", 0, 60})
np.Text = AH_CreateFontString(np, "OVERLAY", {150, 15}, 14, "CENTER", {1, 1, 1}, {"TOP", np, "TOP"})
np.Resting = AH_CreateFontString(np, "BACKGROUND", {75, 12}, 11, "CENTER", {1, 1, 1}, {"BOTTOM", np.Text, "TOP"})
local np = AH_CreateNameplate(main, "pet", {50, 12}, {"BOTTOM", main, "BOTTOM", 0, 45})
np.Text = AH_CreateFontString(np, "OVERLAY", {150, 13}, 12, "CENTER", {1, 1, 1}, {"TOP", np, "TOP"})
AH_CreateNameplate(targethud, "target", {400, 15}, {"TOP", targethud, "TOP"})
AH_CreateNameplate(targethud.Target, "targettarget", {100, 14}, {"TOPLEFT", targethud.Target, "TOPLEFT"})
AH_CreateNameplate(targethud.TargetTarget, "targettargettarget", {100, 14}, {"TOPLEFT", targethud.TargetTarget, "TOPLEFT"})
-- Create buffframes
targethud.Buff1 = AH_CreateBuffButton(targethud, 1, {"TOPRIGHT", targethud.HPText, "BOTTOMRIGHT", 0, -2}, "Buff")
for i=2,10 do
targethud["Buff"..i] = AH_CreateBuffButton(targethud, i, {"RIGHT", targethud["Buff"..(i-1)], "LEFT", -1, 0}, "Buff")
end
targethud.Buff11 = AH_CreateBuffButton(targethud, 11, {"TOPRIGHT", targethud.Buff1, "BOTTOMRIGHT", 0, -1}, "Buff")
for i=12,20 do
targethud["Buff"..i] = AH_CreateBuffButton(targethud, i, {"RIGHT", targethud["Buff"..(i-1)], "LEFT", -1, 0}, "Buff")
end
targethud.Buff21 = AH_CreateBuffButton(targethud, 21, {"TOPRIGHT", targethud.Buff11, "BOTTOMRIGHT", 0, -1}, "Buff")
for i=22,30 do
targethud["Buff"..i] = AH_CreateBuffButton(targethud, i, {"RIGHT", targethud["Buff"..(i-1)], "LEFT", -1, 0}, "Buff")
end
targethud.Buff31 = AH_CreateBuffButton(targethud, 31, {"TOPRIGHT", targethud.Buff21, "BOTTOMRIGHT", 0, -1}, "Buff")
for i=32,40 do
targethud["Buff"..i] = AH_CreateBuffButton(targethud, i, {"RIGHT", targethud["Buff"..(i-1)], "LEFT", -1, 0}, "Buff")
end
-- Create debuffframes
targethud.Debuff1 = AH_CreateBuffButton(targethud, 1, {"TOPLEFT", targethud.MPText, "BOTTOMLEFT", 0, -2}, "DeBuff")
for i=2,10 do
targethud["Debuff"..i] = AH_CreateBuffButton(targethud, i, {"LEFT", targethud["Debuff"..(i-1)], "RIGHT", -1, 0}, "DeBuff")
end
targethud.Debuff11 = AH_CreateBuffButton(targethud, 11, {"TOPLEFT", targethud.Debuff1, "BOTTOMLEFT", 0, -1}, "DeBuff")
for i=12,20 do
targethud["Debuff"..i] = AH_CreateBuffButton(targethud, i, {"LEFT", targethud["Debuff"..(i-1)], "RIGHT", -1, 0}, "DeBuff")
end
targethud.Debuff21 = AH_CreateBuffButton(targethud, 21, {"TOPLEFT", targethud.Debuff11, "BOTTOMLEFT", 0, -1}, "DeBuff")
for i=22,30 do
targethud["Debuff"..i] = AH_CreateBuffButton(targethud, i, {"LEFT", targethud["Debuff"..(i-1)], "RIGHT", -1, 0}, "DeBuff")
end
targethud.Debuff31 = AH_CreateBuffButton(targethud, 31, {"TOPLEFT", targethud.Debuff21, "BOTTOMLEFT", 0, -1}, "DeBuff")
for i=32,40 do
targethud["Debuff"..i] = AH_CreateBuffButton(targethud, i, {"LEFT", targethud["Debuff"..(i-1)], "RIGHT", -1, 0}, "DeBuff")
end
return targethud
end
function ArcHUD:CheckFrames()
--ArcHUD:LevelDebug(1, "CheckFrames")
for id, frame in pairs(self.movableFrames) do
if(frame.moved) then
--ArcHUD:LevelDebug(1, "Update of "..id)
self.db.profile.Positions[id] = {
x = frame:GetLeft(),
y = frame:GetBottom(),
}
frame.moved = false
elseif(frame.reset) then
self.db.profile.Positions[id] = nil
frame.reset = nil
end
end
end
function ArcHUD:Refresh3dUnitModel(event, arg1)
--ArcHUD:LevelDebug(3, "ArcHUD:Refresh3dUnitModel("..tostring(event)..", "..tostring(arg1)..")")
if (ArcHUD.db.profile.TargetFrame) then
if ((event ~= "UNIT_MODEL_CHANGED" and UnitExists("target")) or
(event == "UNIT_MODEL_CHANGED" and arg1 == "target")) then
if ((ArcHUD.db.profile.PlayerModel and UnitIsPlayer("target")) or
(ArcHUD.db.profile.MobModel and not UnitIsPlayer("target"))) then
ArcHUD.TargetHUD.Model:RefreshUnit()
end
end
end
end