Skip to content

Commit

Permalink
2.5.0
Browse files Browse the repository at this point in the history
Added option to Colpase the display and only show the total row(s).  Mousing over the display will show the full display.
Added logic to ensure that the filter button is never hidden off screen, it will now move it it was positioned off screen when moving the display position.
Fixed potential frame taint issue.
  • Loading branch information
Noshei committed Sep 24, 2024
1 parent 72f34d5 commit 557f9a3
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 23 deletions.
48 changes: 44 additions & 4 deletions Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ GT.defaults = {
instanceHide = false,
itemsPerHour = false,
goldPerHour = false,
colpaseDisplay = false,
colpaseTime = 2,
},
Notifications = {
Count = {
Expand Down Expand Up @@ -316,9 +318,45 @@ local generalOptions = {
},
header2 = {
type = "header",
name = "Other",
name = "Colpase Display",
order = 200
},
colpaseDisplay = {
type = "toggle",
name = "Colpase Display",
desc = "When selected the display will be colpased to only display the total rows.",
width = 1.70,
get = function() return GT.db.profile.General.colpaseDisplay end,
set = function(_, key)
GT.db.profile.General.colpaseDisplay = key
GT:ColpaseManager(key)
end,
order = 210
},
colpaseTime = {
type = "range",
name = "Colpase Delay",
desc = "This configures how long after the mouse leaves the display area before it clopases to the total rows.\nDefault is 2.",
min = 0,
max = 10,
step = 0.5,
width = 1.40,
get = function() return GT.db.profile.General.colpaseTime or 2 end,
set = function(_, key) GT.db.profile.General.colpaseTime = key end,
disabled = function()
if GT.db.profile.General.colpaseDisplay then
return false
else
return true
end
end,
order = 215
},
header3 = {
type = "header",
name = "Other",
order = 300
},
instanceHide = {
type = "toggle",
name = "Hide in Instance Content",
Expand All @@ -333,7 +371,7 @@ local generalOptions = {
GT.baseFrame.frame:Show()
end
end,
order = 210
order = 310
},
allFiltered = {
type = "toggle",
Expand All @@ -355,7 +393,7 @@ local generalOptions = {
return false
end
end,
order = 220
order = 320
},
},
},
Expand Down Expand Up @@ -515,7 +553,9 @@ local generalOptions = {
get = function() return GT.db.profile.General.numRows or 1 end,
set = function(_, key)
GT.db.profile.General.numRows = key
GT:AllignRows()
if not GT.db.profile.General.colpaseDisplay then
GT:AllignRows()
end
end,
disabled = function()
if not GT.db.profile.General.multiColumn then
Expand Down
94 changes: 94 additions & 0 deletions DisplayColpase.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local GT = LibStub("AceAddon-3.0"):GetAddon("GatheringTracker")

function GT:ColpaseDisplay()
GT.Debug("ColpaseDisplay", 1)
for itemID, itemFrame in pairs(GT.Display.Frames) do
if itemID < 9999999998 then
itemFrame:Hide()
end
if itemID == 9999999998 then
itemFrame:SetPoint("TOPLEFT", GT.baseFrame.backdrop, "TOPLEFT")
end
end
end

function GT:ExpandDisplay()
GT.Debug("ExpandDisplay", 1)
for itemID, itemFrame in pairs(GT.Display.Frames) do
if itemID < 9999999998 then
itemFrame:Show()
end
end
GT:AllignRows()
end

function GT:ColpaseManager(wait)
GT.Debug("ColpaseManager", 1, wait, GT.db.profile.General.colpaseDisplay, GT.db.profile.General.colpaseTime)
if wait then
GT:wait(GT.db.profile.General.colpaseTime, "ColpaseManager", false)
return
end

if GT.db.profile.General.colpaseDisplay then
GT:ColpaseDisplay()
if GT.Display.Frames[9999999998] then
GT.Display.Frames[9999999998]:SetScript("OnEnter", function(self, motion)
if motion then
GT:ExpandDisplay()
GT.baseFrame.frame:SetScript("OnLeave", function(self, motion)
GT:wait(GT.db.profile.General.colpaseTime, "ColpaseManager", false)
GT.baseFrame.frame:SetScript("OnLeave", nil)
GT.baseFrame.frame:SetMouseClickEnabled(false)
end)
GT:ClearMouse()
end
end)
else
GT:SetupTotalsRow()
GT:AllignRows()
GT:AllignColumns()
GT:UpdateBaseFrameSize()
GT:ColpaseManager(false)
end
if GT.Display.Frames[9999999999] then
GT.Display.Frames[9999999999]:SetScript("OnEnter", function(self, motion)
if motion then
GT:ExpandDisplay()
GT.baseFrame.frame:SetScript("OnLeave", function(self, motion)
GT:wait(GT.db.profile.General.colpaseTime, "ColpaseManager", false)
GT.baseFrame.frame:SetScript("OnLeave", nil)
GT.baseFrame.frame:SetMouseClickEnabled(false)
end)
GT:ClearMouse()
end
end)
end
else
GT:ExpandDisplay()
GT:wait(nil, "ColpaseManager")

GT.baseFrame.frame:SetScript("OnLeave", nil)

GT:ClearMouse()

if #GT.Display.Order == 1 then
GT:PrepareDataForDisplay("ColpaseManager", false)
end
end
end

function GT:ClearMouse()
GT.baseFrame.frame:SetMouseClickEnabled(false)

if GT.Display.Frames[9999999998] then
GT.Display.Frames[9999999998]:SetScript("OnEnter", nil)
GT.Display.Frames[9999999998]:SetMouseClickEnabled(false)
GT.Display.Frames[9999999998]:SetMouseMotionEnabled(false)
end

if GT.Display.Frames[9999999999] then
GT.Display.Frames[9999999999]:SetScript("OnEnter", nil)
GT.Display.Frames[9999999999]:SetMouseClickEnabled(false)
GT.Display.Frames[9999999999]:SetMouseMotionEnabled(false)
end
end
7 changes: 4 additions & 3 deletions DisplayCreation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ local function FramePool_Resetter(framePool, frame)
if frame.priceTotalItem then
frame.priceTotalItem = nil
end
frame:SetScript("OnEnter", nil)
frame:SetMouseClickEnabled(false)
frame:SetMouseMotionEnabled(false)
end

local function InitializePools()
function GT:InitializePools()
GT.Pools.framePool = GT.Pools.framePool or CreateFramePool("Frame", GT.baseFrame.frame, nil, FramePool_Resetter)
GT.Pools.texturePool = GT.Pools.texturePool or CreateTexturePool(GT.baseFrame.frame, "BACKGROUND")
GT.Pools.fontStringPool = GT.Pools.fontStringPool or CreateFontStringPool(GT.baseFrame.frame, "BACKGROUND")
Expand Down Expand Up @@ -76,8 +79,6 @@ function GT:CreateDisplayFrame(id, iconId, iconQuality, iconRarity, displayText,
return
end

InitializePools()

local frame = GT:DisplayFrameBase(id)

frame.displayedCharacters = #displayText
Expand Down
24 changes: 23 additions & 1 deletion FilterButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function GT:FiltersButton(profileChanged)
end

GT.Debug("Create Filters Button", 1)
local filterButton = CreateFrame("Button", "GT_baseFrame_filtersButton", GT.baseFrame.frame, "UIPanelButtonTemplate")
local filterButton = CreateFrame("Button", "GT_baseFrame_filtersButton", UIParent, "UIPanelButtonTemplate")
filterButton:SetPoint("BOTTOMRIGHT", GT.baseFrame.backdrop, "TOPLEFT")
filterButton:SetWidth(25)
filterButton:SetHeight(25)
Expand All @@ -60,6 +60,28 @@ function GT:FiltersButton(profileChanged)
GT:FiltersButtonFade()
end

function GT:AnchorFilterButton()
-- 25 is the size of the filter button, so if any part of the button is off screen it will be moved
local UITop = UIParent:GetTop() - 25
local UILeft = UIParent:GetLeft() + 25
local backdropTop = GT.baseFrame.backdrop:GetTop()
local backdropLeft = GT.baseFrame.backdrop:GetLeft()

if backdropTop >= UITop and backdropLeft <= UILeft then
GT.Debug("Display Location", 1, "Top Left", UITop, UILeft, backdropTop, backdropLeft)
local left, bottom, width, height = GT.baseFrame.frame:GetBoundsRect()
GT.baseFrame.button:SetPoint("BOTTOMRIGHT", GT.baseFrame.backdrop, "TOPLEFT", 25, -1 * (height + 25))
elseif backdropTop >= UITop then
GT.Debug("Display Location", 1, "Top", UITop, UILeft, backdropTop, backdropLeft)
GT.baseFrame.button:SetPoint("BOTTOMRIGHT", GT.baseFrame.backdrop, "TOPLEFT", 0, -25)
elseif backdropLeft <= UILeft then
GT.Debug("Display Location", 1, "Left", UITop, UILeft, backdropTop, backdropLeft)
GT.baseFrame.button:SetPoint("BOTTOMRIGHT", GT.baseFrame.backdrop, "TOPLEFT", 25, 0)
else
GT.baseFrame.button:SetPoint("BOTTOMRIGHT", GT.baseFrame.backdrop, "TOPLEFT")
end
end

function GT:GenerateFiltersMenu(frame)
local function FiltersMenu(frame, rootDescription)
for expansionIndex, expansion in ipairs(GT.expansionsOrder) do
Expand Down
62 changes: 48 additions & 14 deletions GatheringTracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function GT:PLAYER_ENTERING_WORLD()

GT:wait(6, "InventoryUpdate", "PLAYER_ENTERING_WORLD", false)
GT:wait(7, "NotificationHandler", "PLAYER_ENTERING_WORLD")
GT:wait(7, "AnchorFilterButton", "PLAYER_ENTERING_WORLD")
end

function GT:GROUP_ROSTER_UPDATE(event, wait)
Expand Down Expand Up @@ -112,8 +113,11 @@ function GT:CreateBaseFrame()
--this creates the basic frame structure that the addon uses.
--the backdrop is used for positioning through the addon options.
local frame = CreateFrame("Frame", "GT_baseFrame", UIParent)
frame:SetFrameStrata("BACKGROUND")
frame:SetFrameLevel(0)
frame:SetMouseClickEnabled(false)

local backdrop = CreateFrame("Frame", "GT_baseFrame_backdrop", frame, BackdropTemplateMixin and "BackdropTemplate")
local backdrop = CreateFrame("Frame", "GT_baseFrame_backdrop", UIParent, BackdropTemplateMixin and "BackdropTemplate")
backdrop:SetWidth(300)
backdrop:SetHeight(300)
backdrop:SetPoint(GT.db.profile.General.relativePoint, UIParent, GT.db.profile.General.relativePoint, GT.db.profile.General.xPos, GT.db.profile.General.yPos)
Expand All @@ -129,27 +133,60 @@ function GT:CreateBaseFrame()
backdrop:SetBackdropBorderColor(0.4, 0.4, 0.4)
backdrop:SetFrameStrata("FULLSCREEN_DIALOG")
backdrop:SetClampedToScreen(true)
backdrop:SetMouseClickEnabled(false)

backdrop:Hide()

frame:SetPoint("TOPLEFT", backdrop, "TOPLEFT")
frame:Show()
frame:SetMouseClickEnabled(false)

local baseFrame = {
frame = frame,
backdrop = backdrop,
}
GT.baseFrame = baseFrame

GT:FiltersButton()
GT:InitializePools()
end

function GT:UpdateBaseFrameSize()
--Have to reset to 0 otherwise the size will never shrink
GT.baseFrame.frame:SetHeight(0)
GT.baseFrame.frame:SetWidth(0)

local left, bottom, width, height = GT.baseFrame.frame:GetBoundsRect()
GT.baseFrame.frame:SetHeight(height)
GT.baseFrame.frame:SetWidth(width)
end

function GT:ToggleBaseLock(key)
--used to toggle if the base frame should be shown and interactable.
--the base frame should only be shown when unlocked so that the user can position it on screen where they want.
local frame = GT.baseFrame.backdrop

local function stoppedMoving(self)
self:StopMovingOrSizing()
self.isMoving = false
local rel, _, _, xPos, yPos = self:GetPoint()
GT.db.profile.General.xPos = xPos
GT.db.profile.General.yPos = yPos
GT.db.profile.General.relativePoint = rel

--Return if Filter Button is disabled, we only need to do the rest if it is enabled
if not GT.db.profile.General.filtersButton then
return
end
GT:AnchorFilterButton()
end

if key then
GT.Debug("Show baseFrame", 1)
frame:Show()
frame:SetMovable(true)
frame:EnableMouse(true)
frame:SetMouseClickEnabled(true)
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and not self.isMoving then
self:StartMoving()
Expand All @@ -158,29 +195,20 @@ function GT:ToggleBaseLock(key)
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" and self.isMoving then
self:StopMovingOrSizing()
self.isMoving = false
local rel, _, _, xPos, yPos = self:GetPoint()
GT.db.profile.General.xPos = xPos
GT.db.profile.General.yPos = yPos
GT.db.profile.General.relativePoint = rel
stoppedMoving(self)
end
end)
frame:SetScript("OnHide", function(self)
if self.isMoving then
self:StopMovingOrSizing()
self.isMoving = false
local rel, _, _, xPos, yPos = self:GetPoint()
GT.db.profile.General.xPos = xPos
GT.db.profile.General.yPos = yPos
GT.db.profile.General.relativePoint = rel
stoppedMoving(self)
end
end)
else
GT.Debug("Hide baseFrame", 1)
frame:Hide()
frame:SetMovable(false)
frame:EnableMouse(false)
frame:SetMouseClickEnabled(false)
frame:SetScript("OnMouseDown", nil)
frame:SetScript("OnMouseUp", nil)
frame:SetScript("OnHide", nil)
Expand Down Expand Up @@ -327,6 +355,7 @@ function GT:AllignRows()
end
end
end
GT:UpdateBaseFrameSize()
end

function GT:AllignColumns()
Expand All @@ -339,6 +368,7 @@ function GT:AllignColumns()
end
end
GT:SetDisplayFrameWidth()
GT:UpdateBaseFrameSize()
end

function GT:SetDisplayFrameWidth()
Expand Down Expand Up @@ -523,6 +553,10 @@ function GT:PrepareDataForDisplay(event, wait)

GT:AllignRows()
GT:AllignColumns()
GT:UpdateBaseFrameSize()
if GT.db.profile.General.colpaseDisplay then
GT:ColpaseManager(false)
end
end

function GT:SetupItemRows()
Expand Down Expand Up @@ -617,7 +651,7 @@ function GT:SetupTotalsRow()
priceTotal = priceTotal + playerPrice
end
totalItemCount = GT:SumTable(playerTotals)
if totalItemCount > 0 then
if totalItemCount > 0 or GT.db.profile.General.colpaseDisplay then
local itemsPerHour, goldPerHour = GT:CalculateItemsPerHourTotal(totalItemCount)

GT:InitiateFrameProcess(
Expand Down
Loading

0 comments on commit 557f9a3

Please sign in to comment.