Quantcast

V0.5.0

Brandon Talbot [07-11-16 - 19:00]
V0.5.0

* Refactored to allow formatter selection
* Added settings for formatter selection
* Removed irrelevant settings
* Added junk and new container to sort so they always show on top
Filename
src/lua/cache/cache.lua
src/lua/controllers/bag.lua
src/lua/controllers/bank.lua
src/lua/elements/categoryContainer.lua
src/lua/elements/item.lua
src/lua/elements/itemContainer.lua
src/lua/formatters/horizontal.lua
src/lua/formatters/vertical.lua
src/lua/settings/defaults/categoryContainer.lua
src/lua/settings/defaults/formatter.lua
src/lua/settings/defaults/itemContainer.lua
src/lua/settings/editor.lua
src/lua/settings/settings.lua
src/lua/sorters/containers.lua
src/lua/utils/utils.lua
src/manifest.xml
diff --git a/src/lua/cache/cache.lua b/src/lua/cache/cache.lua
index 9fce410..8b79663 100644
--- a/src/lua/cache/cache.lua
+++ b/src/lua/cache/cache.lua
@@ -30,7 +30,7 @@ function cache:GetReagentItemContainer(name)
     return self.reagentContainers[name]
 end

-function cache:UpdateSettings(arrange)
+function cache:UpdateSettings()
     for _, slots in pairs(self.items) do
         for _, item in pairs(slots) do
             item:Setup()
@@ -38,8 +38,11 @@ function cache:UpdateSettings(arrange)
     end
     for _, container in pairs(cache.bagContainers) do
         container:Setup()
-        if arrange then
-            container:Arrange()
-        end
+    end
+    for _, container in pairs(cache.bankContainers) do
+        container:Setup()
+    end
+    for _, container in pairs(cache.reagentContainers) do
+        container:Setup()
     end
 end
\ No newline at end of file
diff --git a/src/lua/controllers/bag.lua b/src/lua/controllers/bag.lua
index 5449ace..3cfda87 100644
--- a/src/lua/controllers/bag.lua
+++ b/src/lua/controllers/bag.lua
@@ -70,24 +70,16 @@ function bag:NewItemsUpdated()
 end

 function bag:UpdateAllItems()
-    local arrangeList = {}
     for bag = 0, NUM_BAG_SLOTS do
-        ADDON.utils:UpdateItemsForBag(self.frame, bag, arrangeList, ADDON.cache.GetBagItemContainer)
-    end
-    self:CheckForRemovedItems(arrangeList)
-    for container, _ in pairs(arrangeList) do
-        container:Arrange()
+        ADDON.utils:UpdateItemsForBag(self.frame, bag, ADDON.cache.GetBagItemContainer)
     end
+    self:CheckForRemovedItems()
     self.frame:Arrange()
 end

 function bag:UpdateAllItemsForBag(bag)
-    local arrangeList = {}
-    ADDON.utils:UpdateItemsForBag(self.frame, bag, arrangeList, ADDON.cache.GetBagItemContainer)
-    self:CheckForRemovedItems(arrangeList)
-    for container, _ in pairs(arrangeList) do
-        container:Arrange()
-    end
+    ADDON.utils:UpdateItemsForBag(self.frame, bag, ADDON.cache.GetBagItemContainer)
+    self:CheckForRemovedItems()
     self.frame:Arrange()
 end

@@ -160,10 +152,10 @@ function bag:BAG_UPDATE_DELAYED()
     self.frame.bagBar:Update()
 end

-function bag:CheckForRemovedItems(arrangeList)
+function bag:CheckForRemovedItems()
     for bag = 1, NUM_BAG_SLOTS do
         if GetContainerNumSlots(bag) == 0 and ADDON.cache.items[bag] then
-            ADDON.utils:UpdateItemsForBag(self.frame, bag, arrangeList, ADDON.cache.GetBagItemContainer)
+            ADDON.utils:UpdateItemsForBag(self.frame, bag, ADDON.cache.GetBagItemContainer)
         end
     end
 end
