view Main.lua @ 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 6e160ec1ef0f
children d2cbfe498c4d
line wrap: on
line source


RTT = LibStub("AceAddon-3.0"):NewAddon("RaidTargetTactics", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("RaidTargetTactics")


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",
    text = "Raid Target Tactics",
    icon = "Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_8",
    OnClick = function() RTT:OnIconClick() end,
    OnTooltipShow = function(tooltip)
        tooltip:AddLine("Raid Target Tactics")
        tooltip:AddLine(L.Minimap_Icon_Tooltip)
    end,
})

local defaults = {
    profile = {
        visible = true,
        minimap = {
            hide = false,
        },
    },
}

function RTT:OnInitialize()
    self.db = LibStub("AceDB-3.0"):New("TacticsSettings", defaults, true)

    LDBIcon:Register("RTTIcon", RTTIcon, self.db.profile.minimap)
    self:InitFrame()
    if self.f:IsShown() ~= self.db.profile.visible then
        if self.db.profile.visible then
            self:ShowFrame()
        else
            self:HideFrame()
        end
    end
end

function RTT:InitFrame()
    self.f = CreateFrame("Frame", nil, UIParent)
    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()
    if self.db.profile.visible then
        self:HideFrame()
    else
        self:ShowFrame()
    end
    self.db.profile.visible = not self.db.profile.visible
end

function RTT:HideFrame()
    self.f:Hide()
end

function RTT:ShowFrame()
    self.f:Show()
end