Add population bar option

Sasky [03-25-15 - 07:10]
Add population bar option
Filename
CyrHUD.lua
classes/ScoringBar.lua
menu.lua
diff --git a/CyrHUD.lua b/CyrHUD.lua
index a62f682..f3178ac 100644
--- a/CyrHUD.lua
+++ b/CyrHUD.lua
@@ -79,6 +79,13 @@ end
 CyrHUD.entryCount = 0
 CyrHUD.entries = {}

+function CyrHUD:reconfigureLabels()
+    for _,entry in pairs(self.entries) do
+        --Forces reconfigure on next update
+        entry.type = nil
+    end
+end
+
 function CyrHUD:getUIRow(index)
     if #self.entries < index then
         table.insert(self.entries, self.Label())
@@ -250,6 +257,7 @@ function CyrHUD.playerInit()
             xoff = -10,
             yoff = 60,
             trackerDisable = false,
+            showPopBars = false,
         }
         self.cfg = ZO_SavedVars:NewAccountWide("CyrHUD_SavedVars", 1.0, "config", def)
     end
diff --git a/classes/ScoringBar.lua b/classes/ScoringBar.lua
index 9507a70..c5ee173 100644
--- a/classes/ScoringBar.lua
+++ b/classes/ScoringBar.lua
@@ -31,19 +31,30 @@ 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:update()
     return self
 end

+function bar:findCampaignIndex(campaignId)
+    for i = 1, GetNumSelectionCampaigns() do
+        local id = GetSelectionCampaignId(i)
+        if campaignId == id then
+            return i
+        end
+    end
+    return 0
+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)

-    self.ad_pop = GetSelectionCampaignPopulationData(self.campaign, AD)
-    self.dc_pop = GetSelectionCampaignPopulationData(self.campaign, DC)
-    self.ep_pop = GetSelectionCampaignPopulationData(self.campaign, EP)
+    self.ad_pop = GetSelectionCampaignPopulationData(self.campaignIndex, AD)
+    self.dc_pop = GetSelectionCampaignPopulationData(self.campaignIndex, DC)
+    self.ep_pop = GetSelectionCampaignPopulationData(self.campaignIndex, EP)
 end

 local TEXT_TIME = "txt4"
@@ -52,16 +63,14 @@ local TEXT_DC, TEXT_EP, TEXT_AD = "txt1", "txt2", "txt3"
 function bar:configureLabel(label)
     d("Configuring label for status bar")
     label:exposeControls(3,4)
+    label.main:SetCenterColor(CyrHUD.info.invisColor:UnpackRGBA())
     label:getControl(ICON_DC):SetTexture(CyrHUD.info[DC].flag)
     label:getControl(ICON_EP):SetTexture(CyrHUD.info[EP].flag)
     label:getControl(ICON_AD):SetTexture(CyrHUD.info[AD].flag)
-    label:positionControl(TEXT_TIME, 90, 40, 10, 5)
-    label:positionControl(ICON_DC, 20, 40,  80, 5)
-    label:positionControl(TEXT_DC, 50, 40, 100, 5)
-    label:positionControl(ICON_EP, 20, 40, 150, 5)
-    label:positionControl(TEXT_EP, 50, 40, 170, 5)
-    label:positionControl(ICON_AD, 20, 40, 220, 5)
-    label:positionControl(TEXT_AD, 50, 40, 240, 5)
+    label:positionControl(TEXT_TIME, 90, 40, 10, 10)
+    label:positionControl(TEXT_DC, 50, 40, 100, 10)
+    label:positionControl(TEXT_EP, 50, 40, 170, 10)
+    label:positionControl(TEXT_AD, 50, 40, 240, 10)
     label:getControl(TEXT_DC):SetColor(CyrHUD.info[DC].color:UnpackRGBA())
     label:getControl(TEXT_EP):SetColor(CyrHUD.info[EP].color:UnpackRGBA())
     label:getControl(TEXT_AD):SetColor(CyrHUD.info[AD].color:UnpackRGBA())
@@ -69,6 +78,16 @@ function bar:configureLabel(label)
         label:getControl(ICON_DC):SetColor(CyrHUD.info[DC].color:UnpackRGBA())
         label:getControl(ICON_EP):SetColor(CyrHUD.info[EP].color:UnpackRGBA())
         label:getControl(ICON_AD):SetColor(CyrHUD.info[AD].color:UnpackRGBA())
+        label:positionControl(ICON_DC, 28, 28,  72, 7)
+        label:positionControl(ICON_EP, 28, 28, 142, 7)
+        label:positionControl(ICON_AD, 28, 28, 212, 7)
+    else
+        label:getControl(ICON_DC):SetColor(CyrHUD.info[ALLIANCE_NONE].color:UnpackRGBA())
+        label:getControl(ICON_EP):SetColor(CyrHUD.info[ALLIANCE_NONE].color:UnpackRGBA())
+        label:getControl(ICON_AD):SetColor(CyrHUD.info[ALLIANCE_NONE].color:UnpackRGBA())
+        label:positionControl(ICON_DC, 20, 40,  80, 10)
+        label:positionControl(ICON_EP, 20, 40, 150, 10)
+        label:positionControl(ICON_AD, 20, 40, 220, 10)
     end
 end

@@ -79,4 +98,9 @@ function bar:updateLabel(label)
     label:getControl(TEXT_DC):SetText(pre .. self.dc_points)
     label:getControl(TEXT_EP):SetText(pre .. self.ep_points)
     label:getControl(TEXT_AD):SetText(pre .. self.ad_points)
+    if CyrHUD.cfg.showPopBars then
+        label:getControl(ICON_DC):SetTexture(ZO_CampaignBrowser_GetPopulationIcon(self.dc_pop))
+        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
diff --git a/menu.lua b/menu.lua
index db2ba49..2bb776a 100644
--- a/menu.lua
+++ b/menu.lua
@@ -26,18 +26,25 @@ CyrHUD.menuPanel = {
 local c1 = "|cC5C29E" -- ZOS standard text color

 CyrHUD.menuOptions = {
-    [1] = {
+    {
         type = "checkbox",
         name = "Auto-hide Quest Tracker",
         tooltip = "Hides quest trackers when CyrHUD is shown",
         getFunc = function() return CyrHUD.cfg.trackerDisable or false end,
         setFunc = function(v) CyrHUD.cfg.trackerDisable = v end
     },
-    [2] = {
+    {
         type = "description",
         text = c1 .. "Currently only works for Wykkyd's MQT"
     },
-    [3] = {
+    {
+        type = "checkbox",
+        name = "Population bars for flags",
+        tooltip = "Shows current population instead of alliance flag in summary",
+        getFunc = function() return CyrHUD.cfg.showPopBars or false end,
+        setFunc = function(v) CyrHUD.cfg.showPopBars = v; CyrHUD:reconfigureLabels() end,
+    },
+    {
         type = "description",
         title = "Keybind",
         text = c1 .. "See the controls game menu for setting a keybind for the |cFFFFFF/cyrhud" .. c1 .. " command.\n"