Add battle restart

Scott Yeskie [06-05-14 - 02:26]
Add battle restart
Set each entry's main as root for its items.
Add on event rather than just scan
Filename
CyrHUD.lua
diff --git a/CyrHUD.lua b/CyrHUD.lua
index 5b413be..523db12 100644
--- a/CyrHUD.lua
+++ b/CyrHUD.lua
@@ -45,6 +45,18 @@ function CyrHUD.updateScore()
 end

 ----------------------------------------------
+-- Events
+----------------------------------------------
+function CyrHUD.eventAttackChange(_, keepID, battlegroundContext, underAttack)
+    if underAttack and GetKeepType(keepID) == KEEPTYPE_KEEP then
+        CyrHUD.add(keepID)
+    elseif CyrHUD.battles[keepID] ~= nil then
+        CyrHUD.battles[keepID]:update()
+    end
+end
+
+
+----------------------------------------------
 -- Notification UI pool
 ----------------------------------------------
 CyrHUD.entryCount = 0
@@ -62,28 +74,28 @@ CyrHUD.createEntry = function()
     entry.main:SetEdgeColor( 0, 0, 0, 0 )

     --TODO - set entry.main as root visual
-    entry.icon = WINDOW_MANAGER:CreateControl(entryName .. "icon", CyrHUD_UI, CT_TEXTURE)
+    entry.icon = WINDOW_MANAGER:CreateControl(entryName .. "icon", entry.main, CT_TEXTURE)
     entry.icon:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2)
     entry.icon:SetDimensions(40,40)

     local fontMain = "EsoUI/Common/Fonts/univers67.otf|18|soft-shadow-thick"
-    entry.name = WINDOW_MANAGER:CreateControl(entryName .. "name", CyrHUD_UI, CT_LABEL)
+    entry.name = WINDOW_MANAGER:CreateControl(entryName .. "name", entry.main, CT_LABEL)
     entry.name:SetDimensions(150,30)
     entry.name:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 35, 5)
     entry.name:SetFont(fontMain)

     --local fontSmall = "EsoUI/Common/Fonts/univers67.otf|14|soft-shadow-thin"
-    entry.defSiege = WINDOW_MANAGER:CreateControl(entryName .. "defSiege", CyrHUD_UI, CT_LABEL)
+    entry.defSiege = WINDOW_MANAGER:CreateControl(entryName .. "defSiege", entry.main, CT_LABEL)
     entry.defSiege:SetDimensions(30,30)
     entry.defSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 220, 5)
     entry.defSiege:SetFont(fontMain)

-    entry.attSiege = WINDOW_MANAGER:CreateControl(entryName .. "attSiege", CyrHUD_UI, CT_LABEL)
+    entry.attSiege = WINDOW_MANAGER:CreateControl(entryName .. "attSiege", entry.main, CT_LABEL)
     entry.attSiege:SetDimensions(30,30)
     entry.attSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 190, 5)
     entry.attSiege:SetFont(fontMain)

-    entry.time = WINDOW_MANAGER:CreateControl(entryName .. "time", CyrHUD_UI, CT_LABEL)
+    entry.time = WINDOW_MANAGER:CreateControl(entryName .. "time", entry.main, CT_LABEL)
     entry.time:SetDimensions(30,30)
     entry.time:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 250, 5)
     entry.time:SetFont(fontMain)
@@ -99,11 +111,6 @@ CyrHUD.getEntry = function()
         CyrHUD.createEntry()
     end
     CyrHUD.entries[CyrHUD.ptr].main:SetHidden(false)
-    CyrHUD.entries[CyrHUD.ptr].icon:SetHidden(false)
-    CyrHUD.entries[CyrHUD.ptr].name:SetHidden(false)
-    CyrHUD.entries[CyrHUD.ptr].defSiege:SetHidden(false)
-    CyrHUD.entries[CyrHUD.ptr].attSiege:SetHidden(false)
-    CyrHUD.entries[CyrHUD.ptr].time:SetHidden(false)
     return CyrHUD.entries[CyrHUD.ptr]
 end

@@ -111,11 +118,6 @@ CyrHUD.ptr = 0
 CyrHUD.reset = function()
     for _,p in pairs(CyrHUD.entries) do
         p.main:SetHidden(true)
-        p.icon:SetHidden(true)
-        p.name:SetHidden(true)
-        p.defSiege:SetHidden(true)
-        p.attSiege:SetHidden(true)
-        p.time:SetHidden(true)
     end
     CyrHUD.ptr = 0
 end
@@ -153,6 +155,8 @@ CyrHUD.add = function(keepID)
     if CyrHUD.battles[keepID] == nil then
         d("Adding " .. GetKeepName(keepID))
         CyrHUD.battles[keepID] = CyrHUD.Battle(keepID)
+    else
+        CyrHUD.battles[keepID]:restart()
     end
 end

@@ -162,6 +166,8 @@ CyrHUD.checkAdd = function(keepID)
         if battle:isBattle() then
             CyrHUD.battles[keepID] = battle
         end
+    elseif CyrHUD.battles[keepID]:isBattle() then
+        CyrHUD.battles[keepID]:restart()
     end
 end

@@ -186,30 +192,31 @@ end
 --TODO: Properly setup on Addon init or playerLoad
 --TODO: only show while in Cyrodiil
 local function init()
+    if WYK_QuestTracker_MQT then WYK_QuestTracker_MQT:SetAlpha(0) end
+    CyrHUD_UI:SetHidden(false)
     d("Adding keep info")
-    EVENT_MANAGER:RegisterForUpdate("CyrHUBKeepCheck", 5000, function()
+    EVENT_MANAGER:RegisterForUpdate("CyrHUDKeepCheck", 5000, function()
         CyrHUD.scanKeeps()
-    end)
-    EVENT_MANAGER:RegisterForUpdate("CyrHUBUIUpdate", 1000, function()
         CyrHUD.updateAll()
+    end)
+    EVENT_MANAGER:RegisterForUpdate("CyrHUDUIUpdate", 1000, function()
         CyrHUD.printAll()
+        CyrHUD.updateScore()
     end)
-    EVENT_MANAGER:RegisterForUpdate("ZDBUpdateAPCount", 1000, CyrHUD.updateScore)
+    EVENT_MANAGER:RegisterForEvent("CyrHUDAttackChange", EVENT_KEEP_UNDER_ATTACK_CHANGED, CyrHUD.eventAttackChange)
+    showCyrHUD = true
 end

 local showCyrHUD = false
 SLASH_COMMANDS["/cyrhud"] = function()
     if showCyrHUD then
-        EVENT_MANAGER:UnregisterForUpdate("CyrHUBKeepCheck")
-        EVENT_MANAGER:UnregisterForUpdate("CyrHUBUIUpdate")
-        EVENT_MANAGER:UnregisterForUpdate("ZDBUpdateAPCount")
+        EVENT_MANAGER:UnregisterForUpdate("CyrHUDKeepCheck")
+        EVENT_MANAGER:UnregisterForUpdate("CyrHUDUIUpdate")
+        EVENT_MANAGER:UnregisterForUpdate("CyrHUDUpdateAPCount")
         if WYK_QuestTracker_MQT then WYK_QuestTracker_MQT:SetAlpha(1) end
         CyrHUD_UI:SetHidden(true)
         showCyrHUD = false
     else
-        WYK_QuestTracker_MQT:SetAlpha(0)
-        if WYK_QuestTracker_MQT then CyrHUD_UI:SetHidden(false) end
         init()
-        showCyrHUD = true
     end
-end
+end
\ No newline at end of file