I'm working on a simple add-on that will allow the user to toggle a "reminder" icon based on a user defined shortcut key combo. I've got the xml down but I have no lua experience (lots of java though) and I want to run it by some vets for help... My main confusion is reading in the user shortcut key in the text box (would this be better as a keybinding and if so how do I do that?) and then checking during play for that key combo (can this be done during combat?). And no I haven't had a chance to test it yet for errors (yes, bad form), but I thought it couldn't hurt to get it checked out to see if I was on the right track.
Code:
debug = 0;
function TMOptions_OnLoad()
if (debug == 1) then DEFAULT_CHAT_FRAME:AddMessage("On load Message"); end
if not SlashCmdList["TODDMODD"] then
SlashCmdList["TODDMODD"] = Toddmodd_slash;
SLASH_TODDMODD = "/toddmodd";
SLASH_TODDMODD2 = "/tm";
end
this:RegisterEvent("VARIABLES_LOADED");
end
function TMOptions_OnEvent(event)
if (debug == 1) then DEFAULT_CHAT_FRAME:AddMessage("EVENT --- loaded"); end
if (event == "VARIABLES_LOADED") then
if not TM_SETTINGS then TM_SETTINGS = {}; end
if not TM_SETTINGS['Shortcut'] then TM_SETTINGS['Shortcut'] = ""; end
if (debug == 1) then
DEFAULT_CHAT_FRAME:AddMessage("Shortcut: "..TM_SETTINGS['Shortcut']);
end
end
end
function Toddmodd_slash(msg)
local cmd = string.lower(msg);
if(cmd == nil) then cmd = ""; end
if(debug == 1) then
DEFAULT_CHAT_FRAME:AddMessage("Slash command setting: "..cmd);
end
end
-- Called from the XML ShortcutKey Input Box
function $parentShortcutKey_OnTextChanged(this)
local self = this.obj
local buttontext
buttontext = self:GetText();
TM_SETTINGS['Shortcut'] = buttontext;
if(debug == 1) then
DEFAULT_CHAT_FRAME:AddMessage("Text changed to: "..buttontext);
end
end
--Set in Bindings.xml
function SCButton_Key(button)
if(button == TM_SETTINGS['Shortcut'].value) then
tmIconFrame:Toggle();
end
end
--Used by SCButton_Key()
function tmIconFrame:Toggle()
if not tmIconFrame:IsVisible() then
self:Show();
else
self:Hide();
end
end