Revision 24
This commit is contained in:
commit
2749216aa5
|
@ -0,0 +1,340 @@
|
|||
local name, addon = ...
|
||||
|
||||
local embed = addon:LibInit("zzCommon-Base", 37, {'RegisterFunc','HandleFunclist','round','split','classcolor','colorize','Print','buildMoneyString','RegisterEventThrottle','RGB2Hex','Hex2RGB','sortArray','IsTwink','getItemId','itemInfo','startup','IsClassic'})
|
||||
if(type(embed) ~= 'function') then return end
|
||||
|
||||
local table = table
|
||||
local string = string
|
||||
local math = math
|
||||
local type = type
|
||||
local tostring = tostring
|
||||
local tonumber = tonumber
|
||||
|
||||
local throttles = {}
|
||||
local schedules = {}
|
||||
local newtmp = {}
|
||||
|
||||
local ScheduleCheckDelay = .5
|
||||
local function checkSchedule()
|
||||
for k = #schedules,1,-1 do
|
||||
local v = schedules[k]
|
||||
if(v['lastcall'] + v['delay'] < GetTime()) then
|
||||
v['func'](v['event'], v['arg1'], v['arg2'])
|
||||
tremove(schedules, k)
|
||||
end
|
||||
end
|
||||
if(#schedules > 0) then
|
||||
C_Timer.After(ScheduleCheckDelay, checkSchedule)
|
||||
end
|
||||
end
|
||||
|
||||
C_Timer.After(ScheduleCheckDelay, checkSchedule)
|
||||
|
||||
local function scheduleThrottle(obj, arg1, arg2)
|
||||
local found,v = false
|
||||
for k = 1, #schedules do
|
||||
local v = schedules[k]
|
||||
if(v['name'] == obj['name']) then
|
||||
v = obj
|
||||
v['arg1'] = arg1
|
||||
v['arg2'] = arg2
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if(not found) then
|
||||
schedules[#schedules + 1] = obj
|
||||
schedules[#schedules]['arg1'] = arg1
|
||||
schedules[#schedules]['arg2'] = arg2
|
||||
end
|
||||
C_Timer.After(ScheduleCheckDelay, checkSchedule)
|
||||
end
|
||||
|
||||
local function eventThrottle(self, event, ...)
|
||||
for k = 1, #throttles do
|
||||
local v = throttles[k]
|
||||
if(v['event'] == event) then
|
||||
if(v['lastcall'] + v['delay'] < GetTime()) then
|
||||
v['lastcall'] = GetTime()
|
||||
v['func'](event, ...)
|
||||
else
|
||||
scheduleThrottle(v, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local lib = {}
|
||||
function lib:RegisterFunc(event,typ,func)
|
||||
local f = CreateFrame("Frame")
|
||||
if(type(event) == "table") then
|
||||
for i = 1, #event do
|
||||
f:RegisterEvent(event[i])
|
||||
end
|
||||
elseif(event) then
|
||||
f:RegisterEvent(event)
|
||||
end
|
||||
if(typ and type(func) == 'function') then
|
||||
f:SetScript(typ, func)
|
||||
end
|
||||
return f
|
||||
end
|
||||
function lib:HandleFunclist(list, ...)
|
||||
for _, v in ipairs(self[list]) do
|
||||
v(...)
|
||||
end
|
||||
end
|
||||
function lib:RGB2Hex(r,g,b)
|
||||
r = r <= 255 and r >= 0 and r or 0
|
||||
g = g <= 255 and g >= 0 and g or 0
|
||||
b = b <= 255 and b >= 0 and b or 0
|
||||
return string.format("%02x%02x%02x", r, g, b)
|
||||
end
|
||||
function lib: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), tonumber(g, 16), tonumber(b, 16)
|
||||
end
|
||||
function lib:sortArray(tmp,dir)
|
||||
wipe(newtmp)
|
||||
local n = 1
|
||||
local cnt = 0
|
||||
local maximum = 0
|
||||
local first
|
||||
for k,v in pairs(tmp) do
|
||||
cnt = cnt + 1
|
||||
if(v > maximum) then
|
||||
maximum = v + 1
|
||||
end
|
||||
first = first or k
|
||||
end
|
||||
while(cnt > 0) do
|
||||
local mx, mn = dir and maximum or 0,first
|
||||
for k,v in pairs(tmp) do
|
||||
if(dir) then
|
||||
if(tonumber(v)<=tonumber(mx)) then
|
||||
mx = v
|
||||
mn = k
|
||||
end
|
||||
else
|
||||
if(tonumber(v)>=tonumber(mx)) then
|
||||
mx = v
|
||||
mn = k
|
||||
end
|
||||
end
|
||||
end
|
||||
newtmp[n] = mn
|
||||
tmp[mn] = nil
|
||||
cnt = 0
|
||||
for k,v in pairs(tmp) do
|
||||
cnt = cnt + 1
|
||||
end
|
||||
n = n + 1
|
||||
mn = 0
|
||||
mx = dir and mx or 0
|
||||
end
|
||||
return newtmp
|
||||
end
|
||||
function lib:split(s, delim)
|
||||
-- assert (type (delim) == "string" and string.len (delim) > 0, "bad delimiter")
|
||||
local start = 1
|
||||
local t = {}
|
||||
while true do
|
||||
local pos = string.find (s, delim, start, true)
|
||||
if not pos then break end
|
||||
table.insert (t, string.sub (s, start, pos - 1))
|
||||
start = pos + string.len (delim)
|
||||
end
|
||||
table.insert (t, string.sub (s, start))
|
||||
return t
|
||||
end
|
||||
function lib:round(num, idp)
|
||||
return math.floor(num * (10^(idp or 0)) + 0.5) / (10^(idp or 0))
|
||||
end
|
||||
function lib:classcolor(text,class)
|
||||
if(not RAID_CLASS_COLORS[class]) then
|
||||
class="PRIEST"
|
||||
end
|
||||
return string.format("|c%s%s|r",RAID_CLASS_COLORS[tostring(class)]['colorStr'],text)
|
||||
end
|
||||
function lib:colorize(text,color)
|
||||
return string.format("|cff%s%s|r",color and color or 'ffffff',text and text or '')
|
||||
end
|
||||
function lib:Print(message)
|
||||
SELECTED_CHAT_FRAME:AddMessage(tostring(message))
|
||||
end
|
||||
function lib:buildMoneyString(money, color, tab, abrevK, abrevM)
|
||||
tab = tab or {}
|
||||
local iconSize = tab['iconSize'] or 12
|
||||
local goldicon = tab['goldicon'] or format("\124TInterface\\MoneyFrame\\UI-GoldIcon:%d:%d:1:0\124t", iconSize, iconSize)
|
||||
local silvericon = tab['silvericon'] or format("\124TInterface\\MoneyFrame\\UI-SilverIcon:%d:%d:1:0\124t", iconSize, iconSize)
|
||||
local coppericon = tab['coppericon'] or format("\124TInterface\\MoneyFrame\\UI-CopperIcon:%d:%d:1:0\124t", iconSize, iconSize)
|
||||
|
||||
local moneystring = ''
|
||||
local g,s,c
|
||||
local neg = false
|
||||
local abrev = ""
|
||||
if(abrevM and money >= 10000000000) then
|
||||
abrev = abrevM
|
||||
money = lib:round(money / 10000000000,1) * 10000
|
||||
elseif(abrevK and money >= 10000000) then
|
||||
abrev = abrevK
|
||||
money = lib:round(money / 10000000,1) * 10000
|
||||
end
|
||||
if(money <0) then
|
||||
neg = true
|
||||
money = money * -1
|
||||
end
|
||||
if(abrev=="") then
|
||||
g=floor(money/10000)
|
||||
s=floor((money-(g*10000))/100)
|
||||
c=money-s*100-g*10000
|
||||
else
|
||||
g = money/10000
|
||||
s = 0
|
||||
c = 0
|
||||
end
|
||||
if(money > 0) then
|
||||
if(g>0) then
|
||||
moneystring = format("%s%s%s",g,abrev,goldicon)
|
||||
end
|
||||
if(s>0) then
|
||||
moneystring = format("%s%s%s",moneystring,s,silvericon)
|
||||
end
|
||||
if(c>0) then
|
||||
moneystring = format("%s%s%s",moneystring,c,coppericon)
|
||||
end
|
||||
else
|
||||
moneystring = format("%s%s",'0',coppericon)
|
||||
end
|
||||
if(neg) then
|
||||
moneystring = format("-%s",moneystring)
|
||||
end
|
||||
if(color) then
|
||||
if(neg) then
|
||||
moneystring = self:colorize(moneystring,"ff0000")
|
||||
elseif(money ~= 0) then
|
||||
moneystring = self:colorize(moneystring,"44dd44")
|
||||
end
|
||||
end
|
||||
return moneystring
|
||||
end
|
||||
function lib:RegisterEventThrottle(storename, event, delay, func)
|
||||
local found = 0
|
||||
if(type(event) ~= 'table') then event = {event} end
|
||||
for i = 1, #event do
|
||||
found = 0
|
||||
local ev = event[i]
|
||||
local sn = storename..i
|
||||
for k = 1, #throttles do
|
||||
local v = throttles[k]
|
||||
if(v['name'] == sn) then
|
||||
found = k
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if(found == 0) then
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent(ev)
|
||||
f:SetScript("OnEvent", eventThrottle)
|
||||
-- lib['RegisterFunc'](ev, "OnEvent", eventThrottle)
|
||||
end
|
||||
throttles[#throttles + 1] = {
|
||||
['name'] = sn,
|
||||
['event'] = ev,
|
||||
['delay'] = delay,
|
||||
['func'] = func,
|
||||
['lastcall'] = GetTime() - delay,
|
||||
}
|
||||
end
|
||||
end
|
||||
function lib:IsTwink(name)
|
||||
local realm = GetRealmName()
|
||||
local _
|
||||
if(self['db']['sv']['profileKeys']) then
|
||||
for k,v in pairs(self['db']['sv']['profileKeys']) do
|
||||
local n,m = strsplit(" - ",k,2)
|
||||
_,m = strsplit(" ",m,2)
|
||||
if(n) then
|
||||
if(n == name and m == realm) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
function lib:getItemId(link)
|
||||
if(link) then
|
||||
local _, _, itemString = string.find(link, "^|c%x+|H(.+)|h%[.*%]")
|
||||
local _,id,_ = strsplit(":",itemString)
|
||||
return tonumber(id)
|
||||
end
|
||||
end
|
||||
function lib:itemInfo(id)
|
||||
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
|
||||
if(itemName) then
|
||||
return {
|
||||
['itemId'] = id,
|
||||
['itemName'] = itemName,
|
||||
['itemLink'] = itemLink,
|
||||
['itemRarity'] = itemRarity,
|
||||
['itemLevel'] = itemLevel,
|
||||
['itemMinLevel'] = itemMinLevel,
|
||||
['itemType'] = itemType,
|
||||
['itemSubType'] = itemSubType,
|
||||
['itemStackCount'] = itemStackCount,
|
||||
['itemEquipLoc'] = itemEquipLoc,
|
||||
['itemTexture'] = itemTexture,
|
||||
['itemSellPrice'] = itemSellPrice
|
||||
}
|
||||
end
|
||||
end
|
||||
function lib:startup(name, childName, init, default, defaults)
|
||||
if(name==childName) then
|
||||
local addon = self
|
||||
self['frame'] = self:RegisterFunc({'PLAYER_LOGOUT','ADDON_LOADED','PLAYER_ENTERING_WORLD'},"OnEvent", function(self, event, arg1,...)
|
||||
if(event=='ADDON_LOADED') then
|
||||
if(arg1 ~= childName) then return end
|
||||
addon['db'] = addon['db'] or LibStub("AceDB-3.0"):New(childName.."DB", nil, default)
|
||||
if(type(defaults) == 'table') then
|
||||
addon['db']['profile'][childName] = addon['db']['profile'][childName] or CopyTable(defaults)
|
||||
else
|
||||
addon['db']['profile'][childName] = addon['db']['profile'][childName] or {}
|
||||
end
|
||||
if(self:IsEventRegistered("PLAYER_ENTERING_WORLD") and IsAddOnLoaded("AddonLoader")) then
|
||||
if(GetAddOnMetadata(name, "X-LoadOn-Always")) then
|
||||
init(self, event, ...)
|
||||
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
|
||||
end
|
||||
end
|
||||
addon:HandleFunclist('preloads', event, arg1, ...)
|
||||
addon['preloads'] = {}
|
||||
elseif(event=='PLAYER_LOGOUT') then
|
||||
addon:HandleFunclist('logouts', event, arg1, ...)
|
||||
elseif(event=='PLAYER_ENTERING_WORLD') then
|
||||
local found = false
|
||||
for i = 1, #addon['inits'] do
|
||||
if(addon['inits'][i] == init) then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
if(not found) then
|
||||
init(self, event, ...)
|
||||
end
|
||||
addon:HandleFunclist('inits', event, arg1, ...)
|
||||
addon['inits'] = {}
|
||||
end
|
||||
self:UnregisterEvent(event)
|
||||
if(type(self[event]) == 'function') then
|
||||
self[event](self, event, arg1, ...)
|
||||
end
|
||||
end)
|
||||
else
|
||||
self:RegisterBroker(childName,init,default,defaults)
|
||||
end
|
||||
end
|
||||
function lib:IsClassic()
|
||||
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
|
||||
end
|
||||
embed(lib)
|
|
@ -0,0 +1,8 @@
|
|||
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
|
||||
<Include file="Libs\embeds.xml"/>
|
||||
<Script file="stub.lua"/>
|
||||
<Script file="common.lua"/>
|
||||
<Script file="ldb.lua"/>
|
||||
<Script file="config.lua"/>
|
||||
<Script file="frames.lua"/>
|
||||
</Ui>
|
|
@ -0,0 +1,147 @@
|
|||
local name, addon = ...
|
||||
|
||||
local embed = addon:LibInit("zzCommon-Conf", 12, {'AddConfigMenu','AddConfigEntry','InitConfig'})
|
||||
if(type(embed) ~= 'function') then return end
|
||||
|
||||
local function getPref(pref)
|
||||
return pref['handler']['db']['profile'][pref[#pref]]
|
||||
end
|
||||
|
||||
local function setPref(pref,value)
|
||||
pref['handler']['db']['profile'][pref[#pref]] = value
|
||||
end
|
||||
local addedPanels = {}
|
||||
local select = select
|
||||
local lib = {}
|
||||
function lib:InitConfig(parentName, AddLDBIconOptions, AddLDB, gp, sp)
|
||||
local options
|
||||
if(not self['options']) then
|
||||
options = {
|
||||
['type']='group',
|
||||
['handler']=self,
|
||||
['get']=gp or getPref,
|
||||
['set']=sp or setPref,
|
||||
['childGroups']='tab',
|
||||
['args']={
|
||||
[parentName] = {
|
||||
['name'] = parentName,
|
||||
['type']='group',
|
||||
['order']=1,
|
||||
['args']={
|
||||
['minimap'] = AddLDBIconOptions and self['AddLDBIconOptions'](self) or nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self['options'] = options
|
||||
self['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(self['db'])
|
||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, self['options'])
|
||||
if(not addedPanels[parentName]) then
|
||||
addedPanels[parentName] = true
|
||||
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName)
|
||||
end
|
||||
else
|
||||
options = {
|
||||
['name'] = parentName,
|
||||
['type']='group',
|
||||
['handler']=self,
|
||||
['get']=gp or getPref,
|
||||
['set']=sp or setPref,
|
||||
['childGroups']='tab',
|
||||
['args']={
|
||||
[parentName] = {
|
||||
['name'] = parentName,
|
||||
['type']='group',
|
||||
['order']=1,
|
||||
['args']={
|
||||
['minimap'] = AddLDBIconOptions and self:AddLDBIconOptions() or nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options)
|
||||
if(not addedPanels[parentName]) then
|
||||
addedPanels[parentName] = true
|
||||
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName, self['parentName'])
|
||||
end
|
||||
end
|
||||
if(AddLDB) then
|
||||
self['AddLDB'](self, parentName,AddLDB)
|
||||
end
|
||||
return options
|
||||
end
|
||||
function lib:AddConfigMenu(menuName, parentMenu)
|
||||
if(not parentMenu) then parentMenu = self['options'] end
|
||||
local menuHandler,menuChildGroups,menuGet,menuSet,menuOrder,menuDesc,menuDisabled,menuHidden,menuInline
|
||||
if(type(menuName) == 'table') then
|
||||
menuHandler = menuName['menuHandler'] or self
|
||||
menuChildGroups = menuName['childGroups'] or 'tree'
|
||||
menuGet = menuName['menuGet'] or getPref
|
||||
menuSet = menuName['menuSet'] or setPref
|
||||
menuOrder = menuName['order'] or 1
|
||||
menuDesc = menuName['desc'] or ''
|
||||
menuDisabled = menuName['disabled'] or false
|
||||
menuHidden = menuName['hidden'] or false
|
||||
menuInline = menuName['inline'] or false
|
||||
menuName = menuName['name']
|
||||
else
|
||||
menuHandler = self
|
||||
menuGet = 'getPref'
|
||||
menuSet = 'setPref'
|
||||
menuOrder = 1
|
||||
menuDesc = ''
|
||||
end
|
||||
parentMenu['args'][menuName] = {
|
||||
['type'] = 'group',
|
||||
['inline'] = menuInline,
|
||||
['name'] = menuName,
|
||||
['desc'] = menuDesc,
|
||||
['childGroups'] = menuChildGroups,
|
||||
['handler'] = menuHandler,
|
||||
['get'] = menuGet,
|
||||
['set'] = menuSet,
|
||||
['order'] = menuOrder,
|
||||
['args'] = {},
|
||||
['hidden'] = menuHidden,
|
||||
['disabled'] = menuDisabled,
|
||||
}
|
||||
return parentMenu['args'][menuName]
|
||||
end
|
||||
function lib:AddConfigEntry(parentName, ...)
|
||||
local menu = select(10,...) or self['options']['args'][parentName]
|
||||
if(menu) then
|
||||
local entryName = select(2,...)
|
||||
menu['args'][entryName] = {
|
||||
['type'] = select(1,...),
|
||||
['name'] = select(3,...),
|
||||
['desc'] = select(4,...),
|
||||
['order'] = select(5,...)
|
||||
}
|
||||
if(select(1,...) == 'range') then
|
||||
menu['args'][entryName]['min'] = select(6,...)
|
||||
menu['args'][entryName]['max'] = select(7,...)
|
||||
menu['args'][entryName]['step'] = select(8,...)
|
||||
menu['args'][entryName]['isPercent'] = select(9,...)
|
||||
elseif(select(1,...) == 'execute') then
|
||||
menu['args'][entryName]['func'] = select(6,...)
|
||||
elseif(select(1,...) == 'color') then
|
||||
menu['args'][entryName]['get'] = select(6,...)
|
||||
menu['args'][entryName]['set'] = select(7,...)
|
||||
menu['args'][entryName]['hasAlpha'] = true
|
||||
elseif(select(1,...) == 'select') then
|
||||
menu['args'][entryName]['values'] = select(6,...)
|
||||
elseif(select(1,...) == 'group') then
|
||||
menu['args'][entryName]['inline'] = select(6,...)
|
||||
menu['args'][entryName]['args'] = {
|
||||
['description'] = {
|
||||
['name'] = select(4,...),
|
||||
['type'] = 'header',
|
||||
['order'] = 0
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
embed(lib)
|
|
@ -0,0 +1,297 @@
|
|||
local name, addon = ...
|
||||
|
||||
local embed = addon:LibInit("zzCommon-Frames", 18, {'AddDrag','LoadFrame','GetFrameCoords','CreateSecureFrame'})
|
||||
if(type(embed) ~= 'function') then return end
|
||||
local base = LibStub('zzCommon-Frames')
|
||||
base['frames'] = base['frames'] or {}
|
||||
|
||||
local function round(num, idp)
|
||||
return math.floor(num * (10^(idp or 0)) + 0.5) / (10^(idp or 0))
|
||||
end
|
||||
|
||||
local function dragAble()
|
||||
return true
|
||||
end
|
||||
|
||||
local defaults = {
|
||||
['parent'] = UIParent,
|
||||
['inherit'] = "SecureHandlerBaseTemplate SecureHandlerStateTemplate SecureHandlerEnterLeaveTemplate SecureHandlerMouseUpDownTemplate",
|
||||
['width'] = 30,
|
||||
['height'] = 30,
|
||||
['selfPoint'] = "CENTER",
|
||||
['relativTo'] = UIParent,
|
||||
['relativPoint'] = "CENTER",
|
||||
['xoff'] = 0,
|
||||
['yoff'] = 0,
|
||||
['dragAble'] = dragAble,
|
||||
['db'] = {},
|
||||
}
|
||||
|
||||
local function setDefaultValues(frame)
|
||||
if(not frame['db'] and frame['name'] and addon['db']) then
|
||||
addon['db']['profile'][frame['name']] = addon['db']['profile'][frame['name']] or {}
|
||||
addon['db']['profile'][frame['name']]['points'] = addon['db']['profile'][frame['name']]['points'] or {}
|
||||
frame['db'] = addon['db']['profile'][frame['name']]['points']
|
||||
end
|
||||
for k, v in pairs(defaults) do
|
||||
if(frame[k] == nil) then
|
||||
frame[k] = v
|
||||
end
|
||||
end
|
||||
return frame
|
||||
end
|
||||
|
||||
local function saveFrame(frame)
|
||||
local db = frame['db']
|
||||
local fn = frame:GetName()
|
||||
db[fn] = db[fn] or {
|
||||
['xpos'] = 0,
|
||||
['ypos'] = 0,
|
||||
}
|
||||
local x, y = frame:GetCenter()
|
||||
local s = frame:GetEffectiveScale()
|
||||
local uis = UIParent:GetScale()
|
||||
x = x*s - GetScreenWidth()*uis/2
|
||||
y = y*s - GetScreenHeight()*uis/2
|
||||
db[fn]['xpos'] = round(x/uis,0)
|
||||
db[fn]['ypos'] = round(y/uis,0)
|
||||
end
|
||||
|
||||
local schedules = {}
|
||||
local scheduleframe = CreateFrame("Frame")
|
||||
scheduleframe:SetScript("OnEvent", function(self, event)
|
||||
for i=1,#schedules do
|
||||
schedules[i]['func'](schedules[i]['frame'])
|
||||
end
|
||||
wipe(schedules)
|
||||
self:UnregisterEvent(event)
|
||||
end)
|
||||
|
||||
local function addSchedule(frame, func)
|
||||
schedules[#schedules + 1] = {
|
||||
['frame'] = frame,
|
||||
['func'] = func,
|
||||
}
|
||||
if(#schedules == 1) then
|
||||
scheduleframe:RegisterEvent("PLAYER_REGEN_ENABLED")
|
||||
end
|
||||
end
|
||||
|
||||
local function getCoords(frame)
|
||||
local s = frame:GetEffectiveScale()
|
||||
local uis = UIParent:GetScale()
|
||||
local fn = frame:GetName()
|
||||
return frame['db'][fn]['xpos']*uis/s, frame['db'][fn]['ypos']*uis/s
|
||||
end
|
||||
|
||||
local function loadFrame(frame)
|
||||
if not frame then return end
|
||||
if( InCombatLockdown() ) then
|
||||
addSchedule(frame, loadFrame)
|
||||
return
|
||||
end
|
||||
frame:SetMovable(true)
|
||||
local db = frame['db']
|
||||
local fn = frame:GetName()
|
||||
db[fn] = db[fn] or {
|
||||
['xpos'] = 0,
|
||||
['ypos'] = 0,
|
||||
}
|
||||
local x, y = getCoords(frame)
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("CENTER", UIParent, "CENTER", x, y)
|
||||
frame:SetUserPlaced(true)
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function storePoints(frame)
|
||||
wipe(frame['db'])
|
||||
for i = 1, frame:GetNumPoints() do
|
||||
frame['db'][#frame['db'] + 1] = {frame:GetPoint(i)}
|
||||
frame['db'][#frame['db']][2] = frame['db'][#frame['db']][2] and frame['db'][#frame['db']][2]:GetName() or "UIParent"
|
||||
frame['db'][#frame['db']][4] = round(frame['db'][#frame['db']][4])
|
||||
frame['db'][#frame['db']][5] = round(frame['db'][#frame['db']][5])
|
||||
-- print("save", frame:GetName(),frame:GetPoint(i),frame['db'][#frame['db']][4],frame['db'][#frame['db']][5])
|
||||
end
|
||||
end
|
||||
|
||||
local function restorePoints(frame)
|
||||
if(#frame['db']<1) then
|
||||
storePoints(frame)
|
||||
end
|
||||
frame:ClearAllPoints()
|
||||
for i = 1, #frame['db'] do
|
||||
if(frame['db'][i][2] == "UIParent") then
|
||||
frame['db'][i][2] = UIParent
|
||||
end
|
||||
-- print("load", frame:GetName(),frame['db'][i][1],_G[frame['db'][i][2]],frame['db'][i][3],frame['db'][i][4],frame['db'][i][5])
|
||||
frame:SetPoint(frame['db'][i][1],frame['db'][i][2] == "UIParent" and UIParent or _G[frame['db'][i][2]],frame['db'][i][3],frame['db'][i][4],frame['db'][i][5])
|
||||
end
|
||||
|
||||
end
|
||||
local function toggle(frame)
|
||||
if(frame:IsVisible()) then
|
||||
frame:Hide()
|
||||
else
|
||||
frame:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local function center(frame)
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("Center", UIParent,"Center",0,0)
|
||||
saveFrame(frame)
|
||||
end
|
||||
|
||||
local function center2(frame)
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint("Center", UIParent,"Center",0,0)
|
||||
storePoints(frame)
|
||||
end
|
||||
|
||||
local function startMove(frame)
|
||||
if InCombatLockdown() then return end
|
||||
if(frame['locked']) then return end
|
||||
if(frame['moveparent']) then
|
||||
frame:GetParent():StartMoving()
|
||||
frame:GetParent():SetUserPlaced(false)
|
||||
else
|
||||
frame:StartMoving()
|
||||
frame:SetUserPlaced(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function stopMove(frame)
|
||||
if(frame['moveparent']) then
|
||||
frame:GetParent():StopMovingOrSizing()
|
||||
saveFrame(frame:GetParent())
|
||||
else
|
||||
frame:StopMovingOrSizing()
|
||||
saveFrame(frame)
|
||||
end
|
||||
end
|
||||
|
||||
local function startMove2(frame)
|
||||
if(not frame:dragAble()) then return end
|
||||
frame:StartMoving()
|
||||
frame:SetUserPlaced(false)
|
||||
end
|
||||
|
||||
local function stopMove2(frame)
|
||||
frame:StopMovingOrSizing()
|
||||
storePoints(frame)
|
||||
end
|
||||
|
||||
local function dragView(frame)
|
||||
if(IsAltKeyDown() and frame:GetParent()['dragAble']() and not InCombatLockdown()) then
|
||||
frame['tex']:SetColorTexture(0, .5, 0, .5)
|
||||
frame:Show()
|
||||
else
|
||||
if(frame:IsVisible()) then
|
||||
frame['tex']:SetColorTexture(0, 1, 0 , 0)
|
||||
stopMove(frame)
|
||||
frame:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
local function checkShow(frame, elapsed)
|
||||
frame['elapsed'] = frame['elapsed'] + elapsed
|
||||
if(frame['elapsed']>1) then
|
||||
dragView(frame)
|
||||
frame['elapsed'] = 0
|
||||
end
|
||||
end
|
||||
local function dragView2(frame)
|
||||
if(IsAltKeyDown() and frame['dragAble']()) then
|
||||
if(not frame:GetScript("OnUpdate")) then
|
||||
frame:SetScript("OnUpdate", function(self, elapsed)
|
||||
self['elapsed'] = self['elapsed'] + elapsed
|
||||
if(self['elapsed']>1) then
|
||||
self['elapsed'] = 0
|
||||
dragView2(self)
|
||||
end
|
||||
end)
|
||||
end
|
||||
frame['tex']:SetColorTexture(0, .5, 0, .5)
|
||||
else
|
||||
frame:SetScript("OnUpdate", nil)
|
||||
frame['tex']:SetColorTexture(0, 0, 0 , 0)
|
||||
end
|
||||
end
|
||||
local lib = {}
|
||||
function lib:GetFrameCoords()
|
||||
return getCoords(self)
|
||||
end
|
||||
function lib:LoadFrame()
|
||||
loadFrame(self)
|
||||
end
|
||||
function lib:AddDrag(frame,typ,tab)
|
||||
tab = tab or {
|
||||
['width'] = 32,
|
||||
['height'] = 32,
|
||||
['anchor'] = "BOTTOMLEFT",
|
||||
['parentanchor'] = "TOPLEFT",
|
||||
['xOffset'] = 0,
|
||||
['yOffset'] = 0,
|
||||
['offset'] = 16,
|
||||
}
|
||||
loadFrame(frame)
|
||||
frame['center'] = center
|
||||
frame['toggle'] = toggle
|
||||
frame['dragframe'] = frame['dragframe'] or CreateFrame("Frame","$PARENTdrag",frame)
|
||||
frame['dragframe']['elapsed'] = 0
|
||||
frame['dragframe']:SetFrameStrata("LOW")
|
||||
frame:SetMovable(true)
|
||||
frame['dragframe']:SetMovable(true)
|
||||
frame['dragframe']:EnableMouse(true)
|
||||
frame['dragframe'].moveparent = true
|
||||
frame['dragframe']:SetScript("OnUpdate", checkShow)
|
||||
frame['dragframe']:SetScript("OnMouseDown", startMove)
|
||||
frame['dragframe']:SetScript("OnMouseUp", stopMove)
|
||||
if(typ == "BOX") then
|
||||
frame['dragframe']:SetWidth(tab['width'])
|
||||
frame['dragframe']:SetHeight(tab['height'])
|
||||
frame['dragframe']:SetPoint(tab['anchor'], frame, tab['parentanchor'], tab['xOffset'], tab['yOffset'])
|
||||
else
|
||||
local offset = tab['offset']
|
||||
frame['dragframe']:ClearAllPoints()
|
||||
frame['dragframe']:SetPoint("TOPLEFT", frame, "TOPLEFT", -offset/2, offset/2)
|
||||
frame['dragframe']:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", offset/2, -offset/2)
|
||||
end
|
||||
frame['dragframe']['tex'] = frame['dragframe']['tex'] or frame['dragframe']:CreateTexture()
|
||||
frame['dragframe']['tex']:SetAllPoints(frame.dragframe)
|
||||
frame['dragframe']['tex']:SetColorTexture(0,0,0,0)
|
||||
frame['dragframe']:RegisterEvent("MODIFIER_STATE_CHANGED")
|
||||
frame['dragframe']:SetScript("OnEvent",dragView)
|
||||
frame['dragframe']:Hide()
|
||||
end
|
||||
function lib:CreateSecureFrame(fname)
|
||||
if(type(fname) == 'string') then fname = {['name'] = fname} end
|
||||
fname = setDefaultValues(fname)
|
||||
local f = CreateFrame("Frame", fname['name'], fname['parent'], fname['inherit'], fname['id'])
|
||||
f:SetSize(fname['width'], fname['height'])
|
||||
f:SetPoint(fname['selfPoint'], fname['relativTo'], fname['relativPoint'], fname['xoff'], fname['yoff'])
|
||||
f['elapsed'] = 0
|
||||
f['db'] = fname['db']
|
||||
f['center'] = center2
|
||||
f['toggle'] = toggle
|
||||
f['dragAble'] = fname['dragAble']
|
||||
f['tex'] = f:CreateTexture()
|
||||
f['tex']:SetAllPoints(f)
|
||||
f['tex']:SetColorTexture(0,0,0,0)
|
||||
f['tex']:SetDrawLayer("BACKGROUND")
|
||||
f:RegisterEvent("MODIFIER_STATE_CHANGED")
|
||||
f:SetScript("OnEvent",dragView2)
|
||||
f:SetMovable(true)
|
||||
f:EnableMouse(true)
|
||||
f:SetScript("OnMouseUp", stopMove2)
|
||||
f:SetScript("OnMouseDown", startMove2)
|
||||
restorePoints(f)
|
||||
base['frames'][#base['frames'] + 1] = f
|
||||
return f
|
||||
end
|
||||
|
||||
|
||||
embed(lib)
|
|
@ -0,0 +1,118 @@
|
|||
local name, addon = ...
|
||||
|
||||
local embed = addon:LibInit("zzCommon-ldb", 13, {'AddLDB','AddLDBIconOptions','OnText','GetLDB'})
|
||||
if(type(embed) ~= 'function') then return end
|
||||
|
||||
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
|
||||
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
|
||||
|
||||
local defaults = {
|
||||
['hide'] = false,
|
||||
}
|
||||
|
||||
local function ldbiconUpdate(objname)
|
||||
local ldbobj = ldb:GetDataObjectByName(objname)
|
||||
if(ldbicon) then
|
||||
local db = ldbobj['zzInfo']['db']
|
||||
db[objname] = db[objname] or CopyTable(defaults)
|
||||
if(db[objname]['hide']) then
|
||||
ldbicon:Hide(objname)
|
||||
else
|
||||
ldbicon:Show(objname)
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
local function ldbOnClick(self, button)
|
||||
local objname = self['objname']
|
||||
if(IsShiftKeyDown() and button == "LeftButton") then
|
||||
if(not ldbicon) then return end
|
||||
local db = self['zzInfo']['db']
|
||||
db[objname]['hide'] = not db[objname]['hide']
|
||||
ldbiconUpdate(objname)
|
||||
else
|
||||
if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then
|
||||
InterfaceOptionsFrame:Hide()
|
||||
else
|
||||
InterfaceOptionsFrame_OpenToCategory(objname)
|
||||
InterfaceOptionsFrame_OpenToCategory(objname) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory
|
||||
end
|
||||
end
|
||||
end
|
||||
]]
|
||||
local function minimapGet(pref)
|
||||
local objname = pref[#pref - 2]
|
||||
local ldbobj = ldb:GetDataObjectByName(objname)
|
||||
local db = ldbobj['zzInfo']['db']
|
||||
return db[objname][pref[#pref]]
|
||||
end
|
||||
|
||||
local function minimapSet(pref,value)
|
||||
local objname = pref[#pref - 2]
|
||||
local ldbobj = ldb:GetDataObjectByName(objname)
|
||||
local db = ldbobj['zzInfo']['db']
|
||||
db[objname][pref[#pref]] = value
|
||||
ldbiconUpdate(objname)
|
||||
end
|
||||
|
||||
local lib = {}
|
||||
function lib:AddLDB(objname, obj)
|
||||
obj = obj or {}
|
||||
local modsDir = self['parentName']
|
||||
if(self['modsDir']) then
|
||||
modsDir = modsDir .. "\\" .. self['modsDir']
|
||||
end
|
||||
local icon = ((self['name'] and objname~=self['parentName']) and "Interface\\AddOns\\"..modsDir.."\\"..objname.."\\icon2.tga" or "Interface\\AddOns\\"..objname.."\\icon2.tga")
|
||||
local ldbobj = ldb:GetDataObjectByName(objname) or ldb:NewDataObject(objname, {
|
||||
['type'] = obj['type'] or 'launcher',
|
||||
['text'] = obj['text'] or objname,
|
||||
['icon'] = obj['icon'] or icon,
|
||||
['iconCoords'] = obj['iconCoords'],
|
||||
['OnLeave'] = obj['OnLeave'],
|
||||
['OnEnter'] = obj['OnEnter'],
|
||||
['zzInfo'] = {}
|
||||
})
|
||||
ldbobj['OnClick'] = type(obj['OnClick']) == 'function' and function(self, button) obj['OnClick'](self, button) end
|
||||
-- ldbobj['OnClick'] = type(obj['OnClick']) == 'function' and function(self, button) obj['OnClick'](self, button) end or function(self, button) ldbOnClick(self, button) end
|
||||
ldbobj['OnTooltipShow'] = type(obj['OnTooltipShow']) == 'function' and obj['OnTooltipShow'] or nil
|
||||
if(ldbobj and ldbicon) then
|
||||
self['db']['global']['ldbicons'] = self['db']['global']['ldbicons'] or {}
|
||||
local db = self['db']['global']['ldbicons']
|
||||
ldbobj['zzInfo']['db'] = self['db']['global']['ldbicons']
|
||||
db[objname] = db[objname] or CopyTable(defaults)
|
||||
if(not ldbicon:IsRegistered(objname)) then
|
||||
ldbicon:Register(objname,ldbobj,db[objname])
|
||||
end
|
||||
ldbiconUpdate(objname)
|
||||
end
|
||||
end
|
||||
function lib:GetLDB(objname)
|
||||
return ldb:GetDataObjectByName(objname)
|
||||
end
|
||||
function lib:OnText(objname, message)
|
||||
ldb:GetDataObjectByName(objname)['text'] = message
|
||||
end
|
||||
function lib:AddLDBIconOptions()
|
||||
return {
|
||||
['name']="Minimapicon",
|
||||
['type']='group',
|
||||
['inline']=true,
|
||||
['get'] = minimapGet,
|
||||
['set'] = minimapSet,
|
||||
['order'] = 100,
|
||||
['args']={
|
||||
['hide'] ={
|
||||
['type'] = 'toggle',
|
||||
['name'] = "Hide Minimapicon",
|
||||
},
|
||||
['minimapPos'] ={
|
||||
['type'] = 'range',
|
||||
['name'] = "Minimapicon Position",
|
||||
['min'] = 1,
|
||||
['max'] = 250,
|
||||
['step']=1,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
embed(lib)
|
|
@ -0,0 +1,36 @@
|
|||
local name, addon = ...
|
||||
setmetatable(addon,getmetatable(CreateFrame("Frame")))
|
||||
local LibStub = LibStub
|
||||
addon['inits'] = addon['inits'] or {}
|
||||
addon['preloads'] = addon['preloads'] or {}
|
||||
addon['logouts'] = addon['logouts'] or {}
|
||||
|
||||
local function embed(major, funclist,lib)
|
||||
local base = LibStub:GetLibrary(major, false)
|
||||
base['addons'] = base['addons'] or {}
|
||||
base['addons'][addon] = true
|
||||
-- print(major, funclist,lib)
|
||||
if(lib) then
|
||||
for i= 1,#funclist do -- update lib
|
||||
base[funclist[i]] = lib[funclist[i]]
|
||||
end
|
||||
for v in pairs(base['addons']) do -- update embeded addons
|
||||
for i= 1,#funclist do
|
||||
v[funclist[i]] = base[funclist[i]]
|
||||
end
|
||||
end
|
||||
else
|
||||
for i= 1,#funclist do
|
||||
addon[funclist[i]] = base[funclist[i]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function addon:LibInit(major, minor, funclist)
|
||||
local lib = LibStub:NewLibrary(major, minor)
|
||||
if not lib then
|
||||
embed(major, funclist)
|
||||
return nil
|
||||
end
|
||||
return function(lib) embed(major, funclist,lib) end
|
||||
end
|
Loading…
Reference in New Issue