Quantcast

added junk equipment fix

Brandon Talbot [06-30-16 - 20:01]
added junk equipment fix
Added settings screen (initial version)
Filename
.idea/misc.xml
src/lua/core.lua
src/lua/elements/item.lua
src/lua/settings/editor.lua
src/lua/settings/settings.lua
src/manifest.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b248dfa..2c9fc54 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -17,23 +17,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="true" assert-keyword="false" jdk-15="false" project-jdk-name="Lua 5.3.3" project-jdk-type="Lua SDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="false" assert-keyword="false" jdk-15="false">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
-  <component name="masterDetails">
-    <states>
-      <state key="ProjectJDKs.UI">
-        <settings>
-          <last-edited>Lua 5.3.3</last-edited>
-          <splitter-proportions>
-            <option name="proportions">
-              <list>
-                <option value="0.2" />
-              </list>
-            </option>
-          </splitter-proportions>
-        </settings>
-      </state>
-    </states>
-  </component>
 </project>
\ No newline at end of file
diff --git a/src/lua/core.lua b/src/lua/core.lua
index 117952d..45c5fce 100644
--- a/src/lua/core.lua
+++ b/src/lua/core.lua
@@ -27,20 +27,19 @@ ADDON.eventManager:AddEvent(core, 'ADDON_LOADED')

 --region Slash Commands

-SLASH_DJBAGS1, SLASH_DJBAGS2 = '/db', '/djbags'; -- 3.
-function SlashCmdList.DJBAGS(msg, editbox) -- 4.
-ADDON.bag:Open()
+SLASH_DJBAGS1, SLASH_DJBAGS2 = '/db', '/djbags';
+function SlashCmdList.DJBAGS(msg, editbox)
+    ADDON.bag:Open()
 end

-SLASH_TDJBAGS1, SLASH_TDJBAGS2 = '/tt', '/ttt'; -- 3.
-function SlashCmdList.TDJBAGS(msg, editbox) -- 4.
-ADDON.settings.item.size = 50
-ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+SLASH_TDJBAGS1, SLASH_TDJBAGS2 = '/tt', '/ttt';
+function SlashCmdList.TDJBAGS(msg, editbox)
+    ADDON.settingsController:ShowSettings()
 end

 SLASH_RELOAD1 = '/rl'
-function SlashCmdList.RELOAD(msg, editbox) -- 4.
-ReloadUI()
+function SlashCmdList.RELOAD(msg, editbox)
+    ReloadUI()
 end

 --endregion
\ No newline at end of file
diff --git a/src/lua/elements/item.lua b/src/lua/elements/item.lua
index f62f17d..5e10756 100644
--- a/src/lua/elements/item.lua
+++ b/src/lua/elements/item.lua
@@ -112,7 +112,7 @@ local function UpdateFiltered(self, filtered, shouldDoRelicChecks, itemID)
 end

 local function UpdateCountcolour(self, equipable, quality)
-    if (equipable) then
+    if equipable and quality then
         self.button.Count:SetVertexColor(BAG_ITEM_QUALITY_COLORS[quality].r, BAG_ITEM_QUALITY_COLORS[quality].g, BAG_ITEM_QUALITY_COLORS[quality].b)
     else
         self.button.Count:SetVertexColor(1, 1, 1)
