From 887d1c8f417cbc32bc688a1d12fc5589cf392891 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Wed, 19 Nov 2025 21:36:16 +0400 Subject: [PATCH] display only current realm characters --- Core/Database.lua | 16 ++++++++++------ Core/Tooltip.lua | 7 ++++--- Data/MoneyTracker.lua | 6 +++--- UI/BagFrame.lua | 18 +++++++++--------- UI/BankFrame.lua | 14 +++++++------- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Core/Database.lua b/Core/Database.lua index 4c6d227..0ae8c87 100644 --- a/Core/Database.lua +++ b/Core/Database.lua @@ -160,11 +160,13 @@ function DB:SaveMoney(copper) end end --- Get all characters (optionally filter by faction) -function DB:GetAllCharacters(sameFactionOnly) +-- Get all characters (optionally filter by faction and/or realm) +function DB:GetAllCharacters(sameFactionOnly, currentRealmOnly) local chars = {} for fullName, data in pairs(Guda_DB.characters) do - if not sameFactionOnly or data.faction == playerFaction then + local factionMatch = not sameFactionOnly or data.faction == playerFaction + local realmMatch = not currentRealmOnly or data.realm == playerRealm + if factionMatch and realmMatch then table.insert(chars, { fullName = fullName, name = data.name, @@ -211,11 +213,13 @@ function DB:GetCharacterInfo(fullName) return char and char.character or {} end --- Get total money across all characters -function DB:GetTotalMoney(sameFactionOnly) +-- Get total money across all characters (optionally filter by faction and/or realm) +function DB:GetTotalMoney(sameFactionOnly, currentRealmOnly) local total = 0 for fullName, data in pairs(Guda_DB.characters) do - if not sameFactionOnly or data.faction == playerFaction then + local factionMatch = not sameFactionOnly or data.faction == playerFaction + local realmMatch = not currentRealmOnly or data.realm == playerRealm + if factionMatch and realmMatch then total = total + (data.money or 0) end end diff --git a/Core/Tooltip.lua b/Core/Tooltip.lua index e90076e..533ce93 100644 --- a/Core/Tooltip.lua +++ b/Core/Tooltip.lua @@ -188,11 +188,12 @@ function Tooltip:AddInventoryInfo(tooltip, link) local hasAnyItems = false local currentPlayerName = addon.Modules.DB:GetPlayerFullName() + local currentRealm = GetRealmName() - -- Count items across all characters with safety checks + -- Count items across characters on current realm only for charName, charData in pairs(Guda_DB.characters) do - -- Ensure charData is actually a table before processing - if type(charData) == "table" then + -- Ensure charData is actually a table and on current realm + if type(charData) == "table" and charData.realm == currentRealm then local isCurrentChar = (charName == currentPlayerName) local bagCount, bankCount, equippedCount = CountItemsForCharacter(itemID, charData, isCurrentChar) diff --git a/Data/MoneyTracker.lua b/Data/MoneyTracker.lua index 77beae5..0ecc772 100644 --- a/Data/MoneyTracker.lua +++ b/Data/MoneyTracker.lua @@ -24,9 +24,9 @@ function MoneyTracker:GetCurrentMoney() return GetMoney() end --- Get total money across all characters -function MoneyTracker:GetTotalMoney(sameFactionOnly) - return addon.Modules.DB:GetTotalMoney(sameFactionOnly) +-- Get total money across all characters (optionally filter by faction and/or realm) +function MoneyTracker:GetTotalMoney(sameFactionOnly, currentRealmOnly) + return addon.Modules.DB:GetTotalMoney(sameFactionOnly, currentRealmOnly) end -- Initialize money tracker diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index cfbecd2..f2b2560 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -659,13 +659,13 @@ function Guda_BagFrame_MoneyOnEnter(self) GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT", 0, 0) GameTooltip:ClearLines() - -- Get all characters and total - local chars = addon.Modules.DB:GetAllCharacters(true) - local totalMoney = addon.Modules.DB:GetTotalMoney(true) + -- Get all characters and total (faction + realm filtered) + local chars = addon.Modules.DB:GetAllCharacters(true, true) + local totalMoney = addon.Modules.DB:GetTotalMoney(true, true) - -- Header with faction/realm total - use colored money + -- Header with current realm total - use colored money GameTooltip:AddLine( - "Faction/realm-wide gold: " .. addon.Modules.Utils:FormatMoney(totalMoney, false, true), + "Current realm gold: " .. addon.Modules.Utils:FormatMoney(totalMoney, false, true), 1, 0.82, 0 ) GameTooltip:AddLine(" ") @@ -732,8 +732,8 @@ function Guda_BagFrame_ToggleCharacterDropdown(button) end characterDropdown.buttons = {} - -- Get all characters - local chars = addon.Modules.DB:GetAllCharacters(true) + -- Get all characters on current realm + local chars = addon.Modules.DB:GetAllCharacters(true, true) -- Add "Current Character" option at the top local yOffset = -8 @@ -900,8 +900,8 @@ function Guda_BagFrame_ToggleBankDropdown(button) end bankDropdown.buttons = {} - -- Get all characters - local chars = addon.Modules.DB:GetAllCharacters(true) + -- Get all characters on current realm + local chars = addon.Modules.DB:GetAllCharacters(true, true) local yOffset = -8 diff --git a/UI/BankFrame.lua b/UI/BankFrame.lua index e24b6d8..3efc838 100644 --- a/UI/BankFrame.lua +++ b/UI/BankFrame.lua @@ -382,13 +382,13 @@ function Guda_BankFrame_MoneyOnEnter(self) GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT", 0, 0) GameTooltip:ClearLines() - -- Get all characters and total - local chars = addon.Modules.DB:GetAllCharacters(true) - local totalMoney = addon.Modules.DB:GetTotalMoney(true) + -- Get all characters and total (faction + realm filtered) + local chars = addon.Modules.DB:GetAllCharacters(true, true) + local totalMoney = addon.Modules.DB:GetTotalMoney(true, true) - -- Header with faction/realm total - use colored money + -- Header with current realm total - use colored money GameTooltip:AddLine( - "Faction/realm-wide gold: " .. addon.Modules.Utils:FormatMoney(totalMoney, false, true), + "Current realm gold: " .. addon.Modules.Utils:FormatMoney(totalMoney, false, true), 1, 0.82, 0 ) GameTooltip:AddLine(" ") @@ -1215,8 +1215,8 @@ function Guda_BankFrame_ToggleBankDropdown(button) end bankCharDropdown.buttons = {} - -- Get all characters - local chars = addon.Modules.DB:GetAllCharacters(true) + -- Get all characters on current realm + local chars = addon.Modules.DB:GetAllCharacters(true, true) local yOffset = -8