Version 1.1.14

Ulrik Larsen [02-19-23 - 13:51]
Version 1.1.14
Filename
Changelog
CollectionBars.lua
bindings/Bindings.lua
bindings/Bindings.xml
components/menu/Settings_Data.lua
values/General.lua
diff --git a/Changelog b/Changelog
index 61c23c4..4cc47f8 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,15 @@
 -------------------------------------------------------------------------------
  Collection bars
 -------------------------------------------------------------------------------
+Version 1.1.14 (2023-02-19)
+- Reworked how bindings are done
+  - BE AWARE - CHANGES ARE NOT BACKWARDS COMPATIBLE
+- Addded functionality to set a number of hotkeys
+  - Be aware when limiting the number of hotkeys, that:
+    - To unbind a hotkey it is not enough to limit the number of hotkeys, you need to unbound it under "ESO: CONTROLS > Keybindings"
+    - The addon no longer monitors hotkeys outside the desired range
+    - Bound hotkeys can be used no matter the range
+
 Version 1.1.13 (2023-02-12)
 - Added confirmation for:
   - Remove all character settings
diff --git a/CollectionBars.lua b/CollectionBars.lua
index 5e92d45..1031769 100644
--- a/CollectionBars.lua
+++ b/CollectionBars.lua
@@ -20,10 +20,9 @@ function base.OnAddOnLoaded(_, addonName)
 		base:SetLogsEnabled()
 		base:GenerateCategories()
 		base:SetSavedSettings() -- Complete saved settings
-		base:InitializeReverseBinding()
+		base:InitializeBindings()
 		base:InitializeCombineFrame()
 		base:InitializeWithSavedData()
-		base:InitializeBindings()
 		base:InitializeSettingsSlash()

 		EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED)
diff --git a/bindings/Bindings.lua b/bindings/Bindings.lua
index c7e251d..b454c6d 100644
--- a/bindings/Bindings.lua
+++ b/bindings/Bindings.lua
@@ -19,35 +19,34 @@ function CBs_Clicked(keyId)
 	base:Debug("CBs_Clicked", keyId)

 	local control = base.WM:GetMouseOverControl()
-	local collectibleId = base.Saved.Bindings[keyId]
+	local existingCollectibleId = base.Saved.Bindings[keyId]

 	if control ~= nil and control.CBs then
-		local newCId = control:GetId()
-		local previousCId = collectibleId
+		local targetCollectibleId = control:GetId()

-		if previousCId ~= newCId then
-			for _keyId, cid in ipairs(base.Saved.Bindings) do
-				if _keyId ~= keyId and cid == newCId then
-					base.Saved.Bindings[_keyId] = 0
-				end
+		if existingCollectibleId ~= targetCollectibleId then
+			local existingTargetBinding = base.Global.ReverseBindings[targetCollectibleId]
+			if existingTargetBinding ~= nil then
+				base.Saved.Bindings[existingTargetBinding] = nil
+				base.Global.ReverseBindings[targetCollectibleId] = nil
 			end

-			for cid, _keyId in pairs(base.Global.ReverseBindings) do
-				if cid ~= newCId and _keyId == keyId then
-					base.Global.ReverseBindings[cid] = nil
-					base:SetBindingText(cid)
-				end
+			local existingSourceBinding = existingCollectibleId ~= nil and base.Global.ReverseBindings[existingCollectibleId]
+			if existingSourceBinding ~= nil then
+				base.Saved.Bindings[existingSourceBinding] = nil
+				base.Global.ReverseBindings[existingCollectibleId] = nil
+				base:SetBindingText(existingCollectibleId)
 			end

-			base.Saved.Bindings[keyId] = newCId
-			base.Global.ReverseBindings[newCId] = keyId
-			base:SetBindingText(newCId)
+			base.Saved.Bindings[keyId] = targetCollectibleId
+			base.Global.ReverseBindings[targetCollectibleId] = keyId
+			base:SetBindingText(targetCollectibleId)
 		end
-	elseif collectibleId > 0 then
-		if base.AllButtons[collectibleId] then
-			base:Activate(base.AllButtons[collectibleId])
+	elseif existingCollectibleId ~= nil and existingCollectibleId > 0 then
+		if base.AllButtons[existingCollectibleId] then
+			base:Activate(base.AllButtons[existingCollectibleId])
 		else
