Permalink
Browse files

BBag我败给你了

  • Loading branch information...
1 parent 39a4355 commit 3108805822efe7fa4a580db3445f7abfc0ce0d45 @Coolkids committed Apr 24, 2012
Showing with 2,622 additions and 428 deletions.
  1. +60 −0 Interface/Addons/!SunUI/Libs/cargBags/base-add/bags.sieve.lua
  2. +167 −0 Interface/Addons/!SunUI/Libs/cargBags/base-add/filters.sieve.lua
  3. +124 −0 Interface/Addons/!SunUI/Libs/cargBags/base/container.lua
  4. +203 −0 Interface/Addons/!SunUI/Libs/cargBags/base/core.lua
  5. +452 −0 Interface/Addons/!SunUI/Libs/cargBags/base/implementation.lua
  6. +96 −0 Interface/Addons/!SunUI/Libs/cargBags/base/itembutton.lua
  7. +73 −0 Interface/Addons/!SunUI/Libs/cargBags/embed.xml
  8. +146 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/default.scaffold.lua
  9. +48 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/itemkeys/basic.lua
  10. +68 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/itemkeys/equipSets.lua
  11. +59 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/itemkeys/tooltip.lua
  12. +76 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/layouts.lua
  13. +227 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/plugins/bagBar.lua
  14. +133 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/plugins/searchBar.lua
  15. +149 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/plugins/tagDisplay.lua
  16. +39 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins-add/sorts.lua
  17. +91 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins/api-common.lua
  18. +63 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins/locale.lua
  19. +69 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins/parseBags.lua
  20. +82 −0 Interface/Addons/!SunUI/Libs/cargBags/mixins/textFilter.lua
  21. +1 −0 Interface/Addons/!SunUI/Libs/load.xml
  22. +196 −428 Interface/Addons/!SunUI/Modules/Bags/bags.lua
