Update .toc 90005, zz2

This commit is contained in:
rilgamon 2021-03-23 11:27:08 +01:00
parent 1ccd1d85a8
commit 5e66e888af
20 changed files with 642 additions and 280 deletions

View File

@ -5,4 +5,4 @@
<Include file="AceConfigDialog-3.0\AceConfigDialog-3.0.xml"/> <Include file="AceConfigDialog-3.0\AceConfigDialog-3.0.xml"/>
<!--<Include file="AceConfigDropdown-3.0\AceConfigDropdown-3.0.xml"/>--> <!--<Include file="AceConfigDropdown-3.0\AceConfigDropdown-3.0.xml"/>-->
<Script file="AceConfig-3.0.lua"/> <Script file="AceConfig-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceConfigCmd-3.0.lua"/> <Script file="AceConfigCmd-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,13 +1,13 @@
--- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables. --- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables.
-- @class file -- @class file
-- @name AceConfigDialog-3.0 -- @name AceConfigDialog-3.0
-- @release $Id: AceConfigDialog-3.0.lua 1247 2021-01-23 23:16:39Z funkehdude $ -- @release $Id: AceConfigDialog-3.0.lua 1248 2021-02-05 14:27:49Z funkehdude $
local LibStub = LibStub local LibStub = LibStub
local gui = LibStub("AceGUI-3.0") local gui = LibStub("AceGUI-3.0")
local reg = LibStub("AceConfigRegistry-3.0") local reg = LibStub("AceConfigRegistry-3.0")
local MAJOR, MINOR = "AceConfigDialog-3.0", 80 local MAJOR, MINOR = "AceConfigDialog-3.0", 81
local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR) local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigDialog then return end if not AceConfigDialog then return end
@ -544,12 +544,13 @@ local function GetFuncName(option)
end end
do do
local frame = AceConfigDialog.popup local frame = AceConfigDialog.popup
if not frame then if not frame or oldminor < 81 then
frame = CreateFrame("Frame", nil, UIParent) frame = CreateFrame("Frame", nil, UIParent)
AceConfigDialog.popup = frame AceConfigDialog.popup = frame
frame:Hide() frame:Hide()
frame:SetPoint("CENTER", UIParent, "CENTER") frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetSize(320, 72) frame:SetSize(320, 72)
frame:EnableMouse(true) -- Do not allow click-through on the frame
frame:SetFrameStrata("TOOLTIP") frame:SetFrameStrata("TOOLTIP")
frame:SetFrameLevel(100) -- Lots of room to draw under it frame:SetFrameLevel(100) -- Lots of room to draw under it
frame:SetScript("OnKeyDown", function(self, key) frame:SetScript("OnKeyDown", function(self, key)
@ -575,7 +576,7 @@ do
insets = { left = 11, right = 11, top = 11, bottom = 11 }, insets = { left = 11, right = 11, top = 11, bottom = 11 },
}) })
else else
local border = CreateFrame("Frame", nil, frame, "DialogBorderDarkTemplate") local border = CreateFrame("Frame", nil, frame, "DialogBorderOpaqueTemplate")
border:SetAllPoints(frame) border:SetAllPoints(frame)
frame:SetFixedFrameStrata(true) frame:SetFixedFrameStrata(true)
frame:SetFixedFrameLevel(true) frame:SetFixedFrameLevel(true)

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceConfigDialog-3.0.lua"/> <Script file="AceConfigDialog-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceConfigRegistry-3.0.lua"/> <Script file="AceConfigRegistry-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceDB-3.0.lua"/> <Script file="AceDB-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceDBOptions-3.0.lua"/> <Script file="AceDBOptions-3.0.lua"/>
</Ui> </Ui>

View File

@ -1,4 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd"> ..\FrameXML\UI.xsd">
<Script file="AceLocale-3.0.lua"/> <Script file="AceLocale-3.0.lua"/>
</Ui> </Ui>

View File

@ -8,6 +8,7 @@
<Include file="AceLocale-3.0\AceLocale-3.0.xml"/> <Include file="AceLocale-3.0\AceLocale-3.0.xml"/>
<Script file="LibDataBroker-1.1\LibDataBroker-1.1.lua"/> <Script file="LibDataBroker-1.1\LibDataBroker-1.1.lua"/>
<Script file="LibDBIcon-1.0\LibDBIcon-1.0.lua"/> <Script file="LibDBIcon-1.0\LibDBIcon-1.0.lua"/>
<Script file="zzHelper\zzHelper.lua"/>
<Script file="zzLDB\zzLDB.lua"/> <Script file="zzLDB\zzLDB.lua"/>
<Script file="zzConfig\zzConfig.lua"/> <Script file="zzConfig\zzConfig.lua"/>
<Script file="zzAddOn\zzAddOn.lua"/> <Script file="zzAddOn\zzAddOn.lua"/>

View File

