Quantcast

Added box format (old DJBags default)

Brandon Talbot [07-21-16 - 18:33]
Added box format (old DJBags default)
Filename
src/lua/constants/contstants.lua
src/lua/element/container.lua
src/lua/settings/settingsController.lua
src/lua/tools/boxFormatter.lua
src/lua/tools/masonryFormatter.lua
src/manifest.xml
diff --git a/src/lua/constants/contstants.lua b/src/lua/constants/contstants.lua
index a2fafb2..10de4d9 100644
--- a/src/lua/constants/contstants.lua
+++ b/src/lua/constants/contstants.lua
@@ -6,8 +6,8 @@ DJBags_TYPE_CONTAINER = 'container'
 DJBags_TYPE_ITEM_CONTAINER = 'itemContainer'
 DJBags_TYPE_SUB_CLASS = 'djbags_sub_classes'

-DJBags_FORMATTER_MASONRY = 'djbags_masonry'
-DJBags_FORMATTER_BLOCK = 'djbags_block'
+DJBags_FORMATTER_MASONRY = 'Massonry'
+DJBags_FORMATTER_BOX = 'Box'

 --endregion

@@ -23,6 +23,7 @@ DJBags_SETTING_FORMATTER = 'djbags_formatter'
 DJBags_SETTING_FORMATTER_VERT = 'djbags_formatter_vert'
 DJBags_SETTING_FORMATTER_MAX_ITEMS = 'djbags_formatter_max_items'
 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'

@@ -44,6 +45,8 @@ localeText['enUS'] = function()
     DJBags_LOCALE_SPACING = 'Spacing'
     DJBags_LOCALE_SCALE = 'Scale'
     DJBags_LOCALE_TEXT_SIZE = 'Text size'
+    DJBags_LOCALE_MASONRY = 'Massonry'
+    DJBags_LOCALE_BOX = 'Box'
 end

 if localeText[GetLocale()] then
diff --git a/src/lua/element/container.lua b/src/lua/element/container.lua
index 43f3b95..62e421f 100644
--- a/src/lua/element/container.lua
+++ b/src/lua/element/container.lua
@@ -69,6 +69,7 @@ function container:Arrange(override)
         self,
         ADDON.settings:GetSettings(self.__type)[DJBags_SETTING_FORMATTER_MAX_ITEMS],
         ADDON.settings:GetSettings(self.__type)[DJBags_SETTING_FORMATTER_MAX_HEIGHT],
+        ADDON.settings:GetSettings(self.__type)[DJBags_SETTING_FORMATTER_BOX_COLS],
         ADDON.settings:GetSettings(self.__type)[DJBags_SETTING_FORMATTER_VERT],
         override
     )
diff --git a/src/lua/settings/settingsController.lua b/src/lua/settings/settingsController.lua
index 752439e..9e8a57a 100644
--- a/src/lua/settings/settingsController.lua
+++ b/src/lua/settings/settingsController.lua
@@ -40,6 +40,7 @@ function settings:Init()
             [DJBags_SETTING_FORMATTER_VERT] = false,
             [DJBags_SETTING_FORMATTER_MAX_ITEMS] = 12,
             [DJBags_SETTING_FORMATTER_MAX_HEIGHT] = 0.5,
+            [DJBags_SETTING_FORMATTER_BOX_COLS] = 4,
             [DJBags_SETTING_TRUNCATE_SUB_CLASS] = true,
         },
         [DJBags_TYPE_ITEM_CONTAINER] = {
diff --git a/src/lua/tools/boxFormatter.lua b/src/lua/tools/boxFormatter.lua
index e69de29..33ebcb5 100644
--- a/src/lua/tools/boxFormatter.lua
+++ b/src/lua/tools/boxFormatter.lua
@@ -0,0 +1,50 @@
+local NAME, ADDON = ...
+
+ADDON.format = ADDON.format or {}
+
+local sorter = function(A, B)
+    if A.name.text == EMPTY then
+        return true
+    elseif B.name.text == EMPTY then
+        return false
+    elseif A.name.text == NEW then
+        return false
+    elseif B.name.text == NEW then
+        return true
+    elseif A.name.text == BAG_FILTER_JUNK then
+        return false
+    elseif B.name.text == BAG_FILTER_JUNK then
+        return true
+    else
+        return A.name.text > B.name.text
+    end
+end
+
+ADDON.format[DJBags_FORMATTER_BOX] = function(frame, _, maxHeight, cols, _, override)
+    local x = 0
+    local y = 0
+    local width = 0
+    local height = 0
+
+    for item in ADDON:PairsByKey(frame.items, sorter) do
+        if item:IsEmpty() then
+            item:Hide()
+        else
+            item:ClearAllPoints()
+            item:Arrange(cols, nil, (item.name:GetText() == EMPTY and 1), override)
+            item:Show()
+            if (y + item:GetHeight() + frame.spacing) > (maxHeight * GetScreenHeight()) then
+                y = 0
+                x = x - item:GetWidth() - frame.spacing
+            end
+
+            item:SetPoint('BOTTOMRIGHT', x, y)
+
+            height = math.max(height, y + item:GetHeight() + frame.padding * 2)
+            width = math.max(width, -x + item:GetWidth() + frame.padding * 2)
+            y = y + frame.spacing + item:GetHeight()
+        end
+    end
+
+    frame:SetSize(width, height)
+end
\ No newline at end of file
diff --git a/src/lua/tools/masonryFormatter.lua b/src/lua/tools/masonryFormatter.lua
index f3d5b69..0c80681 100644
--- a/src/lua/tools/masonryFormatter.lua
+++ b/src/lua/tools/masonryFormatter.lua
@@ -20,7 +20,7 @@ local sorter = function(A, B)
     end
 end

-ADDON.format[DJBags_FORMATTER_MASONRY] = function(frame, maxItems, _, vert, override)
+ADDON.format[DJBags_FORMATTER_MASONRY] = function(frame, maxItems, _, _, vert, override)
     local h = 0
     local x = 0
     local mH = 0
diff --git a/src/manifest.xml b/src/manifest.xml
index 460dfc3..5996652 100644
--- a/src/manifest.xml
+++ b/src/manifest.xml
@@ -27,6 +27,7 @@
     <!-- Formatters -->
     <Script file="src/lua/tools/itemFormatter.lua" />
     <Script file="src/lua/tools/masonryFormatter.lua" />
+    <Script file="src/lua/tools/boxFormatter.lua" />

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