Quantcast

- Add to release of 1.5.0

urnati [12-28-21 - 19:32]
- Add to release of 1.5.0
- Gold changes to allow 'Merger Servers' to show character gold correctly
Filename
TitanGold/TitanGold.lua
diff --git a/TitanGold/TitanGold.lua b/TitanGold/TitanGold.lua
index fe0062f..b02ae8c 100644
--- a/TitanGold/TitanGold.lua
+++ b/TitanGold/TitanGold.lua
@@ -22,7 +22,7 @@ local GOLD_PERHOUR_STATUS;
 local GOLD_STARTINGGOLD;
 local GOLD_SESSIONSTART;
 local L = LibStub("AceLocale-3.0"):GetLocale("Titan", true)
---local DDM = LibStub:GetLibrary("LibUIDropDownMenu-4.0")
+local DDM = LibStub:GetLibrary("LibUIDropDownMenu-4.0")
 local TitanGold = LibStub("AceAddon-3.0"):NewAddon("TitanGold", "AceTimer-3.0")
 local GoldTimer = nil;
 local _G = getfenv(0);
@@ -175,7 +175,7 @@ function TitanPanelGoldButton_OnLoad(self)
 			ShowLabelText =true,
 			ShowRegularText = false,
 			ShowColoredText = false,
-			DisplayOnRightSide = true,
+			DisplayOnRightSide = false
 		},
 		savedVariables = {
 			Initialized = true,
@@ -194,7 +194,6 @@ function TitanPanelGoldButton_OnLoad(self)
 			MergeServers = false,
 			SeparateServers = true,
 			gold = { total = "112233", neg = false },
-			DisplayOnRightSide = false,
 		}
 	};

@@ -252,7 +251,6 @@ end
 -- DESC: Gets our tool-tip text, what appears when we hover over our item on the Titan bar.
 -- *******************************************************************************************
 function TitanPanelGoldButton_GetTooltipText()
-
 	local currentMoneyRichText = "";
 	local countelements = 0;
 	for _ in pairs (realmNames) do countelements = countelements + 1 end
@@ -268,7 +266,7 @@ function TitanPanelGoldButton_GetTooltipText()
 			or TitanGetVar(TITAN_GOLD_ID, "ShowCoinIcons"))

 		-- This next section will sort the array based on user preference
-		-- either by name, or by gold amount decending.
+		-- either by name, or by gold amount descending.

 		local GoldSaveSorted = {};
 		for index, money in pairs(GoldSave) do
@@ -298,50 +296,50 @@ function TitanPanelGoldButton_GetTooltipText()
 			end
 		end
 	else
-		-- Parse the database and display all characters from the same faction and combined servers
-		for ms = 1, countelements do
-			local server = realmNames[ms].."::"..UnitFactionGroup("Player");
-			GoldSave[GOLD_INDEX].gold = GetMoney("player")
-			local coin_str = ""
-			local character, charserver = "", ""
-			local ttlgold = 0
-			local show_labels = (TitanGetVar(TITAN_GOLD_ID, "ShowCoinLabels")
-				or TitanGetVar(TITAN_GOLD_ID, "ShowCoinIcons"))
-
-			-- This next section will sort the array based on user preference
-			-- either by name, or by gold amount decending.
-
-			local GoldSaveSorted = {};
-			for index, money in pairs(GoldSave) do
-				character, charserver = string.match(index, '(.*)_(.*)');
-				if (charserver) then
-					charserver = string.gsub(charserver, "%s", "");
-				end
-				if (character) then
-					if (charserver == server) then
-						table.insert(GoldSaveSorted, index); -- insert all keys from hash into the array
-					end
+		-- Parse the database and display all characters from the same faction across servers
+		local faction = UnitFactionGroup("Player");
+		local server = realmNames[ms]
+		GoldSave[GOLD_INDEX].gold = GetMoney("player")
+		local coin_str = ""
+		local character, charserver = "", ""
+		local ttlgold = 0
+		local show_labels = (TitanGetVar(TITAN_GOLD_ID, "ShowCoinLabels")
+			or TitanGetVar(TITAN_GOLD_ID, "ShowCoinIcons"))
+
+		-- This next section will sort the array based on user preference
+		-- either by name, or by gold amount descending.
+
+		local GoldSaveSorted = {};
+		for index, money in pairs(GoldSave) do
+			character, charserver = string.match(index, '(.*)_(.*)');
+			local _, char_faction = string.match(charserver, '(.*)::(.*)')
+			if (charserver) then
+				charserver = string.gsub(charserver, "%s", "");
+			end
+			if (character) then
+				if (char_faction == faction) then
+					table.insert(GoldSaveSorted, index); -- insert all keys from hash into the array
 				end
 			end