@ -1,33 +1,80 @@
local lib, oldminor = LibStub:NewLibrary("zzAddOn", 2) local lib = LibStub:NewLibrary("zzAddOn", 5)
if not lib then return end if not lib then return end
oldminor = oldminor or 0 local config = LibStub:GetLibrary("zzConfig")
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib) lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
lib['addons'] = lib['addons'] or {} lib['addons'] = lib['addons'] or {}
lib['events'] = lib['events'] or CreateFrame("FRAME") lib['events'] = lib['events'] or CreateFrame("FRAME")
local mixins = {'RegisterEvent','UnregisterEvent','IsClassic', 'GetSpecs'} local function errormsg(err)
print(format("|cffff0000Error:|r %s",err))
end
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic', 'GetSpecs', 'Fire'}
local events = lib['events'] local events = lib['events']
function lib:Fire(...)
lib['callbacks']:Fire(...)
end
function lib:GetAddOn(childName)
return lib['addons'][childName]
end
function lib:GetOptions()
return self['options']
end
function lib:GetParent()
return self['parent']
end
function lib:HasParent()
return self['parent'] and true or false
end
function lib:IsChild()
return self:HasParent()
end
function lib:HasChild()
return self['children'] and #self['children'] > 0
end
function lib:GetSpecs(childName) function lib:GetSpecs(childName)
if(self['specs']) then return lib['addons'][childName]['specs']
return self['specs'][childName] end
local function joinTables(tab1, tab2, prefix)
prefix = prefix or ''
for k, v in pairs(tab2) do
if(tab1[k] and type(v) == 'table') then
joinTables(tab1[k], v, format("%s ", prefix))
else
tab1[k] = v
end
end end
end end
function lib:RegisterEvent(event) function lib:AddChild(child)
local childName = child['specs']['name']
child['parent'] = self
self['children'] = self['children'] or {}
self['children'][#self['children'] + 1] = child
if(child['specs']['defaults']) then
joinTables(self['specs']['defaults'], child['specs']['defaults'])
end
end
function lib:RegisterEvent(event, globalfunc)
if(type(event) == 'table') then if(type(event) == 'table') then
for ev, func in pairs(event) do for k, v in pairs(event) do
-- print("[zza] Registertab CB", type(ev),ev) -- print("[zza] Registertab CB", type(ev),ev)
local ev = k
local func = v
if(type(v) == 'string') then
ev = v
func = globalfunc
end
if(type(ev) == 'string' and type(func) == 'function' and not self['events'][ev]) then if(type(ev) == 'string' and type(func) == 'function' and not self['events'][ev]) then
self['events'][ev] = func self['events'][ev] = func
end end
self:RegisterEvent(ev) self:RegisterEvent(ev, func)
end end
elseif(type(event) == 'string') then elseif(type(event) == 'string') then
-- print("[zza] Register CB", type(event),event) -- print("[zza] Register CB", type(event),event)
if(not lib['events']:IsEventRegistered(event)) then if(not lib['events']:IsEventRegistered(event)) then
lib['events']:RegisterEvent(event) lib['events']:RegisterEvent(event)
end end
lib['RegisterCallback'](self['events'], event) lib.RegisterCallback(self, event, globalfunc)
else else
print("ign reg", type(event), event) errormsg("ign reg", type(event), event)
end end
end end
function lib:UnregisterEvent(event) function lib:UnregisterEvent(event)
@ -36,29 +83,42 @@ function lib:UnregisterEvent(event)
self:UnregisterEvent(ev) self:UnregisterEvent(ev)
end end
else else
lib['UnregisterCallback'](self['events'], event) lib['UnregisterCallback'](self, event)
end end
-- print('unreg', event)
end end
function lib:IsClassic() function lib:IsClassic()
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
end end
function lib:NewAddOn(specs, addonName, addonTable) function lib:NewAddOn(addonName, addonTable)
local specs = self['specs']
local childName = specs['name'] local childName = specs['name']
addonTable['parentName'] = addonName if(lib['addons'][childName]) then
addonTable['specs'] = addonTable['specs'] or {} local oldchild = lib['addons'][childName]
addonTable['specs'][childName] = specs local parent = oldchild:GetParent()
if(parent) then
errormsg(format("%s already loaded by %s", childName, parent['specs']['name']))
else
errormsg(format("|%s already loaded", childName))
end
return
end
if(type(childName) == 'string') then if(type(childName) == 'string') then
lib['addons'][childName] = addonTable self.GetAddOnTable = function() return addonTable end
lib:Embed(addonTable) lib['addons'][childName] = self
if(addonTable['events']) then lib:Embed(self)
for ev, func in pairs(addonTable['events']) do if(childName ~= addonName) then
local parent = lib['addons'][addonName]
parent:AddChild(self)
end
if(self['events']) then
for ev, func in pairs(self['events']) do
if(type(func) == 'function') then if(type(func) == 'function') then
-- print("[zza] Register", ev) self:RegisterEvent(ev, func)
addonTable:RegisterEvent(ev)
end end
end end
end end
return lib['addons'][childName] return self
end end
end end
function lib:Embed(target) function lib:Embed(target)
@ -66,35 +126,73 @@ function lib:Embed(target)
target[name] = lib[name] target[name] = lib[name]
end end
end end
for target, _ in pairs(lib['addons']) do for _, target in pairs(lib['addons']) do
lib:Embed(target) lib:Embed(target)
end end
lib['events']:RegisterEvent('ADDON_LOADED') lib['events']:RegisterEvent('ADDON_LOADED')
local function addLDB(...)
-- print('addLDB', ...)
return LibStub:GetLibrary("zzLDB"):AddLDB(...)
end
local function addConfig(addonName, child, specs)
local at = child:GetAddOnTable()
if(addonName == child['specs']['name']) then
-- print("init options", addonName)
config:InitConfig(child, addonName)
child['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(at['db'])
else
-- print('add child options', specs['name'], addonName)
config:AddConfig(child, addonName)
end
if(type(specs['cfgReset']) == 'function') then
specs['cfgReset'](child)
at['db'].RegisterCallback(specs, "OnProfileReset", 'cfgReset')
end
end
local function SetupSpecs(addonName, child)
local specs = child['specs']
if(specs and specs['sv'] and not child['db']) then
-- print('dbname',type(specs['sv']),type(specs['sv']) == 'boolean' and addonName or specs['sv'])
local dbname = format('%sDB', type(specs['sv']) == 'boolean' and addonName or specs['sv'])
local at = child:GetAddOnTable()
at['db'] = LibStub("AceDB-3.0"):New(dbname, type(specs['defaults']) == 'table' and specs['defaults'] or {}, 'Default')
-- print('setup parent ldb')
if(specs['ldb']) then
local ldbobj = addLDB(specs['name'], specs['ldb'], at['db'])
-- print(' result parent ldb', specs['name'])
end
if(specs['cfg']) then
-- print(' spec parent addcfg', addonName, specs['name'])
addConfig(addonName, child, specs)
end
if(child:HasChild()) then
for i = 1, #child['children'] do
local child = child['children'][i]
local childSpecs = child['specs']
-- print("Add child", childSpecs['name'])
if(childSpecs['ldb']) then
-- print(" Add ldb", childSpecs['name'])
local ldbobj = addLDB(childSpecs['name'], childSpecs['ldb'], at['db'])
end
if(childSpecs['cfg']) then
-- print(' spec child addcfg', addonName, childSpecs['name'])
addConfig(addonName, child, childSpecs)
end
end
end
end
end
lib['events']:SetScript("OnEvent", function(self, event, ...) lib['events']:SetScript("OnEvent", function(self, event, ...)
-- print("[zza]", self, event, ...) -- print("[zza]", self, event, ...)
local addonName = ... local addonName = ...
local addon = lib['addons'][addonName] local child = lib['addons'][addonName]
if(addon) then if(child) then
if(event == 'ADDON_LOADED') then if(event == 'ADDON_LOADED') then
local specs = addon:GetSpecs(addonName) SetupSpecs(addonName, child)
if(specs and specs['sv'] and not addon['db']) then
-- print('dbname',type(specs['sv']),type(specs['sv']) == 'boolean' and addonName or specs['sv'])
local dbname = format('%sDB', type(specs['sv']) == 'boolean' and addonName or specs['sv'])
addon['db'] = LibStub("AceDB-3.0"):New(dbname, type(specs['defaults']) == 'table' and specs['defaults'] or {}, 'Default')
if(specs['ldb']) then
local ldbobj = LibStub:GetLibrary("zzLDB"):AddLDB(specs['name'], specs['ldb'], addon['db'])
end
if(specs['cfg']) then
local config = LibStub:GetLibrary("zzConfig")
addon['options'] = config:InitConfig(addon, addonName)
addon['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(addon['db'])
if(type(specs['cfgReset']) == 'function') then
addon['db'].RegisterCallback(specs, "OnProfileReset", 'cfgReset')
end
end
end
end end
end end
-- print("[zza] Fire", event, ...) -- print("[zza] Fire", event, ...)
lib['callbacks']:Fire(event, ...) lib['callbacks']:Fire(event, self, event, ...)
end) end)

View File

@ -1,27 +1,27 @@
local lib, oldminor = LibStub:NewLibrary("zzConfig", 2) local lib = LibStub:NewLibrary("zzConfig", 3)
if not lib then return end if not lib then return end
oldminor = oldminor or 0
local ldb = LibStub:GetLibrary("LibDataBroker-1.1") local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0") local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
local mixins = {'AddConfigMenu','AddConfigEntry','InitConfig'} local mixins = {'AddConfigMenu', 'AddConfigEntry', 'InitConfig', 'GetDefaultHandler'}
lib['configs'] = lib['configs'] or {} lib['configs'] = lib['configs'] or {}
local function getDB(objname) local function getDB(objname)
if(ldbicon) then if(ldbicon) then
ldbicon:Show(objname) ldbicon:Show(objname)
local iconbtn = ldbicon:GetMinimapButton(objname) local iconbtn = ldbicon:GetMinimapButton(objname)
local db = iconbtn['db'] if(iconbtn) then
if(db['hide']) then local db = iconbtn['db']
ldbicon:Hide(objname) if(db['hide']) then
ldbicon:Hide(objname)
end
return db
else
print("noicon", objname)
end end
return db
end end
end return {}
local function ldbiconUpdate(objname)
local db = getDB(objname)
end end
local function minimapGet(pref) local function minimapGet(pref)
local objname = pref[#pref - 2] local objname = pref[#pref - 2]
-- print('gp', objname, pref)
local db = getDB(objname) local db = getDB(objname)
return db[pref[#pref]] return db[pref[#pref]]
end end
@ -29,7 +29,6 @@ local function minimapSet(pref,value)
local objname = pref[#pref - 2] local objname = pref[#pref - 2]
local db = getDB(objname) local db = getDB(objname)
db[pref[#pref]] = value db[pref[#pref]] = value
ldbiconUpdate(objname)
end end
local function notify(pref, value, oldvalue) local function notify(pref, value, oldvalue)
if(type(pref['handler'].PrefChanged) == 'function') then if(type(pref['handler'].PrefChanged) == 'function') then
@ -38,26 +37,41 @@ local function notify(pref, value, oldvalue)
end end
local function getPref(pref) local function getPref(pref)
if(type(pref['handler']['GetPref']) == 'function') then if(type(pref['handler']['GetPref']) == 'function') then
-- print("use handler getpref", pref[#pref])
return pref['handler']:GetPref(pref) return pref['handler']:GetPref(pref)
end end
-- for i = 1, #pref do local db = pref['handler']['db'] or pref['handler']:GetAddOnTable()['db']['profile'][pref['appName']]
-- print(i, pref[i]) return db and db[pref[#pref]]
-- end
-- print("use default getpref", pref[#pref], pref['handler']['db']['profile'][pref[#pref]])
return pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]]
end end
local function setPref(pref,value) local function setPref(pref, value, ...)
if(type(pref['handler']['SetPref']) == 'function') then if(type(pref['handler']['SetPref']) == 'function') then
pref['handler']:SetPref(pref,value) pref['handler']:SetPref(pref, value, ...)
else else
local oldvalue = pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]] local db = pref['handler']['db'] or pref['handler']:GetAddonTable()['db']['profile'][pref[#pref-1]]
pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]] = value local oldvalue = db[pref[#pref]]
db[pref[#pref]] = value
if(value ~= oldvalue) then if(value ~= oldvalue) then
notify(pref, value, oldvalue) notify(pref, value, oldvalue)
end end
end end
end end
local function GDH_GetPref(self, pref)
return self['db'][pref[#pref]]
end
local function GDH_SetPref(self, pref, value)
self['db'][pref[#pref]] = value
if(type(self['func']) == 'function') then
self['func'](self)
end
end
function lib:GetDefaultHandler(func, db)
return {
['db'] = db,
['func'] = func,
SetDB = function(self, db) self.db = db end,
GetPref = GDH_GetPref,
SetPref = GDH_SetPref,
}
end
function lib:AddLDBIconOptions(options, conf) function lib:AddLDBIconOptions(options, conf)
options['args'][conf] = { options['args'][conf] = {
['name']="Minimapicon", ['name']="Minimapicon",
@ -104,24 +118,26 @@ function lib:AddConfigEntry(options, ...)
elseif(input[2] == 'select') then elseif(input[2] == 'select') then
menu['values'] = input[6] menu['values'] = input[6]
elseif(input[2] == 'group') then elseif(input[2] == 'group') then
menu['inline'] = input[6] menu['inline'] = input[7]
menu['handler'] = input[6]
menu['args'] = { menu['args'] = {
['description'] = { ['description'] = {
['name'] = input[4], ['name'] = input[4],
['type'] = 'header', ['type'] = 'header',
['order'] = 0 ['order'] = 0
} },
} }
end end
options['args'][input[1]] = menu options['args'][input[1]] = menu
return menu return menu
end end
end end
function lib:AddConfigMenu(options, parentName, handler, order, more) function lib:AddConfigMenu(options, parentName, order, handler, more)
local menu = { local menu = {
['name'] = parentName, ['name'] = parentName,
['type'] = 'group', ['type'] = 'group',
['handler'] = handler or self['handler'], ['handler'] = handler or self['handler'],
['childGroups'] =' tab',
['order'] = order or 1, ['order'] = order or 1,
['args'] = {} ['args'] = {}
} }
@ -133,22 +149,41 @@ function lib:AddConfigMenu(options, parentName, handler, order, more)
options['args'][parentName] = menu options['args'][parentName] = menu
return options['args'][parentName] return options['args'][parentName]
end end
function lib:InitConfig(addon, parentName, gp, sp) function lib:InitConfig(child, parentName, gp, sp)
addon['options'] = { local pp = child['specs']['name'] == parentName
['type']='group', child['options'] = {
['handler']=addon, ['name'] = parentName,
['get']=gp or getPref, ['type'] = 'group',
['set']=sp or setPref, ['handler'] = child,
['childGroups']='tab', ['childGroups'] = 'tab',
['args']={} ['get'] = gp or getPref,
['set'] = sp or setPref,
['args'] = {}
} }
local options = addon['options'] local options = child['options']
local par = self:AddConfigMenu(options, parentName) local par = self:AddConfigMenu(options, parentName)
self:AddLDBIconOptions(par, 'minimap') self:AddLDBIconOptions(par, 'minimap')
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options) LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName, self['parentName']) LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName, child['parentName'])
return options return options
end end
function lib:AddConfig(child, parentName, gp, sp)
local specs = child['specs']
child['options'] = {
['name'] = specs['name'],
['type'] = 'group',
['handler'] = child,
['childGroups']='tab',
['get']=gp or getPref,
['set']=sp or setPref,
['args'] = {}
}
local par = self:AddConfigMenu(child['options'], specs['name'])
self:AddLDBIconOptions(par, 'minimap')
LibStub("AceConfig-3.0"):RegisterOptionsTable(specs['name'], child['options'])
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(specs['name'], specs['name'], parentName)
return child['options']
end
function lib:Embed(target) function lib:Embed(target)
for _,name in pairs(mixins) do for _,name in pairs(mixins) do
target[name] = lib[name] target[name] = lib[name]

179
Libs/zzHelper/zzHelper.lua Normal file
View File

@ -0,0 +1,179 @@
local lib = LibStub:NewLibrary("zzHelper", 2)
if not lib then return end
lib['targets'] = lib['targets'] or {}
local mixins = {'colorize', 'round', 'sortArray', 'IsTwink', 'classcolor', 'MoneyString', 'MoneyStringSetString', 'MoneyStringSetSize'}
--[[
*** Stringfunctions ***
]]
function lib:colorize(text, color)
return string.format("|cff%s%s|r",color and color or 'ffffff',text and text or '')
end
local iconbase = "\124TInterface\\MoneyFrame\\UI-%sIcon:%d:%d:1:0\124t"
local iconSize = 14
local moneyText = {
gold = " G",
silver = " S",
copper = " C",
goldColor = lib:colorize(" G", "ffd700"),
silverColor = lib:colorize(" S", "bfc1c2"),
copperColor = lib:colorize(" C", "b87333"),
}
function lib:MoneyStringSetString(coin, str, col)
if(moneyText[coin]) then
moneyText[coin] = str
if(col) then
moneyText[format("%sColor",coin)] = col
end
end
end
function lib:MoneyStringSetSize(size)
if(size and size > 5 and size < 30) then
iconSize = size
end
end
function lib:MoneyString(money, color, abrevK, abrevM, noicon, noiconcolor, size)
local iconSize = size or iconSize
local goldicon = noicon and (noiconcolor and moneyText['goldColor'] or moneyText['gold']) or format(iconbase, 'Gold', iconSize, iconSize)
local silvericon = noicon and (noiconcolor and moneyText['silverColor'] or moneyText['silver']) or format(iconbase, 'Silver', iconSize, iconSize)
local coppericon = noicon and (noiconcolor and moneyText['copperColor'] or moneyText['copper']) or format(iconbase, 'Copper', 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", color and lib:colorize(g, neg and "ff0000" or "44dd44") or g,abrev, goldicon)
end
if(s>0) then
moneystring = format("%s %s%s",moneystring, color and lib:colorize(s, neg and "ff0000" or "44dd44") or s, silvericon)
end
if(c>0) then
moneystring = format("%s %s%s",moneystring, color and lib:colorize(c, neg and "ff0000" or "44dd44") or c, coppericon)
end
else
moneystring = format("%s%s",color and '0' or '0', coppericon)
end
if(neg) then
moneystring = format("%s%s", lib:colorize("-","ff0000"), moneystring)
end
return moneystring
end
--[[
*** Mathfunctions ***
]]
function lib:round(num, idp)
return math.floor(num * (10^(idp or 0)) + 0.5) / (10^(idp or 0))
end
--[[
*** Arrayfunctions ***
]]
function lib:sortArray(tmp,dir)
local 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
--[[
*** Charfunctions ***
]]
function lib:IsTwink(name)
local at = self:GetAddOnTable()
local db = at['db']
local realm = GetRealmName()
local _
if(db['sv']['profileKeys']) then
for k,v in pairs(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:classcolor(text,class)
class = RAID_CLASS_COLORS[class] and class or "PRIEST"
return string.format("|c%s%s|r",RAID_CLASS_COLORS[class]['colorStr'],text)
end
--[[
*** End of functions ***
]]
function lib:Embed(target)
for _,name in pairs(mixins) do
target[name] = lib[name]
end
lib['targets'][target] = true
end
for target, _ in pairs(lib['targets']) do
lib:Embed(target)
end

View File

@ -1,9 +1,9 @@
local lib, oldminor = LibStub:NewLibrary("zzLDB", 2) local lib, oldminor = LibStub:NewLibrary("zzLDB", 4)
if not lib then return end if not lib then return end
local ldb = LibStub:GetLibrary("LibDataBroker-1.1") local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0") local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
oldminor = oldminor or 0 oldminor = oldminor or 0
local mixins = {'AddLDB', 'GetLDB'} local mixins = {'AddLDB', 'GetLDB', 'DefaultOnClick', 'DefaultOnText'}
local defaults = { local defaults = {
['hide'] = false, ['hide'] = false,
} }
@ -11,6 +11,32 @@ lib['ldbs'] = lib['ldbs'] or {}
local function proto_OnClick(self, button) local function proto_OnClick(self, button)
print("onclick required", self, button) print("onclick required", self, button)
end end
function lib:DefaultOnClick(dummy, button, addon, childName)
if(IsShiftKeyDown() and button == "LeftButton") then
local sb = addon['db']['global']['ldbicons']
sb[childName]['hide'] = not sb[childName]['hide']
if(ldbicon) then
if(sb[childName]['hide']) then
ldbicon:Hide(childName)
else
ldbicon:Show(childName)
end
end
else
if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(childName)
InterfaceOptionsFrame_OpenToCategory(childName) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory
end
end
end
function lib:DefaultOnText(objname, message)
local ldbobj = lib:GetLDB(objname)
if(ldbobj['text'] ~= message) then
ldbobj['text'] = message
end
end
function lib:GetLDB(objname) function lib:GetLDB(objname)
return ldb:GetDataObjectByName(objname) return ldb:GetDataObjectByName(objname)
end end
@ -28,7 +54,10 @@ function lib:AddLDB(objname, obj, db)
db['global']['ldbicons'] = db['global']['ldbicons'] or {} db['global']['ldbicons'] = db['global']['ldbicons'] or {}
local sb = db['global']['ldbicons'] local sb = db['global']['ldbicons']
sb[objname] = sb[objname] or CopyTable(defaults) sb[objname] = sb[objname] or CopyTable(defaults)
local oldstatus = sb[objname]['hide']
sb[objname]['hide'] = false
ldbicon:Register(objname, ldbobj, sb[objname]) ldbicon:Register(objname, ldbobj, sb[objname])
sb[objname]['hide'] = oldstatus
end end
return ldbobj return ldbobj
end end
@ -38,6 +67,7 @@ function lib:Embed(target)
for _,name in pairs(mixins) do for _,name in pairs(mixins) do
target[name] = lib[name] target[name] = lib[name]
end end
lib['ldbs'][target] = true
end end
for target, _ in pairs(lib['ldbs']) do for target, _ in pairs(lib['ldbs']) do
lib:Embed(target) lib:Embed(target)

29
broker.lua Normal file
View File

@ -0,0 +1,29 @@
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local events = child['events']
local zzLDB = LibStub:GetLibrary("zzLDB")
local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName)
local function OnClick(self, button)
zzLDB:DefaultOnClick(self, button, addon, childName)
end
local function OnTooltipShow(tip)
tip:AddLine(childName)
for _,v in ipairs({GetLatestThreeSenders()}) do
tip:AddLine(child:colorize(v,"ffffff"))
end
events.MAIL_SHOW(child, 'FIRE')
end
child['ldb'] = { -- https://github.com/tekkub/libdatabroker-1-1/wiki/Data-Specifications
['type'] = 'data source', -- required: 'data source' or 'launcher'
['text'] = childName, -- required/optional for launcher
['icon'] = format("%s\\icon2.tga", folder), -- optional/required for launcher
['OnClick'] = OnClick, -- optional/required for launcher
['OnTooltipShow'] = OnTooltipShow, -- optional
}
local init = {
Setup = function(self, childName, event)
child.OnText = zzLDB.DefaultOnText
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup', childName)

287
core.lua
View File

@ -1,174 +1,113 @@
local addonName, addonTable = ... local addonName, addon = ...
local childName = "zz_Mailbox" local childName = addon['childName']
local db, dbf, dbr,dbp, scanned, ldbobj local child = addon[childName]
addonTable['events'] = addonTable['events'] or {} local events = child['events']
local events = addonTable['events'] local db, dbf, dbr,dbp, scanned, ldbobj
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0") LibStub("zzHelper"):Embed(child)
local function prepareDB() local function prepareDB()
local faction = UnitFactionGroup('player') local faction = UnitFactionGroup('player')
local realm = GetNormalizedRealmName() local realm = GetRealmName()
local player = UnitName("player") local player = UnitName("player")
addonTable['db']['profile'][childName] = addonTable['db']['profile'][childName] or {} addon['db']['profile'][childName] = addon['db']['profile'][childName] or {}
db = addonTable['db']['profile'][childName] db = addon['db']['profile'][childName]
db[faction] = db[faction] or {} db[faction] = db[faction] or {}
dbf = db[faction] dbf = db[faction]
dbf[realm] = dbf[realm] or {} dbf[realm] = dbf[realm] or {}
dbr = dbf[realm] dbr = dbf[realm]
dbr[player] = dbr[player] or { dbr[player] = dbr[player] or {
['mail'] = 0, ['mail'] = 0,
['mailunread'] = 0 ['mailunread'] = 0
} }
dbp = dbr[player] dbp = dbr[player]
end child['db'] = db
local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName) addon['callbacks']:Fire(format("Init%s", childName))
end
local function iterateMail() local function mailupdate()
for i = 1, GetInboxNumItems() do if(not scanned) then
if(not select(9,GetInboxHeaderInfo(i))) then return dbp['mailunread'], dbp['mail']
return 1 else
end local cur, tot = GetInboxNumItems()
end dbp['mail'] = tot
return return dbp['mailunread'], tot
end end
local function OnText(message) end
if(ldbobj and ldbobj['text'] ~= message) then local function mail()
ldbobj['text'] = message local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM
end local index,newunread = 0,0
end local unread, tot = mailupdate()
local function mailupdate() subject = "start"
if(not scanned) then while(subject) do
return dbp['mailunread'], dbp['mail'] index = index + 1
else packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM = GetInboxHeaderInfo(index)
local cur, tot = GetInboxNumItems() if(subject and not wasRead) then
dbp['mail'] = tot newunread = newunread + 1
return dbp['mailunread'], tot if(GetInboxNumItems() == 0 and scanned) then
end newunread = 0
end end
local function mail() end
local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM end
local index,newunread = 0,0 if(not(dbp['mail'] > 0 and GetInboxNumItems() == 0)) then
local unread, tot = mailupdate() dbp['mailunread'] = newunread
subject = "start" end
while(subject) do if(dbp['newmail']) then
index = index + 1 if(HasNewMail() and tot == 0) then
packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM = GetInboxHeaderInfo(index) tot = #{GetLatestThreeSenders()}
if(subject and not wasRead) then if(scanned and select(2,GetInboxNumItems()) == 0) then
newunread = newunread + 1 tot = 0
if(GetInboxNumItems() == 0 and scanned) then end
newunread = 0 end
end if(dbp['mailunread'] == 0) then
end dbp['mailunread'] = 1
end end
if(not(dbp['mail'] > 0 and GetInboxNumItems() == 0)) then if(tot == 0) then
dbp['mailunread'] = newunread return tot
end else
if(dbp['newmail']) then return (dbp['mailunread'] .. "/" .. tot)
if(HasNewMail() and tot == 0) then end
tot = #{GetLatestThreeSenders()} else
if(scanned and select(2,GetInboxNumItems()) == 0) then return tot
tot = 0 end
end end
end local function iterateMail()
if(dbp['mailunread'] == 0) then for i = 1, GetInboxNumItems() do
dbp['mailunread'] = 1 if(not select(9,GetInboxHeaderInfo(i))) then
end return 1
if(tot == 0) then end
return tot end
else return
return (dbp['mailunread'] .. "/" .. tot) end
end function events:MAIL_SHOW(event)
else dbp['newmail'] = HasNewMail()
return tot if(MailFrame:IsVisible() and GetInboxNumItems() > 0) then
end dbp['newmail'] = iterateMail()
end end
local origME child:OnText(childName, child:colorize(mail(),dbp['newmail'] and "00ff00" or "ffffff"))
local function hideMapMail() if(event == "MAIL_SHOW") then
origME = MiniMapMailFrame:GetScript("OnEvent") scanned = true
MiniMapMailFrame:Hide() elseif(event == "UPDATE_PENDING_MAIL") then
MiniMapMailFrame:SetScript("OnEvent", nil) scanned = false
end end
local function showMapMail() end
MiniMapMailFrame:Show() events.MAIL_CLOSED = events.MAIL_SHOW
MiniMapMailFrame:SetScript("OnEvent", origME) child['specs'] = {
origME = nil ['name'] = childName,
end ['sv'] = true,
events.MAIL_SHOW = function(self, event) ['cfg'] = true,
-- print(event) ['cfgReset'] = prepareDB,
dbp['newmail'] = HasNewMail() ['ldb'] = child['ldb'],
if(MailFrame:IsVisible() and GetInboxNumItems() > 0) then ['defaults'] = {
dbp['newmail'] = iterateMail() ['profile'] = {
end [childName] = {}
OnText(addonTable:colorize(mail(),dbp['newmail'] and "00ff00" or "ffffff")) }
if(event == "MAIL_SHOW") then }
scanned = true }
elseif(event == "UPDATE_PENDING_MAIL") then function events:PLAYER_ENTERING_WORLD()
scanned = false if(not realm) then
end prepareDB()
end else
events.MAIL_INBOX_UPDATE = events.MAIL_SHOW child:UnregisterEvent('PLAYER_ENTERING_WORLD')
events.UPDATE_PENDING_MAIL = events.MAIL_SHOW child:RegisterEvent({'MAIL_INBOX_UPDATE', 'UPDATE_PENDING_MAIL'}, events.MAIL_SHOW)
function events:PLAYER_ENTERING_WORLD(event) events.MAIL_SHOW()
prepareDB() end
ldbobj = LibStub:GetLibrary("zzLDB"):GetLDB(childName) end
addonTable:UnregisterEvent('PLAYER_ENTERING_WORLD') child:NewAddOn(...)
local config = LibStub:GetLibrary("zzConfig")
local main = addonTable['options']['args'][childName]
config:AddConfigEntry(main, "showOrgMail", "toggle", 'Show Mail', 'Show original Minimap Symbol',1)
if(not db['showOrgMail']) then hideMapMail() end
end
local function OnClick(self, button)
if(IsShiftKeyDown() and button == "LeftButton") then
addonTable['db']['global']['ldbicons'][childName]['hide'] = not addonTable['db']['global']['ldbicons'][childName]['hide']
if(ldbicon) then
if(addonTable['db']['global']['ldbicons'][childName]['hide']) then
ldbicon:Hide(childName)
else
ldbicon:Show(childName)
end
end
else
if(not InCombatLockdown()) then
if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(childName)
InterfaceOptionsFrame_OpenToCategory(childName) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory
end
end
end
end
local function OnTooltipShow(tip)
tip:AddLine(childName)
local senderlist = {GetLatestThreeSenders()}
for _,v in ipairs(senderlist) do
tip:AddLine(addonTable:colorize(v,"ffffff"))
end
events.MAIL_SHOW(addonTable, 'FIRE')
end
function addonTable:PrefChanged(pref, value, oldvalue)
if(not db['showOrgMail'] and not origME) then
hideMapMail()
elseif(db['showOrgMail']) then
showMapMail()
end
end
local specs = {
['name'] = childName,
['sv'] = true,
['cfg'] = true,
['cfgReset'] = prepareDB,
['ldb'] = { -- https://github.com/tekkub/libdatabroker-1-1/wiki/Data-Specifications
['type'] = 'data source', -- required: 'data source' or 'launcher'
['text'] = childName, -- required/optional for launcher
['icon'] = format("%s\\icon2.tga", folder), -- optional/required for launcher
['OnClick'] = OnClick, -- optional/required for launcher
['OnTooltipShow'] = OnTooltipShow, -- optional
} ,
['defaults'] = {
['profile'] = {
[childName] = {}
}
}
}
LibStub:GetLibrary("zzAddOn"):NewAddOn(specs, ...)

8
init.lua Normal file
View File

@ -0,0 +1,8 @@
local addonName, addon = ...
addon['childName'] = "zz_Mailbox"
addon['callbacks'] = addon['callbacks'] or LibStub("CallbackHandler-1.0"):New(addon)
addon[addon['childName']] = {
['parentName'] = addonName ~= addon['childName'] and addonName or nil,
['events'] = {}
}
LibStub:GetLibrary("zzAddOn"):Embed(addon[addon['childName']])

8
locale_enUS.lua Normal file
View File

@ -0,0 +1,8 @@
local addonname, addon = ...
local childName = addon['childName']
local L = LibStub("AceLocale-3.0"):NewLocale(childName, "enUS", true)
if L then
L[childName] = childName
L['Show Mail'] = true
L['Show original Minimap Symbol'] = true
end

View File

@ -1,4 +1,7 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> <Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Script file="helper.lua"/> <Script file="init.lua"/>
<Script file="core.lua"/> <Script file="locale_enUS.lua"/>
<Script file="prefs.lua"/>
<Script file="broker.lua"/>
<Script file="core.lua"/>
</Ui> </Ui>

33
prefs.lua Normal file
View File

@ -0,0 +1,33 @@
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
local origME
local function hideMapMail()
origME = MiniMapMailFrame:GetScript("OnEvent")
MiniMapMailFrame:Hide()
MiniMapMailFrame:SetScript("OnEvent", nil)
end
local function showMapMail()
MiniMapMailFrame:Show()
MiniMapMailFrame:SetScript("OnEvent", origME)
origME = nil
end
function child:PrefChanged(...)
if(not db['showOrgMail'] and not origME) then
hideMapMail()
elseif(db['showOrgMail']) then
showMapMail()
end
end
local init = {
Setup = function(self)
db =child['db']
local config = LibStub:GetLibrary("zzConfig")
local options = child['options']
local main = options['args'][childName]
config:AddConfigEntry(main, "showOrgMail", "toggle", L['Show Mail'], L['Show original Minimap Symbol'],1)
if(not db['showOrgMail']) then hideMapMail() end
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup')

View File

@ -1,12 +1,10 @@
## Interface: 90005 ## Interface: 90005
## X-Repository: https://git.grml.de/rilgamon/zz_Mailbox.git ## X-Repository: https://git.grml.de/rilgamon/zz_Mailbox.git
## X-WoWI-ID: 20501 ## X-WoWI-ID: 20501
## X-Curse-Project-ID: 39073 ## X-Curse-Project-ID: 39073
## X-TOC-Classic: 11302 ## X-TOC-Classic: 11302
## Title: Mailbox ## Title: Mailbox
## Notes: You've got mail ## OptionalDeps: zzLib, Ace3, BrokerPack
## Author: Rilgamon ## SavedVariables: zz_MailboxDB
## SavedVariables: zz_MailboxDB Libs\embeds.xml
## OptionalDeps: zzLib, Ace3, BrokerPack pack.xml
Libs\embeds.xml
pack.xml