⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bag_status_meters.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
--[[
-------------------
-    Madorin's    -
-Bag Status Meters-
-     v1.3.7      -
-------------------

Author: Romualdo
Original Author: Kevin "Madorin" Hassett
Last Updated: October 15, 2005

-Patch Notes-
v1.3.7 (10/15/2005)
-TOC updated to 1800
-Fixed errors with 1800
-Fixed bug with quiver
v1.3.6 (4/04/2005):
-TOC updated to 4297
-Added support for myAddOns AddOn arrangement (separate AddOn)

v1.3.5.1 (3/03/2005):
-Fixed a bug where any bag after an ammo bag or empty slot would not be checked

v1.3.5 (2/26/2005):
-TOC updated to 4216
-Added an option to hide the background and meter on the Overall Meter

v1.3.4 (2/17/2005):
-Merged all localizations
-TOC updated to 4211
-Added German Description

v1.3.3 (2/04/2005):
-Changed some variables from local to global for dependency possibilities.
-Fixed a quest reward ammo bag, "Bandolier of the Watch", to not show up as inventory.
-Put in bank bag labels.
-Set the Overall and Dropdown frame level to LOW.
-Commented Code.

v1.3.2 (1/24/2005):
-Fixed layering issues with overlay bars/labels.
-Replaced the command system with a GUI for more customizability.
   -To access GUI, just type "/bsm" with anything or nothing following it.
-Added a key binding for BSM Options Pane.
-Added a UI button for the BSM Options Pane.
-Changed binding labels to buttons that toggle corresponding bag.
-Added an option to lock the overall meter.
-Added an option to place the overall meter at a specified location.

v1.3.1 (1/8/2005):
-Added "/bsm color" to toggle colors on/off.
-Added "/bsm totals" to toggle displaying the totals.
-Added "/bsm slots" to toggle using either free or used slots for display.
-Added "/bsm title" to toggle displaying the title on the overall meter.
-Added "/bsm notify" to toggle displaying notifications.
-Fixed "Inventory Full" notification to "Backpack Full".
-Fixed overall frame obstruction.
-Added notification when settings have changed.
-Changed color function to the one contributed by Azam.
-Added a brief readme.

v1.3 (1/5/2005):
-Fixed the small bug with ammo bags counting as inventory.
-Added alternative to use only text for displaying bag status ("/bsm none").
-Added alternative to use a dropdown frame for displaying bag status ("/bsm none").
-Added "/bsm help".
-Added ability to toggle hiding of labels ("/bsm labels").
-Added saved variables.
-Added notification when a bag becomes full.
-Huge XML overhaul.

v1.2 (1/2/2005):
-Fixed a layer problem where the meters showed up over the map frame.
-Added "/bsm hide" and "/bsm show" to hide or show the overall bag meter.
-Minor tweak to the % at which the meters turn yellow.

v1.1 (1/1/2005):
-Optimization help from Vjeux.
-Fixed a bug where a bag dragged into the bag bar from a non-inventory bag would not update.
-Added the missing line of XML to make it draggable.

Special Thanks: Vjeux for v1.1 LUA and XML optimization
                Azam for contributing an improved color function
                kiki for the french localization
                SirPennt for the german localization
                SoNeX for the german description
]]


--BSM_NumSlots: global variable that holds the total number of slots per bag
BSM_NumSlots = {0, 0, 0, 0, 0};
--BSM_UsedSlots: global variable that holds the number of used slots per bag
BSM_UsedSlots = {0, 0, 0, 0, 0};
--BSM_BagFull: global variable used for displaying notifications only once
BSM_BagFull = {false, false, false, false, false};

BSM_LOADED = false;

--Variables for UI Objects
BSM_FRAME = "BSM_Frame";
BSM_DROPDOWNS = "BSM_Dropdowns";
BSM_DROPDOWNS_BARS = "BSM_DropdownsBars";
BSM_BARS = "BSM_Bars";
BSM_COODLOWNS = "BSM_Cooldowns";
BSM_BARS_LABELS = "BSM_BarLabels";
BSM_DROPDOWNS_LABELS = "BSM_DropdownLabels";
BSM_BANK = "BSM_BankBag";

--Variables for the type of slot used to keep count
BSM_SLOTS_FREE = 0;
BSM_SLOTS_TAKEN = 1;



--BSM_SavePosition:
--    Purpose - Save the position of the Overall Meter frame
--    Parameters - None
--    Returns - Nothing
function BSM_SavePosition()
    BSM_Save.dispX = this:GetLeft();
    BSM_Save.dispY = this:GetBottom();
end

--BSM_DisableAllIndividual:
--    Purpose - Hide all the individual meters components
--    Parameters - None
--    Returns - Nothing
function BSM_DisableAllIndividual()
    getglobal(BSM_BARS_LABELS):Hide();
    getglobal(BSM_BARS):Hide();
    getglobal(BSM_DROPDOWNS):Hide();
    getglobal(BSM_DROPDOWNS_LABELS):Hide();