-			UseCollectible(collectibleId)
+			UseCollectible(existingCollectibleId)
 		end
 	end
 end
@@ -61,21 +60,16 @@ function base:SetBindingText(cid)
 end

 function base:InitializeBindings()
-	base:Debug("InitializeBindings")
+	base:Debug("InitializeBindings", base.Saved.Bindings.Number)

 	ZO_CreateStringId(string.format(texts.FormatBindingName, "Settings"), "Settings")

-	for key, _ in ipairs(base.Saved.Bindings) do
+	for key = 1, base.Saved.Bindings.Number do
 		ZO_CreateStringId(string.format(texts.FormatBindingName, key), string.format(texts.FormatAbbreviationLowDash, key))
-	end
-end
-
-function base:InitializeReverseBinding()
-	base:Debug("InitializeReverseBinding")

-	for keyId, collectibleId in ipairs(base.Saved.Bindings) do
-		if collectibleId > 0 then
-			base.Global.ReverseBindings[collectibleId] = keyId
+		local collectibleId = base.Saved.Bindings[key]
+		if collectibleId ~= nil and collectibleId > 0 then
+			base.Global.ReverseBindings[collectibleId] = key
 		end
 	end
 end
diff --git a/bindings/Bindings.xml b/bindings/Bindings.xml
index a2c161b..63c504a 100644
--- a/bindings/Bindings.xml
+++ b/bindings/Bindings.xml
@@ -64,6 +64,246 @@
       <Action name="CBs_20">
         <Down>CBs_Clicked(20)</Down>
       </Action>
