Thread Tools Display Modes
05-10-09, 04:05 PM   #1
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
cargBags - Help & Discussion

Okay, here is the official thread to discuss all parts of modifying cargBags, the modular bag framework.

This thread is mostly for help requests and discussion around layouts, plugins or handlers - for feature requests or bug reports on the core, please write into the comment section of the addon.
Or you just show off your own custom layout

If you have questions, rather write here instead of sending PM's, so people can learn from it

Additional resources:
- cargBags
- Find cargBags layouts/plugins on WoWInterface
- Git repository
- API-specifications

As more plugins and handlers come, I maybe provide some differentiation here and list them.

Good luck on creating your own custom bags!
__________________
« Website | GitHub »

Oh hai!

Last edited by xConStruct : 11-04-09 at 01:48 PM. Reason: Links update.
  Reply With Quote
05-13-09, 10:23 AM   #2
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
Ok very nice, thanks for implementing cargBags_Anywhere.

Question : Can i run a function on the bag data before the bags are populated?

I want to change the types on some of the items before they get filtered by any potential filters that may exist.

ie "Wind-Up Train Wrecker" is listed as consumable when i want it treated as Miscellaneous, and "Fate Rune of Unsurpassed Vigor" is listed as quest when i want it treated as a Consumable.

Code:
local itemConversions = {
	["Wind-Up Train Wrecker"] = {
		type = "Miscellaneous ",
		subtype = "Other"
	},
	["Toy Train Set"] = {
		type = "Miscellaneous ", 
		subtype = "Other"
	},
	["Worn Troll Dice"] = {
		type = "Miscellaneous ",
		subtype = "Other"
	},
	["Fate Rune of Unsurpassed Vigor"] = {
		type = "Consumable ",
		subtype = "Consumable"
	},
	["Fate Rune of Primal Energy"] = {
		type = "Consumable ",
		subtype = "Consumable"
	},
	["Fate Rune of Baneful Intent"] = {
		type = "Consumable ",
		subtype = "Consumable"
	},
}

local function PostBagDBInit(item,name,link)
	ConvertedItem = itemConversions[item.name]
	if(ConvertedItem)then
		item.type = ConvertedItem.type
	end

end
  Reply With Quote
05-13-09, 10:54 AM   #3
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Currently there are no functions for the layout that manipulate item data before it is passed to the filters. But there should be no problem in extending a filter like:
Code:
local onlyConsumables = function(item)
    return item.type == "Consumables" or itemConversions[item.name].type == "Consumables"
end
But there's a good chance that I'll include a callback for that in one of the next updates, but I don't want to commit myself at the moment
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
05-16-09, 04:39 AM   #4
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
How to add item set filters for ItemRack, Outfitter and Blizzards Equipment Manager

Since I spent quite some time to analyse each of those addons code to extract all the information I need and to create all the necessary callbacks, I thought I'd share my resulting code. You are of course absolutely free to use it in your own cargBags layout, however if you decide to publish it, I'd appreciate to be credited.

All three filters are also included in my own layout, you can get it here:
cargBags_Nivaya

