WoWInterface SVN TitanPanelBankItems

[/] [trunk/] [TitanBankItems/] [TitanBankItems.lua] - Rev 4

Compare with Previous | Blame | View Log

--[[
        Name:           Titan BankItems
        Description:    Titan Panel plugin for BankItems
        Author:         Kernighan
        Version:        2.0.7
--]]


-- To save memory
if (not TITAN_MONEY_FORMAT) then
        TITAN_MONEY_FORMAT = "%dg, %ds, %dc";
end

TITAN_BANKITEMS_ID = "BankItems";
TITAN_BANKITEMS_VERSION = "2.0.7";
TITAN_BANKITEMS_TOOLTIP_HINTS_1         = "Hint: Click to toggle BankItems display.";
TITAN_BANKITEMS_TOOLTIP_HEADERS_1       = "Characters - Slots\t"..TitanUtils_GetGreenText("Money");
TITAN_BANKITEMS_TOOLTIP_FORMAT          = "%s - "..TitanUtils_GetHighlightText("%d/%d").."\t"..TitanUtils_GetHighlightText(TITAN_MONEY_FORMAT.."\n");

TITAN_BANKITEMS_SHOWHIDEWINDOW_TEXT     = "Show/Hide BankItems window";
TITAN_BANKITEMS_SHOWHIDEWINDOW_HELPTEXT = "Show/Hide the BankItems window";
TITAN_BANKITEMS_SHOWMINIMAP_TEXT        = "Show Minimap Button";
TITAN_BANKITEMS_SHOWMINIMAP_HELPTEXT    = "Show the BankItems Minimap Button";
TITAN_BANKITEMS_PURGE_TEXT              = "Purge";
TITAN_BANKITEMS_PURGE_HELPTEXT          = "Delete stored data of...";

function TitanPanelBankItemsButton_OnLoad(self)
        if not TitanPanelButton_UpdateButton then
                return;
        end
        self.registry = {
                id = TITAN_BANKITEMS_ID,
                menuText = "BankItems",
                version = TITAN_BANKITEMS_VERSION,
                category = "Information",
                icon = "Interface\\AddOns\\TitanBankItems\\Icons\\bag_blue",
                iconWidth = 16,
                tooltipTitle = "BankItems",
                tooltipTextFunction = "TitanPanelBankItemsButton_GetTooltipText",
        };
        tinsert(TITAN_PANEL_NONMOVABLE_PLUGINS, TITAN_BANKITEMS_ID);
end

function TitanPanelBankItemsButton_OnClick(self, button)
        if (button == "LeftButton") then
                BankItems_SlashHandler();
        end
end
TitanPanelBankItemsButton_OnEvent = function(self, event, ...)
   if TitanPanelButton_UpdateButton then
      TitanPanelButton_UpdateButton(TITAN_BANKITEMS_ID);        
      TitanPanelButton_UpdateTooltip();
   end
end

function TitanPanelBankItemsButton_GetTooltipText()
        local text = "";
        local total = 0;
        local gspace = 0;
        local gtotspace = 0;
        local realm = "|"..strtrim(GetCVar("realmName"));

        text = text..TitanUtils_GetGreenText(TITAN_BANKITEMS_TOOLTIP_HEADERS_1.."\n");

        for key, value in pairs(BankItems_Save) do
                if (type(value) == "table") then
                        if (string.find(key, realm) and value.money and type(value.money) == "number") then
                                local space = 0;
                                local totspace = 28;

                                for num = 1, 28 do
                                        if ( value[num] and value[num].link ) then
                                                space = space + 1;
                                        end
                                end
                                for bagNum = 0, 11 do
                                        if ( value["Bag"..bagNum] and value["Bag"..bagNum].size > 0 ) then
                                                totspace = totspace + value["Bag"..bagNum].size;
                                                for bagItem = 1, value["Bag"..bagNum].size do
                                                        if ( value["Bag"..bagNum][bagItem] and value["Bag"..bagNum][bagItem].link ) then
                                                                space = space + 1;
                                                        end
                                                end
                                        end
                                end
                                if ( not value["Bag0"] ) then
                                        totspace = totspace + GetContainerNumSlots(0);
                                end

                                text = text..string.format(TITAN_BANKITEMS_TOOLTIP_FORMAT, string.gsub(key, realm, ""), space, totspace, TitanPanelMoneyButton_BreakMoney(value.money));

                                total = total + value.money;
                                gspace = gspace + space;
                                gtotspace = gtotspace + totspace;
                        end
                end
        end

        text = text.."\n";
        text = text..string.format(TITAN_BANKITEMS_TOOLTIP_FORMAT, "Total", gspace, gtotspace, TitanPanelMoneyButton_BreakMoney(total));

        text = text..TitanUtils_GetGreenText(TITAN_BANKITEMS_TOOLTIP_HINTS_1);

        return text;