+      <Action name="CBs_21">
+        <Down>CBs_Clicked(21)</Down>
+      </Action>
+      <Action name="CBs_22">
+        <Down>CBs_Clicked(22)</Down>
+      </Action>
+      <Action name="CBs_23">
+        <Down>CBs_Clicked(23)</Down>
+      </Action>
+      <Action name="CBs_24">
+        <Down>CBs_Clicked(24)</Down>
+      </Action>
+      <Action name="CBs_25">
+        <Down>CBs_Clicked(25)</Down>
+      </Action>
+      <Action name="CBs_26">
+        <Down>CBs_Clicked(26)</Down>
+      </Action>
+      <Action name="CBs_27">
+        <Down>CBs_Clicked(27)</Down>
+      </Action>
+      <Action name="CBs_28">
+        <Down>CBs_Clicked(28)</Down>
+      </Action>
+      <Action name="CBs_29">
+        <Down>CBs_Clicked(29)</Down>
+      </Action>
+      <Action name="CBs_30">
+        <Down>CBs_Clicked(30)</Down>
+      </Action>
+      <Action name="CBs_31">
+        <Down>CBs_Clicked(31)</Down>
+      </Action>
+      <Action name="CBs_32">
+        <Down>CBs_Clicked(32)</Down>
+      </Action>
+      <Action name="CBs_33">
+        <Down>CBs_Clicked(33)</Down>
+      </Action>
+      <Action name="CBs_34">
+        <Down>CBs_Clicked(34)</Down>
+      </Action>
+      <Action name="CBs_35">
+        <Down>CBs_Clicked(35)</Down>
+      </Action>
+      <Action name="CBs_36">
+        <Down>CBs_Clicked(36)</Down>
+      </Action>
+      <Action name="CBs_37">
+        <Down>CBs_Clicked(37)</Down>
+      </Action>
+      <Action name="CBs_38">
+        <Down>CBs_Clicked(38)</Down>
+      </Action>
+      <Action name="CBs_39">
+        <Down>CBs_Clicked(39)</Down>
+      </Action>
+      <Action name="CBs_40">
+        <Down>CBs_Clicked(40)</Down>
+      </Action>
+      <Action name="CBs_41">
+        <Down>CBs_Clicked(41)</Down>
+      </Action>
+      <Action name="CBs_42">
+        <Down>CBs_Clicked(42)</Down>
+      </Action>
+      <Action name="CBs_43">
+        <Down>CBs_Clicked(43)</Down>
+      </Action>
+      <Action name="CBs_44">
+        <Down>CBs_Clicked(44)</Down>
+      </Action>
+      <Action name="CBs_45">
+        <Down>CBs_Clicked(45)</Down>
+      </Action>
+      <Action name="CBs_46">
+        <Down>CBs_Clicked(46)</Down>
+      </Action>
+      <Action name="CBs_47">
+        <Down>CBs_Clicked(47)</Down>
+      </Action>
+      <Action name="CBs_48">
+        <Down>CBs_Clicked(48)</Down>
+      </Action>
+      <Action name="CBs_49">
+        <Down>CBs_Clicked(49)</Down>
+      </Action>
+      <Action name="CBs_50">
+        <Down>CBs_Clicked(50)</Down>
+      </Action>
+      <Action name="CBs_51">
+        <Down>CBs_Clicked(51)</Down>
+      </Action>
+      <Action name="CBs_52">
+        <Down>CBs_Clicked(52)</Down>
+      </Action>
+      <Action name="CBs_53">
+        <Down>CBs_Clicked(53)</Down>
+      </Action>
+      <Action name="CBs_54">
+        <Down>CBs_Clicked(54)</Down>
+      </Action>
+      <Action name="CBs_55">
+        <Down>CBs_Clicked(55)</Down>
+      </Action>
+      <Action name="CBs_56">
+        <Down>CBs_Clicked(56)</Down>
+      </Action>
+      <Action name="CBs_57">
+        <Down>CBs_Clicked(57)</Down>
+      </Action>
+      <Action name="CBs_58">
+        <Down>CBs_Clicked(58)</Down>
+      </Action>
+      <Action name="CBs_59">
+        <Down>CBs_Clicked(59)</Down>
+      </Action>
+      <Action name="CBs_60">
+        <Down>CBs_Clicked(60)</Down>
+      </Action>
+      <Action name="CBs_61">
+        <Down>CBs_Clicked(61)</Down>
+      </Action>
+      <Action name="CBs_62">
+        <Down>CBs_Clicked(62)</Down>
+      </Action>
+      <Action name="CBs_63">
+        <Down>CBs_Clicked(63)</Down>
+      </Action>
+      <Action name="CBs_64">
+        <Down>CBs_Clicked(64)</Down>
+      </Action>
+      <Action name="CBs_65">
+        <Down>CBs_Clicked(65)</Down>
+      </Action>
+      <Action name="CBs_66">
+        <Down>CBs_Clicked(66)</Down>
+      </Action>
+      <Action name="CBs_67">
+        <Down>CBs_Clicked(67)</Down>
+      </Action>
+      <Action name="CBs_68">
+        <Down>CBs_Clicked(68)</Down>
+      </Action>
+      <Action name="CBs_69">
+        <Down>CBs_Clicked(69)</Down>
+      </Action>
+      <Action name="CBs_70">
+        <Down>CBs_Clicked(70)</Down>
+      </Action>
+      <Action name="CBs_71">
+        <Down>CBs_Clicked(71)</Down>
+      </Action>
+      <Action name="CBs_72">
+        <Down>CBs_Clicked(72)</Down>
+      </Action>
+      <Action name="CBs_73">
+        <Down>CBs_Clicked(73)</Down>
+      </Action>
+      <Action name="CBs_74">
+        <Down>CBs_Clicked(74)</Down>
+      </Action>
+      <Action name="CBs_75">
+        <Down>CBs_Clicked(75)</Down>
+      </Action>
+      <Action name="CBs_76">
+        <Down>CBs_Clicked(76)</Down>
+      </Action>
+      <Action name="CBs_77">
+        <Down>CBs_Clicked(77)</Down>
+      </Action>
+      <Action name="CBs_78">
+        <Down>CBs_Clicked(78)</Down>
+      </Action>
+      <Action name="CBs_79">
+        <Down>CBs_Clicked(79)</Down>
+      </Action>
+      <Action name="CBs_80">
+        <Down>CBs_Clicked(80)</Down>
+      </Action>
+      <Action name="CBs_81">
+        <Down>CBs_Clicked(81)</Down>
+      </Action>
+      <Action name="CBs_82">
+        <Down>CBs_Clicked(82)</Down>
+      </Action>
+      <Action name="CBs_83">
+        <Down>CBs_Clicked(83)</Down>
+      </Action>
+      <Action name="CBs_84">
+        <Down>CBs_Clicked(84)</Down>
+      </Action>
+      <Action name="CBs_85">
+        <Down>CBs_Clicked(85)</Down>
+      </Action>
+      <Action name="CBs_86">
+        <Down>CBs_Clicked(86)</Down>
+      </Action>
+      <Action name="CBs_87">
+        <Down>CBs_Clicked(87)</Down>
+      </Action>
+      <Action name="CBs_88">
+        <Down>CBs_Clicked(88)</Down>
+      </Action>
+      <Action name="CBs_89">
+        <Down>CBs_Clicked(89)</Down>
+      </Action>
+      <Action name="CBs_90">
+        <Down>CBs_Clicked(90)</Down>
+      </Action>
+      <Action name="CBs_91">
+        <Down>CBs_Clicked(91)</Down>
+      </Action>
+      <Action name="CBs_92">
+        <Down>CBs_Clicked(92)</Down>
+      </Action>
+      <Action name="CBs_93">
+        <Down>CBs_Clicked(93)</Down>
+      </Action>
+      <Action name="CBs_94">
+        <Down>CBs_Clicked(94)</Down>
+      </Action>
+      <Action name="CBs_95">
+        <Down>CBs_Clicked(95)</Down>
+      </Action>
+      <Action name="CBs_96">
+        <Down>CBs_Clicked(96)</Down>
+      </Action>
+      <Action name="CBs_97">
+        <Down>CBs_Clicked(97)</Down>
+      </Action>
+      <Action name="CBs_98">
+        <Down>CBs_Clicked(98)</Down>
+      </Action>
+      <Action name="CBs_99">
+        <Down>CBs_Clicked(99)</Down>
+      </Action>
+      <Action name="CBs_100">
+        <Down>CBs_Clicked(100)</Down>
+      </Action>
     </Category>
   </Layer>
 </Bindings>
