Create Label class for showing info

Sasky [03-22-15 - 07:41]
Create Label class for showing info
Filename
CyrHUD.lua
CyrHUD.xml
classes/Battle.lua
classes/Label.lua
diff --git a/CyrHUD.lua b/CyrHUD.lua
index cb43f4d..9317a4c 100644
--- a/CyrHUD.lua
+++ b/CyrHUD.lua
@@ -20,11 +20,11 @@ CyrHUD = CyrHUD or {}
 ----------------------------------------------
 -- Utility
 ----------------------------------------------
-function bl(val)
+local function bl(val)
 	if val == nil then return "NIL" elseif val then return "T" else return "F" end
 end

-function nn(val)
+local function nn(val)
     if val == nil then return "NIL" end
     return val
 end
@@ -88,60 +88,11 @@ end
 ----------------------------------------------
 CyrHUD.entryCount = 0
 CyrHUD.entries = {}
-CyrHUD.createEntry = function()
-    local num = CyrHUD.entryCount + 1
-    local yoff = num*35-5
-    CyrHUD.entryCount = num
-    local entry = {}
-    local entryName = "CyrHUDEntry" .. num
-    entry.main = WINDOW_MANAGER:CreateControl(entryName .. "main", CyrHUD_UI, CT_BACKDROP)
-    entry.main:SetDimensions(280, 35)
-    entry.main:SetAnchor(TOPLEFT, CyrHUD_UI, TOPLEFT, 0, yoff)
-    entry.main:SetCenterColor( 0, 0, 0, .3 )
-    entry.main:SetEdgeColor( 0, 0, 0, 0 )
-
-    entry.icon = WINDOW_MANAGER:CreateControl(entryName .. "icon", entry.main, CT_TEXTURE)
-    entry.icon:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2)
-    entry.icon:SetDimensions(40,40)
-    entry.icon:SetDrawLayer(2)
-
-    entry.ua = WINDOW_MANAGER:CreateControl(entryName .. "ua", entry.main, CT_TEXTURE)
-    entry.ua:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2)
-    entry.ua:SetDimensions(40,40)
-    entry.ua:SetTexture("/esoui/art/mappins/ava_attackburst_64.dds")
-    entry.ua:SetDrawLayer(1)
-
-    local fontMain = "EsoUI/Common/Fonts/univers67.otf|18|soft-shadow-thick"
-    entry.name = WINDOW_MANAGER:CreateControl(entryName .. "name", entry.main, CT_LABEL)
-    entry.name:SetDimensions(150,30)
-    entry.name:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 35, 5)
-    entry.name:SetFont(fontMain)
-
-    --local fontSmall = "EsoUI/Common/Fonts/univers67.otf|14|soft-shadow-thin"
-    entry.defSiege = WINDOW_MANAGER:CreateControl(entryName .. "defSiege", entry.main, CT_LABEL)
-    entry.defSiege:SetDimensions(30,30)
-    entry.defSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 220, 5)
-    entry.defSiege:SetFont(fontMain)
-
-    entry.attSiege = WINDOW_MANAGER:CreateControl(entryName .. "attSiege", entry.main, CT_LABEL)
-    entry.attSiege:SetDimensions(30,30)
-    entry.attSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 190, 5)
-    entry.attSiege:SetFont(fontMain)
-
-    entry.time = WINDOW_MANAGER:CreateControl(entryName .. "time", entry.main, CT_LABEL)
-    entry.time:SetDimensions(30,30)
-    entry.time:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 250, 5)
-    entry.time:SetFont(fontMain)
-    entry.time:SetColor(.8,.8,.8)
-
-    table.insert(CyrHUD.entries, entry)
-    return entry
-end

 CyrHUD.getEntry = function()
     CyrHUD.ptr = CyrHUD.ptr + 1
     if #CyrHUD.entries < CyrHUD.ptr then
-        CyrHUD.createEntry()
+        table.insert(CyrHUD.entries, CyrHUD.Label())
     end
     CyrHUD.entries[CyrHUD.ptr].main:SetHidden(false)
     return CyrHUD.entries[CyrHUD.ptr]
@@ -150,7 +101,7 @@ end
 CyrHUD.ptr = 0
 CyrHUD.reset = function()
     for _,p in pairs(CyrHUD.entries) do