end
--BSM_EnableAllIndividual:
--    Purpose - Show all the individual meters components that need to be
--    Parameters - None
--    Returns - Nothing
function BSM_EnableAllIndividual()
    if BSM_Save.I.bars and BSM_Save.I.overlay then
        getglobal(BSM_BARS):Show();
    end
    if BSM_Save.I.showlabels and (BSM_Save.I.bars or BSM_Save.I.labels) and BSM_Save.I.overlay then
        getglobal(BSM_BARS_LABELS):Show();
    end
    if BSM_Save.I.dropdowns then
        getglobal(BSM_DROPDOWNS):Show();
        if BSM_Save.I.showlabels then
            getglobal(BSM_DROPDOWNS_LABELS):Show();
        end
    end
end

--BSM_command:
--    Purpose - Show the Options frame for any "/bsm" command
--    Parameters - the message following "/bsm "
--    Returns - Nothing
local function BSM_command(msg)
    msg = string.lower(msg);

    if not getglobal("BSM_Options"):IsVisible() then
        getglobal("BSM_Options"):Show();
    else
        getglobal("BSM_Options"):Hide();
    end
end

--BSM_initCommands:
--    Purpose - Register the "/bsm" slash command
--    Parameters - None
--    Returns - Nothing
function BSM_initCommands()
    SlashCmdList["BSMCOMMAND"] = BSM_command;
    SLASH_BSMCOMMAND1 = "/bsm";
end

--BSM_loadVariables:
--    Purpose - Initialize the save vairiables if they don't exist and hide/show appropriate things
--    Parameters - None
--    Returns - Nothing
function BSM_loadVariables()
    --Register with myAddOns
    if(myAddOnsFrame) then
        myAddOnsList.BagStatusMeters = {name = "Bag Status Meters", 
                                        description = "Use bar/text overlays for bag status",
                                        version = BSM_VERSION, 
                                        category = MYADDONS_CATEGORY_INVENTORY, 
                                        frame = BSM_FRAME, 
                                        optionsframe = "BSM_Options"};
    end
	gLim_RegisterButton (
	"Bag_Status_Meters",
	"包裹信息",
	"Interface\\AddOns\\Bag_Status_Meters\\Icon", 
	function()	
	    if not getglobal("BSM_Options"):IsVisible() then
		getglobal("BSM_Options"):Show();
	    else
		getglobal("BSM_Options"):Hide();
	    end
	end,
	3,
	4
	);

    --If any of the key save elements does not exist, create a new save
    if not BSM_Save or not BSM_Save.I or not BSM_Save.O then
        --BSM_Save: the saved variable for everything
        BSM_Save = { };
        --BSM_Save.I: the saved variables used for individual meters
        BSM_Save.I = { };
        --BSM_Save.O: the saved variables used for the overall meter
        BSM_Save.O = { };
        --BSM_Save.I.enable: enables/disables all of the individual meters
        BSM_Save.I.enable = true;
        --BSM_Save.I.overlay: enables/disables the individual meters displayed over the bag slots
        BSM_Save.I.overlay = true;
        --BSM_Save.I.bars: set the display mode for the overlay meters to include the bar
        BSM_Save.I.bars = true;
        --BSM_Save.I.bars: set the display mode for the overlay meters to only text
        BSM_Save.I.labels = false;
        --BSM_Save.I.dropdowns: enables/disables the dropdown meters from the overall meter
        BSM_Save.I.dropdowns = false;
        --BSM_Save.I.bindings: enables/disables the binding buttons next to the dropdown meters that open the bags
        BSM_Save.I.bindings = true;
        --BSM_Save.I.showlabels: enables/disables the use of any labels on the individual meters
        BSM_Save.I.showlabels = true;
        --BSM_Save.I.color: enables/disables color changing of the individual bars
        BSM_Save.I.color = true;
        --BSM_Save.I.totals: enables/disables displaying the total slots on the labels
        BSM_Save.I.totals = true;
        --BSM_Save.I.slots: determines whether to use free or used slots in the labels
        BSM_Save.I.slots = BSM_SLOTS_FREE;
        --BSM_Save.O.enable: enables/disables the entire overall meter
        BSM_Save.O.enable = true;
        --BSM_Save.O.title: enables/disables displaying the title over the overall meter
        BSM_Save.O.title = true;
        --BSM_Save.O.back: hides/shows the background and meter for the overall meter so there's only text
        BSM_Save.O.back = true;
        --BSM_Save.O.showlabels: enables/disables the use of the label on the overall meter
        BSM_Save.O.showlabels = true;
        --BSM_Save.O.color: enables/disables color changing of the overall bar
        BSM_Save.O.color = true;
        --BSM_Save.O.totals: enables/disables displaying the total slots on the label
        BSM_Save.O.totals = true;
        --BSM_Save.O.slots: determines whether to use free or used slots in the overall label
        BSM_Save.O.slots = BSM_SLOTS_USED;
        --BSM_Save.O.lock: locks/unlocks the overall meter from dragging
        BSM_Save.O.lock = false;
        --BSM_Save.dispX/dispY: the position of the overall meter relative to the bottom left of the screen
        BSM_Save.dispX = GetScreenWidth()/2 + 150;
        BSM_Save.dispY = 50;
        --BSM_Save.notify: enables/disables notifications when bags are full
        BSM_Save.notify = true;
        --BSM_Save.optbutton: enables/disables displaying the options button next to the overall meter
        BSM_Save.optbutton = true;
    end

    BSM_DisableAllIndividual();
    if BSM_Save.I.enable then
        BSM_EnableAllIndividual();
    end
    
    if not BSM_Save.I.bindings then
        for i = 0, 4, 1 do
            getglobal(BSM_DROPDOWNS..i.."Key"):Hide();
        end
    else
    end

    if not BSM_Save.O.enable then
        getglobal(BSM_FRAME):Hide();
    end
    if not BSM_Save.O.showlabels then
        getglobal("BSM_FrameText"):Hide();
    end
    if not BSM_Save.O.title then
        getglobal("BSM_FrameButtonLabel"):Hide();
    end
    if not BSM_Save.optbutton then
        getglobal("BSM_OptionsButton"):Hide();
    end
    if not BSM_Save.O.back then
        getglobal(BSM_FRAME.."BackAlpha"):Hide();
        getglobal(BSM_FRAME.."Border"):Hide();
        BSM_FrameStatus:Hide();
    end
    
    --Set the position of the Overall Meter frame relative to the bottom left of the screen
    getglobal(BSM_FRAME):ClearAllPoints();
    getglobal(BSM_FRAME):SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", BSM_Save.dispX, BSM_Save.dispY);

    BSM_LOADED = true;
    BSM_updateFreeSlots();
