Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix.0.1.8 2 #216

Merged
merged 5 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
libs\LibUIDropDownMenu\LibUIDropDownMenu.xml

templates\container.xml
templates\debug.xml

core\boot.lua

Expand Down
3 changes: 3 additions & 0 deletions BetterBags_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
libs\LibUIDropDownMenu\LibUIDropDownMenu.xml

templates\classic\container.xml
templates\classic\debug.xml
templates\debug.xml


core\boot.lua

Expand Down
2 changes: 2 additions & 0 deletions BetterBags_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
libs\LibUIDropDownMenu\LibUIDropDownMenu.xml

templates\classic\container.xml
templates\classic\debug.xml
templates\debug.xml

core\boot.lua

Expand Down
14 changes: 14 additions & 0 deletions annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ MainMenuBarBackpackButton = {}
---@class BagBarExpandToggle: Button
BagBarExpandToggle = {}

---@class BetterBagsDebugListButton: Button
---@field RowNumber FontString
---@field Category FontString
---@field Message FontString

---@class ScrollingFlatPanelTemplate: Frame
---@field ScrollBox WowScrollBox
---@field ScrollBar MinimalScrollBar

---@class DLAPI
DLAPI = {}

Expand Down Expand Up @@ -154,6 +163,11 @@ function WowScrollBox:ScrollInDirection(percent, direction) end
function WowScrollBox:FullUpdate() end
function WowScrollBox:OnMouseWheel(delta) end
function WowScrollBox:ScrollToEnd() end
---@return Texture
function WowScrollBox:GetUpperShadowTexture() end
---@return Texture
function WowScrollBox:GetLowerShadowTexture() end
function WowScrollBox:SetDataProvider(provider) end

---@class Frame
---@field scrollable boolean
Expand Down
11 changes: 10 additions & 1 deletion data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ local equipmentSets = addon:GetModule('EquipmentSets')
---@class Database: AceModule
local database = addon:GetModule('Database')

---@class Localization: AceModule
local L = addon:GetModule('Localization')

---@class Debug: AceModule
local debug = addon:GetModule('Debug')

Expand Down Expand Up @@ -249,6 +252,11 @@ function items:HasItemChanged(bagid, slotid, data)
return true
end

if data.itemInfo and data.itemInfo.category == L:G("Recent Items") and not self:IsNewItem(data) then
debug:Log("ItemChange", itemLink, "Not Recent Item")
return true
end

return false
end

Expand Down Expand Up @@ -411,8 +419,9 @@ end
---@return boolean
function items:IsNewItem(data)
if not data then return false end
if data.isItemEmpty then return false end
if (self._newItemTimers[data.itemInfo.itemGUID] ~= nil and time() - self._newItemTimers[data.itemInfo.itemGUID] < database:GetNewItemTime()) or
data.itemInfo.isNewItem then
C_NewItems.IsNewItem(data.bagid, data.slotid) then
return true
end
self._newItemTimers[data.itemInfo.itemGUID] = nil
Expand Down
1 change: 1 addition & 0 deletions frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function bagFrame.bagProto:Sort()
PlaySound(SOUNDKIT.UI_BAG_SORTING_01)
items:RemoveNewItemFromAllItems()
C_Container:SortBags()
items:RefreshAll()

for _, item in pairs(lockList) do
item:Lock()
Expand Down
125 changes: 34 additions & 91 deletions frames/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,33 @@ local addonName = ... ---@type string
---@class BetterBags: AceAddon
local addon = LibStub('AceAddon-3.0'):GetAddon(addonName)

---@class GridFrame: AceModule
local grid = addon:GetModule('Grid')

---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Database: AceModule
local database = addon:GetModule('Database')

---@class DebugCell
---@field frame Frame
---@field row FontString
---@field category FontString
---@field message FontString
local debugCell = {}

---@class DebugWindow: AceModule
---@field frame Frame
---@field content Grid
---@field frame ScrollingFlatPanelTemplate
---@field rows number
---@field _pool ObjectPool
local debugWindow = addon:NewModule('DebugWindow')

