a7ed5dd - Fix target cast bar when changing targets
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Tue, 6 Feb 2018 02:12:59 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Tue, 6 Feb 2018 02:12:59 +0000
OmaUF/CastBar.lua

index 7485a8a..f64cff2 100644 (file)
@@ -53,14 +53,15 @@ local function startCast(bar, unit, channeling)
     local name, icon, startTime, endTime, noInterrupt, id;
     if channeling then
         name, _, _, icon, startTime, endTime, _, noInterrupt = UnitChannelInfo(unit);
+        if not startTime or not endTime then return nil end
         bar.channeling = true;
         bar.cast.color = channelingColor;
     else
         _, _, name, icon, startTime, endTime, _, _, noInterrupt, id = UnitCastingInfo(unit);
+        if not startTime or not endTime then return nil end
         bar.channeling = nil;
         bar.cast.color = castingColor;
     end
-    if not startTime or not endTime then return nil end
     bar.startTime = startTime / 1000;
     bar.endTime = endTime / 1000;
     -- don't show samwise for non-existent icons
@@ -97,6 +98,12 @@ local events = {
     ["UNIT_SPELLCAST_START"] = function(bar, unit)
         startCast(bar, unit);
     end,
+    ["PLAYER_TARGET_CHANGED"] = function(bar)
+        bar:Hide();
+        if not startCast(bar, bar.unit) then
+            startCast(bar, bar.unit, true);
+        end
+    end,
     ["UNIT_SPELLCAST_CHANNEL_START"] = function(bar, unit)
         startCast(bar, unit, true);
     end,
@@ -122,6 +129,8 @@ local function onEvent(bar, event, unit)
     if unit == bar.unit or (bar.unit == "player" and unit == "vehicle") then
         --print(unit, event)
         events[event](bar, unit);
+    elseif event == "PLAYER_TARGET_CHANGED" then
+        events[event](bar);
     end
 end
 
@@ -137,6 +146,7 @@ function M.RegisterCastEvents(bar)
     bar:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE");
     bar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE");
     bar:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE");
+    if bar.unit == "target" then bar:RegisterEvent("PLAYER_TARGET_CHANGED") end
     bar:SetScript("OnUpdate", onUpdate);
     -- trigger initial check
     if not startCast(bar, bar.unit) then