35c82f1 - Don't show healabsorb on player frame
[wowui.git] / kehys / boss.lua
1 -- boss.lua
2 local _, addon = ...;
3 local unpack = unpack;
4 local format = string.format;
5 local CFrame = CreateFrame("Frame", "kehysBossInit", UIParent);
6 local CTimerAfter = C_Timer.After;
7
8 local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
9 local class = nil;
10 local attributes = {};
11
12 local function showTooltip(frame)
13     GameTooltip_SetDefaultAnchor(GameTooltip, frame);
14     GameTooltip:SetUnit(frame:GetAttribute("unit"));
15 end
16
17 local function hideTooltip()
18     GameTooltip:FadeOut();
19 end
20
21 local id = 1;
22 local updaters = {};
23 local function initBoss(parent, y, width, height, update, event)
24     assert(type(parent) == "table", "Boss frame creation missing parent!");
25     assert(type(y) == "number", "Boss frame creation missing Y offset!");
26     assert(type(width) == "number", "Boss frame creation missing width!");
27     assert(type(height) == "number", "Boss frame creation missing height!");
28     assert(type(update) == "function",
29            "Boss frame creation missing update function!");
30     assert(type(event) == "function",
31            "Boss frame creation missing event function!");
32
33     local unit = "boss"..id;
34     local f = CreateFrame("Button", "kehysBoss"..id, parent,
35                           "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
36     id = id + 1;
37     f:Hide();
38     f:SetPoint("CENTER", parent, "CENTER", 540, y+200);
39     f:SetWidth(width);
40     f:SetHeight(height);
41     f.barwidth = width - 2; -- 1px padding
42     f:SetAttribute("unit", unit);
43     f:SetAttribute("displayed", unit);
44     f.unit = unit;
45     f.displayed = unit;
46     f.boss = true;
47     f.prev = {};
48
49     updaters[f] = function()
50         if f.updating then
51             CTimerAfter(0.1, updaters[f]);
52             return update(f);
53         end
54     end
55     f:SetScript("OnEvent", event);
56     f:SetScript("OnHide", function()
57         f:UnregisterAllEvents();
58         f.updating = false;
59         f.prev = {};
60     end);
61     f:SetScript("OnShow", function()
62         addon.RegisterEvents(f);
63         addon.RegisterUnitEvents(f);
64         event(f, "UPDATE_ALL_BARS");
65         f.updating = true;
66         updaters[f]();
67     end);
68     f:SetScript("OnEnter", showTooltip);
69     f:SetScript("OnLeave", hideTooltip);
70     -- set attributes
71     f:RegisterForClicks("AnyDown");
72     for attr, val in pairs(attributes) do
73         if attr ~= "type1" and attr ~= "spell1" then f:SetAttribute(attr, val) end
74     end
75     -- rest give target and menu
76     f:SetAttribute("*type1", "target");
77     f:SetAttribute("*type2", "togglemenu");
78     f:SetAttribute("toggleForVehicle", false);
79
80     -- create visuals
81     f.base = f:CreateTexture(nil, "BACKGROUND");
82     f.base:SetAllPoints();
83     f.base:SetColorTexture(0, 0, 0, 0.5);
84     f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
85     f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
86     f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
87     f.health = f:CreateTexture(nil, "BORDER");
88     f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
89     f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, -height/8);
90     f.health:SetTexture(barTexture);
91     f.health:SetVertexColor(0.7, 0.7, 0.7);
92     f.health:Hide();
93     f.mana = f:CreateTexture(nil, "BORDER");
94     f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -height/8);
95     f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
96     f.mana:SetTexture(barTexture);
97     f.mana:SetVertexColor(0.1, 0.5, 0.9);
98     f.mana:Hide();
99     f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
100     f.manatext:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -2, 1);
101     f.manatext:SetFont(STANDARD_TEXT_FONT, 10);
102     f.manatext:Hide();
103     f.shield = f:CreateTexture(nil, "BORDER");
104     f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
105     f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
106     f.shield:SetTexture(barTexture);
107     f.shield:SetVertexColor(0, 0.7, 1);
108     f.shield:Hide();
109     f.shieldhl = f:CreateTexture(nil, "ARTWORK");
110     f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
111     f.shieldhl:SetPoint("BOTTOMRIGHT", f, "RIGHT", 0, -height/8);
112     f.shieldhl:SetColorTexture(0.5, 0.8, 1);
113     f.shieldhl:Hide();
114     f.healpred = f:CreateTexture(nil, "ARTWORK");
115     f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
116     f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
117     f.healpred:SetColorTexture(0.5, 0.6, 0.5);
118     f.healpred:Hide();
119     f.healabsorb = f:CreateTexture(nil, "ARTWORK");
120     f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
121     f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
122     f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
123     f.healabsorb:Hide();
124     f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
125     f.name:SetPoint("LEFT", f, "LEFT", 2, 6);
126     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
127     f.text:SetPoint("RIGHT", f, "RIGHT", -2, 6);
128     f.text:SetFont(STANDARD_TEXT_FONT, 13);
129     f.text:Hide();
130     f.targeticon = f:CreateTexture(nil, "OVERLAY");
131     f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
132     f.targeticon:SetWidth(12);
133     f.targeticon:SetHeight(12);
134     f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
135     f.targeticon:Hide();
136     -- Use Blizzard Alt Power Bar
137     local powerbar = _G[format("Boss%iTargetFramePowerBarAlt", string.sub(unit, 5, 5))];
138     powerbar:SetParent(f);
139     powerbar:ClearAllPoints();
140     powerbar:SetPoint("RIGHT", f, "LEFT");
141
142     RegisterUnitWatch(f);
143     f:Show();
144     return f;
145 end
146
147 CFrame:SetScript("OnEvent", function(self)
148     _, class = UnitClass("player");
149     attributes = addon.Clickheal[class];
150     self:UnregisterAllEvents();
151     CFrame:SetFrameStrata("LOW");
152     CFrame:SetPoint("CENTER", nil, "CENTER");
153     CFrame:SetWidth(2);
154     CFrame:SetHeight(2);
155     for i =1,MAX_BOSS_FRAMES do
156         initBoss(self, -(i*36), 160, 32, addon.FrameUpdate, addon.UnitEvent);
157     end
158 end);
159 CFrame:RegisterEvent("PLAYER_LOGIN");