From 455db074b0bd286031f075f251abe7caa5a2c76e Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Tue, 6 Apr 2021 18:24:21 +0300
Subject: [PATCH] SL-14960 Add checkbox to turn off collision sound.

---
 indra/llprimitive/llmaterialtable.cpp           | 17 +++++++++++++++++
 indra/llprimitive/llmaterialtable.h             |  2 ++
 indra/newview/app_settings/settings.xml         | 11 +++++++++++
 indra/newview/llviewermessage.cpp               |  6 ++++++
 .../default/xui/en/panel_preferences_move.xml   |  9 +++++++++
 5 files changed, 45 insertions(+)

diff --git a/indra/llprimitive/llmaterialtable.cpp b/indra/llprimitive/llmaterialtable.cpp
index 37c718b4c63..58b2d00d44d 100644
--- a/indra/llprimitive/llmaterialtable.cpp
+++ b/indra/llprimitive/llmaterialtable.cpp
@@ -559,6 +559,23 @@ LLUUID LLMaterialTable::getCollisionSoundUUID(U8 mcode, U8 mcode2)
 	}
 }
 
+bool LLMaterialTable::isCollisionSound(const LLUUID &uuid)
+{
+	for (U8 i = 0; i < LL_MCODE_END; i++)
+	{
+		for (U8 j = 0; j < LL_MCODE_END; j++)
+		{
+			i &= LL_MCODE_MASK;
+			j &= LL_MCODE_MASK;
+			if (mCollisionSoundMatrix[i * LL_MCODE_END + j] == uuid)
+			{
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
 LLUUID LLMaterialTable::getSlidingSoundUUID(U8 mcode, U8 mcode2)
 {	
 	mcode &= LL_MCODE_MASK;
diff --git a/indra/llprimitive/llmaterialtable.h b/indra/llprimitive/llmaterialtable.h
index a17e0103ff8..0cf5e626efc 100644
--- a/indra/llprimitive/llmaterialtable.h
+++ b/indra/llprimitive/llmaterialtable.h
@@ -128,6 +128,8 @@ class LLMaterialTable
 	F32 getDamageMod(U8 mcode);
 	F32 getEPMod(U8 mcode);
 
+	bool isCollisionSound(const LLUUID &uuid);
+
 	LLUUID getCollisionSoundUUID(U8 mcode, U8 mcode2); 
 	LLUUID getSlidingSoundUUID(U8 mcode, U8 mcode2); 
 	LLUUID getRollingSoundUUID(U8 mcode, U8 mcode2); 
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index d4ef9cd9743..0236720c205 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -3748,6 +3748,17 @@
       <key>Value</key>
       <integer>1</integer>
     </map>
+    <key>EnableCollisionSounds</key>
+    <map>
+      <key>Comment</key>
+      <string>Play sounds on collision</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>Boolean</string>
+      <key>Value</key>
+      <integer>0</integer>
+    </map>
     <key>EnableMouselook</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index 458fc3b13d8..126d146ac6f 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -38,6 +38,7 @@
 #include "llfollowcamparams.h"
 #include "llinventorydefines.h"
 #include "lllslconstants.h"
+#include "llmaterialtable.h"
 #include "llregionhandle.h"
 #include "llsd.h"
 #include "llsdserialize.h"
@@ -3857,6 +3858,11 @@ void process_sound_trigger(LLMessageSystem *msg, void **)
 		return;
 	}
 
+	if (LLMaterialTable::basic.isCollisionSound(sound_id) && !gSavedSettings.getBOOL("EnableCollisionSounds"))
+	{
+		return;
+	}
+
 	gAudiop->triggerSound(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX, pos_global);
 }
 
diff --git a/indra/newview/skins/default/xui/en/panel_preferences_move.xml b/indra/newview/skins/default/xui/en/panel_preferences_move.xml
index 8794e3bf95a..864223e616c 100644
--- a/indra/newview/skins/default/xui/en/panel_preferences_move.xml
+++ b/indra/newview/skins/default/xui/en/panel_preferences_move.xml
@@ -259,6 +259,15 @@
     <combo_box.commit_callback
      function="Pref.ClickActionChange"/>
   </combo_box>
+  <check_box
+   control_name="EnableCollisionSounds"
+   height="20"
+   label="Play sound on collisions"
+   layout="topleft"
+   left="83"
+   name="sound_on_collisions"
+   top_pad="10"
+   width="200" />
   <button
    height="23"
    label="Other Devices"
-- 
GitLab