Hi guys,
I'm programming a very simple addon, just to learn a bit. It's a addon that shows a simple XP bar. The problem is that sometimes (not everytime), after reloading the UI, my status bar (that's inside a frame) doesn't appear. The rest of the UI loads normally, just my status bar doesn't appear. The code is below:
Code:
local function hex2rgb(hex)
local r, g, b = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)
return (tonumber(r, 16)/255), (tonumber(g, 16)/255), (tonumber(b, 16)/255)
end
local config = {
borderColor = '222222',
backgroundColor = '777777',
borderSize = 1,
align = 'CENTER',
position = { x = 0, y = 0 },
width = 300,
height = 6
}
-- Background Frame
local bgframe = CreateFrame('Frame', nil)
bgframe:SetWidth(config.width)
bgframe:SetHeight(config.height)
bgframe:SetPoint(config.align, config.position.x, config.position.y)
bgframe:SetFrameStrata('LOW')
bgframe.texture = bgframe:CreateTexture()
bgframe.texture:SetAllPoints(bgframe)
bgframe.texture:SetTexture(hex2rgb(config.borderColor))
-- Status Bar Frame -> this is the guy that doesn't appear
local StatusBar = CreateFrame('StatusBar', nil, bgframe)
StatusBar:SetWidth(config.width - (2 * config.borderSize))
StatusBar:SetHeight(config.height - (2 * config.borderSize))
StatusBar:SetPoint('TOPLEFT', config.borderSize, config.borderSize * (-1))
StatusBar.texture = StatusBar:CreateTexture()
StatusBar.texture:SetAllPoints(StatusBar)
StatusBar.texture:SetTexture(hex2rgb(config.backgroundColor))
StatusBar:SetMinMaxValues(0, 100)
StatusBar:SetValue(50) -- 50% just for tests
local _, playerClass = UnitClass("player")
local classColor = RAID_CLASS_COLORS[playerClass]
local r, g, b = classColor.r, classColor.g, classColor.b
local BarTexture = StatusBar:CreateTexture()
BarTexture:SetGradient('VERTICAL', 0.3, 0.3, 0.3, 0.8, 0.8, 0.8)
BarTexture:SetTexture(r, g, b)
StatusBar:SetStatusBarTexture(BarTexture) -- maybe the problem is here, really dunno
Really don't know what is the problem
Sry for my poor english.
-- Editing
In order to explain better, there's a image below: