Quantcast
Download
(5 Kb)
Download
Updated: 12/29/14 02:12 AM
Compatibility:
Update 7 (1.7.0)
Updated:12/29/14 02:12 AM
Created:12/03/14 12:34 AM
Monthly downloads:27
Total downloads:1,270
Favorites:1
MD5:
Circonians LibFilterIt
Version: 1.0_R3
by: circonian [More]
What does it do?
libFilterIt is a library used to filter items from different inventory views.
You can register filtering functions used to filter/hide items from different views.

LibFilterIt Filter Types
The following filterTypes are used to register your filter function for the following window/views
Lua Code:
  1. -- Inventories
  2. FILTERIT_BACKPACK       -- Filters items in the backpack inventory window
  3. FILTERIT_BANK           -- Filters items in the bank window
  4. FILTERIT_GUILDBANK      -- Filters items in the guild bank window
  5. -- Other backpack layouts
  6. FILTERIT_TRADINGHOUSE   -- Filters items in the trading house sell window
  7. FILTERIT_TRADE          -- Filters in from the trade window
  8. FILTERIT_VENDOR         -- Filters items in the vendor sell window
  9. FILTERIT_MAIL           -- Filters items in the mail send window
  10. -- General crafting
  11. FILTERIT_DECONSTRUCTION -- Filters items in all deconstruction windows
  12. FILTERIT_IMPROVEMENT        -- Filters items in all crafting improvement windows
  13. FILTERIT_REFINEMENT     -- Filters items in all refinement windows
  14. FILTERIT_RESEARCH           -- Filters items in the crafting research dialog window
  15. -- crafting
  16. FILTERIT_ALCHEMY        -- Filters items in the alchemy crafting station
  17. FILTERIT_ENCHANTING     -- Filters items in the enchanting creation & extraction window
  18. FILTERIT_PROVISIONING   -- Filters items in the provisioning crafting window

Using libFilterIt In Your Addon

Your Addon .txt
To use libFilterIt make sure you register libstub & libFilterIt in your addons .txt file. The following is an example:
Create a libs folder in your addons folder which will contain the libStub & LibFilterIt-1.0 folders. You would then register libstub & libFilter it in your .txt file like this:
Lua Code:
  1. ## Title: Click4Info
  2. ## APIVersion: 100010
  3. ## OptionalDependsOn: LibAddonMenu-2.0
  4. ## SavedVariables: Click4InfoSavedVars
  5. ## Version: 1.5
  6. ## Author: Circonian
  7. ## Description: Circonians Click4Info Version 1.5
  8.  
  9. libs\LibStub\LibStub.lua
  10. libs\LibFilterIt-1.0\LibFilterIt-1.0.lua
  11.  
  12. -- ... Other files your addon uses --

Loading The Library
In order to use libFilterIt in your addon you must also load the library. To do so add the following code in any/every code file where you intend to call any libFilterIt functions:
Lua Code:
  1. local LFI = LibStub:GetLibrary("LibFilterIt-1.0")
Your Filtering Function
Your filtering functions should return true if the item should be shown and false if the item should be hidden. The filter function takes an inventory slot as its parameter.

In the following example our filtering function returns false if the items quality is greater than ITEM_QUALITY_NORMAL, which means it would hide all green, blue, purple, & gold items. Otherwise it returns true, which means it would allow all trash & white items to be shown. Do take note that these filters work in conjunction with other addons registered filters & the games default filtering logic, so just because an item passes your filter to be shown, it may not pass another addons filter or the games filter and may still be hidden.
Lua Code:
  1. local function FilterQuality(_tSlot)
  2.    local _, _, _, _, _, _, _, quality = GetItemInfo(_tSlot.bagId, _tSlot.slotIndex)
  3.    if quality > ITEM_QUALITY_NORMAL then
  4.       return false
  5.    end
  6.    return true
  7. end

Registering a Filter
To register a filter you can call the register function:
Lua Code:
  1. function lfi:RegisterFilter(AddonName, FilterName, FilterId, FilterFunc)
This function requires that you pass in your AddonsName, a UNIQUE filter name, one of the FilterIt filter types (listed above), and your filter function.

So in our example if we wanted to use our filter function to filter all items of quality green, blue, purple, & gold from the trading house sell window we would call this:
Lua Code:
  1. local boolSuccess, stringReason = LFI:RegisterFilter("MyAddonName", "SomeUniqueFilterName", FILTERIT_TRADINGHOUSE, FilterQuality)
If the filter is successfully registered it will return true & the reason will be nil. If the registration fails it will return false & the reason it failed.

Thats it. Once registered FilterIt takes care of the rest.

Unregistering A Filter
If you ever need to unregister a filter you can call:
Lua Code:
  1. function lfi:UnregisterFilter(AddonName, FilterName, FilterId)

So to unregister the filter we just registered we would call:
Lua Code:
  1. local boolSuccess, stringReason  = LFI:UnregisterFilter("MyAddonName", "SomeUniqueFilterName", FILTERIT_TRADINGHOUSE)
If successful it will return true and the reason will be nil. If the filter is not successfully unregistered it will also return the reason, for example if you had a type-o in the filterType it would tell you "Invalid Filter ID" or if the filter did not exist it would return the reason: "Filter Name does not exist"

Other
If you ever need to check and see if a filter is already registered you can use the following function:
Lua Code:
  1. function lfi:IsFilterRegistered(_FilterName, _FilterId)
Possible returns for this are:
Lua Code:
  1. false, nil  -- If the filter name is not registered for the given filter ID
  2. false, "Invalid FilterId" -- if you make a type-o in the filterId
  3. true, "Filter Name is registered to addon: <Addon That Registered the Filter>"
Version 1.0_R3

CRASH FIX There is apparently a recipe that has either a bugged recipeResultItemLink or it has strange characters in it that was causing the game to crash, for characters that new that recipe, when the new library attempted to use the link. My characters do not know that recipe & the data for recipes can only be accessed if your character knows the recipe so I had no way of knowing this would happen. It has been fixed.

Provisioning Filter Change
Provisioning Filter Change Due to the problem with links & other things I changed the way the provisioning filter works. It doesn't change anything for any addon, just how it filters. If an item is ingredient for a recipe is marked with something other than "Save For Provisioning" it will just tell the user they do not have enough ingredients to craft the recipe and not offer the option to craft it.
Version 1.0_R2

FILTER CHANGES To make it easier to handle filter registering filters & to better fit with the way the game is designed I decided to change the blacksmithing, clothier, woodworking filters. Instead of registering for the craft type you register which view you want it hidden from:
FILTERIT_DECONSTRUCTION
If you have any more problems with it let me know. -- hides items from the deconstruction window views
FILTERIT_IMPROVEMENT
If you have any more problems with it let me know. -- Hides items from improvement window views
FILTERIT_REFINEMENT
If you have any more problems with it let me know. -- hides items from refinement window views
FILTERIT_RESEARCH
If you have any more problems with it let me know. -- Hides items from research dialog window
Code Updates Found a few cleaner ways to do things so while I was at it I updated some of the code.
Archived Files (2)
File Name
Version
Size
Author
Date
1.0_R2
6kB
circonian
12/12/14 12:29 AM
1.0_R1
6kB
circonian
12/03/14 12:34 AM


There have been no comments posted to this file.
Be the first to add one.



Category Jump: