From 9fb97eb5114cfaa9f8e27bb58201348ff372b85b Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 13 Jan 2021 15:24:26 +0100 Subject: [PATCH] Initial push --- .gitmodules | 3 + Common | 1 + core.lua | 367 +++++++++++++++++++++++++++++++++++++++++++++++++ icon2.tga | Bin 0 -> 2848 bytes license.txt | 6 + pack.xml | 4 + stock.lua | 80 +++++++++++ zz_AltMail.toc | 9 ++ 8 files changed, 470 insertions(+) create mode 100644 .gitmodules create mode 160000 Common create mode 100644 core.lua create mode 100644 icon2.tga create mode 100644 license.txt create mode 100644 pack.xml create mode 100644 stock.lua create mode 100644 zz_AltMail.toc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..34950ac --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Common"] + path = Common + url = https://git.grml.de/rilgamon/Common.git diff --git a/Common b/Common new file mode 160000 index 0000000..762c59c --- /dev/null +++ b/Common @@ -0,0 +1 @@ +Subproject commit 762c59c6c6abc6ecaa71f3e36bb2c6dd16b8e0ed diff --git a/core.lua b/core.lua new file mode 100644 index 0000000..4e86ed5 --- /dev/null +++ b/core.lua @@ -0,0 +1,367 @@ +local name, addon = ... +local parentName = addon['parentName'] or "BrokerPack" +local childName = "zz_AltMail" +local defaults = { +} + +local options = { +} + +local db +local realm = GetRealmName() +local function GetUName() + local name = UnitName("player") + return name.."-"..realm +end +addon.GetUName = GetUName +local itemTypes = {} +local itemSubtypes = {} +local function populate() +--[[ for k, v in pairs(_G) do + if strsub(k, 1, 12) == 'NUM_LE_ITEM_' then + print(k, v) + end + end]] + local types = {} + for i = 1, NUM_LE_ITEM_CLASSS do + local n = 1 + local subclassName = '' + local className = GetItemClassInfo(i - 1) + if(className) then + itemTypes[className] = i + itemSubtypes[className] = itemSubtypes[className] or {} + types[i] = { + ['name'] = className, + ['subtypes'] = {} + } + while(subclassName) do + subclassName = GetItemSubClassInfo(i - 1, n - 1) + if(subclassName and strlen(subclassName) > 0) then + itemSubtypes[className][subclassName] = n + types[i]['subtypes'][n] = subclassName + n = n + 1 + end + if(subclassName and strlen(subclassName) < 1) then + subclassName = nil + end + end + end + end + return types +end +local function IsSoulbound(bag, slot) + local item = ItemLocation:CreateFromBagAndSlot(bag, slot) + if(item) then + return C_Item.IsBound(item) + end +end +local function GetDestination(bag,slot) + local item = ItemLocation:CreateFromBagAndSlot(bag, slot) + if(C_Item.IsBound(item)) then return end + local quality = C_Item.GetItemQuality(item) + local itemLink = C_Item.GetItemLink(item) +-- local texture, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemID = GetContainerItemInfo(bag, slot) + if(itemLink) then + local typ = string.match(itemLink, "^(.-):") + if(typ~="battlepet" and quality<5 and quality>0) then + local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID, isCraftingReagent = GetItemInfo(itemLink) + if(itemName) then +-- itemType = LibBabbleDBR[itemType] +-- itemSubType = LibBabbleDBR[itemSubType] + -- print(itemType.."-"..itemSubType.."-"..itemLink) + if(db['itemdb'][realm] and db['itemdb'][realm][itemClassID] and db['itemdb'][realm][itemClassID][itemSubClassID]) then + local tmp = db['itemdb'][realm][itemClassID][itemSubClassID] + sort(tmp, function(a,b) + return (a['order'] or 0) < (b['order'] or 0) + end) + for dest,destInfo in pairs(tmp) do + if(type(destInfo) == 'table') then + local doSkip = false +-- print(dest,destInfo['skip']) + for _,skip in ipairs(destInfo['skip']) do + if(skip == GetUName()) then doSkip=true end + end + if(not doSkip) then + return dest + end + end + end + end + end + end + end +end +local function GetNumMailboxItems() + local count = 0 + for i = 1, ATTACHMENTS_MAX_SEND do + local name, texture, count, quality = GetInboxItem(i) + if(name) then + count = count + 1 + end + end + return count +end +local function sout(target) + SendMail(target, "Post",nil) + SELECTED_CHAT_FRAME:AddMessage("Sending "..target) +end +local sf_new = function() + if(not SendMailFrame:IsVisible()) then return end + local a,b = 0,0 + local tab = {} + while(a<=NUM_BAG_SLOTS) do + b = 1 + while(b<=GetContainerNumSlots(a)) do + local _, _, _, _, _, _, itemLink = GetContainerItemInfo(a, b) + if(itemLink) then + local itemName, itemLink, _, _, _, itemType, itemSubType, _, _, _, _, classID, subclassID, _, _, _, _ = GetItemInfo(itemLink) + if(classID) then + local it = db['itemtypes'][classID + 1]['name'] + if(subclassID and it) then + itemType = it + local ist = db['itemtypes'][classID + 1]['subtypes'][subclassID + 1] + if(ist) then + itemSubType = ist + tab[classID] = tab[classID] or {} + tab[classID][subclassID] = tab[classID][subclassID] or {} + tab[classID][subclassID][#tab[classID][subclassID] + 1] = { + ['bag'] = a, + ['slot'] = b, + } + else + print("no itemsubtype for "..itemName) + end + else + print("no itemtype for "..itemName) + end + end + end + b = b + 1 + end + a = a + 1 + end + local mailout = {} + db['itemdb'][realm] = db['itemdb'][realm] or {} + local realmdb = db['itemdb'][realm] + for t, v in pairs(tab) do + if(t) then + realmdb[t] = realmdb[t] or { + ['Default'] = { + [GetUName()] = { + ['order'] = 1, + ['skip'] = {}, + } + } + } + local typedb = db['itemdb'][realm][t] + for s,d in pairs(v) do + if(s) then + typedb[s] = typedb[s] or CopyTable(typedb['Default']) + local subtypedb = typedb[s] + for g,h in pairs(d) do + local target = GetDestination(tonumber(h['bag']),tonumber(h['slot'])) + if(target and subtypedb[target] and subtypedb[target]['active']) then + mailout[target] = mailout[target] or {} + mailout[target][#mailout[target] + 1] = { + ['bag'] = h['bag'], + ['slot'] = h['slot'] + } + end + end + end + end + end + end + mailout[GetUName()] = nil + for k,v in pairs(mailout) do + local c = 0 + for a,b in pairs(v) do + c = c + 1 + UseContainerItem(tonumber(b['bag']),tonumber(b['slot'])) + if(c >= 12) then + break + end + end + if(c > 0) then + sout(k) + break + end + end +end +SendMailFrame:HookScript("OnShow", function() + C_Timer.After(0.25, sf_new) +end) + +local function OnEvent(self, event, arg1, ...) + if(event == "MAIL_SEND_SUCCESS") then + C_Timer.After(1,sf_new) + end +end +local function OnText(message) + addon:OnText(childName, message) +end + +local function getPref(pref) + return db[pref[#pref]] +end + +local function setPref(pref,value) + db[pref[#pref]] = value +end +local function getPrefI(pref) +--[[ +print("3",pref[#pref]) -- pref name +print("2",pref[#pref-1]) -- dest name +print("1",pref[#pref-2]) -- subtype name +print("0",pref[#pref-3]) -- type name +]] + if(pref[#pref-2] ~= 'Default') then +-- print("D", db['itemdb'][realm][itemTypes[pref[#pref-3]] - 1][itemSubtypes[pref[#pref-3]][pref[#pref-2]] - 1]) + return db['itemdb'][realm][itemTypes[pref[#pref-3]] - 1][itemSubtypes[pref[#pref-3]][pref[#pref-2]] - 1][pref[#pref-1]][pref[#pref]] + else + return db['itemdb'][realm][itemTypes[pref[#pref-3]] - 1]['Default'][pref[#pref-1]][pref[#pref]] + end +end +local function setPrefI(pref,value) + if(pref[#pref-2] ~= 'Default') then + db['itemdb'][realm][itemTypes[pref[#pref-3]] - 1][itemSubtypes[pref[#pref-3]][pref[#pref-2]] - 1][pref[#pref-1]][pref[#pref]] = value + else + db['itemdb'][realm][itemTypes[pref[#pref-3]] - 1]['Default'][pref[#pref-1]][pref[#pref]] = value + end +end +local function getPrefDest(pref) +--[[print("3",pref[#pref]) -- pref name +print("2",pref[#pref-1]) -- subtype name +print("1",pref[#pref-2]) -- type name]] + local t = itemTypes[pref[#pref-2]] - 1 + local s = pref[#pref-1]=='Default' and 'Default' or itemSubtypes[pref[#pref-2]][pref[#pref-1]] - 1 + if(t and s) then + for k, v in pairs(db['itemdb'][realm][t][s]) do + if(type(v) == 'table') then + return k + end + end + end +end +local function setPrefDest(pref, value) + local old = getPrefDest(pref) +--print(old, ">",value) +--[[print("3",pref[#pref]) -- pref name +print("2",pref[#pref-1]) -- subtype name +print("1",pref[#pref-2]) -- type name]] + local t = itemTypes[pref[#pref-2]] - 1 + local s = pref[#pref-1]=='Default' and 'Default' or itemSubtypes[pref[#pref-2]][pref[#pref-1]] - 1 + db['itemdb'][realm][t][s][value] = db['itemdb'][realm][t][s][old] + db['itemdb'][realm][t][s][old] = nil + addon:updatePrefs() +end +local function buildSelectAll() + local sel = {} + local n,m,_ + 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 + end + return sel +end +function addon:updatePrefs() + db['itemdb'] = db['itemdb'] or {} + db['itemdb'][realm] = db['itemdb'][realm] or {} + local itemdb = db['itemdb'][realm] + db['itemtypes'] = populate() + local a,b = 0,0 + local curName = GetUName() + while(a<=NUM_BAG_SLOTS) do + b = 1 + while(b<=GetContainerNumSlots(a)) do + local _, _, _, _, _, _, itemLink = GetContainerItemInfo(a, b) + if(itemLink) then + local _, _, _, _, _, itemType, itemSubType, _, _, _, _, classID, subclassID, _, _, _, _ = GetItemInfo(itemLink) + if(classID and subclassID) then + + itemdb[classID] = itemdb[classID] or { + ['name'] = itemType, + ['Default'] = { + ['name'] = 'Default', + [curName] = { + ['order'] = 1, + ['skip'] = {}, + } + } + } + local classdb = itemdb[classID] + classdb['name'] = itemType + classdb[subclassID] = classdb[subclassID] or CopyTable(classdb['Default']) + classdb[subclassID]['name'] = itemSubType + end + end + b = b + 1 + end + a = a + 1 + end + local p = addon['options']['args']['Types']['args'] + for classID, v in pairs(db['itemdb'][realm]) do + if(v['name']) then + p[v['name']] = { + ['type'] = 'group', + ['childGroups'] = 'tree', + ['name'] = v['name'], + ['args'] = {}, + } + for subclassID, b in pairs(v) do + if(type(b) == 'table' and b['name']) then + p[v['name']]['args'][b['name']]={ + ['type'] = 'group', + ['name'] = b['name'], + ['get'] = getPrefI, + ['set'] = setPrefI, + ['args'] = {}, + } + local c = p[v['name']]['args'][b['name']]['args'] + c['dest'] = { + ['name'] = "Destination", + ['type'] = "select", + ['values'] = buildSelectAll, + ['get'] = getPrefDest, + ['set'] = setPrefDest + } + for d,e in pairs(b) do + if(d ~= 'name') then + c[d] = { + ['name'] = d, + ['type'] = "group", + ['args'] = {}, + } + local f = c[d]['args'] + f['active'] = { + ['name'] = "active", + ['type'] = "toggle", + } + end + end + end + end + end + end +end +local function init() + realm = GetRealmName() + options = addon:InitConfig(childName, true, { + ['type'] = "launcher", + }, getPref, setPref) + db = addon['db']['profile'][childName] + db['itemdb'] = db['itemdb'] or {} + db['itemdb'][realm] = db['itemdb'][realm] or {} + addon:AddConfigMenu({ + ['name'] = "Types", + ['order'] = 2, + ['childGroups'] = 'tree', + ['menuGet'] = getPref, + ['menuSet'] = setPref, + }, addon['options']) + addon:updatePrefs() +end +addon:startup(name, childName, init, true, defaults) +addon:RegisterFunc({'MAIL_SEND_SUCCESS'},"OnEvent", OnEvent) \ No newline at end of file diff --git a/icon2.tga b/icon2.tga new file mode 100644 index 0000000000000000000000000000000000000000..f675e12e0d0804417cc12c597a266809fb754edf GIT binary patch literal 2848 zcmY*b2Ut{R7X1e_f>=PnRTRQv%Nq2Mn;E|UKj;4Eo_pV8Y%=@brOD_|?q2}d zB*tV^n4HQAHe-PiQ(0ufloy(?X`0)ZjQmnsKaF4YPj0C^)6zH5{qIQ!GZ`>9IHeEw!t4DH6ejiZy33x-F2|Yk$HxSwd z_;vy|RU?@7lS>5?$Z7MtoVcx18JjRk^O#rC+g6~IwxqYy)(^CmeuuOGeocUTBj7^+ zH_vFp1iizNl&}K7dkjKn*IDoEb~F<6`wn8K_>-1LwE>R_%Aa7|3C2+Z+@#Ny?ytdS zEIP{XcI2{{&g50+Y`T*mZjb^MlyD9~B()47tgaW2YJ1@;?t`beA1)2UJj}0k!#I)M zhH1vO`HTtFc$85n!8(hZPfDd|8H0M;G62h{WULkb4n6M>==nT`zHb-~#EW>SYc+$o zSk#HXdnSX;TzZa2ap1C2VsgqeH@W;-%VkwdS(TBD@7hNY)6fT>qGmYd)Ztcc1MCW0 z;8ZPz10C>c^#H7LKj2V8B^0)v&m^s8@MvR@%XV7`MIX`H4^$Ie>BmvclG{cQA^C*h z`hIv;cEhWFkk^cd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txt new file mode 100644 index 0000000..b9e992f --- /dev/null +++ b/license.txt @@ -0,0 +1,6 @@ +The following license excludes the libraries (Libs) included. See the libraries directory or website. + +This AddOn is public domain. That means you can change it, rename it or paint it yellow. +My name (Rilgamon) is valid only for WoWInterface.com and curse.com. +If you use/offer this addon on another website please remove my name. +If you want to give me credit you can replace it with a link to my profile on WoWInterface.com. \ No newline at end of file diff --git a/pack.xml b/pack.xml new file mode 100644 index 0000000..bd1c4d7 --- /dev/null +++ b/pack.xml @@ -0,0 +1,4 @@ + +