\ No newline at end of file
diff --git a/components/menu/Settings_Data.lua b/components/menu/Settings_Data.lua
index 5f0d047..76ebeb0 100644
--- a/components/menu/Settings_Data.lua
+++ b/components/menu/Settings_Data.lua
@@ -12,28 +12,22 @@ local texts = base.Texts
 -- FUNCTIONS --
 -------------------------------------------------------------------------------------------------

-ESO_Dialogs["CB_CONFIRM_DIALOG"] =
-{
-    mustChoose = true,
-	title = { text = "Confirm <<1>>" },
-	mainText = { text = "<<1>>" },
-    buttons =
-    {
-        [1] =
-        {
-            text = SI_OPTIONS_RESET,
-            callback = function(dialog)
+ESO_Dialogs["CB_CONFIRM_DIALOG"] = {
+	mustChoose = true,
+	title = {text = "Confirm <<1>>"},
+	mainText = {text = "<<1>>"},
+	buttons = {
+		[1] = {
+			text = SI_OPTIONS_RESET,
+			callback = function(dialog)
 				local callback = dialog and dialog.data and dialog.data.callback
 				if callback ~= nil then
 					callback()
 				end
 			end
-        },
-        [2] =
-        {
-            text = SI_DIALOG_CANCEL,
-        },
-    }
+		},
+		[2] = {text = SI_DIALOG_CANCEL}
+	}
 }

 function base.AppendMasterListTypeGeneral(self, listType)
@@ -60,17 +54,12 @@ function base.AppendMasterListTypeGeneral(self, listType)
 		confirmation = true,
 		message = "ARE YOU SURE!?",
 		funcSet = function()
-			ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG",
-				{
-					callback = function()
-						base:RemoveCharacterSettings()
-						base.Global.Settings.List:RefreshData()
-					end
-				}, {
-					titleParams={"remove all character settings"},
-					mainTextParams={"It will remove all character settings, only relying on account settings."}
-				}
-			)
+			ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG", {
+				callback = function()
+					base:RemoveCharacterSettings()
+					base.Global.Settings.List:RefreshData()
+				end
+			}, {titleParams = {"remove all character settings"}, mainTextParams = {"It will remove all character settings, only relying on account settings."}})
 		end
 	})
 	self:AppendRow_Button(listType, {
@@ -79,21 +68,41 @@ function base.AppendMasterListTypeGeneral(self, listType)
 		confirmation = true,
 		message = "ARE YOU SURE!?",
 		funcSet = function()
-			ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG",
-				{
+			ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG", {
+				callback = function()
+					base:ResetSavedSettings()
+					base:SetLogsEnabled()
+					base:InitializeWithSavedData()
+					base:RestoreFrames()
+					base:RestoreCombineLabels()
+					base.Global.Settings.List:RefreshData()
+				end
+			}, {titleParams = {"reset settings"}, mainTextParams = {"It will reset settings back to default."}})
+		end
+	})
+	self:AppendRow_Title(listType, {name = "Keybindings"})
+	self:AppendRow_Divider(listType, {})
+	self:AppendRow_Dropdown(listType, {
+		name = "Change number of keybindings",
+		tooltipText = "It will change the number of keybindings in the \"Controls\" page",
+		funcGet = function()
+			return base.Saved.Bindings.Number
+		end,
+		choices = base.Global.ChoiceNumberOfBindings,
+		funcSet = function(_, newValue)
+			if base.Saved.Bindings.Number ~= newValue then
+				ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG", {
 					callback = function()
-						base:ResetSavedSettings()
-						base:SetLogsEnabled()
-						base:InitializeWithSavedData()
-						base:RestoreFrames()
-						base:RestoreCombineLabels()
-						base.Global.Settings.List:RefreshData()
+						base.Saved.Bindings.Number = newValue
+						ReloadUI("ingame")
 					end
 				}, {
-					titleParams={"reset settings"},
-					mainTextParams={"It will reset settings back to default."}
-				}
-			)
+					titleParams = {"change number of keybindings"},
+					mainTextParams = {
+						"Be aware when limiting the number of hotkeys, that:\n- To unbind a hotkey it is not enough to limit the number of hotkeys, you need to unbound it under \"ESO: CONTROLS > Keybindings\".\n- The addon no longer monitors hotkeys outside the desired range.\n- Bound hotkeys can be used no matter the range"
+					}
+				})
+			end
 		end
 	})
 	self:AppendRow_Title(listType, {name = "Position and size"})