(Note: ClosetGnome doesn't need support anymore, since it is now only an LDB plugin for switching sets from Blizzards Equipment Manager.)

I'll first explain the code for extracting the item set info from each of those addons. The basic idea is to add some specific callbacks or hooks to each addon, which notify us when sets are added, removed or changed. Those callbacks then create a table containing all set items as a key, so the final filter can do its work efficiently.

Blizzards Equipment Manager
Code:
-- This table will hold information about all items which are part of a set:
local item2setEM = {}

-- This function will extract the item set data, so it can be 
-- efficiently checked in the filter later:
local function cacheSetsEM()
    for k in pairs(item2setEM) do item2setEM[k] = nil end
    for k = 1, GetNumEquipmentSets() do
        local sName = GetEquipmentSetInfo(k)
        local set = GetEquipmentSetItemIDs(sName)
        for _,item in next, set do
            -- "item" is simply the item ID here:
            if item then item2setEM[item] = true end
        end
    end
    cargBags:UpdateBags()
end

-- This creates an invisible frame to hold the required event handlers:
local EQ_Event = CreateFrame("Frame")
EQ_Event:RegisterEvent("PLAYER_LOGIN")
EQ_Event:RegisterEvent("EQUIPMENT_SETS_CHANGED")
EQ_Event:SetScript("OnEvent", cacheSetsEM)
Outfitter
Code:
local OF = IsAddOnLoaded('Outfitter')
local item2setOF = {}
local pLevel = UnitLevel("player")
-- Outfitter doesn't use item strings or links to identify items by default, 
-- so this is the function to create an item string:
local function createItemString(i) return "item:"..i.Code..":"..i.EnchantCode..":"..i.JewelCode1..":"..i.JewelCode2..":"..i.JewelCode3..":"..i.JewelCode4..":"..i.SubCode..":"..i.UniqueID..":"..pLevel end

local function cacheSetsOF()
    for k in pairs(item2setOF) do item2setOF[k] = nil end
    -- Outfitter grants access to sets via categories,
    -- so there are two loops here:
    for _,id in ipairs(Outfitter_GetCategoryOrder()) do
        local OFsets = Outfitter_GetOutfitsByCategoryID(id)
        for _,vSet in pairs(OFsets) do
            for _,item in pairs(vSet.Items) do
                -- "item" is a table here, and since I don't want to save 
                -- the whole table, I'll create an itemstring out of it:
                if item then item2setOF[createItemString(item)] = true end
            end
        end
    end
    cargBags:UpdateBags()
end

if OF then
    -- Outfitter supports the needed callbacks by itself:
    Outfitter_RegisterOutfitEvent("ADD_OUTFIT", cacheSetsOF)
    Outfitter_RegisterOutfitEvent("DELETE_OUTFIT", cacheSetsOF)
    Outfitter_RegisterOutfitEvent("EDIT_OUTFIT", cacheSetsOF)
    if Outfitter:IsInitialized() then
        cacheSetsOF()
    else
        Outfitter_RegisterOutfitEvent('OUTFITTER_INIT', cacheSetsOF)
    end
end
ItemRack
Code:
local IR = IsAddOnLoaded('ItemRack')
local item2setIR = {}
local function cacheSetsIR()
    for k in pairs(item2setIR) do item2setIR[k] = nil end
    local IRsets = ItemRackUser.Sets
    for i in next, IRsets do
        -- Some internal sets and queues start with one of these 
        -- characters, so let's exclude them:
	if not string.find(i, "^~") then 
            for _,item in pairs(IRsets[i].equip) do
                -- "item" is a custom itemstring here:
                if item then item2setIR[item] = true end
	    end
	end
    end
end

if IR then
    cacheSetsIR()
    -- ItemRack doesn't support any callbacks by itself, so we're going to
    -- hook into the functions we need manually:
    local function ItemRackOpt_CreateHooks()
        -- Those are the actual hooks for adding, updating and deleting sets:
        local IRsaveSet = ItemRackOpt.SaveSet
        function ItemRackOpt.SaveSet(...) IRsaveSet(...); cacheSetsIR(); cargBags:UpdateBags() end
        local IRdeleteSet = ItemRackOpt.DeleteSet
        function ItemRackOpt.DeleteSet(...) IRdeleteSet(...); cacheSetsIR(); cargBags:UpdateBags() end
    end
    -- Amusingly, ItemRack puts its set updating functions into a 
    -- load-on-demand module, so we need to hook into the LoD-function first:
    local IRtoggleOpts = ItemRack.ToggleOptions
    function ItemRack.ToggleOptions(...) IRtoggleOpts(...) ItemRackOpt_CreateHooks() end
end

The filter

Finally the filter itself, use this function as an argument to SetFilter() for one of your cargBags bag objects:
Code:
local fItemSets = function(item)
    if not item.link then return false end
    -- Check ItemRack sets:
    if item2setIR[string.match(item.link,"item:(.+):%-?%d+")] then return true end
    -- Check Outfitter sets:
    local _,_,itemStr = string.find(item.link, "^|c%x+|H(.+)|h%[.*%]")
    if item2setOF[itemStr] then return true end
    -- Check Equipment Manager sets:
    local _,itemID = strsplit(":", itemStr)
    if item2setEM[tonumber(itemID)] then return true end    
    return false
end
Blizzards Equipment Manager simply uses the item ID to identify set items, ItemRack uses some custom item string and Outfitter uses a table with extracted values from the item link. I manually created an itemstring from those values in the corresponding cacheSets-function, so I don't have to match the whole table.

**edit: Updated for Blizzards Equipment Manager and removed ClosetGnome stuff, since it is not needed anymore.

Last edited by Luzzifus : 05-20-09 at 11:01 AM.
  Reply With Quote
05-16-09, 07:25 AM   #5
Soeters
A Warpwood Thunder Caller
 
Soeters's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 97
Thanks for this very very good work Luzzifus.

Great job
__________________
  Reply With Quote
05-16-09, 07:44 AM   #6
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Originally Posted by jadakren View Post
Question : Can i run a function on the bag data before the bags are populated?
The new update introduces the callback function cargBags:PreCheckFilters(item, updateType). This should make it a bit more easy
Please note that it's not a bag object callback, but one for the complete cargBags

@Luzzifus: I agree with Soeters - Yep, it's a nice tutorial!
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
05-16-09, 08:20 AM   #7
illum1n4ti
A Defias Bandit
 
illum1n4ti's Avatar
Join Date: Jun 2006
Posts: 3
Hello mates,

I was thinking to share this with you .. As you can see i have changed the texture of the border .. see my screen shot.



Code:
-- Function is called after a button was added to an object
-- We color the borders of the button to see if it is an ammo bag or else
-- Please note that the buttons are in most cases recycled and not new created
local PostAddButton = function(self, button, bag)
	if(not button.NormalTexture) then return end
	button.NormalTexture:SetWidth(43)
        button.NormalTexture:SetHeight(43)
	button.NormalTexture:SetTexture([[Interface\FXP\Classic.tga]])

	local bagType = cargBags.Bags[button.bagID].bagType
	if(button.bagID == KEYRING_CONTAINER) then
		button.NormalTexture:SetVertexColor(1, 0.7, 0)		-- Key ring
	elseif(bagType and bagType > 0 and bagType < 8) then
		button.NormalTexture:SetVertexColor(1, 1, 0)		-- Ammo bag
	elseif(bagType and bagType > 4) then
		button.NormalTexture:SetVertexColor(0, 1, 0)		-- Profession bags
	else
		button.NormalTexture:SetVertexColor(0.5, 0.5, 0.5)	-- Normal bags
	end
end
But as u can see my Ammo and Herb bags ain't coloring am i doing something wrong? maybe you guys can help me out.
  Reply With Quote
05-17-09, 08:44 AM   #8
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Okay, this seems to be a problem of the core. It will be fixed in the next cargBags-update.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
05-17-09, 08:49 AM   #9
illum1n4ti
A Defias Bandit
 
illum1n4ti's Avatar
Join Date: Jun 2006
Posts: 3
Originally Posted by Cargor View Post
Okay, this seems to be a problem of the core. It will be fixed in the next cargBags-update.
i will be waiting in the mean time i am gonna look at core maybe i can find it

Cheers mate
  Reply With Quote
05-18-09, 02:16 PM   #10
moniker
A Defias Bandit
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 3
Hello,

I had started working on my own layout, but Luzzifus has implemented at least the containers that I want with cbNivaya (and Luzz is adding nice features faster than I have time to .

However, I have two additional custom functions that I always have to go in and add that color 'unusable' items with a red overlay (thanks for the help here Cargor) and another text overlay with '*BoE*' for BoE equipment (for mailing to my enchanter).

I looked into Plugins and Handlers but it seems these have a different purpose. Beyond hooking the two functions in cbNivaya directly (UpdateButton and UpdateButtonLock) using Lua is there a more 'recommended' approach?

Thanks!
  Reply With Quote
05-18-09, 02:52 PM   #11
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
I think not. It's up to the layout and cargBags doesn't provide more than one different callback per object. But hooking should be perfectly fine
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
05-18-09, 02:53 PM   #12
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
If you PM me the code how you do that I might include it in my layout.
  Reply With Quote
01-14-10, 02:43 PM   #13
theiven
A Defias Bandit
Join Date: Feb 2007
Posts: 3
woooooo back up

I just downloaded cargbags and it is the closest thing to what I have been looking for that I have found. At least after I downloaded cargBags_Nivaya to go with it.
but it isnt perfect of course, and I would like to make a new bag or 3.
so I tried your more info links to find out how to make a bag.
The first link API-specifications seems to be broken ( so I figure with my luck that's the one I need).
then there was this link......... just a tad over the head of someone that just downloaded this thing.
could someone point me to a page that will get me started.

the nivaya layout is almost perfect all i want to change is.
I have 2 gem bags and a mining bag in my bank.
yet my gems are in my bank bag and my mining mats are in trade goods with a bunch of meet.
I would just like to add a miner bag and a JCing bag to the layout.
I'm cool with learning what I need to.
but I need a place to start and this thread seems to jump right in the middle.
If I missed something obvious feal free to flame me, but try to add the info someplace in the flame please.
  Reply With Quote
01-14-10, 04:30 PM   #14
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
The key to adding bags is in the filter section and in the right order.

cargBags_Nivaya keeps the info in two places. In filters.lua you have the basic filters which then get applied in cargBags_Nivaya.lua and some descriptions in localization.lua.

Assuming you want to do it right, I'd start out in localization.lua. Here, I'd start with adding 'cBinvL.Mining = "Mining"' after the bullet entry, and then add '["cBinv_Mining"],' after the new items entry. Do something similar for JC.

Next we head over to filters.lua. I'd add these just after the Trade Goods filter in here, but that's just to keep them ordered in my mind. I don't think they have to go in any order here.

Our first filter is going to be for mining. The first few lines for a filter in Nivaya look to be pretty common (ignoring the config option). A basic filter looks like this:
Code:
cB_Filters.fMining = function(item)
  local tC = cBniv_CatInfo[item.name]
  if tC then return (tC == "cBinv_Mining") and true or false end
  return (item.type and item.type == L.Trades) and (item.subType == "Metal & Stone")
end
The subType info comes from http://www.wowwiki.com/ItemType.

Then create something similar for JC.

Now we get to the fun part. Something important about cargBags is that when it processes the filters it does so in a particular order. The first filter it comes across that matches the item is where it is placed. This means that if we put our above filters after the trade goods filter, they'll only ever be placed in trade goods.

The order of the filters seems to be around lines 64 - 153 of cargBags_Nivaya.lua. We see the trade goods bag appears at 144 - 147, so let's put our new bags just before that and after Consumable. Since filters appear to be applied in order of the bags, this should work for us.

The format for the bags is very simple. The mining bag should look something like this:
Code:
local t = cargBags:Spawn("cBinv_Mining") -- from localization.lua
t:SetFilter(cB_Filters.fMining, true) -- from the filter we created
cB_Bags.mining = t -- creating a new bag for the stuff
Again, do the same for JC.

Finally, we place the bag by anchoring it to something else. While you can place it where you want, I'll put it under the quest items.

The function to use here is called out at line 159 (note, all line numbers are before changes) and is really simple: CreateAnchorInfo(bag we anchor to, bag we want to anchor, source bag anchor point). So, if we want to attach our bag to the bottom of something, it appears to be "CreateAnchorInfo(cB_Bags.bagStuff, cB_Bags.mining, "Top")". If we put that in after the last CreateAnchorInfo line, you should be good.

Now, I haven't tested this, but it should work with only minimal debugging. Hopefully there was enough explanation there to help.
  Reply With Quote
01-15-10, 11:55 AM   #15
theiven
A Defias Bandit
Join Date: Feb 2007
Posts: 3
wow that was amazing
thanks for the trouble you went threw
I spent a good part of last night playing with it and got it (sorta) working as I want.
with a little more learning and playing I think ill have it.
thanks again.
once I finnish compleetly is there a place you would like me to post my new arangment so others can use it
or is it werth it

I cant say this setup method is user friendly, but it sure is powerful
but I spose if everyone posts there work when they create a new layout soon there will be something out there for everyone
thnks again for your trouble and your addon
  Reply With Quote
06-20-10, 08:35 PM   #16
Phlanax
A Defias Bandit
Join Date: Jan 2005
Posts: 3
Whats the command to open this addon gui if any? Shouldn't it appear to have this addon's default design the moment I log onto my character with this addon enabled?

I don't see anything at all. No GUI, don't know the / command, no icon around minimap, and no hot keys.

Yes this addon been added to my addon folder and enabled it.
  Reply With Quote
06-20-10, 08:44 PM   #17
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
There is no GUI, no slash-command, no minimap-button, no hot-key - and most important: no default layout

You need to download one of the layouts (or some other addon which embeds cargBags). These could maybe have their own config GUI / slash-command, depending on the author.
cargBags by itself does nothing, just provides functionality for other addons/layouts.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » Released AddOns » cargBags - Help & Discussion


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off