Quantcast

- Extend custom labels to 2 thru 4; update Config to only show labels 'seen'. Config may not be right, especially if plugin shows more than 1 label until plugin is used / shown.

urnati [01-09-23 - 19:21]
- Extend custom labels to 2 thru 4; update Config to only show labels 'seen'. Config may not be right, especially if plugin shows more than 1 label until plugin is used / shown.
Filename
Titan/TitanConfig.lua
Titan/TitanPanelTemplate.lua
Titan/TitanUtils.lua
diff --git a/Titan/TitanConfig.lua b/Titan/TitanConfig.lua
index 263009d..96118f0 100644
--- a/Titan/TitanConfig.lua
+++ b/Titan/TitanConfig.lua
@@ -33,21 +33,11 @@ local notes = ""
 		.."On PTR the menu & bag frame and the status / xp frame ARE adjustable via edit mode. This adjustment will be removed in a future release.\n"
 		)
 local changes = ""
-	..TitanUtils_GetGoldText("6.00.11.100002 : 2023/02/01\n\n")
+	..TitanUtils_GetGoldText("6.00.11.100002 : 2023/01/31\n\n")
 	..TitanUtils_GetGreenText("Plugins over another : \n")
 	..TitanUtils_GetHighlightText(""
 		.."- Fix for plugins that could show over another.\n"
 		)
-	..TitanUtils_GetGreenText("TitanRepair : \n")
-	..TitanUtils_GetHighlightText(""
-		.."- Added feature to sell ALL gray items at vendor - auto sell or on left click while at vendor\n"
-		.."- NOTE: ALL grays are sold - use CAUTION!\n"
-		)
-	..TitanUtils_GetGreenText("TitanBag : \n")
-	..TitanUtils_GetHighlightText(""
-		.."- Rewritten due to inaccurate info being seen.\n"
-		.."- NOTE: At entering world or reload the bag names may not be know. This will correct at next bag trigger.\n"
-		)
 	..TitanUtils_GetGreenText("Scaling : \n")
 	..TitanUtils_GetHighlightText(""
 		.."- Fix for error when changing scaling.\n"
@@ -57,6 +47,10 @@ local changes = ""
 		.."- About : Add slash command description to About.\n"
 		.."- Changes : Added to show change history.\n"
 		)
+	..TitanUtils_GetGreenText("Plugins : \n")
+	..TitanUtils_GetHighlightText(""
+		.."- Labels : Extend custom labels to 2 (second) through 4 (fourth). Plugins should be used / shown at least once, especially if more than one label / value pair is shown by that plugin.\n"
+		)
 	..TitanUtils_GetGoldText("6.00.10.100002 : 2022/12/13\n\n")
 	..TitanUtils_GetGreenText("TitanBag : \n")
 	..TitanUtils_GetHighlightText(""
@@ -1847,37 +1841,9 @@ local function TitanUpdateConfigAddons()
 				name = "  ",
 				cmdHidden = true,
 			}
-			--
-			-- Custom Label
-			args[plug_in.id].args.custom_labels = {
-				order = 60,
-				type = "header",
-				name = SHOW.." "..CUSTOM.." ".."Labels",
-			}
-			args[plug_in.id].args.custom_label_show = {
-				type = "toggle",
-				name = SHOW,
-				order = 62,
-				get = function(info) return (TitanGetVar(info[1], "CustomLabelTextShow") or false) end,
-				set = function(info, v)
-					TitanToggleVar(info[1], "CustomLabelTextShow");
-					TitanPanelButton_UpdateButton(info[1])
-				end,
-			}
-			args[plug_in.id].args.custom_label_text = {
-				order = 64,
-				name = CUSTOM,
-				desc = "Custom label text to show",
-				type = "input", width = "full",
-				get = function(info) return (TitanGetVar(info[1], "CustomLabelText") or "") end,
-				set = function(info,v)
-					TitanSetVar(info[1], "CustomLabelText", v);
-					TitanPanelButton_UpdateButton(info[1])
-					end,
-			}
 			-- Notes, if available
 			args[plug_in.id].args.custom_notes = {
-				order = 70,
+				order = 60,
 				type = "header",
 				name = "Notes",
 			}
