Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FadeMeter(meter, startAlpha, endAlpha, speed)
- local startAlpha = startAlpha or 255 --"default" starting alpha
- local endAlpha = endAlpha or 0 --"default ending alpha
- local speed = speed or 0.1
- local meter = SKIN:GetMeter(meter) --get the meter to fade
- if meter == nil then print("Error: "..meter.." is not a valid meter.") return end --some simple error checking
- if (startAlpha > 255 or startAlpha < 0) or (endAlpha > 255 or endAlpha < 0) then print("Error: Alpha value out of range, must be between 0-255") return end
- if startAlpha > endAlpha then speed = -speed end --counting down instead of up
- local meterType = string.lower(meter:GetOption("Meter")) --get the "type" of meter (ie. String, Bar, etc.)
- local config = SKIN:GetVariable("CURRENTCONFIG")
- local solidColor, solidColor2 = nil, nil
- if meter:GetOption("SolidColor") ~= "" then solidColor = stripAlpha(meter:GetOption("SolidColor")) end
- if meter:GetOption("SolidColor2") ~= "" then solidColor2 = stripAlpha(meter:GetOption("SolidColor2")) end
- if meterType == "bar" then
- local barColor = stripAlpha(meter:GetOption("BarColor"))
- local imageAlpha = meter:GetOption("ImageAlpha")
- setAlpha(meter:GetName(), config, startAlpha, endAlpha, speed, "SolidColor", solidColor, "SolidColor2", solidColor2, "BarColor", barColor, "ImageAlpha", imageAlpha)
- elseif meterType == "bitmap" or meterType == "button" or meterType == "image" or meterType == "rotator" then
- local imageAlpha = meter:GetOption("ImageAlpha")
- setAlpha(meter:GetName(), config, startAlpha, endAlpha, speed, "SolidColor", solidColor, "SolidColor2", solidColor2, "ImageAlpha", imageAlpha)
- elseif meterType == "histogram" then
- local primaryColor = stripAlpha(meter:GetOption("PrimaryColor"))
- local secondaryColor = stripAlpha(meter:GetOption("SecondaryColor"))
- local bothColor = stripAlpha(meter:GetOption("BothColor"))
- local primaryImageAlpha = meter:GetOption("PrimaryImageAlpha")
- local secondaryImageAlpha = meter:GetOption("SecondaryImageAlpha")
- local bothImageAlpha = meter:GetOption("BothImageAlpha")
- setAlpha(meter:GetName(), config, startAlpha, endAlpha, speed, "SolidColor", solidColor, "SolidColor2", solidColor2, "PrimaryColor", primaryColor, "SecondaryColor", secondaryColor, "BothColor", bothColor, "PrimaryImageAlpha", primaryImageAlpha, "SecondaryImageAlpha", secondaryImageAlpha, "BothImageAlpha", bothImageAlpha)
- elseif meterType == "line" then
- SKIN:Bang("!ShowMeter "..meter:GetName().." "..config)
- local horizontalLineColor = stripAlpha(meter:GetOption("HorizontalLineColor"))
- local lineColor = { }
- lineColor[1] = stripAlpha(meter:GetOption("LineColor"))
- local i = 2
- repeat
- local found = false
- if meter:GetOption("MeasureName"..i) == "" then found = true else lineColor[i] = stripAlpha(meter:GetOption("LineColor"..i)) end
- i = i + 1
- until (found == true)
- for i=startAlpha, endAlpha, speed do
- if ((speed > 0) and ((i + speed) > endAlpha)) or ((speed < 0) and ((i + speed) < endAlpha)) then i = endAlpha end
- if horizontalLineColor ~= nil then SKIN:Bang("!SetOption "..meter:GetName().." HorizontalLineColor "..horizontalLineColor..i.." "..config) end
- if solidColor ~= nil then SKIN:Bang("!SetOption "..meter:GetName().." SolidColor "..solidColor..i.." "..config) end
- if solidColor2 ~= nil then SKIN:Bang("!SetOption "..meter:GetName().." SolidColor2 "..solidColor2..i.." "..config) end
- if lineColor[1] ~= nil then SKIN:Bang("!SetOption "..meter:GetName().." LineColor "..lineColor[1]..i.." "..config) end
- for j=2, #lineColor do SKIN:Bang("!SetOption "..meter:GetName().." LineColor"..j.." "..lineColor[j]..i.." "..config) end
- SKIN:Bang("!UpdateMeter "..meter:GetName().." "..config)
- SKIN:Bang("!Redraw "..config)
- end
- elseif meterType == "roundline" then
- local lineColor = stripAlpha(meter:GetOption("LineColor"))
- setAlpha(meter:GetName(), config, startAlpha, endAlpha, speed, "SolidColor", solidColor, "SolidColor2", solidColor2, "LineColor", lineColor)
- elseif meterType == "string" then
- local fontColor = stripAlpha(meter:GetOption("FontColor"), "0,0,0,")
- local effectColor = stripAlpha(meter:GetOption("FontEffectColor"), "0,0,0,")
- setAlpha(meter:GetName(), config, startAlpha, endAlpha, speed, "SolidColor", solidColor, "SolidColor2", solidColor2, "FontColor", fontColor, "FontEffectColor", effectColor)
- end
- if endAlpha == 0 then --Hide the meter if the Alpha value is 0
- SKIN:Bang("!HideMeter "..meter:GetName().." "..config)
- end
- end
- function stripAlpha(option, defaultValue)
- local defaultValue = defaultValue or "255,255,255,"
- if option == "" or option == nil then
- if string.sub(defaultValue, -1) ~= "," then defaultValue = defaultValue.."," end --add a comma at the end of the string if none is provided
- option = defaultValue
- elseif string.find(option, ",") then
- option = string.join(string.split(option, ",", 3), ",")..","
- else
- local temp = { }
- local j = 1
- for i=1, 6, 2 do
- temp[j] = tonumber(string.sub(option, i, i+1), 16)
- j = j + 1
- end
- option = string.join(temp, ",")..","
- end
- return option
- end
- function setAlpha(meterName, config, startAlpha, endAlpha, speed, ...)
- SKIN:Bang("!ShowMeter "..meterName.." "..config)
- local i, j
- for i=startAlpha, endAlpha, speed do
- if ((speed > 0) and ((i + speed) > endAlpha)) or ((speed < 0) and ((i + speed) < endAlpha)) then
- i = endAlpha --close enough to the endAlpha value
- end
- for j=1, arg['n'], 2 do
- if string.find(arg[j], "Alpha") then
- SKIN:Bang("!SetOption "..meterName.." "..arg[j].." "..i.." "..config) --if the option is a single number (ie. ImageAlpha)
- elseif arg[j+1] ~= nil then
- SKIN:Bang("!SetOption "..meterName.." "..arg[j].." "..arg[j+1]..i.." "..config) --if option is a comma separated value (ie. FontColor)
- end
- end
- SKIN:Bang("!UpdateMeter "..meterName.." "..config)
- SKIN:Bang("!Redraw "..config)
- end
- end
- string.join = function(myTable, deliminator)
- if deliminator == nil then return table.concat(myTable)
- else return table.concat(myTable, deliminator) end
- end
- string.split = function(myString, deliminator, maxIndex)
- if string.find(myString, deliminator) == nil then return {myString} end --return the string (as a table) if no deliminator is found
- if maxIndex == nil or maxIndex < 1 then maxIndex = 0 end --maxIndex is the number of index's to return (0 for unlimited)
- local result = {}
- local pattern = "(.-)"..deliminator.."()"
- local index = 0
- local lastPosition
- for match, position in string.gmatch(myString, pattern) do
- index = index + 1
- result[index] = match
- lastPosition = position
- if index == maxIndex then break end
- end
- if index ~= maxIndex then result[index + 1] = string.sub(myString, lastPosition) end
- return result
- end
Add Comment
Please, Sign In to add comment