Quantcast

Blacklist Window Completed!

Xruptor [08-25-16 - 17:58]
Blacklist Window Completed!
Filename
BagSync.lua
locale/enUS.lua
modules/blacklist.lua
modules/config.lua
modules/minimap.lua
modules/profiles.lua
modules/search.lua
diff --git a/BagSync.lua b/BagSync.lua
index a27fa6d..9183c9f 100644
--- a/BagSync.lua
+++ b/BagSync.lua
@@ -1304,11 +1304,7 @@ function BSYC:OnEnable()
 				end
 				return true
 			elseif c and c:lower() == L.SlashBlacklist then
-				if BagSync_BlackListFrame:IsVisible() then
-					BagSync_BlackListFrame:Hide()
-				else
-					BagSync_BlackListFrame:Show()
-				end
+				self:GetModule("Blacklist").frame:Show()
 				return true
 			elseif c and c:lower() == L.SlashFixDB then
 				self:FixDB()
diff --git a/locale/enUS.lua b/locale/enUS.lua
index 9c44d3c..7fa7639 100644
--- a/locale/enUS.lua
+++ b/locale/enUS.lua
@@ -43,6 +43,11 @@ L.ErrorUserNotFound = "BagSync: Error user not found!"
 L.EnterItemID = "Please enter an itemid. (Use Wowhead.com)"
 L.AddItemID = "Add ItemID"
 L.RemoveItemID = "Remove ItemID"
+L.ItemIDNotFound = "[%d] ItemID not found.  Try again!"
+L.ItemIDNotValid = "[%d] ItemID not valid ItemID or the server didn't respond.  Try again!"
+L.ItemIDRemoved = "[%d] ItemID Removed"
+L.ItemIDAdded = "[%d] ItemID Added"
+L.ItemIDExist = "[%d] ItemID already in database."
 -- ----THESE ARE FOR SLASH COMMANDS
 L.SlashItemName = "[itemname]"
 L.SlashSearch = "search"
diff --git a/modules/blacklist.lua b/modules/blacklist.lua
index 6d0c70f..3ed36c3 100644
--- a/modules/blacklist.lua
+++ b/modules/blacklist.lua
@@ -1,217 +1,170 @@
+
+local BSYC = select(2, ...) --grab the addon namespace
+local Blacklist = BSYC:NewModule("Blacklist")
+
 local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true)
-local blacklistTable = {}
-local tRows, tAnchor = {}
-local currentPlayer = UnitName("player")
-local currentRealm = select(2, UnitFullName("player")) --get shortend realm name with no spaces and dashes
-local storedBarCount = 0
-local prevClickedBar
-
-local bgBlackList = CreateFrame("Frame","BagSync_BlackListFrame", UIParent)
-
---itemid popup
-StaticPopupDialogs["BAGSYNC_BLACKLIST"] = {
-	text = L.EnterItemID,
-	button1 = "Yes",
-	button2 = "No",
-	hasEditBox = true,
-    hasWideEditBox = true,
-	timeout = 0,
-	exclusive = 1,
-	hideOnEscape = 1,
-	EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
-	OnAccept = function (self, data, data2)
-		local text = self.editBox:GetText()
-		if BagSync_BlackListFrame then
-			BagSync_BlackListFrame:processAdd(text)
-		end
-	end,
-	whileDead = 1,
-	maxLetters = 255,
-}
-
-local function LoadSlider()
-
-	local EDGEGAP, ROWHEIGHT, ROWGAP, GAP = 16, 20, 2, 4
-	local FRAME_HEIGHT = bgBlackList:GetHeight() - 90
-	local SCROLL_TOP_POSITION = -80
-	local totaltRows = math.floor((FRAME_HEIGHT-22)/(ROWHEIGHT + ROWGAP))
-
-	for i=1, totaltRows do
-		if not tRows[i] then
-			local row = CreateFrame("Button", nil, bgBlackList)
-			if not tAnchor then row:SetPoint("BOTTOMLEFT", bgBlackList, "TOPLEFT", 0, SCROLL_TOP_POSITION)
-			else row:SetPoint("TOP", tAnchor, "BOTTOM", 0, -ROWGAP) end
-			row:SetPoint("LEFT", EDGEGAP, 0)
-			row:SetPoint("RIGHT", -EDGEGAP*2-8, 0)
-			row:SetHeight(ROWHEIGHT)
-			row:EnableMouse(true)
-			row:SetBackdrop({
-				bgFile = "Interface\\Buttons\\WHITE8x8",
-			})
-			row:SetBackdropColor(0,0,0,0)
-			tAnchor = row
-			tRows[i] = row
-
-			local title = row:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
-			title:SetPoint("LEFT")
-			title:SetJustifyH("LEFT")
-			title:SetWidth(row:GetWidth())
-			title:SetHeight(ROWHEIGHT)
-			row.title = title
-
-			row:SetScript("OnClick", function (self, button, down)
-				if prevClickedBar then
-					prevClickedBar:SetBackdropColor(0,0,0,0)
-				end
-				prevClickedBar = self
-				self:SetBackdropColor(0,1,0,0.25)
-			end)
-		end
-	end
+local AceGUI = LibStub("AceGUI-3.0")

