Switch to using ZO_ColorDef for color management

Sasky [03-25-15 - 04:26]
Switch to using ZO_ColorDef for color management
Filename
classes/Battle.lua
classes/Info.lua
classes/Label.lua
classes/ScoringBar.lua
diff --git a/classes/Battle.lua b/classes/Battle.lua
index 2ccb283..6e9d88c 100644
--- a/classes/Battle.lua
+++ b/classes/Battle.lua
@@ -112,23 +112,21 @@ function CyrHUD.Battle:updateLabel(label)
     --Keep name
     local name = label:getControl(L_NAME)
     name:SetText(self.keepName)
-    local color = CyrHUD.info[self.defender].color
-    name:SetColor(color.r, color.g, color.b)
+    name:SetColor(CyrHUD.info[self.defender].color:UnpackRGBA())
     --Time
     label:getControl(L_TIME):SetText(self:getDuration())
     --Defensive siege
     local ds, dc = self:getDefSiege()
     local defSiege = label:getControl(L_DEF_SIEGE)
     defSiege:SetText(ds)
-    defSiege:SetColor(dc.r, dc.g, dc.b)
+    defSiege:SetColor(dc:UnpackRGBA())
     --Attacing siege
     local as, ac = self:getAttSiege()
     local attSiege = label:getControl(L_ATT_SIEGE)
     attSiege:SetText(as)
-    attSiege:SetColor(ac.r, ac.g, ac.b)
+    attSiege:SetColor(ac:UnpackRGBA())
     --Background color
-    local r,g,b,a = self:getBGColor()
-    label.main:SetCenterColor(r,g,b,a)
+    label.main:SetCenterColor(self:getBGColor():UnpackRGBA())
 end


@@ -169,16 +167,16 @@ end
 function CyrHUD.Battle:getBGColor()
     if self.endBattle then
         if self.defender == GetUnitAlliance("player") then
-            return .2,.5,.2,.6
+            return CyrHUD.info.defendedColor
         end
-        return .5,.5,.5,.3
+        return CyrHUD.info.endAttackColor
     end
     local delta = GetDiffBetweenTimeStamps(GetTimeStamp(), self.startBattle)
     if delta < 60 then
-        return (60-delta)/120,0,0,.3
+        CyrHUD.info.newAttackColor:Lerp(CyrHUD.info.defaultBGColor, delta/120)
     end