---@return DebugCell
function debugWindow:NewCell()
local cell = setmetatable({}, { __index = debugCell }) --[[@as DebugCell]]
cell.frame = CreateFrame("Frame", nil)
cell.frame:SetSize(self.content:GetContainer():GetWidth(), 20)
cell.frame:SetScript("OnMouseWheel", function(_, delta)
self.content:GetContainer():OnMouseWheel(delta)
end)
cell.frame:EnableMouse(true)
cell.row = cell.frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
cell.row:SetPoint("LEFT", 0, 0)
cell.row:SetText(format("%s", self.rows))
cell.row:SetTextColor(1, 1, 1)
cell.row:SetWidth(30)
cell.row:SetJustifyH("LEFT")
cell.category = cell.frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
cell.category:SetPoint("LEFT", cell.row, "RIGHT", 10, 0)
cell.category:SetJustifyH("LEFT")
cell.category:SetTextColor(1, 1, 1)
cell.category:SetWidth(120)
cell.category:SetWordWrap(false)
cell.category:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
cell.message = cell.frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
cell.message:SetPoint("LEFT", cell.category, "RIGHT", 5, 0)
cell.message:SetTextColor(0.8, 0.8, 0.8)
return cell
end

function debugWindow:_ResetCell(cell)
cell.frame:Hide()
end

function debugWindow:SetupPool()
print("BetterBags: Creating Debug Pool")
self._pool = CreateObjectPool(function() return self:NewCell() end, self._ResetCell)
self._pool:SetResetDisallowedIfNew(true)
---@type DebugCell[]
local objs = {}
for _ = 1, 1000 do
local o = self._pool:Acquire()
table.insert(objs, o)
end
for _, o in pairs(objs) do
self._pool:Release(o)
end
---@param button BetterBagsDebugListButton
---@param elementData table
local function initDebugListItem(button, elementData)
button.RowNumber:SetText(format("%s", elementData.row))
button.Category:SetText(elementData.title)
button.Category:SetPoint("LEFT", button.RowNumber, "RIGHT", 10, 0)
button.Message:SetText(elementData.message)
button.Message:SetPoint("LEFT", button.Category, "RIGHT", 10, 0)
end

function debugWindow:Create()
self.frame = CreateFrame("Frame", "BetterBagsDebugWindow", UIParent, "DefaultPanelFlatTemplate") --[[@as Frame]]
self.cells = {}
self.rows = 0
self.provider = CreateDataProvider()
self.frame = CreateFrame("Frame", "BetterBagsDebugWindow", UIParent, "ScrollingFlatPanelTemplate") --[[@as ScrollingFlatPanelTemplate]]
self.frame:SetPoint("CENTER")
self.frame:SetSize(800, 600)
self.frame:SetMovable(true)
Expand All @@ -85,33 +38,31 @@ function debugWindow:Create()
self.frame:SetScript("OnDragStart", self.frame.StartMoving)
self.frame:SetScript("OnDragStop", self.frame.StopMovingOrSizing)
self.frame:SetTitle("BetterBags Debug Window")
self.rows = 0

self.content = grid:Create(self.frame)
self.content:GetContainer():SetPoint("TOPLEFT", 10, -35)
self.content:GetContainer():SetPoint("BOTTOMRIGHT", -10, 10)
self.content.maxCellWidth = 1

self.frame.ScrollBox:SetInterpolateScroll(true)
self.frame.ScrollBar:SetInterpolateScroll(true)
local view = CreateScrollBoxListLinearView()
view:SetElementInitializer("BetterBagsDebugListButton", initDebugListItem)
view:SetPadding(4,4,8,4,0)
ScrollUtil.InitScrollBoxListWithScrollBar(self.frame.ScrollBox, self.frame.ScrollBar, view)
self.frame.ScrollBox:GetUpperShadowTexture():ClearAllPoints()
self.frame.ScrollBox:GetLowerShadowTexture():ClearAllPoints()
self.frame.ScrollBox:SetDataProvider(self.provider)

events:GroupBucketEvent({}, {'debug/LogAdded'}, function()
self.provider:InsertTable(self.cells)
wipe(self.cells)
self.frame.ScrollBox:ScrollToEnd()
end)
events:RegisterMessage('config/DebugMode', function(_, enabled)
if enabled then
self.frame:Show()
if not self._pool then
self:SetupPool()
end
else
self.frame:Hide()
end
end)

events:GroupBucketEvent({}, {'debug/LogLineAdded'}, function()
self.content:Draw()
self.content:GetContainer():FullUpdate()
self.content:GetContainer():ScrollToEnd()
end)

if database:GetDebugMode() then
self.frame:Show()
debugWindow:SetupPool()
else
self.frame:Hide()
end
Expand All @@ -122,19 +73,11 @@ function debugWindow:AddLogLine(title, message)
if not self.frame:IsVisible() then
return
end
local cell = self._pool:Acquire()

