Quantcast

Add bank and reagents

Brandon Talbot [07-23-16 - 16:03]
Add bank and reagents
Filename
src/lua/constants/contstants.lua
src/lua/controller/bag.lua
src/lua/controller/bank.lua
src/lua/core.lua
src/lua/element/bagItem.lua
src/lua/element/bankBar.lua
src/lua/element/container.lua
src/lua/element/item.lua
src/lua/element/itemContainer.lua
src/lua/element/mainBar.lua
src/lua/settings/settingsController.lua
src/lua/settings/settingsElements.lua
src/lua/tools/itemFormatter.lua
src/manifest.xml
src/xml/element/bankBar.xml
src/xml/element/mainBar.xml
src/xml/settings/bankBarSettings.xml
src/xml/settings/settingsContainer.xml
src/xml/settings/subClassSettings.xml
src/xml/settings/toggleSettings.xml
diff --git a/src/lua/constants/contstants.lua b/src/lua/constants/contstants.lua
index 10de4d9..d2218a7 100644
--- a/src/lua/constants/contstants.lua
+++ b/src/lua/constants/contstants.lua
@@ -5,6 +5,9 @@ local NAME, ADDON = ...
 DJBags_TYPE_CONTAINER = 'container'
 DJBags_TYPE_ITEM_CONTAINER = 'itemContainer'
 DJBags_TYPE_SUB_CLASS = 'djbags_sub_classes'
+DJBags_TYPE_MAIN = 'djbags_main_settings'
+DJBags_TYPE_MAIN_BAR = 'djbags_main_bar'
+DJBags_TYPE_BANK_BAR = 'djbags_bank_bar'

 DJBags_FORMATTER_MASONRY = 'Massonry'
 DJBags_FORMATTER_BOX = 'Box'
@@ -26,6 +29,9 @@ DJBags_SETTING_FORMATTER_MAX_HEIGHT = 'djbags_formatter_max_height'
 DJBags_SETTING_FORMATTER_BOX_COLS = 'djbags_formatter_box_cols'
 DJBags_SETTING_TRUNCATE_SUB_CLASS = 'djbags_truncate_sub_class'
 DJBags_SETTING_TEXT_SIZE = 'djbags_truncate_text_size'
+DJBags_SETTING_STACK_ALL = 'djbags_stack_all_items'
+DJBags_SETTING_SELL_JUNK = 'djbags_auto_sell_junk'
+DJBags_SETTING_DEPOSIT_REAGENT = 'djbags_auto_deposit_reagents'

 --endregion

@@ -45,6 +51,9 @@ localeText['enUS'] = function()
     DJBags_LOCALE_SPACING = 'Spacing'
     DJBags_LOCALE_SCALE = 'Scale'
     DJBags_LOCALE_TEXT_SIZE = 'Text size'
+    DJBags_LOCALE_STACK_ALL = 'Stack all items'
+    DJBags_LOCALE_SELL_JUNK = 'Auto sell junk'
+    DJBags_LOCALE_DEPOSIT_REAGENT = 'Auto deposit reagents'
     DJBags_LOCALE_MASONRY = 'Massonry'
     DJBags_LOCALE_BOX = 'Box'
 end
diff --git a/src/lua/controller/bag.lua b/src/lua/controller/bag.lua
index e904af1..1c9f704 100644
--- a/src/lua/controller/bag.lua
+++ b/src/lua/controller/bag.lua
@@ -10,6 +10,7 @@ function controller:Init()
 end

 function DJBagsBagContainer_OnShow()
+    DJBagsBagContainer.mainBar:Show()
     ADDON.events:Add('INVENTORY_SEARCH_UPDATE', controller)
     ADDON.events:Add('BAG_UPDATE', controller)
     ADDON.events:Add('BAG_UPDATE_COOLDOWN', controller)
@@ -63,19 +64,21 @@ function controller:BAG_UPDATE(bag)
 end

 function controller:MERCHANT_SHOW()
-    local price = 0
-    for bag = 0, NUM_BAG_SLOTS do
-        for slot = 1 , GetContainerNumSlots(bag) do
-            if select(4, GetContainerItemInfo(bag, slot)) == LE_ITEM_QUALITY_POOR then
-                ShowMerchantSellCursor(1)
-                UseContainerItem(bag, slot)
-                price = price + select(11, GetItemInfo(GetContainerItemID(bag, slot)))
+    if ADDON.settings:GetSettings(DJBags_TYPE_MAIN)[DJBags_SETTING_SELL_JUNK] then
+        local price = 0
+        for bag = 0, NUM_BAG_SLOTS do
+            for slot = 1 , GetContainerNumSlots(bag) do
+                if select(4, GetContainerItemInfo(bag, slot)) == LE_ITEM_QUALITY_POOR then
+                    ShowMerchantSellCursor(1)
+                    UseContainerItem(bag, slot)
+                    price = price + select(11, GetItemInfo(GetContainerItemID(bag, slot)))
+                end
             end
         end
-    end
-    ResetCursor()
-    if price ~= 0 then
-        DEFAULT_CHAT_FRAME:AddMessage("Sold junk for: " .. GetCoinTextureString(price))
+        ResetCursor()
+        if price ~= 0 then
+            DEFAULT_CHAT_FRAME:AddMessage("Sold junk for: " .. GetCoinTextureString(price))
+        end
     end
 end