\ No newline at end of file
diff --git a/src/lua/controllers/bank.lua b/src/lua/controllers/bank.lua
index dce5cb1..732648c 100644
--- a/src/lua/controllers/bank.lua
+++ b/src/lua/controllers/bank.lua
@@ -92,13 +92,9 @@ function bank:OnHide()
 end

 function bank:UpdateAllItems()
-    local arrangeList = {}
-    ADDON.utils:UpdateItemsForBag(self.bankContainer, BANK_CONTAINER, arrangeList, ADDON.cache.GetBankItemContainer)
+    ADDON.utils:UpdateItemsForBag(self.bankContainer, BANK_CONTAINER, ADDON.cache.GetBankItemContainer)
     for bag = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + GetNumBankSlots() do
-        ADDON.utils:UpdateItemsForBag(self.bankContainer, bag, arrangeList, ADDON.cache.GetBankItemContainer)
-    end
-    for container, _ in pairs(arrangeList) do
-        container:Arrange()
+        ADDON.utils:UpdateItemsForBag(self.bankContainer, bag, ADDON.cache.GetBankItemContainer)
     end
     self.bankContainer:Arrange()

@@ -107,11 +103,7 @@ end

 function bank:UpdateReagentBank()
     if IsReagentBankUnlocked() then
-        local arrangeList = {}
-        ADDON.utils:UpdateItemsForBag(self.reagentContainer, REAGENTBANK_CONTAINER, arrangeList, ADDON.cache.GetReagentItemContainer)
-        for container, _ in pairs(arrangeList) do
-            container:Arrange()
-        end
+        ADDON.utils:UpdateItemsForBag(self.reagentContainer, REAGENTBANK_CONTAINER, ADDON.cache.GetReagentItemContainer)
         self.reagentContainer:Arrange()
         self.reagentButton:SetText(REAGENTBANK_DEPOSIT)
         self.reagentButton:SetWidth(self.reagentButton:GetFontString():GetStringWidth() + 31)
@@ -122,11 +114,7 @@ function bank:UpdateReagentBank()
 end

 function bank:UpdateAllItemsForBag(bag)
-    local arrangeList = {}
-    ADDON.utils:UpdateItemsForBag(self.bankContainer, bag, arrangeList, ADDON.cache.GetBankItemContainer)
-    for container, _ in pairs(arrangeList) do
-        container:Arrange()
-    end
+    ADDON.utils:UpdateItemsForBag(self.bankContainer, bag, ADDON.cache.GetBankItemContainer)
     self.bankContainer:Arrange()
 end

diff --git a/src/lua/elements/categoryContainer.lua b/src/lua/elements/categoryContainer.lua
index 2ce72cf..ae8049e 100644
--- a/src/lua/elements/categoryContainer.lua
+++ b/src/lua/elements/categoryContainer.lua
@@ -48,7 +48,7 @@ function container:Setup()

     self.padding = settings.padding
     self.spacing = settings.spacing
-    self.sortFunction = ADDON.sorters.containers[settings.sortFunction]
+    self.formatter = ADDON.formatters[settings.formatter]
     self.maxHeight = settings.maxHeight
     if settings.closeVisible then
         self.closeBtn:Show()
@@ -64,33 +64,5 @@ function container:AddContainer(container)
 end

 function container:Arrange()
-    local list = self.containers
-
-    local x = -self.padding
-    local y = self.padding
-    local width = 0
-    local height = 0
-
-    for item in ADDON.utils:PairsByKey(list, self.sortFunction) do
-        item:ClearAllPoints()
-        item:SetParent(self)
-
-        if item:IsEmpty() then
-            item:Hide()
-        else
-            item:Show()
-            if (y + item:GetHeight() + self.spacing) > self.maxHeight then
-                y = self.padding
-                x = x - item:GetWidth() - self.spacing
-            end
-
-            item:SetPoint('BOTTOMRIGHT', x, y)
-
-            height = math.max(height, y + item:GetHeight() + self.padding)
-            width = math.max(width, -x + self.padding + item:GetWidth())
-            y = y + self.spacing + item:GetHeight()
-        end
-    end
-
-    self:SetSize(width, height)
+    self.formatter:Format(self)
 end
