X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/2f553796e9d199c00890cf09e8ff86265d591696..5e453fca39c69856e27a063146a32c0ee13a52b7:/OmaRF/Indicators.lua diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index 8dd2ba9..d37383a 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -3,35 +3,54 @@ local pairs, ipairs = pairs, ipairs; local floor = math.floor; local GetTime = GetTime; local UnitAura = UnitAura; -local UnitIsPlayer = UnitIsPlayer; +local CreateFrame = CreateFrame; local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected; local CTimerAfter = C_Timer.After; -local watchedAuras = { - [53563] = "TOPRIGHT", - [156910] = "TOPRIGHT", - [200025] = "TOPRIGHT", - [200654] = "BOTTOMLEFT", -}; -local majorAuras = { - ["Psychic Assault"] = true, - ["Everburning Flames"] = true, - ["Corrupt"] = true, - ["Sleep Canister"] = true, - ["Misery"] = true, - ["Necrotic Embrace"] = true, - ["Fulminating Pulse"] = true, - ["Chilled Blood"] = true, - ["Soulblight"] = true, - ["Soulburst"] = true, - ["Soulbomb"] = true, - ["Aqua Bomb"] = true, -}; +local Settings = OmaRFSettings; +local majorAuras = Settings.MajorAuras; +local watchedAuras = {}; local updaters = {}; local updating = {}; -local positions = {"TOPRIGHT", "BOTTOMLEFT"}; -local auraFilters = {"HELPFUL", "HARMFUL"}; + +local M = {}; +OmaRFIndicators = M; +M.Class = {}; + +function M.SetupIndicators(frame, class) + frame.indBase = CreateFrame("Frame", nil, frame); + frame.indBase:SetAllPoints(); + frame.indBase:Hide(); + if M.Class[class] then + watchedAuras = M.Class[class].Auras; + frame.inds = M.Class[class].Setup(frame.indBase); + else + frame.inds = {}; + end + + frame.majorBase = CreateFrame("Frame", nil, frame); + frame.majorBase:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -10); + frame.majorBase:SetPoint("BOTTOMRIGHT"); + frame.majors = {}; + for i = 1,3 do + local tex = frame.majorBase:CreateTexture(nil, "OVERLAY"); + tex = frame.majorBase:CreateTexture(nil, "OVERLAY"); + if i == 1 then tex:SetPoint("TOPLEFT", frame.majorBase, "TOPLEFT"); + else tex:SetPoint("TOPLEFT", frame.majors[i-1], "TOPRIGHT"); end + tex:SetWidth(20); + tex:SetHeight(20); + tex:Hide(); + tex.text = frame.majorBase:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + tex.text:SetPoint("CENTER", tex, "BOTTOMRIGHT", -2, 2); + tex.text:Hide(); + tex.stack = frame.majorBase:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + tex.stack:SetPoint("CENTER", tex, "TOPLEFT", 1, 0); + tex.stack:Hide(); + tex.icon = true; + frame.majors[i] = tex; + end +end local function remaining(text, expires, current) if expires == 0 then @@ -47,7 +66,8 @@ local function remaining(text, expires, current) return true; end -local function updateIndicators(frame, unit) +local function updateIndicators(frame) + local unit = frame.displayed; if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then updating[frame] = nil; return; @@ -55,85 +75,101 @@ local function updateIndicators(frame, unit) local needUpdate = false; local current = GetTime(); - for _, pos in pairs(positions) do - local ind = frame.inds[pos]; - if ind.expires ~= nil then - needUpdate = remaining(ind.text, ind.expires, current) or needUpdate; + for _, ind in pairs(frame.inds) do + if ind.text and ind.text.expires ~= nil then + needUpdate = remaining(ind.text, ind.text.expires, current) or needUpdate; end end - for i = 1,3 do - local ind = frame.major[i]; - if ind.expires ~= nil then - needUpdate = remaining(ind.text, ind.expires, current) or needUpdate; + for _, ind in pairs(frame.majors) do + if ind.text and ind.text.expires ~= nil then + needUpdate = remaining(ind.text, ind.text.expires, current) or needUpdate; end end if needUpdate then - CTimerAfter(0.16, updaters[frame]); + CTimerAfter(0.20, updaters[frame]); else updating[frame] = nil; end end -function OmaCheckIndicators(frame, unit) - for _, pos in pairs(positions) do - frame.inds[pos].expires = nil; - frame.inds[pos]:Hide(); - frame.inds[pos].text:Hide(); +local function showInd(ind, expires, current, count, icon) + local needUpdate = false; + if ind.icon then + ind:SetTexture(icon); end - for i = 1,3 do - frame.major[i].expires = nil; - frame.major[i]:Hide(); - frame.major[i].text:Hide(); - frame.major[i].stack:Hide(); + if ind.text then + needUpdate = remaining(ind.text, expires, current); + ind.text.expires = expires; + ind.text:Show(); + end + if ind.stack and count > 1 then + ind.stack:SetText(count); + ind.stack:Show(); + end + ind:Show(); + return needUpdate; +end + +local function hideInd(ind) + if ind.text then + ind.text.expires = nil; + ind.text:Hide(); + end + if ind.stack then ind.stack:Hide() end + ind:Hide(); +end + +function M.CheckIndicators(frame, unit) + for _, ind in pairs(frame.inds) do + hideInd(ind); + end + for _, ind in pairs(frame.majors) do + hideInd(ind); end local name, icon, count, expires, caster, id; local showInds, showMajors, needUpdate = false, false, false; local majorPos = 1; + local alert = false; -- color the whole bar local current = GetTime(); - for _, filter in ipairs(auraFilters) do - local i = 1; - while true do - name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter); - if not id then break end - local pos = watchedAuras[id] or watchedAuras[name]; - if pos and UnitIsPlayer(caster) then - needUpdate = remaining(frame.inds[pos].text, expires, current); - frame.inds[pos].expires = expires; - frame.inds[pos]:Show(); - frame.inds[pos].text:Show(); - showInds = true; - end - if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then - needUpdate = remaining(frame.major[majorPos].text, expires, current); - frame.major[majorPos].expires = expires; - frame.major[majorPos]:SetTexture(icon); - frame.major[majorPos]:Show(); - frame.major[majorPos].text:Show(); - if count > 1 then - frame.major[majorPos].stack:SetText(count); - frame.major[majorPos].stack:Show(); - end - showMajors = true; - majorPos = majorPos + 1; - end - i = i + 1; + for spell, pos in pairs(watchedAuras) do + name, _, icon, count, _, _, expires = UnitAura(unit, spell, nil, "PLAYER HELPFUL"); + if name then + needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; + showInds = true; + end + end + + local i = 1; + while true do + name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, "HARMFUL"); + if not id or majorPos > 3 then break end + local major = majorAuras[id] or majorAuras[name]; + if major then + needUpdate = showInd(frame.majors[majorPos], expires, current, count, icon) or needUpdate; + if major.bar then alert = true end + showMajors = true; + majorPos = majorPos + 1; end + i = i + 1; end + if showInds or showMajors then - frame.inds:Show(); - frame.major:Show(); + frame.indBase:Show(); + frame.majorBase:Show(); if needUpdate and not updating[frame] then updating[frame] = true; -- race? -- create a function for updating the indicator local func = updaters[frame]; if not func then - func = function() updateIndicators(frame, unit) end; + func = function() updateIndicators(frame) end; updaters[frame] = func; end - CTimerAfter(0.16, func); + CTimerAfter(0.20, func); end else - frame.inds:Hide(); - frame.major:Hide(); + frame.indBase:Hide(); + frame.majorBase:Hide(); end + + return alert; end