end

-- The tooltips in this menu only displays if the player has "Show Detailed Tooltips" turned on in the Interface Options.
function TitanPanelRightClickMenu_PrepareBankItemsMenu(self)
        local info;

        if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then
                if (self.value == "purge") then
                        local realm = "|"..strtrim(GetCVar("realmName"));
                        local cname;

                        for key, value in pairs(BankItems_Save) do
                                if (type(value) == "table") then
                                        cname = string.gsub(key, realm, "");
                                        if (string.find(key, realm)) then
                                                info = {};
                                                info.text = cname;
                                                info.arg1 = cname;
                                                info.tooltipTitle = TITAN_BANKITEMS_PURGE_TEXT;
                                                info.tooltipText = "... "..cname;
                                                info.func = TitanPanelBankItems_DelPlayer;
                                                if (cname == UnitName("player")) then
                                                        info.disabled = true;
                                                end
                                                UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                                        end
                                end
                        end

                end
        else
                TitanPanelRightClickMenu_AddTitle("BankItems");
        
                info = {};
                info.text = TITAN_BANKITEMS_SHOWHIDEWINDOW_TEXT;
                info.func = BankItems_SlashHandler;
                info.tooltipTitle = TITAN_BANKITEMS_SHOWHIDEWINDOW_TEXT;
                info.tooltipText = TITAN_BANKITEMS_SHOWHIDEWINDOW_HELPTEXT;
                UIDropDownMenu_AddButton(info);

                info = {};
                info.text = TITAN_BANKITEMS_SHOWMINIMAP_TEXT;
                info.func = BankItems_MinimapButton_Toggle;
                info.checked = BankItems_Save.ButtonShown;
                info.tooltipTitle = TITAN_BANKITEMS_SHOWMINIMAP_TEXT;
                info.tooltipText = TITAN_BANKITEMS_SHOWMINIMAP_HELPTEXT;
                UIDropDownMenu_AddButton(info);

                TitanPanelRightClickMenu_AddSpacer();

                info = {};
                info.text = TITAN_BANKITEMS_PURGE_TEXT;
                info.hasArrow = 1;
                info.value = "purge";
                info.tooltipTitle = TITAN_BANKITEMS_PURGE_TEXT;
                info.tooltipText = TITAN_BANKITEMS_PURGE_HELPTEXT;
                UIDropDownMenu_AddButton(info);

                TitanPanelRightClickMenu_AddSpacer();
                TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_BANKITEMS_ID, TITAN_PANEL_MENU_FUNC_HIDE);
        end
end

function TitanPanelBankItems_DelPlayer(name)
        BankItems_DelPlayer(name.."|"..strtrim(GetCVar("realmName")));
        BankItems_Chat("Data of '"..name.." of "..strtrim(GetCVar("realmName")).."' deleted");
        BankItems_Frame:Hide();
end;

-- To save memory
if (not TitanPanelMoneyButton_BreakMoney) then
        function TitanPanelMoneyButton_BreakMoney(money)
                -- Non-negative money only
                if (money >= 0) then
                        local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
                        local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
                        local copper = mod(money, COPPER_PER_SILVER);
                        return gold, silver, copper;
                end
        end
end

Compare with Previous | Blame