e8f2d3b - Change bar texture, explicitly hide focus spell bar
[wowui.git] / OmaUF / BossFrames.lua
1 -- BossFrames.lua
2 local _;
3 local unpack, pairs = unpack, pairs;
4 local format = string.format;
5 local GameTooltip = nil;
6 local GameTooltip_SetDefaultAnchor = nil;
7
8 local registerUnitEvents = OmaUFEvents.RegisterUnitEvents;
9 local unitEvent = OmaUFEvents.UnitEvent;
10
11 local Settings = OmaUFSettings;
12 local baseColor = Settings.BaseColor;
13 local bgColor = Settings.BgColor;
14 local healthColor = Settings.HealthColor;
15 local shieldColor = Settings.ShieldColor;
16 local shieldhlColor = Settings.ShieldhlColor;
17 local healpredColor = Settings.HealpredColor;
18 local healabsorbColor = Settings.HealabsorbColor;
19 local width, height = Settings.Boss.Width, Settings.Boss.Height;
20 local anchorX, anchorY = Settings.Boss.AnchorX, Settings.Boss.AnchorY;
21 -- placeholders with visible values when error happens
22 local attributes = {};
23
24 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
25
26 local function frameShow(frame)
27     frame:RegisterEvent("PLAYER_ENTERING_WORLD");
28     frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
29     frame:RegisterEvent("UNIT_TARGETABLE_CHANGED");
30     frame:RegisterUnitEvent("UNIT_LEVEL", frame.unit);
31     registerUnitEvents(frame);
32     unitEvent(frame, "UPDATE_ALL_BARS");
33 end
34
35 local function frameHide(frame)
36     frame:UnregisterAllEvents();
37 end
38
39 local function showTooltip(secure)
40     GameTooltip_SetDefaultAnchor(GameTooltip, secure);
41     GameTooltip:SetUnit(secure:GetAttribute("unit"));
42 end
43
44 local function hideTooltip(secure)
45     GameTooltip:FadeOut();
46 end
47
48 local function createFrame(framename, securename, parent, unit, anchorX, anchorY)
49     local secure = CreateFrame("Button", securename, parent, inheritedFrames);
50     local frame = CreateFrame("Frame", framename, parent);
51     secure:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY);
52     secure:SetAttribute("unit", unit);
53     frame:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY);
54     frame:SetAttribute("unit", unit);
55     frame.unit = unit;
56     frame.displayed = unit;
57     -- hide frame to get initial frameShow call
58     frame:Hide();
59     -- create visuals
60     secure:SetWidth(width+2);
61     secure:SetHeight(height+2);
62     frame:SetWidth(width+2);
63     frame:SetHeight(height+2);
64     frame.width = width;
65     frame.base = frame:CreateTexture(nil, "BACKGROUND");
66     frame.base:SetAllPoints();
67     frame.base:SetColorTexture(1, 1, 1);
68     frame.base:SetVertexColor(unpack(baseColor));
69     frame.healthback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
70     frame.healthback:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
71     frame.healthback:SetPoint("BOTTOMRIGHT", frame, "RIGHT", -1, -5);
72     frame.healthback:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
73     frame.healthback:SetVertexColor(unpack(bgColor));
74     frame.health = frame:CreateTexture(nil, "BORDER");
75     frame.health:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT");
76     frame.health:SetPoint("BOTTOMLEFT", frame.healthback, "BOTTOMLEFT");
77     frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
78     frame.health:SetVertexColor(unpack(healthColor));
79     frame.healthText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
80     frame.healthText:SetPoint("RIGHT", frame.healthback, "RIGHT", -2, 0);
81     frame.healthText.percent = true;
82     frame.manaback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
83     frame.manaback:SetPoint("TOPLEFT", frame, "LEFT", 1, -5);
84     frame.manaback:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
85     frame.manaback:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
86     frame.manaback:SetVertexColor(unpack(bgColor));
87     frame.mana = frame:CreateTexture(nil, "BORDER");
88     frame.mana:SetPoint("TOPLEFT", frame.manaback, "TOPLEFT");
89     frame.mana:SetPoint("BOTTOMLEFT", frame.manaback, "BOTTOMLEFT");
90     frame.mana:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
91     frame.manaText = frame:CreateFontString(nil, "ARTWORK", "GameFontWhiteTiny");
92     frame.manaText:SetPoint("RIGHT", frame.manaback, "RIGHT", -2, 0);
93     frame.manaText:Hide();
94     frame.shield = frame:CreateTexture(nil, "BORDER");
95     frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
96     frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
97     frame.shield:SetTexture("Interface\\RaidFrame\\Shield-Fill");
98     frame.shield:SetVertexColor(unpack(shieldColor));
99     frame.shield:Hide();
100     frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
101     frame.shieldhl:SetPoint("TOPLEFT", frame.healthback, "TOPRIGHT", -1, 0);
102     frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.healthback, "BOTTOMRIGHT", 1, 0);
103     frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
104     frame.shieldhl:Hide();
105     frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
106     frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
107     frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
108     frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
109     frame.healabsorb:Hide();
110     frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
111     frame.name:SetPoint("LEFT", frame.healthback, "LEFT", 2, 1);
112     frame.name.count = 10;
113     frame.level = frame:CreateFontString(nil, "OVERLAY", "GameFontWhiteTiny");
114     frame.level:SetPoint("LEFT", frame.manaback, "LEFT", 2, 1);
115     frame.targeticon = frame:CreateTexture(nil, "OVERLAY");
116     frame.targeticon:SetPoint("CENTER", frame.healthback, "TOP");
117     frame.targeticon:SetWidth(16);
118     frame.targeticon:SetHeight(16);
119     frame.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
120     frame.targeticon:Hide();
121     -- set scripts
122     frame:SetScript("OnShow", frameShow);
123     frame:SetScript("OnHide", frameHide);
124     frame:SetScript("OnEvent", unitEvent);
125     secure:SetScript("OnEnter", showTooltip);
126     secure:SetScript("OnLeave", hideTooltip);
127     -- set attributes
128     -- TODO other set of click cast on boss frames possibly
129     secure:RegisterForClicks("AnyDown");
130     for attr, val in pairs(attributes) do
131         secure:SetAttribute(attr, val);
132     end
133     -- rest give target and menu
134     secure:SetAttribute("*type1", "target");
135     secure:SetAttribute("*type2", "togglemenu");
136     secure:SetAttribute("toggleForVehicle", false);
137     RegisterUnitWatch(frame);
138     RegisterUnitWatch(secure);
139 end
140
141 function OmaUnitFrames.InitializeBoss(parent)
142     GameTooltip = _G["GameTooltip"];
143     GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
144     attributes = Settings.Character.Clickheal;
145
146     createFrame("OmaBoss1", "OmaBossSecure1", parent, "boss1", anchorX, anchorY);
147     for i = 2,MAX_BOSS_FRAMES do
148         createFrame("OmaBoss"..i, "OmaBossSecure"..i, _G["OmaBoss"..(i-1)], "boss"..i, 0, -height-15);
149     end
150     -- Arena frames are in the same spot
151     createFrame("OmaArena1", "OmaArenaSecure1", parent, "arena1", anchorX, anchorY);
152     -- MAX_ARENA_ENEMIES from AddOns/Blizzard_ArenaUI/Blizzard_ArenaUI.lua not available
153     -- as the addon is not loaded yet, update manually if it changes
154     for i = 2,5 do
155         createFrame("OmaArena"..i, "OmaArenaSecure"..i, _G["OmaArena"..(i-1)], "arena"..i, 0, -height-15);
156     end
157 end