\ No newline at end of file
diff --git a/src/lua/elements/item.lua b/src/lua/elements/item.lua
index cfb2aaa..1679eb3 100644
--- a/src/lua/elements/item.lua
+++ b/src/lua/elements/item.lua
@@ -63,6 +63,10 @@ function item:Init()
     self.button:HookScript('OnClick', self.OnClick)
 end

+function item:ShowCountText(text)
+    SetItemButtonCount(self.button, text)
+end
+
 function item:Setup()
     local settings = ADDON.settings.item
     self:SetSize(settings.size, settings.size)
diff --git a/src/lua/elements/itemContainer.lua b/src/lua/elements/itemContainer.lua
index 0514c3c..b50bf04 100644
--- a/src/lua/elements/itemContainer.lua
+++ b/src/lua/elements/itemContainer.lua
@@ -25,6 +25,11 @@ function container:Init(hasTitle)
     self.items = {}
     if hasTitle == nil or hasTitle then
         self.title = self:CreateFontString(self:GetName() .. 'Title', 'OVERLAY', 'GameFontNormal')
+        self.title.scriptHandler = CreateFrame('FRAME', 'DJBagsScriptHandler' .. self.name, self)
+        self.title.scriptHandler:SetPoint('TOPLEFT')
+        self.title.scriptHandler:SetPoint('TOPRight')
+        self.title.scriptHandler:SetScript('OnEnter', self.TitleEnter)
+        self.title.scriptHandler:SetScript('OnLeave', self.TitleLeave)
     end
 end

@@ -35,18 +40,24 @@ function container:Setup()

     self.padding = settings.padding
     self.spacing = settings.spacing
-    self.cols = settings.cols
     self.sortFunction = ADDON.sorters.items[settings.sortFunction]
+    self.fontSize = settings.fontSize

     if self.title then
         local font, _, outline = self.title:GetFont()
         self.title:SetFont(font, settings.fontSize, outline)
-        self.title:SetText(self.name)
+        if not settings.showClassWithSub and string.match(self.name, '%a*_%a*') then
+            local name = string.match(self.name, '%a*_(%a*)')
+            self.title:SetText(name)
+        else
+            self.title:SetText(self.name)
+        end
+        self.title:SetMaxLines(1)
         self.title:SetTextColor(unpack(settings.fontColor))
         self.title:ClearAllPoints()
-        self.title:SetPoint('TOPLEFT', self.padding, -self.padding)
-        self.title:SetPoint('TOPRIGHT', -self.padding, -self.padding)
+        self.title:SetPoint('TOPLEFT', 0, -self.padding)
         self.title.margin = settings.titleMargin
+        self.title.scriptHandler:SetHeight(self.fontSize)
     end
 end

@@ -58,11 +69,11 @@ function container:RemoveItem(item)
     self.items[item] = nil
 end

-function container:Arrange()
+function container:Arrange(cols)
     local list = self.items

     local x = self.padding
-    local y = -self.padding - (self.title and (self.title:GetStringHeight() + self.title.margin) or 0)
+    local y = -self.padding - (self.title and (self.fontSize + self.title.margin) or 0)
     local width
     local height = 0

@@ -72,30 +83,58 @@ function container:Arrange()
         item:ClearAllPoints()
         item:SetParent(self)

-        if self.max and cnt >= self.cols then
+        if self.max and cnt >= cols then
             item:Hide()
         else
             item:SetPoint('TOPLEFT', x, y)
             item:Show()

-            width = width or self.cols * (self.spacing + item:GetWidth()) - self.spacing + self.padding * 2
+            width = width or cols * (self.spacing + item:GetWidth()) - self.spacing + self.padding * 2
             height = math.max(height, -y + item:GetHeight() + self.padding)

             cnt = cnt + 1

