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