From 82fb4a08ec469cc2c44833d2240564e3f9045d03 Mon Sep 17 00:00:00 2001
From: Andrey Lihatskiy <alihatskiy@productengine.com>
Date: Thu, 13 Apr 2023 07:05:05 +0300
Subject: [PATCH] SL-19591 Prompt user to save current settings as Graphics
 Preset before enabling AutoFPS

---
 indra/newview/llfloaterperformance.cpp        | 26 ++++++++++++++++++-
 indra/newview/llfloaterperformance.h          |  1 +
 .../skins/default/xui/en/notifications.xml    | 14 ++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llfloaterperformance.cpp b/indra/newview/llfloaterperformance.cpp
index 5eb58b9482e..e35fa555646 100644
--- a/indra/newview/llfloaterperformance.cpp
+++ b/indra/newview/llfloaterperformance.cpp
@@ -39,6 +39,7 @@
 #include "llnamelistctrl.h"
 #include "llnotificationsutil.h"
 #include "llperfstats.h"
+#include "llpresetsmanager.h"
 #include "llradiogroup.h"
 #include "llsliderctrl.h"
 #include "lltextbox.h"
@@ -158,6 +159,8 @@ BOOL LLFloaterPerformance::postBuild()
     mStartAutotuneBtn->setCommitCallback(boost::bind(&LLFloaterPerformance::startAutotune, this));
     mStopAutotuneBtn->setCommitCallback(boost::bind(&LLFloaterPerformance::stopAutotune, this));
 
+    gSavedPerAccountSettings.declareBOOL("HadEnabledAutoFPS", FALSE, "User had enabled AutoFPS at least once", LLControlVariable::PERSIST_ALWAYS);
+
     return TRUE;
 }
 
@@ -188,7 +191,10 @@ void LLFloaterPerformance::showAutoadjustmentsPanel()
 
 void LLFloaterPerformance::draw()
 {
-    if (mUpdateTimer->hasExpired())
+    enableAutotuneWarning();
+
+    if (mUpdateTimer->hasExpired() && 
+        !LLFloaterReg::instanceVisible("save_pref_preset", PRESETS_GRAPHIC)) // give user a chance to save the graphics settings before updating them
     {
         setFPSText();
         if (mHUDsPanel->getVisible())
@@ -672,4 +678,22 @@ void LLFloaterPerformance::updateAutotuneCtrls(bool autotune_enabled)
     getChild<LLTextBox>("wip_desc")->setVisible(autotune_enabled && !auto_tune_locked);
     getChild<LLTextBox>("display_desc")->setVisible(LLPerfStats::tunables.vsyncEnabled);
 }
+
+void LLFloaterPerformance::enableAutotuneWarning()
+{
+    if (!gSavedPerAccountSettings.getBOOL("HadEnabledAutoFPS") && LLPerfStats::tunables.userAutoTuneEnabled)
+    {
+        gSavedPerAccountSettings.setBOOL("HadEnabledAutoFPS", TRUE);
+
+        LLNotificationsUtil::add("EnableAutoFPSWarning", LLSD(), LLSD(),
+            [](const LLSD& notif, const LLSD& resp)
+            {
+                S32 opt = LLNotificationsUtil::getSelectedOption(notif, resp);
+                if (opt == 0)
+                { // offer user to save current graphics settings as a preset
+                    LLFloaterReg::showInstance("save_pref_preset", PRESETS_GRAPHIC);
+                }
+            });
+    }
+}
 // EOF
diff --git a/indra/newview/llfloaterperformance.h b/indra/newview/llfloaterperformance.h
index 648e5902b65..00f904f6d62 100644
--- a/indra/newview/llfloaterperformance.h
+++ b/indra/newview/llfloaterperformance.h
@@ -71,6 +71,7 @@ class LLFloaterPerformance : public LLFloater
     void startAutotune();
     void stopAutotune();
     void updateAutotuneCtrls(bool autotune_enabled);
+    void enableAutotuneWarning();
 
     void updateMaxRenderTime();
 
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 067e5c23c9d..f9211600ea0 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -11965,4 +11965,18 @@ If you want others to see this object, remove it and re-attach it to an avatar a
         yestext="OK"/>
   </notification>
 
+  <notification
+   icon="alertmodal.tga"
+   name="EnableAutoFPSWarning"
+   type="alertmodal">
+You are about to enable AutoFPS. All unsaved graphics settings will be lost.
+
+Would you like to save them first?
+      <tag>confirm</tag>
+      <usetemplate
+       name="okcancelbuttons"
+       notext="No"
+       yestext="Yes"/>
+  </notification>
+    
 </notifications>
-- 
GitLab