146 lines
3.9 KiB
Lua
146 lines
3.9 KiB
Lua
local name, addon = ...
|
|
local f = CreateFrame('FRAME', nil, UIParent)
|
|
local bars = {}
|
|
local function layoutProto(self)
|
|
-- print('val', self:GetValue(), self:GetMinMaxValues())
|
|
if(tonumber(self:GetValue())==0) then
|
|
self:Hide()
|
|
else
|
|
self:Show()
|
|
end
|
|
end
|
|
local layouts = {
|
|
['defaultLayout'] = {
|
|
['texture'] = "Interface\\TargetingFrame\\UI-StatusBar",
|
|
['tile'] = false,
|
|
['width'] = 160,
|
|
['height'] = 16,
|
|
['value'] = 100,
|
|
['color'] = { 1, 1, 1, 1 },
|
|
['script'] = layoutProto,
|
|
}
|
|
}
|
|
local tip = CreateFrame("GameTooltip", format("%s_tooltip", name), nil, "GameTooltipTemplate")
|
|
tip:SetScale(0.75)
|
|
local function OnEnter(self)
|
|
tip:ClearLines()
|
|
tip:SetOwner(self, "ANCHOR_CURSOR");
|
|
self.tooltip = tip
|
|
local p = self:GetParent()
|
|
if(p.StatusBarOnEnter and type(p.StatusBarOnEnter) == 'function') then
|
|
p:StatusBarOnEnter(self)
|
|
end
|
|
tip:Show()
|
|
end
|
|
local function OnLeave(self)
|
|
local p = self:GetParent()
|
|
if(p.StatusBarOnLeave and type(p.StatusBarOnLeave) == 'function') then
|
|
p:StatusBarOnLeave(self)
|
|
end
|
|
self.tooltip:Hide()
|
|
self.tooltip = nil
|
|
end
|
|
local bar_methods = {}
|
|
function bar_methods:Release()
|
|
self['active'] = false
|
|
self['class'] = nil
|
|
self:Hide()
|
|
end
|
|
function bar_methods:SetText(text, text2)
|
|
if(text) then
|
|
self['fontstring']:SetText(text)
|
|
end
|
|
if(text2) then
|
|
self['fontstring2']:SetText(text2)
|
|
end
|
|
end
|
|
function addon:GetClassColors(class, undef)
|
|
if(class) then
|
|
if(RAID_CLASS_COLORS[class]) then
|
|
local col = RAID_CLASS_COLORS[class]
|
|
return {col['r'], col['g'], col['b'], col['a'] or 1, undef}
|
|
end
|
|
end
|
|
return self:GetClassColors('WARRIOR', true)
|
|
end
|
|
function bar_methods:SetColorByClass(class)
|
|
local r, g, b, a, u = unpack(addon:GetClassColors(class))
|
|
if(not u) then
|
|
self['class'] = class
|
|
else
|
|
self['class'] = nil
|
|
end
|
|
self:SetStatusBarColor(r, g, b, a)
|
|
end
|
|
function bar_methods:GetText()
|
|
return self['fontstring']:GetText()
|
|
end
|
|
function bar_methods:GetText2()
|
|
return self['fontstring2']:GetText()
|
|
end
|
|
function bar_methods:SetLayout(layout)
|
|
if(not layout or not layouts[layout]) then
|
|
layout = 'defaultLayout'
|
|
end
|
|
local d = layouts['defaultLayout']
|
|
local l = layouts[layout]
|
|
self:SetScript("OnEnter", OnEnter)
|
|
self:SetScript("OnLeave", OnLeave)
|
|
self:SetStatusBarTexture(l['texture'] or d['texture'])
|
|
self:GetStatusBarTexture():SetHorizTile(l['tile'] or d['tile'])
|
|
self:SetValue(l['value'] or d['value'])
|
|
self:SetWidth(l['width'] or d['width'])
|
|
self:SetHeight(l['height'] or d['height'])
|
|
self:SetScript("OnValueChanged", l['script'] or d['script'])
|
|
self:SetPoint("CENTER")
|
|
self:SetStatusBarColor((l['color'] and unpack(l['color']) or unpack(d['color'])))
|
|
self['fontstring'] = self:CreateFontString(nil, "OVERLAY", "TextStatusBarText")
|
|
self['fontstring']:ClearAllPoints()
|
|
self['fontstring']:SetAllPoints(self)
|
|
self['fontstring']:SetText(" *.*")
|
|
self['fontstring']:SetJustifyH('LEFT')
|
|
self['fontstring2'] = self:CreateFontString(nil, "OVERLAY", "TextStatusBarText")
|
|
self['fontstring2']:ClearAllPoints()
|
|
self['fontstring2']:SetAllPoints(self)
|
|
self['fontstring2']:SetText(" 0")
|
|
self['fontstring2']:SetJustifyH('RIGHT')
|
|
self:Show()
|
|
return self
|
|
end
|
|
|
|
function addon:IsStatusBarActive(bid)
|
|
if(bars[bid] and bars[bid]['active']) then
|
|
return true
|
|
end
|
|
end
|
|
function addon:CreateStatusBar(layout)
|
|
-- print("Create bar",format("%s_Statusbar_%i",name,#bars + 1))
|
|
local bar = CreateFrame("StatusBar",format("%s_Statusbar_%i",name,#bars + 1),f)
|
|
for method, func in pairs(bar_methods) do
|
|
bar[method] = func
|
|
end
|
|
return bar:SetLayout(layout)
|
|
end
|
|
function addon:GetStatusBar(bid)
|
|
if(not bid or type(bid) ~= 'number' or bid > #bars) then
|
|
for i = 1, #bars do
|
|
if(not bars[i]['active']) then
|
|
bid = i
|
|
break
|
|
end
|
|
end
|
|
if(not bid) then
|
|
bid = #bars + 1
|
|
end
|
|
end
|
|
-- if(addon:IsStatusBarActive(bid)) then
|
|
if(not bars[bid]) then
|
|
bars[bid] = addon:CreateStatusBar()
|
|
end
|
|
bars[bid]['active'] = true
|
|
-- else
|
|
-- print("Bar not active")
|
|
-- end
|
|
-- print("Bar", bid, bars[bid])
|
|
return bars[bid]
|
|
end |