From 9fedebdd462bb0162cf1d92f2391aca5ffcec35f Mon Sep 17 00:00:00 2001 From: Xruptor Date: Thu, 25 Aug 2016 12:36:30 -0400 Subject: [PATCH] Profiles and Search Window Completed -The redesigned Profiles and Search windows are done. They have been migrated over to Ace3GUI. -Next up... too much stuff :( --- BagSync.lua | 34 ++--- BagSync.toc | 6 +- locale/enUS.lua | 4 +- modules/minimap.lua | 4 +- modules/profiles.lua | 147 +++++++++---------- modules/search.lua | 381 +++++++++++++++++++++----------------------------- modules/test.lua | 52 ++++--- 7 files changed, 285 insertions(+), 343 deletions(-) diff --git a/BagSync.lua b/BagSync.lua index 5cc8006..a27fa6d 100644 --- a/BagSync.lua +++ b/BagSync.lua @@ -11,10 +11,8 @@ local BSYC = select(2, ...) --grab the addon namespace BSYC = LibStub("AceAddon-3.0"):NewAddon(BSYC, "BagSync", "AceEvent-3.0", "AceConsole-3.0") -BSYC.callbacks = BSYC.callbacks or LibStub("CallbackHandler-1.0"):New(BSYC) local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true) - local strsub, strsplit, strlower, strmatch, strtrim = string.sub, string.split, string.lower, string.match, string.trim local format, tonumber, tostring, tostringall = string.format, tonumber, tostring, tostringall local tsort, tinsert, unpack = table.sort, table.insert, unpack @@ -41,12 +39,8 @@ local dataobj = ldb:NewDataObject("BagSyncLDB", { text = "BagSync", OnClick = function(self, button) - if button == "LeftButton" and BagSync_SearchFrame then - if BagSync_SearchFrame:IsVisible() then - BagSync_SearchFrame:Hide() - else - BagSync_SearchFrame:Show() - end + if button == "LeftButton" then + BSYC:GetModule("Search").frame:Show() elseif button == "RightButton" and BagSync_TokensFrame then if bgsMinimapDD then ToggleDropDownMenu(1, nil, bgsMinimapDD, "cursor", 0, 0) @@ -904,7 +898,7 @@ function BSYC:AddItemToTooltip(frame, link) --workaround local grandTotal = 0 local first = true - local xDB = BSYC:FilterDB() + local xDB = self:FilterDB() --loop through our characters --k = player, v = stored data for player @@ -955,7 +949,7 @@ function BSYC:AddItemToTooltip(frame, link) --workaround if guildN and self.db.guild[v.realm][guildN] then --check to see if this guild has already been done through this run (so we don't do it multiple times) --check for XR/B.Net support, you can have multiple guilds with same names on different servers - local gName = BSYC:GetGuildRealmInfo(guildN, v.realm) + local gName = self:GetGuildRealmInfo(guildN, v.realm) if not previousGuilds[gName] then --we only really need to see this information once per guild @@ -978,7 +972,7 @@ function BSYC:AddItemToTooltip(frame, link) --workaround infoString = self:CreateItemTotals(allowList) if infoString then - k = BSYC:GetCharacterRealmInfo(k, v.realm) + k = self:GetCharacterRealmInfo(k, v.realm) table.insert(self.PreviousItemTotals, self:GetClassColor(k or "Unknown", pClass).."@"..(infoString or "unknown")) end @@ -1287,11 +1281,7 @@ function BSYC:OnEnable() if a then if c and c:lower() == L.SlashSearch then - if BagSync_SearchFrame:IsVisible() then - BagSync_SearchFrame:Hide() - else - BagSync_SearchFrame:Show() - end + self:GetModule("Search"):StartSearch() return true elseif c and c:lower() == L.SlashGold then self:ShowMoneyTooltip() @@ -1304,7 +1294,7 @@ function BSYC:OnEnable() end return true elseif c and c:lower() == L.SlashProfiles then - self.FrameProfile:Show() + self:GetModule("Profiles").frame:Show() return true elseif c and c:lower() == L.SlashProfessions then if BagSync_CraftsFrame:IsVisible() then @@ -1328,11 +1318,7 @@ function BSYC:OnEnable() return true elseif c and c:lower() ~= "" then --do an item search - if BagSync_SearchFrame then - if not BagSync_SearchFrame:IsVisible() then BagSync_SearchFrame:Show() end - BagSync_SearchFrame.SEARCHBTN:SetText(msg) - BagSync_SearchFrame:initSearch() - end + self:GetModule("Search"):StartSearch(msg) return true end end @@ -1350,10 +1336,6 @@ function BSYC:OnEnable() end self:Print("[v|cFFDF2B2B"..ver.."|r] /bgs, /bagsync") - - --fire off the callback for BagSync fully loaded - BSYC.callbacks:Fire("BAGSYNC_LOADED") - end ------------------------------ diff --git a/BagSync.toc b/BagSync.toc index 7274bb7..c96ed40 100644 --- a/BagSync.toc +++ b/BagSync.toc @@ -30,6 +30,8 @@ locale\zhTW.lua locale\ptBR.lua locale\esES.lua +BagSync.lua + modules\minimap.lua modules\search.lua modules\tokens.lua @@ -37,6 +39,4 @@ modules\professions.lua modules\blacklist.lua modules\profiles.lua modules\config.lua -modules\test.lua - -BagSync.lua \ No newline at end of file +modules\test.lua \ No newline at end of file diff --git a/locale/enUS.lua b/locale/enUS.lua index 14bf7b1..9c44d3c 100644 --- a/locale/enUS.lua +++ b/locale/enUS.lua @@ -13,6 +13,7 @@ L.TooltipAuction = "AH: %d" L.TooltipTotal = "Total:" L.TooltipDelimiter = ", " L.Search = "Search" +L.Refresh = "Refresh" L.Tokens = "Tokens" L.Profiles = "Profiles" L.Professions = "Professions" @@ -88,5 +89,6 @@ L.ConfigColor = "Color" L.ConfigColorHeader = "Color settings for BagSync tooltip information." L.ConfigMain = "Main" L.ConfigMainHeader = "Main settings for BagSync." -L.WarningItemSearch = "WARNING: A total of [%d] items were not searched!\nBagSync is still waiting for the server/cache to respond.\nPress the Search button again to retry." +L.WarningItemSearch = "WARNING: A total of [|cFFFFFFFF%d|r] items were not searched!\n\nBagSync is still waiting for the server/cache to respond.\n\nPress refresh button." L.WarningUpdatedDB = "You have been updated to latest database version! You will need to rescan all your characters again!|r" +L.WarningHeader = "Warning!" diff --git a/modules/minimap.lua b/modules/minimap.lua index 6480c9b..8001bba 100644 --- a/modules/minimap.lua +++ b/modules/minimap.lua @@ -41,13 +41,13 @@ bgsMinimapDD.initialize = function(self, level) PlaySound('gsTitleOptionExit') addButton(level, 'BagSync ', 1, 1) addButton(level, L.Search, nil, 1, nil, 'search', function(frame, ...) - if BagSync_SearchFrame then BagSync_SearchFrame:Show() end + BSYC:GetModule("Search").frame:Show() end) addButton(level, L.Tokens, nil, 1, nil, 'tokens', function(frame, ...) if BagSync_TokensFrame then BagSync_TokensFrame:Show() end end) addButton(level, L.Profiles, nil, 1, nil, 'profiles', function(frame, ...) - BSYC.FrameProfile:Show() + BSYC:GetModule("Profiles").frame:Show() end) addButton(level, L.Professions, nil, 1, nil, 'professions', function(frame, ...) if BagSync_CraftsFrame then BagSync_CraftsFrame:Show() end diff --git a/modules/profiles.lua b/modules/profiles.lua index 9979322..133b0c0 100644 --- a/modules/profiles.lua +++ b/modules/profiles.lua @@ -1,94 +1,97 @@ + local BSYC = select(2, ...) --grab the addon namespace ---BSYC.callbacks = BSYC.callbacks or LibStub("CallbackHandler-1.0"):New(BSYC) +local Profiles = BSYC:NewModule("Profiles") + local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true) local AceGUI = LibStub("AceGUI-3.0") -local bgProfiles = AceGUI:Create("Frame") ---set the defaults for the main frame -bgProfiles:SetTitle(L.Profiles) -bgProfiles:SetHeight(200) -bgProfiles:SetWidth(375) -bgProfiles.statustext:GetParent():Hide() --hide the statusbar background -bgProfiles:EnableResize(false) +function Profiles:OnInitialize() ---lets create our widgets -local warning = AceGUI:Create("Label") -local deleteButton = AceGUI:Create("Button") -local confirmButton = AceGUI:Create("Button") -local ddlist = AceGUI:Create("Dropdown") + --lets create our widgets + local ProfilesFrame = AceGUI:Create("Window") + local warning = AceGUI:Create("Label") + local deleteButton = AceGUI:Create("Button") + local confirmButton = AceGUI:Create("Button") + local ddlist = AceGUI:Create("Dropdown") ---this will populate and fix up the UI a bit -local function CreateProfileWindow() - local tmp = {} - - --add all the accounts, who cares if it's the current user - for realm, rd in pairs(BSYC.db.global) do - for k, v in pairs(rd) do - local key = k.."^"..realm - tmp[key] = k.." - "..(BSYC.db.realmkey[realm] or realm) - end - end - - table.sort(tmp, function(a,b) return (a < b) end) + Profiles.frame = ProfilesFrame + + --add the controls first then edit them + ProfilesFrame:AddChild(warning) + ProfilesFrame:AddChild(ddlist) + ProfilesFrame:AddChild(deleteButton) + ProfilesFrame:AddChild(confirmButton) - --set the list and move the dropdown a bit - ddlist:SetList(tmp) - ddlist:SetWidth(300) - ddlist:ClearAllPoints() - ddlist:SetPoint( "TOPLEFT", bgProfiles.frame, "TOPLEFT", 35, -70) + --set the defaults for the main frame + ProfilesFrame:SetTitle("BagSync "..L.Profiles) + ProfilesFrame:SetHeight(200) + ProfilesFrame:SetWidth(375) + ProfilesFrame:EnableResize(false) - --fix the label a bit + --I wish Ace3 had better methods for modifying the alignment of widgets on a container.... + --list has to be in order for editing, warning, ddlist, deletebutton, confirmbutton, etc.. warning:SetText(L.DeleteWarning) warning:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE) warning:ClearAllPoints() - warning:SetPoint( "CENTER", bgProfiles.frame, "CENTER", 10, 55) + warning:SetPoint( "CENTER", ProfilesFrame.frame, "CENTER", 10, 55) + + ddlist:SetWidth(300) + ddlist:ClearAllPoints() + ddlist:SetPoint( "TOPLEFT", ProfilesFrame.frame, "TOPLEFT", 35, -70) deleteButton:ClearAllPoints() deleteButton:SetPoint("BOTTOMLEFT", ddlist.frame, "LEFT", 0, -50) confirmButton:ClearAllPoints() confirmButton:SetPoint("BOTTOMRIGHT", ddlist.frame, "RIGHT", 0, -50) + + deleteButton:SetText(L.Delete) + deleteButton:SetCallback("OnClick", function() + if not ddlist:GetValue() then BSYC:Print(L.ErrorUserNotFound) return end + confirmButton:SetDisabled(false) + end) -end - -deleteButton:SetText(L.Delete) -deleteButton:SetCallback("OnClick", function() - if not ddlist:GetValue() then BSYC:Print(L.ErrorUserNotFound) return end - confirmButton:SetDisabled(false) -end) + confirmButton:SetText(L.Confirm) + confirmButton:SetCallback("OnClick", function() + if not ddlist:GetValue() then return end -confirmButton:SetText(L.Confirm) -confirmButton:SetCallback("OnClick", function() - if not ddlist:GetValue() then return end + local yName, yRealm = strsplit("^", ddlist:GetValue()) + + --call me paranoid but I want to make sure we have something to work with before we even think of deleting... double checking everything + if yName and string.len(yName) > 0 and yRealm and string.len(yRealm) > 0 then + BSYC.db.global[yRealm][yName] = nil --remove it + BSYC:FixDB() --remove all associated tables from the user + BSYC:Print(L.Profiles.." "..L.Delete.." ["..yName.." - "..(BSYC.db.realmkey[yRealm] or yRealm).."]!") + ddlist:SetValue(nil) --remove the currently selected player from dropdown + ProfilesFrame:Hide() + else + BSYC:Print(L.ErrorUserNotFound) + end + + confirmButton:SetDisabled(true) + end) + confirmButton:SetDisabled(true) - local yName, yRealm = strsplit("^", ddlist:GetValue()) + deleteButton:SetWidth(100) + confirmButton:SetWidth(100) - --call me paranoid but I want to make sure we have something to work with before we even think of deleting... double checking everything - if yName and string.len(yName) > 0 and yRealm and string.len(yRealm) > 0 then - BSYC.db.global[yRealm][yName] = nil --remove it - BSYC:FixDB() --remove all associated tables from the user - BSYC:Print(L.Profiles.." "..L.Delete.." ["..yName.." - "..(BSYC.db.realmkey[yRealm] or yRealm).."]!") - ddlist:SetValue(nil) --remove the currently selected player from dropdown - bgProfiles:Hide() - else - BSYC:Print(L.ErrorUserNotFound) - end + --populate the dropdown + hooksecurefunc(ProfilesFrame, "Show" ,function() + local tmp = {} + + --add all the accounts, who cares if it's the current user + for realm, rd in pairs(BSYC.db.global) do + for k, v in pairs(rd) do + local key = k.."^"..realm + tmp[key] = k.." - "..(BSYC.db.realmkey[realm] or realm) + end + end + + table.sort(tmp, function(a,b) return (a < b) end) + + --set the list and move the dropdown a bit + ddlist:SetList(tmp) + end) - confirmButton:SetDisabled(true) -end) -confirmButton:SetDisabled(true) - -deleteButton:SetWidth(100) -confirmButton:SetWidth(100) - -bgProfiles:AddChild(warning) -bgProfiles:AddChild(ddlist) -bgProfiles:AddChild(deleteButton) -bgProfiles:AddChild(confirmButton) - -hooksecurefunc(bgProfiles, "Show" , function() CreateProfileWindow() end) ---BSYC.RegisterCallback(bgProfiles, "BAGSYNC_LOADED", CreateProfileWindow) - -bgProfiles:Hide() - -BSYC.FrameProfile = bgProfiles \ No newline at end of file + ProfilesFrame:Hide() +end \ No newline at end of file diff --git a/modules/search.lua b/modules/search.lua index 28af5b7..cafd166 100644 --- a/modules/search.lua +++ b/modules/search.lua @@ -1,12 +1,9 @@ -local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true) -local searchTable = {} -local rows, anchor = {} -local currentRealm = select(2, UnitFullName("player")) -local GetItemInfo = _G["GetItemInfo"] -local currentPlayer = UnitName("player") -local bgSearch = CreateFrame("Frame","BagSync_SearchFrame", UIParent) +local BSYC = select(2, ...) --grab the addon namespace +local Search = BSYC:NewModule("Search") +local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true) +local AceGUI = LibStub("AceGUI-3.0") local customSearch = LibStub('CustomSearch-1.0') local ItemSearch = LibStub("LibItemSearch-1.2") @@ -39,131 +36,143 @@ ItemSearch.Filters.class = { end } -local function LoadSlider() +function Search:OnInitialize() - local function OnEnter(self) - if self.link then - GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT") - GameTooltip:SetHyperlink(self.link) - GameTooltip:Show() - end - end - local function OnLeave() GameTooltip:Hide() end + --lets create our widgets + local SearchFrame = AceGUI:Create("Window") + Search.frame = SearchFrame - local EDGEGAP, ROWHEIGHT, ROWGAP, GAP = 16, 20, 2, 4 - local FRAME_HEIGHT = bgSearch:GetHeight() - 60 - local SCROLL_TOP_POSITION = -90 - local totalRows = math.floor((FRAME_HEIGHT-22)/(ROWHEIGHT + ROWGAP)) + SearchFrame:SetTitle("BagSync "..L.Search) + SearchFrame:SetHeight(500) + SearchFrame:SetWidth(380) + SearchFrame:EnableResize(false) - for i=1, totalRows do - if not rows[i] then - local row = CreateFrame("Button", "BagSyncSearchRow"..i, bgSearch) - if not anchor then row:SetPoint("BOTTOMLEFT", bgSearch, "TOPLEFT", 0, SCROLL_TOP_POSITION) - else row:SetPoint("TOP", anchor, "BOTTOM", 0, -ROWGAP) end - row:SetPoint("LEFT", EDGEGAP, 0) - row:SetPoint("RIGHT", -EDGEGAP*2-8, 0) - row:SetHeight(ROWHEIGHT) - row:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") - anchor = row - rows[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("OnEnter", OnEnter) - row:SetScript("OnLeave", OnLeave) - row:SetScript("OnClick", function(self) - if self.link then - if HandleModifiedItemClick(self.link) then - return - end - if IsModifiedClick("CHATLINK") then - local editBox = ChatEdit_ChooseBoxForSend() - if editBox then - editBox:Insert(self.link) - ChatFrame_OpenChat(editBox:GetText()) - end - end - end - end) - end - end - - local offset = 0 - local RefreshSearch = function() - if not BagSync_SearchFrame:IsVisible() then return end - for i,row in ipairs(rows) do - if (i + offset) <= #searchTable then - if searchTable[i + offset] then - if searchTable[i + offset].rarity then - --local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity))) - local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity))) - row.title:SetText(format("|c%s%s|r", hex, searchTable[i + offset].name) or searchTable[i + offset].name) - else - row.title:SetText(searchTable[i + offset].name) - end - row.link = searchTable[i + offset].link - row:Show() - end - else - row.title:SetText(nil) - row:Hide() - end - end - end - - RefreshSearch() - - if not bgSearch.scrollbar then - bgSearch.scrollbar = LibStub("tekKonfig-Scroll").new(bgSearch, nil, #rows/2) - bgSearch.scrollbar:ClearAllPoints() - bgSearch.scrollbar:SetPoint("TOP", rows[1], 0, -16) - bgSearch.scrollbar:SetPoint("BOTTOM", rows[#rows], 0, 16) - bgSearch.scrollbar:SetPoint("RIGHT", -16, 0) - end + local w = AceGUI:Create("SimpleGroup") + w:SetLayout("Flow") + w:SetFullWidth(true) + SearchFrame:AddChild(w) + + local searchbar = AceGUI:Create("EditBox") + searchbar:SetText() + searchbar:SetWidth(255) + searchbar:SetCallback("OnEnterPressed",function(widget) + searchbar:ClearFocus() + self:DoSearch(searchbar:GetText()) + end) - if #searchTable > 0 then - bgSearch.scrollbar:SetMinMaxValues(0, math.max(0, #searchTable - #rows)) - bgSearch.scrollbar:SetValue(0) - bgSearch.scrollbar:Show() - else - bgSearch.scrollbar:Hide() - end + Search.searchbar = searchbar + w:AddChild(searchbar) - local f = bgSearch.scrollbar:GetScript("OnValueChanged") - bgSearch.scrollbar:SetScript("OnValueChanged", function(self, value, ...) - offset = math.floor(value) - RefreshSearch() - return f(self, value, ...) + local refreshbutton = AceGUI:Create("Button") + refreshbutton:SetText(L.Refresh) + refreshbutton:SetWidth(100) + refreshbutton:SetHeight(20) + refreshbutton:SetCallback("OnClick", function() + searchbar:ClearFocus() + self:DoSearch(searchbar:GetText()) end) - - bgSearch:EnableMouseWheel() - bgSearch:SetScript("OnMouseWheel", function(self, val) - bgSearch.scrollbar:SetValue(bgSearch.scrollbar:GetValue() - val*#rows/2) + w:AddChild(refreshbutton) + + local scrollframe = AceGUI:Create("ScrollFrame"); + scrollframe:SetFullWidth(true) + scrollframe:SetLayout("Flow") + + Search.scrollframe = scrollframe + SearchFrame:AddChild(scrollframe) + + local warningframe = AceGUI:Create("Window") + warningframe:SetTitle(L.WarningHeader) + warningframe:SetWidth(300) + warningframe:SetHeight(170) + warningframe.frame:SetParent(SearchFrame.frame) + warningframe:SetLayout("Flow") + warningframe:EnableResize(false) + + local warninglabel = AceGUI:Create("Label") + warninglabel:SetText(L.WarningItemSearch) + warninglabel:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE) + warninglabel:SetColor(1, 165/255, 0) --orange, red is just too much sometimes + warninglabel:SetFullWidth(true) + warningframe:AddChild(warninglabel) + + Search.warningframe = warningframe + Search.warninglabel = warninglabel + + hooksecurefunc(warningframe, "Show" ,function() + --always show the warning frame on the right of the BagSync window + warningframe.frame:ClearAllPoints() + warningframe:SetPoint( "TOPLEFT", SearchFrame.frame, "TOPRIGHT", 0, 0) + end) + + --hide the warning window if they close the search window + SearchFrame:SetCallback("OnClose",function(widget) + warningframe:Hide() end) + + warningframe:Hide() + SearchFrame:Hide() end ---do search routine -local function DoSearch() - if not BagSync or not BagSyncDB then return end - local searchStr = bgSearch.SEARCHBTN:GetText() +function Search:StartSearch(searchStr) + self.frame:Show() + self.searchbar:SetText(searchStr) + self:DoSearch(searchStr) +end - searchStr = searchStr:lower() - - searchTable = {} --reset +function Search:AddEntry(entry, counter) + + local highlightColor = {1, 0, 0} + local label = AceGUI:Create("InteractiveLabel") + + local name, link, rarity, texture = entry.name, entry.link, entry.rarity, entry.texture + local r, g, b, hex = GetItemQualityColor(rarity) + label:SetText(name) + label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE) + label:SetFullWidth(true) + label:SetColor( r, g, b) + label:SetImage(texture) + label:SetCallback( + "OnClick", + function (widget, sometable, button) + if "LeftButton" == button then + print("left") + elseif "RightButton" == button then + print("right") + end + end) + label:SetCallback( + "OnEnter", + function (widget, sometable) + label:SetColor(unpack(highlightColor)) + GameTooltip:SetOwner(label.frame, "ANCHOR_BOTTOMRIGHT") + GameTooltip:SetHyperlink(link) + GameTooltip:Show() + end) + label:SetCallback( + "OnLeave", + function (widget, sometable) + label:SetColor(r, g, b) + GameTooltip:Hide() + end) + + self.scrollframe:AddChild(label) +end + +function Search:DoSearch(searchStr) + local searchStr = searchStr or self.searchbar:GetText() + searchStr = searchStr:lower() + local tempList = {} local previousGuilds = {} local count = 0 local playerSearch = false + local countWarning = 0 + + self.scrollframe:ReleaseChildren() --clear out the scrollframe if strlen(searchStr) > 0 then - local playerFaction = UnitFactionGroup("player") local allowList = { ["bag"] = 0, ["bank"] = 0, @@ -177,17 +186,17 @@ local function DoSearch() if string.len(searchStr) > 1 and string.find(searchStr, "@") and allowList[string.sub(searchStr, 2)] ~= nil then playerSearch = true end - local xDB = BagSync:getFilteredDB() + local xDB = BSYC:FilterDB() --loop through our characters --k = player, v = stored data for player for k, v in pairs(xDB) do - local pFaction = v.faction or playerFaction --just in case ;) if we dont know the faction yet display it anyways + local pFaction = v.faction or BSYC.playerFaction --just in case ;) if we dont know the faction yet display it anyways local yName, yRealm = strsplit("^", k) --check if we should show both factions or not - if BagSyncOpt.enableFaction or pFaction == playerFaction then + if BSYC.options.enableFaction or pFaction == BSYC.playerFaction then --now count the stuff for the user --q = bag name, r = stored data for bag name @@ -201,19 +210,21 @@ local function DoSearch() for slotID, itemValue in pairs(bagInfo) do local dblink, dbcount = strsplit(",", itemValue) if dblink then - local dName, dItemLink, dRarity = GetItemInfo(dblink) - if dName and dItemLink then + local dName, dItemLink, dRarity, _, _, _, _, _, _, dTexture = GetItemInfo(dblink) + if dName then --are we checking in our bank,void, etc? - if playerSearch and string.sub(searchStr, 2) == q and string.sub(searchStr, 2) ~= "guild" and yName == currentPlayer and not tempList[dblink] then - table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } ) + if playerSearch and string.sub(searchStr, 2) == q and string.sub(searchStr, 2) ~= "guild" and yName == BSYC.currentPlayer and not tempList[dblink] then + self:AddEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 --we found a match elseif not playerSearch and not tempList[dblink] and ItemSearch:Matches(dItemLink, searchStr) then - table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } ) + self:AddEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 end + else + countWarning = countWarning + 1 end end end @@ -222,37 +233,40 @@ local function DoSearch() end end - if BagSyncOpt.enableGuild then + if BSYC.options.enableGuild then local guildN = v.guild or nil --check the guild bank if the character is in a guild - if BagSyncGUILD_DB and guildN and BagSyncGUILD_DB[v.realm][guildN] then + if guildN and BSYC.db.guild[v.realm][guildN] then --check to see if this guild has already been done through this run (so we don't do it multiple times) --check for XR/B.Net support - local gName = BagSync:getGuildRealmInfo(guildN, v.realm) + local gName = BSYC:GetGuildRealmInfo(guildN, v.realm) if not previousGuilds[gName] then --we only really need to see this information once per guild - for q, r in pairs(BagSyncGUILD_DB[v.realm][guildN]) do + for q, r in pairs(BSYC.db.guild[v.realm][guildN]) do local dblink, dbcount = strsplit(",", r) if dblink then - local dName, dItemLink, dRarity = GetItemInfo(dblink) + local dName, dItemLink, dRarity, _, _, _, _, _, _, dTexture = GetItemInfo(dblink) if dName then - if playerSearch and string.sub(searchStr, 2) == "guild" and GetGuildInfo("player") and guildN == GetGuildInfo("player") and not tempList[dblink] then - table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } ) + if playerSearch and string.sub(searchStr, 2) == "guild" and BSYC.db.player.guild and guildN == BSYC.db.player.guild and not tempList[dblink] then + self:AddEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 --we found a match elseif not playerSearch and not tempList[dblink] and ItemSearch:Matches(dItemLink, searchStr) then - table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } ) + self:AddEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 end + else + countWarning = countWarning + 1 end end end previousGuilds[gName] = true end + end end @@ -260,98 +274,21 @@ local function DoSearch() end - table.sort(searchTable, function(a,b) return (a.name < b.name) end) - end - - bgSearch.totalC:SetText("|cFFFFFFFF"..L.TooltipTotal.." "..count.."|r") - - LoadSlider() -end - -local function escapeEditBox(self) - self:SetAutoFocus(false) -end - -local function enterEditBox(self) - self:ClearFocus() - --self:GetParent():DoSearch() - DoSearch() -end - -local function createEditBox(name, labeltext, obj, x, y) - local editbox = CreateFrame("EditBox", name, obj, "InputBoxTemplate") - editbox:SetAutoFocus(false) - editbox:SetWidth(180) - editbox:SetHeight(16) - editbox:SetPoint("TOPLEFT", obj, "TOPLEFT", x or 0, y or 0) - local label = editbox:CreateFontString(nil, "ARTWORK", "GameFontNormal") - label:SetPoint("BOTTOMLEFT", editbox, "TOPLEFT", -6, 4) - label:SetText(labeltext) - editbox:SetScript("OnEnterPressed", enterEditBox) - editbox:HookScript("OnEscapePressed", escapeEditBox) - return editbox -end - -bgSearch:SetFrameStrata("HIGH") -bgSearch:SetToplevel(true) -bgSearch:EnableMouse(true) -bgSearch:SetMovable(true) -bgSearch:SetClampedToScreen(true) -bgSearch:SetWidth(380) -bgSearch:SetHeight(500) - -bgSearch: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 } -}) - -bgSearch:SetBackdropColor(0,0,0,1) -bgSearch:SetPoint("CENTER", UIParent, "CENTER", 0, 0) - -bgSearch.SEARCHBTN = createEditBox("$parentEdit1", (L.Search..":"), bgSearch, 60, -50) - -local addonTitle = bgSearch:CreateFontString(nil, "BACKGROUND", "GameFontNormal") -addonTitle:SetPoint("CENTER", bgSearch, "TOP", 0, -20) -addonTitle:SetText("|cFF99CC33BagSync|r |cFFFFFFFF("..L.Search..")|r") - -local totalC = bgSearch:CreateFontString(nil, "BACKGROUND", "GameFontNormal") -totalC:SetPoint("RIGHT", bgSearch.SEARCHBTN, 70, 0) -totalC:SetText("|cFFFFFFFF"..L.TooltipTotal.." 0|r") -bgSearch.totalC = totalC - -local closeButton = CreateFrame("Button", nil, bgSearch, "UIPanelCloseButton"); -closeButton:SetPoint("TOPRIGHT", bgSearch, -15, -8); - -bgSearch:SetScript("OnShow", function(self) - LoadSlider() - self.SEARCHBTN:SetFocus() -end) -bgSearch:SetScript("OnHide", function(self) - searchTable = {} - self.SEARCHBTN:SetText("") - self.totalC:SetText("|cFFFFFFFF"..L.TooltipTotal.." 0|r") -end) + --show warning window if the server hasn't queried all the items yet + if countWarning > 0 then + self.warninglabel:SetText(L.WarningItemSearch:format(countWarning)) + self.warningframe:Show() + else + self.warningframe:Hide() + end -bgSearch:SetScript("OnMouseDown", function(frame, button) - if frame:IsMovable() then - frame.isMoving = true - frame:StartMoving() end -end) - -bgSearch:SetScript("OnMouseUp", function(frame, button) - if( frame.isMoving ) then - frame.isMoving = nil - frame:StopMovingOrSizing() + + --show or hide the scrolling frame depending on count + if strlen(searchStr) > 0 and count > 0 then + self.scrollframe.frame:Show() + else + self.scrollframe.frame:Hide() end -end) - -function bgSearch:initSearch() - DoSearch() -end - -bgSearch:Hide() + +end \ No newline at end of file diff --git a/modules/test.lua b/modules/test.lua index 2062442..740ab93 100644 --- a/modules/test.lua +++ b/modules/test.lua @@ -1,3 +1,4 @@ +local BSYC = select(2, ...) --grab the addon namespace local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true) local testTable = {} local rows, anchor = {} @@ -13,10 +14,11 @@ local frame = AceGUI:Create("Frame") frame:SetTitle("Example Frame") frame:SetStatusText("AceGUI-3.0 Example Container Frame") +frame:EnableResize(false) local scrollframe = AceGUI:Create("ScrollFrame"); scrollframe:SetFullWidth(true) -scrollframe:SetLayout("List") +scrollframe:SetLayout("Flow") frame:AddChild(scrollframe) @@ -29,12 +31,13 @@ local function addEntry(entry, counter) local highlightColor = {1, 0, 0} local label = AceGUI:Create("InteractiveLabel") - local name, link, rarity = entry.name, entry.link, entry.rarity + local name, link, rarity, texture = entry.name, entry.link, entry.rarity, entry.texture label:SetText(name) label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE) label:SetFullWidth(true) label:SetColor(unpack(color)) + label:SetImage(texture) label:SetCallback( "OnClick", function (widget, sometable, button) @@ -60,7 +63,6 @@ local function addEntry(entry, counter) end local function DoSearch() - if not BagSync or not BagSyncDB then return end local searchStr = "red" searchStr = searchStr:lower() @@ -89,7 +91,7 @@ local function DoSearch() if string.len(searchStr) > 1 and string.find(searchStr, "@") and allowList[string.sub(searchStr, 2)] ~= nil then playerSearch = true end - local xDB = BagSync:getFilteredDB() + local xDB = BSYC:FilterDB() --loop through our characters --k = player, v = stored data for player @@ -99,7 +101,7 @@ local function DoSearch() local yName, yRealm = strsplit("^", k) --check if we should show both factions or not - if BagSyncOpt.enableFaction or pFaction == playerFaction then + if BSYC.options.enableFaction or pFaction == playerFaction then --now count the stuff for the user --q = bag name, r = stored data for bag name @@ -113,16 +115,16 @@ local function DoSearch() for slotID, itemValue in pairs(bagInfo) do local dblink, dbcount = strsplit(",", itemValue) if dblink then - local dName, dItemLink, dRarity = GetItemInfo(dblink) + local dName, dItemLink, dRarity, _, _, _, _, _, _, dTexture = GetItemInfo(dblink) if dName then --are we checking in our bank,void, etc? if playerSearch and string.sub(searchStr, 2) == q and string.sub(searchStr, 2) ~= "guild" and yName == currentPlayer and not tempList[dblink] then - addEntry({ name=dName, link=dItemLink, rarity=dRarity }, count) + addEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 --we found a match elseif not playerSearch and not tempList[dblink] and ItemSearch:Matches(dItemLink, searchStr) then - addEntry({ name=dName, link=dItemLink, rarity=dRarity }, count) + addEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 end @@ -136,29 +138,29 @@ local function DoSearch() end end - if BagSyncOpt.enableGuild then + if BSYC.options.enableGuild then local guildN = v.guild or nil --check the guild bank if the character is in a guild - if BagSyncGUILD_DB and guildN and BagSyncGUILD_DB[v.realm][guildN] then + if guildN and BSYC.db.guild[v.realm][guildN] then --check to see if this guild has already been done through this run (so we don't do it multiple times) --check for XR/B.Net support - local gName = BagSync:getGuildRealmInfo(guildN, v.realm) + local gName = BSYC:GetGuildRealmInfo(guildN, v.realm) if not previousGuilds[gName] then --we only really need to see this information once per guild for q, r in pairs(BagSyncGUILD_DB[v.realm][guildN]) do local dblink, dbcount = strsplit(",", r) if dblink then - local dName, dItemLink, dRarity = GetItemInfo(dblink) + local dName, dItemLink, dRarity, _, _, _, _, _, _, dTexture = GetItemInfo(dblink) if dName then if playerSearch and string.sub(searchStr, 2) == "guild" and GetGuildInfo("player") and guildN == GetGuildInfo("player") and not tempList[dblink] then - addEntry({ name=dName, link=dItemLink, rarity=dRarity }, count) + addEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 --we found a match elseif not playerSearch and not tempList[dblink] and ItemSearch:Matches(dItemLink, searchStr) then - addEntry({ name=dName, link=dItemLink, rarity=dRarity }, count) + addEntry({ name=dName, link=dItemLink, rarity=dRarity, texture=dTexture }, count) tempList[dblink] = dName count = count + 1 end @@ -192,9 +194,25 @@ frame:AddChild(OKbutton) --lets create the warning frame. ---local warning = AceGUI:Create("Frame") ---f.statusbg:Hide() ---f:SetWidth(400) f:SetHeight(320) +local warning = AceGUI:Create("Window") +warning:SetTitle(L.WarningHeader) +warning:SetWidth(300) +warning:SetHeight(170) +warning.frame:SetParent(frame.frame) +warning:SetLayout("Flow") +warning:EnableResize(false) + +local warningLabel = AceGUI:Create("Label") +warningLabel:SetText(L.WarningItemSearch) +warningLabel:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE) +warningLabel:SetColor(1, 165/255, 0) --orange, red is just too much sometimes +warningLabel:SetFullWidth(true) +warning:AddChild(warningLabel) + +warning:Hide() + + +frame.warningFrame = warning frame:Hide() -- 1.7.9.5