Hi im having truble with this code for some resone the addon just keeps growing by 10kb a sec when its running in wow and i just cant work out why???
i was wondering if some one could please have a look and let me know thank you.
Code:
local SortColumn = 1;
local SortReverse;
local NextUpdate = 0;
local AddOnList = {};
--620 total
local Columns = {
{Name = "Name", Width = 325},
{Name = "Enabled", Width = 100},
{Name = "Loaded", Width = 100},
{Name = "Memory", Width = 80, Right = true, Format = function(Input)
if(Input >= 1024)then
return format("%.2f MB", Input / 1024);
end
return format("%.0f KB", Input);
end},
};
StaticPopupDialogs["AddonDB_RELOADUI"] = {
text = "The UI must be reloaded for the change to take effect. Do you want to reload the UI now?",
button1 = "Reload UI",
button2 = "Not Now",
OnAccept = function()
AddonDBConfig.Show = true;
ReloadUI();
end,
timeout = 0,
exclusive = 1,
hideOnEscape = 1
};
function AddonDB_OnLoad(self)
tinsert(UISpecialFrames, self:GetName());
SlashCmdList["AddonDB"] = function()
AddonDBFrame:Show();
end
SLASH_AddonDB1 = "/AddonDB";
SLASH_AddonDBMenuName = "Addon Data Base";
self:RegisterForDrag("LeftButton");
self:RegisterEvent("VARIABLES_LOADED");
self:RegisterEvent("PLAYER_LOGIN");
local ScrollBox = AddonDBScrollBox;
local Left = 10;
local Button, Text;
for Key, Value in ipairs(Columns)do
Button = CreateFrame("Button",self:GetName().."Col"..Key, self);
Button:SetID(Key);
Value.Header = Button;
Value.Left = Left;
Button:SetWidth(Value.Width);
Button:SetHeight(16);
Button:SetScript("OnClick", AddonDBColumn_OnClick);
Button:SetPoint("BOTTOMLEFT", ScrollBox, "TOPLEFT", Left, 0);
Text = Button:CreateFontString(Button:GetName().."Text", "ARTWORK", "GameFontNormal");
Text:SetText(Value.Name);
Text:SetPoint("LEFT", 10, 0);
Left = Left + Value.Width;
end
ScrollBox.Entries = 20;
local Entry;
for Index = 1, ScrollBox.Entries do
Entry = CreateFrame("Button",ScrollBox:GetName().."Entry"..Index,ScrollBox);
Entry:SetHeight(16);
Entry:SetPoint("LEFT", 10, 0);
Entry:SetPoint("RIGHT", -10, 0);
Entry:SetPoint("TOP", 0, -10 - (Index - 1) * 16);
for Key, Value in ipairs(Columns)do
Text = Entry:CreateFontString(Entry:GetName().."Text"..Key, "ARTWORK", "GameFontHighlight");
Text:SetPoint("TOP");
Text:SetPoint("LEFT", Value.Header);
Text:SetPoint("RIGHT", Value.Header);
Text:SetJustifyH(Value.Right and "RIGHT" or "LEFT");
end
Entry:RegisterForClicks("RightButtonUp");
Entry:SetScript("OnClick", AddonDBEntry_OnClick);
Entry:SetScript("OnEnter", AddonDBEntry_OnEnter);
Entry:SetScript("OnLeave", AddonDBEntry_OnLeave);
Entry:Hide();
end
DEFAULT_CHAT_FRAME:AddMessage("Addon Data Base: AddOn loaded. Use /AddonDB for addon info.");
end
function AddonDB_OnEvent()
if(event=="VARIABLES_LOADED")then
if not AddonDBConfig then
AddonDBConfig = {};
end
end
end
function AddonDB_OnUpdate()
if(GetTime() > NextUpdate)then
AddonDBUpdateList();
end
end
function AddonDBLoadFrame_OnUpdate(self)
self:Hide();
if AddonDBConfig.Show then
AddonDBConfig.Show = nil;
AddonDBFrame:Show();
end
end
function AddonDB_OnShow(self)
self:ClearAllPoints();
self:SetPoint("CENTER");
PlaySound("gsTitleOptionOK");
end
function AddonDB_OnHide()
PlaySound("gsTitleOptionExit");
end
function AddonDB_OnDragStart(self)
self:StartMoving();
end
function AddonDB_OnDragStop(self)
self:StopMovingOrSizing();
self:SetUserPlaced(false);
end
function AddonDBColumn_OnClick(self)
PlaySound("igMainMenuOptionCheckBoxOn");
if(self:GetID()==SortColumn)then
SortReverse = not SortReverse;
else
SortColumn = self:GetID();
SortReverse = nil;
end
AddonDBSortList();
end
function AddonDBEntry_OnClick(self)
ToggleDropDownMenu(1, self:GetID(), AddonDBDropDown, "cursor");
end
function AddonDBEntry_OnEnter(self)
local Name, Title, Notes, Enabled, Loadable, Reason, Security = GetAddOnInfo(AddOnList[self:GetID()].Name);
GameTooltip:SetOwner(self,"ANCHOR_CURSOR");
GameTooltip:AddLine(Title);
GameTooltip:AddLine(Notes,1,1,1,1);
local Author, Version = GetAddOnMetadata(Name, "Author"), GetAddOnMetadata(Name, "Version");
if Author then
GameTooltip:AddLine("Author: "..Author,1,1,1);
end
if Version then
GameTooltip:AddLine("Version: "..Version,1,1,1);
end
GameTooltip:AddLine("Enabled: |cff"..(Enabled and "19ff19Yes" or "ff1919No"),1,1,1);
local Loaded = IsAddOnLoaded(Name);
GameTooltip:AddLine("Loaded: |cff"..(Loaded and "19ff19Yes" or "ff1919No"),1,1,1);
if not Loaded then
if Reason then
Reason = strsub(Reason,1,1)..strlower(strsub(Reason,2));
Reason = string.gsub(Reason,"_(%a)", function(a)return (" "..strupper(a));end);
GameTooltip:AddLine("Loadable: |cffff1919No|r ("..Reason..")",1,1,1);
else
GameTooltip:AddLine("Loadable: |cff19ff19Yes",1,1,1);
end
end
GameTooltip:Show();
end
function AddonDBEntry_OnLeave()
GameTooltip:Hide();
end
function AddonDBEnabled_OnClick(self)
if self:GetChecked()then
PlaySound("igMainMenuOptionCheckBoxOff");
else
PlaySound("igMainMenuOptionCheckBoxOn");
end
SetCVar("scriptProfile", self:GetChecked()and "1" or "0");
StaticPopup_Show("AddonDB_RELOADUI");
end
function AddonDBUpdateList()
NextUpdate = GetTime() + 1;
UpdateAddOnMemoryUsage();
local Name, Title, Notes, Enabled, Loadable, Reason, Security;
local Data;
for Index = 1, GetNumAddOns()do
Name, Title, Notes, Enabled, Loadable, Reason, Security = GetAddOnInfo(Index);
Data = {Title, (Enabled and "Enabled" or "Disabled"), Name = Name};
tinsert(Data, (IsAddOnLoaded(Name)and "Loaded" or "Not Loaded"));
tinsert(Data, GetAddOnMemoryUsage(Index));
AddOnList[Index] = Data;
end
AddonDBSortList();
end
function AddonDBSortList()
AddonDBArrow:ClearAllPoints();
AddonDBArrow:SetPoint("LEFT",getglobal(Columns[SortColumn].Header:GetName().."Text"), "RIGHT");
if SortReverse then
AddonDBArrow:SetTexCoord(0, 0.5625, 1.0, 0);
table.sort(AddOnList, function(a, b)
return (a[SortColumn] > b[SortColumn]);
end);
else
AddonDBArrow:SetTexCoord(0, 0.5625, 0, 1.0);
table.sort(AddOnList, function(a, b)
return (a[SortColumn] < b[SortColumn]);
end);
end
AddonDBScrollBar_Update();
end
function AddonDBScrollBar_Update()
local ScrollBar = AddonDBScrollBar;
local ScrollBox = AddonDBScrollBox;
FauxScrollFrame_Update(ScrollBar, #AddOnList, ScrollBox.Entries,16);
local Entry, Index, Text;
for Line = 1, ScrollBox.Entries do
Entry = getglobal(ScrollBox:GetName().."Entry"..Line);
Index = Line + FauxScrollFrame_GetOffset(ScrollBar);
if(Index > #AddOnList)then
Entry:Hide();
else
Entry:SetID(Index);
for Key, Value in ipairs(Columns)do
Text = getglobal(Entry:GetName().."Text"..Key);
Text:SetText(Value.Format and Value.Format(AddOnList[Index][Key])or AddOnList[Index][Key]);
end
if GameTooltip:IsOwned(Entry)then
AddonDBEntry_OnEnter(Entry);
end
Entry:Show();
end
end
end
function AddonDBDropDown_OnLoad(self)
UIDropDownMenu_Initialize(self, AddonDBDropDown_Initialize, "MENU");
end
function AddonDBDropDown_Initialize()
if not UIDROPDOWNMENU_MENU_VALUE then
return;
end
local AddOn = AddOnList[UIDROPDOWNMENU_MENU_VALUE]
local Name = AddOn.Name;
local info = UIDropDownMenu_CreateInfo();
info.notCheckable = true;
info.isTitle = true;
info.text = AddOn[1];
UIDropDownMenu_AddButton(info);
info = UIDropDownMenu_CreateInfo();
info.notCheckable = true;
info.arg1 = Name;
local _, Title, Notes, Enabled, Loadable, Reason, Security = GetAddOnInfo(Name);
info.arg2 = Enabled;
info.text = (Enabled and "Disable" or "Enable").." (For this Character)";
info.func = function(self, Name, State)
PlaySound("igMainMenuOptionCheckBoxOn");
if State then
DisableAddOn(Name);
if not IsAddOnLoaded(Name)then
return;
end
else
EnableAddOn(Name);
if select(5, GetAddOnInfo(Name))then
return;
end
end
AddonDBScrollBar_Update();
StaticPopup_Show("AddonDB_RELOADUI");
end
UIDropDownMenu_AddButton(info);
if Loadable and not IsAddOnLoaded(Name)then
info.text = "Load Now";
info.func = function(self, Name)
local _, Title, Notes, Enabled = GetAddOnInfo(Name);
DEFAULT_CHAT_FRAME:AddMessage("AddonDB: Loading "..Title.."...");
if not Enabled then
EnableAddOn(Name);
end
LoadAddOn(Name);
AddonDBScrollBar_Update();
end
UIDropDownMenu_AddButton(info);
end
end
function AddonDBMinimapButton_OnLoad(self)
self:RegisterForClicks("LeftButtonUp", "RightButtonUp");
self:RegisterForDrag("LeftButton");
self:SetFrameLevel(self:GetFrameLevel()+1);
end
function AddonDBMinimapButton_OnClick()
ToggleDropDownMenu(1, nil, AddonDBDropDown);
AddonDBFrame:Show();
end
function AddonDBMinimapButton_OnEnter(self)
if self.Dragging then
return;
end
GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT");
GameTooltip:AddLine("Addon Data Base");
GameTooltip:AddLine("View Addon information.",1,1,1);
GameTooltip:AddLine("Shift-drag to move button.",1,1,1);
GameTooltip:Show();
end
function AddonDBMinimapButton_OnLeave()
GameTooltip:Hide();
end
function AddonDBMinimapButton_OnDragStart(self)
MinimapButton_OnMouseUp(self);
if IsShiftKeyDown()then
self:SetScript("OnUpdate", AddonDBMinimapButton_OnUpdate);
self.Dragging = true;
AddonDBMinimapButton_OnLeave();
end
end
function AddonDBMinimapButton_OnDragStop(self)
if self.Dragging then
self:SetScript("OnUpdate", nil);
self:StopMovingOrSizing();
self.Dragging = nil;
self.Moving = nil;
end
end
--This script handler is only active when the button is being dragged
function AddonDBMinimapButton_OnUpdate(self)
local MapScale = Minimap:GetEffectiveScale();
local CX, CY = GetCursorPosition();
local X, Y = (Minimap:GetRight() - 70) * MapScale, (Minimap:GetTop() - 70) * MapScale;
local Dist = sqrt(math.pow(X - CX, 2) + math.pow(Y - CY, 2)) / MapScale;
local Scale = self:GetEffectiveScale();
if(Dist <= 90)and Minimap:IsVisible()then
if self.Moving then
self:StopMovingOrSizing();
self.Moving = nil;
end
local Angle = atan2(CY - Y, X - CX) - 90;
self:ClearAllPoints();
self:SetPoint("CENTER", Minimap, "TOPRIGHT", (sin(Angle) * 80 - 70) * MapScale / Scale, (cos(Angle) * 77 - 73) * MapScale / Scale);
elseif not self.Moving then
self:ClearAllPoints();
self:SetPoint("CENTER", UIParent, "BOTTOMLEFT",CX / Scale, CY / Scale);
self:StartMoving();
self.Moving = true;
end
end