Made volume setting more explicit to the addon setting's rather than reading from current

Wobin [04-16-14 - 12:58]
Made volume setting more explicit to the addon setting's rather than reading from current
Added a keybind
Made both halves of the addon toggleable on or off
Filename
Bindings.xml
BorrowerAndLender.lua
BorrowerAndLender.txt
diff --git a/Bindings.xml b/Bindings.xml
new file mode 100644
index 0000000..32502a2
--- /dev/null
+++ b/Bindings.xml
@@ -0,0 +1,9 @@
+<Bindings>
+  <Layer name="General">
+    <Category name="Borrower And Lender">
+      <Action name="TOGGLE_BAL">
+        <Down>BorrowerAndLender.CommandHandler()</Down>
+      </Action>
+    </Category>
+  </Layer>
+</Bindings>
diff --git a/BorrowerAndLender.lua b/BorrowerAndLender.lua
index 06d44f1..3ef82c8 100644
--- a/BorrowerAndLender.lua
+++ b/BorrowerAndLender.lua
@@ -5,7 +5,6 @@ local LAM = LibStub:GetLibrary("LibAddonMenu-1.0")
 local originalLevel
 local inBank
 local control = ZO_OptionsWindow.controlTable[2][9]
-local currentLevels
 local currentWait = nil
 local settings

@@ -13,18 +12,14 @@ function EndsWith(String,End)
    return End=='' or string.sub(String,-string.len(End))==End
 end

-local function Hush()
-	if control.currentChoice ~= 0 then
-		currentLevels = control.currentChoice or control.value
-		SetSetting(control.system, control.settingId, 0)
-	end
+local function Hush()
+	SetSetting(control.system, control.settingId, 0)
 end

 local function SpeakUpLad()
 	if currentWait then BorrowerAndLender:CancelTimer(currentWait) end
-	currentWait = nil
-	control.currentChoice = currentLevels or settings.defaultSoundLevel
-	SetSetting(control.system, control.settingId, control.currentChoice)
+	currentWait = nil
+	SetSetting(control.system, control.settingId, settings.defaultSoundLevel)
 end

 local function WhoAmI(eventCode, options)
@@ -57,10 +52,12 @@ local function BorrowerAndLenderLoaded(eventCode, addOnName)

 	local defaults = {
 		chats = {},
-		defaultSoundLevel = control.currentChoice or control.value or 0
+		defaultSoundLevel = control.currentChoice or control.value or 75,
+		muteBank = true,
+		muteAmbient = true
 	}

-	settings = ZO_SavedVars:NewAccountWide("BorrowerAndLender_Settings", 1, nil, defaults)
+	settings = ZO_SavedVars:NewAccountWide("BorrowerAndLender_Settings", 3, nil, defaults)

 	local panel = LAM:CreateControlPanel("BAL", "Borrower And Lender")

@@ -70,12 +67,46 @@ local function BorrowerAndLenderLoaded(eventCode, addOnName)
 						"Set this value to your standard voice over volume",
 						0, 100, 1, function() return settings.defaultSoundLevel end,
 						function(value) settings.defaultSoundLevel = value end)
-
-
-	EVENT_MANAGER:RegisterForEvent("BALWho", EVENT_CHATTER_BEGIN, WhoAmI)
-	EVENT_MANAGER:RegisterForEvent("BALWho", EVENT_CHATTER_END, SpeakUpLad)
-	EVENT_MANAGER:RegisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL, FilterNPC)
+	LAM:AddCheckbox(panel, "muteBank", "Mute bank npcs", "Set this on to mute all bank NPCs from speaking",
+					function() return settings.muteBank end,
+					function(value)
+						if value == false then
+							EVENT_MANAGER:UnregisterForEvent("BALWho", EVENT_CHATTER_BEGIN)
+							EVENT_MANAGER:UnregisterForEvent("BALTalk", EVENT_CHATTER_END)
+						else
+							EVENT_MANAGER:RegisterForEvent("BALWho", EVENT_CHATTER_BEGIN, WhoAmI)
+							EVENT_MANAGER:RegisterForEvent("BALTalk", EVENT_CHATTER_END, SpeakUpLad)
+						end
+						settings.muteBank = value
+					end)
+	LAM:AddCheckbox(panel, "muteAmbient", "Mute ambient NPCs", "Mute passing npcs from repeated chats",
+					function() return settings.muteAmbient end,
+					function(value)
+						if value == false then
+							EVENT_MANAGER:UnregisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL)
+						else
+							EVENT_MANAGER:RegisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL, FilterNPC)
+						end
+						settings.muteAmbient = value
+					end)
+	if settings.muteBank then
+		EVENT_MANAGER:RegisterForEvent("BALWho", EVENT_CHATTER_BEGIN, WhoAmI)
+		EVENT_MANAGER:RegisterForEvent("BALTalk", EVENT_CHATTER_END, SpeakUpLad)
+	end
+	if settings.muteAmbient then
+		EVENT_MANAGER:RegisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL, FilterNPC)
+	end
 end

+function BorrowerAndLender:CommandHandler()
+	settings.muteAmbient = not settings.muteAmbient
+	if settings.muteAmbient == false then
+		EVENT_MANAGER:UnregisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL)
+	else
+		EVENT_MANAGER:RegisterForEvent("BALChat", EVENT_CHAT_MESSAGE_CHANNEL, FilterNPC)
+	end
+
+end
+ZO_CreateStringId("SI_BINDING_NAME_TOGGLE_BAL", "Toggle Ambient NPC Ignoring")

 EVENT_MANAGER:RegisterForEvent("BorrowerAndLenderLoaded", EVENT_ADD_ON_LOADED, BorrowerAndLenderLoaded)
\ No newline at end of file
diff --git a/BorrowerAndLender.txt b/BorrowerAndLender.txt
index 538a670..6b5f973 100644
--- a/BorrowerAndLender.txt
+++ b/BorrowerAndLender.txt
@@ -8,4 +8,5 @@ libs/LibStub/LibStub.lua
 libs/AceTimer-3.0/AceTimer-3.0.lua
 libs\LibAddonMenu-1.0\LibAddonMenu-1.0.lua

-BorrowerAndLender.lua
\ No newline at end of file
+BorrowerAndLender.lua
+Bindings.xml
\ No newline at end of file