vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Helper functions for the GUI elements of FlexBar |
||
3 | Last Modified |
||
4 | 04/09/2005 Initial version |
||
5 | 08/21/2005 Small change to FB_ScriptsDelete - fully delete a script |
||
6 | --]] |
||
7 | |||
8 | local util = Utility_Class:New() |
||
9 | local OldToggleGameMenu = ToggleGameMenu |
||
10 | local panels = { |
||
11 | ["FBScriptsFrame"] = { "FBMenuScript", "FBScriptsMenu" }, |
||
12 | ["FBEventEditorFrame"] = { "FBIfOpsMenu", "FBEEDDMenu" }, |
||
13 | ["FBOptionsFrame"] = {}, |
||
14 | ["FBPerformanceFrame"] = {}, |
||
15 | ["FBAutoItemsFrame"] = {}, |
||
16 | } |
||
17 | |||
18 | -- Hooking GUI escape press to close my menus as I couldn't figure out how |
||
19 | -- to get them to behave like UI dropdowns |
||
20 | function ToggleGameMenu(clicked) |
||
21 | -- |
||
22 | local index,panel,menus |
||
23 | local nomenushowing = true |
||
24 | local nopanelshowing = true |
||
25 | for panel,menus in pairs(panels) do |
||
26 | for index2, menu in ipairs(menus) do |
||
27 | if getglobal(menu):IsVisible() then |
||
28 | getglobal(menu):Hide() |
||
29 | nomenushowing = false |
||
30 | end |
||
31 | end |
||
32 | end |
||
33 | |||
34 | if nomenushowing then |
||
35 | for panel,menus in pairs(panels) do |
||
36 | if getglobal(panel):IsVisible() then |
||
37 | getglobal(panel):Hide() |
||
38 | nopanelshowing = false |
||
39 | end |
||
40 | end |
||
41 | end |
||
42 | |||
43 | if nopanelshowing and nomenushowing then |
||
44 | if FBMenu1:IsVisible() then |
||
45 | FBMenu1:Hide() |
||
46 | else |
||
47 | OldToggleGameMenu( clicked ) |
||
48 | end |
||
49 | end |
||
50 | |||
51 | end |
||
52 | |||
53 | |||
54 | -- Register our panels |
||
55 | UIPanelWindows["FBScriptsFrame"] = { area = "center", pushable = 0 }; |
||
56 | UIPanelWindows["FBEventEditorFrame"] = { area = "center", pushable = 0 }; |
||
57 | UIPanelWindows["FBPerformanceFrame"] = { area = "center", pushable = 0 }; |
||
58 | UIPanelWindows["FBOptionsFrame"] = { area = "center", pushable = 0 }; |
||
59 | UIPanelWindows["FBAutoItemsFrame"] = { area = "center", pushable = 0 }; |
||
60 | |||
61 | function FB_GUI_Main_Menu() |
||
62 | -- display a menu of ui panels |
||
63 | FB_Menu_Display("FBMenu1",FBGUIPanelsList, FB_GUIPanelsCallBack, |
||
64 | 5, 240, "UIParent", "CENTER", "CENTER", 0, 0) |
||
65 | end |
||
66 | |||
67 | function FB_GUIPanelsCallBack(value,action) |
||
68 | -- display appropriate panel |
||
69 | if action ~= "click" then return end |
||
70 | if value == "Event Editor" then |
||
71 | FB_DisplayEventEditor() |
||
72 | elseif value == "Script Editor" then |
||
73 | FB_ShowScripts() |
||
74 | elseif value == "Global Options" then |
||
75 | FB_ShowGlobalOptions() |
||
76 | elseif value == "Auto Items" then |
||
77 | FB_DisplayAutoItems() |
||
78 | elseif value == "Performance Options" then |
||
79 | FB_Show_PerformanceOptions() |
||
80 | end |
||
81 | end |
||
82 | |||
83 | function FB_Show_Scripts_Dropdown() |
||
84 | -- Display menu of available scripts |
||
85 | local scripts = {} |
||
86 | local index, value |
||
87 | for index, value in pairs(FBScripts) do |
||
88 | table.insert(scripts,index) |
||
89 | end |
||
90 | table.sort(scripts, function(v1,v2) return string.lower(v1) < string.lower(v2) end) |
||
91 | |||
92 | local callback = function(value, action, name, button) |
||
93 | if action == "click" then |
||
94 | ScriptNameEditBox:SetText(value) |
||
95 | getglobal(name):GetParent():Hide() |
||
96 | if button=="RightButton" then FB_Scripts_Load() end |
||
97 | end |
||
98 | end |
||
99 | |||
100 | FB_Menu_Display("FBMenuScript",scripts,callback,FBToggles["dropdown"],300,"ScriptNameEditBox","TOPLEFT","BOTTOMLEFT",-6,0) |
||
101 | FBScriptsEditBox:ClearFocus() |
||
102 | ScriptNameEditBox:ClearFocus() |
||
103 | end |
||
104 | |||
105 | function FB_ShowScripts() |
||
106 | -- Show Scripts frame |
||
107 | FBScriptsFrame:Show() |
||
108 | FBScriptsEditBox:SetFocus() |
||
109 | end |
||
110 | function FB_Scripts_Delete() |
||
111 | -- Delete script named in ScriptNameEditBox |
||
112 | local scriptname = ScriptNameEditBox:GetText() |
||
113 | if scriptname and scriptname ~= "" then |
||
114 | FBTextChunks[scriptname] = nil |
||
115 | FBScripts[scriptname] = nil |
||
116 | message("Script " .. scriptname .. " deleted") |
||
117 | else |
||
118 | message("Script " .. scriptname .. " not found") |
||
119 | end |
||
120 | FB_DisplayScripts() |
||
121 | end |
||
122 | |||
123 | function FB_Scripts_Save() |
||
124 | -- Save current text in text editor under name in ScriptNameEditBox |
||
125 | local scriptname = ScriptNameEditBox:GetText() |
||
126 | if scriptname and scriptname ~= "" then |
||
127 | local text = FBScriptsEditBox:GetText() |
||
128 | FBScripts[scriptname]=FBScriptsEditBox:GetText() |
||
129 | if string.len(text) > 512 then |
||
130 | FBTextChunks[scriptname] = {} |
||
131 | local index |
||
132 | local len = 511 |
||
133 | for index = 1,string.len(text),512 do |
||
134 | if index + len > string.len(text) then |
||
135 | len = string.len(text) - index |
||
136 | end |
||
137 | local chunk = string.sub(text,index,index+len) |
||
138 | table.insert(FBTextChunks[scriptname], chunk) |
||
139 | end |
||
140 | else |
||
141 | FBTextChunks[scriptname] = nil |
||
142 | end |
||
143 | else |
||
144 | message("Please specify a script name") |
||
145 | end |
||
146 | FB_DisplayScripts() |
||
147 | end |
||
148 | |||
149 | function FB_Scripts_Load() |
||
150 | -- Load named script into script editor |
||
151 | local scriptname = ScriptNameEditBox:GetText() |
||
152 | if scriptname and scriptname ~= "" then |
||
153 | FBScriptsEditBox:SetText(FBScripts[scriptname]) |
||
154 | FBScriptsEditBox:SetFocus(); |
||
155 | else |
||
156 | message("Script " .. scriptname .. " not found") |
||
157 | end |
||
158 | end |
||
159 | |||
160 | function FB_Scripts_List() |
||
161 | -- Show scripts list - OBSOLETE |
||
162 | if FBScriptsMenu:IsVisible() then |
||
163 | FBScriptsMenu:Hide() |
||
164 | else |
||
165 | FBScriptsMenu:Show() |
||
166 | FB_DisplayScripts() |
||
167 | end |
||
168 | end |
||
169 | |||
170 | function FB_Scripts_Import() |
||
171 | -- Search for config from FBScripts and import into straight text format |
||
172 | local temp = getglobal(ScriptNameEditBox:GetText()) |
||
173 | if not temp then |
||
174 | message(ScriptNameEditBox .. " not found") |
||
175 | else |
||
176 | local index, value |
||
177 | local text = "" |
||
178 | for index, value in ipairs(temp) do |
||
179 | text = text .. value .. "\n" |
||
180 | end |
||
181 | FBScriptsEditBox:SetText(text) |
||
182 | end |
||
183 | end |
||
184 | |||
185 | function FB_Scripts_TextChanged(editbox) |
||
186 | -- Text changed, cursor may have changed, reset scroll frame |
||
187 | local scrollframe = editbox:GetParent():GetParent() |
||
188 | local scrollbar = getglobal(scrollframe:GetName().."ScrollBar") |
||
189 | scrollframe:UpdateScrollChildRect(); |
||
190 | local scrollmin, scrollmax = scrollbar:GetMinMaxValues(); |
||
191 | if ( scrollmax > 0 and (this.max ~= scrollmax) ) then |
||
192 | this.max = scrollmax; |
||
193 | -- scrollbar:SetValue(scrollmax); |
||
194 | end |
||
195 | end |
||
196 | |||
197 | function FB_Scripts_OnCursorChanged(editbox) |
||
198 | -- Cursor has moved, scroll frame appropriately |
||
199 | local scrollframe = editbox:GetParent():GetParent() |
||
200 | local scrollbar = getglobal(scrollframe:GetName().."ScrollBar") |
||
201 | local scrollamt = scrollbar:GetValue()/arg4 |
||
202 | local scrollmin, scrollmax = scrollbar:GetMinMaxValues() |
||
203 | local linenumber = -(arg2/arg4) |
||
204 | if linenumber-math.floor(linenumber) > .5 then |
||
205 | linenumber = math.ceil(linenumber) |
||
206 | else |
||
207 | linenumber = math.floor(linenumber) |
||
208 | end |
||
209 | |||
210 | local page = math.floor(linenumber/17) + 1 |
||
211 | |||
212 | scrollbar:SetValue((page-1) * 17 * arg4) |
||
213 | |||
214 | if ((page-1)*17*arg4) > (scrollmax - (arg4/2)) then |
||
215 | scrollbar:SetValue(scrollmax) |
||
216 | end |
||
217 | |||
218 | editbox.pagenumber = page |
||
219 | editbox.linenumber = linenumber |
||
220 | local status = "(%d | %d)" |
||
221 | FBScriptsStatusText:SetText(format(status,editbox.linenumber+1,editbox:GetNumLetters())) |
||
222 | scrollframe:UpdateScrollChildRect(); |
||
223 | |||
224 | end |
||
225 | |||
226 | function FB_Scripts_ExportEvents() |
||
227 | local i, j, k, target, subtarget, event, text |
||
228 | text = "" |
||
229 | for i, event in ipairs(FBEvents) do |
||
230 | text = text..tostring(event["command"]).." on='"..tostring(event["on"]).."'" |
||
231 | if event["target"] ~= nil then |
||
232 | text = text.." target='[ " |
||
233 | for j, target in pairs(event["target"]) do |
||
234 | if type(target) == "string" then text = text.."\""..target.."\" " |
||
235 | elseif type(target) == "number" then text = text..target.." " end |
||
236 | end |
||
237 | text = text.."]'" |
||
238 | end |
||
239 | text = text.."\n" |
||
240 | end |
||
241 | FBScriptsEditBox:SetText(text) |
||
242 | end |
||
243 | function FB_Scripts_ExportPositions() |
||
244 | local btn, state, export |
||
245 | export = '' |
||
246 | for btn, state in pairs(FBState) do |
||
247 | if type(state) == "table" then |
||
248 | export = export.. string.format("moveabs button=%d xx=%d yy=%d\n", btn, state.xcoord, state.ycoord) |
||
249 | end |
||
250 | end |
||
251 | FBScriptsEditBox:SetText(export) |
||
252 | end |
||
253 | function FB_Scripts_ExportSetup() |
||
254 | local i, j, btn, state, formatb, masscommands, attrib, key, val, export |
||
255 | export = "show button=1-120\ndisable button=1-120 state='off'\n" |
||
256 | masscommands = {} |
||
257 | masscommands.hidden = {} |
||
258 | masscommands.scale = {} |
||
259 | masscommands.locked = {} |
||
260 | masscommands.lockedicon = {} |
||
261 | masscommands.hotkeytext = {} |
||
262 | masscommands.text2 = {} |
||
263 | masscommands.text3 = {} |
||
264 | masscommands.group = {} |
||
265 | masscommands.justifytext = {} |
||
266 | masscommands.justifytext2 = {} |
||
267 | masscommands.justifytext3 = {} |
||
268 | masscommands.icon = {} |
||
269 | masscommands.hotkeycolor = {} |
||
270 | masscommands.text2color = {} |
||
271 | masscommands.text3color = {} |
||
272 | masscommands.hidegrid = {} |
||
273 | masscommands.disabled = {} |
||
274 | formatb = {} |
||
275 | formatb.hotkeytext = "text button=[ %s ] text='%s'\n" |
||
276 | formatb.text2 = "text2 button=[ %s ] text='%s'\n" |
||
277 | formatb.text3 = "text3 button=[ %s ] text='%s'\n" |
||
278 | formatb.hidden = "hide button=[ %s ]\n" |
||
279 | formatb.scale = "scale button=[ %s ] scale=%s\n" |
||
280 | formatb.fade = "fade button=[ %s ] alpha=%d\n" |
||
281 | formatb.icon = "shade button=[ %s ] color=[ %s]\n" |
||
282 | formatb.justifytext = "justifytext button=[ %s ] pos='%s'\n" |
||
283 | formatb.justifytext2 = "justifytext2 button=[ %s ] pos='%s'\n" |
||
284 | formatb.justifytext3 = "justifytext3 button=[ %s ] pos='%s'\n" |
||
285 | formatb.hotkeycolor = "shadetext button=[ %s ] color=[ %s]\n" |
||
286 | formatb.text2color = "shadetext2 button=[ %s ] color=[ %s]\n" |
||
287 | formatb.text3color = "shadetext3 button=[ %s ] color=[ %s]\n" |
||
288 | formatb.hidegrid = "hidegrid button=[ %s ]\n" |
||
289 | formatb.locked = "lock button=[ %s ]\n" |
||
290 | formatb.lockedicon = "lockicon button=[ %s ]\n" |
||
291 | formatb.disabled = "disable button=[ %s ] state='on'\n" |
||
292 | formatb.remap = "remap button=[ %s ] base=%d\n" |
||
293 | formatb.group = "group button=[ %s ] anchor=%d\n" |
||
294 | for btn, state in pairs(FBState) do |
||
295 | if type(state)=="table" then |
||
296 | for key, val in pairs(state) do |
||
297 | if masscommands[key] ~= nil then |
||
298 | if key == "scale" then val = val * 10 end |
||
299 | if type(val) == "table" then |
||
300 | local tempval = '' |
||
301 | i = 1 |
||
302 | while i <= table.getn(val) do |
||
303 | tempval = tempval .. val[i]*10 .." " |
||
304 | i = i + 1 |
||
305 | end |
||
306 | val = tempval |
||
307 | end |
||
308 | if masscommands[key][val] == nil then |
||
309 | masscommands[key][val] = {} |
||
310 | end |
||
311 | table.insert(masscommands[key][val], btn) |
||
312 | end |
||
313 | end |
||
314 | end |
||
315 | end |
||
316 | for attrib, val in pairs(masscommands) do |
||
317 | --FB_ReportToUser("'"..attrib.."'") |
||
318 | for state, key in val do |
||
319 | btn = '' |
||
320 | --FB_ReportToUser(" ".. tostring(state)) |
||
321 | for i, j in pairs(key) do |
||
322 | btn = btn..j.." " |
||
323 | end |
||
324 | if state ~= nil and state ~= '' then |
||
325 | export = export..string.format(formatb[attrib], btn, state) |
||
326 | end |
||
327 | end |
||
328 | end |
||
329 | FBScriptsEditBox:SetText(export) |
||
330 | |||
331 | end |
||
332 | function FB_Scripts_ExportActions() |
||
333 | local i, action, text |
||
334 | text = "" |
||
335 | --FB_ReportToUser("Exporting Actions") |
||
336 | for i, action in pairs(FBSavedProfile[FBProfileName].FlexActions) do |
||
337 | -- Ensure the target button is cleared |
||
338 | text = text..string.format("runscript script='PickupAction(%d);PutItemInBackpack();'\nclearflex id=%d\n", i, i) |
||
339 | --FB_ReportToUser("Action "..i) |
||
340 | if action.action == "script" then |
||
341 | text = text..string.format("flexscript id=%d script='%s' texture='%s' name='%s'\n", |
||
342 | i, |
||
343 | string.gsub(action.script, "'", "\'"), |
||
344 | string.gsub(action.texture, "'", "\'"), |
||
345 | string.gsub(action.name, "'", "\'")) |
||
346 | elseif action.action == "macro" then |
||
347 | text = text..string.format("flexmacro id=%d macro='%s' texture='%s' name='%s'\n", |
||
348 | i, |
||
349 | string.gsub(action.macro, "'", "\'"), |
||
350 | string.gsub(action.texture, "'", "\'"), |
||
351 | string.gsub(action.name, "'", "\'")) |
||
352 | elseif action.action == "pet" then |
||
353 | text = text..string.format("flexpet id=%d petid=%d\n", i, action.id) |
||
354 | elseif action.action == "settexture" then |
||
355 | text = text..string.format("settexture id=%d texture='%s'\n", i, action.texture) |
||
356 | end |
||
357 | end |
||
358 | FBScriptsEditBox:SetText(text) |
||
359 | end |
||
360 | function FB_Set_PerformanceOptions() |
||
361 | -- Set labels and initial values from performance options table |
||
362 | local index, value |
||
363 | |||
364 | FBEventToggleInfo["sortlist"] = {} |
||
365 | for index,value in pairs(FBEventToggleInfo) do |
||
366 | if index ~= "sortlist" then |
||
367 | table.insert(FBEventToggleInfo["sortlist"],{ index, value["desc"] }) |
||
368 | end |
||
369 | end |
||
370 | table.sort(FBEventToggleInfo["sortlist"],function(v1,v2) return v1[2] < v2[2] end) |
||
371 | |||
372 | local count = 1 |
||
373 | for index,value in pairs(FBEventToggleInfo["sortlist"]) do |
||
374 | if count > 34 then break end |
||
375 | local event = FBEventToggleInfo[value[1]] |
||
376 | if string.sub(event["desc"],1,3) ~= "XXX" then |
||
377 | local button = getglobal("FBPerfBtn"..count) |
||
378 | local label = getglobal("FBPerfBtn"..count.."Label") |
||
379 | label:SetText(string.sub(event["desc"],5)) |
||
380 | button:SetText(FBEventToggles[value[1]]) |
||
381 | if FBEventToggles[value[1]] == "off" and event["timer"] then |
||
382 | FBTimers[event["timer"]]:Pause() |
||
383 | elseif FBEventToggles[value[1]] ~= "off" and event["timer"] then |
||
384 | FBTimers[event["timer"]]:Start() |
||
385 | end |
||
386 | button:Show() |
||
387 | count = count+1 |
||
388 | end |
||
389 | end |
||
390 | for index = count,34 do |
||
391 | local button = getglobal("FBPerfBtn"..index) |
||
392 | button:Hide() |
||
393 | end |
||
394 | end |
||
395 | |||
396 | function FB_Show_PerformanceOptions() |
||
397 | -- Show Performance Options frame |
||
398 | table.sort(FBEventToggles, function(v1,v2) return v1["desc"] < v2["desc"] end) |
||
399 | FB_Set_PerformanceOptions() |
||
400 | FBPerformanceFrame:Show() |
||
401 | end |
||
402 | |||
403 | function FB_Performance_Changed(button) |
||
404 | -- set new performance level for event group |
||
405 | local label = getglobal(button:GetName().."Label") |
||
406 | local index,value |
||
407 | FBEventToggleInfo["sortlist"]["lowlist"] = nil |
||
408 | for index,value in pairs(FBEventToggleInfo["sortlist"]) do |
||
409 | if string.sub(value[2],5) == label:GetText() then |
||
410 | if FBEventToggles[value[1]] == "off" then |
||
411 | FBEventToggles[value[1]] = "low" |
||
412 | elseif FBEventToggles[value[1]] == "low" then |
||
413 | FBEventToggles[value[1]] = "high" |
||
414 | else |
||
415 | FBEventToggles[value[1]] = "off" |
||
416 | end |
||
417 | end |
||
418 | end |
||
419 | FB_Set_PerformanceOptions() |
||
420 | end |
||
421 | |||
422 | function FB_LoadOptionsClick(button) |
||
423 | -- Set loadtype |
||
424 | local label = getglobal(button:GetName() .. "Label") |
||
425 | if button:GetText() == "safe" then |
||
426 | button:SetText("std") |
||
427 | elseif button:GetText() == "std" then |
||
428 | button:SetText("fast") |
||
429 | else |
||
430 | button:SetText("safe") |
||
431 | end |
||
432 | FBToggles["loadtype"] = string.lower(button:GetText()) |
||
433 | end |
||
434 | |||
435 | function FB_DropDownOptionsClick(button) |
||
436 | -- Set loadtype |
||
437 | local label = getglobal(button:GetName() .. "Label") |
||
438 | if button:GetText() == "5" then |
||
439 | button:SetText("10") |
||
440 | elseif button:GetText() == "10" then |
||
441 | button:SetText("15") |
||
442 | else |
||
443 | button:SetText("5") |
||
444 | end |
||
445 | FBToggles["dropdown"] = tonumber(button:GetText()) |
||
446 | end |
||
447 | |||
448 | function FB_ShowGlobalOptions() |
||
449 | -- load global options |
||
450 | FBOptionsFrame:Show() |
||
451 | |||
452 | if FBToggles["notooltips"] and not FBTooltipsOption:GetChecked() then |
||
453 | FBTooltipsOption:SetChecked(1) |
||
454 | end |
||
455 | if FBToggles["verbose"] and not FBVerboseOption:GetChecked() then |
||
456 | FBVerboseOption:SetChecked(1) |
||
457 | end |
||
458 | if FBToggles["forceshading"] and not FBShadingOption:GetChecked() then |
||
459 | FBShadingOption:SetChecked(1) |
||
460 | end |
||
461 | if FBToggles["autoperf"] and not FBAutoPerformanceOption:GetChecked() then |
||
462 | FBAutoPerformanceOption:SetChecked(1) |
||
463 | end |
||
464 | FBLoadOptionsButton:SetText(FBToggles["loadtype"]) |
||
465 | FBDropDownOptionsButton:SetText(FBToggles["dropdown"]) |
||
466 | end |
||
467 | |||
468 | function FB_Menu_Display(menuname, valuelist, callback, maxitems, width, parentframe, menuanchor, parentanchor, dx, dy) |
||
469 | -- Show a menu with the attached list of values and using the provided callback. |
||
470 | local menu = getglobal(menuname) |
||
471 | if not menu then return end |
||
472 | if not valuelist and not menu.list then return end |
||
473 | if not callback and not menu.callback then return end |
||
474 | local index |
||
475 | |||
476 | if valuelist then |
||
477 | menu.CurrentItem = 1 |
||
478 | menu.list = util:TableCopy(valuelist) |
||
479 | local index, value |
||
480 | menu.list.n = 0 |
||
481 | for index, value in ipairs(menu.list) do |
||
482 | menu.list.n = menu.list.n + 1 |
||
483 | end |
||
484 | end |
||
485 | if maxitems then |
||
486 | if maxitems < 3 then maxitems = 3 end |
||
487 | if maxitems > 25 then maxitems = 25 end |
||
488 | menu.maxitems = maxitems |
||
489 | end |
||
490 | |||
491 | if callback then menu.callback = callback end |
||
492 | |||
493 | if maxitems then |
||
494 | if menu.list.n <= maxitems then maxitems = menu.list.n end |
||
495 | menu:SetHeight((maxitems * 15) + 20) |
||
496 | local index |
||
497 | for index = maxitems+1,25 do |
||
498 | local item = getglobal(menu:GetName()..index) |
||
499 | item:Hide() |
||
500 | end |
||
501 | end |
||
502 | |||
503 | getglobal(menu:GetName().."ScrollDown"):Show() |
||
504 | getglobal(menu:GetName().."ScrollUp"):Show() |
||
505 | |||
506 | if maxitems and (menu.list.n <= maxitems) then |
||
507 | getglobal(menu:GetName().."ScrollDown"):Hide() |
||
508 | getglobal(menu:GetName().."ScrollUp"):Hide() |
||
509 | end |
||
510 | |||
511 | if width then |
||
512 | if width < 100 then width = 100 end |
||
513 | menu:SetWidth(width) |
||
514 | local index |
||
515 | for index = 1, menu.maxitems do |
||
516 | local item = getglobal(menu:GetName()..index) |
||
517 | local text = getglobal(item:GetName().."Label") |
||
518 | item:SetWidth(width - 32) |
||
519 | text:SetWidth(width - 32) |
||
520 | end |
||
521 | end |
||
522 | |||
523 | if parentframe then |
||
524 | if not menuanchor then menuanchor = "TOPLEFT" end |
||
525 | if not parentanchor then parentanchor = "TOPLEFT" end |
||
526 | if not dx then dx = 0 end |
||
527 | if not dy then dy = 0 end |
||
528 | menu:ClearAllPoints() |
||
529 | menu:SetPoint(menuanchor, parentframe, parentanchor, dx, dy) |
||
530 | menu:SetFrameLevel(getglobal(parentframe):GetFrameLevel() + 50) |
||
531 | local index |
||
532 | getglobal(menu:GetName().."ScrollUp"):SetFrameLevel(menu:GetFrameLevel()+5) |
||
533 | getglobal(menu:GetName().."ScrollDown"):SetFrameLevel(menu:GetFrameLevel()+5) |
||
534 | getglobal(menu:GetName().."CloseButton"):SetFrameLevel(menu:GetFrameLevel()+5) |
||
535 | for index = 1, menu.maxitems do |
||
536 | local item = getglobal(menu:GetName()..index) |
||
537 | local text = getglobal(item:GetName().."Label") |
||
538 | item:SetFrameLevel(menu:GetFrameLevel()+5) |
||
539 | end |
||
540 | end |
||
541 | |||
542 | if (menu.CurrentItem + (menu.maxitems - 1)) > menu.list.n then menu.CurrentItem = menu.list.n - (menu.maxitems - 1) end |
||
543 | if menu.CurrentItem < 1 then menu.CurrentItem = 1 end |
||
544 | |||
545 | for index = 0, menu.maxitems - 1 do |
||
546 | local button = getglobal(menu:GetName()..(index+1)) |
||
547 | local label = getglobal(button:GetName().."Label") |
||
548 | if menu.list[index+menu.CurrentItem] then |
||
549 | label:SetText(menu.list[index+menu.CurrentItem]) |
||
550 | button:Show() |
||
551 | else |
||
552 | button:Hide() |
||
553 | end |
||
554 | end |
||
555 | |||
556 | menu:Show() |
||
557 | end |
||
558 | |||
559 | -- Functions for the Event Editor |
||
560 | |||
561 | function FB_DisplayEventEditor() |
||
562 | -- Load event list into Event editor |
||
563 | if FBEvents.n < 11 then FBEventEditorFrame.FirstEvent = 1 end |
||
564 | if FBEventEditorFrame.FirstEvent > 1 and |
||
565 | FBEventEditorFrame.FirstEvent + 9 > FBEvents.n then |
||
566 | FBEventEditorFrame.FirstEvent = FBEvents.n - 9 |
||
567 | end |
||
568 | if FBEventEditorFrame.FirstEvent < 1 then FBEventEditorFrame.FirstEvent = 1 end |
||
569 | |||
570 | local index |
||
571 | for index = 0,9 do |
||
572 | local eventframe = getglobal("FBEventEditorFrame"..index+1) |
||
573 | local eventnum = getglobal(eventframe:GetName().."Number") |
||
574 | if FBEvents[index+FBEventEditorFrame.FirstEvent] then |
||
575 | local event = FBEvents[index+FBEventEditorFrame.FirstEvent] |
||
576 | eventnum:SetText(tostring(index+FBEventEditorFrame.FirstEvent)) |
||
577 | local eventon = getglobal(eventframe:GetName().."Event") |
||
578 | eventon:SetText(tostring(event["on"])) |
||
579 | local eventtarget = getglobal(eventframe:GetName().."Target") |
||
580 | eventtarget:SetText(string.gsub(tostring(event["targettext"]),"Target=","")) |
||
581 | local eventcommand = getglobal(eventframe:GetName().."Command") |
||
582 | eventcommand:SetText(tostring(event["command"])) |
||
583 | eventframe:Show() |
||
584 | else |
||
585 | eventframe:Hide() |
||
586 | end |
||
587 | end |
||
588 | FB_EventEditor_DisplayNewEvent() |
||
589 | FBEventEditorFrame:Show() |
||
590 | end |
||
591 | |||
592 | function FB_MoveEventDown(eventnumber) |
||
593 | -- move an event down the list |
||
594 | if eventnumber < FBEvents.n then |
||
595 | local temp = FBEvents[eventnumber+1] |
||
596 | FBEvents[eventnumber+1] = FBEvents[eventnumber] |
||
597 | FBEvents[eventnumber] = temp |
||
598 | end |
||
599 | FBSavedProfile[FBProfileName].Events = util:TableCopy(FBEvents) |
||
600 | FB_CreateQuickDispatch() |
||
601 | FB_DisplayEventEditor() |
||
602 | end |
||
603 | |||
604 | function FB_MoveEventUp(eventnumber) |
||
605 | -- move an event Up the list |
||
606 | if eventnumber > 1 then |
||
607 | local temp = FBEvents[eventnumber-1] |
||
608 | FBEvents[eventnumber-1] = FBEvents[eventnumber] |
||
609 | FBEvents[eventnumber] = temp |
||
610 | end |
||
611 | FBSavedProfile[FBProfileName].Events = util:TableCopy(FBEvents) |
||
612 | FB_CreateQuickDispatch() |
||
613 | FB_DisplayEventEditor() |
||
614 | end |
||
615 | |||
616 | function FB_DeleteEvent(eventnumber) |
||
617 | -- move an event down the list |
||
618 | table.remove(FBEvents, eventnumber) |
||
619 | FBSavedProfile[FBProfileName].Events = util:TableCopy(FBEvents) |
||
620 | FB_CreateQuickDispatch() |
||
621 | FB_DisplayEventEditor() |
||
622 | FBEventEditorFrameEventEdit:SetFocus() |
||
623 | end |
||
624 | |||
625 | function FB_InsertEvent(eventnumber) |
||
626 | -- Insert an event in the list |
||
627 | FBEventEditorFrameModeLabel:SetText("Inserting") |
||
628 | FBEventEditorFrameEventNumberLabel:SetText(tostring(eventnumber)) |
||
629 | FB_Clear_Fields() |
||
630 | FB_Hide_Parameters() |
||
631 | FBEventEditorFrameTargetMenu:Hide() |
||
632 | FBEventEditorFrameEventEdit:SetFocus() |
||
633 | end |
||
634 | |||
635 | function FB_EditEvent(eventnumber,name) |
||
636 | -- Edit an event in the list |
||
637 | local list = {"Event","Target","If","In","TName","TToggle","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"} |
||
638 | FBEventEditorFrameModeLabel:SetText("Editing") |
||
639 | FBEventEditorFrameEventNumberLabel:SetText(tostring(eventnumber)) |
||
640 | FB_Clear_Fields() |
||
641 | FB_Hide_Parameters() |
||
642 | local commandtext = getglobal(name.."Command"):GetText() |
||
643 | local target = getglobal(name.."Target"):GetText() |
||
644 | local event = getglobal(name.."Event"):GetText() |
||
645 | local firsti,lasti,command = string.find(commandtext,"(%w+) ") |
||
646 | local msg = string.sub(commandtext,lasti+1) |
||
647 | local args = FBcmd:GetParameters(msg) |
||
648 | args["target"] = FBEvents[eventnumber]["target"] |
||
649 | FBEventEditorFrameEventEdit:SetText("'"..string.lower(event).."'") |
||
650 | FBEventEditorFrameCommandEdit:SetText(string.lower(command)) |
||
651 | FB_Set_Parameters(command) |
||
652 | local index,value |
||
653 | local i,v |
||
654 | for i,v in ipairs(list) do |
||
655 | local label = getglobal("FBEventEditorFrame"..v.."Label"):GetText() |
||
656 | if string.sub(label,-1,-1) == "=" then label = string.sub(label,1,-2) end |
||
657 | if string.sub(label,1,1) == "[" then label = string.sub(label,2,-2) end |
||
658 | if args[string.lower(label)] then |
||
659 | if type(args[string.lower(label)]) == "string" then |
||
660 | getglobal("FBEventEditorFrame"..v.."Edit"):SetText("'"..args[string.lower(label)].."'") |
||
661 | elseif type(args[string.lower(label)]) == "number" then |
||
662 | getglobal("FBEventEditorFrame"..v.."Edit"):SetText(args[string.lower(label)]) |
||
663 | elseif type(args[string.lower(label)]) == "table" then |
||
664 | local i2, v2 |
||
665 | local text = "[" |
||
666 | for i2,v2 in args[string.lower(label)] do |
||
667 | if type(v2) == "string" then |
||
668 | text = text .. "'"..v2.."' " |
||
669 | else |
||
670 | text = text .. tostring(v2) .. " " |
||
671 | end |
||
672 | end |
||
673 | text = text .. "]" |
||
674 | getglobal("FBEventEditorFrame"..v.."Edit"):SetText(text) |
||
675 | end |
||
676 | |||
677 | getglobal("FBEventEditorFrame"..v.."Label"):Show() |
||
678 | getglobal("FBEventEditorFrame"..v.."Edit"):Show() |
||
679 | if getglobal("FBEventEditorFrame"..v.."Menu") then getglobal("FBEventEditorFrame"..v.."Menu"):Show() end |
||
680 | end |
||
681 | end |
||
682 | if IsShiftKeyDown() then |
||
683 | FB_EventEditor_DisplayNewEvent(true) |
||
684 | FBEventEditorFrameModeLabel:SetText("Inserting") |
||
685 | else |
||
686 | FBEventEditorFrameP1Edit:SetFocus() |
||
687 | FBEventEditorFrameTargetMenu:Show() |
||
688 | end |
||
689 | end |
||
690 | |||
691 | local fieldlist = {"Event","Target","If","Command","In","TName","TToggle","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"} |
||
692 | function FB_EventEditor_MenuDropDown(name) |
||
693 | -- drop menu down for named dropdown button |
||
694 | if FBEEDDMenu:IsVisible() then |
||
695 | FBEEDDMenu:Hide() |
||
696 | FBIfOpsMenu:Hide() |
||
697 | return |
||
698 | end |
||
699 | |||
700 | local label = string.gsub(name,"Menu","Label") |
||
701 | local editbox = getglobal(string.gsub(name,"Menu","Edit")) |
||
702 | local labeltext = string.lower(getglobal(label):GetText()) |
||
703 | if string.sub(labeltext,-1,-1) == "=" then labeltext = string.sub(labeltext,1,-2) end |
||
704 | if string.sub(labeltext,1,1) == "[" then labeltext = string.sub(labeltext,2,-2) end |
||
705 | FBEventEditorFrame.CurrentEdit = editbox |
||
706 | FB_Menu_Display("FBEEDDMenu",FBGUIParamValues[labeltext](), |
||
707 | FBGUIParamCallbacks[labeltext], |
||
708 | FBToggles["dropdown"],200,name,"TOPRIGHT","BOTTOMRIGHT",0,0) |
||
709 | if labeltext == "if" then |
||
710 | FB_Menu_Display("FBIfOpsMenu",FBGUIParamValues[labeltext.."ops"](), |
||
711 | FBGUIParamCallbacks[labeltext], |
||
712 | FBToggles["dropdown"],50,name,"TOPRIGHT","BOTTOMRIGHT",-200,0) |
||
713 | end |
||
714 | local index,field |
||
715 | for index, field in ipairs(fieldlist) do |
||
716 | getglobal("FBEventEditorFrame"..field.."Edit"):ClearFocus() |
||
717 | end |
||
718 | end |
||
719 | |||
720 | function FB_EventEditor_NextEditBox(name) |
||
721 | -- find the next edit box to go to. |
||
722 | local index, value |
||
723 | local found = false |
||
724 | for index,value in ipairs(fieldlist) do |
||
725 | if found and getglobal("FBEventEditorFrame"..value.."Label"):IsVisible() then |
||
726 | getglobal("FBEventEditorFrame"..value.."Edit"):SetFocus() |
||
727 | return |
||
728 | end |
||
729 | if string.find(string.sub(name,19),value.."Edit") then |
||
730 | found = true |
||
731 | if value == "Command" and FBEventEditorFrameCommandEdit:GetText() then |
||
732 | FB_Set_Parameters(string.lower(FBEventEditorFrameCommandEdit:GetText())) |
||
733 | elseif value == "Event" and FBEventEditorFrameEventEdit:GetText() then |
||
734 | FBEventEditorFrameTargetMenu:Show() |
||
735 | end |
||
736 | end |
||
737 | end |
||
738 | getglobal("FBEventEditorFrameEventEdit"):SetFocus() |
||
739 | end |
||
740 | |||
741 | function FB_EventEditor_DisplayNewEvent(fromedit) |
||
742 | -- Set up for adding a new event |
||
743 | if not FBEvents.n then FBEvents.n = 0 end |
||
744 | local nextevent = FBEvents.n + 1 |
||
745 | FBEventEditorFrameEventNumberLabel:SetText(tostring(nextevent)) |
||
746 | if not fromedit then |
||
747 | FB_Clear_Fields() |
||
748 | FB_Hide_Parameters() |
||
749 | FBEventEditorFrameTargetMenu:Hide() |
||
750 | end |
||
751 | FBEventEditorFrameEventEdit:SetFocus() |
||
752 | FBEventEditorFrameModeLabel:SetText("Adding") |
||
753 | end |
||
754 | |||
755 | function FB_Hide_Parameters() |
||
756 | -- hide the parameter list until it is populated |
||
757 | local index |
||
758 | for index = 1,10 do |
||
759 | getglobal("FBEventEditorFrameP"..index.."Label"):Hide() |
||
760 | getglobal("FBEventEditorFrameP"..index.."Edit"):Hide() |
||
761 | getglobal("FBEventEditorFrameP"..index.."Menu"):Hide() |
||
762 | end |
||
763 | end |
||
764 | |||
765 | function FB_Clear_Fields() |
||
766 | -- clear all fields of values |
||
767 | local list = {"Event","Target","If","In","TName","TToggle","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"} |
||
768 | local index, value |
||
769 | for index,value in ipairs(list) do |
||
770 | getglobal("FBEventEditorFrame"..value.."Edit"):SetText("") |
||
771 | end |
||
772 | FBEventEditorFrameCommandEdit:SetText("") |
||
773 | end |
||
774 | |||
775 | function FB_Set_Parameters(value) |
||
776 | -- Set up the parameters for the given command |
||
777 | FB_Hide_Parameters() |
||
778 | local command,param,index |
||
779 | for index,param in ipairs(FBGUIParamList[value]) do |
||
780 | getglobal("FBEventEditorFrameP"..index.."Label"):Show() |
||
781 | getglobal("FBEventEditorFrameP"..index.."Label"):SetText(param) |
||
782 | getglobal("FBEventEditorFrameP"..index.."Edit"):Show() |
||
783 | getglobal("FBEventEditorFrameP"..index.."Edit"):SetText("") |
||
784 | getglobal("FBEventEditorFrameP"..index.."Menu"):Show() |
||
785 | end |
||
786 | end |
||
787 | |||
788 | function FB_EventEditor_SaveEvent() |
||
789 | -- Create an event command from the current fields |
||
790 | local list = {"Event","Target","If","In","TName","TToggle","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"} |
||
791 | local ef = FBEventEditorFrame:GetName() |
||
792 | local command = getglobal(ef.."CommandEdit"):GetText() .. " " |
||
793 | local value, index |
||
794 | for index,value in pairs(list) do |
||
795 | local label = getglobal(ef..value.."Label"):GetText() |
||
796 | local edit = getglobal(ef..value.."Edit"):GetText() |
||
797 | if getglobal(ef..value.."Label"):IsVisible() and label and label ~="" then |
||
798 | if string.sub(label,1,1) == "[" then label = string.sub(label,2,-2) end |
||
799 | if string.sub(label,-1,-1) ~= "=" then label = label.."=" end |
||
800 | command = command .. label .. edit .. " " |
||
801 | end |
||
802 | end |
||
803 | FBcmd:Dispatch(command) |
||
804 | local eventnum = tonumber(getglobal(ef.."EventNumberLabel"):GetText()) |
||
805 | local mode = getglobal(ef.."ModeLabel"):GetText() |
||
806 | if mode == "Editing" then |
||
807 | FBEvents[eventnum] = FBEvents[FBEvents.n] |
||
808 | table.remove(FBEvents, FBEvents.n) |
||
809 | elseif mode == "Inserting" then |
||
810 | table.insert(FBEvents,eventnum,FBEvents[FBEvents.n]) |
||
811 | table.remove(FBEvents, FBEvents.n) |
||
812 | end |
||
813 | FBSavedProfile[FBProfileName].Events = util:TableCopy(FBEvents) |
||
814 | FB_CreateQuickDispatch() |
||
815 | getglobal(ef.."ModeLabel"):SetText("Adding") |
||
816 | FB_EventEditor_DisplayNewEvent() |
||
817 | FB_DisplayEventEditor() |
||
818 | end |
||
819 | |||
820 | function FB_GetItems() |
||
821 | -- Generate a list of items in ID slots |
||
822 | local index |
||
823 | local autoitemlist = {} |
||
824 | FB_MoneyToggle(); |
||
825 | for index = 1,120 do |
||
826 | local count = GetActionCount(index) |
||
827 | if count and count > 0 then |
||
828 | FlexBarTooltip:SetAction(index) |
||
829 | local name = FlexBarTooltipTextLeft1:GetText() |
||
830 | table.insert(autoitemlist,{index,name,count}) |
||
831 | elseif FBSavedProfile[FBProfileName].FlexActions[index] and |
||
832 | FBSavedProfile[FBProfileName].FlexActions[index]["action"] == "autoitem" then |
||
833 | table.insert(autoitemlist,{index, |
||
834 | FBSavedProfile[FBProfileName].FlexActions[index]["name"], |
||
835 | |||
836 | end |
||
837 | end |
||
838 | FB_MoneyToggle(); |
||
839 | autoitemlist.n = 0 |
||
840 | for index in ipairs(autoitemlist) do |
||
841 | autoitemlist.n = index |
||
842 | end |
||
843 | return autoitemlist |
||
844 | end |
||
845 | |||
846 | function FB_DisplayAutoItems() |
||
847 | -- display current items in frame |
||
848 | |||
849 | if not FBAutoItemsFrame.FirstItem then FBAutoItemsFrame.FirstItem = 1 end |
||
850 | local items = FB_GetItems() |
||
851 | if FBAutoItemsFrame.FirstItem + 4 > items.n then FBAutoItemsFrame.FirstItem = items.n - 4 end |
||
852 | if FBAutoItemsFrame.FirstItem < 1 then FBAutoItemsFrame.FirstItem = 1 end |
||
853 | local first = FBAutoItemsFrame.FirstItem |
||
854 | |||
855 | local index |
||
856 | for index = 1,5 do |
||
857 | local pos = index+first-1 |
||
858 | if items[pos] then |
||
859 | local checkbox = getglobal("FBAutoItemsFrame"..index.."On") |
||
860 | local label = getglobal("FBAutoItemsFrame"..index.."Label") |
||
861 | local idlabel = getglobal("FBAutoItemsFrame"..index.."IDLabel") |
||
862 | local countlabel = getglobal("FBAutoItemsFrame"..index.."CountLabel") |
||
863 | if FBSavedProfile[FBProfileName].FlexActions[items[pos][1]] and |
||
864 | FBSavedProfile[FBProfileName].FlexActions[items[pos][1]]["action"] == "autoitem" then |
||
865 | checkbox:SetChecked(1) |
||
866 | else |
||
867 | checkbox:SetChecked(0) |
||
868 | end |
||
869 | label:SetText(items[pos][2]) |
||
870 | countlabel:SetText(items[pos][3]) |
||
871 | idlabel:SetText(items[pos][1]) |
||
872 | getglobal("FBAutoItemsFrame"..index):Show() |
||
873 | else |
||
874 | getglobal("FBAutoItemsFrame"..index):Hide() |
||
875 | end |
||
876 | end |
||
877 | FBAutoItemsFrame:Show() |
||
878 | end |
||
879 | |||
880 | function FB_AutoItemOnClick(number,checkbox,parent) |
||
881 | -- Toggle auto item |
||
882 | local first = FBAutoItemsFrame.FirstItem or 1 |
||
883 | local pos = number+first-1 |
||
884 | if checkbox:GetChecked() then |
||
885 | local name = getglobal(parent:GetName().."Label"):GetText() |
||
886 | local idlabel = getglobal(parent:GetName().."IDLabel"):GetText() |
||
887 | local id = tonumber(idlabel) |
||
888 | local countlabel = getglobal(parent:GetName().."CountLabel"):GetText() |
||
889 | local count = tonumber(countlabel) |
||
890 | if not FBSavedProfile[FBProfileName].FlexActions[id] then |
||
891 | FBSavedProfile[FBProfileName].FlexActions[id] = {} |
||
892 | end |
||
893 | FBSavedProfile[FBProfileName].FlexActions[id]["action"] = "autoitem" |
||
894 | FBSavedProfile[FBProfileName].FlexActions[id]["name"] = name |
||
895 | FBSavedProfile[FBProfileName].FlexActions[id]["count"] = count |
||
896 | FBSavedProfile[FBProfileName].FlexActions[id]["texture"] = GetActionTexture(id) |
||
897 | else |
||
898 | local idlabel = getglobal(parent:GetName().."IDLabel"):GetText() |
||
899 | local id = tonumber(idlabel) |
||
900 | FBSavedProfile[FBProfileName].FlexActions[id] = nil |
||
901 | local buttonnum |
||
902 | for buttonnum = 1,FBNumButtons do |
||
903 | local button = FB_GetWidgets(buttonnum) |
||
904 | if button:GetID() == id then |
||
905 | FlexBarButton_Update(button) |
||
906 | FlexBarButton_UpdateUsable(button) |
||
907 | end |
||
908 | end |
||
909 | FB_DisplayAutoItems() |
||
910 | end |
||
911 | local id = tonumber(idlabel) |
||
912 | local index |
||
913 | for index = 1,120 do |
||
914 | local button = FB_GetWidgets(index) |
||
915 | if button:GetID() == id then |
||
916 | local profile = FBSavedProfile[FBProfileName] |
||
917 | local action = profile.FlexActions[id] |
||
918 | local state = profile[index].State |
||
919 | if action then |
||
920 | state["savedgrid"] = state["hidegrid"] |
||
921 | state["hidegrid"] = nil |
||
922 | else |
||
923 | state["hidegrid"] = state["savedgrid"] |
||
924 | state["savedgrid"] = nil |
||
925 | end |
||
926 | FBState[index]["savedgrid"] = state["savedgrid"] |
||
927 | FBState[index]["hidegrid"] = state["hidegrid"] |
||
928 | FB_ApplyGrid(index) |
||
929 | FlexBarButton_Update(button) |
||
930 | FlexBarButton_UpdateUsable(button) |
||
931 | end |
||
932 | end |
||
933 | |||
934 | end |