diff --git a/src/lua/controller/bank.lua b/src/lua/controller/bank.lua
index 5825d60..c441873 100644
--- a/src/lua/controller/bank.lua
+++ b/src/lua/controller/bank.lua
@@ -1,8 +1,159 @@
---
--- Created by IntelliJ IDEA.
--- User: bjtal
--- Date: 2016/07/17
--- Time: 8:38 AM
--- To change this template use File | Settings | File Templates.
---
+local NAME, ADDON = ...

+ADDON.bankController = {}
+ADDON.bankController.__index = ADDON.bankController
+
+local controller = ADDON.bankController
+
+
+function controller:Init()
+    ADDON.events:Add('BANKFRAME_OPENED', self)
+    ADDON.events:Add('BANKFRAME_CLOSED', self)
+end
+
+function DJBagsBankBar_OnShow(self)
+    PanelTemplates_SetTab(self, 1)
+    DJBagsBankContainer:Show()
+    DJBagsReagentContainer:Hide()
+    self:Update()
+    controller:Register()
+    controller:Update()
+end
+
+function DJBagsBankBar_OnHide(self)
+    controller:UnRegister()
+end
+
+function DJBagsBankTab_OnClick(tab)
+    PlaySound("igMainMenuOpen")
+    PanelTemplates_SetTab(DJBagsBankBar, tab.tab)
+    if tab.tab == 1 then
+        DJBagsBankContainer:Show()
+        DJBagsReagentContainer:Hide()
+    else
+        DJBagsBankContainer:Hide()
+        DJBagsReagentContainer:Show()
+    end
+end
+
+function controller:Update()
+    ADDON:UpdateBags({-1, 5, 6, 7, 8, 9, 10, 11, -3})
+    DJBagsBankContainer:Arrange()
+    self:ArrangeReagents()
+end
+
+function controller:ArrangeReagents()
+    if IsReagentBankUnlocked() then
+        DJBagsReagentContainer.reagentButton:Hide()
+        DJBagsReagentContainer:Arrange()
+    else
+        DJBagsReagentContainer:SetSize(110, 35)
+        DJBagsReagentContainer.reagentButton:Show()
+    end
+end
+
+function controller:BANKFRAME_OPENED()
+    DJBagsBankBar:Show()
+end
+
+function controller:BANKFRAME_CLOSED()
+    DJBagsBankBar:Hide()
+end
+
+function controller:Register()
+    ADDON.events:Add('PLAYERBANKSLOTS_CHANGED', self)
+    ADDON.events:Add('BAG_UPDATE', self)
+    ADDON.events:Add('INVENTORY_SEARCH_UPDATE', self)
+    ADDON.events:Add('BAG_UPDATE_COOLDOWN', self)
+    ADDON.events:Add('ITEM_LOCK_CHANGED', self)
+    ADDON.events:Add('PLAYERREAGENTBANKSLOTS_CHANGED', self)
+    ADDON.events:Add('PLAYERBANKBAGSLOTS_CHANGED', self)
+    ADDON.events:Add('REAGENTBANK_PURCHASED', self)
+    ADDON.events:Add('BAG_UPDATE_DELAYED', self)
+end
+
+function controller:UnRegister()
+    ADDON.events:Remove('PLAYERBANKSLOTS_CHANGED', self)
+    ADDON.events:Remove('BAG_UPDATE', self)
+    ADDON.events:Remove('INVENTORY_SEARCH_UPDATE', self)
+    ADDON.events:Remove('BAG_UPDATE_COOLDOWN', self)
+    ADDON.events:Remove('ITEM_LOCK_CHANGED', self)
+    ADDON.events:Remove('PLAYERREAGENTBANKSLOTS_CHANGED', self)
+    ADDON.events:Remove('PLAYERBANKBAGSLOTS_CHANGED', self)
+    ADDON.events:Remove('REAGENTBANK_PURCHASED', self)
+    ADDON.events:Remove('BAG_UPDATE_DELAYED', self)
+end
+
+function controller:PLAYERBANKSLOTS_CHANGED()
+    ADDON:UpdateBags({BANK_CONTAINER})
+    DJBagsBankContainer:Arrange()
+end
+
+function controller:BAG_UPDATE(bag)
+    if bag > NUM_BAG_SLOTS then
+        ADDON:UpdateBags({bag})
+    end
+end
+
+function controller:INVENTORY_SEARCH_UPDATE()
+    local function updateSearch(bag)
+        for slot = 1, GetContainerNumSlots(bag) do
+            ADDON.cache:GetItem(bag, slot):UpdateSearch()
+        end
+    end
+
+    updateSearch(-3)
+    updateSearch(-1)
+    updateSearch(5)
+    updateSearch(6)
+    updateSearch(7)
+    updateSearch(8)
+    updateSearch(9)
+    updateSearch(10)
+    updateSearch(11)
+end
+
+function controller:BAG_UPDATE_COOLDOWN()
+    local function updateCooldown(bag)
+        for slot = 1, GetContainerNumSlots(bag) do
+            ADDON.cache:GetItem(bag, slot):UpdateCooldown()
+        end
+    end
+
+    updateCooldown(-3)
+    updateCooldown(-1)
+    updateCooldown(5)
+    updateCooldown(6)
+    updateCooldown(7)
+    updateCooldown(8)
+    updateCooldown(9)
+    updateCooldown(10)
+    updateCooldown(11)
+end
+
+function controller:ITEM_LOCK_CHANGED(bag, slot)
+    if bag ~= BANK_CONTAINER and bag ~= REAGENTBANK_CONTAINER and bag <= NUM_BAG_SLOTS then return end
+
+    if bag == BANK_CONTAINER and slot > NUM_BANKGENERIC_SLOTS then
+        _G[DJBagsBankBar:GetName() .. 'Bag' .. (slot-NUM_BANKGENERIC_SLOTS)]:UpdateLock()
+    elseif slot then
+        ADDON.cache:GetItem(bag, slot):UpdateLock()
+    end
+end
+
+function controller:PLAYERREAGENTBANKSLOTS_CHANGED()
+    ADDON:UpdateBags({REAGENTBANK_CONTAINER})
+    self:ArrangeReagents()
+end
+
+function controller:PLAYERBANKBAGSLOTS_CHANGED()
+    DJBagsBankBar:Update()
+end
+
+function controller:REAGENTBANK_PURCHASED()
+    self:PLAYERREAGENTBANKSLOTS_CHANGED()
+end
+
+function controller:BAG_UPDATE_DELAYED()
+    DJBagsBankBar:Update()
+end
\ No newline at end of file
diff --git a/src/lua/core.lua b/src/lua/core.lua
index 02dc9c6..8d8f39f 100644
--- a/src/lua/core.lua
+++ b/src/lua/core.lua
@@ -7,6 +7,7 @@ function core:ADDON_LOADED(name)

     ADDON.settings:Init()
     ADDON.bagController:Init()
+    ADDON.bankController:Init()

     ADDON.events:Remove('ADDON_LOADED', self)
 end
@@ -49,7 +50,7 @@ end

 SLASH_DJBAGS1 = '/djb';
 function SlashCmdList.DJBAGS(msg, editbox)
-    ADDON.bagController:Open()
+    DJBagsBankBar:Show()
 end

 SLASH_RL1 = '/rl';
diff --git a/src/lua/element/bagItem.lua b/src/lua/element/bagItem.lua
index 4bb2445..85063be 100644
--- a/src/lua/element/bagItem.lua
+++ b/src/lua/element/bagItem.lua
@@ -10,13 +10,24 @@ function ADDON:NewBagItem(name, slot, id)
     return frame
 end

+function DJBagsBagItemLoad(button, slot, id)
+    ADDON:CreateAddon(button, item, id, slot)
+end
+
 function item:Init(id, slot)
     self:SetID(id)
     self.slot = slot

     self:SetScript('OnDragStart', self.DragItem)
     self:SetScript('OnReceiveDrag', self.PlaceOrPickup)
-    self:SetScript('OnClick', self.PlaceOrPickup)
+    self:SetScript('OnClick', function (self, ...)
+        if self.buy then
+            PlaySound("igMainMenuOption");
+            StaticPopup_Show("CONFIRM_BUY_BANK_SLOT");
+        else
+            self:PlaceOrPickup(...)
+        end
+    end)
     self:SetScript('OnEnter', self.OnEnter)
     self:SetScript('OnLeave', self.OnLeave)
 end
@@ -72,6 +83,16 @@ function item:OnEnter()
     ADDON.events:Fire('DJBAGS_BAG_HOVER', self.slot, true)
 end

+function item:SetCost(cost)
+    if cost > -1 then
+        self.IconBorder:Show()
+        self.IconBorder:SetVertexColor(1, 0, 0, 1)
+        self.Count:Show()
+        self.Count:SetText(cost)
+        self.buy = true
+    end
+end
+
 function item:OnLeave()
     GameTooltip_Hide();
     ResetCursor();
diff --git a/src/lua/element/bankBar.lua b/src/lua/element/bankBar.lua
new file mode 100644
index 0000000..d279fd0
--- /dev/null
+++ b/src/lua/element/bankBar.lua
@@ -0,0 +1,41 @@
+local NAME, ADDON = ...
+
+local container = {}
+
+function DJBagsBankBarLoad(self)
+    ADDON:CreateAddon(self, container)
+end
+
+function container:Init()
+    self.__type = DJBags_TYPE_BANK_BAR
+
+    table.insert(UISpecialFrames, self:GetName())
+    self:RegisterForDrag("LeftButton")
+    self:SetScript("OnDragStart", self.StartMoving)
+    self:SetScript("OnDragStop", self.StopMovingOrSizing)
+
+    self:SetColors(
+        {0, 0, 0, 0.6},
+        {0.3, 0.3, 0.3, 1}
+    )
+end
+
+function container:Update()
+    for i = 1, 7 do
+        _G[self:GetName() .. 'Bag' .. i]:Update()
+    end
+end
+
+function container:UpdateFromSettings()
+    local settings = ADDON.settings:GetSettings(self.__type)
+
+    self:SetColors(
+        settings[DJBags_SETTING_BACKGROUND_COLOR],
+        settings[DJBags_SETTING_BORDER_COLOR]
+    )
+end
+
+function container:SetColors(background, border)
+    self:SetBackdropColor(unpack(background))
+    self:SetBackdropBorderColor(unpack(border))
+end
diff --git a/src/lua/element/container.lua b/src/lua/element/container.lua
index 62e421f..01ed7b0 100644
--- a/src/lua/element/container.lua
+++ b/src/lua/element/container.lua
@@ -12,9 +12,23 @@ function container:Init()

     table.insert(UISpecialFrames, self:GetName())
     self:RegisterForDrag("LeftButton")