+		end

-			if TitanGetVar(TITAN_GOLD_ID, "SortByName") then
-				table.sort(GoldSaveSorted, function (key1, key2) return GoldSave[key1].name < GoldSave[key2].name end)
-			else
-				table.sort(GoldSaveSorted, function (key1, key2) return GoldSave[key1].gold > GoldSave[key2].gold end)
-			end
+		if TitanGetVar(TITAN_GOLD_ID, "SortByName") then
+			table.sort(GoldSaveSorted, function (key1, key2) return GoldSave[key1].name < GoldSave[key2].name end)
+		else
+			table.sort(GoldSaveSorted, function (key1, key2) return GoldSave[key1].gold > GoldSave[key2].gold end)
+		end

-			for i = 1, getn(GoldSaveSorted) do
-				character, charserver = string.match(GoldSaveSorted[i], '(.*)_(.*)');
-				if (charserver) then
-					charserver = string.gsub(charserver, "%s", "");
-				end
-				if (character) then
-					if (charserver == server) then
-						if (GoldSave[GoldSaveSorted[i]].show) then
-							coin_str = NiceCash(GoldSave[GoldSaveSorted[i]].gold, false, false)
-
-							currentMoneyRichText = currentMoneyRichText.."\n"..character.."-"..realmNames[ms].."\t"..coin_str
-						end
+		for i = 1, getn(GoldSaveSorted) do
+			character, charserver = string.match(GoldSaveSorted[i], '(.*)_(.*)');
+			local _, char_faction = string.match(charserver, '(.*)::(.*)')
+			if (charserver) then
+				charserver = string.gsub(charserver, "%s", "");
+			end
+			if (character) then
+				if (char_faction == faction) then
+					if (GoldSave[GoldSaveSorted[i]].show) then
+						coin_str = NiceCash(GoldSave[GoldSaveSorted[i]].gold, false, false)
+						currentMoneyRichText = currentMoneyRichText.."\n"..character.."-"..charserver.."\t"..coin_str
 					end
 				end
 			end
@@ -450,7 +448,10 @@ end
 -- *******************************************************************************************
 function TitanPanelGoldButton_TotalGold()
 	local ttlgold = 0;
+	local cnt = 0;
 	local countelements = 0;
+	local faction = UnitFactionGroup("Player");
+
 	for _ in pairs (realmNames) do countelements = countelements + 1 end
 	if countelements == 0 or TitanGetVar(TITAN_GOLD_ID, "SeparateServers") then
 		local server = realmName.."::"..UnitFactionGroup("Player");
@@ -467,20 +468,18 @@ function TitanPanelGoldButton_TotalGold()
 			end
 		end
 	else
-		for ms = 1, countelements do
-			local server = realmNames[ms].."::"..UnitFactionGroup("Player");
-			GoldSave[GOLD_INDEX].gold = GetMoney("player")
-
-			for index, money in pairs(GoldSave) do
-				local character, charserver = string.match(index, '(.*)_(.*)');
-				if (charserver) then
-					charserver = string.gsub(charserver, "%s", "");
-				end
-				if (character) then
-					if (charserver == server) then
-						if GoldSave[index].show then
-							ttlgold = ttlgold + GoldSave[index].gold;
-						end
+		GoldSave[GOLD_INDEX].gold = GetMoney("player")
+
+		for index, money in pairs(GoldSave) do
+			local character, charserver = string.match(index, '(.*)_(.*)');
+			local _, char_faction = string.match(charserver, '(.*)::(.*)')
+			if (charserver) then
+				charserver = string.gsub(charserver, "%s", "");
+			end
+			if (character) then
+				if (char_faction == faction) then
+					if GoldSave[index].show then
+						ttlgold = ttlgold + GoldSave[index].gold;
 					end
 				end
 			end
@@ -509,7 +508,7 @@ local function ShowMenuButtons(faction)
 				GoldSave[rementry].show = not GoldSave[rementry].show;
 				TitanPanelButton_UpdateButton(TITAN_GOLD_ID)
 			end
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+			DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);
 		end
 	end
 end
@@ -535,7 +534,7 @@ local function DeleteMenuButtons(faction)
 			else
 				info.disabled = nil;
 			end
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+			DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);
 		end
 	end
 end