-            if cnt % self.cols == 0 then
+            if cnt % cols == 0 then
                 y = y - self.spacing - item:GetHeight()
                 x = self.padding
             else
                 x = x + self.spacing + item:GetWidth()
             end
+            if self.max and cnt == cols then
+                item:ShowCountText(self:Count() - cnt + 1)
+            end
         end
     end
     if width then
         self:SetSize(width, height)
+        if self.title then
+            self.title:SetWidth(width)
+        end
     end
 end

+function container:Count()
+    local count = 0
+    for _, v in pairs(self.items) do
+        if v and v ~= nil then
+            count = count + 1
+        end
+    end
+    return count
+end
+
 function container:IsEmpty()
     return next(self.items) == nil
+end
+
+function container:TitleEnter()
+    if (self:GetParent().title:IsTruncated()) then
+        GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
+        GameTooltip:SetText(self:GetParent().name)
+        GameTooltip:Show()
+    end
+end
+
+function container:TitleLeave()
+    GameTooltip:Hide()
 end
\ No newline at end of file
diff --git a/src/lua/formatters/horizontal.lua b/src/lua/formatters/horizontal.lua
new file mode 100644
index 0000000..fc20d81
--- /dev/null
+++ b/src/lua/formatters/horizontal.lua
@@ -0,0 +1,61 @@
+local NAME, ADDON = ...
+
+ADDON.formatters = ADDON.formatters or {}
+
+ADDON.formatters['horizontal'] = {}
+
+local formatter = ADDON.formatters['horizontal']
+formatter.__index = formatter
+
+function formatter:Format(container)
+    local settings = ADDON.settings.formatter.horizontal
+
+    local list = container.containers
+
+    local maxCols = settings.cols
+    local h = container.padding
+
+    local x = container.padding
+    local mH = 0
+    local mW = 0
+    local cnt = 0
+    local lastH = 0
+
+    for v in ADDON.utils:PairsByKey(list, ADDON.sorters.containers[settings.sorter]) do
+        if v:IsEmpty() then
+            v:Hide()
+        else
+            v:Show()
+            local numItems = v.name == EMPTY and 1 or v:Count()
+
+            if cnt ~= 0 and (cnt + numItems) > maxCols then
+                x = container.padding
+                h = h + mH + container.spacing
+                cnt = 0
+                mH = 0
+            end
+
+            if numItems > maxCols then
+                v:Arrange(maxCols)
+            else
+                v:Arrange(numItems)
+            end
+
+            v:SetParent(container)
+            v:ClearAllPoints()
+            v:SetPoint('TOPLEFT', x, -h)
+
+            mH = math.max(mH, v:GetHeight())
+            mW = math.max(mW, x + v:GetWidth())
+            x = x + container.spacing + v:GetWidth()
+
+            cnt = cnt + numItems
+            lastH = v:GetHeight()
+        end
+    end
+
+    container:SetSize(
+        mW + container.padding,
+        h + container.padding + lastH
+    )
+end
\ No newline at end of file
diff --git a/src/lua/formatters/vertical.lua b/src/lua/formatters/vertical.lua
new file mode 100644
index 0000000..92e32cb
--- /dev/null
+++ b/src/lua/formatters/vertical.lua
@@ -0,0 +1,43 @@
+local NAME, ADDON = ...
+
+ADDON.formatters = ADDON.formatters or {}
+
+ADDON.formatters['vertical'] = {}
+
+local formatter = ADDON.formatters['vertical']
+formatter.__index = formatter
+
+function formatter:Format(container)
+    local settings = ADDON.settings.formatter.vertical
+
+    local list = container.containers
+
+    local x = -container.padding
+    local y = container.padding
+    local width = 0
+    local height = 0
+
+    for item in ADDON.utils:PairsByKey(list, ADDON.sorters.containers[settings.sorter]) do
+        item:Arrange(settings.cols)
+        item:ClearAllPoints()
+        item:SetParent(container)
+
+        if item:IsEmpty() then
+            item:Hide()
+        else
+            item:Show()
+            if (y + item:GetHeight() + container.spacing) > (settings.maxHeight / 100 * GetScreenHeight()) then
+                y = container.padding
+                x = x - item:GetWidth() - container.spacing
+            end
+
+            item:SetPoint('BOTTOMRIGHT', x, y)
+
+            height = math.max(height, y + item:GetHeight() + container.padding)
+            width = math.max(width, -x + container.padding + item:GetWidth())
+            y = y + container.spacing + item:GetHeight()
+        end
+    end
+
+    container:SetSize(width, height)
+end
\ No newline at end of file
diff --git a/src/lua/settings/defaults/categoryContainer.lua b/src/lua/settings/defaults/categoryContainer.lua
index 84915dd..55df250 100644
--- a/src/lua/settings/defaults/categoryContainer.lua
+++ b/src/lua/settings/defaults/categoryContainer.lua
@@ -5,8 +5,7 @@ ADDON.settings = ADDON.settings or {}
 ADDON.settings.categoryContainer = {
     padding = 5,
     spacing = 3,
-    maxHeight = 450,
-    sortFunction = 'default',
+    formatter = 'vertical',
     closeVisible = false,
     closeSize = 25,
 }