-        p.main:SetHidden(true)
+        p:Hide()
     end
     CyrHUD.ptr = 0
 end
diff --git a/CyrHUD.xml b/CyrHUD.xml
index 0e4064e..3a26609 100644
--- a/CyrHUD.xml
+++ b/CyrHUD.xml
@@ -43,9 +43,20 @@
                        wrapMode="ELLIPSIS" text="" horizontalAlignment="LEFT" opacity="0.85">
                     <Anchor point="TOPLEFT" offsetX="240" />
                 </Label>
-
+<!--
+                <Control name="CyrHUD_Label" virtual="true">
+                    <Backdrop name="$(parent)Main" centerColor="0000005A" edgeColor="00000000">
+                        <Anchor point="TOPLEFT" relativeTo="$(parent)" />
+                        <Dimensions x="280" y="35" />
+                    </Backdrop>
+
+                    <Texture name="$(parent)Icon" layer="OVERLAY">
+                        <Dimensions x="40" y="40" />
+                        <Anchor point="TOPLEFT" relativePoint="TOPLEFT" relativeTo="$(parent)Main" offsetX="35" offsetY="5" />
+                    </Texture>
+                </Control>
+-->
             </Controls>
-
         </TopLevelControl>
     </Controls>
 </GuiXml>
\ No newline at end of file
diff --git a/classes/Battle.lua b/classes/Battle.lua
index 5ff580b..f53db08 100644
--- a/classes/Battle.lua
+++ b/classes/Battle.lua
@@ -1,19 +1,3 @@
---[[
-  * CyrHUD.Battle class
-  * Author: Sasky
-  * Contains all information about a conflict
-]]--
-
-if CyrHUD == nil then
-    --noinspection GlobalCreationOutsideO
-    CyrHUD = {}
-end
-
-local function n0(val) if val == nil then return 0 end return val end
-
--- Setup class
-CyrHUD.Battle = {}
-CyrHUD.Battle.__index = CyrHUD.Battle
 -- This file is part of CyrHUD
 --
 -- (C) 2014 Scott Yeskie (Sasky)
@@ -31,6 +15,13 @@ CyrHUD.Battle.__index = CyrHUD.Battle
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.

