diff --git a/Titan/TitanGlobal.lua b/Titan/TitanGlobal.lua index 2588389..577c4e4 100644 --- a/Titan/TitanGlobal.lua +++ b/Titan/TitanGlobal.lua @@ -166,15 +166,21 @@ Titan_Global.literals = { Titan_Global.colors = { alliance = "00adf0", -- PLAYER_FACTION_COLOR_ALLIANCE blue = "0000ff", -- PURE_BLUE_COLOR + blue_light = "69ccf0", coin_gold = "ffd100", coin_silver = "e6e6e6", coin_copper = "c8602c", + copper = "b87333", gold = "f2e699", -- GOLD_FONT_COLOR gray = "808080", -- GRAY_FONT_COLOR green = "19ff19", -- GREEN_FONT_COLOR horde = "ff2934", -- PLAYER_FACTION_COLOR_HORDE orange = "ff8c00", + pink = "f48cb78", + purple = "949cc9", + tan = "c79c6e", red = "ff2020", -- RED_FONT_COLOR + silver = "cccccc", white = "ffffff", -- HIGHLIGHT_FONT_COLOR yellow_gold = "ffd200", -- NORMAL_FONT_COLOR yellow = "ffff00", -- YELLOW_FONT_COLOR diff --git a/Titan/TitanHistory.lua b/Titan/TitanHistory.lua index 95c2207..494b642 100644 --- a/Titan/TitanHistory.lua +++ b/Titan/TitanHistory.lua @@ -20,7 +20,6 @@ Titan_Global.recent_changes = "" .. TitanUtils_GetHighlightText("" .. "- Updated TOC files to use *_Classic; single TOC file for Classic versions" ) -.. "\n\n" .. TitanUtils_GetGreenText("Gold : \n") .. TitanUtils_GetHighlightText("" .. "- Retail ONLY - Added Warband bank at bottom of list for totals.\n" @@ -29,6 +28,12 @@ Titan_Global.recent_changes = "" .. "- Show and Delete toon menus sort per user options.\n" .. "- Shift + Left click will put the connected server list into Chat (also in Plugin Notes).\n" ) +.. TitanUtils_GetGreenText("Bags : \n") +.. TitanUtils_GetHighlightText("" +.. "- Retail ONLY : Added Reagent Bag slot.\n" +.. "- All : Removed profession count option.\n" +.. "- All : Profession counts are in Detailed Tooltip as grey - NOT added to free / used totals.\n" +) .. TitanUtils_GetGreenText("Regen : \n") .. TitanUtils_GetHighlightText("" .. "- Cleanup documentation (comments); made some routines local.\n" diff --git a/TitanBag/TitanBag.lua b/TitanBag/TitanBag.lua index dd99751..525e31f 100644 --- a/TitanBag/TitanBag.lua +++ b/TitanBag/TitanBag.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field -- ************************************************************************** -- * TitanBag.lua -- * @@ -7,103 +8,74 @@ -- ******************************** Constants ******************************* local _G = getfenv(0); local TITAN_BAG_ID = "Bag"; -local TITAN_BUTTON = "TitanPanel"..TITAN_BAG_ID.."Button" +local TITAN_BUTTON = "TitanPanel" .. TITAN_BAG_ID .. "Button" local TITAN_BAG_THRESHOLD_TABLE = { Values = { 0.5, 0.75, 0.9 }, Colors = { HIGHLIGHT_FONT_COLOR, NORMAL_FONT_COLOR, ORANGE_FONT_COLOR, RED_FONT_COLOR }, } +local L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true) --local updateTable = {TITAN_BAG_ID, TITAN_PANEL_UPDATE_BUTTON}; + -- ******************************** Variables ******************************* --local AceTimer = LibStub("AceTimer-3.0") -local L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true) ---local BagTimer - -local bag_info = { -- itemType : warcraft.wiki.gg/wiki/itemType - [1] = -- Soul bag - { color = {r=0.96,g=0.55,b=0.73}}, -- PINK - [2] = -- HERBALISM = - { color = {r=0,g=1,b=0}}, -- GREEN - [3] = -- ENCHANTING = - { color = {r=0,g=0,b=1}}, -- BLUE - [4] = -- ENGINEERING = - { color = {r=1,g=0.49,b=0.04}}, -- ORANGE - [5] = -- JEWELCRAFTING = - { color = {r=1,g=0,b=0}}, -- RED - [6] = -- MINING = - { color = {r=1,g=1,b=1}}, -- WHITE - [7] = -- LEATHERWORKING = - { color = {r=0.78,g=0.61,b=0.43}}, -- TAN - [8] = -- INSCRIPTION = - { color = {r=0.58,g=0.51,b=0.79}}, -- PURPLE - [9] = -- FISHING = - { color = {r=0.41,g=0.8,b=0.94}}, -- LIGHT_BLUE - [10] = -- COOKING = - { color = {r=0.96,g=0.55,b=0.73}}, -- PINK - -- These are Classic arrow or bullet bags - [22] = -- Classic arrow - { color = {r=1,g=.4,b=0}}, -- copper - [23] = -- Classic bullet - { color = {r=0.8,g=0.8,b=0.8}}, -- silver -} + local trace = false local MIN_BAGS = 0 -local MAX_BAGS = Constants.InventoryConstants.NumBagSlots +local MAX_BAGS = 0 local bag_data = {} -- to hold the user bag data -- ******************************** Functions ******************************* +-- Set so Retail and Classic can run local GetItemNow = C_Item.GetItemInfoInstant or GetItemInfoInstant +---Determine if this is a profession bag using only instant data rather than calling server +---@param slot number +---@return boolean local function IsProfessionBagID(slot) - -- The info needed is available using GetItemInfoInstant; only the bag / item id is required + -- The info needed is available using GetItemInfoInstant; only the bag slot or item id is required. + -- A LOT of info is available but we only need class and subclass here. -- itemType : warcraft.wiki.gg/wiki/itemType local res = false - local style = 0 local info, itemId, itemType, itemSubType, itemEquipLoc, itemTexture, classID, subclassID local inv_id = C_Container.ContainerIDToInventoryID(slot) if inv_id == nil then -- Only works on bag and bank bags NOT backpack! + -- However the backpack is never a profession bag. else info = GetInventoryItemLink("player", inv_id) - itemId, itemType, itemSubType, itemEquipLoc, itemTexture, classID, subclassID = GetItemNow(info) - style = subclassID - if classID == 1 then -- is a container / bag - if subclassID >= 1 then - -- profession bag of some type [2 - 10] Jan 2024 (DragonFlight / Wrath / Classic Era) - -- OR soul bag [1] + if info == nil then + -- Slot likely empty, no need to process. + else + itemId, itemType, itemSubType, itemEquipLoc, itemTexture, classID, subclassID = GetItemNow(info) + if classID == 1 then -- is a container / bag + if subclassID >= 1 then + -- profession bag of some type [2 - 10] Jan 2024 (DragonFlight / Wrath / Classic Era) + -- OR soul bag [1] + res = true + else + -- is a arrow or bullet bag; only two options + end + elseif classID == 6 then -- is a 'projectile' holder + res = true + -- is a ammo bag or quiver; only two options + elseif classID == 11 then -- is a 'quiver'; Wrath and CE res = true + -- is a ammo pouch or quiver; only two options + -- style = subclassID + 20 -- change to get local color for name else - -- is a arrow or bullet; only two options + -- not a profession bag end - elseif classID == 6 then -- is a 'projectile' holder - res = true - -- is a ammo bag or quiver; only two options - elseif classID == 11 then -- is a 'quiver'; Wrath and CE - res = true - -- is a ammo pouch or quiver; only two options - style = subclassID + 20 -- change to get local color for name - else - -- not a bag end end - if trace then - TitanDebug("T isP:" - .." "..tostring(res).."" - .." "..tostring(style).."" - .." "..tostring(itemId).."" - .." "..tostring(classID).."" - .." "..tostring(subclassID).."" - .." "..tostring(inv_id).."" - ) - end - - return res, style + return res end +---Tell the UI to open / close the bags local function ToggleBags() if TitanGetVar(TITAN_BAG_ID, "OpenBags") then ToggleAllBags() @@ -112,94 +84,80 @@ local function ToggleBags() end end +---Collect bag info - name, slots (total, used, free), name (if available). +--- The bag name is not always available when player entering world but the required info is. +---@param id string Plugin ID local function GetBagData(id) --[[ - The bag name is not always available when player entering world - Grabbing the total slots is available though to determine if a bag exists. + The bag name is not always available when player entering world. The user may see bag name as <unknown> until an event triggers a bag check AND the name is available. + Grabbing the total slots is available on client to determine if a bag exists and get its free / used counts. --]] - + -- 2024 Jan : Moved away from named based to id based. Allows name to come later from server + -- 2024 Aug : Removed coloring of bag name to focus on counts which is the real info. + + if trace then + TitanPluginDebug(TITAN_BAG_ID, "T GetBagData" + .. " '" .. tostring(id) .. "'" + ) + end local total_slots = 0 local total_free = 0 local total_used = 0 - - local count_prof = TitanGetVar(TITAN_BAG_ID, "CountProfBagSlots") + local is_prof_bag = false + -- calculated but not used ATM + local prof_slots = 0 + local prof_free = 0 + local prof_used = 0 for bag_slot = MIN_BAGS, MAX_BAGS do -- assuming 0 (Backpack) will not be a profession bag - local slots = C_Container.GetContainerNumSlots(bag_slot) - - -- Ensure a blank structure exists + -- Ensure a blank structure exists. + -- Blanking data may seem overkill but it allows the plugin to react to events without + -- caring when they occur and it will set the bag name when it arrives AND an event occurs. bag_data[bag_slot] = { has_bag = false, name = "", - maxi_slots = 0, + max_slots = 0, free_slots = 0, used_slots = 0, style = "", color = "", - } + } + + local slots = C_Container.GetContainerNumSlots(bag_slot) + + -- Check type here to set slot style properly. + -- Profession bags are NOT included in overall free / used counts + local bag_type = "none" + is_prof_bag = IsProfessionBagID(bag_slot) + + -- Blizz treats 'last' slot as a reagent only slot... + -- For our purpose, treat it as a profession bag. + if is_prof_bag or bag_slot == 5 then + bag_type = "profession" + else + bag_type = "normal" + end + bag_data[bag_slot].style = bag_type if slots > 0 then bag_data[bag_slot].has_bag = true - + local bag_name = (C_Container.GetBagName(bag_slot) or UNKNOWN) bag_data[bag_slot].name = bag_name - bag_data[bag_slot].maxi_slots = slots - + bag_data[bag_slot].max_slots = slots + local free = C_Container.GetContainerNumFreeSlots(bag_slot) local used = slots - free bag_data[bag_slot].free_slots = free bag_data[bag_slot].used_slots = used - ---[[ -TitanDebug("T Bag:" -.." "..tostring(bag_slot).."" -.." "..tostring(slots).."" -.." "..tostring(free).."" -.." '"..tostring(bag_name).."'" -) ---]] - -- some info is not known until the name is available... - -- The API requires name to get the bag ID. - local bag_type = "none" - local color = {r=0,g=0,b=0} -- black (should never be used...) - if bag_name == UNKNOWN then - -- name not available yet - else - end - -- Jan 2024 : Moved away from named based to an id based. Allows name to come later from server - local is_prof_bag, style = IsProfessionBagID(bag_slot) ---[[ -if trace then -TitanDebug("T Bag...:" -.." "..tostring(bag_slot).."" -.." "..tostring(is_prof_bag).."" -.." '"..tostring(style).."'" -.." "..tostring(itemClassID).."" -.." "..tostring(itemSubClassID).."" -) -end ---]] - if is_prof_bag then - color = bag_info[style].color - bag_type = "profession" - else - bag_type = "normal" - end - bag_data[bag_slot].style = bag_type - bag_data[bag_slot].color = color - -- add to total if bag_data[bag_slot].style == "profession" then - if count_prof then - total_slots = total_slots + slots - total_free = total_free + free - total_used = total_used + used - else - -- ignore in totals - end + prof_slots = prof_slots + slots + prof_free = prof_free + free + prof_used = prof_used + used else total_slots = total_slots + slots total_free = total_free + free @@ -207,378 +165,352 @@ end end else bag_data[bag_slot].has_bag = false + bag_data[bag_slot].name = NONE end - + if trace then - TitanDebug("T info" - .." "..tostring(bag_slot).."" - .." ?:"..tostring(bag_data[bag_slot].has_bag).."" - .." max: "..tostring(bag_data[bag_slot].maxi_slots).."" - .." used: "..tostring(bag_data[bag_slot].used_slots).."" - .." free: "..tostring(bag_data[bag_slot].free_slots).."" - .." type: "..tostring(bag_data[bag_slot].style).."" - .." count: "..tostring(count_prof).."" - .." '"..tostring(bag_data[bag_slot].name).."'" + TitanPluginDebug(TITAN_BAG_ID, "...T GetBagData" + .. " " .. tostring(bag_slot) .. "" + .. " ?:" .. tostring(bag_data[bag_slot].has_bag) .. "" + .. " max: " .. tostring(bag_data[bag_slot].max_slots) .. "" + .. " used: " .. tostring(bag_data[bag_slot].used_slots) .. "" + .. " free: " .. tostring(bag_data[bag_slot].free_slots) .. "" + .. " type: " .. tostring(bag_data[bag_slot].style) .. "" + .. " prof: " .. tostring(is_prof_bag) .. "" + .. " '" .. tostring(bag_data[bag_slot].name) .. "'" ) end end + -- Normal bags bag_data.total_slots = total_slots bag_data.total_free = total_free bag_data.total_used = total_used + -- Profession / reagent bags + bag_data.prof_slots = prof_slots + bag_data.prof_free = prof_free + bag_data.prof_used = prof_used +end + +---plugin Handle registered events +---@param self Button +---@param event string +---@param ... any +local function OnEvent(self, event, ...) + if event == "PLAYER_ENTERING_WORLD" then + -- Leave in case future code is needed... + elseif event == "BAG_UPDATE" then + -- update the plugin text + TitanPanelButton_UpdateButton(TITAN_BAG_ID); + elseif event == "BAG_CONTAINER_UPDATE" then + -- 2024 Aug : Added as additional check if user swaps bags; may not be required + -- update the plugin text + TitanPanelButton_UpdateButton(TITAN_BAG_ID); + end + + if trace then + TitanPluginDebug(TITAN_BAG_ID, "_OnEvent" + .. " " .. tostring(event) .. "" + ) + end +end + +---Opens all bags on a LeftClick +---@param self Button +---@param button string +local function OnClick(self, button) + if (button == "LeftButton") then + ToggleBags(); + end +end + +---Generate the plugin button text +---@param id string +---@return string +---@return string +local function GetButtonText(id) + GetBagData(id) + local bagText = "" - if (TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")) then - bagText = format(L["TITAN_BAG_FORMAT"], total_used, total_slots); + if TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots") then + bagText = format(L["TITAN_BAG_FORMAT"], bag_data.total_used, bag_data.total_slots); else - bagText = format(L["TITAN_BAG_FORMAT"], total_free, total_slots); + bagText = format(L["TITAN_BAG_FORMAT"], bag_data.total_free, bag_data.total_slots); end local bagRichText = "" - if ( TitanGetVar(TITAN_BAG_ID, "ShowColoredText") ) then + if (TitanGetVar(TITAN_BAG_ID, "ShowColoredText")) then local color = "" - color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, total_used / total_slots); + color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, bag_data.total_used / bag_data.total_slots); bagRichText = TitanUtils_GetColoredText(bagText, color); else bagRichText = TitanUtils_GetHighlightText(bagText); end - bagRichText = bagRichText --..bagRichTextProf[1]..bagRichTextProf[2]..bagRichTextProf[3]..bagRichTextProf[4]..bagRichTextProf[5]; + bagRichText = bagRichText + --..bagRichTextProf[1]..bagRichTextProf[2]..bagRichTextProf[3]..bagRichTextProf[4]..bagRichTextProf[5]; - return L["TITAN_BAG_BUTTON_LABEL"], bagRichText -end - ---[[ plugin --- ************************************************************************** --- NAME : TitanPanelBagButton_OnLoad() --- DESC : Registers the plugin upon it loading --- ************************************************************************** ---]] -function TitanPanelBagButton_OnLoad(self) - local notes = "" - .."Adds bag and free slot information to Titan Panel.\n" - .."- Open bags should work... Retail taint fixed Apr 2024 (10.2.7).\n" --- .."- xxx.\n" - self.registry = { - id = TITAN_BAG_ID, - category = "Built-ins", - version = TITAN_VERSION, - menuText = L["TITAN_BAG_MENU_TEXT"], - buttonTextFunction = "TitanPanelBagButton_GetButtonText", - tooltipTitle = L["TITAN_BAG_TOOLTIP"], - tooltipTextFunction = "TitanPanelBagButton_GetTooltipText", - icon = "Interface\\AddOns\\TitanBag\\TitanBag", - iconWidth = 16, - notes = notes, - controlVariables = { - ShowIcon = true, - ShowLabelText = true, - ShowColoredText = true, - DisplayOnRightSide = true, - }, - savedVariables = { - ShowUsedSlots = 1, - ShowDetailedInfo = false, - CountProfBagSlots = false, - ShowIcon = 1, - ShowLabelText = 1, - ShowColoredText = 1, - DisplayOnRightSide = false, - OpenBags = true, - } - }; - - -- As of Apr 2024 (10.2.7) the taint on opening bags in Retail is fixed. - - self:RegisterEvent("PLAYER_ENTERING_WORLD"); -end - ---[[ plugin --- ************************************************************************** --- NAME : TitanPanelBagButton_OnEvent() --- DESC : Parse events registered to plugin and act on them --- ************************************************************************** ---]] -function TitanPanelBagButton_OnEvent(self, event, a1, a2, ...) - if event == "PLAYER_ENTERING_WORLD" then - -- Leave in case future code is needed... - end - - if event == "BAG_UPDATE" then - -- update the plugin text - TitanPanelButton_UpdateButton(TITAN_BAG_ID); + if trace then + TitanPluginDebug(TITAN_BAG_ID, "T GetBagData" + .. " '" .. tostring(bagRichText) .. "'" + ) end ---[[ -print("_OnEvent" -.." "..tostring(event).."" -) ---]] + return L["TITAN_BAG_BUTTON_LABEL"], bagRichText end ---[[ plugin --- ************************************************************************** --- NAME : TitanPanelBagButton_OnClick(button) --- DESC : Opens all bags on a LeftClick --- VARS : button = value of action --- ************************************************************************** ---]] -function TitanPanelBagButton_OnClick(self, button) - if (button == "LeftButton") then - ToggleBags(); +---Determine the color based on percentage +---@param text string +---@param show_color boolean +---@param numerator number +---@param denom number +---@return string +local function ThresholdColor(text, show_color, numerator, denom) + local res = "" + local color = "" + if show_color then + if denom == 0 then + color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, 1); + else + color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, numerator / denom); + end + res = TitanUtils_GetColoredText(text, color); + else + -- use without color + res = TitanUtils_GetHighlightText(text); end -end --- plugin -function TitanPanelBagButton_GetButtonText(id) - local strA, strB = GetBagData(id) - return strA, strB + return res end ---[[ plugin --- ************************************************************************** --- NAME : TitanPanelBagButton_GetTooltipText() --- DESC : Display tooltip text --- ************************************************************************** ---]] -function TitanPanelBagButton_GetTooltipText() - local totalSlots, usedSlots, availableSlots; +---Generate tooltip text +---@return string +local function GetTooltipText() + -- Normal shows free / used of total per user options. + -- Detailed shows list bags with profession bag counts in gray - not counted. + -- Hint shows if user selects open bags on left click. + --#region-- 2024 Aug (8.1.0) : With the addition of new 'reagent' slot, we dropped coloring & counting profession bags. local returnstring = ""; + local show_color = TitanGetVar(TITAN_BAG_ID, "ShowColoredText") + -- Collect names and x / y numbers, color numbers if user requested if TitanGetVar(TITAN_BAG_ID, "ShowDetailedInfo") then returnstring = "\n"; if TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots") then - returnstring = returnstring..TitanUtils_GetNormalText(L["TITAN_BAG_MENU_TEXT"]) - ..":\t"..TitanUtils_GetNormalText(L["TITAN_BAG_USED_SLOTS"])..":\n"; + returnstring = returnstring .. TitanUtils_GetNormalText(L["TITAN_BAG_MENU_TEXT"]) + .. ":\t" .. TitanUtils_GetNormalText(L["TITAN_BAG_USED_SLOTS"]) .. ":\n"; else - returnstring = returnstring..TitanUtils_GetNormalText(L["TITAN_BAG_MENU_TEXT"]) - ..":\t"..TitanUtils_GetNormalText(L["TITAN_BAG_FREE_SLOTS"])..":\n"; + returnstring = returnstring .. TitanUtils_GetNormalText(L["TITAN_BAG_MENU_TEXT"]) + .. ":\t" .. TitanUtils_GetNormalText(L["TITAN_BAG_FREE_SLOTS"]) .. ":\n"; end for bag = MIN_BAGS, MAX_BAGS do - local bagText, bagRichText, color; ---[[ -TitanDebug("T Bag: TT" -.." "..tostring(bag).."" -.." "..tostring(bag_data[bag].has_bag).."" -.." "..tostring(bag_data[bag].name).."" -.." "..tostring(bag_data[bag].maxi_slots).."" -.." "..tostring(bag_data[bag].used_slots).."" -.." "..tostring(bag_data[bag].free_slots).."" -) ---]] - if bag_data[bag] and bag_data[bag].has_bag then - if (TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")) then - bagText = format(L["TITAN_BAG_FORMAT"], bag_data[bag].used_slots, bag_data[bag].maxi_slots); - else - bagText = format(L["TITAN_BAG_FORMAT"], bag_data[bag].free_slots, bag_data[bag].maxi_slots); - end - - if bag_data[bag].style == "profession" - and not TitanGetVar(TITAN_BAG_ID, "CountProfBagSlots") - then - bagRichText = "|cffa0a0a0"..bagText.."|r" -- show as gray - elseif ( TitanGetVar(TITAN_BAG_ID, "ShowColoredText") ) then - if bag_data[bag].maxi_slots == 0 then - color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, 1 ); + local bagText = "" + local bagRichText + + if bag_data[bag] then + if bag_data[bag].has_bag then + -- Format the x / y slots per user options + if (TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")) then + bagText = format(L["TITAN_BAG_FORMAT"], bag_data[bag].used_slots, bag_data[bag].max_slots); else - color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, bag_data[bag].used_slots / bag_data[bag].maxi_slots); + bagText = format(L["TITAN_BAG_FORMAT"], bag_data[bag].free_slots, bag_data[bag].max_slots); + end + -- Format x / y per user options + if bag_data[bag].style == "profession" then + bagRichText = TitanUtils_GetGrayText(bagText) + else + bagRichText = ThresholdColor(bagText, show_color, bag_data[bag].used_slots, bag_data[bag].max_slots) end - bagRichText = TitanUtils_GetColoredText(bagText, color); - else - -- use without color - bagRichText = TitanUtils_GetHighlightText(bagText); - end - - local name_text = bag_data[bag].name - if bag_data[bag].style == "profession" - then - name_text = TitanUtils_GetColoredText(name_text, bag_data[bag].color) else - -- use without color + bagRichText = "" end - returnstring = returnstring..name_text.."\t"..bagRichText.."\n"; + -- Format bag name as 'normal' 2024 Aug + local name_text = TitanUtils_GetNormalText(bag_data[bag].name) + returnstring = returnstring .. name_text .. "\t" .. bagRichText .. "\n"; else - returnstring = returnstring..NONE.."\n"; + --Silent error - should never get here... end end - returnstring = returnstring.."\n"; + returnstring = returnstring .. "------\t" .. "---\n"; end + -- Always show free / used of max slots to user + local xofy = "" + local slots = "" if TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots") then - local xofy = ""..tostring(bag_data.total_used) - .."/"..tostring(bag_data.total_slots).."\n" - returnstring = returnstring..TitanUtils_GetNormalText(L["TITAN_BAG_USED_SLOTS"]) - ..":\t"..xofy + xofy = "" .. tostring(bag_data.total_used) .. "/" .. tostring(bag_data.total_slots) + xofy = ThresholdColor(xofy, show_color, bag_data.total_used, bag_data.total_slots) + slots = L["TITAN_BAG_USED_SLOTS"] else - local xofy = ""..tostring(bag_data.total_free) - .."/"..tostring(bag_data.total_slots).."\n" - returnstring = returnstring..TitanUtils_GetNormalText(L["TITAN_BAG_USED_SLOTS"]) - ..":\t"..xofy + xofy = "" .. tostring(bag_data.total_free) .. "/" .. tostring(bag_data.total_slots) + xofy = ThresholdColor(xofy, show_color, bag_data.total_free, bag_data.total_slots) + slots = L["TITAN_BAG_FREE_SLOTS"] end - - -- Add Hint + returnstring = returnstring .. TitanUtils_GetNormalText(slots) .. ":\t" .. xofy .. "\n" + + -- Add Hint if user wants to open bags on left click. if TitanGetVar(TITAN_BAG_ID, "OpenBags") then - returnstring = returnstring..TitanUtils_GetGreenText(L["TITAN_BAG_TOOLTIP_HINTS"]) + returnstring = returnstring .. "\n" .. TitanUtils_GetGreenText(L["TITAN_BAG_TOOLTIP_HINTS"]) else -- nop end return returnstring end ---[[ plugin --- ************************************************************************** --- NAME : TitanPanelRightClickMenu_PrepareBagMenu() --- DESC : Display rightclick menu options --- NOTE : Titan builds this name to call on right click --- ************************************************************************** ---]] -function TitanPanelRightClickMenu_PrepareBagMenu() +---Generate and display rightclick menu options for user. +local function PrepareBagMenu() local info - -- level 2 - if TitanPanelRightClickMenu_GetDropdownLevel() == 2 then - if TitanPanelRightClickMenu_GetDropdMenuValue() == "Options" then - TitanPanelRightClickMenu_AddTitle(L["TITAN_PANEL_OPTIONS"], TitanPanelRightClickMenu_GetDropdownLevel()) - info = {}; - info.text = L["TITAN_BAG_MENU_SHOW_USED_SLOTS"]; - info.func = TitanPanelBagButton_ShowUsedSlots; - info.checked = TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots"); - TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); - - info = {}; - info.text = L["TITAN_BAG_MENU_SHOW_AVAILABLE_SLOTS"]; - info.func = TitanPanelBagButton_ShowAvailableSlots; - info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")); - TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); - - info = {}; - info.text = L["TITAN_BAG_MENU_SHOW_DETAILED"]; - info.func = TitanPanelBagButton_ShowDetailedInfo; - info.checked = TitanGetVar(TITAN_BAG_ID, "ShowDetailedInfo"); - TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); - - info = {}; - info.text = L["TITAN_BAG_MENU_OPEN_BAGS"] - info.func = function() - TitanToggleVar(TITAN_BAG_ID, "OpenBags") - end - info.checked = TitanGetVar(TITAN_BAG_ID, "OpenBags"); - TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); - end - return - end - -- level 1 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_BAG_ID].menuText); info = {}; - info.notCheckable = true - info.text = L["TITAN_PANEL_OPTIONS"]; - info.value = "Options" - info.hasArrow = 1; + info.text = L["TITAN_BAG_MENU_SHOW_USED_SLOTS"]; + info.func = function() + TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", 1); + TitanPanelButton_UpdateButton(TITAN_BAG_ID); + end + info.checked = TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots"); + TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); + + info = {}; + info.text = L["TITAN_BAG_MENU_SHOW_AVAILABLE_SLOTS"]; + info.func = function() + TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", nil); + TitanPanelButton_UpdateButton(TITAN_BAG_ID); + end + info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")); TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); - TitanPanelRightClickMenu_AddSpacer(); info = {}; - info.text = L["TITAN_BAG_MENU_IGNORE_PROF_BAGS_SLOTS"]; - info.func = TitanPanelBagButton_ToggleIgnoreProfBagSlots; - info.checked = not TitanGetVar(TITAN_BAG_ID, "CountProfBagSlots") + info.text = L["TITAN_BAG_MENU_SHOW_DETAILED"]; + info.func = function() + TitanToggleVar(TITAN_BAG_ID, "ShowDetailedInfo"); + end + info.checked = TitanGetVar(TITAN_BAG_ID, "ShowDetailedInfo"); + TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); + + info = {}; + info.text = L["TITAN_BAG_MENU_OPEN_BAGS"] + info.func = function() + TitanToggleVar(TITAN_BAG_ID, "OpenBags") + end + info.checked = TitanGetVar(TITAN_BAG_ID, "OpenBags"); TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel()); + TitanPanelRightClickMenu_AddSpacer(); + TitanPanelRightClickMenu_AddControlVars(TITAN_BAG_ID) end ---[[ --- ************************************************************************** --- NAME : TitanPanelBagButton_ShowUsedSlots() --- DESC : Set option to show used slots --- ************************************************************************** ---]] -function TitanPanelBagButton_ShowUsedSlots() - TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", 1); - TitanPanelButton_UpdateButton(TITAN_BAG_ID); -end +---plugin Registers the plugin and simple init +---@param self Button +local function OnLoad(self) + local notes = "" + .. "Adds bag and free slot information to Titan Panel.\n" + .. "- Open bags should work... Retail taint fixed Apr 2024 (10.2.7).\n" + .. "- Professions counts moved to tooltip only : Aug 2024 (Titan 8.1.0).\n" + self.registry = { + id = TITAN_BAG_ID, + category = "Built-ins", + version = TITAN_VERSION, + menuText = L["TITAN_BAG_MENU_TEXT"], + menuTextFunction = PrepareBagMenu, + buttonTextFunction = GetButtonText, + tooltipTitle = L["TITAN_BAG_TOOLTIP"], + tooltipTextFunction = GetTooltipText, + icon = "Interface\\AddOns\\TitanBag\\TitanBag", + iconWidth = 16, + notes = notes, + controlVariables = { + ShowIcon = true, + ShowLabelText = true, + ShowColoredText = true, + DisplayOnRightSide = true, + }, + savedVariables = { + ShowUsedSlots = 1, + ShowDetailedInfo = false, + ShowIcon = 1, + ShowLabelText = 1, + ShowColoredText = 1, + DisplayOnRightSide = false, + OpenBags = true, + } + }; ---[[ --- ************************************************************************** --- NAME : TitanPanelBagButton_ShowAvailableSlots() --- DESC : Set option to show available slots --- ************************************************************************** ---]] -function TitanPanelBagButton_ShowAvailableSlots() - TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", nil); - TitanPanelButton_UpdateButton(TITAN_BAG_ID); -end + -- As of Apr 2024 (10.2.7) the taint on opening bags in Retail is fixed. ---[[ --- ************************************************************************** --- NAME : TitanPanelBagButton_ToggleIgnoreProfBagSlots() --- DESC : Set option to count profession bag slots --- ************************************************************************** ---]] -function TitanPanelBagButton_ToggleIgnoreProfBagSlots() - TitanToggleVar(TITAN_BAG_ID, "CountProfBagSlots"); - TitanPanelButton_UpdateButton(TITAN_BAG_ID); -end + -- Reagent bag slot added end of DragonFlight for War Within expansion. + if NUM_TOTAL_EQUIPPED_BAG_SLOTS == nil then -- NOT Retail as of DragonFlight WHY BLIZZ!? + MAX_BAGS = Constants.InventoryConstants.NumBagSlots + else -- Classic API + MAX_BAGS = NUM_TOTAL_EQUIPPED_BAG_SLOTS + end -function TitanPanelBagButton_ShowDetailedInfo() - TitanToggleVar(TITAN_BAG_ID, "ShowDetailedInfo"); + self:RegisterEvent("PLAYER_ENTERING_WORLD"); end -function TitanPanelBagButton_OnShow(self) +---Prep and update plugin button here to minimize resources. +---@param self Button +local function OnShow(self) -- Register for bag updates and update the plugin text self:RegisterEvent("BAG_UPDATE") + self:RegisterEvent("BAG_CONTAINER_UPDATE") TitanPanelButton_UpdateButton(TITAN_BAG_ID); end -function TitanPanelBagButton_OnHide(self) +---Shutdown plugin button here to minimize resources. +---@param self Button +local function OnHide(self) self:UnregisterEvent("BAG_UPDATE") + self:UnregisterEvent("BAG_CONTAINER_UPDATE") end --- ====== Create needed frames +---Create needed plugin frames local function Create_Frames() if _G[TITAN_BUTTON] then return -- if already created end - + -- general container frame local f = CreateFrame("Frame", nil, UIParent) --- f:Hide() + -- f:Hide() -- Titan plugin button local window = CreateFrame("Button", TITAN_BUTTON, f, "TitanPanelComboTemplate") window:SetFrameStrata("FULLSCREEN") -- Using SetScript("OnLoad", does not work - TitanPanelBagButton_OnLoad(window); --- TitanPanelButton_OnLoad(window); -- Titan XML template calls this... - + OnLoad(window); + -- TitanPanelButton_OnLoad(window); -- Titan XML template calls this... + window:SetScript("OnShow", function(self) - TitanPanelBagButton_OnShow(self); + OnShow(self); TitanPanelButton_OnShow(self); end) window:SetScript("OnHide", function(self) - TitanPanelBagButton_OnHide(self) + OnHide(self) end) window:SetScript("OnEvent", function(self, event, ...) - TitanPanelBagButton_OnEvent(self, event, ...) + OnEvent(self, event, ...) end) window:SetScript("OnClick", function(self, button) - TitanPanelBagButton_OnClick(self, button); + OnClick(self, button); TitanPanelButton_OnClick(self, button); end) end - Create_Frames() -- do the work --[[ TitanDebug("T isP 0:" .." "..tostring(slot).."" - .." "..tostring(itemId).."" - .." '"..tostring(itemType).."'" - .." '"..tostring(itemSubType).."'" - .." "..tostring(itemEquipLoc).."" - .." '"..tostring(itemTexture).."'" - .." "..tostring(classID).."" - .." "..tostring(subclassID).."" + .." "..tostring(itemId).."" + .." '"..tostring(itemType).."'" + .." '"..tostring(itemSubType).."'" + .." "..tostring(itemEquipLoc).."" + .." '"..tostring(itemTexture).."'" + .." "..tostring(classID).."" + .." "..tostring(subclassID).."" ) --]] diff --git a/TitanGold/TitanGold.lua b/TitanGold/TitanGold.lua index f99c08d..977fe7f 100644 --- a/TitanGold/TitanGold.lua +++ b/TitanGold/TitanGold.lua @@ -1150,8 +1150,10 @@ end ---@param self Button local function OnHide(self) self:UnregisterEvent("PLAYER_MONEY"); ----@diagnostic disable-next-line: param-type-mismatch - self:UnregisterEvent("ACCOUNT_MONEY"); + if Warband.active then + ---@diagnostic disable-next-line: param-type-mismatch + self:UnregisterEvent("ACCOUNT_MONEY") + end AceTimer:CancelTimer(GoldTimer) GoldTimerRunning = false end