-    self:SetScript("OnDragStart", self.StartMoving)
-    self:SetScript("OnDragStop", self.StopMovingOrSizing)
-    self:SetUserPlaced(true)
+    self:SetScript("OnDragStart", function(self, ...)
+        if self:GetParent() == UIParent then
+            self:StartMoving()
+        elseif self:GetParent():IsMovable() then
+            self:GetParent():StartMoving(...)
+        end
+    end)
+    self:SetScript("OnDragStop", function(self, ...)
+        if self:GetParent() == UIParent then
+            self:StopMovingOrSizing(...)
+        elseif self:GetParent():IsMovable() then
+            self:GetParent():StopMovingOrSizing(...)
+        end
+    end)
+    if self:GetParent() == UIParent then
+        self:SetUserPlaced(true)
+    end

     self:SetColors(
         {0, 0, 0, 0.6},
@@ -36,7 +50,6 @@ function container:UpdateFromSettings()
     )
     self:SetPadding(settings[DJBags_SETTING_PADDING])
     self:SetSpacing(settings[DJBags_SETTING_SPACING])
-    self:SetScale(settings[DJBags_SETTING_SCALE])
 end

 function container:SetPadding(padding)
diff --git a/src/lua/element/item.lua b/src/lua/element/item.lua
index 4d2b0f5..18fc737 100644
--- a/src/lua/element/item.lua
+++ b/src/lua/element/item.lua
@@ -176,6 +176,7 @@ function item:Update()
     self.classId = classId
     self.class = class
     self.subClass = subClass
+    self.count = count or 1
     self.button.hasItem = nil

     if isEquipment then
diff --git a/src/lua/element/itemContainer.lua b/src/lua/element/itemContainer.lua
index a4b2fec..8b422ae 100644
--- a/src/lua/element/itemContainer.lua
+++ b/src/lua/element/itemContainer.lua
@@ -14,8 +14,6 @@ end
 function container:Init(name)
     self.__type = DJBags_TYPE_ITEM_CONTAINER

-    self:SetMovable(false)
-
     if string.match(name, '%a*_%a*') then
         local txt = string.match(name, '%a*_(%a*)')
         self.name:SetText(txt)
@@ -27,6 +25,7 @@ function container:Init(name)
     self.items = {}

     self:UpdateFromSettings()
+    self.container:EnableMouse(false)
 end

 function container:UpdateFromSettings()
diff --git a/src/lua/element/mainBar.lua b/src/lua/element/mainBar.lua
new file mode 100644
index 0000000..f2ec1a1
--- /dev/null
+++ b/src/lua/element/mainBar.lua
@@ -0,0 +1,40 @@
+local NAME, ADDON = ...
+
+local container = {}
+
+function DJBagsMainBarLoad(self)
+    ADDON:CreateAddon(self, container)
+end
+
+function container:Init()
+    self.__type = DJBags_TYPE_MAIN_BAR
+
+    table.insert(UISpecialFrames, self:GetName())
+    self:RegisterForDrag("LeftButton")
+    self:SetScript("OnDragStart", function(self)
+        self:GetParent():StartMoving()
+    end)
+    self:SetScript("OnDragStop", function(self)
+        self:GetParent():StopMovingOrSizing()
+    end)
+
+    self:SetColors(
+        {0, 0, 0, 0.6},
+        {0.3, 0.3, 0.3, 1}
+    )
+    self:Show()
+end
+
+function container:UpdateFromSettings()
+    local settings = ADDON.settings:GetSettings(self.__type)
+
+    self:SetColors(
+        settings[DJBags_SETTING_BACKGROUND_COLOR],
+        settings[DJBags_SETTING_BORDER_COLOR]
+    )
+end
+
+function container:SetColors(background, border)
+    self:SetBackdropColor(unpack(background))
+    self:SetBackdropBorderColor(unpack(border))
+end
diff --git a/src/lua/settings/settingsController.lua b/src/lua/settings/settingsController.lua
index 9e8a57a..ffb3cbf 100644
--- a/src/lua/settings/settingsController.lua
+++ b/src/lua/settings/settingsController.lua
@@ -30,12 +30,17 @@ function settings:Init()
     DJBags_DB.global.userDefined = DJBags_DB.global.userDefined or {}

     self.default = {
+        [DJBags_TYPE_MAIN] = {
+            [DJBags_SETTING_STACK_ALL] = false,
+            [DJBags_SETTING_SELL_JUNK] = false,
+            [DJBags_SETTING_DEPOSIT_REAGENT] = false,
+            [DJBags_SETTING_SCALE] = 1,
+        },
         [DJBags_TYPE_CONTAINER] = {
             [DJBags_SETTING_BACKGROUND_COLOR] = {0, 0, 0, 0.6},
             [DJBags_SETTING_BORDER_COLOR] = {0.3, 0.3, 0.3, 1},
             [DJBags_SETTING_PADDING] = 5,
             [DJBags_SETTING_SPACING] = 5,
-            [DJBags_SETTING_SCALE] = 1,
             [DJBags_SETTING_FORMATTER] = DJBags_FORMATTER_MASONRY,
             [DJBags_SETTING_FORMATTER_VERT] = false,
             [DJBags_SETTING_FORMATTER_MAX_ITEMS] = 12,
@@ -62,6 +67,14 @@ function settings:Init()
             [LE_ITEM_CLASS_TRADEGOODS] = true,
             [LE_ITEM_CLASS_WEAPON] = false,
         },
+        [DJBags_TYPE_MAIN_BAR] = {
+            [DJBags_SETTING_BACKGROUND_COLOR] = {0, 0, 0, 0.6},
+            [DJBags_SETTING_BORDER_COLOR] = {0.3, 0.3, 0.3, 1},
+        },
+        [DJBags_TYPE_BANK_BAR] = {
+            [DJBags_SETTING_BACKGROUND_COLOR] = {0, 0, 0, 0.6},
+            [DJBags_SETTING_BORDER_COLOR] = {0.3, 0.3, 0.3, 1},
+        }
     }

     self:Update()