end

--BSM_updateFreeSlots:
--    Purpose - Update the BSM_NumSlots and BSM_UsedSlots to accurately reflect the inventory
--              Also updates all meters that need to be updated
--    Parameters - None
--    Returns - Nothing
function BSM_updateFreeSlots()
    --totalSlots: the number of slots in all bags
	local totalSlots = 0;
	--totalUsedSlots: the number of used slots in all bags
	local totalUsedSlots = 0;
	--slotsText: the text that is to be displayed on the meter labels
	local slotsText = 0;
	--isAmmo:  true if the current bag is one of the recognized ammo bags
	local isAmmo = false;

    --Loop through for every bag
	for bag = 0, 4, 1 do
        --Save the number of total slots in the current bag to the global variable
		BSM_NumSlots[bag+1] = GetContainerNumSlots(bag);
		
		isAmmo = false;
		
		--Check if the current bag is an ammo bag or can't get the bag name
		if ( not GetBagName(bag) ) then
            isAmmo = true;
		else
    		for i = 1, table.getn( BSM_AMMO ), 1 do
                if ( string.find( GetBagName(bag), BSM_AMMO[i] ) ) then
                    isAmmo = true;
                    break;
                end
    		end
		end

		--If there is no bag in the current bag slot or it is an ammo bag, hide all of its meters and don't count it in the total
		if (BSM_NumSlots[bag+1] == 0 or isAmmo) then
			getglobal(BSM_BARS..bag):Hide();
			getglobal(BSM_BARS_LABELS..bag):Hide();
			getglobal(BSM_DROPDOWNS..bag):Hide();
			getglobal(BSM_DROPDOWNS_LABELS..bag):Hide();
			getglobal(BSM_DROPDOWNS_BARS..bag):Hide();
			BSM_BagFull[bag+1] = false;
		else
			totalSlots = totalSlots + BSM_NumSlots[bag+1];
			
			--Reset the used slots global variable and
            --loop through every slot in the current bag and 
            --increment the variable if an item exists
			BSM_UsedSlots[bag+1] = 0;
			for slot = 1, BSM_NumSlots[bag+1], 1 do
				if (GetContainerItemInfo(bag, slot)) then
					BSM_UsedSlots[bag+1] = BSM_UsedSlots[bag+1] + 1;
					totalUsedSlots = totalUsedSlots + 1;
				end
			end

            --If free slots are used in the individual labels, subtract the used slots from the free slots and
            --use that number in the slots text instead of used slots
			if BSM_Save.I.slots == BSM_SLOTS_FREE then
                slotsText = BSM_NumSlots[bag+1] - BSM_UsedSlots[bag+1];
			else
                slotsText = BSM_UsedSlots[bag+1];
			end
			--If the totals are shown in the individual labels, concatenate it onto the end of the text
			if BSM_Save.I.totals then
                slotsText = slotsText.."/"..BSM_NumSlots[bag+1];
			end

            --Show the current bag text and reset the text color
            getglobal(BSM_BARS_LABELS..bag):Show();
			getglobal(BSM_BARS_LABELS..bag):SetText(slotsText);
            getglobal(BSM_BARS_LABELS..bag):SetTextColor(1.0, 1.0, 1.0, 1.0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -