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

📄 bag_status_meters.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
            getglobal(BSM_DROPDOWNS_LABELS..bag):Show();
			getglobal(BSM_DROPDOWNS_LABELS..bag):SetText(slotsText);

            --status: a temporary variable to hold the current meter being updated
			local status;
			--If the bars are shown and the overlay is enabled, update the meter/label over the current bag
			if BSM_Save.I.bars and BSM_Save.I.overlay then
                --Set status to the meter that is over the current bag
                status = getglobal(BSM_BARS..bag);
                --Set the meter's min, max, and current values accordingly
    			status:SetMinMaxValues(0, BSM_NumSlots[bag+1]);
    			status:SetValue(BSM_UsedSlots[bag+1]);
    			--If color is enabled, color the bar according to the ratio of used slots to total slots
    			--Otherwise make it a gray color
    			if BSM_Save.I.color then
        			status:SetStatusBarColor(BSM_GetColor(BSM_NumSlots[bag+1] - BSM_UsedSlots[bag+1], BSM_NumSlots[bag+1], 0.6));
        		else
        			status:SetStatusBarColor(0.5, 0.5, 0.5, 0.6);
        		end
                status:Show();
            end

            --If the overlay display is set to just labels and the overlay is enabled, update only the label
    		if BSM_Save.I.labels and BSM_Save.I.overlay then
                --If color is disabled or the bag is less than half full, keep the label white
                --Otherwise color the label according to the ratio of used slots to total slots
                if not BSM_Save.I.color then
                    getglobal(BSM_BARS_LABELS..bag):SetTextColor(1.0, 1.0, 1.0, 1.0);
                elseif BSM_UsedSlots[bag+1] / BSM_NumSlots[bag+1] >= 0.5 then
                    getglobal(BSM_BARS_LABELS..bag):SetTextColor(BSM_GetColor(BSM_NumSlots[bag+1] - BSM_UsedSlots[bag+1], BSM_NumSlots[bag+1], 1.0));
                else
                    getglobal(BSM_BARS_LABELS..bag):SetTextColor(1.0, 1.0, 1.0, 1.0);
                end
            end

            --If the dropdown meters are enabled, update them
			if BSM_Save.I.dropdowns then
                --Set status to the dropdown meter that is for the current bag
                status = getglobal(BSM_DROPDOWNS_BARS..bag);
                --Set the meter's min, max, and current values accordingly
    			status:SetMinMaxValues(0, BSM_NumSlots[bag+1]);
    			status:SetValue(BSM_UsedSlots[bag+1]);
    			--If color is enabled, color the bar according to the ratio of used slots to total slots
    			--Otherwise make it a gray color
    			if BSM_Save.I.color then
        			status:SetStatusBarColor(BSM_GetColor(BSM_NumSlots[bag+1] - BSM_UsedSlots[bag+1], BSM_NumSlots[bag+1], 1.0));
        		else
        			status:SetStatusBarColor(0.5, 0.5, 0.5, 1.0);
        		end
                status:Show();
                getglobal(BSM_DROPDOWNS..bag):Show()
            end

            --If the current bag is full and notifications are enabled, check if a notification should be given
            if BSM_UsedSlots[bag+1] == BSM_NumSlots[bag+1] and BSM_Save.notify then
                --If the bag was not full last check, give a notification and
                --set the full bag variable to true
                --Otherwise keep the full bag variable false
                if not BSM_BagFull[bag+1] then
                    if bag == 0 then
                        UIErrorsFrame:AddMessage(BSM_BACKPACK..BSM_FULL, 1.0, 0.1, 1.0, 1.0, UIERRORS_HOLD_TIME);
                        DEFAULT_CHAT_FRAME:AddMessage(BSM_MSG.."|cffff0fff"..BSM_BACKPACK..BSM_FULL.."|r");
                    else
                        UIErrorsFrame:AddMessage(BSM_BAG..bag..BSM_FULL, 1.0, 0.1, 1.0, 1.0, UIERRORS_HOLD_TIME);
                        DEFAULT_CHAT_FRAME:AddMessage(BSM_MSG.."|cffff0fff"..BSM_BAG..bag..BSM_FULL.."|r");
                    end
                    BSM_BagFull[bag+1] = true;
                end
            else
                BSM_BagFull[bag+1] = false;
            end
		end
	end

    --Update the bindings for all of the dropdown meter buttons
    getglobal(BSM_DROPDOWNS.."0Key"):SetText(GetBindingText(GetBindingKey("TOGGLEBACKPACK"), "KEY_"));
    getglobal(BSM_DROPDOWNS.."4Key"):SetText(GetBindingText(GetBindingKey("TOGGLEBAG1"), "KEY_"));
    getglobal(BSM_DROPDOWNS.."3Key"):SetText(GetBindingText(GetBindingKey("TOGGLEBAG2"), "KEY_"));
    getglobal(BSM_DROPDOWNS.."2Key"):SetText(GetBindingText(GetBindingKey("TOGGLEBAG3"), "KEY_"));
    getglobal(BSM_DROPDOWNS.."1Key"):SetText(GetBindingText(GetBindingKey("TOGGLEBAG4"), "KEY_"));

    --If the overall meter is disabled, then everything else can be ignored
    if not BSM_Save.O.enable then return; end

    --totalFreeSlots: free slots in all of the bags
	local totalFreeSlots = totalSlots - totalUsedSlots;

    --If free slots are used in the overall label, use that number in the slots text instead of used slots
	if BSM_Save.O.slots == BSM_SLOTS_FREE then
        slotsText = totalFreeSlots;
	else
        slotsText = totalUsedSlots;
	end
	--If the totals are shown in the overall label, concatenate it onto the end of the text
	if BSM_Save.O.totals then
        slotsText = slotsText.."/"..totalSlots;
	end

    --Update the text and
    --min, max, and current values of the overall bar
	BSM_FrameText:SetText(slotsText);
	BSM_FrameStatus:SetMinMaxValues(0, totalSlots);
	BSM_FrameStatus:SetValue(totalUsedSlots);
	--If color is enabled, color the bar according to the ratio of used slots to total slots
    --Otherwise make it a gray color
    if BSM_Save.O.color then
    	BSM_FrameStatus:SetStatusBarColor(BSM_GetColor(totalFreeSlots, totalSlots, 1.0));
    else
        BSM_FrameStatus:SetStatusBarColor(0.5, 0.5, 0.5, 1.0);
    end

    --Update the bank bars if the Bank frame is open
	--[[if getglobal("BSM_Bank_Bars"):IsVisible() then
    	BSM_updateBankBags();
	end]]
end

--BSM_GetColor:
--    Purpose - Get the appropriate color for the bar being updated
--    Parameters - freeSlots: free slots in the bag
--                 totalSlots: number of slots in the bag
--                 alpha: desired opacity of the color
--    Returns - Color for the bar (red, green, blue, alpha)
function BSM_GetColor(freeSlots, totalSlots, alpha)
    local pct = freeSlots / totalSlots;
    local r, g;
    r = 1.0;
    g = 1.0;
	if  pct < 0.5 then
        --r = 1.0;
		g = pct * 2;
	elseif pct > 0.5 then
        r = 1.0 - (pct-0.5) * 2;
        --g = 1.0;
	--elseif pct == 0.5 then
		--Do nothing, both already 1.0
	end
	
	return r, g, 0.0, alpha;
end



--BSM_updateBankBags:
--    Purpose - Update the bank bars when the bank frame is open
--    Parameters - None
--    Returns - Nothing
function BSM_updateBankBags()
    --num: number of slots in the current bank bag
    local num = 0;
    --used: number of used slots in the current bank bag
    local used = 0;
    --slotsText: the text that is to be displayed on the meter labels
	local slotsText = 0;
	--status: the current bar being updated
	local status;

    --Loop through for every bank bag
	for bag = 5, 10, 1 do
        --set status to the current bar and get the number of slots in the current bank bag
        status = getglobal(BSM_BANK..(bag-4));
		num = GetContainerNumSlots(bag);
		--if there is no bag in the current bank bag slot, then hide the bar
		if num == 0 then
            status:Hide();
		else
            --Reset the used slots and
            --loop through every slot in the current bank bag and
            --increment the variable if an item exists
			used = 0;
			for slot = 1, num, 1 do
				if GetContainerItemInfo(bag, slot) then
					used = used + 1;
				end
			end

            --[[--bar: the bar to the current bank bag
            local bar = getglobal(status:GetName().."Bar");
            --Set the meter's min, max, and current values accordingly
    		bar:SetMinMaxValues(0, num);
    		bar:SetValue(used);
    		--If color is enabled, color the bar according to the ratio of used slots to total slots
    		--Otherwise make it a gray color
    		if BSM_Save.I.color then
        		bar:SetStatusBarColor(BSM_GetColor(num - used, num, 0.6));
        	else
        		bar:SetStatusBarColor(0.5, 0.5, 0.5, 0.6);
        	end]]

			if BSM_Save.I.slots == BSM_SLOTS_FREE then
                slotsText = num - used;
			else
                slotsText = used;
			end
			
			if BSM_Save.I.totals then
                slotsText = slotsText.."/"..num;
			end

            status:Show();
            getglobal(status:GetName().."Label"):SetText(slotsText);
		end
	end
end

--BSM_DividerOnShow:
--    Purpose - Set the text of a header depending on its name
--    Parameters - h: the header that's being shown
--    Returns - Nothing
function BSM_DividerOnShow(h)
    local name = h:GetName();

    if name == "BSM_Divider_Individual" then
        getglobal(name.."HeaderText"):SetText(BSM_OPTIONS_INDIVID);
        getglobal(name.."Header"):SetWidth(250);
    elseif name == "BSM_Divider_Overall" then
        getglobal(name.."HeaderText"):SetText(BSM_OPTIONS_OVERALL);
        getglobal(name.."Header"):SetWidth(220);
    elseif name == "BSM_Divider_Global" then
        getglobal(name.."HeaderText"):SetText(BSM_OPTIONS_GLOBAL);
        getglobal(name.."Header"):SetWidth(128);
    end
end

--BSM_EnableIndividualChecks:
--    Purpose - Enables all the check boxes having to do with individual meters
--    Parameters - None
--    Returns - Nothing
function BSM_EnableIndividualChecks()
    getglobal("BSM_Check_Overlay"):Enable();
    getglobal("BSM_Check_Bars"):Enable();
    getglobal("BSM_Check_Labels"):Enable();
    getglobal("BSM_Check_Dropdown"):Enable();
    getglobal("BSM_Check_IndvLabels"):Enable();
    getglobal("BSM_Check_IndvColor"):Enable();
    getglobal("BSM_Check_IndvTotals"):Enable();
    getglobal("BSM_Check_IndvSlots"):Enable();
    getglobal("BSM_Check_Bindings"):Enable();
end

--BSM_DisableIndividualChecks:
--    Purpose - Disables all the check boxes having to do with individual meters
--    Parameters - None
--    Returns - Nothing
function BSM_DisableIndividualChecks()
    getglobal("BSM_Check_Overlay"):Disable();
    getglobal("BSM_Check_Bars"):Disable();
    getglobal("BSM_Check_Labels"):Disable();
    getglobal("BSM_Check_Dropdown"):Disable();
    getglobal("BSM_Check_IndvLabels"):Disable();
    getglobal("BSM_Check_IndvColor"):Disable();
    getglobal("BSM_Check_IndvTotals"):Disable();
    getglobal("BSM_Check_IndvSlots"):Disable();
    getglobal("BSM_Check_Bindings"):Disable();
end

--BSM_CheckOnShow:
--    Purpose - Set the text of a check box depending on its name
--              Also makes the necessary checks for enabling/disabling child check boxes
--    Parameters - b: the check box that's being shown
--    Returns - Nothing
function BSM_CheckOnShow(b)
    local name = b:GetName();
    
    if name == "BSM_Check_Individual" then
        getglobal(name.."Text"):SetText(BSM_TEXT_INDIVIDUAL);
        if BSM_Save.I.enable then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
        if b:GetChecked() == 1 then
            BSM_EnableIndividualChecks();
        else
            BSM_DisableIndividualChecks();
        end
    elseif name == "BSM_Check_Overlay" then
        getglobal(name.."Text"):SetText(BSM_TEXT_OVERLAY);
        if BSM_Save.I.overlay then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
        if b:GetChecked() == 1 and BSM_Save.I.enable then
            getglobal("BSM_Check_Bars"):Enable();
            getglobal("BSM_Check_Labels"):Enable();
        else
            getglobal("BSM_Check_Bars"):Disable();
            getglobal("BSM_Check_Labels"):Disable();
        end
    elseif name == "BSM_Check_Bars" then
        getglobal(name.."Text"):SetText(BSM_TEXT_BAR);
        if BSM_Save.I.bars then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_Labels" then
        getglobal(name.."Text"):SetText(BSM_TEXT_LABELSTAT);
        if BSM_Save.I.labels then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_Dropdown" then
        getglobal(name.."Text"):SetText(BSM_TEXT_DROPDOWN);
        if BSM_Save.I.dropdowns then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
        if b:GetChecked() == 1 and BSM_Save.I.enable then
            getglobal("BSM_Check_Bindings"):Enable();
        else
            getglobal("BSM_Check_Bindings"):Disable();
        end
    elseif name == "BSM_Check_Bindings" then
        getglobal(name.."Text"):SetText(BSM_TEXT_BINDINGS);
        if BSM_Save.I.bindings then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_IndvLabels" then
        getglobal(name.."Text"):SetText(BSM_TEXT_LABELS);
        if BSM_Save.I.showlabels then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_IndvColor" then
        getglobal(name.."Text"):SetText(BSM_TEXT_COLOR);
        if BSM_Save.I.color then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_IndvTotals" then
        getglobal(name.."Text"):SetText(BSM_TEXT_TOTALS);
        if BSM_Save.I.totals then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
    elseif name == "BSM_Check_IndvSlots" then
        getglobal(name.."Text"):SetText(BSM_TEXT_SLOTS);
        if BSM_Save.I.slots == BSM_SLOTS_FREE then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end

    elseif name == "BSM_Check_Overall" then
        getglobal(name.."Text"):SetText(BSM_TEXT_OVERALL);
        if BSM_Save.O.enable then
            b:SetChecked(1);
        else
            b:SetChecked(0);
        end
        if b:GetChecked() == 1 then
            getglobal("BSM_Check_Title"):Enable();
            getglobal("BSM_Check_Back"):Enable();
            getglobal("BSM_Check_OverallLabels"):Enable();
            getglobal("BSM_Check_OverallColor"):Enable();
            getglobal("BSM_Check_OverallTotals"):Enable();
            getglobal("BSM_Check_OverallSlots"):Enable();
        else

⌨️ 快捷键说明

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