e5fe597 - Add priest TMW
[wowui.git] / OmaTMW / Nameplates.lua
1 -- Nameplates.lua
2 local _;
3 local next = next;
4 local GetNamePlateForUnit = C_NamePlate.GetNamePlateForUnit;
5 local UnitExists = UnitExists;
6 local UnitAura = UnitAura;
7
8 local main = CreateFrame("Frame", "OmaNameplateAuras");
9 main:Hide();
10
11 local frames = {};
12 local unique = 1;
13 local function createNameplate(parent)
14     local name = format("OmaPlate%i", unique);
15     local frame = CreateFrame("Frame", name, parent);
16     frames[parent] = frame;
17     unique = unique + 1;
18     frame:SetPoint("BOTTOM", parent, "TOP", 0, 14);
19     frame:SetWidth(32);
20     frame:SetHeight(32);
21     frame:Hide();
22     frame.base = frame:CreateTexture(nil, "BACKGROUND");
23     frame.base:SetAllPoints();
24     frame.base:SetColorTexture(0, 0, 0, 0.6);
25     frame.icon = frame:CreateTexture(nil, "ARTWORK");
26     frame.icon:SetPoint("TOPLEFT", frame.base, "TOPLEFT", 1, -1);
27     frame.icon:SetPoint("BOTTOMRIGHT", frame.base, "BOTTOMRIGHT", -1, 1);
28     frame.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93);
29     frame.cd = CreateFrame("Cooldown", format("%sCD", name), frame, "CooldownFrameTemplate");
30     frame.cd:SetReverse(true);
31     frame.cd:SetHideCountdownNumbers(true);
32     frame.cd:SetAllPoints();
33     return frame;
34 end
35
36 local function setNameplate(unit)
37     local frame = frames[GetNamePlateForUnit(unit)];
38     -- TODO register interesting events to track on nameplates
39 end
40
41 local function unsetNameplate(unit)
42     local frame = frames[GetNamePlateForUnit(unit)];
43     frame:UnregisterAllEvents();
44     frame:Hide();
45 end
46
47 local events = {
48     ["NAME_PLATE_CREATED"] = createNameplate,
49     ["NAME_PLATE_UNIT_ADDED"] = setNameplate,
50     ["NAME_PLATE_UNIT_REMOVED"] = unsetNameplate,
51 };
52 main:SetScript("OnEvent", function(self, event)
53     main:UnregisterAllEvents();
54     main:SetScript("OnEvent", function(self, event, arg1)
55         events[event](arg1);
56     end);
57     main:RegisterEvent("NAME_PLATE_CREATED");
58     main:RegisterEvent("NAME_PLATE_UNIT_ADDED");
59     main:RegisterEvent("NAME_PLATE_UNIT_REMOVED");
60 end);
61 main:RegisterEvent("PLAYER_LOGIN");