@@ -0,0 +1,60 @@
+--[[
+LICENSE
+ cargBags: An inventory framework addon for World of Warcraft
+
+ Copyright (C) 2010 Constantin "Cargor" Schomburg <xconstruct@gmail.com>
+
+ cargBags is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ cargBags is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cargBags; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+DESCRIPTION
+ The bag sieve just places items in the right containers based on their bagID
+
+DEPENDENCIES
+ mixins\parseBags.lua (optional)
+]]
+local _, ns = ...
+local cargBags = ns.cargBags
+
+local Implementation = cargBags.classes.Implementation
+
+--[[!
+ Returns a container for a specific item [replaces virtual function]
+ @param item <ItemTable>
+ @returns container <Container>
+]]
+function Implementation:GetContainerForItem(item)
+ return item.bagID and self.bagToContainer and self.bagToContainer[item.bagID]
+end
+
+local Container = cargBags.classes.Container
+
+--[[!
+ Sets the handled bags for a container
+ @param bags <BagType>
+]]
+function Container:SetBags(bags)
+ if(cargBags.ParseBags) then
+ bags = cargBags:ParseBags(bags)
+ end
+
+ if(not bags) then return end
+
+ self.implementation.bagToContainer = self.implementation.bagToContainer or {}
+ local b2c = self.implementation.bagToContainer
+
+ for i, bagID in pairs(bags) do
+ b2c[bagID] = self
+ end
+end
@@ -0,0 +1,167 @@
+--[[
+LICENSE
+ cargBags: An inventory framework addon for World of Warcraft
+
+ Copyright (C) 2010 Constantin "Cargor" Schomburg <xconstruct@gmail.com>
+
+ cargBags is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ cargBags is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cargBags; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+DESCRIPTION
+ This file implements the filtering system for categories into cargBags.
+ It is not compatible with other container sieves, especially not
+ with the ones using Implementation:GetContainerForItem()
+]]
+local _, ns = ...
+local cargBags = ns.cargBags
+local Implementation = cargBags.classes.Implementation
+local Container = cargBags.classes.Container
+
+local FilterSet = cargBags:NewClass("FilterSet")
+
+--[[!
+ Returns a new FilterSet
+ @return set <FilterSet>
+]]
+function FilterSet:New()
+ return setmetatable({
+ funcs = {},
+ params = {},
+ chained = {},
+ }, self.__index)
+end
+
+--[[!
+ Empties the filter table
+]]
+function FilterSet:Empty()
+ for k in pairs(self.funcs) do self.funcs[k] = nil end
+ for k in pairs(self.params) do self.params[k] = nil end
+ for k in pairs(self.chained) do self.chained[k] = nil end
+end
+
+--[[!
+ Sets a filter function and its flag
+ @param filter <function>
+ @param flag <bool> whether the filter is enabled (-1: inverted)
+]]
+function FilterSet:Set(filter, flag)
+ self.funcs[filter] = flag
+end
+
+--[[!
+ Sets a filter and its parameter
+ @param filter <function>
+ @param param <any>
+ @param flag <bool> whether the filter is enabled (-1: inverted) [optional]
+]]
+function FilterSet:SetExtended(filter, param, flag)
+ if(not flag and param) then
+ flag = true
+ end
+
+ self:Set(filter, flag)
+ self.params[filter] = param
+end
+
+--[[!
+ Sets multiple filters
+ @param flag <bool> whether the filters are enabled (-1: inverted)
+ @param ... <function> a list of filters
+]]
+function FilterSet:SetMultiple(flag, ...)
+ for i=1, select("#", ...) do
+ local filter = select(i, ...)
+ self:Set(filter, flag)
+ end
+end
+
+--[[!
+ chains / unchains an additional filter set
+ @param set <FilterSet>
+ @param flag <bool> enabled or not
+]]
+function FilterSet:Chain(set, flag)
+ self.chained[set] = flag
+end
+
+--[[!
+ Checks if an item passes this filter table
+ @param item <ItemTable>
+ @return passed <bool>
+]]
+function FilterSet:Check(item)
+ local funcs, params = self.funcs, self.params
+
+ -- check own filters
+ for filter, flag in pairs(funcs) do
+ local result = filter(item, params[filter])
+ if((flag == true and not result) or (flag == -1 and result)) then
+ return nil
+ end
+ end
+
+ -- check filters of chained sets
+ for table in pairs(self.chained) do
+ if(not table:Check(item)) then
+ return nil
+ end
+ end
+
+ return true
+end
+
+--[[!
+ Returns the right container for a specific item
+ @param item <ItemTable>
+ @return container <Container>
+]]
+function Implementation:GetContainerForItem(item)
+ for i, container in ipairs(self.contByID) do
+ if(not container.filters or container.filters:Check(item)) then
+ return container
+ end
+ end
+end
+
+--[[
+ Simple function shortcuts for Containers
+]]
+for name, func in pairs{
+ ["SetFilter"] = "Set",
+ ["SetExtendedFilter"] = "SetExtended",
+ ["SetMultipleFilters"] = "SetMultiple",
+ ["ChainFilters"] = "Chain",
+ ["CheckFilters"]= "Check",
+} do
+ Container[name] = function(self, ...)
+ self.filters = self.filters or FilterSet:New()
+ self.filters[func](self.filters, ...)
+ end
+end
+
+--[[!
+ Calls a function(button, result) with the result of the filters on all child-itembuttons
+ @param func <function>
+ @param filters <FilterTable> check against other filters [optional]
+]]
+function Container:FilterForFunction(func, filters)
+ filters = filters or self.filters
+
+ for i, button in pairs(self.buttons) do
+ local result = filters:Check(button:GetItemInfo())
+ func(button, result)
+ end
+end
+
@@ -0,0 +1,124 @@
+--[[
+ cargBags: An inventory framework addon for World of Warcraft
+
+ Copyright (C) 2010 Constantin "Cargor" Schomburg <xconstruct@gmail.com>
+
+ cargBags is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ cargBags is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cargBags; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+]]
+local _, ns = ...
+local cargBags = ns.cargBags
+
+--[[!
+ @class Container
+ The container class provides the virtual bags for cargBags
+]]
+local Container = cargBags:NewClass("Container", nil, "Button")
+
+local mt_bags = {__index=function(self, bagID)
+ self[bagID] = CreateFrame("Frame", nil, self.container)
+ self[bagID]:SetID(bagID)
+ return self[bagID]
+end}
+
+--[[!
+ Creates a new instance of the class
+ @param name <string>
+ @param ... Arguments passed to the OnCreate-callback
+ @return container <Container>
+ @callback container:OnCreate(name, ...)
+]]
+function Container:New(name, ...)
+ local implName = self.implementation.name
+ local container = setmetatable(CreateFrame("Button", implName..name), self.__index)
+
+ container.name = name
+ container.buttons = {}
+ container.bags = setmetatable({container = container}, mt_bags)
+ container:ScheduleContentCallback()
+
+ container.implementation.contByName[name] = container -- Make this into pretty function?
+ table.insert(container.implementation.contByID, container)
+
+ container:SetParent(self.implementation)
+
+ if(container.OnCreate) then container:OnCreate(name, ...) end
+
+ return container
+end
+
+--[[!
+ Adds an ItemButton to this container
+ @param button <ItemButton>
+ @callback button:OnAdd(self)
+ @callback OnButtonAdd(button)
+]]
+function Container:AddButton(button)
+ button.container = self
+ button:SetParent(self.bags[button.bagID])
+ self:ScheduleContentCallback()
+ table.insert(self.buttons, button)
+ if(button.OnAdd) then button:OnAdd(self) end
+ if(self.OnButtonAdd) then self:OnButtonAdd(button) end
+end
+
+--[[!
+ Removes an ItemButton from the container
+ @param button <ItemButton>
+ @callback button:OnRemove(self)
+ @callback OnButtonRemove(button)
+]]
+function Container:RemoveButton(button)
+ for i, single in ipairs(self.buttons) do
+ if(button == single) then
+ self:ScheduleContentCallback()
+ button.container = nil
+ if(button.OnRemove) then button:OnRemove(self) end
+ if(self.OnButtonRemove) then self:OnButtonRemove(button) end
+ return table.remove(self.buttons, i)
+ end
+ end
+end
+
+--[[
+ @callback OnContentsChanged()
+]]
+local updater, scheduled = CreateFrame"Frame", {}
+updater:Hide()
+updater:SetScript("OnUpdate", function(self)
+ self:Hide()
+ for container in pairs(scheduled) do
+ if(container.OnContentsChanged) then container:OnContentsChanged() end
+ scheduled[container] = nil
+ end
+end)
+
+--[[
+ Schedules a Content-callback in the next update
+]]
+function Container:ScheduleContentCallback()
+ scheduled[self] = true
+ updater:Show()
+end
+
+--[[
+ Applies a function to the contained buttons
+ @param func <function>
+ @param ... Arguments which are passed to the function
+]]
+function Container:ApplyToButtons(func, ...)
+ for i, button in pairs(self.buttons) do
+ func(button, ...)
+ end
+end
Oops, something went wrong.

0 comments on commit 3108805

Please sign in to comment.