-    return 0,0,0,.3
+    return CyrHUD.info.defaultBGColor
 end

 --[[
@@ -222,7 +220,7 @@ function CyrHUD.Battle:getAttSiege()
             end
         end
     end
-    local color = { hex = "CCCCCC", r=.8, g=.8, b=.8 }
+    local color = CyrHUD.info[ALLIANCE_NONE].color
     if faction and faction ~= 0 then
         color = CyrHUD.info[faction].color
     end
diff --git a/classes/Info.lua b/classes/Info.lua
index 9e57758..ea592eb 100644
--- a/classes/Info.lua
+++ b/classes/Info.lua
@@ -24,23 +24,28 @@ local EP = ALLIANCE_EBONHEART_PACT
 CyrHUD.info = {}
 CyrHUD.info.underAttack = "/esoui/art/mappins/ava_attackburst_64.dds"
 CyrHUD.info.noIcon = "/esoui/art/mappins/ava_largekeep_neutral.dds"
+CyrHUD.info.defendedColor = ZO_ColorDef:New(.2, .5, .2, .6)
+CyrHUD.info.newAttackColor = ZO_ColorDef:New(.5, 0, 0, .3)
+CyrHUD.info.endAttackColor = ZO_ColorDef:New(.5, .5, .5, .3)
+CyrHUD.info.defaultBGColor = ZO_ColorDef:New(0, 0, 0, .3)
+CyrHUD.info.invisColor = ZO_ColorDef:New(0,0,0,0)
 CyrHUD.info[ALLIANCE_NONE] = {}
-CyrHUD.info[ALLIANCE_NONE].color = { hex = "CCCCCC", r = .8, g = .8, b = .8 }
+CyrHUD.info[ALLIANCE_NONE].color = ZO_ColorDef:New(.8, .8, .8, 1)
 CyrHUD.info[ALLIANCE_NONE][KEEPTYPE_KEEP] = "/esoui/art/mappins/ava_largekeep_neutral.dds"
 CyrHUD.info[ALLIANCE_NONE][KEEPTYPE_OUTPOST] = "/esoui/art/mappins/ava_largekeep_neutral.dds"
 CyrHUD.info[ALLIANCE_NONE][10 + RESOURCETYPE_FOOD] = "/esoui/art/mappins/ava_farm_neutral.dds"
 CyrHUD.info[ALLIANCE_NONE][10 + RESOURCETYPE_ORE] = "/esoui/art/mappins/ava_mine_neutral.dds"
 CyrHUD.info[ALLIANCE_NONE][10 + RESOURCETYPE_WOOD] = "/esoui/art/mappins/ava_lumbermill_neutral.dds"
 CyrHUD.info[AD] = {}
-CyrHUD.info[AD].color = { hex = "c3aa4a", r = .765, g = .667, b = .290 }
-CyrHUD.info[AD].flag = ""/esoui/art/ava/ava_allianceflag_aldmeri.dds""
+CyrHUD.info[AD].color = ZO_ColorDef:New(.765, .667, .290, 1)
+CyrHUD.info[AD].flag = "/esoui/art/ava/ava_allianceflag_aldmeri.dds"
 CyrHUD.info[AD][KEEPTYPE_KEEP] = "/esoui/art/mappins/ava_largekeep_aldmeri.dds"
 CyrHUD.info[AD][KEEPTYPE_OUTPOST] = "/esoui/art/mappins/ava_outpost_aldmeri.dds"
 CyrHUD.info[AD][10 + RESOURCETYPE_FOOD] = "/esoui/art/mappins/ava_farm_aldmeri.dds"
 CyrHUD.info[AD][10 + RESOURCETYPE_ORE] = "/esoui/art/mappins/ava_mine_aldmeri.dds"
 CyrHUD.info[AD][10 + RESOURCETYPE_WOOD] = "/esoui/art/mappins/ava_lumbermill_aldmeri.dds"
 CyrHUD.info[DC] = {}
-CyrHUD.info[DC].color = { hex = "688fb2", r = .408, g = .560, b = .698 }
+CyrHUD.info[DC].color = ZO_ColorDef:New(.408, .560, .698, 1)
 CyrHUD.info[DC].flag = "/esoui/art/ava/ava_allianceflag_daggerfall.dds"
 CyrHUD.info[DC][KEEPTYPE_KEEP] = "/esoui/art/mappins/ava_largekeep_daggerfall.dds"
 CyrHUD.info[DC][KEEPTYPE_OUTPOST] = "/esoui/art/mappins/ava_outpost_daggerfall.dds"
@@ -48,7 +53,7 @@ CyrHUD.info[DC][10 + RESOURCETYPE_FOOD] = "/esoui/art/mappins/ava_farm_daggerfal
 CyrHUD.info[DC][10 + RESOURCETYPE_ORE] = "/esoui/art/mappins/ava_mine_daggerfall.dds"
 CyrHUD.info[DC][10 + RESOURCETYPE_WOOD] = "/esoui/art/mappins/ava_lumbermill_daggerfall.dds"
 CyrHUD.info[EP] = {}
-CyrHUD.info[EP].color = { hex = "de5c4f", r = .871, g = .361, b = .310 }
+CyrHUD.info[EP].color = ZO_ColorDef:New(.871, .361, .310, 1)
 CyrHUD.info[EP].flag = "/esoui/art/ava/ava_allianceflag_ebonheart.dds"
 CyrHUD.info[EP][KEEPTYPE_KEEP] = "/esoui/art/mappins/ava_largekeep_ebonheart.dds"
 CyrHUD.info[EP][KEEPTYPE_OUTPOST] = "/esoui/art/mappins/ava_outpost_ebonheart.dds"
diff --git a/classes/Label.lua b/classes/Label.lua
index 02f35db..c6523cc 100644
--- a/classes/Label.lua
+++ b/classes/Label.lua
@@ -42,8 +42,8 @@ function Label.new()
     self.main = WINDOW_MANAGER:CreateControl(self.entryName .. "main", CyrHUD_UI, CT_BACKDROP)
     self.main:SetDimensions(280, 35)
     self.main:SetAnchor(TOPLEFT, CyrHUD_UI, TOPLEFT, 0, yoff)
-    self.main:SetCenterColor( 0, 0, 0, .3 )
-    self.main:SetEdgeColor( 0, 0, 0, 0 )
+    self.main:SetCenterColor(CyrHUD.info.defaultBGColor:UnpackRGBA())
+    self.main:SetEdgeColor(CyrHUD.info.invisColor:UnpackRGBA())

     -- Images
     entry.img1 = WINDOW_MANAGER:CreateControl(self.entryName .. "img1", self.main, CT_TEXTURE)
diff --git a/classes/ScoringBar.lua b/classes/ScoringBar.lua
index f663cd1..5913e1a 100644
--- a/classes/ScoringBar.lua
+++ b/classes/ScoringBar.lua
@@ -28,9 +28,9 @@ local AD = ALLIANCE_ALDMERI_DOMINION
 local DC = ALLIANCE_DAGGERFALL_COVENANT
 local EP = ALLIANCE_EBONHEART_PACT

-function CyrHUD.ScoringBar.new()
+function CyrHUD.ScoringBar.new(campaign)
     local self = setmetatable({}, CyrHUD.ScoringBar)
-    self.campaign = GetCurrentCampaignId()
+    self.campaign = campaign or GetCurrentCampaignId()
     self:update()
     return self
 end
@@ -63,9 +63,9 @@ function bar:configureLabel(label)
     label:positionControl(TEXT_AD, 240, 5, 50, 40)
     --TODO: Set font
     if CyrHUD.cfg.showPopBars then
-        label:getControl(ICON_DC):SetColor()
-        label:getControl(ICON_EP):SetColor()
-        label:getControl(ICON_AD):SetColor()
+        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())
     end
 end