-	local offset = 0
-	local RefreshBlackList = function()
-		if not BagSync_BlackListFrame:IsVisible() then return end
-		for i,row in ipairs(tRows) do
-			if (i + offset) <= #blacklistTable then
-				if blacklistTable[i + offset] then
-					row.title:SetText(blacklistTable[i + offset])
-					row:Show()
-				end
-			else
-				row:Hide()
-			end
-		end
-	end
+function Blacklist:OnEnable()

-	RefreshBlackList()
+	--lets create our widgets
+	local BlacklistFrame = AceGUI:Create("Window")
+	Blacklist.frame = BlacklistFrame

-	if not bgBlackList.scrollbar then
-		bgBlackList.scrollbar = LibStub("tekKonfig-Scroll").new(bgBlackList, nil, #tRows/2)
-		bgBlackList.scrollbar:ClearAllPoints()
-		bgBlackList.scrollbar:SetPoint("TOP", tRows[1], 0, -16)
-		bgBlackList.scrollbar:SetPoint("BOTTOM", tRows[#tRows], 0, 16)
-		bgBlackList.scrollbar:SetPoint("RIGHT", -16, 0)
-	end
+	BlacklistFrame:SetTitle("BagSync "..L.Blacklist)
+	BlacklistFrame:SetHeight(500)
+	BlacklistFrame:SetWidth(380)
+	BlacklistFrame:EnableResize(false)

-	if #blacklistTable > 0 then
-		bgBlackList.scrollbar:SetMinMaxValues(0, math.max(0, #blacklistTable - #tRows))
-		bgBlackList.scrollbar:SetValue(0)
-		bgBlackList.scrollbar:Show()
-	else
-		bgBlackList.scrollbar:Hide()
-	end

-	local f = bgBlackList.scrollbar:GetScript("OnValueChanged")
-	bgBlackList.scrollbar:SetScript("OnValueChanged", function(self, value, ...)
-		offset = math.floor(value)
-		RefreshBlackList()
-		return f(self, value, ...)
+	local editbox = AceGUI:Create("EditBox")
+	editbox:SetText()
+	editbox:SetWidth(357)
+	editbox.disablebutton = true --disable the okay button
+	editbox:SetCallback("OnEnterPressed",function(widget)
+		editbox:ClearFocus()
+	end)
+
+	Blacklist.editbox = editbox
+	BlacklistFrame:AddChild(editbox)
+
+	local w = AceGUI:Create("SimpleGroup")
+	w:SetLayout("Flow")
+	w:SetFullWidth(true)
+	BlacklistFrame:AddChild(w)
+
+	local addbutton = AceGUI:Create("Button")
+	addbutton:SetText(L.AddItemID)
+	addbutton:SetWidth(150)
+	addbutton:SetHeight(20)
+	addbutton:SetCallback("OnClick", function()
+		editbox:ClearFocus()
+		self:AddItemID()
 	end)
+	w:AddChild(addbutton)
+
+	local removebutton = AceGUI:Create("Button")
+	removebutton:SetText(L.RemoveItemID)
+	removebutton:SetWidth(150)
+	removebutton:SetHeight(20)
+	removebutton:SetCallback("OnClick", function()
+		editbox:ClearFocus()
+		self:RemoveItemID()
+	end)
+	w:AddChild(removebutton)
+
+	local scrollframe = AceGUI:Create("ScrollFrame");
+	scrollframe:SetFullWidth(true)
+	scrollframe:SetLayout("Flow")

-	bgBlackList:EnableMouseWheel()
-	bgBlackList:SetScript("OnMouseWheel", function(self, val)
-		bgBlackList.scrollbar:SetValue(bgBlackList.scrollbar:GetValue() - val*#tRows/2)
+	Blacklist.scrollframe = scrollframe
+	BlacklistFrame:AddChild(scrollframe)
+
+	hooksecurefunc(BlacklistFrame, "Show" ,function()
+		self:DisplayList()
 	end)
+
+	BlacklistFrame:Hide()
 end

-local function DoBlackList()
-	if not BagSync or not BagSyncBLACKLIST_DB then return end
-	if not BagSyncBLACKLIST_DB[currentRealm] then return end
+function Blacklist:AddItemID()
+	local itemid = self.editbox:GetText()

-	blacklistTable = {} --reset
-	local tmp = {}
+	if string.len(self.editbox:GetText()) < 1 or not tonumber(itemid) then
+		BSYC:Print(L.EnterItemID)
+		return
+	end

-	--loop through our blacklist
-	-----------------------------------
-	if BagSyncBLACKLIST_DB[currentRealm] then
-		for k, v in pairs(BagSyncBLACKLIST_DB[currentRealm]) do
-			table.insert(blacklistTable, k)
-		end
+	if BSYC.db.blacklist[BSYC.currentRealm][tonumber(itemid)] then
+		BSYC:Print(L.ItemIDExist:format(tonumber(itemid)))
+		return
 	end
-	-----------------------------------
-
-	--sort it
-	table.sort(blacklistTable)
-
-	LoadSlider()
+
+	if not GetItemInfo(tonumber(self.editbox:GetText())) then
+		BSYC:Print(L.ItemIDNotValid:format(tonumber(itemid)))
+		return
+	end
+
+	local dName, dItemLink = GetItemInfo(tonumber(itemid))
+
+	BSYC.db.blacklist[BSYC.currentRealm][tonumber(itemid)] = true
+	BSYC:Print(L.ItemIDAdded:format(tonumber(itemid)), dItemLink)
+
+	self.editbox:SetText()
+
+	self:DisplayList()
 end

-bgBlackList:SetFrameStrata("HIGH")
-bgBlackList:SetToplevel(true)
-bgBlackList:EnableMouse(true)
-bgBlackList:SetMovable(true)
-bgBlackList:SetClampedToScreen(true)
-bgBlackList:SetWidth(380)
-bgBlackList:SetHeight(490)
-
-bgBlackList:SetBackdrop({
-		bgFile = "Interface/Tooltips/UI-Tooltip-Background",
-		edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
-		tile = true,
-		tileSize = 16,
-		edgeSize = 32,
-		insets = { left = 5, right = 5, top = 5, bottom = 5 }
-})
-
-bgBlackList:SetBackdropColor(0,0,0,1)
-bgBlackList:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
-
-local addonTitle = bgBlackList:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
-addonTitle:SetPoint("CENTER", bgBlackList, "TOP", 0, -20)
-addonTitle:SetText("|cFF99CC33BagSync|r |cFFFFFFFF("..L.Blacklist..")|r")
-
-local closeButton = CreateFrame("Button", nil, bgBlackList, "UIPanelCloseButton");
-closeButton:SetPoint("TOPRIGHT", bgBlackList, -15, -8);
-
---Add ItemID
-local addItemButton = CreateFrame("Button", nil, bgBlackList, "UIPanelButtonTemplate")
-addItemButton:SetWidth(130)
-addItemButton:SetHeight(25)
-addItemButton:SetPoint("BOTTOMLEFT", bgBlackList, "BOTTOMLEFT", 20, 15)
-addItemButton:SetText(L.AddItemID)
-addItemButton:SetScript("OnClick", function() StaticPopup_Show("BAGSYNC_BLACKLIST") end)
-
---Remove ItemID
-local removeItemButton = CreateFrame("Button", nil, bgBlackList, "UIPanelButtonTemplate")
-removeItemButton:SetWidth(130)
-removeItemButton:SetHeight(25)
-removeItemButton:SetPoint("BOTTOMRIGHT", bgBlackList, "BOTTOMRIGHT", -20, 15)
-removeItemButton:SetText(L.RemoveItemID)
-removeItemButton:SetScript("OnClick", function()
-	if not BagSync or not BagSyncBLACKLIST_DB then return end
-	if not BagSyncBLACKLIST_DB[currentRealm] then return end
-	if not prevClickedBar or not prevClickedBar.title or not prevClickedBar.title:GetText() then return end
-	if not tonumber(prevClickedBar.title:GetText()) then return end
-	BagSyncBLACKLIST_DB[currentRealm][tonumber(prevClickedBar.title:GetText())] = nil
-	DoBlackList()
-end)
-
-bgBlackList:SetScript("OnShow", function(self) DoBlackList(); LoadSlider(); end)
-bgBlackList:SetScript("OnHide", function(self)
-	blacklistTable = {}
-end)
-
-bgBlackList:SetScript("OnMouseDown", function(frame, button)
-	if frame:IsMovable() then
-		frame.isMoving = true
-		frame:StartMoving()
+function Blacklist:RemoveItemID()
+	local itemid = self.editbox:GetText()
+
+	if string.len(self.editbox:GetText()) < 1 or not tonumber(itemid) then
+		BSYC:Print(L.EnterItemID)
+		return
 	end
-end)

-bgBlackList:SetScript("OnMouseUp", function(frame, button)
-	if( frame.isMoving ) then
-		frame.isMoving = nil
-		frame:StopMovingOrSizing()
+	if not BSYC.db.blacklist[BSYC.currentRealm][tonumber(itemid)] then
+		BSYC:Print(L.ItemIDNotFound:format(tonumber(itemid)))
+		return
 	end
-end)
-
-function bgBlackList:processAdd(itemid)
-	if not BagSync or not BagSyncBLACKLIST_DB then return end
-	if not BagSyncBLACKLIST_DB[currentRealm] then return end
-	if not tonumber(itemid) then return end
-	BagSyncBLACKLIST_DB[currentRealm][tonumber(itemid)] = true
-	DoBlackList()
+
+	BSYC.db.blacklist[BSYC.currentRealm][tonumber(itemid)] = nil
+	BSYC:Print(L.ItemIDRemoved:format(tonumber(itemid)))
+
+	self.editbox:SetText()
+
+	self:DisplayList()
+end
+
+function Blacklist:AddEntry(entry, counter)
+
+	local highlightColor = {1, 0, 0}
+	local label = AceGUI:Create("InteractiveLabel")
+
+	label:SetText(entry)
+	label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE)
+	label:SetFullWidth(true)
+	label:SetColor( r, g, b)
+	label:SetCallback(
+		"OnClick",
+		function (widget, sometable, button)
+			self.editbox:SetText(entry)
+		end)
+	label:SetCallback(
+		"OnEnter",
+		function (widget, sometable)
+			label:SetColor(unpack(highlightColor))
+			GameTooltip:SetOwner(label.frame, "ANCHOR_BOTTOMRIGHT")
+			GameTooltip:SetHyperlink("item:"..entry)
+			GameTooltip:Show()
+		end)
+	label:SetCallback(
+		"OnLeave",
+		function (widget, sometable)
+			label:SetColor(r, g, b)
+			GameTooltip:Hide()
+		end)
+
+	self.scrollframe:AddChild(label)
 end

-bgBlackList:Hide()
+function Blacklist:DisplayList()
+
+	self.scrollframe:ReleaseChildren() --clear out the scrollframe
+
+	local count = 0
+
+	--loop through our blacklist
+	for k, v in pairs(BSYC.db.blacklist[BSYC.currentRealm]) do
+		self:AddEntry(k, count)
+		count = count + 1
+	end
+
+	--show or hide the scrolling frame depending on count
+	if count > 0 then
+		self.scrollframe.frame:Show()
+	else
+		self.scrollframe.frame:Hide()
+	end
+
+end
\ No newline at end of file
diff --git a/modules/config.lua b/modules/config.lua
index f3bd36e..8ae23b6 100644
--- a/modules/config.lua
+++ b/modules/config.lua
@@ -1,8 +1,4 @@
 local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true)
-local currentPlayer = UnitName("player")
-local currentRealm = select(2, UnitFullName("player"))
-local ver = GetAddOnMetadata("BagSync","Version") or 0
-
 local config = LibStub("AceConfig-3.0")
 local configDialog = LibStub("AceConfigDialog-3.0")

diff --git a/modules/minimap.lua b/modules/minimap.lua
index 8001bba..0a6fa73 100644
--- a/modules/minimap.lua
+++ b/modules/minimap.lua
@@ -53,7 +53,7 @@ bgsMinimapDD.initialize = function(self, level)
 			if BagSync_CraftsFrame then BagSync_CraftsFrame:Show() end
 		end)
 		addButton(level, L.Blacklist, nil, 1, nil, 'blacklist', function(frame, ...)
-			if BagSync_BlackListFrame then BagSync_BlackListFrame:Show() end
+			BSYC:GetModule("Blacklist").frame:Show()
 		end)
 		addButton(level, L.Gold, nil, 1, nil, 'gold', function(frame, ...)
 			if BagSync then BagSync:ShowMoneyTooltip() end
diff --git a/modules/profiles.lua b/modules/profiles.lua
index 133b0c0..8256b8f 100644
--- a/modules/profiles.lua
+++ b/modules/profiles.lua
@@ -5,7 +5,7 @@ local Profiles = BSYC:NewModule("Profiles")
 local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true)
 local AceGUI = LibStub("AceGUI-3.0")

-function Profiles:OnInitialize()
+function Profiles:OnEnable()

 	--lets create our widgets
 	local ProfilesFrame = AceGUI:Create("Window")
diff --git a/modules/search.lua b/modules/search.lua
index cafd166..ba0b3b6 100644
--- a/modules/search.lua
+++ b/modules/search.lua
@@ -36,7 +36,7 @@ ItemSearch.Filters.class = {
 	end
 }

-function Search:OnInitialize()
+function Search:OnEnable()

 	--lets create our widgets
 	local SearchFrame = AceGUI:Create("Window")