Hello all!
I'm about 3 hours in to my first attempt at creating (err, finding one and building on to it) an addon. I found an addon that I thought was a good start, but lacked a lot of what I desired, so why not learn LUA and write my own eh?
What I've had a tough time doing is creating a toggle effect when using slash commands + Msg.
As you can see in the code, if Msg == "on" then I CreateFrame. If Msg == "off", essentially I would like to just undo the CreateFrame that I just created. I can't figure out how to do this without just applying a ReloadUI (as you see commented out), which, while effective, rather annoying.
Any help would be much appreciated!
Lua Code:
--Tribute to Kip who's code I copied and altered... Consider this Kudos for your 'Bootstrap'
--define global vars (saved between sessions)
Enabled = true
--define local module vars and defaults
local AddonVersion = GetAddOnMetadata("RyinnsCursorFinder", "Version")
local function print(msg)
DEFAULT_CHAT_FRAME:AddMessage("RyinnsCursorFinder: " .. tostring(msg))
end
function Ryinn_Command(Msg,Editbox)
if Msg then Msg=strlower(Msg); end
if Msg == "help" then
print("v"..AddonVersion)
print("Use /rcf + on/off to Enable/Disable")
print("Example: /rcf on")
elseif Msg == "on" then
local frame = CreateFrame("Frame", nil, UIParent);
frame:SetFrameStrata("TOOLTIP");
local texture = frame:CreateTexture();
texture:SetTexture([[Interface\Cooldown\ping4]]);
texture:SetBlendMode("ADD");
texture:SetAlpha(0.5);
local x = 0;
local y = 0;
local speed = 0;
local function OnUpdate(_, elapsed)
local dX = x;
local dY = y;
x, y = GetCursorPosition();
dX = x - dX;
dY = y - dY;
local weight = 2048 ^ -elapsed;
speed = math.min(weight * speed + (1 - weight) * math.sqrt(dX * dX + dY * dY) / elapsed, 768);
local size = speed / 6 - 16;
if (size > 0) then
local scale = UIParent:GetEffectiveScale();
texture:SetHeight(size);
texture:SetWidth(size);
texture:SetPoint("CENTER", UIParent, "BOTTOMLEFT", (x + 0.5 * dX) / scale, (y + 0.5 * dY) / scale);
texture:Show();
else
texture:Hide();
end
end
frame:SetScript("OnUpdate", OnUpdate);
print("Ryinn's Flash Cursor is Now Enabled. Use /ryn off to disable")
elseif Msg == "off" then
Frame1:SetScript("OnShow",nil);
--StaticPopup_Show("ReloadPop")
print("test")
else
Ryinn_Command("help")
end
end
--Create an anonymous blank frame
local Ryinn = CreateFrame("Frame")
Ryinn:RegisterEvent("PLAYER_REGEN_ENABLED")
Ryinn:RegisterEvent("PLAYER_REGEN_DISABLED")
Ryinn:SetScript("OnEvent", Ryinn_OnEvent)
--setup slash command feature
SlashCmdList["Ryinn"]=Ryinn_Command
SLASH_Ryinn1="/rcf",
Ryinn_Command("help")
--Setup our Pop Up Warning for Reload UI
--StaticPopupDialogs["ReloadPop"] = {
--text = "In order to remove the cursor texture, you need to reload your UI. Is that okay?",
--button1 = "Yes",
--button2 = "No",
--OnAccept = function() ReloadUI() end,
--timeout = 0,
--sound = "RaidWarning",
--whileDead = true,
--hideOnEscape = true,
--preferredIndex = 3, -- avoid some UI taint, see [url]http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/[/url]
--}