diff --git a/Libs/AceConfig-3.0/AceConfig-3.0.xml b/Libs/AceConfig-3.0/AceConfig-3.0.xml
index d9eb96a..84c8d03 100755
--- a/Libs/AceConfig-3.0/AceConfig-3.0.xml
+++ b/Libs/AceConfig-3.0/AceConfig-3.0.xml
@@ -5,4 +5,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml b/Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml
index b2f2c20..c8caf34 100755
--- a/Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml
+++ b/Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua b/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua
index a2930e2..f8386c7 100755
--- a/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua
+++ b/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua
@@ -1,13 +1,13 @@
--- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables.
-- @class file
-- @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 gui = LibStub("AceGUI-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)
if not AceConfigDialog then return end
@@ -544,12 +544,13 @@ local function GetFuncName(option)
end
do
local frame = AceConfigDialog.popup
- if not frame then
+ if not frame or oldminor < 81 then
frame = CreateFrame("Frame", nil, UIParent)
AceConfigDialog.popup = frame
frame:Hide()
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetSize(320, 72)
+ frame:EnableMouse(true) -- Do not allow click-through on the frame
frame:SetFrameStrata("TOOLTIP")
frame:SetFrameLevel(100) -- Lots of room to draw under it
frame:SetScript("OnKeyDown", function(self, key)
@@ -575,7 +576,7 @@ do
insets = { left = 11, right = 11, top = 11, bottom = 11 },
})
else
- local border = CreateFrame("Frame", nil, frame, "DialogBorderDarkTemplate")
+ local border = CreateFrame("Frame", nil, frame, "DialogBorderOpaqueTemplate")
border:SetAllPoints(frame)
frame:SetFixedFrameStrata(true)
frame:SetFixedFrameLevel(true)
diff --git a/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml b/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml
index 69597e9..068be6f 100755
--- a/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml
+++ b/Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml b/Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml
index f65f5dd..5989072 100755
--- a/Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml
+++ b/Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceDB-3.0/AceDB-3.0.xml b/Libs/AceDB-3.0/AceDB-3.0.xml
index e825f7b..28998e5 100755
--- a/Libs/AceDB-3.0/AceDB-3.0.xml
+++ b/Libs/AceDB-3.0/AceDB-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml b/Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml
index a34c086..9ecffa1 100755
--- a/Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml
+++ b/Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/AceLocale-3.0/AceLocale-3.0.xml b/Libs/AceLocale-3.0/AceLocale-3.0.xml
index d69dbb1..a4cf340 100755
--- a/Libs/AceLocale-3.0/AceLocale-3.0.xml
+++ b/Libs/AceLocale-3.0/AceLocale-3.0.xml
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
diff --git a/Libs/embeds.xml b/Libs/embeds.xml
index 6597053..9a9f19e 100755
--- a/Libs/embeds.xml
+++ b/Libs/embeds.xml
@@ -8,6 +8,7 @@
+
diff --git a/Libs/zzAddOn/zzAddOn.lua b/Libs/zzAddOn/zzAddOn.lua
index c684eda..23c8cb4 100644
--- a/Libs/zzAddOn/zzAddOn.lua
+++ b/Libs/zzAddOn/zzAddOn.lua
@@ -1,33 +1,80 @@
-local lib, oldminor = LibStub:NewLibrary("zzAddOn", 2)
+local lib = LibStub:NewLibrary("zzAddOn", 5)
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['addons'] = lib['addons'] or {}
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']
+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)
- if(self['specs']) then
- return self['specs'][childName]
+ return lib['addons'][childName]['specs']
+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
-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
- for ev, func in pairs(event) do
+ for k, v in pairs(event) do
-- 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
self['events'][ev] = func
end
- self:RegisterEvent(ev)
+ self:RegisterEvent(ev, func)
end
elseif(type(event) == 'string') then
-- print("[zza] Register CB", type(event),event)
if(not lib['events']:IsEventRegistered(event)) then
lib['events']:RegisterEvent(event)
end
- lib['RegisterCallback'](self['events'], event)
+ lib.RegisterCallback(self, event, globalfunc)
else
- print("ign reg", type(event), event)
+ errormsg("ign reg", type(event), event)
end
end
function lib:UnregisterEvent(event)
@@ -36,29 +83,42 @@ function lib:UnregisterEvent(event)
self:UnregisterEvent(ev)
end
else
- lib['UnregisterCallback'](self['events'], event)
+ lib['UnregisterCallback'](self, event)
end
+-- print('unreg', event)
end
function lib:IsClassic()
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
end
-function lib:NewAddOn(specs, addonName, addonTable)
+function lib:NewAddOn(addonName, addonTable)
+ local specs = self['specs']
local childName = specs['name']
- addonTable['parentName'] = addonName
- addonTable['specs'] = addonTable['specs'] or {}
- addonTable['specs'][childName] = specs
+ if(lib['addons'][childName]) then
+ local oldchild = lib['addons'][childName]
+ 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
- lib['addons'][childName] = addonTable
- lib:Embed(addonTable)
- if(addonTable['events']) then
- for ev, func in pairs(addonTable['events']) do
+ self.GetAddOnTable = function() return addonTable end
+ lib['addons'][childName] = self
+ lib:Embed(self)
+ 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
--- print("[zza] Register", ev)
- addonTable:RegisterEvent(ev)
+ self:RegisterEvent(ev, func)
end
end
end
- return lib['addons'][childName]
+ return self
end
end
function lib:Embed(target)
@@ -66,35 +126,73 @@ function lib:Embed(target)
target[name] = lib[name]
end
end
-for target, _ in pairs(lib['addons']) do
+for _, target in pairs(lib['addons']) do
lib:Embed(target)
end
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, ...)
-- print("[zza]", self, event, ...)
local addonName = ...
- local addon = lib['addons'][addonName]
- if(addon) then
+ local child = lib['addons'][addonName]
+ if(child) then
if(event == 'ADDON_LOADED') then
- local specs = addon:GetSpecs(addonName)
- 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
+ SetupSpecs(addonName, child)
end
end
-- print("[zza] Fire", event, ...)
- lib['callbacks']:Fire(event, ...)
+ lib['callbacks']:Fire(event, self, event, ...)
end)
\ No newline at end of file
diff --git a/Libs/zzConfig/zzConfig.lua b/Libs/zzConfig/zzConfig.lua
index b6794ae..6137cf0 100644
--- a/Libs/zzConfig/zzConfig.lua
+++ b/Libs/zzConfig/zzConfig.lua
@@ -1,27 +1,27 @@
-local lib, oldminor = LibStub:NewLibrary("zzConfig", 2)
+local lib = LibStub:NewLibrary("zzConfig", 3)
if not lib then return end
-oldminor = oldminor or 0
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
-local mixins = {'AddConfigMenu','AddConfigEntry','InitConfig'}
+local mixins = {'AddConfigMenu', 'AddConfigEntry', 'InitConfig', 'GetDefaultHandler'}
lib['configs'] = lib['configs'] or {}
local function getDB(objname)
if(ldbicon) then
ldbicon:Show(objname)
local iconbtn = ldbicon:GetMinimapButton(objname)
- local db = iconbtn['db']
- if(db['hide']) then
- ldbicon:Hide(objname)
+ if(iconbtn) then
+ local db = iconbtn['db']
+ if(db['hide']) then
+ ldbicon:Hide(objname)
+ end
+ return db
+ else
+ print("noicon", objname)
end
- return db
end
-end
-local function ldbiconUpdate(objname)
- local db = getDB(objname)
+ return {}
end
local function minimapGet(pref)
local objname = pref[#pref - 2]
--- print('gp', objname, pref)
local db = getDB(objname)
return db[pref[#pref]]
end
@@ -29,7 +29,6 @@ local function minimapSet(pref,value)
local objname = pref[#pref - 2]
local db = getDB(objname)
db[pref[#pref]] = value
- ldbiconUpdate(objname)
end
local function notify(pref, value, oldvalue)
if(type(pref['handler'].PrefChanged) == 'function') then
@@ -38,26 +37,41 @@ local function notify(pref, value, oldvalue)
end
local function getPref(pref)
if(type(pref['handler']['GetPref']) == 'function') then
--- print("use handler getpref", pref[#pref])
return pref['handler']:GetPref(pref)
end
--- for i = 1, #pref do
--- print(i, pref[i])
--- end
--- print("use default getpref", pref[#pref], pref['handler']['db']['profile'][pref[#pref]])
- return pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]]
+ local db = pref['handler']['db'] or pref['handler']:GetAddOnTable()['db']['profile'][pref['appName']]
+ return db and db[pref[#pref]]
end
-local function setPref(pref,value)
+local function setPref(pref, value, ...)
if(type(pref['handler']['SetPref']) == 'function') then
- pref['handler']:SetPref(pref,value)
+ pref['handler']:SetPref(pref, value, ...)
else
- local oldvalue = pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]]
- pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]] = value
+ local db = pref['handler']['db'] or pref['handler']:GetAddonTable()['db']['profile'][pref[#pref-1]]
+ local oldvalue = db[pref[#pref]]
+ db[pref[#pref]] = value
if(value ~= oldvalue) then
notify(pref, value, oldvalue)
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)
options['args'][conf] = {
['name']="Minimapicon",
@@ -104,24 +118,26 @@ function lib:AddConfigEntry(options, ...)
elseif(input[2] == 'select') then
menu['values'] = input[6]
elseif(input[2] == 'group') then
- menu['inline'] = input[6]
+ menu['inline'] = input[7]
+ menu['handler'] = input[6]
menu['args'] = {
['description'] = {
['name'] = input[4],
['type'] = 'header',
['order'] = 0
- }
+ },
}
end
options['args'][input[1]] = menu
return menu
end
end
-function lib:AddConfigMenu(options, parentName, handler, order, more)
+function lib:AddConfigMenu(options, parentName, order, handler, more)
local menu = {
['name'] = parentName,
['type'] = 'group',
['handler'] = handler or self['handler'],
+ ['childGroups'] =' tab',
['order'] = order or 1,
['args'] = {}
}
@@ -133,22 +149,41 @@ function lib:AddConfigMenu(options, parentName, handler, order, more)
options['args'][parentName] = menu
return options['args'][parentName]
end
-function lib:InitConfig(addon, parentName, gp, sp)
- addon['options'] = {
- ['type']='group',
- ['handler']=addon,
- ['get']=gp or getPref,
- ['set']=sp or setPref,
- ['childGroups']='tab',
- ['args']={}
+function lib:InitConfig(child, parentName, gp, sp)
+ local pp = child['specs']['name'] == parentName
+ child['options'] = {
+ ['name'] = parentName,
+ ['type'] = 'group',
+ ['handler'] = child,
+ ['childGroups'] = 'tab',
+ ['get'] = gp or getPref,
+ ['set'] = sp or setPref,
+ ['args'] = {}
}
- local options = addon['options']
+ local options = child['options']
local par = self:AddConfigMenu(options, parentName)
self:AddLDBIconOptions(par, 'minimap')
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
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)
for _,name in pairs(mixins) do
target[name] = lib[name]
diff --git a/Libs/zzHelper/zzHelper.lua b/Libs/zzHelper/zzHelper.lua
new file mode 100644
index 0000000..7d172e4
--- /dev/null
+++ b/Libs/zzHelper/zzHelper.lua
@@ -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
\ No newline at end of file
diff --git a/Libs/zzLDB/zzLDB.lua b/Libs/zzLDB/zzLDB.lua
index 6212f73..af84790 100644
--- a/Libs/zzLDB/zzLDB.lua
+++ b/Libs/zzLDB/zzLDB.lua
@@ -1,9 +1,9 @@
-local lib, oldminor = LibStub:NewLibrary("zzLDB", 2)
+local lib, oldminor = LibStub:NewLibrary("zzLDB", 4)
if not lib then return end
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
oldminor = oldminor or 0
-local mixins = {'AddLDB', 'GetLDB'}
+local mixins = {'AddLDB', 'GetLDB', 'DefaultOnClick', 'DefaultOnText'}
local defaults = {
['hide'] = false,
}
@@ -11,6 +11,32 @@ lib['ldbs'] = lib['ldbs'] or {}
local function proto_OnClick(self, button)
print("onclick required", self, button)
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)
return ldb:GetDataObjectByName(objname)
end
@@ -28,7 +54,10 @@ function lib:AddLDB(objname, obj, db)
db['global']['ldbicons'] = db['global']['ldbicons'] or {}
local sb = db['global']['ldbicons']
sb[objname] = sb[objname] or CopyTable(defaults)
+ local oldstatus = sb[objname]['hide']
+ sb[objname]['hide'] = false
ldbicon:Register(objname, ldbobj, sb[objname])
+ sb[objname]['hide'] = oldstatus
end
return ldbobj
end
@@ -38,6 +67,7 @@ function lib:Embed(target)
for _,name in pairs(mixins) do
target[name] = lib[name]
end
+ lib['ldbs'][target] = true
end
for target, _ in pairs(lib['ldbs']) do
lib:Embed(target)
diff --git a/broker.lua b/broker.lua
new file mode 100644
index 0000000..49ea0d4
--- /dev/null
+++ b/broker.lua
@@ -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)
\ No newline at end of file
diff --git a/core.lua b/core.lua
index e5d109b..7eb5ce8 100644
--- a/core.lua
+++ b/core.lua
@@ -1,174 +1,113 @@
-local addonName, addonTable = ...
-local childName = "zz_Mailbox"
-local db, dbf, dbr,dbp, scanned, ldbobj
-addonTable['events'] = addonTable['events'] or {}
-local events = addonTable['events']
-local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
-local function prepareDB()
- local faction = UnitFactionGroup('player')
- local realm = GetNormalizedRealmName()
- local player = UnitName("player")
- addonTable['db']['profile'][childName] = addonTable['db']['profile'][childName] or {}
- db = addonTable['db']['profile'][childName]
- db[faction] = db[faction] or {}
- dbf = db[faction]
- dbf[realm] = dbf[realm] or {}
- dbr = dbf[realm]
- dbr[player] = dbr[player] or {
- ['mail'] = 0,
- ['mailunread'] = 0
- }
- dbp = dbr[player]
-end
-local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName)
-
-local function iterateMail()
- for i = 1, GetInboxNumItems() do
- if(not select(9,GetInboxHeaderInfo(i))) then
- return 1
- end
- end
- return
-end
-local function OnText(message)
- if(ldbobj and ldbobj['text'] ~= message) then
- ldbobj['text'] = message
- end
-end
-local function mailupdate()
- if(not scanned) then
- return dbp['mailunread'], dbp['mail']
- else
- local cur, tot = GetInboxNumItems()
- dbp['mail'] = tot
- return dbp['mailunread'], tot
- end
-end
-local function mail()
- local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM
- local index,newunread = 0,0
- local unread, tot = mailupdate()
- subject = "start"
- while(subject) do
- index = index + 1
- packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM = GetInboxHeaderInfo(index)
- if(subject and not wasRead) then
- newunread = newunread + 1
- if(GetInboxNumItems() == 0 and scanned) then
- newunread = 0
- end
- end
- end
- if(not(dbp['mail'] > 0 and GetInboxNumItems() == 0)) then
- dbp['mailunread'] = newunread
- end
- if(dbp['newmail']) then
- if(HasNewMail() and tot == 0) then
- tot = #{GetLatestThreeSenders()}
- if(scanned and select(2,GetInboxNumItems()) == 0) then
- tot = 0
- end
- end
- if(dbp['mailunread'] == 0) then
- dbp['mailunread'] = 1
- end
- if(tot == 0) then
- return tot
- else
- return (dbp['mailunread'] .. "/" .. tot)
- end
- else
- return tot
- end
-end
-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
-events.MAIL_SHOW = function(self, event)
--- print(event)
- dbp['newmail'] = HasNewMail()
- if(MailFrame:IsVisible() and GetInboxNumItems() > 0) then
- dbp['newmail'] = iterateMail()
- end
- OnText(addonTable:colorize(mail(),dbp['newmail'] and "00ff00" or "ffffff"))
- if(event == "MAIL_SHOW") then
- scanned = true
- elseif(event == "UPDATE_PENDING_MAIL") then
- scanned = false
- end
-end
-events.MAIL_INBOX_UPDATE = events.MAIL_SHOW
-events.UPDATE_PENDING_MAIL = events.MAIL_SHOW
-function events:PLAYER_ENTERING_WORLD(event)
- prepareDB()
- ldbobj = LibStub:GetLibrary("zzLDB"):GetLDB(childName)
- addonTable:UnregisterEvent('PLAYER_ENTERING_WORLD')
- 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, ...)
\ No newline at end of file
+local addonName, addon = ...
+local childName = addon['childName']
+local child = addon[childName]
+local events = child['events']
+local db, dbf, dbr,dbp, scanned, ldbobj
+LibStub("zzHelper"):Embed(child)
+local function prepareDB()
+ local faction = UnitFactionGroup('player')
+ local realm = GetRealmName()
+ local player = UnitName("player")
+ addon['db']['profile'][childName] = addon['db']['profile'][childName] or {}
+ db = addon['db']['profile'][childName]
+ db[faction] = db[faction] or {}
+ dbf = db[faction]
+ dbf[realm] = dbf[realm] or {}
+ dbr = dbf[realm]
+ dbr[player] = dbr[player] or {
+ ['mail'] = 0,
+ ['mailunread'] = 0
+ }
+ dbp = dbr[player]
+ child['db'] = db
+ addon['callbacks']:Fire(format("Init%s", childName))
+end
+local function mailupdate()
+ if(not scanned) then
+ return dbp['mailunread'], dbp['mail']
+ else
+ local cur, tot = GetInboxNumItems()
+ dbp['mail'] = tot
+ return dbp['mailunread'], tot
+ end
+end
+local function mail()
+ local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM
+ local index,newunread = 0,0
+ local unread, tot = mailupdate()
+ subject = "start"
+ while(subject) do
+ index = index + 1
+ packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM = GetInboxHeaderInfo(index)
+ if(subject and not wasRead) then
+ newunread = newunread + 1
+ if(GetInboxNumItems() == 0 and scanned) then
+ newunread = 0
+ end
+ end
+ end
+ if(not(dbp['mail'] > 0 and GetInboxNumItems() == 0)) then
+ dbp['mailunread'] = newunread
+ end
+ if(dbp['newmail']) then
+ if(HasNewMail() and tot == 0) then
+ tot = #{GetLatestThreeSenders()}
+ if(scanned and select(2,GetInboxNumItems()) == 0) then
+ tot = 0
+ end
+ end
+ if(dbp['mailunread'] == 0) then
+ dbp['mailunread'] = 1
+ end
+ if(tot == 0) then
+ return tot
+ else
+ return (dbp['mailunread'] .. "/" .. tot)
+ end
+ else
+ return tot
+ end
+end
+local function iterateMail()
+ for i = 1, GetInboxNumItems() do
+ if(not select(9,GetInboxHeaderInfo(i))) then
+ return 1
+ end
+ end
+ return
+end
+function events:MAIL_SHOW(event)
+ dbp['newmail'] = HasNewMail()
+ if(MailFrame:IsVisible() and GetInboxNumItems() > 0) then
+ dbp['newmail'] = iterateMail()
+ end
+ child:OnText(childName, child:colorize(mail(),dbp['newmail'] and "00ff00" or "ffffff"))
+ if(event == "MAIL_SHOW") then
+ scanned = true
+ elseif(event == "UPDATE_PENDING_MAIL") then
+ scanned = false
+ end
+end
+events.MAIL_CLOSED = events.MAIL_SHOW
+child['specs'] = {
+ ['name'] = childName,
+ ['sv'] = true,
+ ['cfg'] = true,
+ ['cfgReset'] = prepareDB,
+ ['ldb'] = child['ldb'],
+ ['defaults'] = {
+ ['profile'] = {
+ [childName] = {}
+ }
+ }
+}
+function events:PLAYER_ENTERING_WORLD()
+ if(not realm) then
+ prepareDB()
+ else
+ child:UnregisterEvent('PLAYER_ENTERING_WORLD')
+ child:RegisterEvent({'MAIL_INBOX_UPDATE', 'UPDATE_PENDING_MAIL'}, events.MAIL_SHOW)
+ events.MAIL_SHOW()
+ end
+end
+child:NewAddOn(...)
\ No newline at end of file
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..a8356a9
--- /dev/null
+++ b/init.lua
@@ -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']])
diff --git a/locale_enUS.lua b/locale_enUS.lua
new file mode 100644
index 0000000..ff6f434
--- /dev/null
+++ b/locale_enUS.lua
@@ -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
\ No newline at end of file
diff --git a/pack.xml b/pack.xml
index 965c8f8..6561d66 100644
--- a/pack.xml
+++ b/pack.xml
@@ -1,4 +1,7 @@
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/prefs.lua b/prefs.lua
new file mode 100644
index 0000000..ebbc15b
--- /dev/null
+++ b/prefs.lua
@@ -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')
\ No newline at end of file
diff --git a/zz_Mailbox.toc b/zz_Mailbox.toc
index afa9630..540467a 100644
--- a/zz_Mailbox.toc
+++ b/zz_Mailbox.toc
@@ -1,12 +1,10 @@
-## Interface: 90005
-## X-Repository: https://git.grml.de/rilgamon/zz_Mailbox.git
-## X-WoWI-ID: 20501
-## X-Curse-Project-ID: 39073
-## X-TOC-Classic: 11302
-## Title: Mailbox
-## Notes: You've got mail
-## Author: Rilgamon
-## SavedVariables: zz_MailboxDB
-## OptionalDeps: zzLib, Ace3, BrokerPack
-Libs\embeds.xml
-pack.xml
+## Interface: 90005
+## X-Repository: https://git.grml.de/rilgamon/zz_Mailbox.git
+## X-WoWI-ID: 20501
+## X-Curse-Project-ID: 39073
+## X-TOC-Classic: 11302
+## Title: Mailbox
+## OptionalDeps: zzLib, Ace3, BrokerPack
+## SavedVariables: zz_MailboxDB
+Libs\embeds.xml
+pack.xml
\ No newline at end of file