@@ -69,6 +82,14 @@ end

 function settings:Update(force)
     self:UpdateBag(DJBagsBagContainer, ADDON.bagController, ADDON.cache.bagContainers, force)
+    self:UpdateBag(DJBagsBankContainer, ADDON.bankController, ADDON.cache.bankContainers, force)
+    self:UpdateBag(DJBagsReagentContainer, ADDON.bankController, ADDON.cache.reagentContainers, force)
+    self:UpdateBar(DJBagsBagContainer.mainBar)
+    self:UpdateBar(DJBagsBankBar)
+end
+
+function settings:UpdateBar(bar)
+    bar:UpdateFromSettings()
 end

 function settings:UpdateBag(bag, controller, list, force)
diff --git a/src/lua/settings/settingsElements.lua b/src/lua/settings/settingsElements.lua
index 250b074..fb80662 100644
--- a/src/lua/settings/settingsElements.lua
+++ b/src/lua/settings/settingsElements.lua
@@ -57,9 +57,10 @@ function DJBagsSettingsColorPicker_OnClick(self)
     ShowUIPanel(ColorPickerFrame)
 end

-function DJBagsInitSettingsCheckBox(checkbox, name, type, setting)
+function DJBagsInitSettingsCheckBox(checkbox, name, type, setting, arrangeType)
     checkbox.type = type
     checkbox.setting = setting
+    checkbox.arrangeType = arrangeType

     _G[checkbox:GetName() .. "Text"]:SetText(name)

@@ -67,5 +68,5 @@ function DJBagsInitSettingsCheckBox(checkbox, name, type, setting)
 end

 function DJBagsSettingsCheckBox_OnChange(checkbox, checked)
-    ADDON.settings:SetSettings(checkbox.type, checkbox.setting, checked, 2)
+    ADDON.settings:SetSettings(checkbox.type, checkbox.setting, checked, checkbox.arrangeType)
 end
\ No newline at end of file
diff --git a/src/lua/tools/itemFormatter.lua b/src/lua/tools/itemFormatter.lua
index fced31f..822e154 100644
--- a/src/lua/tools/itemFormatter.lua
+++ b/src/lua/tools/itemFormatter.lua
@@ -3,7 +3,10 @@ local NAME, ADDON = ...
 local itemSorter = function (A, B)
     if A.quality == B.quality then
         if A.ilevel == B.ilevel then
-            return A.name < B.name
+            if A.name == B.name then
+                return A.count > B.count
+            end
+            return A.name < B.name
         end
         return A.ilevel > B.ilevel
     end
@@ -20,10 +23,30 @@ end
 function ADDON:ArrangeItemContainer(frame, max, vert, maxCnt)
     if frame:IsEmpty() or alreadySorted(frame, max, vert) then return end

-    local itemCount = maxCnt or frame:GetCount()
+    local itemCount = 0
     local cnt = 0

+    local items = {}
     for item in ADDON:PairsByKey(frame.items, itemSorter) do