diff --git a/values/General.lua b/values/General.lua
index 528bc85..6399ff1 100644
--- a/values/General.lua
+++ b/values/General.lua
@@ -7,14 +7,14 @@ Filename: General.lua
 -------------------------------------------------------------------------------------------------
 CollectionBars = {
 	WM = GetWindowManager(),
-	Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 11, SettingsSlash = "/cb", Author = "Jarth"},
+	Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 14, SettingsSlash = "/cb", Author = "Jarth"},
 	AllButtons = {},
 	Default = {
 		UseAccountSettings = true,
 		Bar = {Depth = 5, Width = 0, SnapSize = 5},
 		Button = {Size = ZO_GAMEPAD_ACTION_BUTTON_SIZE, IsAudioEnabled = true, IsActiveActivationEnabled = true},
 		Scene = {OnHud = true, OnHudUI = true, InMenu = true, InInventory = false, InInteract = false, InBank = false, InFence = false, InStore = false},
-		Bindings = {Show = true, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0, [11] = 0, [12] = 0, [13] = 0, [14] = 0, [15] = 0, [16] = 0, [17] = 0, [18] = 0, [19] = 0, [20] = 0},
+		Bindings = {Show = true, Number = 20},
 		Combine = {Bar = {Depth = 0, Width = 0, Offset = {X = CENTER, Y = CENTER}}, Label = {Show = true, Display = "CombineBar", Offset = {X = 0, Y = 0}, Position = BOTTOMLEFT, PositionTarget = TOPLEFT}},
 		Categories = {},
 		Logging = {Info = false, Debug = false, Verbose = false}
@@ -26,6 +26,7 @@ CollectionBars = {
 		Settings = {Frame = nil, List = nil, Filters = {["Categories"] = "Categories", ["Collectibles"] = "Collectibles", ["Category"] = "Category", ["General"] = "General", ["Combined"] = "Combined bar"}},
 		Combine = {Name = "Combine", EventTS = nil, Frames = {Frame = nil, Move = nil}, category = nil, HideAll = nil, Fragment = nil, IsEmpty = false},
 		ChoiceLocations = {"top", "topright", "right", "bottomright", "bottom", "bottomleft", "left", "topleft", "center"},
+		ChoiceNumberOfBindings = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100},
 		AvailableFonts = {"ZoFontGameSmall", "ZoFontGameLarge", "ZoFontGameLargeBold", "ZoFontGameLargeBoldShadow", "ZoFontHeader", "ZoFontHeader2", "ZoFontHeader3", "ZoFontHeader4"},
 		Scenes = {
 			[1] = {Name = "OnHud", Instance = HUD_SCENE, Description = "%s on main view/hud"},