Fix issue with campaign population bars

Scott Yeskie [07-25-16 - 04:11]
Fix issue with campaign population bars

When logging into Cyrodiil directly, the campaign data isn't generated. Addeded call
to generate campaign data and re-determine the index used for population bars.

Still unknown: if QueryCampaignSelectionData() needs to be called to update the population bars.
Filename
CyrHUD.txt
classes/ScoringBar.lua
diff --git a/CyrHUD.txt b/CyrHUD.txt
index 97386db..b1d4c53 100644
--- a/CyrHUD.txt
+++ b/CyrHUD.txt
@@ -1,6 +1,6 @@
 ## APIVersion: 100015
 ## Title: CyrHUD
-## Version: 1.4.0
+## Version: 1.4.1
 ## Author: Sasky
 ## SavedVariables: CyrHUD_SavedVars
 ## OptionalDependsOn: LibAddonMenu-2.0
diff --git a/classes/ScoringBar.lua b/classes/ScoringBar.lua
index 8f1faba..50e4c8b 100644
--- a/classes/ScoringBar.lua
+++ b/classes/ScoringBar.lua
@@ -31,19 +31,27 @@ local EP = ALLIANCE_EBONHEART_PACT
 function CyrHUD.ScoringBar.new(campaign)
     local self = setmetatable({}, CyrHUD.ScoringBar)
     self.campaign = campaign or GetCurrentCampaignId()
-    self.campaignIndex = self:findCampaignIndex(self.campaign)
+    self:determineCampaignIndex()
     self:update()
     return self
 end

-function bar:findCampaignIndex(campaignId)
+function bar:determineCampaignIndex()
+    d("Calling findCampaignIndex for " .. self.campaign)
+    self.campaignIndex = 0
     for i = 1, GetNumSelectionCampaigns() do
         local id = GetSelectionCampaignId(i)
-        if campaignId == id then
-            return i
+        if self.campaign == id then
+            d("Result: " .. i)
+            self.campaignIndex = i
         end
     end
-    return 0
+
+    if self.campaignIndex == 0 then
+        d("No campaign index. Running QueryCampaignSelectionData()")
+        QueryCampaignSelectionData()
+        zo_callLater(function() self:determineCampaignIndex() end, 2000)
+    end
 end

 function bar:update()
@@ -101,4 +109,4 @@ function bar:updateLabel(label)
         label:getControl(ICON_AD):SetTexture(ZO_CampaignBrowser_GetPopulationIcon(self.ad_pop))
         label:getControl(ICON_EP):SetTexture(ZO_CampaignBrowser_GetPopulationIcon(self.ep_pop))
     end
-end
\ No newline at end of file
+end