diff --git a/Titan/TitanHistory.lua b/Titan/TitanHistory.lua index 562210a..95c2207 100644 --- a/Titan/TitanHistory.lua +++ b/Titan/TitanHistory.lua @@ -15,17 +15,19 @@ Green - 'header' - Titan or plugin Highlight - notes. tips. and details --]] Titan_Global.recent_changes = "" -.. TitanUtils_GetGoldText("8.0.17 : 2024/08/06\n") +.. TitanUtils_GetGoldText("8.1.0 : 2024/08/06\n") .. TitanUtils_GetGreenText("Titan : \n") .. TitanUtils_GetHighlightText("" .. "- Updated TOC files to use *_Classic; single TOC file for Classic versions" ) .. "\n\n" -.. TitanUtils_GetGreenText("Gold, Repair, XP : \n") +.. TitanUtils_GetGreenText("Gold : \n") .. TitanUtils_GetHighlightText("" -.. "- Gold : Fix gold display when user selects . (period) as thousands separator.\n" -.. "- Added TitanUtils_NumToString for use in all 3.\n" -.. "- Added TitanUtils_CashToString for use in Gold and Repair for common look of gold/silver/copper.\n" +.. "- Retail ONLY - Added Warband bank at bottom of list for totals.\n" +.. "- Better alignment when silver or copper are zero.\n" +.. "- Added space (' ') as a thousands separator option with comma and period.\n" +.. "- 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("Regen : \n") .. TitanUtils_GetHighlightText("" diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua index 607fe7b..0ac9b5e 100644 --- a/Titan/TitanUtils.lua +++ b/Titan/TitanUtils.lua @@ -2507,6 +2507,19 @@ function TitanDumpTable(tb, level) end end +---Titan: From a given table; find input in its indexes. +---@param tb table +---@param val string 1 or defaults to 1 +function TitanFindIndex(tb, val) + for k, v in pairs(tb) do + if type(k) == 'string' and string.find(k, val) then + print("idx [" .. tostring(k) .. "] = " .. " '" .. tostring(v) .. "'") + else + -- keep looking + end + end +end + --====== Deprecated routines -- These routines will be commented out for a couple releases then deleted. -- diff --git a/TitanGold/TitanGold.lua b/TitanGold/TitanGold.lua index 6d94f07..f99c08d 100644 --- a/TitanGold/TitanGold.lua +++ b/TitanGold/TitanGold.lua @@ -33,21 +33,68 @@ local merged_realms = {} -- fill on PEW -- English faction for indexing and sorting and coloring local TITAN_ALLIANCE = "Alliance" local TITAN_HORDE = "Horde" -local TITAN_WARBAND= "Warband" local player_faction, player_faction_locale = UnitFactionGroup("Player") --- check for func even though it does not work atm... 2024 Aug (Added 11.0.0) -local warband_active = (C_Bank and C_Bank.CanUseBank) and true or false -local warband_toon = ACCOUNT_BANK_PANEL_TITLE or "WarBand Bank" -- may not be the best... -local warband_server = "WarBandBank" -- may not be the best... - --[[ debug local FACTION_ALLIANCE = "Alliance_debug" local FACTION_HORDE = "Horde_debug" --]] -- ******************************** Functions ******************************* +local Warband = { + bank_sum = 0, + active = false, + label = "", +} +---local Warband Bank debug +function Warband.debug(reason) + print("WB "..reason + .." "..tostring(Warband.active) + .." "..tostring(Warband.label) + .." "..tostring(Warband.bank_sum) + ) +end +---local Update Warband Bank info - sum +function Warband.SetSum() + Warband.bank_sum = C_Bank.FetchDepositedMoney(Enum.BankType.Account) +-- Warband.debug("SetSum") +end +---local Return Warband Bank info +function Warband.Init() + -- check for func even though it does not work atm... 2024 Aug (Added 11.0.0) + Warband.active = (C_Bank and C_Bank.CanUseBank) and true or false + if Warband.active then + Warband.label = L["TITAN_WARBAND_BANK"] + Warband.SetSum() + else + -- Likely Classic version + end +-- Warband.debug("Init") + end +---local Return Warband Bank info +---@return number +function Warband.GetSum() +-- Warband.debug("GetSum") + return Warband.bank_sum +end +---local Return Warband Bank info +---@return string +function Warband.GetName() +-- Warband.debug("GetName") + return Warband.label +end + +--=== + +local function GetConnectedRealms() + local realms = GetAutoCompleteRealms() + if #realms == 0 then + realms[1] = GetRealmName() + end + return realms +end + ---Take a table of indexes to sort GoldSave ---@param gold_table table ---@return table sorted May not be need but it is explicit @@ -128,20 +175,20 @@ local function EvalIndexInfo(index) res.ignore_faction = TitanGetVar(TITAN_GOLD_ID, "IgnoreFaction") - if (char_faction == player_faction) or char_faction == TITAN_WARBAND then + if (char_faction == player_faction) then res.same_faction = true else res.same_faction = false end - if (charserver == realmName) or (charserver == warband_server) then + if (charserver == realmName) then res.same_realm = true else res.same_realm = false end local saved_server = string.gsub(charserver, "%s", "") -- GetAutoCompleteRealms removes spaces, idk why... - if merged_realms[saved_server] or (charserver == warband_server) then + if merged_realms[saved_server] then res.merge_realm = true else res.merge_realm = false @@ -425,9 +472,6 @@ local function GetTooltipText() countelements = countelements + 1 end - -- if countelements == 0 or TitanGetVar(TITAN_GOLD_ID, "SeparateServers") then - -- The check for no connected realms was confusing so use the 'merge' format - -- if requested. -- insert all keys from hash into the GoldSorted array if TitanGetVar(TITAN_GOLD_ID, "SeparateServers") then @@ -494,10 +538,15 @@ local function GetTooltipText() end if ignore_faction then + local font_size = TitanPanelGetVar("FontSize") + local icon_pre = "|TInterface/AddOns/TitanGold/Artwork/" + local icon_post = ":" .. font_size .. ":" .. font_size .. ":2:0|t" + local a_icon = icon_pre .. "UI_AllianceIcon-round" .. icon_post + local h_icon = icon_pre .. "UI_HordeIcon-round" .. icon_post if char_faction == TITAN_ALLIANCE then - faction_text = TitanUtils_GetHexText(GoldSave[GoldSorted[i]].faction, Titan_Global.colors.alliance) + faction_text = " " .. a_icon elseif char_faction == TITAN_HORDE then - faction_text = "-" .. TitanUtils_GetHexText(GoldSave[GoldSorted[i]].faction, Titan_Global.colors.horde) + faction_text = " " .. h_icon end end @@ -509,6 +558,17 @@ local function GetTooltipText() .. "\t" .. coin_str end + -- + -- === Add Warband Bank + -- + if Warband.active then + currentMoneyRichText = currentMoneyRichText .. "\n" + .. "------ \t +" .. "\n" + .. Warband.GetName() -- localized + .. "\t" .. NiceCash(Warband.GetSum(), false, false) + end + + --[[ print("TG" .." "..tostring(counter) @@ -523,6 +583,9 @@ print("TG" ) --]] + -- + -- === Add Total per user options + -- coin_str = "" -- Display total gold coin_str = NiceCash(TotalGold(), false, false) @@ -573,6 +636,9 @@ print("TG" -- Do not display session info end + -- + -- === Add Gold notes and info + -- local final_tooltip = TitanUtils_GetGoldText(L["TITAN_GOLD_TOOLTIPTEXT"] .. " : ") local final_server = "" @@ -635,19 +701,6 @@ local function Initialize_Array(self) GoldSave[GOLD_INDEX] = { gold = GetMoney(), name = UnitName("player") } end - if warband_active then - if GoldSave[WARBAND_INDEX] then - -- already exists - else - -- Add a Warband entry with defaults - GoldSave[WARBAND_INDEX] = { - gold = 0, - name = warband_toon, - show = true, - } - end - end - -- Ensure the saved vars are usable for index, money in pairs(GoldSave) do local character, charserver, char_faction = GetIndexInfo(index) @@ -674,7 +727,7 @@ local function Initialize_Array(self) GOLD_STARTINGGOLD = GetMoney(); GOLD_SESSIONSTART = GetTime(); GOLD_INITIALIZED = true; ----[[ +--[[ print("Init" .." "..tostring(GOLD_STARTINGGOLD).."" .." "..tostring(GOLD_SESSIONSTART).."" @@ -1019,6 +1072,7 @@ local function OnLoad(self) .. "Keeps track of all gold held by a player's toons.\n" .. "- Can show by server / merged servers / all servers.\n" .. "- Can show by faction.\n" + .. "Shift + Left click will print list of connected servers to chat.\n" self.registry = { id = TITAN_GOLD_ID, category = "Built-ins", @@ -1084,9 +1138,9 @@ local function OnShow(self) else -- timer running or user does not want gold per hour end - - if warband_active then - GoldSave[WARBAND_INDEX].gold = C_Bank.FetchDepositedMoney(Enum.BankType.Account) + + if Warband.active then + Warband.SetSum() ---@diagnostic disable-next-line: param-type-mismatch self:RegisterEvent("ACCOUNT_MONEY") -- register for changes end @@ -1123,14 +1177,14 @@ print("_OnEvent" if (event == "ACCOUNT_MONEY") then if (GOLD_INITIALIZED) then - GoldSave[WARBAND_INDEX].gold = C_Bank.FetchDepositedMoney(Enum.BankType.Account) + Warband.SetSum() end - return; + return end if (event == "ADDON_LOADED") then realmName = GetRealmName() -- this realm - realmNames = GetAutoCompleteRealms() -- connected realms + realmNames = GetConnectedRealms() -- flip to make a simple lookup later rather than a loop for index, realm in pairs(realmNames) do merged_realms[realm] = true @@ -1139,21 +1193,37 @@ print("_OnEvent" -- Faction is English to use as index NOT display GOLD_INDEX = CreateIndex(UnitName("player"), realmName, UnitFactionGroup("Player")) - -- New in 11.0.0 (War Within) is Warband Bank Tab - if warband_active then - WARBAND_INDEX = CreateIndex(warband_toon, warband_server, TITAN_WARBAND) - end - return; end if (event == "PLAYER_ENTERING_WORLD") then Initialize_Array(self); + Warband.Init() TitanPanelButton_UpdateButton(TITAN_GOLD_ID) return; end end +---Button clicks - only shift-left for now +---@param self Button +---@param button string +function OnClick(self, button) + if button == "LeftButton" and IsShiftKeyDown() then + local realms = GetConnectedRealms() + local this_realm = " * " + local mark = "" + TitanPrint("Connected Realms:", "plain") + for idx = 1, #realms do + if realms[idx] == realmName then + mark = this_realm + else + mark = "" + end + TitanPrint("- "..tostring(realms[idx])..mark, "plain") + end + end +end + ---local Create required Gold frames local function Create_Frames() if _G[TITAN_BUTTON] then @@ -1181,7 +1251,10 @@ local function Create_Frames() window:SetScript("OnEvent", function(self, event, ...) OnEvent(self, event, ...) end) + window:SetScript("OnClick", function(self, button) + OnClick(self, button); + TitanPanelButton_OnClick(self, button); + end) end - Create_Frames() -- do the work