@@ -628,23 +627,21 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.func = function()
 			ShowProperLabels("ShowCoinNone")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);
 		local info = {};
 		info.text = L["TITAN_GOLD_COIN_LABELS"];
 		info.checked = TitanGetVar(TITAN_GOLD_ID, "ShowCoinLabels");
 		info.func = function()
 			ShowProperLabels("ShowCoinLabels")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);
 		local info = {};
 		info.text = L["TITAN_GOLD_COIN_ICONS"];
 		info.checked = TitanGetVar(TITAN_GOLD_ID, "ShowCoinIcons");
 		info.func = function()
 			ShowProperLabels("ShowCoinIcons")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);

 		TitanPanelRightClickMenu_AddSpacer();

@@ -654,15 +651,14 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.func = function()
 			Seperator("UseSeperatorComma")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);
 		local info = {};
 		info.text = L["TITAN_USE_PERIOD"];
 		info.checked = TitanGetVar(TITAN_GOLD_ID, "UseSeperatorPeriod");
 		info.func = function()
 			Seperator("UseSeperatorPeriod")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);

 		TitanPanelRightClickMenu_AddSpacer();

@@ -672,15 +668,14 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.func = function()
 			Merger("MergeServers")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);
 		local info = {};
 		info.text = L["TITAN_GOLD_SEPARATE"];
 		info.checked = TitanGetVar(TITAN_GOLD_ID, "SeparateServers");
 		info.func = function()
 			Merger("SeparateServers")
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);

 		TitanPanelRightClickMenu_AddSpacer();

@@ -691,7 +686,7 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 			TitanToggleVar(TITAN_GOLD_ID, "ShowGoldOnly");
 			TitanPanelButton_UpdateButton(TITAN_GOLD_ID);
 		end
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, _G["L_UIDROPDOWNMENU_MENU_LEVEL"]);

 		-- A blank line in the menu
 		TitanPanelRightClickMenu_AddSpacer();
@@ -702,7 +697,7 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.text = L["TITAN_GOLD_SHOW_PLAYER"];
 		info.value = "ToonShow";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info);

 		-- Delete toon
 		info = {};
@@ -710,7 +705,7 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.text = L["TITAN_GOLD_DELETE_PLAYER"];
 		info.value = "ToonDelete";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info);

 		-- A blank line in the menu
 		TitanPanelRightClickMenu_AddSpacer();
@@ -720,7 +715,7 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.notCheckable = true
 		info.text = L["TITAN_GOLD_CLEAR_DATA_TEXT"];
 		info.func = TitanGold_ClearDB;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info);

 		TitanPanelRightClickMenu_AddCommand(L["TITAN_GOLD_RESET_SESS_TEXT"], TITAN_GOLD_ID, "TitanPanelGoldButton_ResetSession");

@@ -729,7 +724,6 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		TitanPanelRightClickMenu_AddToggleIcon(TITAN_GOLD_ID);
 		TitanPanelRightClickMenu_AddToggleLabelText(TITAN_GOLD_ID);
 		TitanPanelRightClickMenu_AddToggleColoredText(TITAN_GOLD_ID);
-		TitanPanelRightClickMenu_AddToggleRightSide(TITAN_GOLD_ID);
 		TitanPanelRightClickMenu_AddSpacer();

 		-- Generic function to toggle and hide
@@ -742,24 +736,24 @@ function TitanPanelRightClickMenu_PrepareGoldMenu()
 		info.text = L["TITAN_GOLD_FACTION_PLAYER_ALLY"];
 		info.value = "DeleteAlliance";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);

 		info.text = L["TITAN_GOLD_FACTION_PLAYER_HORDE"];
 		info.value = "DeleteHorde";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);
 	elseif L_UIDROPDOWNMENU_MENU_LEVEL == 2 and L_UIDROPDOWNMENU_MENU_VALUE == "ToonShow" then
 		local info = {};
 		info.notCheckable = true
 		info.text = L["TITAN_GOLD_FACTION_PLAYER_ALLY"];
 		info.value = "ShowAlliance";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);

 		info.text = L["TITAN_GOLD_FACTION_PLAYER_HORDE"];
 		info.value = "ShowHorde";
 		info.hasArrow = 1;
-		TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+		DDM:UIDropDownMenu_AddButton(info, L_UIDROPDOWNMENU_MENU_LEVEL);
 	end

 	if L_UIDROPDOWNMENU_MENU_LEVEL == 3 and L_UIDROPDOWNMENU_MENU_VALUE == "DeleteAlliance" then