+CyrHUD = CyrHUD or {}
+
+local function n0(val) if val == nil then return 0 end return val end
+
+-- Setup class
+CyrHUD.Battle = {}
+CyrHUD.Battle.__index = CyrHUD.Battle
 setmetatable(CyrHUD.Battle, {
     __call = function (cls, ...)
         return cls.new(...)
diff --git a/classes/Label.lua b/classes/Label.lua
new file mode 100644
index 0000000..3ffcf4f
--- /dev/null
+++ b/classes/Label.lua
@@ -0,0 +1,135 @@
+-- This file is part of CyrHUD
+--
+-- (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/>.
+
+-- Setup class
+CyrHUD.Label = {}
+CyrHUD.Label.__index = CyrHUD.Label
+setmetatable(CyrHUD.Label, {
+    __call = function (cls, ...)
+        return cls.new(...)
+    end,
+})
+
+local Label = CyrHUD.Label
+
+function Label.new()
+    local self = setmetatable({}, CyrHUD.Label)
+    self.labelType = "uninit"
+    self.num = CyrHUD.entryCount + 1
+    self.entryName = "CyrHUDEntry" .. self.num
+    self.entry = {}
+    local entry = self.entry
+
+    --Main control/backdrop
+    local yoff = self.num*35-5
+    entry.main = WINDOW_MANAGER:CreateControl(self.entryName .. "main", CyrHUD_UI, CT_BACKDROP)
+    entry.main:SetDimensions(280, 35)
+    entry.main:SetAnchor(TOPLEFT, CyrHUD_UI, TOPLEFT, 0, yoff)
+    entry.main:SetCenterColor( 0, 0, 0, .3 )
+    entry.main:SetEdgeColor( 0, 0, 0, 0 )
+
+    -- Images
+    entry.img1 = WINDOW_MANAGER:CreateControl(self.entryName .. "img1", entry.main, CT_TEXTURE)
+    entry.img2 = WINDOW_MANAGER:CreateControl(self.entryName .. "img2", entry.main, CT_TEXTURE)
+    entry.img3 = WINDOW_MANAGER:CreateControl(self.entryName .. "img3", entry.main, CT_TEXTURE)
+
+    --Labels
+    entry.txt1 = WINDOW_MANAGER:CreateControl(self.entryName .. "txt1", entry.main, CT_LABEL)
+    entry.txt2 = WINDOW_MANAGER:CreateControl(self.entryName .. "txt2", entry.main, CT_LABEL)
+    entry.txt3 = WINDOW_MANAGER:CreateControl(self.entryName .. "txt3", entry.main, CT_LABEL)
+    entry.txt4 = WINDOW_MANAGER:CreateControl(self.entryName .. "txt4", entry.main, CT_LABEL)
+end
+
+function Label:Hide()
+    self.entry.main:SetHidden(true)
+end
+
+function Label:Show()
+    self.entry.main:SetHidden(false)
+end
+
+function Label:getControl(name)
+    return self.entry[name]
+end
+
+function Label:moveControl(name, x, y)
+    if self.entry[name] and name ~= "main" then
+        self.entry[name]:ClearAnchors()
+        self.entry[name]:SetAnchor(TOPLEFT, self.entry.main, TOPLEFT, x, y)
+    end
+end
+
+function Label:resizeControl(name, width, height)
+    if self.entry[name] and name ~= "main" then
+        self.entry[name]:SetDimensions(width, height)
+    end
+end
+
+function Label:reconfigure(type, labelObj)
+    if self.type ~= labelObj.type then
+        labelObj:configure(self)
+    end
+end
+
+--Original create label
+function Label:create(entryName, num)
+    local yoff = num*35-5
+    self.entry = {}
+    local entry = {}
+    entry.main = WINDOW_MANAGER:CreateControl(entryName .. "main", CyrHUD_UI, CT_BACKDROP)
+    entry.main:SetDimensions(280, 35)
+    entry.main:SetAnchor(TOPLEFT, CyrHUD_UI, TOPLEFT, 0, yoff)
+    entry.main:SetCenterColor( 0, 0, 0, .3 )
+    entry.main:SetEdgeColor( 0, 0, 0, 0 )
+
+    entry.icon = WINDOW_MANAGER:CreateControl(entryName .. "icon", entry.main, CT_TEXTURE)
+    entry.icon:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2)
+    entry.icon:SetDimensions(40,40)
+    entry.icon:SetDrawLayer(2)
+
+    entry.ua = WINDOW_MANAGER:CreateControl(entryName .. "ua", entry.main, CT_TEXTURE)
+    entry.ua:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2)
+    entry.ua:SetDimensions(40,40)
+    entry.ua:SetTexture("/esoui/art/mappins/ava_attackburst_64.dds")
+    entry.ua:SetDrawLayer(1)
+
+    local fontMain = "EsoUI/Common/Fonts/univers67.otf|18|soft-shadow-thick"
+    entry.name = WINDOW_MANAGER:CreateControl(entryName .. "name", entry.main, CT_LABEL)
+    entry.name:SetDimensions(150,30)
+    entry.name:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 35, 5)
+    entry.name:SetFont(fontMain)
+
+    --local fontSmall = "EsoUI/Common/Fonts/univers67.otf|14|soft-shadow-thin"
+    entry.defSiege = WINDOW_MANAGER:CreateControl(entryName .. "defSiege", entry.main, CT_LABEL)
+    entry.defSiege:SetDimensions(30,30)
+    entry.defSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 220, 5)
+    entry.defSiege:SetFont(fontMain)
+
+    entry.attSiege = WINDOW_MANAGER:CreateControl(entryName .. "attSiege", entry.main, CT_LABEL)
+    entry.attSiege:SetDimensions(30,30)
+    entry.attSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 190, 5)
+    entry.attSiege:SetFont(fontMain)
+
+    entry.time = WINDOW_MANAGER:CreateControl(entryName .. "time", entry.main, CT_LABEL)
+    entry.time:SetDimensions(30,30)
+    entry.time:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 250, 5)
+    entry.time:SetFont(fontMain)
+    entry.time:SetColor(.8,.8,.8)
+
+    table.insert(CyrHUD.entries, entry)
+    return entry
+end