Copy over initial code from scratchpad addon

Sasky [03-31-15 - 06:24]
Copy over initial code from scratchpad addon
Filename
ChampionBar.lua
ChampionBar.txt
EnlightenmentPoolBar.lua
VPMaxBar.lua
diff --git a/ChampionBar.lua b/ChampionBar.lua
index cbdfbda..fd924d3 100644
--- a/ChampionBar.lua
+++ b/ChampionBar.lua
@@ -19,9 +19,78 @@

 ChampionBar = ChampionBar or {}

+local function replaceBars()
+    local ppb = PLAYER_PROGRESS_BAR
+    ppb.barTypeClasses[PPB_CLASS_EP] = ChampionBar.EPBarType
+    ppb.barTypeClasses[PPB_CLASS_VP] = ChampionBar.VPMaxBarType
+    ppb.nextBarType = 1
+    ppb.barTypes = {}
+
+    PPB_XP = ppb:InstantiateBarType(PPB_CLASS_XP)
+    PPB_VP = ppb:InstantiateBarType(PPB_CLASS_VP)
+    PPB_CP = ppb:InstantiateBarType(PPB_CLASS_CP)
+    PPB_EP = ppb:InstantiateBarType(PPB_CLASS_EP)
+    ppb:InitializeLastValues()
+end
+
+local function replaceHandlers()
+    function PLAYER_PROGRESS_BAR:RefreshSecondaryBar()
+        local secondaryBarInfo = self:GetSecondaryBarInfo()
+        if secondaryBarInfo then
+            local current = secondaryBarInfo:GetCurrent()
+            local max = secondaryBarInfo:GetLevelSize(secondaryBarInfo:GetLevel())
+            if max == nil then
+                current = 1
+                max = 1
+            end
+            self.secondaryBarControl:SetMinMax(0, max)
+            self.secondaryBarControl:SetValue(current)
+            local gradient = secondaryBarInfo:GetBarGradient()
+            ZO_StatusBar_SetGradientColor(self.secondaryBarControl, gradient)
+            ZO_StatusBar_SetGradientColor(self.enlightenedBarControl, gradient)
+            local icon = secondaryBarInfo:GetIcon()
+            if icon then
+                self.secondaryBarLevelTypeIcon:SetTexture(icon)
+            end
+            self.secondaryBarLevelTypeIcon:SetHidden(not icon)
+            local txt = current == 0 and "" or "ENLIGHTENED"
+            self.secondaryBarControl:GetNamedChild("SecondaryLevelType"):SetText(txt)
+        end
+        self.secondaryBarControl:SetHidden(secondaryBarInfo == nil)
+    end
+
+    function PLAYER_PROGRESS_BAR:Show()
+        self:SetBarState("showing")
+
+        local barTypeInfo = self:GetBarTypeInfo()
+        AAA = barTypeInfo
+        ZO_StatusBar_SetGradientColor(self.barControl, barTypeInfo:GetBarGradient())
+
+        self:RefreshSecondaryBar()
+
+        for i = 1, self.glowContainer:GetNumChildren() do
+            local glowTexture = self.glowContainer:GetChild(i)
+            glowTexture:SetColor(barTypeInfo.barGlowColor:UnpackRGB())
+        end
+
+        self.levelTypeLabel:SetText(zo_strformat(SI_LEVEL_BAR_LABEL, barTypeInfo.levelTypeText))
+
+        if(barTypeInfo:GetIcon() ~= nil) then
+            self.levelTypeIcon:SetHidden(false)
+            self.levelTypeIcon:SetTexture(barTypeInfo.icon)
+        else
+            self.levelTypeIcon:SetHidden(true)
+        end
+
+        self.control:SetHidden(false)
+        self.fadeTimeline:PlayForward()
+    end
+end
+
 local function onAddOnLoaded(_, addonName)
     if addonName ~= "ChampionBar" then return end
-
+    replaceBars()
+    replaceHandlers()
 end

 EVENT_MANAGER:RegisterForEvent("ChampionBarReplace", EVENT_ADD_ON_LOADED, onAddOnLoaded)
\ No newline at end of file
diff --git a/ChampionBar.txt b/ChampionBar.txt
index 8de32b0..5aad8cc 100644
--- a/ChampionBar.txt
+++ b/ChampionBar.txt
@@ -3,4 +3,6 @@
 ## Version: 1.0.0
 ## Author: Sasky

+VPMaxBar.lua
+EnlightenmentPoolBar.lua
 ChampionBar.lua