diff --git a/src/lua/settings/editor.lua b/src/lua/settings/editor.lua
new file mode 100644
index 0000000..c2c4058
--- /dev/null
+++ b/src/lua/settings/editor.lua
@@ -0,0 +1,247 @@
+local NAME, ADDON = ...
+
+local STEP = 1
+local SCROLL = 1
+local MAX = 1
+
+ADDON.settingsEditor = {}
+ADDON.settingsEditor.__index = ADDON.settingsEditor
+
+local settings = ADDON.settingsEditor
+setmetatable(settings, {
+    __call = function(self)
+        return self.frame or self:CreateFrame()
+    end
+})
+
+function settings:UpdateSettings()
+    print('asd')
+    if self.frame then
+        self.frame:Setup()
+        if self.containers then
+            for _, v in pairs(self.containers) do
+                v:Setup()
+            end
+        end
+    end
+end
+
+function settings:CreateFrame()
+    self.frame = ADDON.container('DJBagsSettingsScreen')
+    self.frame:SetSize(520, 450)
+    self.frame:SetPoint("TOPLEFT", 200, -200)
+    self.frame:Hide()
+    table.insert(UISpecialFrames, self.frame:GetName())
+
+    self.title = self.frame:CreateFontString('DJBagsSettingsScreenTitle', nil, 'GameFontNormal')
+    self.title:SetText('DJBags Settings')
+    self.title:SetPoint('TOPLEFT', 5, -5)
+
+    self.exitBtn = CreateFrame('BUTTON', 'DJBagsSettingsScreenExitButton', self.frame, 'UIPanelCloseButton')
+    self.exitBtn:SetPoint('TOPRIGHT')
+
+    self.scrollBar = CreateFrame("Slider", 'DJBagsSettingsScreenScrollBar', self.frame, "UIPanelScrollBarTemplate")
+    self.scrollBar:SetPoint('TOPRIGHT', -5, -50)
+    self.scrollBar:SetPoint('BOTTOMRIGHT', -5, 25)
+    self.scrollBar:SetMinMaxValues(1, MAX)
+    self.scrollBar:SetValueStep(STEP)
+    self.scrollBar.scrollStep = SCROLL
+    self.scrollBar:SetScript("OnValueChanged",
+        function(self, value)
+            settings.scrollFrame:SetVerticalScroll(value)
+        end)
+
+    self.scrollFrame = CreateFrame("ScrollFrame", 'DJBagsSettingsScreenScrollFrame', self.frame)
+    self.scrollFrame:SetPoint('TOPLEFT', 5, -30)
+    self.scrollFrame:SetPoint('BOTTOMRIGHT', self.scrollBar, 'BOTTOMLEFT', -5, 0)
+    self.scrollBar:SetValue(1)
+
+    self.scrollFrame:EnableMouseWheel(true)
+    self.scrollFrame:SetScript("OnMouseWheel", function(self, delta)
+        local current = settings.scrollBar:GetValue()
+
+        if IsShiftKeyDown() and (delta > 0) then
+            settings.scrollBar:SetValue(0)
+        elseif IsShiftKeyDown() and (delta < 0) then
+            settings.scrollBar:SetValue(MAX)
+        elseif (delta < 0) and (current < MAX) then
+            settings.scrollBar:SetValue(math.min(current + 20, MAX))
+        elseif (delta > 0) and (current > 1) then
+            settings.scrollBar:SetValue(math.max(current - 20, 1))
+        end
+    end)
+
+    self.content = CreateFrame("Frame", 'DJBagsSettingsScreenContent', self.scrollFrame)
+    self.content:SetSize(self.scrollFrame:GetWidth(), 0)
+
+    self.scrollFrame:SetScrollChild(self.content)
+
+    self:CreateContainerSettings()
+    self:CreateItemContainerSettings()
+
+    return self.frame
+end
+
+function settings:AddSettingsPanel(panel)
+    self.containers = self.containers or {}
+    tinsert(self.containers, panel)
+    panel:SetParent(self.content)
+    panel:SetPoint('TOPLEFT', 0, -5 - self.content:GetHeight())
+    panel:SetPoint('TOPRIGHT', 0, -5 - self.content:GetHeight())
+    self.content:SetHeight(self.content:GetHeight() + panel:GetHeight() + 5)
+
+    MAX = math.max(MAX, self.content:GetHeight() - self.scrollFrame:GetHeight())
+    self.scrollBar:SetMinMaxValues(1, MAX)
+end
+
+local function CreateColorSelector(name, parent, getColor, callBack)
+    local colourSelector = CreateFrame('BUTTON', 'DJBagsSettingsColourSelector' .. name, parent)
+    colourSelector:SetNormalFontObject("GameFontHighlight")
+    colourSelector:SetText(name)
+    colourSelector:SetBackdrop({
+        bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
+        edgeFile = "Interface\\Buttons\\WHITE8x8",
+        tile = true,
+        tileSize = 16,
+        edgeSize = 2,
+    })
+    colourSelector:SetBackdropBorderColor(unpack(getColor()))
+    colourSelector:SetBackdropColor(0, 0, 0, 1)
+    colourSelector.call = callBack
+
+    colourSelector:SetScript('OnClick', function(self)
+        local r, g, b, a = unpack(getColor())
+
+        local function callback(restore)
+            local newR, newG, newB, newA = r, g, b, a;
+            if not restore then
+                newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
+            end
+
+            self:SetBackdropBorderColor(newR, newG, newB, newA)
+            self.call(newR, newG, newB, newA)
+        end
+
+        ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = callback, callback, callback;
+        ColorPickerFrame:SetColorRGB(r, g, b, a);
+        ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (a ~= nil), a;
+        ColorPickerFrame.previousValues = { r, g, b, a };
+        ShowUIPanel(ColorPickerFrame)
+    end)
+
+    colourSelector:SetSize(150, 20)
+    return colourSelector
+end
+
+local function round(num)
+    if num >= 0 then return math.floor(num + .5)
+    else return math.ceil(num - .5)
+    end
+end
+
+local function CreateSlider(parent, name, min, max, value, callBack)
+    local slider = CreateFrame('Slider', name .. 'slider', parent, 'OptionsSliderTemplate')
+    getglobal(slider:GetName() .. "Text"):SetText(name .. ' - ' .. tostring(value()));
+    getglobal(slider:GetName() .. "High"):SetText(max);
+    getglobal(slider:GetName() .. "Low"):SetText(min);
+    slider:SetMinMaxValues(min, max)
+    slider:SetValue(value())
+    slider:Show()
+
+    slider:SetScript('OnValueChanged', function(self, value)
+        value = round(value)
+        callBack(value)
+        getglobal(self:GetName() .. "Text"):SetText(name .. ' - ' .. tostring(value));
+    end)
+
+    return slider
+end
+
+local function CreateTitle(title, parent)
+    parent.title = parent:CreateFontString('DJBagsSettingsScreenTitle' .. title, nil, 'GameFontNormal')
+    parent.title:SetText(title)
+    parent.title:SetPoint('TOPLEFT', 5, -5)
+end
+
+function settings:CreateContainerSettings()
+    local container = ADDON.container('DJBagsSettingsContainerScreen', nil)
+
+    CreateTitle('Border and Background', container)
+
+    container.borderPicker = CreateColorSelector('Border Colour', container, function()
+        return ADDON.settings.container.borderColor
+    end, function(r, g, b, a)
+        ADDON.settings.container.borderColor = { r, g, b, a }
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.borderPicker:SetPoint('TOPLEFT', 5, -25)
+
+    container.backgroundPicker = CreateColorSelector('Background Colour', container, function()
+        return ADDON.settings.container.backgroundColor
+    end, function(r, g, b, a)
+        ADDON.settings.container.backgroundColor = { r, g, b, a }
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.backgroundPicker:SetPoint('TOPLEFT', container.borderPicker, 'TOPRIGHT', 15, 0)
+
+    container.borderWidth = CreateSlider(container, 'Border Width', 1, 4, function()
+        return ADDON.settings.container.borderWidth
+    end, function(value)
+        ADDON.settings.container.borderWidth = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.borderWidth:SetPoint('TOPLEFT', container.backgroundPicker, 'TOPRIGHT', 15, 0)
+
+
+    container:SetHeight(55)
+    self:AddSettingsPanel(container)
+end
+
+function settings:CreateItemContainerSettings()
+    local container = ADDON.container('DJBagsSettingsItemContainerScreen', nil)
+
+    CreateTitle('Category container settings', container)
+
+    container.fontColor = CreateColorSelector('Font Colour', container, function()
+        return ADDON.settings.itemContainer.fontColor
+    end, function(r, g, b, a)
+        ADDON.settings.itemContainer.fontColor = { r, g, b, a }
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.fontColor:SetPoint('TOPLEFT', 5, -25)
+
+    container.fontSize = CreateSlider(container, 'Font size', 8, 18, function()
+        return ADDON.settings.itemContainer.fontSize
+    end, function(value)
+        ADDON.settings.itemContainer.fontSize = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.fontSize:SetPoint('TOPLEFT', container.fontColor, 'TOPRIGHT', 15, 0)
+
+    container.colsSlider = CreateSlider(container, 'Columns', 4, 10, function()
+        return ADDON.settings.itemContainer.cols
+    end, function(value)
+        ADDON.settings.itemContainer.cols = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.colsSlider:SetPoint('TOPLEFT', container.fontSize, 'TOPRIGHT', 15, 0)
+
+    container.padding = CreateSlider(container, 'Padding', 1, 10, function()
+        return ADDON.settings.itemContainer.padding
+    end, function(value)
+        ADDON.settings.itemContainer.padding = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.padding:SetPoint('TOPLEFT', container.fontColor, 'BOTTOMLEFT', 2, -20)
+
+    container.spacing = CreateSlider(container, 'Item Spacing', 1, 10, function()
+        return ADDON.settings.itemContainer.spacing
+    end, function(value)
+        ADDON.settings.itemContainer.spacing = value
+        ADDON.eventManager:FireEvent('SETTINGS_UPDATE')
+    end)
+    container.spacing:SetPoint('TOPLEFT', container.padding, 'TOPRIGHT', 15, 0)
+
+    container:SetHeight(95)
+    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 b55fa58..b946744 100644
--- a/src/lua/settings/settings.lua
+++ b/src/lua/settings/settings.lua
@@ -9,10 +9,17 @@ settings.__index = settings
 function settings:Init()
     self:GetCharacterSettings()

-    ADDON.eventManager:AddEvent("SETTING_UPDATE")
+    self.screen = ADDON.settingsEditor()
+
+    ADDON.eventManager:AddEvent(self, "SETTINGS_UPDATE")
+end
+
+function settings:ShowSettings()
+    self.screen:Show()
 end

 function settings:SETTINGS_UPDATE()
+    print('lol')
     local realm = GetRealmName()
     local player = UnitName("player")

@@ -23,6 +30,8 @@ function settings:SETTINGS_UPDATE()
         DJBagsConfig[realm] = {}
     end
     --    DJBagsConfig[player] = ADDON.settings
+
+    ADDON.settingsEditor:UpdateSettings()
 end

 function settings:GetCharacterSettings()
diff --git a/src/manifest.xml b/src/manifest.xml
index b1ce275..b1160f0 100644
--- a/src/manifest.xml
+++ b/src/manifest.xml
@@ -15,6 +15,7 @@
     <Script file="src/lua/settings/defaults/category.lua"/>
     <Script file="src/lua/settings/defaults/categoryContainer.lua"/>
     <Script file="src/lua/settings/defaults/mainBar.lua"/>
+    <Script file="src/lua/settings/editor.lua"/>
     <Script file="src/lua/settings/settings.lua"/>

     <!-- sorters -->