Use zzLibs 2021-03-21

This commit is contained in:
rilgamon 2021-03-21 17:12:55 +01:00
parent 03c4e24880
commit 29f50033c1
14 changed files with 465 additions and 348 deletions

View File

@ -1,31 +1,75 @@
local lib, oldminor = LibStub:NewLibrary("zzAddOn", 2)
local lib = LibStub:NewLibrary("zzAddOn", 4)
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 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)
end
@ -36,29 +80,32 @@ 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(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)
@ -70,31 +117,69 @@ 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)

View File

@ -2,21 +2,23 @@ local lib = LibStub:NewLibrary("zzConfig", 3)
if not lib then return end
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
local mixins = {'AddConfigMenu','AddConfigEntry','InitConfig', 'GetDefaultHandler'}
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]
@ -27,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,14 +39,16 @@ local function getPref(pref)
if(type(pref['handler']['GetPref']) == 'function') then
return pref['handler']:GetPref(pref)
end
return pref['handler']['db']['profile'][pref[#pref-1]] and pref['handler']['db']['profile'][pref[#pref-1]][pref[#pref]] or nil
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
@ -134,6 +137,7 @@ function lib:AddConfigMenu(options, parentName, order, handler, more)
['name'] = parentName,
['type'] = 'group',
['handler'] = handler or self['handler'],
['childGroups'] =' tab',
['order'] = order or 1,
['args'] = {}
}
@ -145,22 +149,41 @@ function lib:AddConfigMenu(options, parentName, order, handler, 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]

View File

@ -141,10 +141,12 @@ end
]]
function lib:IsTwink(name)
local at = self:GetAddOnTable()
local db = at['db']
local realm = GetRealmName()
local _
if(self['db']['sv']['profileKeys']) then
for k,v in pairs(self['db']['sv']['profileKeys']) do
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

View File

@ -1,9 +1,9 @@
local lib, oldminor = LibStub:NewLibrary("zzLDB", 3)
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

View File

@ -1,17 +1,8 @@
local addonName, addonTable = ...
addonTable['events'] = addonTable['events'] or {}
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local db, mailSum, mailRec, player, dbb, dbr, dbf, L, faction, realm
local events = addonTable['events']
function addonTable:SetupBanker()
player = UnitName('player')
L = addonTable['storage']['L']
db = addonTable['storage']['db']
dbr = addonTable['storage']['dbr']
dbf = addonTable['storage']['dbf']
dbb = dbf['banker']
faction = addonTable['storage']['faction']
realm = addonTable['storage']['realm']
end
local events = child['events']
local mailframes = {}
local posFrame = CreateFrame("Frame")
posFrame:SetSize(32,1)
@ -35,8 +26,8 @@ local lastframe = posFrame
local function GetFactionList()
local n,m,_
local l = {}
if(addonTable['db']['sv']['profileKeys']) then
for k,v in pairs(addonTable['db']['sv']['profileKeys']) do
if(addon['db']['sv']['profileKeys']) then
for k,v in pairs(addon['db']['sv']['profileKeys']) do
n,_,m = strsplit(' ',k,3)
if(n) then
if(m == realm) then
@ -71,7 +62,7 @@ local function getDeliver(name)
end
local function Click(self,button)
local sendSum = getDeliver(self['destName'])
if(addonTable:IsTwink(self['destName']) and self['destName']~=player) then
if(child:IsTwink(self['destName']) and self['destName']~=player) then
if(sendSum>0) then
if(SetSendMailMoney(sendSum)) then
posFrame:RegisterEvent('MAIL_SEND_SUCCESS')
@ -83,7 +74,6 @@ local function Click(self,button)
end
end
end
local function Mouse(self)
local tip = GameTooltip
tip:SetOwner(self, "ANCHOR_BOTTOM")
@ -161,3 +151,16 @@ end
function events:MAIL_SHOW()
buildMailFrames()
end
local init = {
Setup = function(self)
player = UnitName('player')
L = child['storage']['L']
db = child['storage']['db']
dbr = child['storage']['dbr']
dbf = child['storage']['dbf']
dbb = dbf['banker']
faction = child['storage']['faction']
realm = child['storage']['realm']
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup')

View File

@ -1,29 +1,18 @@
local addonName, addonTable = ...
local childName = "zz_Money"
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local db, dbr, dbp, L, lineIn, lineOut, session, faction, realm
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
function addonTable:SetupBroker()
L = addonTable['storage']['L']
db = addonTable['storage']['db']
dbr = addonTable['storage']['dbr']
dbp = addonTable['storage']['dbp']
session = addonTable['storage']['session']
faction = addonTable['storage']['faction']
realm = addonTable['storage']['realm']
local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName)
lineIn = format("|T%s:0|t %s", format("%s\\in.tga", folder), L['Einnahmen'])
lineOut = format("|T%s:0|t %s", format("%s\\out.tga", folder), L['Ausgaben'])
end
local zzLDB = LibStub:GetLibrary("zzLDB")
local function cdbCheck(n,realm)
db[realm] = db[realm] or {}
db[realm][n] = db[realm][n] or { currentGold = 0 }
end
addonTable.cdbCheck = cdbCheck
child.cdbCheck = cdbCheck
local function getSumToday(d)
if(faction=='Neutral') then return 0,0 end
local sumIn,sumOut = 0,0
d = d or 0
local day = addonTable:getDateString() + d
local day = child:getDateString() + d
for a,b in pairs(dbr['activity'][faction][tostring(day)] or {}) do
if(b < 0) then
sumOut = sumOut + b
@ -53,118 +42,117 @@ local function Helper_Tooltip3(realm)
end
end
end
addonTable.Helper_Tooltip3 = Helper_Tooltip3
child.Helper_Tooltip3 = Helper_Tooltip3
local function OnClick(self, button)
if(IsShiftKeyDown() and button == "LeftButton") then
local sb = addonTable['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(not InCombatLockdown()) then
if(InterfaceOptionsFrame:IsVisible()) then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(childName)
InterfaceOptionsFrame_OpenToCategory(childName) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory
end
end
end
zzLDB:DefaultOnClick(self, button, addon, childName)
end
local function OnTooltipShow(tip)
tip:AddLine(childName)
if(faction == 'Neutral') then
tip:AddLine(L['neutral'])
return
end
local sessdiff = dbp['currentGold'] - session['start']
local sdr,sdg,sdb = 1, 1, 1
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
end
tip:AddDoubleLine(L['Sitzung'], addonTable:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, addonTable:displayMoney(session['income'], db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, addonTable:displayMoney(abs(session['expense']), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(childName)
if(faction == 'Neutral') then
tip:AddLine(L['neutral'])
return
end
local sessdiff = dbp['currentGold'] - session['start']
local sdr,sdg,sdb = 1, 1, 1
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
end
tip:AddDoubleLine(L['Sitzung'], child:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, child:displayMoney(session['income'], db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, child:displayMoney(abs(session['expense']), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumToday()
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['Heute'], child:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, child:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, child:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumToday(-1)
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['Gestern'], child:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, child:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, child:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumWeek()
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['7-Tage'], child:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, child:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, child:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumToday()
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['Heute'], addonTable:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, addonTable:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, addonTable:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumToday(-1)
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['Gestern'], addonTable:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, addonTable:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, addonTable:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sumOut,sumIn = getSumWeek()
sessdiff = sumOut+sumIn
if(sessdiff<0) then
sdr,sdg,sdb = 1, 0, 0
else
sdr,sdg,sdb = 1, 1, 1
end
tip:AddDoubleLine(L['7-Tage'], addonTable:displayMoney(abs(sessdiff), db['shortMoneyTip']),1,1,0,sdr,sdg,sdb)
tip:AddDoubleLine(lineIn, addonTable:displayMoney(sumIn, db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddDoubleLine(lineOut, addonTable:displayMoney(abs(sumOut), db['shortMoneyTip']),1,1,1,1,1,1)
tip:AddLine(' ')
local sum = 0
local ttlist = {}
if(addonTable['db']['sv']['profileKeys']) then
for k,v in pairs(addonTable['db']['sv']['profileKeys']) do
local n,_,m = strsplit(' ',k,3)
if(n) then
local cr = Helper_Tooltip3(m)
if(m == realm or cr) then
cdbCheck(n, m)
if( faction == db[m][n]['faction']) then
local sum = 0
local ttlist = {}
if(addon['db']['sv']['profileKeys']) then
for k,v in pairs(addon['db']['sv']['profileKeys']) do
local n,_,m = strsplit(' ',k,3)
if(n) then
local cr = Helper_Tooltip3(m)
if(m == realm or cr) then
cdbCheck(n, m)
if( faction == db[m][n]['faction']) then
-- sum = sum + db[m][n]['currentGold']
ttlist[k] = db[m][n]['currentGold']
end
elseif(db['accountMoney']) then
-- sum = sum + db[m][n]['currentGold']
ttlist[k] = db[m][n]['currentGold']
end
elseif(db['accountMoney']) then
-- sum = sum + db[m][n]['currentGold']
end
end
end
for _,v in pairs(addonTable:sortArray(ttlist,db['sortDir'])) do
local n,_,m = strsplit(' ',v,3)
local cr = Helper_Tooltip3(m)
tip:AddDoubleLine(addonTable:classcolor(n,db[cr and m or realm][n]['class']),addonTable:displayMoney(db[cr and m or realm][n]['currentGold']+(db[cr and m or realm][n]['incoming'] or 0), db['shortMoneyTip']),0,1,0,1,1,1)
end
tip:AddLine(' ')
tip:AddDoubleLine(L['Gesamt'],addonTable:displayMoney(addonTable:GetGold(db['displaySelTT'] or 2), db['shortMoneyTip']),0,1,0,1,1,1)
end
function addonTable:GetBroker(objname)
return LibStub:GetLibrary("zzLDB"):GetLDB(objname)
end
function addonTable:OnText(objname, message)
local ldbobj = addonTable:GetBroker(objname)
if(ldbobj['text'] ~= message) then
ldbobj['text'] = message
end
for _,v in pairs(child:sortArray(ttlist,db['sortDir'])) do
local n,_,m = strsplit(' ',v,3)
local cr = Helper_Tooltip3(m)
local rm = cr and m or realm
tip:AddDoubleLine(
child:classcolor(n,db[rm][n]['class']),
child:displayMoney(db[rm][n]['currentGold']+(db[rm][n]['incoming'] or 0), db['shortMoneyTip']),
0,1,0,
1,1,1
)
end
tip:AddLine(' ')
tip:AddDoubleLine(L['Gesamt'],child:displayMoney(child:GetGold(db['displaySelTT'] or 2), db['shortMoneyTip']),0,1,0,1,1,1)
end
addonTable['ldb'] = { -- https://github.com/tekkub/libdatabroker-1-1/wiki/Data-Specifications
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'] = 'Interface\\Icons\\INV_Misc_Bag_10_Blue', -- optional/required for launcher
['OnClick'] = OnClick, -- optional/required for launcher
['OnTooltipShow'] = OnTooltipShow, -- optional
}
function child:OnText(objname, message)
local ldbobj = zzLDB:GetLDB(objname)
if(ldbobj['text'] ~= message) then
ldbobj['text'] = message
end
end
local init = {
Setup = function(self, childName, event)
L = child['storage']['L']
db = child['storage']['db']
dbr = child['storage']['dbr']
dbp = child['storage']['dbp']
session = child['storage']['session']
faction = child['storage']['faction']
realm = child['storage']['realm']
local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName)
lineIn = format("|T%s:0|t %s", format("%s\\in.tga", folder), L['Einnahmen'])
lineOut = format("|T%s:0|t %s", format("%s\\out.tga", folder), L['Ausgaben'])
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup', childName)

107
core.lua
View File

@ -1,19 +1,19 @@
local addonName, addonTable = ...
local childName = "zz_Money"
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local events = child['events']
local db, dbr, dbp, faction, realm
LibStub("zzHelper"):Embed(addonTable)
addonTable['events'] = addonTable['events'] or {}
local events = addonTable['events']
LibStub("zzHelper"):Embed(child)
local session = { start = 0, income = 0, expense = 0 }
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
local function prepareDB()
local function prepareDB(self)
local player = UnitName('player')
realm = GetNormalizedRealmName()
if(not realm) then return end
faction = UnitFactionGroup('player')
local className, classFilename, classId = UnitClass('player')
addonTable['db']['profile'][childName] = addonTable['db']['profile'][childName] or {}
db = addonTable['db']['profile'][childName]
addon['db']['profile'][childName] = addon['db']['profile'][childName] or {}
db = addon['db']['profile'][childName]
db[realm] = db[realm] or {}
db[faction] = db[faction] or {}
db[faction]['banker'] = db[faction]['banker'] or {
@ -31,7 +31,7 @@ local function prepareDB()
dbp['currentGold'] = dbp['currentGold'] or 0
dbp['class'] = classFilename
dbp['faction'] = faction
addonTable['storage'] = {
child['storage'] = {
['db'] = db,
['dbr'] = dbr,
['dbp'] = dbp,
@ -41,39 +41,22 @@ local function prepareDB()
['faction'] = faction,
['realm'] = realm,
}
addonTable:SetupPrefs(childName)
addonTable:SetupBroker()
addonTable:SetupBanker()
child['db'] = db
addon['callbacks']:Fire(format("Init%s", childName))
child['events']['PLAYER_MONEY']()
end
function addonTable:getDateString()
function child:getDateString()
return format("%s%s",tostring(date("%Y")),tostring(1000 + date("%j")))
end
local specs = {
['name'] = childName,
['sv'] = true,
['cfg'] = true,
['cfgReset'] = prepareDB,
['ldb'] = addonTable['ldb'] ,
['defaults'] = {
['profile'] = {
[childName] = {
['disableBanker'] = true,
['displaySelTT'] = 2,
['displaySel'] = 2,
['connectedRealms'] = true
}
}
}
}
function addonTable:GetGold(val)
function child:GetGold(val)
local val = val or 2
local sums = { dbp['currentGold'], 0, 0, 0 }
if(addonTable['db']['sv']['profileKeys']) then
for k,v in pairs(addonTable['db']['sv']['profileKeys']) do
if(addon['db']['sv']['profileKeys']) then
for k,v in pairs(addon['db']['sv']['profileKeys']) do
local n,_,m = strsplit(' ',k,3)
if(n) then
local cr = addonTable.Helper_Tooltip3(m)
addonTable.cdbCheck(n, m)
local cr = child.Helper_Tooltip3(m)
child.cdbCheck(n, m)
local ch = db[m][n]
sums[3] = sums[3] + ch['currentGold'] -- global all
if(faction == ch['faction']) then
@ -87,29 +70,28 @@ function addonTable:GetGold(val)
end
return sums[val]
end
function addonTable:displayMoney(money, abr)
function child:displayMoney(money, abr)
if(abr) then
if(db['shortMoney'] and money>10000)then
money = addonTable:round(money / 10000,0) * 10000
money = child:round(money / 10000,0) * 10000
end
end
return addonTable:MoneyString(money, color, abr and (db['abrevK'] and L['abrK'] or nil) or nil, abr and (db['abrevM'] and L['abrM'] or nil) or nil, db['noIcon'], db['noIconColor'])
return child:MoneyString(money, color, abr and (db['abrevK'] and L['abrK'] or nil) or nil, abr and (db['abrevM'] and L['abrM'] or nil) or nil, db['noIcon'], db['noIconColor'])
end
local pew_events = {}
function pew_events:PLAYER_MONEY(event)
function events:PLAYER_MONEY(event)
local money = GetMoney()
if(money == 0) then return end
if(session['start'] == 0) then
session['start'] = money
end
dbp['currentGold'] = dbp['currentGold'] or 0
dbp['incoming'] = 0
dbp['incoming'] = nil
if(money ~= dbp['currentGold']) then
local diff = money - dbp['currentGold']
local out = GetCoinTextureString(abs(diff))
local color = "ffffff"
local stamp = time()
local day = addonTable:getDateString()
local day = child:getDateString()
local dba = dbr['activity'][faction]
dba[day] = dba[day] or {}
local dbd = dba[day]
@ -124,21 +106,36 @@ function pew_events:PLAYER_MONEY(event)
end
dbd[stamp] = diff
if(db['showLog']) then
print(addonTable:colorize(out, color))
print(child:colorize(out, color))
end
dbp['currentGold'] = money
end
local sum = addonTable:GetGold(db['displaySel'] or 2)
addonTable:OnText(childName, addonTable:displayMoney(sum, true))
local sum = child:GetGold(db['displaySel'] or 2)
child:OnText(childName, child:displayMoney(sum, true))
end
function addonTable:PrefChanged(pref, value, oldvalue)
pew_events:PLAYER_MONEY()
child['specs'] = {
['name'] = childName,
['sv'] = true,
['cfg'] = true,
['cfgReset'] = prepareDB,
['ldb'] = child['ldb'],
['defaults'] = {
['profile'] = {
[childName] = {
['disableBanker'] = true,
['displaySelTT'] = 2,
['displaySel'] = 2,
['connectedRealms'] = true
}
}
},
['events'] = events
}
function events:PLAYER_ENTERING_WORLD()
if(not realm) then
prepareDB()
else
child:UnregisterEvent('PLAYER_ENTERING_WORLD')
end
end
function events:PLAYER_ENTERING_WORLD(event)
prepareDB()
addonTable:UnregisterEvent('PLAYER_ENTERING_WORLD')
addonTable:RegisterEvent(pew_events)
pew_events:PLAYER_MONEY()
end
LibStub:GetLibrary("zzAddOn"):NewAddOn(specs, ...)
child:NewAddOn(...)

View File

@ -1,9 +1,9 @@
local addonname, addon = ...
local name = "zz_Money"
local L = LibStub("AceLocale-3.0"):NewLocale(name, "deDE", false)
local addonName, addon = ...
local childName = addon['childName']
local L = LibStub("AceLocale-3.0"):NewLocale(childName, "deDE", false)
if L then
L[name] = name
L[name..' Settings'] = name..' Einstellungen'
L[childName] = childName
L[childName..' Settings'] = childName..' Einstellungen'
L['Sitzung']='Sitzung'
L['Einnahmen']='Einnahmen'
L['Ausgaben']='Ausgaben'

View File

@ -1,9 +1,9 @@
local addonname, addon = ...
local name = "zz_Money"
local L = LibStub("AceLocale-3.0"):NewLocale(name, "enUS", true)
local childName = addon['childName']
local L = LibStub("AceLocale-3.0"):NewLocale(childName, "enUS", true)
if L then
L[name] = name
L[name..' Settings'] = name..' Settings'
L[childName] = childName
L[childName..' Settings'] = childName..' Settings'
L['Sitzung']='Session'
L['Einnahmen']='Income'
L['Ausgaben']='Expenses'

View File

@ -1,9 +1,9 @@
local addonname, addon = ...
local name = "zz_Money"
local L = LibStub("AceLocale-3.0"):NewLocale(name, "koKR", false)
local childName = addon['childName']
local L = LibStub("AceLocale-3.0"):NewLocale(childName, "koKR", false)
if L then
L[name] = name
L[name..' Settings'] = name..' 설정'
L[childName] = childName
L[childName..' Settings'] = childName..' 설정'
L['Sitzung']='세션'
L['Einnahmen']='수입'
L['Ausgaben']='지출'

View File

@ -1,9 +1,9 @@
local addonname, addon = ...
local name = "zz_Money"
local L = LibStub("AceLocale-3.0"):NewLocale(name, "ruRU", false)
local childName = addon['childName']
local L = LibStub("AceLocale-3.0"):NewLocale(childName, "ruRU", false)
if L then
L[name] = name
L[name..' Settings'] = name..' Настройки'
L[childName] = childName
L[childName..' Settings'] = childName..' Настройки'
L['Sitzung']='Сессия'
L['Einnahmen']='Доход'
L['Ausgaben']='Расход'

View File

@ -1,10 +1,11 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<script file="locale_deDE.lua"/>
<script file="locale_koKR.lua"/>
<script file="locale_enUS.lua"/>
<script file="locale_ruRU.lua"/>
<Script file="init.lua"/>
<Script file="locale_enUS.lua"/>
<Script file="locale_deDE.lua"/>
<Script file="locale_koKR.lua"/>
<Script file="locale_ruRU.lua"/>
<Script file="banker.lua"/>
<Script file="prefs.lua"/>
<Script file="broker.lua"/>
<Script file="banker.lua"/>
<Script file="core.lua"/>
</Ui>

113
prefs.lua
View File

@ -1,24 +1,14 @@
local addonName, addonTable = ...
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local db, dbr, faction
local childName = "zz_Money"
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
addonTable['bankHandler'] = {
SetDB = function(self, db) self.db = db end,
GetPref = function(self, pref)
return self['db'][pref[#pref]]
end,
SetPref = function (self, pref, value)
self['db'][pref[#pref]] = value
addonTable['events']['MAIL_SHOW'](addonTable)
end,
}
local function buildSelect()
local sel = {}
local n,m,_
if(addonTable['db']['sv']['profileKeys']) then
for k,v in pairs(addonTable['db']['sv']['profileKeys']) do
if(addon['db']['sv']['profileKeys']) then
for k,v in pairs(addon['db']['sv']['profileKeys']) do
n,_,m = strsplit(' ',k,3)
if(addonTable:IsTwink(n)) then
if(child:IsTwink(n)) then
if(dbr[n] and faction == dbr[n]['faction']) then
sel[n] = n
end
@ -27,16 +17,11 @@ local function buildSelect()
end
return sel
end
local buildDisplayValue = {
L['displayMoneyChar'], L['displayMoneyRealm'], L['displayMoneyGlobal'], L['displayMoneyGlobalFaction']
}
local function buildSelectAll()
local sel = {}
local n,m,_
if(addonTable['db']['sv']['profileKeys']) then
for k,v in pairs(addonTable['db']['sv']['profileKeys']) do
if(addon['db']['sv']['profileKeys']) then
for k,v in pairs(addon['db']['sv']['profileKeys']) do
n,_,m = strsplit(' ',k,3)
sel[format("%s-%s",n,m)] = format("%s-%s",n,m)
end
@ -48,43 +33,53 @@ local function deleteChar()
local charName, charRealm = strsplit('-', db['deleteChar'],2)
if(db[charRealm] and db[charRealm][charName]) then
db[charRealm][charName] = nil
addonTable['db']['sv']['profileKeys'][format("%s - %s", charName, charRealm)] = nil
addon['db']['sv']['profileKeys'][format("%s - %s", charName, charRealm)] = nil
end
end
db['deleteCharOk'] = nil
end
function addonTable:SetupPrefs(childName)
local L = addonTable['storage']['L']
dbr = addonTable['storage']['dbr']
db = addonTable['storage']['db']
local dbf = addonTable['storage']['dbf']
local dbb = dbf['banker']
faction = addonTable['storage']['faction']
local config = LibStub:GetLibrary("zzConfig")
local main = addonTable['options']['args'][childName]
config:AddConfigEntry(main, "displaySel", "select", L['Displayvalue'], L['DisplayvalueDesc'], 1, buildDisplayValue)
config:AddConfigEntry(main, "connectedRealms", "toggle", L['connectedRealms'], nil, 2)
config:AddConfigEntry(main, "showLog", "toggle", L['showLog'], nil, 3)
config:AddConfigEntry(main, "shortMoney", "toggle", L['shortMoney'], nil, 4)
config:AddConfigEntry(main, "disableBanker", "toggle", L['nobanker'], nil, 5)
config:AddConfigEntry(main, "abrevK", "toggle", L['abrevK'], nil, 6)
config:AddConfigEntry(main, "abrevM", "toggle", L['abrevM'], nil, 7)
local noicon = config:AddConfigEntry(main, "noIcon", "toggle", L['noIcon'], L['noIconDesk'], 6)
local noiconColor = config:AddConfigEntry(main, "noIconColor", "toggle", L['Color text'], L['Color text desc'], 7)
noiconColor['disabled'] = function(self) if(not db['noIcon']) then return true end end
local menu = config:AddConfigMenu(addonTable['options'], L['Bankier'], 2, config:GetDefaultHandler(addonTable['events']['MAIL_SHOW'], dbb), { disabled = function() return db['disableBanker']
end})
config:AddConfigEntry(menu, "minLimit", "range", L['Minimum Limit'], L['Desc MinL'], 1, 10, 150000, 5, false)
config:AddConfigEntry(menu, "maxLimit", "range", L['Maximum Limit'], L['Desc MaxL'], 2, 10, 150000, 5, false)
config:AddConfigEntry(menu, "banker","select",L['Bankier'],nil,3,buildSelect)
local ttmenu = config:AddConfigEntry(main, "ttmenu", "group", L['ttmenu_title'], L['ttmenu_desc'], 9, config:GetDefaultHandler(addonTable['events']['PLAYER_MONEY'], db), true)
config:AddConfigEntry(ttmenu, "displaySelTT", "select", L['Gesamt'], L['DisplayvalueDesc'], 1, buildDisplayValue)
config:AddConfigEntry(ttmenu, "sortDir", "toggle", L['sortDir'], nil, 2)
config:AddConfigEntry(ttmenu, "accountMoney", "toggle", L['accountMoney'], L['accountMoneyDesc'], 3)
local short = config:AddConfigEntry(ttmenu, "shortMoneyTip", "toggle", L['shortMoneyTip'], nil, 4)
short['disabled'] = function(self) if(not db['abrevK'] and not db['abrevM']) then return true end end
local delmenu = config:AddConfigEntry(main, "delmenu", "group", L['DeleteChar'], L['DeleteCharDesc'], 10, config:GetDefaultHandler(nil, db), true)
config:AddConfigEntry(delmenu, "deleteChar", "select", L['DeleteChar'], L['DeleteCharDesc'], 1, buildSelectAll)
config:AddConfigEntry(delmenu, "deleteCharOk", "toggle", L['DeleteCharOk'], nil , 2)
config:AddConfigEntry(delmenu, "deleteCharExec", "execute", L['DeleteChar'], L['DeleteCharDesc'], 3, deleteChar)
end
local init = {
Setup = function(self)
local L = child['storage']['L']
dbr = child['storage']['dbr']
db = child['storage']['db']
local dbf = child['storage']['dbf']
local dbb = dbf['banker']
faction = child['storage']['faction']
local config = LibStub:GetLibrary("zzConfig")
local options = child['options']
local main = options['args'][childName]
local buildDisplayValue = {
L['displayMoneyChar'], L['displayMoneyRealm'], L['displayMoneyGlobal'], L['displayMoneyGlobalFaction']
}
config:AddConfigEntry(main, "displaySel", "select", L['Displayvalue'], L['DisplayvalueDesc'], 1, buildDisplayValue)
config:AddConfigEntry(main, "connectedRealms", "toggle", L['connectedRealms'], nil, 2)
config:AddConfigEntry(main, "showLog", "toggle", L['showLog'], nil, 3)
config:AddConfigEntry(main, "shortMoney", "toggle", L['shortMoney'], nil, 4)
config:AddConfigEntry(main, "disableBanker", "toggle", L['nobanker'], nil, 5)
config:AddConfigEntry(main, "abrevK", "toggle", L['abrevK'], nil, 6)
config:AddConfigEntry(main, "abrevM", "toggle", L['abrevM'], nil, 7)
local noicon = config:AddConfigEntry(main, "noIcon", "toggle", L['noIcon'], L['noIconDesk'], 6)
local noiconColor = config:AddConfigEntry(main, "noIconColor", "toggle", L['Color text'], L['Color text desc'], 7)
noiconColor['disabled'] = function(self) if(not db['noIcon']) then return true end end
local menu = config:AddConfigMenu(options, L['Bankier'], 2, config:GetDefaultHandler(child['events']['MAIL_SHOW'], dbb), { disabled = function() return db['disableBanker']
end})
config:AddConfigEntry(menu, "minLimit", "range", L['Minimum Limit'], L['Desc MinL'], 1, 10, 150000, 5, false)
config:AddConfigEntry(menu, "maxLimit", "range", L['Maximum Limit'], L['Desc MaxL'], 2, 10, 150000, 5, false)
config:AddConfigEntry(menu, "banker","select",L['Bankier'],nil,3,buildSelect)
local ttmenu = config:AddConfigEntry(main, "ttmenu", "group", L['ttmenu_title'], L['ttmenu_desc'], 9, config:GetDefaultHandler(child['events']['PLAYER_MONEY'], db), true)
config:AddConfigEntry(ttmenu, "displaySelTT", "select", L['Gesamt'], L['DisplayvalueDesc'], 1, buildDisplayValue)
config:AddConfigEntry(ttmenu, "sortDir", "toggle", L['sortDir'], nil, 2)
config:AddConfigEntry(ttmenu, "accountMoney", "toggle", L['accountMoney'], L['accountMoneyDesc'], 3)
local short = config:AddConfigEntry(ttmenu, "shortMoneyTip", "toggle", L['shortMoneyTip'], nil, 4)
short['disabled'] = function(self) if(not db['abrevK'] and not db['abrevM']) then return true end end
local delmenu = config:AddConfigEntry(main, "delmenu", "group", L['DeleteChar'], L['DeleteCharDesc'], 10, config:GetDefaultHandler(nil, db), true)
config:AddConfigEntry(delmenu, "deleteChar", "select", L['DeleteChar'], L['DeleteCharDesc'], 1, buildSelectAll)
config:AddConfigEntry(delmenu, "deleteCharOk", "toggle", L['DeleteCharOk'], nil , 2)
config:AddConfigEntry(delmenu, "deleteCharExec", "execute", L['DeleteChar'], L['DeleteCharDesc'], 3, deleteChar)
child.PrefChanged = child['events']['PLAYER_MONEY']
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup')

View File

@ -1,12 +1,6 @@
## Interface: 90005
## Title: Money
## Notes: Broker Money display
## Notes-deDE: Broker zur Goldanzeige
## Author: Rilgamon
## X-WoWI-ID: 15621
## X-Curse-Project-ID: 39054
## X-Repository: https://git.grml.de/rilgamon/zz_Money.git
## OptionalDeps: zzLib, Ace3, BrokerPack
## SavedVariables: zz_MoneyDB
Libs\embeds.xml
## Interface: 90005
## Title: Money
## OptionalDeps: zzLib, Ace3, BrokerPack
## SavedVariables: zz_MoneyDB
Libs\embeds.xml
pack.xml