\ No newline at end of file
diff --git a/EnlightenmentPoolBar.lua b/EnlightenmentPoolBar.lua
new file mode 100644
index 0000000..1fca211
--- /dev/null
+++ b/EnlightenmentPoolBar.lua
@@ -0,0 +1,103 @@
+--[[============================================================================
+  This file is a part of ChampionBar
+
+  Copyright (C) 2015 Scott Yeskie (Sasky)
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  ============================================================================]]
+
+---
+--- Create new type for Enlightenment Pool
+---
+ChampionBar = ChampionBar or {}
+local EPBarType = ZO_Object:Subclass()
+ChampionBar.EPBarType = EPBarType
+
+function EPBarType:New(barTypeClass, barTypeId)
+    local obj = ZO_Object.New(self)
+    obj.barTypeClass = barTypeClass
+    obj.barTypeId = barTypeId
+    obj:Initialize()
+    obj:InitializeLastValues()
+    return obj
+end
+
+function EPBarType:Initialize()
+    self.barGradient = { ZO_ColorDef:New("EEFF66"), ZO_ColorDef:New("EEFF00") }
+    self.levelTypeText = "Enlightenment Pool"
+    self.tooltipCurrentMaxFormat = 120000
+    self.icon = "EsoUI/Art/Champion/champion_points_health_icon-HUD-32.dds"
+end
+
+function EPBarType:InitializeLastValues()
+    self.lastLevel = self:GetLevel()
+    self.lastCurrent = self:GetCurrent()
+end
+
+function EPBarType:Equals(barTypeClass, ...)
+    if(self.barTypeClass == barTypeClass) then
+        for i = 1, select("#", ...) do
+            local param = select(i, ...)
+            if(param ~= self.params[i]) then
+                return false
+            end
+        end
+        return true
+    end
+    return false
+end
+
+function EPBarType:GetEnlightenedPool()
+    if IsEnlightenedAvailableForCharacter() then
+        return 1
+    else
+        return 0
+    end
+end
+
+function EPBarType:GetEnlightenedTooltip()
+    return "Enlightenment: " .. self:GetCurrent() .. "/" ..self:GetLevelSize()
+end
+
+function EPBarType:GetSecondaryBarType()
+    return nil
+end
+
+function EPBarType:GetLevelSize(rank)
+    return 1200000
+end
+
+function EPBarType:GetLevel()
+    return GetPlayerChampionPointsEarned()
+end
+
+function EPBarType:GetCurrent()
+    return GetEnlightenedPool()
+end
+
+function EPBarType:GetBarGradient()
+    return self.barGradient
+end
+
+function EPBarType:GetShownAttribute()
+    local level = self:GetLevel()
+    if self:GetLevelSize(level) ~= nil then
+        level = level + 1
+    end
+    return GetChampionPointAttributeForRank(level)
+end
+
+function EPBarType:GetIcon()
+    return "/esoui/art/champion/champion_star_burst.dds"
+end
\ No newline at end of file
diff --git a/VPMaxBar.lua b/VPMaxBar.lua
new file mode 100644
index 0000000..0c091d6
--- /dev/null
+++ b/VPMaxBar.lua
@@ -0,0 +1,111 @@
+--[[============================================================================
+  This file is a part of ChampionBar
+
+  Copyright (C) 2015 Scott Yeskie (Sasky)
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  ============================================================================]]
+
+---
+--- Overwrite the VPBarType to show CP in the main bar
+---
+ChampionBar = ChampionBar or {}
+local VPMaxBarType = ZO_Object:Subclass()
+ChampionBar.VPMaxBarType =VPMaxBarType
+
+function VPMaxBarType:New(barTypeClass, barTypeId)
+    local obj = ZO_Object.New(self)
+    obj.barTypeClass = barTypeClass
+    obj.barTypeId = barTypeId
+    obj:Initialize()
+    obj:InitializeLastValues()
+    return obj
+end
+
+function VPMaxBarType:Initialize()
+    self.barGradient = ZO_CP_BAR_GRADIENT_COLORS[self:GetShownAttribute()]
+    self.barGlowColor = ZO_ColorDef:New(1,1,1,.3)
+    self.levelTypeText = GetString(SI_EXPERIENCE_CHAMPION_RANK_LABEL)
+    self.tooltipCurrentMaxFormat = SI_CHAMPION_POINTS_CURRENT_MAX
+    self.icon = self:GetIcon()
+end
+
+function VPMaxBarType:InitializeLastValues()
+    self.lastLevel = self:GetLevel()
+    self.lastCurrent = self:GetCurrent()
+end
+
+function VPMaxBarType:Equals(barTypeClass, ...)
+    if(self.barTypeClass == barTypeClass) then
+        for i = 1, select("#", ...) do
+            local param = select(i, ...)
+            if(param ~= self.params[i]) then
+                return false
+            end
+        end
+        return true
+    end
+    return false
+end
+
+function VPMaxBarType:GetEnlightenedPool()
+    return 0
+end
+
+function VPMaxBarType:GetEnlightenedTooltip()
+    return nil
+end
+
+function VPMaxBarType:GetSecondaryBarType()
+    return PPB_EP
+end
+
+function VPMaxBarType:GetLevelSize(rank)
+    return GetChampionXPInRank(rank)
+end
+
+function VPMaxBarType:GetLevel()
+    return GetPlayerChampionPointsEarned()
+end
+
+function VPMaxBarType:GetCurrent()
+    return GetPlayerChampionXP()
+end
+
+function VPMaxBarType:GetBarGradient()
+    return ZO_CP_BAR_GRADIENT_COLORS[self:GetShownAttribute()]
+end
+
+function VPMaxBarType:GetShownAttribute()
+    local level = self:GetLevel()
+    if self:GetLevelSize(level) ~= nil then
+        level = level + 1
+    end
+    return GetChampionPointAttributeForRank(level)
+end
+
+function VPMaxBarType:GetBarGradient()
+    return ZO_CP_BAR_GRADIENT_COLORS[self:GetShownAttribute()]
+end
+
+local CHAMPION_ATTRIBUTE_HUD_ICONS =
+{
+    [ATTRIBUTE_HEALTH] = "EsoUI/Art/Champion/champion_points_health_icon-HUD-32.dds",
+    [ATTRIBUTE_MAGICKA] = "EsoUI/Art/Champion/champion_points_magicka_icon-HUD-32.dds",
+    [ATTRIBUTE_STAMINA] = "EsoUI/Art/Champion/champion_points_stamina_icon-HUD-32.dds",
+}
+
+function VPMaxBarType:GetIcon()
+    return CHAMPION_ATTRIBUTE_HUD_ICONS[self:GetShownAttribute()]
+end
\ No newline at end of file