+        tinsert(items, item)
+    end
+
+    local index = 1
+    while (index <= #items) do
+        local item = items[index]
+        local nItem = items[index + 1]
+        local totalCnt = 0
+        local mustStackAll = ADDON.settings:GetSettings(DJBags_TYPE_MAIN)[DJBags_SETTING_STACK_ALL]
+        while mustStackAll and nItem and nItem.id == item.id do
+            totalCnt = totalCnt + nItem.count
+            index = index + 1
+            nItem:Hide()
+            nItem = items[index+1]
+        end
+        if totalCnt > 0 then
+            item:SetItemCount(item.count + totalCnt)
+        end
+
         if maxCnt and cnt >= maxCnt then
             item:Hide()
         else
@@ -40,11 +63,13 @@ function ADDON:ArrangeItemContainer(frame, max, vert, maxCnt)
             if maxCnt and cnt == maxCnt then
                 item:SetItemCount(frame:GetCount() - cnt + 1)
             end
+            itemCount = itemCount + 1
         end
+        index = index + 1
     end

     local colSize = math.ceil(itemCount / max) * (next(frame.items):GetWidth() + frame.spacing) - frame.spacing
-    local rowSize = max * (frame.spacing + next(frame.items):GetWidth()) - frame.spacing
+    local rowSize = (maxCnt and maxCnt or (itemCount < max and itemCount or max)) * (frame.spacing + next(frame.items):GetWidth()) - frame.spacing

     frame:SetSize(
         (vert and colSize or rowSize) + frame.padding * 2,
diff --git a/src/manifest.xml b/src/manifest.xml
index 5996652..2e49aa6 100644
--- a/src/manifest.xml
+++ b/src/manifest.xml
@@ -9,20 +9,19 @@
     <!-- Events -->
     <Script file="src/lua/events/events.lua" />

-    <!-- Element XML-->
+    <!-- Elements-->
     <Include file="src/xml/element/tooltip.xml" />
-    <Include file="src/xml/element/mainBar.xml" />
-    <Include file="src/xml/element/itemContainer.xml" />
-
-    <!-- Element Script -->
     <Script file="src/lua/element/tooltip.lua" />
+    <Script file="src/lua/element/bagItem.lua" />
     <Script file="src/lua/element/item.lua" />
+    <Include file="src/xml/element/itemContainer.xml" />
     <Script file="src/lua/element/itemContainer.lua" />
-    <Script file="src/lua/element/bagItem.lua" />
-
-    <!-- Container special load -->
+    <Script file="src/lua/element/mainBar.lua" />
+    <Include file="src/xml/element/mainBar.xml" />
     <Script file="src/lua/element/container.lua" />
     <Include file="src/xml/element/container.xml" />
+    <Script file="src/lua/element/bankBar.lua" />
+    <Include file="src/xml/element/bankBar.xml" />

     <!-- Formatters -->
     <Script file="src/lua/tools/itemFormatter.lua" />
@@ -31,6 +30,7 @@

     <!-- Controller -->
     <Script file="src/lua/controller/bag.lua" />
+    <Script file="src/lua/controller/bank.lua" />

     <!-- Settings -->
     <Script file="src/lua/settings/settingsController.lua" />
@@ -41,6 +41,7 @@
     <Include file="src/xml/settings/itemContainerSettings.xml" />
     <Include file="src/xml/settings/containerSettings.xml" />
     <Include file="src/xml/settings/subClassSettings.xml" />
+    <Include file="src/xml/settings/toggleSettings.xml" />
     <Include file="src/xml/settings/settingsContainer.xml" />

     <!-- Core (Load last) -->
diff --git a/src/xml/element/bankBar.xml b/src/xml/element/bankBar.xml
index 5031a52..b1c359b 100644
--- a/src/xml/element/bankBar.xml
+++ b/src/xml/element/bankBar.xml
@@ -1,3 +1,157 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
+    <Frame name="DJBagsBankBar" parent="UIParent" movable="true" enableMouse="true" hidden="true">
+        <Size x="299" y="77" />
+        <Anchors>
+            <Anchor point="TOPLEFT" x="150" y="-100" />
+        </Anchors>
+        <Backdrop bgFile="Interface\ChatFrame\ChatFrameBackground" edgeFile="Interface\Buttons\WHITE8x8">
+            <EdgeSize>
+                <AbsValue val="1" />
+            </EdgeSize>
+        </Backdrop>
+        <Frames>
+            <Button name="$parentBag1" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" x="5" y="-5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 1, BankButtonIDToInvSlotID(1, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag2" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag1" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 2, BankButtonIDToInvSlotID(2, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag3" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag2" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 3, BankButtonIDToInvSlotID(3, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag4" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag3" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 4, BankButtonIDToInvSlotID(4, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag5" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag4" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 5, BankButtonIDToInvSlotID(5, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag6" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag5" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 6, BankButtonIDToInvSlotID(6, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <Button name="$parentBag7" inherits="ItemButtonTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag6" relativePoint="TOPRIGHT" x="5" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        DJBagsBagItemLoad(self, NUM_BAG_SLOTS + 7, BankButtonIDToInvSlotID(7, 1))
+                    </OnLoad>
+                </Scripts>
+            </Button>
+            <EditBox name="$parentSearchBar" inherits="BagSearchBoxTemplate">
+                <Size y="25" />
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentBag1" relativePoint="BOTTOMLEFT" x="5" y="-5"/>
+                    <Anchor point="TOPRIGHT" relativeTo="$parentBag7" relativePoint="BOTTOMRIGHT" y="-5" />
+                </Anchors>
+            </EditBox>
+            <Button name="$parentTab1" inherits="TabButtonTemplate" text="BANK">
+                <Anchors>
+                    <Anchor point="BOTTOMLEFT" relativeTo="$parent" relativePoint="TOPLEFT" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        PanelTemplates_TabResize(self, 0);
+                        self.HighlightTexture:SetWidth(self:GetTextWidth() + 31);
+                        self.tab = 1
+                    </OnLoad>
+                    <OnClick>
+                        DJBagsBankTab_OnClick(self)
+                    </OnClick>
+                </Scripts>
+            </Button>
+            <Button name="$parentTab2" inherits="TabButtonTemplate" text="REAGENT_BANK">
+                <Anchors>
+                    <Anchor point="BOTTOMLEFT" relativeTo="$parentTab1" relativePoint="BOTTOMRIGHT" />
+                </Anchors>
+                <Scripts>
+                    <OnLoad>
+                        PanelTemplates_TabResize(self, 0);
+                        self.HighlightTexture:SetWidth(self:GetTextWidth() + 31);
+                        self.tab = 2
+                    </OnLoad>
+                    <OnClick>
+                        DJBagsBankTab_OnClick(self)
+                    </OnClick>
+                </Scripts>
+            </Button>

+            <Frame name="DJBagsBankContainer" parent="DJBagsBankBar" inherits="DJBagsContainerTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="BOTTOMLEFT" y="-5" />
+                </Anchors>
+            </Frame>
+            <Frame name="DJBagsReagentContainer" parent="DJBagsBankBar" inherits="DJBagsContainerTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="BOTTOMLEFT" y="-5" />
+                </Anchors>
+            </Frame>
+            <Button name="$parentReagentButton" parent="DJBagsReagentContainer" parentKey="reagentButton" inherits="UIPanelButtonTemplate" text="BANKSLOTPURCHASE" hidden="true">
+                <Size x="100" y="25"/>
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="DJBagsReagentContainer" relativePoint="TOPLEFT" x="5" y="-5" />
+                </Anchors>
+                <Scripts>
+                    <OnClick>
+                        PlaySound("igMainMenuOption");
+                        StaticPopup_Show("CONFIRM_BUY_REAGENTBANK_TAB");
+                    </OnClick>
+                </Scripts>
+            </Button>
+        </Frames>
+        <Scripts>
+            <OnLoad>
+                PanelTemplates_SetNumTabs(self, 2)
+                DJBagsBankBarLoad(self)
+            </OnLoad>
+            <OnShow>
+                DJBagsBankBar_OnShow(self)
+            </OnShow>
+            <OnHide>
+                DJBagsBankBar_OnHide(self)
+            </OnHide>
+        </Scripts>
+    </Frame>
 </Ui>
diff --git a/src/xml/element/mainBar.xml b/src/xml/element/mainBar.xml
index 555377c..cd295ac 100644
--- a/src/xml/element/mainBar.xml
+++ b/src/xml/element/mainBar.xml
@@ -1,5 +1,5 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
-    <Frame name="DJBagsMainBarTemplate" virtual="true">
+    <Frame name="DJBagsMainBarTemplate" virtual="true" movable="true" enableMouse="true">
         <Size x="300" y="25" />
         <Backdrop bgFile="Interface\ChatFrame\ChatFrameBackground" edgeFile="Interface\Buttons\WHITE8x8">
             <EdgeSize>
@@ -65,8 +65,7 @@
         </Frames>
         <Scripts>
             <OnLoad>
-                self:SetBackdropColor(0, 0, 0, 0.6)
-                self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
+                DJBagsMainBarLoad(self)
             </OnLoad>
         </Scripts>
     </Frame>
diff --git a/src/xml/settings/bankBarSettings.xml b/src/xml/settings/bankBarSettings.xml
new file mode 100644
index 0000000..e69de29
diff --git a/src/xml/settings/settingsContainer.xml b/src/xml/settings/settingsContainer.xml
index 8c60aa5..181faa8 100644
--- a/src/xml/settings/settingsContainer.xml
+++ b/src/xml/settings/settingsContainer.xml
@@ -1,6 +1,6 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
-    <Frame name="DJBagsSettingsContainer" parent="UIParent" inherits="DJBagsContainerTemplate">
+    <Frame name="DJBagsSettingsContainer" parent="UIParent" movable="true" enableMouse="true"  inherits="DJBagsContainerTemplate">
         <Size x="545" y="600"/>
         <Anchors>
             <Anchor point="TOPLEFT" x="200" y="-100"/>
@@ -18,11 +18,16 @@
             <Frame name="DJBagsSettingsContent">
                 <Size x="500" y="565" />
                 <Frames>
-                    <Frame name="$parentSubClassSettings" inherits="DJBagsSubClassSettings">
+                    <Frame name="$parentMainSettings" inherits="DJBagsMainSettings">
                         <Anchors>
                             <Anchor point="TOP" />
                         </Anchors>
                     </Frame>
+                    <Frame name="$parentSubClassSettings" inherits="DJBagsSubClassSettings">
+                        <Anchors>
+                            <Anchor point="TOP" relativeTo="$parentMainSettings" relativePoint="BOTTOM" />
+                        </Anchors>
+                    </Frame>
                     <Frame name="$parentItemContainerSettings" inherits="DJBagsItemContainerSettings">
                         <Anchors>
                             <Anchor point="TOP" relativeTo="$parentSubClassSettings" relativePoint="BOTTOM" />
@@ -65,7 +70,7 @@
                     </OnMouseWheel>
                 </Scripts>
             </ScrollFrame>
-            <Slider name="$parentScrollBar" inherits="UIPanelScrollBarTemplate" minValue="0" maxValue="65" defaultValuie="1" valueStep="1">
+            <Slider name="$parentScrollBar" inherits="UIPanelScrollBarTemplate" minValue="0" maxValue="90" defaultValuie="1" valueStep="1">
                 <Backdrop bgFile="Interface\Buttons\UI-SliderBar-Background"
                           edgeFile="Interface\Buttons\UI-SliderBar-Border" tile="true">
                     <EdgeSize val="8"/>
diff --git a/src/xml/settings/subClassSettings.xml b/src/xml/settings/subClassSettings.xml
index 4a71934..9c0b282 100644
--- a/src/xml/settings/subClassSettings.xml
+++ b/src/xml/settings/subClassSettings.xml
@@ -18,7 +18,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_ARMOR, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_ARMOR)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_ARMOR, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_ARMOR, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -28,7 +28,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_CONSUMABLES, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_CONSUMABLE)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_CONSUMABLES, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_CONSUMABLE, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -38,7 +38,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_GEMS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_GEM)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_GEMS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_GEM, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -48,7 +48,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_GLYPHS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_GLYPH)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_GLYPHS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_GLYPH, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -58,7 +58,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_ITEM_ENHANCEMENT, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_ITEM_ENHANCEMENT)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_ITEM_ENHANCEMENT, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_ITEM_ENHANCEMENT, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -68,7 +68,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_MISCELLANEOUS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_MISCELLANEOUS)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_MISCELLANEOUS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_MISCELLANEOUS, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -78,7 +78,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_RECIPES, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_RECIPE)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_RECIPES, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_RECIPE, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -88,7 +88,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_TRADE_GOODS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_TRADEGOODS)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_TRADE_GOODS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_TRADEGOODS, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
@@ -98,7 +98,7 @@
                 </Anchors>
                 <Scripts>
                     <OnShow>
