8b1be3a - More auras and stagger tracking
[wowui.git] / OmaAB / StanceBar.lua
1 local _;
2 local format = string.format;
3 local stancebar = CreateFrame("Frame", "OmaStanceBar", UIParent);
4
5 function create(slot, bar, prev)
6     local frame = CreateFrame("CheckButton", "OmaBTStance"..slot, bar, "StanceButtonTemplate");
7     bar[slot] = frame;
8     frame:SetID(slot);
9     frame:SetWidth(32);
10     frame:SetHeight(32);
11     frame:GetNormalTexture():SetTexture("");
12     frame.cooldown = { SetSwipeColor = function() end, };
13     frame.base = frame:CreateTexture(nil, "BACKGROUND");
14     frame.base:SetAllPoints();
15     frame.base:SetColorTexture(0, 0, 0, 0.5);
16     frame.icon = frame:CreateTexture(nil, "ARTWORK");
17     frame.icon:SetPoint("TOPLEFT", frame.base, "TOPLEFT", 1, -1);
18     frame.icon:SetPoint("BOTTOMRIGHT", frame.base, "BOTTOMRIGHT", -1, 1);
19     frame.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93);
20
21     if slot == 1 then
22         frame:SetPoint("TOPLEFT");
23     else
24         frame:SetPoint("TOPLEFT", prev, "TOPRIGHT");
25     end
26     frame:RegisterForClicks("AnyUp");
27 end
28
29 -- FIXME if more stances necessary use NUM_STANCE_SLOTS for the max, paladins have 3
30 function update(bar)
31     local n = GetNumShapeshiftForms();
32     --for i=1,NUM_STANCE_SLOTS do
33     for i=1,4 do
34         local button = bar[i];
35         if i <= n then
36             local tex, active, castable = GetShapeshiftFormInfo(i);
37             local icon = button.icon;
38             icon:SetTexture(tex);
39             if active then
40                 button:SetChecked(true);
41             else
42                 button:SetChecked(false);
43             end
44             if castable then
45                 icon:SetVertexColor(1, 1, 1);
46             else
47                 icon:SetVertexColor(0.4, 0.4, 0.4);
48             end
49             --button:Show();
50         else
51             --button:Hide();
52         end
53     end
54 end
55
56 stancebar:SetScript("OnEvent", function(self, event)
57     if event == "UPDATE_SHAPESHIFT_COOLDOWN" then
58         update(self);
59     elseif event == "PLAYER_LOGIN" then
60         -- TODO do class detection and only create necessary buttons
61         stancebar:UnregisterAllEvents();
62         local _, class = UnitClass("player");
63         if class ~= "PALADIN" and class ~= "DRUID" then
64             return
65         end
66         for i=1,4 do
67             create(i, self, self[i-1]);
68         end
69         update(self);
70         _G["BINDING_HEADER_OMAABSTANCE"] = "Stance Bar";
71         for i = 1,4 do
72             _G[format("BINDING_NAME_CLICK OmaBTStance%d:LeftButton", i)] = format("Stance Bar Button %d", i);
73         end
74         stancebar:RegisterEvent("UPDATE_SHAPESHIFT_COOLDOWN");
75     end
76 end);
77 stancebar:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 580, 40);
78 stancebar:SetFrameStrata("LOW");
79 stancebar:SetWidth(1);
80 stancebar:SetHeight(1);
81 stancebar:RegisterEvent("PLAYER_LOGIN");
82 stancebar:Show();