diff --git a/src/lua/settings/defaults/formatter.lua b/src/lua/settings/defaults/formatter.lua
new file mode 100644
index 0000000..c9ecae2
--- /dev/null
+++ b/src/lua/settings/defaults/formatter.lua
@@ -0,0 +1,16 @@
+local NAME, ADDON = ...
+
+ADDON.settings = ADDON.settings or {}
+
+ADDON.settings.formatter = {
+    vertical = {
+        sorter = 'defaultVertical',
+        cols = 4,
+        maxHeight = 50,
+    },
+    horizontal = {
+        sorter = 'defaultHorizontal',
+        cols = 12,
+    },
+}
+
diff --git a/src/lua/settings/defaults/itemContainer.lua b/src/lua/settings/defaults/itemContainer.lua
index 60042ea..b2ebaa0 100644
--- a/src/lua/settings/defaults/itemContainer.lua
+++ b/src/lua/settings/defaults/itemContainer.lua
@@ -10,4 +10,5 @@ ADDON.settings.itemContainer = {
     fontColor = { 0.5, 1, 0.5, 1 },
     titleMargin = 5,
     sortFunction = 'default',
+    showClassWithSub = true,
 }
\ No newline at end of file
diff --git a/src/lua/settings/editor.lua b/src/lua/settings/editor.lua
index 4e5a640..76c6346 100644
--- a/src/lua/settings/editor.lua
+++ b/src/lua/settings/editor.lua
@@ -27,7 +27,7 @@ end

 function settings:CreateFrame()
     self.frame = ADDON.container('DJBagsSettingsScreen')
-    self.frame:SetSize(520, 450)
+    self.frame:SetSize(520, 0.5 * GetScreenHeight())
     self.frame:SetPoint("TOPLEFT", 200, -200)
     self.frame:Hide()
     table.insert(UISpecialFrames, self.frame:GetName())
@@ -77,6 +77,7 @@ function settings:CreateFrame()

     self:CreateAutoSettings()
     self:CreateCategorySettings()
+    self:CreateFormatterSettings()
     self:CreateItemSettings()
     self:CreateContainerSettings()
     self:CreateItemContainerSettings()
@@ -257,21 +258,13 @@ function settings:CreateItemContainerSettings()
     end)
     container.fontSize:SetPoint('TOPLEFT', container.fontColor, 'TOPRIGHT', 15, 0)

-    container.colsSlider = CreateSlider('Columns', container, 4, 10, function()
-        return ADDON.settings.itemContainer.cols
-    end, function(value)
-        ADDON.settings.itemContainer.cols = value
-        ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
-    end)
-    container.colsSlider:SetPoint('TOPLEFT', container.fontSize, 'TOPRIGHT', 15, 0)
-
     container.padding = CreateSlider('Padding', container, 1, 10, function()
         return ADDON.settings.itemContainer.padding
     end, function(value)
         ADDON.settings.itemContainer.padding = value
         ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
     end)
