changeset 10:f93b554bb7cf

class implementation, Icon class for Raid Target Icons
author Jay Bird <a4blank@yahoo.com>
date Sun, 28 Nov 2010 18:59:31 +0300
parents 7201711b23e9
children d2cbfe498c4d
files Icon.lua Main.lua class.lua
diffstat 3 files changed, 138 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Icon.lua	Sun Nov 28 18:59:31 2010 +0300
@@ -0,0 +1,30 @@
+
+local RaidIcon = class()
+local _G = _G
+
+function RaidIcon:init(num)
+    self.num = num
+end
+
+function RaidIcon:draw(parent, x, y)
+    local frame = CreateFrame("Frame", nil, parent)
+    frame:SetWidth(16)
+    frame:SetHeight(16)
+    frame:SetPoint("TOPLEFT", x, y)
+    local tex = frame:CreateTexture(nil, "ARTWORK")
+    tex:SetAllPoints(frame)
+    tex:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_" .. self.num)
+    frame:Show()
+    return frame
+end
+
+_G.RaidIcons = {}
+_G.RaidIcons[1] = RaidIcon("1")
+_G.RaidIcons[2] = RaidIcon("2")
+_G.RaidIcons[3] = RaidIcon("3")
+_G.RaidIcons[4] = RaidIcon("4")
+_G.RaidIcons[5] = RaidIcon("5")
+_G.RaidIcons[6] = RaidIcon("6")
+_G.RaidIcons[7] = RaidIcon("7")
+_G.RaidIcons[8] = RaidIcon("8")
+
--- a/Main.lua	Mon Nov 22 08:40:26 2010 -0500
+++ b/Main.lua	Sun Nov 28 18:59:31 2010 +0300
@@ -6,6 +6,7 @@
 
 local LDB = LibStub("LibDataBroker-1.1", true)
 local LDBIcon = LibStub("LibDBIcon-1.0", true)
+local AceGUI = LibStub("AceGUI-3.0")
 
 local RTTIcon = LibStub("LibDataBroker-1.1"):NewDataObject("RTTIcon", {
     type = "data source",
@@ -32,7 +33,7 @@
 
     LDBIcon:Register("RTTIcon", RTTIcon, self.db.profile.minimap)
     self:InitFrame()
-    if self.f:IsShown() != self.db.profile.visible then
+    if self.f:IsShown() ~= self.db.profile.visible then
         if self.db.profile.visible then
             self:ShowFrame()
         else
@@ -43,9 +44,66 @@
 
 function RTT:InitFrame()
     self.f = CreateFrame("Frame", nil, UIParent)
-    self.f:SetWidth(100)
+    self.f:SetWidth(300)
     self.f:SetHeight(200)
+    self.f:SetAlpha(0.8)
     self.f:SetPoint("LEFT", UIParent, "LEFT", 10, 0)
+    --[[self.f:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
+                        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
+                        tile = true, tileSize = 16, edgeSize = 16,
+                        insets = { left = 4, right = 4, top = 4, bottom = 4 }})
+    ]]
+    local backdrop = {
+      -- path to the background texture
+      bgFile = "Interface\\FrameGeneral\\UI-Background-Marble",
+      -- path to the border texture
+      edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border",
+      -- true to repeat the background texture to fill the frame, false to scale it
+      tile = true,
+      -- size (width or height) of the square repeating background tiles (in pixels)
+      tileSize = 256,
+      -- thickness of edge segments and square size of edge corners (in pixels)
+      edgeSize = 32,
+      -- distance from the edges of the frame to those of the background texture (in pixels)
+      insets = {
+        left = 11,
+        right = 12,
+        top = 12,
+        bottom = 11
+      }
+    }
+    self.f:SetBackdrop(backdrop)
+    self.f:SetFrameStrata("HIGH")
+    --self.f:SetBackdropColor(0, 0, 0, 0.5)
+
+    self.fields = {}
+    self.selects = {}
+    for num, icon in ipairs(RaidIcons) do
+        icon:draw(self.f, 20, num * -20)
+
+        local field = CreateFrame("EditBox", "__RTT_EditBox_" .. tostring(num), self.f, "InputBoxTemplate")
+        field:SetAutoFocus(false)
+        field:SetFontObject(ChatFontNormal)
+        field:SetWidth(100)
+        field:SetHeight(16)
+        field:SetTextInsets(0, 0, 3, 3)
+        field:SetPoint("TOPLEFT", 40, num * -20)
+        table.insert(self.fields, field)
+        field:Show()
+
+        local userSelect = AceGUI:Create("Dropdown")
+        userSelect.frame:SetParent(self.f)
+        local raid = {}
+        for i=1, GetNumRaidMembers() do
+            raid[i] = UnitName("raid" .. i)
+        end
+        userSelect:SetList(raid)
+        userSelect:SetWidth(100)
+        userSelect:SetHeight(16)
+        userSelect:SetPoint("TOPLEFT", 160, num * -20)
+        table.insert(self.selects, userSelect)
+        userSelect.frame:Show()
+    end
 end
 
 function RTT:OnIconClick()
@@ -54,7 +112,7 @@
     else
         self:ShowFrame()
     end
-    self.db.profile.visible = !self.db.profile.visible
+    self.db.profile.visible = not self.db.profile.visible
 end
 
 function RTT:HideFrame()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/class.lua	Sun Nov 28 18:59:31 2010 +0300
@@ -0,0 +1,47 @@
+-- class.lua
+-- taken from http://lua-users.org/wiki/SimpleLuaClasses
+-- Compatible with Lua 5.1 (not 5.0).
+function class(base, init)
+   local c = {}    -- a new class instance
+   if not init and type(base) == 'function' then
+      init = base
+      base = nil
+   elseif type(base) == 'table' then
+    -- our new class is a shallow copy of the base class!
+      for i,v in pairs(base) do
+         c[i] = v
+      end
+      c._base = base
+   end
+   -- the class will be the metatable for all its objects,
+   -- and they will look up their methods in it.
+   c.__index = c
+
+   -- expose a constructor which can be called by <classname>(<args>)
+   local mt = {}
+   mt.__call = function(class_tbl, ...)
+   local obj = {}
+   setmetatable(obj,c)
+   if class_tbl.init then
+      class_tbl.init(obj,...)
+   else 
+      -- make sure that any stuff from the base class is initialized!
+      if base and base.init then
+      base.init(obj, ...)
+      end
+   end
+   return obj
+   end
+   c.init = init
+   c.is_a = function(self, klass)
+      local m = getmetatable(self)
+      while m do 
+         if m == klass then return true end
+         m = m._base
+      end
+      return false
+   end
+   setmetatable(c, mt)
+   return c
+end
+