05-10-09, 04:05 PM | #1 |
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! Last edited by xConStruct : 11-04-09 at 01:48 PM. Reason: Links update. |
|
05-13-09, 10:23 AM | #2 |
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 |
|
05-13-09, 10:54 AM | #3 |
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 |
|
05-16-09, 04:39 AM | #4 |
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) 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 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 **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. |
|
05-16-09, 07:25 AM | #5 |
Thanks for this very very good work Luzzifus.
Great job |
|
05-16-09, 07:44 AM | #6 | |
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! |
||
05-16-09, 08:20 AM | #7 |
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 |
|
05-17-09, 08:44 AM | #8 |
Okay, this seems to be a problem of the core. It will be fixed in the next cargBags-update.
|
|
05-17-09, 08:49 AM | #9 |
05-18-09, 02:16 PM | #10 |
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! |
|
05-18-09, 02:52 PM | #11 |
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
|
|
05-18-09, 02:53 PM | #12 |
If you PM me the code how you do that I might include it in my layout.
|
|
05-24-09, 11:33 AM | #13 | |
Restack Button
After moving to cargBags from ArkInventory, I was missing Ark's item stack merging feature, so I wrote kRestack (~18kb idle) and created a button for it in the Aurora layout (v1.0.1). Now, kRestack isn't a plugin, but the function to run it is global and can be called directly from cargBags.
Code:
--[[ place in layout function ]] if select(4,GetAddOnInfo("kRestack")) and (name == "cBags_Main" or name == "cBags_Bank") then local restack = createSmallButton("R", self, "BOTTOMLEFT", name == "cBags_Main" and 75 or 50, 0) restack:SetScript("OnClick", function() kRestack(name == "cBags_Main" and "bags" or "bank") end) end Also missed, was search from other mods, so I wrote these snipplets. I personally didn't think it warranted creating a whole plugin. One downside is it doesn't work for keys or other custom windows. I tried, but the extra windows kept bugging out when the filter was applied, and it wasn't pretty. Maybe someone else can figure it out. edit: the problem was actually hiding the key frame when there turned out to be no matches, this was the result. filterName() was changed to work with the keyring and other (specified) spawned frames. This is also for Aurora, and by all means, make it work better. Code:
--[[ place in layout function ]] local sText = "Search" local searchBar = CreateFrame("EditBox", "searchBar", self) searchBar:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", (name == "cBags_Main" and 125 or 75), 0) searchBar:SetWidth(100) searchBar:SetHeight(20) searchBar:SetAutoFocus(false) searchBar:SetFontObject("GameFontHighlight") searchBar:SetTextColor(1,1,1) searchBar:SetText(sText) searchBar:SetAltArrowKeyMode() searchBar:SetScript("OnTextChanged", function() count = 0 filterName(searchBar:GetText(), self) if count == 0 and searchBar:GetText() ~= "" and searchBar:GetText() ~= sText then searchBar:SetTextColor(1,0.38,0.38) filterName("", self) elseif searchBar:GetText() == "" or searchBar:GetText() == sText then searchBar:SetTextColor(1,1,1) filterName("", self) else searchBar:SetTextColor(0.38,1,0.38) end end) searchBar:SetScript("OnEditFocusGained", function() if searchBar:GetText() ~= sText then if count == 0 and searchBar:GetText() ~= "" then searchBar:SetTextColor(1,0.38,0.38) filterName("", self) elseif searchBar:GetText() == "" then searchBar:SetTextColor(1,1,1) else searchBar:SetTextColor(0.38,1,0.38) end searchBar:HighlightText() else searchBar:SetText("") end end) searchBar:SetScript("OnEditFocusLost", function() searchBar:HighlightText(0,0) searchBar:SetTextColor(1,1,1) if searchBar:GetText() == "" then searchBar:SetText(sText) end end) searchBar:SetScript("OnEnterPressed", function() searchBar:ClearFocus() end) searchBar:SetScript("OnEscapePressed", function() searchBar:SetText(""); searchBar:ClearFocus() end) --[[ place with filters ]] local searchName = function(item) local found if item.texture ~= nil and filter then found = strfind(string.lower(item.name), filter) ~= nil else found = false end if found then count = count + 1 end return found end --[[ place after bag objects are declared ]] function filterName(str, frame) if str == "" then filter = nil frame:SetFilter(searchName, false) key:SetFilter(searchName, false) junk:SetFilter(searchName, false) else filter = string.lower(str) frame:SetFilter(searchName, true) if key:IsShown() then count = 0 key:SetFilter(searchName, true) end if junk:IsShown() then count = 0 junk:SetFilter(searchName, true) end end end Last edited by Katae : 06-02-09 at 04:28 AM. |
||
06-04-09, 02:06 AM | #14 |
Hi, I'm trying to replace the bags when his anchor is hidden.
So far here's the code I have (don't care the strange characters near bak, it means that the previous string his between brackets most likely this, bak[frame]) : lua Code:
Everything works well execpt for equipment, if I hide it then stuff or quest (depending on which ones are shown) don't move at all. It can understand why this bag seems not to work (different anchoring method) but not how to resolve it. |
|
06-17-09, 03:49 AM | #15 |
No one knows ?
|
|
06-18-09, 03:24 AM | #16 |
I'm not exactly certain what you're trying to achieve. If you want empty bags to hide and all bags around the hidden bag to move together then you could also take a look at my approach, which works perfectly an is easily extendable.
My idea was to save anchoring information for every bag frame. This is not information about which one the bag is anchored to but rather which bags are anchored to the current one (mainly for performance reasons). Then there is a function which does the actual anchoring based on this information whenever it is needed (UpdateButtonPositions). If that is what you need I can explain my approach further if you want. |
|
06-18-09, 04:18 AM | #17 |
What I try to achieve is move the bag to his parent previous placement when the parent hides. For exemple I hide my consumable bag and then my trade goods bag moves to consumable place, but when I show the consumable bag again the tade goods bag goes to his initial placement.
If I use my work (the functions given above) everything works fine, except for the equipment bag, because the stuff bag doesn't move when I hide it. I don't know why the bag doesn't move but the only difference with the other bags is that it has a different anchoring method (topright to topleft). But you can help me with hiding empty bags that would also be cool |
|
06-18-09, 04:46 AM | #18 |
Ok, now what comes to my attention is that you don't call ClearAllPoints in the parents OnHide() function. And if I understand your code correctly this should be there, since you always re-set the points on hiding/showing.
---------- What I am doing has a pretty similar effect to what you are doing, though I'm doing it different. You could simply expand your code to hide empty bags by simply expanding your conditions to hide bags. Hiding empty bags with parent anchoring The idea was to save anchoring information in every frame. This is not information about which one the frame is anchored to but rather which frames are anchored to the current one (mainly for performance reasons). So when I'm spawning the bags, it looks like this: Code:
----------------------------------------------- -- Store the anchoring order: -- read: "tar" is anchored to "src" in the direction denoted by "dir". ----------------------------------------------- local function CreateAnchorInfo(src,tar,dir) tar.AnchorTo = src tar.AnchorDir = dir if src then if not src.AnchorTargets then src.AnchorTargets = {} end src.AnchorTargets[tar] = true end end -- Main Anchors: -- Note that you still have to set points for those! CreateAnchorInfo(nil, cB_Bags.main, "Bottom") CreateAnchorInfo(nil, cB_Bags.bank, "Bottom") cB_Bags.main:SetPoint("BOTTOMRIGHT", -20, 150) cB_Bags.bank:SetPoint("LEFT", 15, 0) -- Bank Anchors: CreateAnchorInfo(cB_Bags.bank, cB_Bags.bankArmor, "Right") CreateAnchorInfo(cB_Bags.bankArmor, cB_Bags.bankTrade, "Bottom") -- more CreateAnchorInfos -- Now you need this little fella in your code: Code:
function cargBags_Nivaya:UpdateAnchors(self) if not self.AnchorTargets then return end for v,_ in pairs(self.AnchorTargets) do local t, u = v.AnchorTo, v.AnchorDir if t then local h = cB_BagHidden[t.Name] v:ClearAllPoints() if not h and u == "Top" then v:SetPoint("BOTTOM", t, "TOP", 0, 15) elseif h and u == "Top" then v:SetPoint("BOTTOM", t, "BOTTOM") elseif not h and u == "Bottom" then v:SetPoint("TOP", t, "BOTTOM", 0, -15) elseif h and u == "Bottom" then v:SetPoint("TOP", t, "TOP") elseif u == "Left" then v:SetPoint("BOTTOMRIGHT", t, "BOTTOMLEFT", -15, 0) elseif u == "Right" then v:SetPoint("TOPLEFT", t, "TOPRIGHT", 15, 0) end end end end The last thing you have to do is bind the anchoring update to an event. So just add something like the following to your UpdateButtonPositions handler. At the same time I'm checking for empty bags: Code:
local tName = self.Name local isEmpty = true for _,v in ipairs(buttons) do ... isEmpty = false end cB_BagHidden[tName] = (not t) and isEmpty or false cargBags_Nivaya:UpdateAnchors(self) Now it basically should work. There's two things you still have to do. First is to apply the check for empty bags to you OpenCargBags() function, I'm doing it like this: Code:
local function ShowBag(bag) if not cB_BagHidden[bag.Name] then bag:Show() end end function OpenCargBags() cB_Bags.main:Show() ShowBag(cB_Bags.armor) ShowBag(cB_Bags.bagNew) ShowBag(cB_Bags.bagItemSets) ShowBag(cB_Bags.quest) ... end Code:
local tName = self.Name local tBankBags = string.find(tName, "cBniv_Bank%a+") local tBank = tBankBags or (tName == "cBniv_Bank") local t = (tName == "cBniv_Bag") or (tName == "cBniv_Bank") or (tName == "cBniv_Keyring") local tAS = (tName == "cBniv_Ammo") or (tName == "cBniv_Soulshards") if (not tBankBags and cB_Bags.main:IsShown() and not (t or tAS)) or (tBankBags and cB_Bags.bank:IsShown()) then if isEmpty then self:Hide() else self:Show() end end After typing all that I realize how complex my solution is.. Hope it helps anyways. Last edited by Luzzifus : 06-18-09 at 05:00 AM. |
|
06-18-09, 05:29 AM | #19 |
This isn't so complex, it's just a different point of view for setting points.
Thanks for the help, I didn't see that I forgot the ClearAllPoints in the OnHide script but not in the OnShow. Now everything is fine. I will adapt your solution to adapt this with my layout. |
|
07-08-09, 11:19 AM | #20 |
didn't see there is a help & discussion session, sry.
so here again my post: i use the Nivaya addon! first of all: very good addon, i want to use it further!! ;-) but... the game always gets really jerky if (it wasn't so before!) there's access to the bags. they are closed, and if i pick up loot or craft something which involves a bag place, the game stops for about 0,5 sec. it's a no go :-( as in raids/instances where you often loot, it slows the whole game down... never had that in ANY other addon! i hope there is a fix for this great addon... *sigh* Last edited by jedcooper : 07-08-09 at 01:25 PM. Reason: added the addon name |
|
WoWInterface » AddOns, Compilations, Macros » Released AddOns » cargBags - Help & Discussion |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|