vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 BClassBar
3 <description>
4  
5 Saved Variables:
6 Bongos.class = {
7 <All variables from BBar>
8 space
9 The spacing between action buttons, in pixels. A nil value means that the bar is using default spacing
10 rows
11 How many rows the bar is organized into.
12 }
13 --]]
14  
15 --constants
16 local DEFAULT_SPACING = 2;
17 local DEFAULT_ROWS = 1;
18  
19 --[[ Utility Functions ]]--
20  
21 function BClassBar_ForAllButtons(action, arg1)
22 for i = 1, GetNumShapeshiftForms() do
23 local button = getglobal("BClassBarButton" .. i);
24 if button then
25 action(button, arg1);
26 else
27 return;
28 end
29 end
30 end
31  
32 --[[ Layout Functions ]]--
33  
34 local function SaveSettings(bar, rows, space)
35 if not space or space == DEFAULT_SPACING then
36 space = nil;
37 end
38 bar.sets.space = space;
39  
40 if not rows or rows == DEFAULT_ROWS then
41 rows = nil;
42 end
43 bar.sets.rows = rows;
44  
45 return (rows or DEFAULT_ROWS), (space or DEFAULT_SPACING);
46 end
47  
48 local function Layout(bar, rows, space)
49 rows, space = SaveSettings(bar, rows, space);
50  
51 local numForms = GetNumShapeshiftForms();
52 local columns = math.ceil(numForms / rows);
53  
54 --resize the bar
55 bar:SetWidth((30 + space) * columns - space);
56 bar:SetHeight((30 + space) * math.ceil(numForms / columns) - space);
57  
58 local index = 1;
59 local buttonPrefix = bar:GetName() .. "Button";
60  
61 --set the position of the first button of the bar
62 local button = getglobal(buttonPrefix .. index);
63 button:ClearAllPoints();
64 button:SetPoint("TOPLEFT", bar);
65  
66 --set the positions of the remaining buttons
67 for i = 1, rows, 1 do
68 for j = 1, columns, 1 do
69 index = index + 1;
70 if index > numForms then return; end
71  
72 button = getglobal(buttonPrefix .. index);
73 button:ClearAllPoints();
74 button:SetPoint("LEFT", buttonPrefix .. index - 1, "RIGHT", space, 0);
75 end
76 if(index > numForms) then return; end
77  
78 button = getglobal(buttonPrefix .. index);
79 button:ClearAllPoints();
80 button:SetPoint("TOP", buttonPrefix .. index - columns, "BOTTOM", 0, -space);
81 end
82 end
83  
84 --[[ OnX Functions ]]--
85  
86 local function OnEvent()
87 if event == "UPDATE_BINDINGS" then
88 BClassBar_ForAllButtons(BClassButton.UpdateHotkey);
89 return;
90 end
91 local bar = this;
92  
93 --Update buttons
94 for i=1, GetNumShapeshiftForms() do
95 local button = getglobal(bar:GetName() .. "Button" .. i);
96 if not button then
97 button = BClassButton.Create(i, bar);
98 layoutChanged = 1;
99 else
100 BClassButton.Update(button);
101 end
102 end
103  
104 if layoutChanged then
105 Layout(bar, bar.sets.rows, bar.sets.space);
106 end
107 end
108  
109 --[[ Rightclick Menu Functions ]]--
110  
111 local function CreateConfigMenu(name)
112 local menu = CreateFrame("Button", name, UIParent, "BongosRightClickMenu");
113 menu:SetText("Class Bar");
114 menu:SetWidth(220);
115 menu:SetHeight(236);
116  
117 local hideButton = CreateFrame("CheckButton", name .. "Hide", menu, "BongosHideButtonTemplate");
118  
119 local rowsSlider = CreateFrame("Slider", name .. "Rows", menu, "BongosSlider");
120 rowsSlider:SetPoint("TOPLEFT", hideButton, "BOTTOMLEFT", 2, -10);
121 rowsSlider:SetScript("OnValueChanged", function()
122 if not this:GetParent().onShow then
123 Layout(BClassBar, this:GetValue(), BClassBar.sets.space);
124 end
125 getglobal(this:GetName() .. "ValText"):SetText( this:GetValue() );
126 end);
127 rowsSlider:SetValueStep(1);
128 rowsSlider:SetMinMaxValues(1, GetNumShapeshiftForms());
129 getglobal(name .. "RowsText"):SetText("Rows");
130 getglobal(name .. "RowsLow"):SetText(1);
131  
132 local spacingSlider = CreateFrame("Slider", name .. "Spacing", menu, "BongosSpaceSlider");
133 spacingSlider:SetPoint("TOP", rowsSlider, "BOTTOM", 0, -24);
134 spacingSlider:SetScript("OnValueChanged", function()
135 if not this:GetParent().onShow then
136 Layout(BClassBar, BClassBar.sets.rows, this:GetValue());
137 end
138 getglobal(this:GetName() .. "ValText"):SetText( this:GetValue() );
139 end);
140  
141 local scaleSlider = CreateFrame("Slider", name .. "Scale", menu, "BongosScaleSlider");
142 scaleSlider:SetPoint("TOP", spacingSlider, "BOTTOM", 0, -24);
143  
144 local opacitySlider = CreateFrame("Slider", name .. "Opacity", menu, "BongosOpacitySlider");
145 opacitySlider:SetPoint("TOP", scaleSlider, "BOTTOM", 0, -24);
146 end
147  
148 --Called when the right click menu is shown, loads the correct values to the checkbuttons/sliders/text
149 local function ShowMenu(bar)
150 if not BongosClassBarMenu then
151 CreateConfigMenu("BongosClassBarMenu");
152 end
153  
154 BongosClassBarMenu.onShow = 1;
155 BongosClassBarMenu.frame = bar;
156  
157 BongosClassBarMenuHide:SetChecked(not bar.sets.vis);
158 BongosClassBarMenuSpacing:SetValue(bar.sets.space or DEFAULT_SPACING);
159 BongosClassBarMenuRows:SetValue(bar.sets.rows or DEFAULT_ROWS);
160  
161 BongosClassBarMenuRowsHigh:SetText(GetNumShapeshiftForms());
162 BongosClassBarMenuRows:SetMinMaxValues(1, GetNumShapeshiftForms());
163  
164 BongosClassBarMenuScale:SetValue(bar:GetScale() * 100);
165 BongosClassBarMenuOpacity:SetValue(bar:GetAlpha() * 100);
166  
167 --Position menu then show it
168 BMenu.ShowMenuForBar(BongosClassBarMenu, bar);
169 BongosClassBarMenu.onShow = nil;
170 end
171  
172 --[[ Startup ]]--
173  
174 BScript.AddStartupAction(function()
175 local bar = BBar.Create("class", "BClassBar", "BActionSets.class", ShowMenu);
176 if not bar:IsUserPlaced() then
177 bar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 480);
178 end
179  
180 bar:SetScript("OnEvent", OnEvent);
181  
182 bar:RegisterEvent("UPDATE_SHAPESHIFT_FORMS");
183 bar:RegisterEvent("ACTIONBAR_UPDATE_USABLE");
184 bar:RegisterEvent("UPDATE_INVENTORY_ALERTS");
185 bar:RegisterEvent("SPELL_UPDATE_COOLDOWN");
186 bar:RegisterEvent("SPELL_UPDATE_USABLE");
187 bar:RegisterEvent("PLAYER_AURAS_CHANGED");
188 bar:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
189 bar:RegisterEvent("UNIT_HEALTH");
190 bar:RegisterEvent("UNIT_HEALTH");
191 bar:RegisterEvent("UNIT_RAGE");
192 bar:RegisterEvent("UNIT_FOCUS");
193 bar:RegisterEvent("UNIT_ENERGY");
194 bar:RegisterEvent("UPDATE_BINDINGS");
195 end);