@@ -1885,7 +1851,7 @@ local function TitanUpdateConfigAddons()
 				args[plug_in.id].args.notes = {
 					type = "description",
 					name = "Notes",
-					order = 71,
+					order = 61,
 				name = ""
 					.._G["GREEN_FONT_COLOR_CODE"]..plug_in.notes.."|r",
 				cmdHidden = true,
@@ -1894,11 +1860,112 @@ local function TitanUpdateConfigAddons()
 				args[plug_in.id].args.notes = {
 					type = "description",
 					name = "Notes",
-					order = 71,
+					order = 61,
 				name = _G["GREEN_FONT_COLOR_CODE"]..NONE.."|r",
 				cmdHidden = true,
 				}
 			end
+			--
+			-- Custom Labels 1 - 4
+			local num_labels = tonumber(TitanGetVar(plug_in.id, "NumLabelsSeen") or 1)
+
+			if num_labels >= 1 then
+				args[plug_in.id].args.custom_labels = {
+					order = 70,
+					type = "header",
+					name = SHOW.." "..CUSTOM.." ".."Labels",
+				}
+				args[plug_in.id].args.custom_label_show = {
+					type = "toggle",
+					name = SHOW,
+					order = 71,
+					get = function(info) return (TitanGetVar(info[1], "CustomLabelTextShow") or false) end,
+					set = function(info, v)
+						TitanToggleVar(info[1], "CustomLabelTextShow");
+						TitanPanelButton_UpdateButton(info[1])
+					end,
+				}
+				args[plug_in.id].args.custom_label_text = {
+					order = 72,
+					name = CUSTOM,
+					desc = "Custom label text to show",
+					type = "input", width = "full",
+					get = function(info) return (TitanGetVar(info[1], "CustomLabelText") or "") end,
+					set = function(info,v)
+						TitanSetVar(info[1], "CustomLabelText", v);
+						TitanPanelButton_UpdateButton(info[1])
+						end,
+				}
+			end
+			if num_labels >= 2 then
+				args[plug_in.id].args.custom_label2_show = {
+					type = "toggle",
+					name = SHOW.." 2",
+					order = 73,
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel2TextShow") or false) end,
+					set = function(info, v)
+						TitanToggleVar(info[1], "CustomLabel2TextShow");
+						TitanPanelButton_UpdateButton(info[1])
+					end,
+				}
+				args[plug_in.id].args.custom_label2_text = {
+					order = 74,
+					name = CUSTOM,
+					desc = "Custom label text to show",
+					type = "input", width = "full",
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel2Text") or "") end,
+					set = function(info,v)
+						TitanSetVar(info[1], "CustomLabel2Text", v);
+						TitanPanelButton_UpdateButton(info[1])
+						end,
+				}
+			end
+			if num_labels >= 3 then
+				args[plug_in.id].args.custom_label3_show = {
+					type = "toggle",
+					name = SHOW.." 3",
+					order = 75,
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel3TextShow") or false) end,
+					set = function(info, v)
+						TitanToggleVar(info[1], "CustomLabel3TextShow");
+						TitanPanelButton_UpdateButton(info[1])
+					end,
+				}
+				args[plug_in.id].args.custom_label3_text = {
+					order = 76,
+					name = CUSTOM,
+					desc = "Custom label text to show",
+					type = "input", width = "full",
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel3Text") or "") end,
+					set = function(info,v)
+						TitanSetVar(info[1], "CustomLabel3Text", v);
+						TitanPanelButton_UpdateButton(info[1])
+						end,
+				}
+			end
+			if num_labels >= 4 then
+				args[plug_in.id].args.custom_label4_show = {
+					type = "toggle",
+					name = SHOW.." 4",
+					order = 77,
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel4TextShow") or false) end,
+					set = function(info, v)
+						TitanToggleVar(info[1], "CustomLabel4TextShow");
+						TitanPanelButton_UpdateButton(info[1])
+					end,
+				}
+				args[plug_in.id].args.custom_label4_text = {
+					order = 78,
+					name = CUSTOM,
+					desc = "Custom label text to show",
+					type = "input", width = "full",
+					get = function(info) return (TitanGetVar(info[1], "CustomLabel4Text") or "") end,
+					set = function(info,v)
+						TitanSetVar(info[1], "CustomLabel4Text", v);
+						TitanPanelButton_UpdateButton(info[1])
+						end,
+				}
+			end
 		end
 	end

diff --git a/Titan/TitanPanelTemplate.lua b/Titan/TitanPanelTemplate.lua
index 867dd8a..b22adb9 100644
--- a/Titan/TitanPanelTemplate.lua
+++ b/Titan/TitanPanelTemplate.lua
@@ -814,7 +814,6 @@ local function TitanPanelButton_SetButtonText(id)
 		label1, value1, label2, value2, label3, value3, label4, value4 =
 			pcall(buttonTextFunction, id)

---	if not call_success then buttonText:SetText("<?>") return end
 	if call_success then
 		-- All is good
 	else
@@ -826,13 +825,25 @@ local function TitanPanelButton_SetButtonText(id)
 		return
 	end

+	--=====================================
+	-- Determine the label value pairs : 1 - 4
+	-- Each could be custom per user
+	--
+	-- NummLabelsSeen - used for the config to avoid confusing user
+	-- Plugin MUST have been shown at least once.
+
+	-- In the case of first label only (no value), set the button and return.
 	if label1 and
 		not (label2 or label3 or label4
 		or value1 or value2 or value3 or value4) then
 		buttonText:SetText(label1)
+
+		TitanSetVar(id, "NumLabelsSeen", 1)
+
 		return
 	end

+
 	local show_label = TitanGetVar(id, "ShowLabelText")
 	local values = 0
 	if label1 or value1 then
@@ -848,18 +859,45 @@ local function TitanPanelButton_SetButtonText(id)
 		end
 		if label2 or value2 then
 			values = 2
-			if not show_label then label2 = "" end
+			if show_label then
+				if TitanGetVar(id, "CustomLabel2TextShow") then
+					-- override the label per the user
+					label2 = TitanGetVar(id, "CustomLabel2Text")
+				else
+				end
+			else
+				label2 = ""
+			end
 			if label3 or value3 then
+				if show_label then
+					if TitanGetVar(id, "CustomLabel3TextShow") then
+						-- override the label per the user
+						label3 = TitanGetVar(id, "CustomLabel3Text")
+					else
+					end
+				else
+					label3 = ""
+				end
 				values = 3
-				if not show_label then label3 = "" end
 				if label4 or value4 then
 					values = 4
-					if not show_label then label4 = "" end
+					if show_label then
+						if TitanGetVar(id, "CustomLabel43TextShow") then
+							-- override the label per the user
+							label4 = TitanGetVar(id, "CustomLabel4Text")
+						else
+						end
+					else
+						label4 = ""
+					end
 				end
 			end
 		end
 	end

+	TitanSetVar(id, "NumLabelsSeen", values)
+
+	-- values tells which format to use from the array
 	buttonText:SetFormattedText(format_with_label[values],
 		label1 or "", value1 or "",
 		label2 or "", value2 or "",
diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua
index 95136b2..83e64a2 100644
--- a/Titan/TitanUtils.lua
+++ b/Titan/TitanUtils.lua
@@ -1405,6 +1405,23 @@ local function NoColor(name)
 	return no_color
 end

+local function AddCustomPluginVars(reg)
+	-- These are added to EACH plugin for various Titan controlled features
+
+	--==================
+	-- Custom labels
+	reg.savedVariables.CustomLabelTextShow = false
+	reg.savedVariables.CustomLabelText = ""
+	reg.savedVariables.CustomLabel2TextShow = false
+	reg.savedVariables.CustomLabel2Text = ""
+	reg.savedVariables.CustomLabel3TextShow = false
+	reg.savedVariables.CustomLabel3Text = ""
+	reg.savedVariables.CustomLabel4TextShow = false
+	reg.savedVariables.CustomLabel4Text = ""
+	-- Number of labels seen - make config less confusing
+	reg.savedVariables.NumLabelsSeen = 1 -- assume at least one label
+end
+
 --[[ local
 NAME: TitanUtils_RegisterPluginProtected
 DESC: This routine is intended to be called in a protected manner (pcall) by Titan when it attempts to register a plugin.
@@ -1449,7 +1466,7 @@ local function TitanUtils_RegisterPluginProtected(plugin)
 				id = self.registry.id
 				if TitanUtils_IsPluginRegistered(id) then
 					-- We have already registered this plugin!
-					issue =  "Plugin already loaded. "
+					issue =  "Plugin '"..tostring(id).."' already loaded. "
 					.."Please see if another plugin (Titan or LDB) is also loading "
 					.."with the same name.\n"
 					.."<Titan>.registry.id or <LDB>.label"
@@ -1464,6 +1481,12 @@ local function TitanUtils_RegisterPluginProtected(plugin)
 							-- Custom labels
 							self.registry.savedVariables.CustomLabelTextShow = false
 							self.registry.savedVariables.CustomLabelText = ""
+							self.registry.savedVariables.CustomLabel2TextShow = false
+							self.registry.savedVariables.CustomLabel2Text = ""
+							self.registry.savedVariables.CustomLabel3TextShow = false
+							self.registry.savedVariables.CustomLabel3Text = ""
+							self.registry.savedVariables.CustomLabel4TextShow = false
+							self.registry.savedVariables.CustomLabel4Text = ""
 						end

 						-- Assign and Sort the list of plugins
@@ -1477,15 +1500,6 @@ local function TitanUtils_RegisterPluginProtected(plugin)
 						table.insert(TitanPluginsIndex, self.registry.id);
 						table.sort(TitanPluginsIndex,
 							function(a, b)
---[[
-								-- if the .menuText is missing then use .id
-								if TitanPlugins[a].menuText == nil then
-									TitanPlugins[a].menuText = TitanPlugins[a].id;
-								end
-								if TitanPlugins[b].menuText == nil then
-									TitanPlugins[b].menuText = TitanPlugins[b].id;
-								end
---]]
 								return string.lower(TitanPlugins[a].menuText)
 									< string.lower(TitanPlugins[b].menuText);
 							end