View Single Post
07-08-09, 07:29 PM   #2
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Gradients with a stats display



I'll start with some scripts I've been using. This is the same layout code I used for the stats display, copy and paste this into the default or your character's profile. This also demonstrates the built-in class coloring.

If you want to only use the gradient box, you could remove the stats panel (name = "Stats") and tweak the dimensions, locations, and colors. (Font in the screenshot is 04B_03)

Code:
lpanels:CreateLayout("Stats", {
    -- Stat Container
    {    name = "Container",
        anchor_to = "TOP",
        width = 280, height = 20,
        x_off = 0, y_off = -30,
        bg_alpha = 0,
    },
    -- Left mid-section of the box
    {    name = "BoxL", parent = "Container",
        anchor_to = "LEFT",
        width = "50%", height = "100%",
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0, gradient_alpha = 0.2,
    },
    -- Right mid-section
    {    name = "BoxR", parent = "Container",
        anchor_to = "RIGHT",
        width = "50%", height = "100%",
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0.2, gradient_alpha = 0,
    },
    -- Top Left gradient line
    {    name = "LineTL",
        parent = "BoxL", anchor_to = "TOP",
        width = "100%", height = 1,
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0, gradient_alpha = 0.8,
    },
    -- Top right line
    {    name = "LineTR",
        parent = "BoxR", anchor_to = "TOP",
        width = "100%", height = 1,
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0.8, gradient_alpha = 0,
    },
    -- Bottom left line
    {    name = "LineBL",
        parent = "BoxL", anchor_to = "BOTTOM",
        width = "100%", height = 1,
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0, gradient_alpha = 0.8,
    },
    -- Bottom right line
    {    name = "LineBR",
        parent = "BoxR", anchor_to = "BOTTOM",
        width = "100%", height = 1,
        gradient = "H",
        bg_color = "CLASS", gradient_color = "CLASS",
        bg_alpha = 0.8, gradient_alpha = 0,
    },
    -- Text display
    {    name = "Stats", parent = "Container",
        anchor_to = "CENTER", anchor_from = "CENTER",
        text = {
            string = function()
                -- monies
                local gold = format("%.1f|cffffd700g|r",GetMoney()/10000)

                -- durability
                local durability = 100
                for i = 1, 11 do
                    if GetInventoryItemDurability(i) ~= nil then
                        local dur, max = GetInventoryItemDurability(i)
                        local perc = dur / max * 100
                        if perc < durability then
                            durability = floor(perc)
                        end
                    end
                end

                -- fps
                local fps = floor(GetFramerate())

                -- memory
                local memory = 0
                UpdateAddOnMemoryUsage()
                for i = 1, GetNumAddOns() do
                    if IsAddOnLoaded(i) then
                        memory = memory + GetAddOnMemoryUsage(i)
                    end
                end
                memory = format("%.1f", memory/1024)

                -- latency
                local latency = select(3,GetNetStats())

                return format(":: %s :: %s%%dur :: %sfps :: %smB :: %sms ::", gold, durability, fps, memory, latency)
            end, update = 1,
            size=10, shadow=1, font = "Fonts\\FRIZQT__.TTF",
        }
    }
}); lpanels:ApplyLayout(nil, "Stats")
Afker "mod"



If you're like me and you have auto-clear afk turned off, you may sometimes unintentionally spam your friends. This functionality is much like LazyAFK.

Whether this is useful for you or not, I'm hoping to demonstrate how simple addons can be created with relative ease using this framework. Also note that you may create multiple text objects per frame.

Code:
lpanels:CreateLayout("Afker", {
    {    name = "AFK", anchor_to = "TOP", y_off = -210,
        bg_alpha = 0.5, width = 200, height = 75,
        border = "SOLID", border_color = "1 1 0",
        text = {
        -- "YOU ARE AFK!"
            {    string = "You are AFK!", anchor_to = "TOP", y_off = -10,
                shadow=1, font = "Fonts\\FRIZQT__.TTF", size=14,
            },
            -- "0:00" TIMER
            {    string=function()
                    if afk_timer then
                        local secs = mod(time() - afk_timer, 60)
                        local mins = floor((time() - afk_timer) / 60)
                        return format("%s:%02.f", mins, secs)
                    end
                end, update=0.1,
                shadow=1, font = "Fonts\\FRIZQT__.TTF", size=16,
                anchor_to = "CENTER", color = "1 0.3 0.3"
            },
            -- "RIGHT CLICK TO HIDE"
            {    string="Right click to hide.", anchor_to="BOTTOM", y_off = 10,
                shadow=1, size=8, font = "Fonts\\FRIZQT__.TTF",
            }
        },
        OnLoad = function(self)
            self:RegisterEvent("PLAYER_FLAGS_CHANGED")
            self:Hide()
        end,
        OnEvent = function(self)
            if UnitIsAFK("player") and not afk_timer then
                self.text2:SetText("0:00")
                afk_timer = time()
                self:Show()
            elseif not UnitIsAFK("player") then
                self:Hide()
                afk_timer = nil
            end
        end,
        OnClick = function(self, b)
            self:Hide()
            if b == "LeftButton" then SendChatMessage("", "AFK") end
        end,
        OnEnter = function(self) self.bg:SetTexture(.1,.1,.1,.5) end,
        OnLeave = function(self) self.bg:SetTexture(0,0,0,.5) end
    }
}); lpanels:ApplyLayout(nil, "Afker")
Whether or not these "addons" are useful to you, I would hope you get the feel for how panel codes should be set up.

Last edited by Katae : 08-31-11 at 05:01 AM.
  Reply With Quote