-    container.padding:SetPoint('TOPLEFT', container.fontColor, 'BOTTOMLEFT', 2, -20)
+    container.padding:SetPoint('TOPLEFT', container.fontSize, 'TOPRIGHT', 15, 0)

     container.spacing = CreateSlider('Item Spacing', container, 1, 10, function()
         return ADDON.settings.itemContainer.spacing
@@ -279,7 +272,13 @@ function settings:CreateItemContainerSettings()
         ADDON.settings.itemContainer.spacing = value
         ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
     end)
-    container.spacing:SetPoint('TOPLEFT', container.padding, 'TOPRIGHT', 15, 0)
+    container.spacing:SetPoint('TOPLEFT', container.fontColor, 'BOTTOMLEFT', 2, -20)
+
+    container.subClassWithClass = CreateCheckBox('Show Class With Subclass', container, ADDON.settings.itemContainer.showClassWithSub, function(value)
+        ADDON.settings.itemContainer.showClassWithSub = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.subClassWithClass:SetPoint('LEFT', container.spacing, 'RIGHT', 10, 0)

     container:SetHeight(95)
     self:AddSettingsPanel(container)
@@ -306,21 +305,13 @@ function settings:CreateCategoryContainerSettings()
     end)
     container.spacing:SetPoint('TOPLEFT', container.padding, 'TOPRIGHT', 15, 0)

-    container.maxHeight = CreateSlider('Max height', container, 250, 1000, function()
-        return ADDON.settings.categoryContainer.maxHeight
-    end, function(value)
-        ADDON.settings.categoryContainer.maxHeight = value
-        ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
-    end)
-    container.maxHeight:SetPoint('TOPLEFT', container.spacing, 'TOPRIGHT', 15, 0)
-
     local closeBtn = CreateCheckBox("Close Button visible", container, ADDON.settings.categoryContainer.closeVisible, function(value)
         ADDON.settings.categoryContainer.closeVisible = value
         ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
     end)
-    closeBtn:SetPoint('TOPLEFT', container.padding, 'BOTTOMLEFT', -10, -15)
+    closeBtn:SetPoint('LEFT', container.spacing, 'RIGHT', 15, 0)

-    container:SetHeight(100)
+    container:SetHeight(65)
     self:AddSettingsPanel(container)
 end

@@ -353,7 +344,7 @@ function settings:CreateMainBarSettings()
     end)
     container.currencyFontSize:SetPoint('TOPLEFT', container.slotFontColor, 'TOPRIGHT', 15, 0)

