From 7af2d51f57416cb68b435cecfd4eacf5d1a4c9fc Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Fri, 4 Feb 2022 12:46:23 +0200
Subject: [PATCH] SL-15923 increase the shortcut level to the minimum required
 when clicking advanced lighting or shadows settings

---
 indra/newview/llfloaterperformance.cpp        | 55 +++++++++++++++++++
 indra/newview/llfloaterperformance.h          |  4 ++
 .../skins/default/xui/en/notifications.xml    | 28 +++++++++-
 3 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llfloaterperformance.cpp b/indra/newview/llfloaterperformance.cpp
index 9cb3c4ce666..e45d7a0c73e 100644
--- a/indra/newview/llfloaterperformance.cpp
+++ b/indra/newview/llfloaterperformance.cpp
@@ -32,6 +32,7 @@
 #include "llavataractions.h"
 #include "llavatarrendernotifier.h"
 #include "llcheckboxctrl.h"
+#include "llcombobox.h"
 #include "llfeaturemanager.h"
 #include "llfloaterpreference.h" // LLAvatarComplexityControls
 #include "llfloaterreg.h"
@@ -120,6 +121,8 @@ BOOL LLFloaterPerformance::postBuild()
 
     mSettingsPanel->getChild<LLButton>("advanced_btn")->setCommitCallback(boost::bind(&LLFloaterPerformance::onClickAdvanced, this));
     mSettingsPanel->getChild<LLRadioGroup>("graphics_quality")->setCommitCallback(boost::bind(&LLFloaterPerformance::onChangeQuality, this, _2));
+    mSettingsPanel->getChild<LLCheckBoxCtrl>("advanced_lighting_model")->setMouseDownCallback(boost::bind(&LLFloaterPerformance::onClickAdvancedLighting, this));
+    mSettingsPanel->getChild<LLComboBox>("ShadowDetail")->setMouseDownCallback(boost::bind(&LLFloaterPerformance::onClickShadows, this));
 
     mNearbyPanel->getChild<LLButton>("exceptions_btn")->setCommitCallback(boost::bind(&LLFloaterPerformance::onClickExceptions, this));
     mNearbyPanel->getChild<LLCheckBoxCtrl>("hide_avatars")->setCommitCallback(boost::bind(&LLFloaterPerformance::onClickHideAvatars, this));
@@ -540,4 +543,56 @@ void LLFloaterPerformance::onAvatarListRightClick(LLUICtrl* ctrl, S32 x, S32 y)
     }
 }
 
+const U32 RENDER_QUALITY_LEVEL = 3;
+void LLFloaterPerformance::changeQualityLevel(const std::string& notif)
+{
+    LLNotificationsUtil::add(notif, LLSD(), LLSD(),
+        [](const LLSD&notif, const LLSD&resp)
+    {
+        S32 opt = LLNotificationsUtil::getSelectedOption(notif, resp);
+        if (opt == 0)
+        {
+            LLFloaterPreference* instance = LLFloaterReg::getTypedInstance<LLFloaterPreference>("preferences");
+            if (instance)
+            {
+                gSavedSettings.setU32("RenderQualityPerformance", RENDER_QUALITY_LEVEL);
+                instance->onChangeQuality(LLSD((S32)RENDER_QUALITY_LEVEL));
+            }
+        }
+    });
+}
+
+bool is_ALM_available()
+{
+    bool bumpshiny = gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps && LLFeatureManager::getInstance()->isFeatureAvailable("RenderObjectBump") && gSavedSettings.getBOOL("RenderObjectBump");
+    bool shaders = gSavedSettings.getBOOL("WindLightUseAtmosShaders");
+    
+    return LLFeatureManager::getInstance()->isFeatureAvailable("RenderDeferred") &&
+        bumpshiny &&
+        shaders &&
+        gGLManager.mHasFramebufferObject;
+}
+
+void LLFloaterPerformance::onClickAdvancedLighting()
+{
+    if (!is_ALM_available())
+    {
+        changeQualityLevel("AdvancedLightingConfirm");
+    }
+}
+
+void LLFloaterPerformance::onClickShadows()
+{
+    if (gSavedSettings.getBOOL("AutoFPS"))
+    {
+        LLFloaterPreference::showAutoAdjustWarning();
+    }
+    else
+    {
+        if (!is_ALM_available() || !gSavedSettings.getBOOL("RenderDeferred"))
+        {
+            changeQualityLevel("ShadowsConfirm");
+        }
+    }
+}
 // EOF
diff --git a/indra/newview/llfloaterperformance.h b/indra/newview/llfloaterperformance.h
index d8288b0728e..9ccb29cd7b5 100644
--- a/indra/newview/llfloaterperformance.h
+++ b/indra/newview/llfloaterperformance.h
@@ -62,10 +62,14 @@ class LLFloaterPerformance : public LLFloater
     void onChangeQuality(const LLSD& data);
     void onClickHideAvatars();
     void onClickExceptions();
+    void onClickShadows();
+    void onClickAdvancedLighting();
 
     void updateMaxComplexity();
     void updateComplexityText();
 
+    static void changeQualityLevel(const std::string& notif);
+
     LLPanel* mMainPanel;
     LLPanel* mNearbyPanel;
     LLPanel* mComplexityPanel;
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 2fed214d698..e01865a5eaf 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -1848,9 +1848,9 @@ Graphics Quality can be raised in Preferences &gt; Graphics.
   </notification>
 
   <notification
- icon="alertmodal.tga"
- name="AutoFPSConfirmDisable"
- type="alertmodal">
+   icon="alertmodal.tga"
+   name="AutoFPSConfirmDisable"
+   type="alertmodal">
     Changing this setting will disable automatic adjustment and turn off 'Auto FPS' setting.
 Are you sure you want to continue?
     <tag>confirm</tag>
@@ -1859,6 +1859,28 @@ Are you sure you want to continue?
      notext="Cancel"
      yestext="Continue"/>
   </notification>
+  <notification
+   icon="alertmodal.tga"
+   name="AdvancedLightingConfirm"
+   type="alertmodal">
+To turn on advanced lighting, we need to increase quality to level 4.
+    <tag>confirm</tag>
+  <usetemplate
+   name="okcancelbuttons"
+   notext="Cancel"
+   yestext="OK"/>
+  </notification>
+  <notification
+ icon="alertmodal.tga"
+   name="ShadowsConfirm"
+   type="alertmodal">
+To enable shadows, we need to increase quality to level 4.
+    <tag>confirm</tag>
+    <usetemplate
+     name="okcancelbuttons"
+     notext="Cancel"
+     yestext="OK"/>
+  </notification>
 
   <notification
    icon="alertmodal.tga"
-- 
GitLab