cell.row:SetText(format("%s", self.rows))
cell.category:SetText(format("%s", title))
cell.category:SetScript("OnEnter", function()
GameTooltip:SetOwner(cell.frame, "ANCHOR_LEFT")
GameTooltip:SetText(title)
GameTooltip:Show()
end)

cell.message:SetText(message)

self.content:AddCell(tostring(self.rows), cell)
table.insert(self.cells, {
row=self.rows,
title=title,
message=message
})
self.rows = self.rows + 1
events:SendMessageLater('debug/LogLineAdded')
events:SendMessage('debug/LogAdded')
end
4 changes: 2 additions & 2 deletions integrations/pawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local pawn = addon:NewModule('Pawn')
---@param item Item
local function onItemUpdateRetail(event, item)
local bagid, slotid = item.data.bagid, item.data.slotid
if item.data.isItemEmpty or event == 'item/Clearing' then
if item.data.isItemEmpty or event == 'item/Clearing' or not bagid or not slotid then
item.button.UpgradeIcon:SetShown(false)
else
item.button.UpgradeIcon:SetShown(PawnIsContainerItemAnUpgrade(bagid, slotid) or false)
Expand All @@ -23,7 +23,7 @@ end
---@param event string
---@param item Item
local function onItemUpdateClassic(event, item)
if item.data.isItemEmpty or event == 'item/Clearing' then
if item.data.isItemEmpty or event == 'item/Clearing' or not item.data.slotid or not item.data.bagid then
item.button.UpgradeIcon:SetShown(false)
else
local pawnData = PawnGetItemData(item.data.itemInfo.itemLink)
Expand Down
96 changes: 96 additions & 0 deletions templates/classic/ScrollingFlatPanel.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---@diagnostic disable: duplicate-set-field,duplicate-doc-field
local ScrollBarWidth = 16;

ScrollingFlatPanelMixin = {};

function ScrollingFlatPanelMixin:OnLoad()
self:SetTitle(self.panelTitle);

self.onCloseCallback = function(_)
self:OnCloseCallback();
return false;
end

self.HideAnim:SetScript("OnFinished", function()
self:OnHideAnimFinished();
end);
end

function ScrollingFlatPanelMixin:OnCloseCallback()
self:PlayCloseAnimation();
end

function ScrollingFlatPanelMixin:Open(skipShow)
self.isOpen = true;

-- Managing the visibility of this panel may occur manually
-- in some special cases, such as EditMode.
if not skipShow then
self:Show();
end

self:Resize();
self:PlayOpenAnimation();
end

function ScrollingFlatPanelMixin:Resize()
local anchors = 26;
local extra = 20;
---@type number
local height = self:CalculateElementsHeight() + anchors + extra;
self:SetHeight(math.min(height, self.panelMaxHeight));

---@type boolean
local showScrollBar = self.ScrollBox:HasScrollableExtent();
self:SetWidth(self.panelWidth + (showScrollBar and ScrollBarWidth or 0));

self.ScrollBar:SetShown(showScrollBar);

---@type CallbackRegistryMixin|unknown
local view = self.ScrollBox:GetView();
---@type table<string, number>
local padding = view:GetPadding();
self.ScrollBox:SetWidth(self.panelWidth - padding.left);
end

function ScrollingFlatPanelMixin:GetMaxPossibleWidth()
return self.panelWidth + ScrollBarWidth;
end

function ScrollingFlatPanelMixin:OnHideAnimFinished()
HideUIPanel(self);
end

function ScrollingFlatPanelMixin:StopAllAnimations()
self.ShowAnim:Stop();
self.HideAnim:Stop();
end

function ScrollingFlatPanelMixin:PlayOpenAnimation()
self.HideAnim:Stop();

local reverse = true;
self.ShowAnim:Play(reverse);
end

function ScrollingFlatPanelMixin:PlayCloseAnimation()
self.ShowAnim:Stop();

local reverse = false;
self.HideAnim:Play(reverse);
end

function ScrollingFlatPanelMixin:Close()
self.isOpen = false;

self:PlayCloseAnimation();
end

function ScrollingFlatPanelMixin:GetPanelMaxHeight()
assert(self.panelMaxHeight ~= nil, "panelMaxHeight was not assigned.")
return self.panelMaxHeight;
end

function ScrollingFlatPanelMixin:CalculateElementsHeight()
error("Requires implementation of ScrollingFlatPanelMixin:CalculateElementsHeight.");
end
Loading