summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2025-07-28 15:13:36 +0800
committerErik Kundiman <erik@megapahit.org>2025-07-28 15:13:36 +0800
commit306eb28d78c9aa83669307dc49daacb94f8c8742 (patch)
tree90062be2796d4fb8aababf11f670f8a2e9224dad
parentec86ee28171428824cde4afe88d1165e80633233 (diff)
Location for Discord Rich Presence Activity State
I was going to use LLAgentUI::buildLocationString but there's no location format that shows only region and coords without having to have the parcel name empty, so I copied buildLocationString implementation in the case of LOCATION_FORMAT_NO_MATURITY but when the parcel name is empty. I had to make updateDiscordActivity check agent's ID and the existence of agent avatar pointer first before trying to set Activity Details or State, cause I like the "Show location" button be checkable not only after online when both the ID & pointer will have existed. I think this way is simpler than programmatically enabling the "Show location" button after the user is logged in. I put a trigger to Activity update somewhere after the user is logged in for now, not yet after a TP. The elapsed time gets reset whenever Activity is updated for now, but I'll try to make elapsed time extended instead. No Party for now, because I couldn't find a way to make a Party shown without showing its CurrentSize (I could still get away not showing its MaxSize by setting it to 0), so the State (location) is shown above the elapsed time, not on the right of it. I'll try to figure out to get some representative numbers for its CurrentSize & MaxSize next. Also no privacy on hiding the username for now, until the UI is ready.
-rw-r--r--indra/newview/app_settings/settings.xml11
-rw-r--r--indra/newview/llappviewer.cpp32
-rw-r--r--indra/newview/llappviewer.h1
-rw-r--r--indra/newview/llfloaterpreference.cpp8
-rw-r--r--indra/newview/llstartup.cpp3
-rw-r--r--indra/newview/skins/default/xui/en/panel_preferences_privacy.xml1
6 files changed, 56 insertions, 0 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index a2e0a8dbbe..bb7211514d 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -1172,6 +1172,17 @@
<key>Value</key>
<integer>0</integer>
</map>
+ <key>ShowDiscordActivityState</key>
+ <map>
+ <key>Comment</key>
+ <string>When set, show location on Discord Rich Presence</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
<key>EnableDiskCacheDebugInfo</key>
<map>
<key>Comment</key>
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 030c778990..3d8dfd39e6 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -5980,4 +5980,36 @@ void LLAppViewer::handleDiscordSocial(bool enable)
}
}
+void LLAppViewer::updateDiscordActivity()
+{
+ discordpp::Activity activity;
+ activity.SetType(discordpp::ActivityTypes::Playing);
+ if (gAgentAvatarp)
+ activity.SetDetails(gAgentAvatarp->getFullname());
+ if (gAgent.getID() != LLUUID::null && gSavedSettings.getBOOL("ShowDiscordActivityState"))
+ {
+ auto agent_pos_region = gAgent.getPositionAgent();
+ S32 pos_x = S32(agent_pos_region.mV[VX] + 0.5f);
+ S32 pos_y = S32(agent_pos_region.mV[VY] + 0.5f);
+ S32 pos_z = S32(agent_pos_region.mV[VZ] + 0.5f);
+ F32 velocity_mag_sq = gAgent.getVelocity().magVecSquared();
+ const F32 FLY_CUTOFF = 6.f;
+ const F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF;
+ const F32 WALK_CUTOFF = 1.5f;
+ const F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF;
+ if (velocity_mag_sq > FLY_CUTOFF_SQ)
+ {
+ pos_x -= pos_x % 4;
+ pos_y -= pos_y % 4;
+ }
+ else if (velocity_mag_sq > WALK_CUTOFF_SQ)
+ {
+ pos_x -= pos_x % 2;
+ pos_y -= pos_y % 2;
+ }
+ activity.SetState(llformat("%s (%d, %d, %d)", gAgent.getRegion()->getName().c_str(), pos_x, pos_y, pos_z));
+ }
+ gDiscordClient->UpdateRichPresence(activity, [](discordpp::ClientResult) {});
+}
+
#endif
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index 8ff07accbe..79db515970 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -253,6 +253,7 @@ public:
#ifdef LL_DISCORD
static void initDiscordSocial();
static void handleDiscordSocial(bool enable);
+ static void updateDiscordActivity();
#endif
protected:
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 136683296f..c6e839c5de 100644
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -238,10 +238,17 @@ void handleAppearanceCameraMovementChanged(const LLSD& newvalue)
}
#ifdef LL_DISCORD
+
void handleDiscordSocial(const LLSD& newvalue)
{
LLAppViewer::handleDiscordSocial(newvalue.asBoolean());
}
+
+void handleDiscordActivityState(const LLSD& newvalue)
+{
+ LLAppViewer::updateDiscordActivity();
+}
+
#endif
void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator)
@@ -375,6 +382,7 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
mCommitCallbackRegistrar.add("UpdateFilter", boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false)); // <FS:ND/> Hook up for filtering
#ifdef LL_DISCORD
gSavedSettings.getControl("EnableDiscord")->getCommitSignal()->connect(boost::bind(&handleDiscordSocial, _2));
+ gSavedSettings.getControl("ShowDiscordActivityState")->getCommitSignal()->connect(boost::bind(&handleDiscordActivityState, _2));
#endif
}
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index 8d010553a0..2f40beb9c4 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -2082,6 +2082,9 @@ bool idle_startup()
// We have a region, and just did a big inventory download.
// We can estimate the user's connection speed, and set their
// max bandwidth accordingly. JC
+#ifdef LL_DISCORD
+ LLAppViewer::updateDiscordActivity();
+#endif
if (gSavedSettings.getBOOL("FirstLoginThisInstall"))
{
// This is actually a pessimistic computation, because TCP may not have enough
diff --git a/indra/newview/skins/default/xui/en/panel_preferences_privacy.xml b/indra/newview/skins/default/xui/en/panel_preferences_privacy.xml
index 8d78618a21..86bc23d699 100644
--- a/indra/newview/skins/default/xui/en/panel_preferences_privacy.xml
+++ b/indra/newview/skins/default/xui/en/panel_preferences_privacy.xml
@@ -150,6 +150,7 @@
<check_box
enabled_control="EnableDiscord"
+ control_name="ShowDiscordActivityState"
height="16"
enabled="false"
label="Show location"