Reorganize initialization

Sasky [03-28-15 - 21:48]
Reorganize initialization

Fixes issue when switching directly campign > campaign.
Filename
CyrHUD.lua
classes/Info.lua
classes/ScoringBar.lua
diff --git a/CyrHUD.lua b/CyrHUD.lua
index 80c1ea4..75ee45a 100644
--- a/CyrHUD.lua
+++ b/CyrHUD.lua
@@ -174,14 +174,8 @@ function CyrHUD:init()
     self:disableQuestTrackers()
     self.ui:SetHidden(false)

-
-    --Get initial scan
-    self.battles = {}
-    self.battleContext = BGQUERY_LOCAL
-    self.campaign = GetCurrentCampaignId()
-    self.statusBars = {}
-    table.insert(self.statusBars, self.ScoringBar())
-    self:scanKeeps()
+    --Populate data
+    self:refresh()

     --Add events
     EVENT_MANAGER:RegisterForUpdate("CyrHUDKeepCheck", 5000, function()
@@ -198,6 +192,17 @@ function CyrHUD:init()
     EVENT_MANAGER:RegisterForEvent('CyrHUD', EVENT_ACTION_LAYER_PUSHED, self.actionLayerChange)
 end

+function CyrHUD:refresh()
+    --Get initial scan
+    self.battles = {}
+    self.battleContext = BGQUERY_LOCAL
+    self.campaign = GetCurrentCampaignId()
+    --Could separate this with a data refresh eventually, but just do a hard reset for now
+    self.statusBars = {}
+    table.insert(self.statusBars, self.ScoringBar())
+    self:scanKeeps()
+end
+
 function CyrHUD:disableQuestTrackers()
     self.trackers = {}
     if self.cfg.trackerDisable then
@@ -240,35 +245,64 @@ end
 --TODO: only show while in Cyrodiil?
 SLASH_COMMANDS["/cyrhud"] = CyrHUD.toggle

+--Called once. Handles controls, etc.
+function CyrHUD.addonInit()
+    local self = CyrHUD
+    --Create UI
+    self.ui = WINDOW_MANAGER:CreateTopLevelWindow("CyrHUD_UI")
+    self.ui:SetWidth(280)
+    self.ui:SetResizeToFitDescendents(true)
+    self.ui:SetMouseEnabled(true)
+    self.ui:SetMovable(true)
+    self.ui:SetClampedToScreen(true)
+    self.ui:SetHandler("OnMoveStop", self.saveWindowPosition)
+    --Create settings menu
+    local LAM = LibStub("LibAddonMenu-2.0")
+    LAM:RegisterAddonPanel("CyrHUD-LAM", self.menuPanel)
+    LAM:RegisterOptionControls("CyrHUD-LAM", self.menuOptions)
+    self.initLAM = true
+
+    --Init saved variables
+    local def = {
+        xoff = -10,
+        yoff = 60,
+        trackerDisable = false,
+        showPopBars = false,
+    }
+    self.cfg = ZO_SavedVars:NewAccountWide("CyrHUD_SavedVars", 1.0, "config", def)
+
+    if not self.cfg.aprOff and ((GetDate() % 1000) == 401) then
+        local side = GetUnitAlliance("player")
+        local color = self.info[side].color
+        for i=1,3 do
+            self.info[i].color = self.info[side].opcolor
+        end
+        self.info[side].color = color
+    end
+
+    if (GetDate() % 1000)== 328 then
+        --NOTE: If you see this before 4/1, please don't share
+        table.insert(self.menuOptions,{
+            type = "checkbox",
+            name = "April Fools Fix",
+            tooltip = "Turn on to restore normal coloring",
+            warning = "Requires a /reloadui",
+            getFunc = function() return CyrHUD.cfg.aprOff or false end,
+            setFunc = function(v) CyrHUD.cfg.aprOff = v end,
+        })
+    end
+end
+
 function CyrHUD.playerInit()
     local self = CyrHUD
     if not self.initLAM then
-        --Create UI
-        self.ui = WINDOW_MANAGER:CreateTopLevelWindow("CyrHUD_UI")
-        self.ui:SetWidth(280)
-        self.ui:SetResizeToFitDescendents(true)
-        self.ui:SetMouseEnabled(true)
-        self.ui:SetMovable(true)
-        self.ui:SetClampedToScreen(true)
-        self.ui:SetHandler("OnMoveStop", self.saveWindowPosition)
-        --Create settings menu
-        local LAM = LibStub("LibAddonMenu-2.0")
-        LAM:RegisterAddonPanel("CyrHUD-LAM", self.menuPanel)
-        LAM:RegisterOptionControls("CyrHUD-LAM", self.menuOptions)
-        self.initLAM = true
-
-        --Init saved variables
-        local def = {
-            xoff = -10,
-            yoff = 60,
-            trackerDisable = false,
-            showPopBars = false,
-        }
-        self.cfg = ZO_SavedVars:NewAccountWide("CyrHUD_SavedVars", 1.0, "config", def)
+        self.addonInit()
     end

     if IsPlayerInAvAWorld() then
-        if not self.visible then
+        if self.visible then
+            self:refresh()
+        else
             self:init()
         end
     elseif self.visible then
diff --git a/classes/Info.lua b/classes/Info.lua
index f9d20d7..4124e9d 100644
--- a/classes/Info.lua
+++ b/classes/Info.lua
@@ -61,7 +61,9 @@ CyrHUD.info[EP][KEEPTYPE_OUTPOST] = "/esoui/art/mappins/ava_outpost_ebonheart.dd
 CyrHUD.info[EP][10 + RESOURCETYPE_FOOD] = "/esoui/art/mappins/ava_farm_ebonheart.dds"
 CyrHUD.info[EP][10 + RESOURCETYPE_ORE] = "/esoui/art/mappins/ava_mine_ebonheart.dds"
 CyrHUD.info[EP][10 + RESOURCETYPE_WOOD] = "/esoui/art/mappins/ava_lumbermill_ebonheart.dds"
-
+CyrHUD.info[AD].opcolor = ZO_ColorDef:New(.7, .4, .73, 1)
+CyrHUD.info[DC].opcolor = ZO_ColorDef:New(.9, .65, .3, 1)
+CyrHUD.info[EP].opcolor = ZO_ColorDef:New(.6222, .7, .4532, 1)
 --/esoui/art/campaign/overview_scrollicon_aldmeri.dds
 --/esoui/art/campaign/overview_scrollicon_daggefall.dds
 --/esoui/art/campaign/overview_scrollicon_ebonheart.dds
\ No newline at end of file
diff --git a/classes/ScoringBar.lua b/classes/ScoringBar.lua
index 75499d0..8f1faba 100644
--- a/classes/ScoringBar.lua
+++ b/classes/ScoringBar.lua
@@ -47,7 +47,6 @@ function bar:findCampaignIndex(campaignId)
 end

 function bar:update()
-    local time = CyrHUD.formatTime(GetSecondsUntilCampaignScoreReevaluation(cID), true)
     self.ad_points = GetCampaignAlliancePotentialScore(self.campaign, AD)
     self.dc_points = GetCampaignAlliancePotentialScore(self.campaign, DC)
     self.ep_points = GetCampaignAlliancePotentialScore(self.campaign, EP)