-                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_WEAPONS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_WEAPON)
+                        DJBagsInitSettingsCheckBox(self, AUCTION_CATEGORY_WEAPONS, DJBags_TYPE_SUB_CLASS, LE_ITEM_CLASS_WEAPON, 2)
                     </OnShow>
                 </Scripts>
             </CheckButton>
diff --git a/src/xml/settings/toggleSettings.xml b/src/xml/settings/toggleSettings.xml
new file mode 100644
index 0000000..c4c98b9
--- /dev/null
+++ b/src/xml/settings/toggleSettings.xml
@@ -0,0 +1,53 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
+    <Frame name="DJBagsMainSettings" inherits="DJBagsContainerTemplate" hidden="false" virtual="true">
+        <Size x="500" y="65"/>
+        <Layers>
+            <Layer level="ARTWORK">
+                <FontString name="$parentName" inherits="GameFontNormal" text="DJBags_LOCALE_SUB_CLASS_SETTINGS">
+                    <Anchors>
+                        <Anchor point="TOPLEFT" x="15" y="-5"/>
+                    </Anchors>
+                </FontString>
+            </Layer>
+        </Layers>
+        <Frames>
+            <CheckButton name="$parentAutoSellJunk" inherits="DJBagsSettingsCheckBoxTemplate">
+                <Anchors>
+                    <Anchor point="TOPLEFT" relativeTo="$parentName" relativePoint="BOTTOMLEFT" x="5" y="-5" />
+                </Anchors>
+                <Scripts>
+                    <OnShow>
+                        DJBagsInitSettingsCheckBox(self, DJBags_LOCALE_SELL_JUNK, DJBags_TYPE_MAIN, DJBags_SETTING_SELL_JUNK)
+                    </OnShow>
+                </Scripts>
+            </CheckButton>
+            <CheckButton name="$parentDepositReagents" inherits="DJBagsSettingsCheckBoxTemplate">
+                <Anchors>
+                    <Anchor point="LEFT" relativeTo="$parentAutoSellJunk" relativePoint="RIGHT" x="140" />
+                </Anchors>
+                <Scripts>
+                    <OnShow>
+                        DJBagsInitSettingsCheckBox(self, DJBags_LOCALE_DEPOSIT_REAGENT, DJBags_TYPE_MAIN, DJBags_SETTING_DEPOSIT_REAGENT)
+                    </OnShow>
+                </Scripts>
+            </CheckButton>
+            <CheckButton name="$parentStackAllItems" inherits="DJBagsSettingsCheckBoxTemplate">
+                <Anchors>
+                    <Anchor point="LEFT" relativeTo="$parentDepositReagents" relativePoint="RIGHT" x="140" />
+                </Anchors>
+                <Scripts>
+                    <OnShow>
+                        DJBagsInitSettingsCheckBox(self, DJBags_LOCALE_STACK_ALL, DJBags_TYPE_MAIN, DJBags_SETTING_STACK_ALL, 2)
+                    </OnShow>
+                </Scripts>
+            </CheckButton>
+        </Frames>
+        <Scripts>
+            <OnLoad>
+                self:SetBackdropColor(0, 0, 0, 0.6)
+                self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
+            </OnLoad>
+        </Scripts>
+    </Frame>
+</Ui>