You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1820 lines
55 KiB

4 years ago
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
local Details = _G.Details
3 years ago
local Loc = LibStub("AceLocale-3.0"):GetLocale ( "Details" )
local addonName, Details222 = ...
4 years ago
local _
3 years ago
4 years ago
local upper = string.upper --lua local
3 years ago
local ipairs = ipairs --lua local
local pairs = pairs --lua local
4 years ago
local _math_floor = math.floor --lua local
local _math_max = math.max --lua local
local _math_min = math.min --lua local
local _math_random = math.random --lua local
local type = type --lua local
local _string_match = string.match --lua local
local _string_format = string.format --lua local
local loadstring = loadstring --lua local
3 years ago
local select = select
local tonumber = tonumber
local strsplit = strsplit
4 years ago
local _pcall = pcall
3 years ago
local GetTime = GetTime
local GetUnitName = _G.GetUnitName
local UnitExists = UnitExists
local UnitGUID = UnitGUID
3 years ago
local IsInRaid = IsInRaid --wow api local
local IsInGroup = IsInGroup --wow api local
local GetNumGroupMembers = GetNumGroupMembers --wow api local
local UnitAffectingCombat = UnitAffectingCombat --wow api local
4 years ago
local _InCombatLockdown = InCombatLockdown --wow api local
local playerRealmName = GetRealmName()
4 years ago
local gump = Details.gump --details local
local predicateFunc = function(spellIdToFind, casterName, _, name, icon, applications, dispelName, duration, expirationTime, sourceUnit, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, isFromPlayerOrPlayerPet, nameplateShowAll, timeMod, applications)
if (spellIdToFind == spellId and UnitExists(sourceUnit)) then
if (casterName == Details:GetFullName(sourceUnit)) then
return true
end
end
end
do
function Details:FindDebuffDurationByUnitName(targetString, spellId, casterString)
local targetName, targetRealm = strsplit("-", targetString)
if (playerRealmName ~= targetRealm) then
targetName = targetString
end
local casterName, casterRealm = strsplit("-", casterString)
if (playerRealmName ~= casterRealm) then
casterName = casterString
end
return Details:FindDebuffDuration(targetName, spellId, casterName)
end
---find the duration of a debuff by passing the spellId and the caster name
---@param unitId unit
---@param spellId spellid
---@param casterName actorname
---@return auraduration|nil auraDuration
---@return number|nil expirationTime
function Details:FindDebuffDuration(unitId, spellId, casterName)
local name, texture, count, debuffType, duration, expirationTime = AuraUtil.FindAura(predicateFunc, unitId, "HARMFUL", spellId, casterName)
if (name) then
return duration, expirationTime
end
end
end
do
function Details:FindBuffDurationByUnitName(targetString, spellId, casterString)
local targetName, targetRealm = strsplit("-", targetString)
if (playerRealmName ~= targetRealm) then
targetName = targetString
end
local casterName, casterRealm = strsplit("-", casterString)
if (playerRealmName ~= casterRealm) then
casterName = casterString
end
return Details:FindBuffDuration(targetName, spellId, casterName)
end
---find the duration of a buff by passing the spellId and the caster name
---@param unitId unit
---@param spellId spellid
---@param casterName actorname
---@return auraduration|nil auraDuration
---@return number|nil expirationTime
function Details:FindBuffDuration(unitId, spellId, casterName)
local name, texture, count, debuffType, duration, expirationTime = AuraUtil.FindAura(predicateFunc, unitId, "HELPFUL", spellId, casterName)
if (name) then
return duration, expirationTime
end
end
end
do
function Details:FindBuffCastedByUnitName(targetString, buffSpellId, casterString)
local targetName, targetRealm = strsplit("-", targetString)
if (playerRealmName ~= targetRealm) then
targetName = targetString
end
local casterName, casterRealm = strsplit("-", casterString)
if (playerRealmName ~= casterRealm) then
casterName = casterString
end
return Details:FindBuffCastedBy(targetName, buffSpellId, casterName)
end
function Details:FindBuffCastedBy(unitId, buffSpellId, casterName)
local auraName, texture, count, auraType, duration, expTime, sourceUnit, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, playerOrPet, nameplateShowAll, timeMod, v1, v2, v3, v4, v5 = AuraUtil.FindAura(predicateFunc, unitId, "HELPFUL", buffSpellId, casterName)
if (auraName) then
return auraName, texture, count, auraType, duration, expTime, sourceUnit, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, playerOrPet, nameplateShowAll, timeMod, v1, v2, v3, v4, v5
end
end
end
---return the unitId by passing a unit serial (guid)
---@param unitSerial serial
---@return unit|nil unitId
function Details:FindUnitIDByUnitSerial(unitSerial)
--target
if (UnitExists("target")) then
if (UnitGUID("target") == unitSerial) then
return "target"
end
end
--focus
if (UnitExists("focus")) then
if (UnitGUID("focus") == unitSerial) then
return "focus"
end
end
--boss
for i = 1, 9 do
local unitId = Details222.UnitIdCache.Boss[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
else
break
end
end
--nameplate
for i = 1, 40 do
local unitId = Details222.UnitIdCache.Nameplate[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
end
end
--arena enemies
for i = 1, #Details222.UnitIdCache.Arena do
local unitId = Details222.UnitIdCache.Arena[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
else
break
end
end
end
4 years ago
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--fade handler
4 years ago
Details.FadeHandler = {
frames = {}
}
--fade in is hidding the frame, it is the opposite of the stardard
local fadeINFinishedCallback = function(frame)
if (frame.fading_in) then
frame.hidden = true
frame.faded = true
frame.fading_in = false
frame:Hide()
end
end
--fade out is showing the frame
local fadeOUTFinishedCallback = function(frame)
if (frame:IsShown() and frame.fading_out) then
frame.hidden = false
frame.faded = false
frame.fading_out = false
else
frame:SetAlpha(0)
end
end
local just_fade_func = function(frame)
frame.hidden = false
frame.faded = true
frame.fading_in = false
end
local cancelFadeAnimation = function(frame)
Details.FadeHandler.frames[frame] = nil
end
Details.FadeHandler.OnUpdateFrame = CreateFrame("frame", "DetailsFadeFrameOnUpdate", UIParent)
Details.FadeHandler.OnUpdateFrame:SetScript("OnUpdate", function(self, deltaTime)
for frame, frameSettings in pairs(Details.FadeHandler.frames) do
local totalTime = frameSettings.totalTime
local initAlpha = frameSettings.startAlpha
local targetAlpha = frameSettings.endAlpha
frameSettings.elapsed = frameSettings.elapsed + deltaTime
local currentAlpha = Lerp(initAlpha, targetAlpha, frameSettings.elapsed / totalTime)
if (frameSettings.elapsed >= totalTime) then
frame:SetAlpha(targetAlpha)
frameSettings.finishedCallback(frame)
--remove the frame from the list
Details.FadeHandler.frames[frame] = nil
else
frame:SetAlpha(currentAlpha)
end
end
end)
--fade in is hidding the frame
local startFadeINAnimation = function(frame, totalTime, startAlpha, endAlpha, callbackFunc)
frame.fading_out = nil
frame.fading_in = true
Details.FadeHandler.frames[frame] = {
totalTime = totalTime or Details.fade_speed,
startAlpha = startAlpha or frame:GetAlpha(),
endAlpha = endAlpha or 0,
finishedCallback = callbackFunc or fadeINFinishedCallback,
elapsed = 0,
}
end
--fade out is showing the frame
local startFadeOUTAnimation = function(frame, totalTime, startAlpha, endAlpha, callbackFunc)
frame.fading_in = nil
frame.fading_out = true
Details.FadeHandler.frames[frame] = {
totalTime = totalTime or Details.fade_speed,
startAlpha = startAlpha or frame:GetAlpha() or 0,
endAlpha = endAlpha or 1,
finishedCallback = callbackFunc or fadeOUTFinishedCallback,
elapsed = 0,
}
end
function Details.FadeHandler.Fader(frame, animationType, speed, hideType, param5)
if (frame == nil) then
frame, animationType, speed, hideType = animationType, speed, hideType, param5
end
--if is a table, might be passed an instance object
if (type(frame) == "table") then
--is it an instance
if (frame.meu_id) then
local instance = frame
--hide all bars in the instance
if (hideType == "barras") then
if (speed) then
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, speed)
end
return
else
speed = speed or Details.fade_speed
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, Details.fade_speed+(i/10))
end
return
end
--instant hide all bars in the instance
elseif (hideType == "hide_barras") then
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
if (instanceBar.fading_in or instanceBar.fading_out) then
startFadeINAnimation(instanceBar, 0.01, instanceBar:GetAlpha(), instanceBar:GetAlpha())
end
instanceBar.hidden = true
instanceBar.faded = true
instanceBar.fading_in = false
instanceBar.fading_out = false
instanceBar:Hide()
instanceBar:SetAlpha(0)
end
return
end
--if is a framework widget
elseif (frame.dframework) then
frame = frame.widget
end
end
speed = speed or Details.fade_speed
--animationType = upper(animationType)
--hide all instanceBars on all instances
if (frame == "all") then
for _, instancia in ipairs(Details.tabela_instancias) do
4 years ago
if (hideType == "barras") then
for i = 1, instancia.rows_created do
local instanceBar = instancia.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, speed+(i/10))
end
end
end
return
3 years ago
4 years ago
elseif (upper(animationType) == "IN") then --hide the frame
--check if already hidden
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then
return
--chekc if already with an animation going on
elseif (frame.fading_in) then
return
end
3 years ago
4 years ago
--cancel face out animation if exists
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, speed, frame:GetAlpha(), 0)
elseif (upper(animationType) == "OUT") then --show the frame
3 years ago
if (frame:GetAlpha() == 1 and not frame.hidden and not frame.fading_in) then --ja esta na tela
4 years ago
return
3 years ago
elseif (frame.fading_out) then --j� ta com fading out
4 years ago
return
end
3 years ago
if (frame.fading_in) then --se tiver uma anima��o de hidar em andamento se for true
4 years ago
frame.fading_in = false
end
3 years ago
4 years ago
frame:Show()
startFadeOUTAnimation(frame, speed, frame:GetAlpha(), 1.0)
frame.fading_out = true
3 years ago
4 years ago
elseif (animationType == 0) then --force show the frame
frame.hidden = false
frame.faded = false
frame.fading_out = false
frame.fading_in = false
cancelFadeAnimation(frame) --cancel any ongoing animation
frame:Show()
frame:SetAlpha(1)
3 years ago
4 years ago
elseif (animationType == 1) then --force hide the frame
frame.hidden = true
frame.faded = true
frame.fading_out = false
frame.fading_in = false
cancelFadeAnimation(frame) --cancel any ongoing animation
frame:SetAlpha(0)
frame:Hide()
3 years ago
4 years ago
elseif (animationType == -1) then --just fade to zero without hidding the frame
--check already hidden
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then
return
--check already hidding
elseif (frame.fading_in) then
return
end
3 years ago
4 years ago
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, speed, frame:GetAlpha(), 0, just_fade_func)
elseif (upper(animationType) == "ALPHAANIM") then
local value = speed
local currentApha = frame:GetAlpha()
frame:Show()
3 years ago
4 years ago
if (currentApha < value) then
if (frame.fading_in) then
frame.fading_in = false
end
startFadeOUTAnimation(frame, Details.fade_speed, currentApha, value, function(frame) frame.fading_out = false end)
else
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, Details.fade_speed, currentApha, value, function(frame) frame.fading_in = false end)
end
--set a fixed alpha value
elseif (upper(animationType) == "ALPHA") then
local alphaAmount = speed
if (frame.fading_in or frame.fading_out) then
startFadeINAnimation(frame, speed, alphaAmount, alphaAmount)
end
frame.hidden = false
frame.faded = false
frame.fading_in = false
frame.fading_out = false
frame:Show()
frame:SetAlpha(alphaAmount)
end
end
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--details api functions
4 years ago
3 years ago
--get the npc id from guid
function Details:GetNpcIdFromGuid (guid)
3 years ago
local NpcId = select( 6, strsplit( "-", guid ) )
4 years ago
if (NpcId) then
3 years ago
return tonumber( NpcId )
4 years ago
end
return 0
end
3 years ago
function Details:GetSourceFromNpcId (npcId)
for index, container in ipairs(Details.tabela_vigente) do
4 years ago
if (index <= 4) then
local t = container._ActorTable
for i = 1, #t do
if (Details:GetNpcIdFromGuid (t[i].serial) == npcId) then
4 years ago
return t[i].nome
end
end
end
end
end
function Details:GetRaidLeader()
if (IsInRaid()) then
for i = 1, GetNumGroupMembers() do
local actorName, rank = GetRaidRosterInfo(i)
4 years ago
if (rank == 2) then
return actorName, "raid" .. i
4 years ago
end
end
end
end
3 years ago
---unpack a death table
---@param deathTable table
---@return actorname actorName name of the actor
---@return actorclass actorClass class of the actor
---@return unixtime deathTime unittime of when the death occurred
---@return combattime deathCombatTime time in seconds since the combat start
---@return timestring deathTimeString time in string format
---@return number maxHealth max health of the actor
---@return table deathEvents events that lead the actor to death
---@return {key1: unixtime, key2: spellid}
---@return specializationid specId
function Details:UnpackDeathTable(deathTable)
local deathevents = deathTable[1]
local deathtime = deathTable[2]
local playername = deathTable[3]
local playerclass = deathTable[4]
local playermaxhealth = deathTable[5]
local deathtimestring = deathTable[6]
local lastcooldown = deathTable.last_cooldown
local deathcombattime = deathTable.dead_at
local spec = deathTable.spec
3 years ago
return playername, playerclass, deathtime, deathcombattime, deathtimestring, playermaxhealth, deathevents, lastcooldown, spec
4 years ago
end
---get a random fraction number
---@return number
function Details:GetOrderNumber() --anyString
--local name = upper(anyString .. "zz")
--local byte1 = abs(_string_byte(name, 2)-91) / 1000000
--return byte1 + abs(_string_byte(name, 1)-91) / 10000
return _math_random(1000, 9000) / 1000000
4 years ago
end
3 years ago
--/script print(tonumber(4/1000000)) - 4e-006
4 years ago
--0.000004
3 years ago
--set all table keys to lower
4 years ago
local temptable = {}
function Details:LowerizeKeys (_table)
3 years ago
for key, value in pairs(_table) do
temptable [string.lower(key)] = value
4 years ago
end
temptable, _table = Details:Destroy(_table), temptable
4 years ago
return _table
end
3 years ago
Details.ToKFunctions = {}
3 years ago
4 years ago
--krKR by @yuk6196 (http://wow.curseforge.com/profiles/yuk6196)
function Details:UseEastAsianNumericalSystem()
3 years ago
--try to auto detect the language
4 years ago
local symbol_1K, symbol_10K, symbol_1B
if (LibStub("AceLocale-3.0"):NewLocale ("Details", "koKR")) then --Korea
symbol_1K, symbol_10K, symbol_1B = "", "", ""
elseif (LibStub("AceLocale-3.0"):NewLocale ("Details", "zhCN")) then --China
symbol_1K, symbol_10K, symbol_1B = "", "", "亿"
elseif (LibStub("AceLocale-3.0"):NewLocale ("Details", "zhTW")) then --Taiwan
symbol_1K, symbol_10K, symbol_1B = "", "", ""
end
3 years ago
--override, force details! to use symbols for a specific language.
--usage: _detalhes:SetNumericalSystemOverride (language) language can be: "kr", "cn", "tw"
--just in case the user mess up something
if (type(Details.numerical_system_symbols) ~= "string") then
Details.numerical_system_symbols = "auto"
4 years ago
end
3 years ago
--do the override
if (Details.numerical_system_symbols ~= "auto") then
local locale = string.lower(Details.numerical_system_symbols)
3 years ago
4 years ago
if (locale == "kr") then
symbol_1K, symbol_10K, symbol_1B = "", "", ""
elseif (locale == "cn") then
symbol_1K, symbol_10K, symbol_1B = "", "", "亿"
4 years ago
elseif (locale == "tw") then
symbol_1K, symbol_10K, symbol_1B = "", "", ""
4 years ago
end
end
3 years ago
4 years ago
if (not symbol_1K) then
3 years ago
--if a english client is trying to use east asian numeral system and there is no override, let's just use the chinese as default.
--if the user is from kr or tw and want to use english client, an override must be used.
symbol_1K, symbol_10K, symbol_1B = "", "", "亿"
4 years ago
end
3 years ago
function Details:ToK (numero)
4 years ago
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
function Details:ToK2 (numero)
4 years ago
if (numero > 99999999) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 999999) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 99999) then
3 years ago
return _math_floor(numero/10000) .. symbol_10K
4 years ago
elseif (numero > 9999) then
return _string_format ("%.1f", (numero/10000)) .. symbol_10K
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. symbol_1K
end
return _string_format ("%.1f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToK0 (numero)
4 years ago
if (numero > 100000000) then
return _string_format ("%.0f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.0f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
function Details:ToKMin (numero)
4 years ago
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
3 years ago
function Details:ToK2Min (numero)
4 years ago
if (numero > 99999999) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 999999) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 99999) then
3 years ago
return _math_floor(numero/10000) .. symbol_10K
4 years ago
elseif (numero > 9999) then
return _string_format ("%.1f", (numero/10000)) .. symbol_10K
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. symbol_1K
end
return _string_format ("%.1f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToK0Min (numero)
4 years ago
if (numero > 100000000) then
return _string_format ("%.0f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.0f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToKReport (numero)
4 years ago
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.1f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return numero
end
3 years ago
function Details:Format (n, custom)
3 years ago
n = _math_floor(n)
4 years ago
if (custom) then
if (n > 99999999) then
return _string_format (custom, n/100000000) .. symbol_1B
elseif (n > 9999) then
return _string_format (custom, n/10000) .. symbol_10K
elseif (n > 999) then
return _string_format (custom, (n/1000))
else
return n
end
else
return Details.ToKFunctions [Details.ps_abbreviation] (nil, n)
4 years ago
end
end
3 years ago
--no changes
function Details:NoToK (numero)
3 years ago
return _math_floor(numero)
4 years ago
end
3 years ago
4 years ago
-- thanks http://richard.warburton.it
function Details:comma_value (n)
4 years ago
if (not n) then return "0" end
3 years ago
n = _math_floor(n)
4 years ago
if (n == 0) then
return "0"
end
local left,num,right = _string_match (n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
function Details:comma_value_raw (n)
4 years ago
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
3 years ago
Details:Destroy(Details.ToKFunctions)
3 years ago
table.insert(Details.ToKFunctions, Details.NoToK)
table.insert(Details.ToKFunctions, Details.ToK)
table.insert(Details.ToKFunctions, Details.ToK2)
table.insert(Details.ToKFunctions, Details.ToK0)
table.insert(Details.ToKFunctions, Details.ToKMin)
table.insert(Details.ToKFunctions, Details.ToK2Min)
table.insert(Details.ToKFunctions, Details.ToK0Min)
table.insert(Details.ToKFunctions, Details.comma_value)
3 years ago
end
function Details:UseWestNumericalSystem()
3 years ago
--short numbers
function Details:ToK (numero)
4 years ago
if (numero > 999999999) then
3 years ago
return format("%.2f", numero/1000000000) .. "B"
4 years ago
elseif (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 999) then
return _string_format ("%.1f", numero/1000) .. "K"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
function Details:ToK2 (numero)
4 years ago
if (numero > 999999999) then
3 years ago
return format("%.2f", numero/1000000000) .. "B"
4 years ago
elseif (numero > 999999) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 99999) then
3 years ago
return _math_floor(numero/1000) .. "K"
4 years ago
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. "K"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToK0 (numero)
4 years ago
if (numero > 999999999) then
3 years ago
return format("%.2f", numero/1000000000) .. "B"
4 years ago
elseif (numero > 1000000) then
return _string_format ("%.0f", numero/1000000) .. "M"
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. "K"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
function Details:ToKMin (numero)
4 years ago
if (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "m"
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. "k"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
function Details:ToK2Min (numero)
4 years ago
if (numero > 999999) then
return _string_format ("%.2f", numero/1000000) .. "m"
elseif (numero > 99999) then
3 years ago
return _math_floor(numero/1000) .. "k"
4 years ago
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. "k"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToK0Min (numero)
4 years ago
if (numero > 1000000) then
return _string_format ("%.0f", numero/1000000) .. "m"
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. "k"
end
3 years ago
4 years ago
return _string_format ("%.0f", numero)
end
3 years ago
--short numbers no numbers after comma
function Details:ToKReport (numero)
4 years ago
if (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. "K"
end
3 years ago
4 years ago
return numero
end
3 years ago
function Details:Format (n, custom)
3 years ago
n = _math_floor(n)
4 years ago
if (custom) then
if (n > 999999) then
return _string_format (custom, n/1000000) .. "M"
elseif (n > 999) then
return _string_format (custom, (n/1000))
else
return n
end
else
return Details.ToKFunctions [Details.ps_abbreviation] (nil, n)
4 years ago
end
end
3 years ago
--no changes
function Details:NoToK (numero)
3 years ago
return _math_floor(numero)
4 years ago
end
3 years ago
4 years ago
-- thanks http://richard.warburton.it
function Details:comma_value (n)
4 years ago
if (not n) then return "0" end
3 years ago
n = _math_floor(n)
4 years ago
if (n == 0) then
return "0"
end
local left,num,right = _string_match (n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
function Details:comma_value_raw (n)
4 years ago
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
3 years ago
Details:Destroy(Details.ToKFunctions)
3 years ago
table.insert(Details.ToKFunctions, Details.NoToK)
table.insert(Details.ToKFunctions, Details.ToK)
table.insert(Details.ToKFunctions, Details.ToK2)
table.insert(Details.ToKFunctions, Details.ToK0)
table.insert(Details.ToKFunctions, Details.ToKMin)
table.insert(Details.ToKFunctions, Details.ToK2Min)
table.insert(Details.ToKFunctions, Details.ToK0Min)
table.insert(Details.ToKFunctions, Details.comma_value)
3 years ago
4 years ago
--
end
3 years ago
--load western as default, the proper method is loaded within the profile
Details:UseWestNumericalSystem()
4 years ago
function Details:GetCurrentToKFunction()
return Details.ToKFunctions [Details.ps_abbreviation]
4 years ago
end
3 years ago
--alias
---transfor an integer into a string separating thousands with a comma
---@param number number
---@return string
function Details:CommaValue(number)
return Details:comma_value(number)
end
4 years ago
------------------------------------------------------------------------------------------------------------
3 years ago
--numerical system
4 years ago
function Details:SetNumericalSystemOverride (language)
4 years ago
if (not language) then
language = "auto"
end
Details.numerical_system_symbols = language
Details:Msg("NumSystem override is now:", language)
3 years ago
Details:SelectNumericalSystem()
4 years ago
end
3 years ago
function Details:GetNumericalSystem()
return Details.numerical_system
4 years ago
end
3 years ago
function Details:SelectNumericalSystem (system)
3 years ago
if (not system or type(system) ~= "number") then
system = Details.numerical_system or 1
4 years ago
end
Details.numerical_system = system
3 years ago
4 years ago
if (system == 1) then
Details:UseWestNumericalSystem()
4 years ago
elseif (system == 2) then
Details:UseEastAsianNumericalSystem()
4 years ago
end
3 years ago
Details:UpdateToKFunctions()
4 years ago
end
3 years ago
function Details:UpdateToKFunctions()
Details.atributo_damage:UpdateSelectedToKFunction()
Details.atributo_heal:UpdateSelectedToKFunction()
Details.atributo_energy:UpdateSelectedToKFunction()
Details.atributo_misc:UpdateSelectedToKFunction()
Details.atributo_custom:UpdateSelectedToKFunction()
4 years ago
Details:RefreshMainWindow(-1, true)
end
3 years ago
4 years ago
--------end of ToK functions----
3 years ago
--replacing data for custom texts
Details.string = {}
3 years ago
4 years ago
local function_cache = {}
local arguments_cache = {}
local parameters_cache = {}
3 years ago
local replace_arg = function(i)
4 years ago
return arguments_cache [tonumber(i)]
end
3 years ago
local run_function = function(str)
--cache functions
4 years ago
local func, errortext = function_cache [str]
if (not func) then
func = loadstring (str)
if (not func) then
Details:Msg("|cFFFF9900error compiling script on custom text|r: ", errortext)
4 years ago
return 0
end
DetailsFramework:SetEnvironment(func)
function_cache [str] = func
end
3 years ago
local okey, value = _pcall (func, parameters_cache [1], parameters_cache [2], parameters_cache [3], parameters_cache [4], arguments_cache[1], arguments_cache[2], arguments_cache[3])
4 years ago
if (not okey) then
Details:Msg("|cFFFF9900error on custom text|r:", value)
4 years ago
return 0
end
return value or 0
end
function Details.string.replace (str, v1, v2, v3, v4, v5, v6, v7)
4 years ago
arguments_cache [1] = v1
arguments_cache [2] = v2
arguments_cache [3] = v3
parameters_cache [1] = v4
parameters_cache [2] = v5
parameters_cache [3] = v6
parameters_cache [4] = v7
3 years ago
return (str:gsub("{data(%d+)}", replace_arg):gsub("{func(.-)}", run_function))
4 years ago
end
3 years ago
--remove a index from a hash table
function Details:tableRemove (tabela, indexName)
4 years ago
local newtable = {}
3 years ago
for hash, value in pairs(tabela) do
4 years ago
if (hash ~= indexName) then
newtable [hash] = value
end
end
return newtable
end
3 years ago
--return if the numeric table have an object
function Details:tableIN (tabela, objeto)
3 years ago
for index, valor in ipairs(tabela) do
4 years ago
if (valor == objeto) then
return index
end
end
return false
end
3 years ago
--reverse numerical table
function Details:reverse_table (t)
4 years ago
local new = {}
local index = 1
for i = #t, 1, -1 do
new [index] = t[i]
index = index + 1
end
return new
end
3 years ago
Details.table = {}
3 years ago
function Details.table.reverse (t)
4 years ago
local new = {}
local index = 1
for i = #t, 1, -1 do
new [index] = t[i]
index = index + 1
end
return new
end
--yah, i know
3 years ago
function Details.table.copy(t1, t2)
3 years ago
for key, value in pairs(t2) do
if (type(value) == "table") then
t1 [key] = Details.CopyTable(value)
4 years ago
else
t1 [key] = value
end
end
return t1
end
3 years ago
function Details.table.deploy(t1, t2)
3 years ago
for key, value in pairs(t2) do
if (type(value) == "table") then
4 years ago
t1 [key] = t1 [key] or {}
Details.table.deploy(t1 [key], t2 [key])
4 years ago
elseif (t1 [key] == nil) then
t1 [key] = value
end
end
end
3 years ago
function Details.table.overwrite (t1, t2)
3 years ago
for key, value in pairs(t2) do
if (type(value) == "table") then
4 years ago
t1 [key] = t1 [key] or {}
Details.table.overwrite (t1 [key], t2 [key])
4 years ago
else
t1 [key] = value
end
end
3 years ago
end
function Details.table.dump (t, s, deep)
4 years ago
if (type(t) == "number") then
return t
end
3 years ago
4 years ago
s = s or ""
deep = deep or 0
local space = ""
for i = 1, deep do
space = space .. " "
end
3 years ago
for key, value in pairs(t) do
local tpe = type(value)
if (type(key) == "function") then
4 years ago
key = "#function#"
3 years ago
elseif (type(key) == "table") then
4 years ago
key = "#table#"
end
3 years ago
if (type(key) ~= "string" and type(key) ~= "number") then
4 years ago
key = "unknown?"
end
3 years ago
4 years ago
if (tpe == "table") then
3 years ago
if (type(key) == "number") then
4 years ago
s = s .. space .. "[" .. key .. "] = |cFFa9ffa9table {|r\n"
else
s = s .. space .. "[\"" .. key .. "\"] = |cFFa9ffa9table {|r\n"
end
s = s .. Details.table.dump (value, nil, deep+1)
4 years ago
s = s .. space .. "|cFFa9ffa9}|r\n"
3 years ago
4 years ago
elseif (tpe == "string") then
s = s .. space .. "[\"" .. key .. "\"] = '|cFFfff1c1" .. value .. "|r'\n"
3 years ago
4 years ago
elseif (tpe == "number") then
s = s .. space .. "[\"" .. key .. "\"] = |cFFffc1f4" .. value .. "|r\n"
3 years ago
4 years ago
elseif (tpe == "function") then
s = s .. space .. "|cFFa9a9ff[\"|r" .. key .. "|cFFa9a9ff\"]|r = |cFFa9a9fffunction()|r\n"
3 years ago
4 years ago
elseif (tpe == "boolean") then
s = s .. space .. "[\"" .. key .. "\"] = |cFF99d0ff" .. (value and "true" or "false") .. "|r\n"
3 years ago
4 years ago
end
3 years ago
4 years ago
end
3 years ago
4 years ago
return s
end
3 years ago
function Details:hex (num)
4 years ago
local hexstr = '0123456789abcdef'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '00' end
3 years ago
if (string.len(s) == 1) then
4 years ago
s = "0"..s
end
return s
end
3 years ago
function Details:percent_color (value, inverted)
4 years ago
local r, g
if (value < 50) then
r = 255
else
3 years ago
r = _math_floor( 255 - (value * 2 - 100) * 255 / 100)
4 years ago
end
3 years ago
4 years ago
if (value > 50) then
g = 255
else
3 years ago
g = _math_floor( (value * 2) * 255 / 100)
4 years ago
end
3 years ago
4 years ago
if (inverted) then
return g/255, r/255, 0
else
return r/255, g/255, 0
end
end
3 years ago
--unpack more than 1 table
4 years ago
-- http://www.dzone.com/snippets/lua-unpack-multiple-tables
function Details:unpacks (...)
4 years ago
local values = {}
3 years ago
for i = 1, select('#', ...) do
for _, value in ipairs(select(i, ...)) do
4 years ago
values[ #values + 1] = value
end
end
3 years ago
return unpack(values)
4 years ago
end
3 years ago
--trim http://lua-users.org/wiki/StringTrim
function Details:trim (s)
4 years ago
local from = s:match"^%s*()"
return from > #s and "" or s:match(".*%S", from)
end
3 years ago
4 years ago
-- lua base64 codec (c) 2006-2008 by Alex Kloss - http://www.it-rfc.de - licensed under the terms of the LGPL2 - http://lua-users.org/wiki/BaseSixtyFour
do
Details._encode = {}
3 years ago
4 years ago
-- shift left
local function lsh (value,shift)
return (value*(2^shift)) % 256
end
-- shift right
local function rsh (value,shift)
return math.floor(value/2^shift) % 256
end
-- return single bit (for OR)
local function bit (x,b)
return (x % 2^b - x % 2^(b-1) > 0)
end
-- logic OR for number values
local function lor (x,y)
local result = 0
4 years ago
for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
return result
end
-- encryption table
local base64chars = {[0]='A',[1]='B',[2]='C',[3]='D',[4]='E',[5]='F',[6]='G',[7]='H',[8]='I',[9]='J',[10]='K',[11]='L',[12]='M',[13]='N',[14]='O',[15]='P',[16]='Q',[17]='R',[18]='S',[19]='T',[20]='U',[21]='V',[22]='W',[23]='X',[24]='Y',[25]='Z',[26]='a',[27]='b',[28]='c',[29]='d',[30]='e',[31]='f',[32]='g',[33]='h',[34]='i',[35]='j',[36]='k',[37]='l',[38]='m',[39]='n',[40]='o',[41]='p',[42]='q',[43]='r',[44]='s',[45]='t',[46]='u',[47]='v',[48]='w',[49]='x',[50]='y',[51]='z',[52]='0',[53]='1',[54]='2',[55]='3',[56]='4',[57]='5',[58]='6',[59]='7',[60]='8',[61]='9',[62]='-',[63]='_'}
-- function encode
-- encodes input string to base64.
function Details._encode:enc (data)
4 years ago
local bytes = {}
local result = ""
for spos=0,string.len(data)-1,3 do
for byte=1,3 do bytes[byte] = string.byte(string.sub(data,(spos+byte))) or 0 end
result = string.format('%s%s%s%s%s',result,base64chars[rsh(bytes[1],2)],base64chars[lor(lsh((bytes[1] % 4),4), rsh(bytes[2],4))] or "=",((#data-spos) > 1) and base64chars[lor(lsh(bytes[2] % 16,2), rsh(bytes[3],6))] or "=",((#data-spos) > 2) and base64chars[(bytes[3] % 64)] or "=")
end
return result
end
-- decryption table
local base64bytes = {['A']=0,['B']=1,['C']=2,['D']=3,['E']=4,['F']=5,['G']=6,['H']=7,['I']=8,['J']=9,['K']=10,['L']=11,['M']=12,['N']=13,['O']=14,['P']=15,['Q']=16,['R']=17,['S']=18,['T']=19,['U']=20,['V']=21,['W']=22,['X']=23,['Y']=24,['Z']=25,['a']=26,['b']=27,['c']=28,['d']=29,['e']=30,['f']=31,['g']=32,['h']=33,['i']=34,['j']=35,['k']=36,['l']=37,['m']=38,['n']=39,['o']=40,['p']=41,['q']=42,['r']=43,['s']=44,['t']=45,['u']=46,['v']=47,['w']=48,['x']=49,['y']=50,['z']=51,['0']=52,['1']=53,['2']=54,['3']=55,['4']=56,['5']=57,['6']=58,['7']=59,['8']=60,['9']=61,['-']=62,['_']=63,['=']=nil}
-- function decode
-- decode base64 input to string
function Details._encode:Decode (data)
4 years ago
local chars = {}
local result=""
for dpos=0,string.len(data)-1,4 do
for char=1,4 do chars[char] = base64bytes[(string.sub(data,(dpos+char),(dpos+char)) or "=")] end
result = string.format('%s%s%s%s',result,string.char(lor(lsh(chars[1],2), rsh(chars[2],4))),(chars[3] ~= nil) and string.char(lor(lsh(chars[2],4), rsh(chars[3],2))) or "",(chars[4] ~= nil) and string.char(lor(lsh(chars[3],6) % 192, (chars[4]))) or "")
end
return result
end
function Details._encode:Encode (s)
return Details._encode:enc (s)
4 years ago
end
end
3 years ago
--scale
function Details:Scale (rangeMin, rangeMax, scaleMin, scaleMax, x)
4 years ago
return 1 + (x - rangeMin) * (scaleMax - scaleMin) / (rangeMax - rangeMin)
end
3 years ago
--font color
function Details:SetFontColor(fontString, r, g, b, a)
3 years ago
r, g, b, a = gump:ParseColors(r, g, b, a)
fontString:SetTextColor(r, g, b, a)
4 years ago
end
3 years ago
--font size
function Details:SetFontSize(fontString, ...)
4 years ago
local fonte, _, flags = fontString:GetFont()
fontString:SetFont(fonte, _math_max (...), flags)
4 years ago
end
function Details:GetFontSize (fontString)
4 years ago
local _, size = fontString:GetFont()
return size
end
3 years ago
--font face
function Details:SetFontFace (fontString, fontface)
4 years ago
local _, size, flags = fontString:GetFont()
fontString:SetFont(fontface, size, flags)
4 years ago
end
function Details:GetFontFace (fontString)
4 years ago
local fontface = fontString:GetFont()
return fontface
3 years ago
end
--font outline
function Details:SetFontOutline (fontString, outline)
4 years ago
local fonte, size = fontString:GetFont()
if (outline) then
3 years ago
if (type(outline) == "boolean" and outline) then
4 years ago
outline = "OUTLINE"
elseif (outline == 1) then
outline = "OUTLINE"
elseif (outline == 2) then
outline = "THICKOUTLINE"
end
end
3 years ago
if (Details.force_font_outline ~= "") then
if (Details.force_font_outline == "OUTLINE") then
4 years ago
outline = "OUTLINE"
elseif (Details.force_font_outline == "THICKOUTLINE") then
4 years ago
outline = "THICKOUTLINE"
elseif (Details.force_font_outline == "MONOCHROME") then
4 years ago
outline = "MONOCHROME"
end
end
fontString:SetFont(fonte, size, outline)
4 years ago
end
3 years ago
function Details:UseOutline (outline)
4 years ago
outline = outline or ""
Details.force_font_outline = outline
for ID, instance in Details:ListInstances() do
4 years ago
if (instance:IsEnabled()) then
instance:RefreshBars()
instance:InstanceReset()
instance:ReajustaGump()
end
end
end
3 years ago
4 years ago
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--internal functions
4 years ago
function Details:HealthTick()
3 years ago
if (UnitExists("boss1") and IsInRaid() and IsInInstance()) then
4 years ago
local health = (UnitHealth ("boss1") or 0) / (UnitHealthMax ("boss1") or 0)
if (Details.boss1_health_percent) then
if (Details.boss1_health_percent < health) then
4 years ago
return
end
end
Details.boss1_health_percent = health
4 years ago
end
end
---do tasks that need to run every second during the combat
---also check if all members of the group are in combat or not
---when no one is in combat, the combat is over
---@return boolean bIsInCombat if true, the comabt is still going on
local combatTicker = function()
Details:TimeDataTick()
Details:BrokerTick()
Details:HealthTick()
4 years ago
local zoneName, zoneType = GetInstanceInfo()
4 years ago
if (Details.Coach.Server.IsEnabled()) then
if (Details.debug) then
print("coach server is enabled, can't leave combat...")
end
return true
--battleground
elseif (zoneType == "pvp" and Details.use_battleground_server_parser) then
4 years ago
return true
--arena
elseif (zoneType == "arena" or _InCombatLockdown()) then
return true
--is in combat
elseif (UnitAffectingCombat("player")) then
return true
elseif (IsInRaid()) then
local unitIdCache = Details222.UnitIdCache.Raid
for i = 1, GetNumGroupMembers(), 1 do
if (UnitAffectingCombat(unitIdCache[i])) then
return true
4 years ago
end
end
4 years ago
elseif (IsInGroup()) then
local unitIdCache = Details222.UnitIdCache.Party
for i = 1, GetNumGroupMembers()-1, 1 do
if (UnitAffectingCombat(unitIdCache[i])) then
return true
4 years ago
end
end
end
4 years ago
--coach feature
if (not Details.Coach.Server.IsEnabled()) then
if (Details.debug) then
Details:Msg("coach is disabled, the combat is now over!")
end
end
Details:StopCombatTicker()
Details:SairDoCombate()
return false
end
function Details:StartCombatTicker()
if (Details.CombatTicker) then
Details.CombatTicker:Cancel()
end
Details.CombatTicker = Details.Schedules.NewTicker(1, combatTicker)
end
function Details:StopCombatTicker()
if (Details.CombatTicker) then
Details.CombatTicker:Cancel()
end
4 years ago
end
function Details:FindGUIDFromName (name)
3 years ago
if (IsInRaid()) then
for i = 1, GetNumGroupMembers(), 1 do
4 years ago
local this_name, _ = UnitName ("raid"..i)
if (this_name == name) then
3 years ago
return UnitGUID("raid"..i)
4 years ago
end
end
3 years ago
elseif (IsInGroup()) then
for i = 1, GetNumGroupMembers()-1, 1 do
4 years ago
local this_name, _ = UnitName ("party"..i)
if (this_name == name) then
3 years ago
return UnitGUID("party"..i)
4 years ago
end
end
end
if (UnitName ("player") == name) then
3 years ago
return UnitGUID("player")
4 years ago
end
return nil
end
--[[ test grayscale ]]
function Details:teste_grayscale()
local instancia = Details.tabela_instancias[1]
4 years ago
for i = 1, instancia.rows_created, 1 do
local barra = instancia.barras[i]
local red, green, blue, alpha = barra.textura:GetVertexColor()
3 years ago
local grayscale = (red*0.03+green+blue) / 3 --grayscale lightness method
4 years ago
gump:GradientEffect ( barra.textura, "texture", red, green, blue, alpha, grayscale, grayscale, grayscale, alpha, 1)
end
end
local function frame_task (self, elapsed)
self.FrameTime = self.FrameTime + elapsed
if (self.HaveGradientEffect) then
3 years ago
4 years ago
local done = false
3 years ago
for index, ThisGradient in ipairs(self.gradientes) do
4 years ago
if (not ThisGradient.done) then
3 years ago
local percent = _math_min((GetTime() - ThisGradient.TimeStart) / ThisGradient.Duration * 100, 100)
4 years ago
local red_now = ThisGradient.StartRed + (percent * ThisGradient.OnePercentRed)
local green_now = ThisGradient.StartGreen + (percent * ThisGradient.OnePercentGreen)
local blue_now = ThisGradient.StartBlue + (percent * ThisGradient.OnePercentBlue)
local alpha_now = ThisGradient.StartAlpha + (percent * ThisGradient.OnePercentAlpha)
3 years ago
red_now = Saturate(red_now)
green_now = Saturate(green_now)
blue_now = Saturate(blue_now)
alpha_now = Saturate(alpha_now)
4 years ago
if (ThisGradient.ObjectType == "frame") then
3 years ago
ThisGradient.Object:SetBackdropColor(red_now, green_now, blue_now, alpha_now)
4 years ago
elseif (ThisGradient.ObjectType == "texture") then
3 years ago
ThisGradient.Object:SetVertexColor(red_now, green_now, blue_now, alpha_now)
4 years ago
end
3 years ago
4 years ago
if (percent == 100) then
if (ThisGradient.Func) then
local okey, errortext = _pcall (ThisGradient.Func, ThisGradient.FuncParam)
if (not okey) then
Details:Msg("GradientEffect() end function error:", errortext)
4 years ago
end
end
3 years ago
4 years ago
ThisGradient.done = true
done = true
end
end
end
3 years ago
4 years ago
if (done) then
local _iter = {index = 1, data = self.gradientes [1]}
3 years ago
while (_iter.data) do
4 years ago
if (_iter.data.done) then
_iter.data.Object.HaveGradientEffect = false
table.remove (self.gradientes, _iter.index)
_iter.data = self.gradientes [_iter.index]
else
_iter.index = _iter.index + 1
_iter.data = self.gradientes [_iter.index]
end
end
3 years ago
4 years ago
if (#self.gradientes < 1) then
self.HaveGradientEffect = false
end
end
end
3 years ago
4 years ago
if (not self.HaveGradientEffect) then
3 years ago
self:SetScript("OnUpdate", nil)
4 years ago
end
3 years ago
4 years ago
end
3 years ago
4 years ago
function gump:GradientEffect (Object, ObjectType, StartRed, StartGreen, StartBlue, StartAlpha, EndRed, EndGreen, EndBlue, EndAlpha, Duration, EndFunction, FuncParam)
3 years ago
if (type(StartRed) == "table" and type(StartGreen) == "table") then
4 years ago
Duration, EndFunction = StartBlue, StartAlpha
3 years ago
EndRed, EndGreen, EndBlue, EndAlpha = unpack(StartGreen)
StartRed, StartGreen, StartBlue, StartAlpha = unpack(StartRed)
elseif (type(StartRed) == "table") then
4 years ago
EndRed, EndGreen, EndBlue, EndAlpha, Duration, EndFunction = StartGreen, StartBlue, StartAlpha, EndRed, EndGreen, EndBlue
3 years ago
StartRed, StartGreen, StartBlue, StartAlpha = unpack(StartRed)
elseif (type(EndRed) == "table") then
4 years ago
Duration, EndFunction = EndGreen, EndBlue
3 years ago
EndRed, EndGreen, EndBlue, EndAlpha = unpack(EndRed)
4 years ago
end
3 years ago
4 years ago
if (not EndAlpha) then
EndAlpha = 1.0
end
if (not StartAlpha) then
StartAlpha = 1.0
end
if (not StartRed) then
StartRed = 1.0
end
if (not StartGreen) then
StartGreen = 1.0
end
if (not startBlue) then
StartBlue = 1.0
end
if (not EndRed or EndRed > 1.0) then
EndRed = 1.0
end
if (not EndGreen or EndGreen > 1.0) then
EndGreen = 1.0
end
if (not EndBlue or EndBlue > 1.0) then
EndBlue = 1.0
3 years ago
end
local GradientFrameControl = Details.listener
4 years ago
GradientFrameControl.gradientes = GradientFrameControl.gradientes or {}
3 years ago
4 years ago
for index = 1, #GradientFrameControl.gradientes do
if (GradientFrameControl.gradientes[index].Object == Object) then
GradientFrameControl.gradientes[index].done = true
end
end
3 years ago
if (EndFunction and type(EndFunction) == "string") then
4 years ago
EndFunction = loadstring (EndFunction) or false
if (EndFunction) then
DetailsFramework:SetEnvironment(EndFunction)
end
4 years ago
end
3 years ago
4 years ago
GradientFrameControl.gradientes [#GradientFrameControl.gradientes+1] = {
Object = Object,
3 years ago
ObjectType = string.lower(ObjectType),
4 years ago
Func = EndFunction,
FuncParam = FuncParam,
TimeStart = GetTime(),
Duration = Duration,
3 years ago
4 years ago
StartRed = StartRed,
StartGreen = StartGreen,
StartBlue = StartBlue,
StartAlpha = StartAlpha,
3 years ago
4 years ago
OnePercentRed = StartRed > EndRed and (StartRed - EndRed) / 100 * -1 or (EndRed - StartRed) / 100,
OnePercentGreen = StartGreen > EndGreen and (StartGreen - EndGreen) / 100 * -1 or (EndGreen - StartGreen) / 100,
OnePercentBlue = StartBlue > EndBlue and (StartBlue - EndBlue) / 100 * -1 or (EndBlue - StartBlue) / 100,
OnePercentAlpha = StartAlpha > EndAlpha and (StartAlpha - EndAlpha) / 100 * -1 or (EndAlpha - StartAlpha) /100,
}
3 years ago
4 years ago
Object.HaveGradientEffect = true
GradientFrameControl.HaveGradientEffect = true
3 years ago
if (not GradientFrameControl:GetScript("OnUpdate")) then
GradientFrameControl:SetScript("OnUpdate", frame_task)
4 years ago
end
end
3 years ago
--work around to solve the UI Frame Flashes
local onFinish = function(self)
4 years ago
if (self.showWhenDone) then
3 years ago
self.frame:SetAlpha(1)
4 years ago
else
3 years ago
self.frame:SetAlpha(0)
4 years ago
self.frame:Hide()
end
3 years ago
4 years ago
if (self.onFinishFunc) then
self:onFinishFunc (self.frame)
end
end
3 years ago
local stop = function(self)
4 years ago
local FlashAnimation = self.FlashAnimation
FlashAnimation:Stop()
end
3 years ago
local flash = function(self, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime, loopType)
4 years ago
local FlashAnimation = self.FlashAnimation
3 years ago
4 years ago
local fadeIn = FlashAnimation.fadeIn
local fadeOut = FlashAnimation.fadeOut
3 years ago
4 years ago
fadeIn:Stop()
fadeOut:Stop()
3 years ago
fadeIn:SetDuration(fadeInTime or 1)
4 years ago
fadeIn:SetEndDelay (flashInHoldTime or 0)
3 years ago
fadeOut:SetDuration(fadeOutTime or 1)
4 years ago
fadeOut:SetEndDelay (flashOutHoldTime or 0)
FlashAnimation.duration = flashDuration
FlashAnimation.loopTime = FlashAnimation:GetDuration()
FlashAnimation.finishAt = GetTime() + flashDuration
FlashAnimation.showWhenDone = showWhenDone
3 years ago
4 years ago
FlashAnimation:SetLooping (loopType or "REPEAT")
3 years ago
4 years ago
self:Show()
3 years ago
self:SetAlpha(0)
4 years ago
FlashAnimation:Play()
end
3 years ago
4 years ago
function gump:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc)
3 years ago
local FlashAnimation = frame:CreateAnimationGroup()
FlashAnimation.fadeOut = FlashAnimation:CreateAnimation("Alpha") --fade out anime
4 years ago
FlashAnimation.fadeOut:SetOrder (1)
3 years ago
4 years ago
FlashAnimation.fadeOut:SetFromAlpha (0)
FlashAnimation.fadeOut:SetToAlpha (1)
3 years ago
FlashAnimation.fadeIn = FlashAnimation:CreateAnimation("Alpha") --fade in anime
4 years ago
FlashAnimation.fadeIn:SetOrder (2)
FlashAnimation.fadeIn:SetFromAlpha (0)
FlashAnimation.fadeIn:SetToAlpha (1)
3 years ago
4 years ago
frame.FlashAnimation = FlashAnimation
FlashAnimation.frame = frame
FlashAnimation.onFinishFunc = onFinishFunc
3 years ago
FlashAnimation:SetScript("OnLoop", onLoopFunc)
FlashAnimation:SetScript("OnFinished", onFinish)
4 years ago
frame.Flash = flash
frame.Stop = stop
3 years ago
4 years ago
end
3 years ago
--todo: remove the function creation everytime this function run.
4 years ago
3 years ago
local fade_OUT_finished_func = function(frame)
4 years ago
if (frame:IsShown() and frame.fading_out) then
frame.hidden = false
frame.faded = false
frame.fading_out = false
else
frame:SetAlpha(0)
end
end
3 years ago
local just_fade_func = function(frame)
4 years ago
frame.hidden = false
frame.faded = true
frame.fading_in = false
end
3 years ago
local anim_OUT_alpha_func = function(frame)
4 years ago
frame.fading_out = false
end
3 years ago
local anim_IN_alpha_func = function(frame)
4 years ago
frame.fading_in = false
end
3 years ago
4 years ago
--this functions should be called anymore
function gump:Fade (frame, tipo, velocidade, parametros)
a = a + 1 --throw an error if called
3 years ago
if (type(frame) == "table") then
if (frame.meu_id) then --ups, � uma inst�ncia
if (parametros == "barras") then --hida todas as barras da inst�ncia
4 years ago
if (velocidade) then
for i = 1, frame.rows_created, 1 do
3 years ago
Details.FadeHandler.Fader(frame.barras[i], tipo, velocidade)
4 years ago
end
return
else
velocidade = velocidade or 0.3
for i = 1, frame.rows_created, 1 do
3 years ago
Details.FadeHandler.Fader(frame.barras[i], tipo, 0.3+(i/10))
4 years ago
end
return
end
3 years ago
elseif (parametros == "hide_barras") then --hida todas as barras da inst�ncia
4 years ago
for i = 1, frame.rows_created, 1 do
local esta_barra = frame.barras[i]
if (esta_barra.fading_in or esta_barra.fading_out) then
esta_barra.fadeInfo.finishedFunc = nil
-- _UIFrameFadeIn (esta_barra, 0.01, esta_barra:GetAlpha(), esta_barra:GetAlpha())
end
esta_barra.hidden = true
esta_barra.faded = true
esta_barra.fading_in = false
esta_barra.fading_out = false
esta_barra:Hide()
esta_barra:SetAlpha(0)
end
return
end
elseif (frame.dframework) then
frame = frame.widget
end
end
3 years ago
4 years ago
velocidade = velocidade or 0.3
3 years ago
--esse ALL aqui pode dar merda com as inst�ncias n�o ativadas
if (frame == "all") then --todas as inst�ncias
for _, instancia in ipairs(Details.tabela_instancias) do
3 years ago
if (parametros == "barras") then --hida todas as barras da inst�ncia
4 years ago
for i = 1, instancia.rows_created, 1 do
3 years ago
Details.FadeHandler.Fader(instancia.barras[i], tipo, velocidade+(i/10))
4 years ago
end
end
end
3 years ago
4 years ago
elseif (upper (tipo) == "IN") then
3 years ago
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --ja esta escondida
4 years ago
return
3 years ago
elseif (frame.fading_in) then --ja esta com uma anima��o, se for true
4 years ago
return
end
3 years ago
if (frame.fading_out) then --se tiver uma anima��o de aparecer em andamento se for true
4 years ago
frame.fading_out = false
end
-- _UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0)
frame.fading_in = true
3 years ago
4 years ago
frame.fadeInfo.finishedFunc = fade_IN_finished_func
frame.fadeInfo.finishedArg1 = frame
3 years ago
elseif (upper (tipo) == "OUT") then --aparecer
if (frame:GetAlpha() == 1 and not frame.hidden and not frame.fading_in) then --ja esta na tela
4 years ago
return
3 years ago
elseif (frame.fading_out) then --j� ta com fading out
4 years ago
return
end
3 years ago
if (frame.fading_in) then --se tiver uma anima��o de hidar em andamento se for true
4 years ago
frame.fading_in = false
end
3 years ago
4 years ago
frame:Show()
-- _UIFrameFadeOut (frame, velocidade, frame:GetAlpha(), 1.0)
frame.fading_out = true
3 years ago
4 years ago
frame.fadeInfo.finishedFunc = fade_OUT_finished_func
frame.fadeInfo.finishedArg1 = frame
3 years ago
elseif (tipo == 0) then --for�a o frame a ser mostrado
4 years ago
frame.hidden = false
frame.faded = false
frame.fading_out = false
frame.fading_in = false
frame:Show()
3 years ago
frame:SetAlpha(1)
elseif (tipo == 1) then --for�a o frame a ser hidado
4 years ago
frame.hidden = true
frame.faded = true
frame.fading_out = false
frame.fading_in = false
3 years ago
frame:SetAlpha(0)
4 years ago
frame:Hide()
3 years ago
elseif (tipo == -1) then --apenas da fade sem hidar
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --ja esta escondida
4 years ago
return
3 years ago
elseif (frame.fading_in) then --ja esta com uma anima��o, se for true
4 years ago
return
end
3 years ago
if (frame.fading_out) then --se tiver uma anima��o de aparecer em andamento se for true
4 years ago
frame.fading_out = false
end
-- _UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0)
frame.fading_in = true
frame.fadeInfo.finishedFunc = just_fade_func
frame.fadeInfo.finishedArg1 = frame
elseif (upper (tipo) == "ALPHAANIM") then
local value = velocidade
local currentApha = frame:GetAlpha()
frame:Show()
3 years ago
4 years ago
if (currentApha < value) then
3 years ago
if (frame.fading_in) then --se tiver uma anima��o de hidar em andamento se for true
4 years ago
frame.fading_in = false
frame.fadeInfo.finishedFunc = nil
end
-- _UIFrameFadeOut (frame, 0.3, currentApha, value)
frame.fading_out = true
frame.fadeInfo.finishedFunc = anim_OUT_alpha_func
frame.fadeInfo.finishedArg1 = frame
else
3 years ago
if (frame.fading_out) then --se tiver uma anima��o de hidar em andamento se for true
4 years ago
frame.fading_out = false
frame.fadeInfo.finishedFunc = nil
end
-- _UIFrameFadeIn (frame, 0.3, currentApha, value)
frame.fading_in = true
3 years ago
4 years ago
frame.fadeInfo.finishedFunc = anim_IN_alpha_func
frame.fadeInfo.finishedArg1 = frame
end
3 years ago
elseif (upper (tipo) == "ALPHA") then --setando um alpha determinado
4 years ago
if (frame.fading_in or frame.fading_out) then
frame.fadeInfo.finishedFunc = nil
-- _UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), frame:GetAlpha())
end
frame.hidden = false
frame.faded = false
frame.fading_in = false
frame.fading_out = false
frame:Show()
3 years ago
frame:SetAlpha(velocidade)
4 years ago
end
end
function Details:name_space (barra)
4 years ago
--if (barra.icone_secundario_ativo) then
-- local tamanho = barra:GetWidth()-barra.lineText4:GetStringWidth()-16-barra:GetHeight()
3 years ago
-- barra.lineText1:SetSize(tamanho-2, 15)
4 years ago
--else
3 years ago
barra.lineText1:SetSize(barra:GetWidth()-barra.lineText4:GetStringWidth()-18, 15)
4 years ago
--end
end
function Details:name_space_info (barra)
4 years ago
if (barra.icone_secundario_ativo) then
local tamanho = barra:GetWidth()-barra.lineText4:GetStringWidth()-16-barra:GetHeight()
3 years ago
barra.lineText1:SetSize(tamanho-10, 15)
4 years ago
else
local tamanho = barra:GetWidth()-barra.lineText4:GetStringWidth()-16
3 years ago
barra.lineText1:SetSize(tamanho-10, 15)
4 years ago
end
end
function Details:name_space_generic (barra, separador)
4 years ago
local texto_direita_tamanho = barra.lineText4:GetStringWidth()
local tamanho = barra:GetWidth()-texto_direita_tamanho-16
3 years ago
if (separador) then
barra.lineText1:SetSize(tamanho+separador, 10)
barra.lineText4:SetSize(texto_direita_tamanho+15, 10)
4 years ago
else
3 years ago
barra.lineText1:SetSize(tamanho-10, 15)
barra.lineText4:SetSize(texto_direita_tamanho+5, 15)
4 years ago
end
end