-    container.slotFontSize = CreateSlider('Currency font size', container, 8, 18, function()
+    container.slotFontSize = CreateSlider('Slots font size', container, 8, 18, function()
         return ADDON.settings.mainBar.slotsFontSize
     end, function(value)
         ADDON.settings.mainBar.slotsFontSize = value
@@ -452,4 +443,87 @@ function settings:CreateAutoSettings()

     container:SetHeight(55)
     self:AddSettingsPanel(container)
+end
+
+function settings:CreateFormatterSettings()
+    local container = ADDON.container('DJBagsSettingsFormatter', nil)
+
+    CreateTitle('Format settings', container)
+
+    container.dropDown = CreateFrame("Button", "DJBagsCategoryDialogDropDown", container, "UIDropDownMenuTemplate")
+    container.dropDown:SetPoint('TOPLEFT', container, 5, -20)
+    UIDropDownMenu_SetWidth(container.dropDown, 100);
+    UIDropDownMenu_SetButtonWidth(container.dropDown, 124)
+    UIDropDownMenu_JustifyText(container.dropDown, "LEFT")
+
+    UIDropDownMenu_Initialize(container.dropDown, function(self, level)
+        local info
+        for k, _ in pairs(ADDON.formatters) do
+            info = UIDropDownMenu_CreateInfo()
+            info.text = k
+            info.value = k
+            info.func = function(self)
+                UIDropDownMenu_SetSelectedID(container.dropDown, self:GetID())
+                ADDON.settings.categoryContainer.formatter = tostring(self.value)
+                if self.value == 'vertical' then
+                    container.vertical:Show()
+                    container.horizontal:Hide()
+                else
+                    container.vertical:Hide()
+                    container.horizontal:Show()
+                end
+                ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
+            end
+            UIDropDownMenu_AddButton(info, level)
+        end
+    end)
+
+    UIDropDownMenu_SetSelectedValue(container.dropDown, ADDON.settings.categoryContainer.formatter)
+
+    container.vertical = CreateFrame('FRAME', 'DJBagsSettingsFormatterVert', container)
+    container.vertical:SetPoint('TOPLEFT', 0, -50)
+    container.vertical:SetPoint('TOPRIGHT', 0, -50)
+    container.vertical:SetPoint('BOTTOMLEFT')
+    container.vertical:SetPoint('BOTTOMRIGHT')
+
+    container.colsVertical = CreateSlider('Columns', container.vertical, 4, 12, function()
+        return ADDON.settings.formatter.vertical.cols
+    end, function(value)
+        ADDON.settings.formatter.vertical.cols = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
+    end)
+    container.colsVertical:SetPoint('TOPLEFT', 10, -20)
+
+    container.maxHeight = CreateSlider('Max Height', container.vertical, 20, 100, function()
+        return ADDON.settings.formatter.vertical.maxHeight
+    end, function(value)
+        ADDON.settings.formatter.vertical.maxHeight = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
+    end)
+    container.maxHeight:SetPoint('TOPLEFT', container.colsVertical, 'TOPRIGHT', 15, 0)
+
+    container.horizontal = CreateFrame('FRAME', 'DJBagsSettingsFormatterHoz', container)
+    container.horizontal:SetPoint('TOPLEFT', 0, -50)
+    container.horizontal:SetPoint('TOPRIGHT', 0, -50)
+    container.horizontal:SetPoint('BOTTOMLEFT')
+    container.horizontal:SetPoint('BOTTOMRIGHT')
+
+    container.colsHorizontal = CreateSlider('Columns', container.horizontal, 4, 16, function()
+        return ADDON.settings.formatter.horizontal.cols
+    end, function(value)
+        ADDON.settings.formatter.horizontal.cols = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE', true)
+    end)
+    container.colsHorizontal:SetPoint('TOPLEFT', 10, -20)
+
+    if ADDON.settings.categoryContainer.formatter == 'vertical' then
+        container.vertical:Show()
+        container.horizontal:Hide()
+    else
+        container.vertical:Hide()
+        container.horizontal:Show()
+    end
+
+    container:SetHeight(100)
+    self:AddSettingsPanel(container)
 end
\ No newline at end of file
diff --git a/src/lua/settings/settings.lua b/src/lua/settings/settings.lua
index ebe57aa..385908c 100644
--- a/src/lua/settings/settings.lua
+++ b/src/lua/settings/settings.lua
@@ -50,7 +50,7 @@ end

 function settings:MigrateSettings(table, default)
     for k, v in pairs(default) do
-        if table[k] then
+        if table[k] ~= nil then
             if type(v) ~= type(table[k]) then
                 table[k] = v
             elseif type(v) == 'table' then
diff --git a/src/lua/sorters/containers.lua b/src/lua/sorters/containers.lua
index 3681f47..621fe89 100644
--- a/src/lua/sorters/containers.lua
+++ b/src/lua/sorters/containers.lua
@@ -3,13 +3,38 @@ local NAME, ADDON = ...
 ADDON.sorters = ADDON.sorters or {}

 ADDON.sorters.containers = {
-    ['default'] = function(A, B)
+    ['defaultVertical'] = function(A, B)
         if A.name == EMPTY then
             return true
         elseif B.name == EMPTY then
             return false
+        elseif A.name == NEW then
+            return false
+        elseif B.name == NEW then
+            return true
+        elseif A.name == BAG_FILTER_JUNK then
+            return false
+        elseif B.name == BAG_FILTER_JUNK then
+            return true
         else
             return A.name > B.name
         end
     end,
+    ['defaultHorizontal'] = function(A, B)
+        if A.name == EMPTY then
+            return false
+        elseif B.name == EMPTY then
+            return true
+        elseif A.name == NEW then
+            return true
+        elseif B.name == NEW then
+            return false
+        elseif A.name == BAG_FILTER_JUNK then
+            return true
+        elseif B.name == BAG_FILTER_JUNK then
+            return false
+        else
+            return A.name < B.name
+        end
+    end,
 }
\ No newline at end of file
diff --git a/src/lua/utils/utils.lua b/src/lua/utils/utils.lua
index 3ca6b57..b3458d1 100644
--- a/src/lua/utils/utils.lua
+++ b/src/lua/utils/utils.lua
@@ -59,7 +59,7 @@ function utils:GetItemContainerName(bag, slot)

         local subClassSplitList = ADDON.settings.categories.subClass
         if subClassSplitList[cId] then
-            return className .. ' ' .. subClassName
+            return className .. (subClassName == BAG_FILTER_JUNK and '' or '_' .. subClassName)
         end

         return className
@@ -67,7 +67,7 @@ function utils:GetItemContainerName(bag, slot)
     return EMPTY
 end

-function utils:UpdateItemsForBag(frame, bag, arrangeList, containerFunc)
+function utils:UpdateItemsForBag(frame, bag, containerFunc)
     local count = GetContainerNumSlots(bag)
     if count == 0 and ADDON.cache.items[bag] then
         for _, item in pairs(ADDON.cache.items[bag]) do
@@ -75,7 +75,6 @@ function utils:UpdateItemsForBag(frame, bag, arrangeList, containerFunc)
                 local previousContainer = item:GetParent()
                 previousContainer:RemoveItem(item)
                 item:SetParent(nil)
-                arrangeList[previousContainer] = true
                 item:Hide()
             end
         end
@@ -91,15 +90,27 @@ function utils:UpdateItemsForBag(frame, bag, arrangeList, containerFunc)

             local newContainer = containerFunc(ADDON.cache, ADDON.utils:GetItemContainerName(bag, slot))
             frame:AddContainer(newContainer)
-            arrangeList[newContainer] = true

             if previousContainer ~= newContainer then
                 if previousContainer then
                     previousContainer:RemoveItem(item)
-                    arrangeList[previousContainer] = true
                 end
                 newContainer:AddItem(item)
             end
         end
     end
+end
+
+function utils:PrintTable(tbl, lvl)
+    local prefix = ''
+    lvl = lvl or 0
+    for _ = 1, lvl do
+        prefix = prefix .. '\t'
+    end
+    for k, v in pairs(tbl) do
+        print(prefix, k, v)
+        if (type(v) == 'table') then
+            printTable(v, lvl + 1)
+        end
+    end
 end
\ No newline at end of file
diff --git a/src/manifest.xml b/src/manifest.xml
index 208f409..050d7eb 100644
--- a/src/manifest.xml
+++ b/src/manifest.xml
@@ -17,6 +17,7 @@
     <Script file="src/lua/settings/defaults/mainBar.lua"/>
     <Script file="src/lua/settings/defaults/bagItem.lua"/>
     <Script file="src/lua/settings/defaults/auto.lua"/>
+    <Script file="src/lua/settings/defaults/formatter.lua"/>
     <Script file="src/lua/settings/editor.lua"/>
     <Script file="src/lua/settings/settings.lua"/>

@@ -24,6 +25,10 @@
     <Script file="src/lua/sorters/items.lua"/>
     <Script file="src/lua/sorters/containers.lua"/>

+    <!-- formatters -->
+    <Script file="src/lua/formatters/vertical.lua"/>
+    <Script file="src/lua/formatters/horizontal.lua"/>
+
     <!-- Tools -->
     <Script file="src/lua/event/eventManager.lua"/>