hbfloaterradar.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /**
  2. * @file hbfloaterradar.h
  3. * @brief Radar floater class definition
  4. *
  5. * @authors Original code from Dale Glass, amended by jcool410 for Emerald,
  6. * fully rewritten and heavily modified by Henri Beauchamp (the laggy spying
  7. * tool becomes a true, low lag radar), with avatar marking and announcements
  8. * additions, among others.
  9. *
  10. * $LicenseInfo:firstyear=2007&license=viewergpl$
  11. *
  12. * Copyright (c) 2008-2024, Henri Beauchamp.
  13. *
  14. * Second Life Viewer Source Code
  15. * The source code in this file ("Source Code") is provided by Linden Lab
  16. * to you under the terms of the GNU General Public License, version 2.0
  17. * ("GPL"), unless you have obtained a separate licensing agreement
  18. * ("Other License"), formally executed by you and Linden Lab. Terms of
  19. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  20. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  21. *
  22. * There are special exceptions to the terms and conditions of the GPL as
  23. * it is applied to this Source Code. View the full text of the exception
  24. * in the file doc/FLOSS-exception.txt in this software distribution, or
  25. * online at
  26. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  27. *
  28. * By copying, modifying or distributing this software, you acknowledge
  29. * that you have read and understood your obligations described above,
  30. * and agree to abide by those obligations.
  31. *
  32. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  33. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  34. * COMPLETENESS OR PERFORMANCE.
  35. * $/LicenseInfo$
  36. */
  37. #ifndef LL_HBFLOATERRADAR_H
  38. #define LL_HBFLOATERRADAR_H
  39. #include "llfloater.h"
  40. #include "llframetimer.h"
  41. #include "lltimer.h"
  42. #include "llavatartracker.h"
  43. #include "llmutelist.h"
  44. class LLButton;
  45. class LLCheckBoxCtrl;
  46. class HBFloaterRadar;
  47. class LLScrollListCtrl;
  48. class LLTabContainer;
  49. class LLVOAvatar;
  50. // This class is used to cache data about avatars. Instances are kept in an
  51. // unordered map. We keep track of the frame where the avatar was last seen.
  52. class HBRadarListEntry
  53. {
  54. friend class HBFloaterRadar;
  55. public:
  56. HBRadarListEntry(LLVOAvatar* avatarp, const LLUUID& avid,
  57. const std::string& name, const std::string& listed_name,
  58. const LLVector3d& position, bool marked);
  59. // We delete the copy constructor for performances (as a result all entries
  60. // will have to be constructed emplace in the avatar list).
  61. HBRadarListEntry(const HBRadarListEntry&) = delete;
  62. ~HBRadarListEntry();
  63. // Update world position. Affects age.
  64. void setPosition(const LLVector3d& position, bool this_sim, bool drawn,
  65. bool chatrange, bool shoutrange);
  66. LL_INLINE const LLVector3d& getPosition() const { return mPosition; }
  67. // This is only used for determining whether the avatar is still around:
  68. // see getEntryAgeSeconds()
  69. bool getAlive();
  70. // Returns the age of this entry in seconds
  71. LL_INLINE F32 getEntryAgeSeconds() const
  72. {
  73. return mUpdateTimer.getElapsedTimeF32();
  74. }
  75. // Returns the ID of the avatar
  76. LL_INLINE const LLUUID& getID() const { return mID; }
  77. // Returns the legacy name of the avatar
  78. LL_INLINE const std::string& getLegacyName() const
  79. {
  80. return mLegacyName;
  81. }
  82. // Sets the name of the avatar as listed in the radar floater
  83. LL_INLINE void setListedName(const std::string& name)
  84. {
  85. mListedName = name;
  86. }
  87. // Returns the name of the avatar as listed in the radar floater
  88. LL_INLINE const std::string& getListedName() const
  89. {
  90. return mListedName;
  91. }
  92. LL_INLINE bool isMuted() const { return mMuted; }
  93. LL_INLINE bool isDerendered() const { return mDerendered; }
  94. LL_INLINE bool isFriend() const { return mFriend; }
  95. // Sets the 'focus' status on this entry (camera focused on this avatar)
  96. LL_INLINE void setFocus(bool value) { mFocused = value; }
  97. LL_INLINE bool isFocused() const { return mFocused; }
  98. LL_INLINE bool isMarked() const { return mMarked; }
  99. LL_INLINE bool isCustomMark() const { return mCustomMark; }
  100. LL_INLINE bool isDrawn() const { return mInDrawFrame != U32_MAX; }
  101. LL_INLINE bool isInSim() const { return mInSimFrame != U32_MAX; }
  102. // Returns true when the item is dead and should not appear in the list
  103. LL_INLINE bool isDead() const
  104. {
  105. // How long to keep people who are gone in the list and in memory.
  106. constexpr F32 DEAD_KEEP_TIME = 10.f;
  107. return getEntryAgeSeconds() > DEAD_KEEP_TIME;
  108. }
  109. LL_INLINE void setColor(const LLColor4& col) { mColor = col; }
  110. LL_INLINE const LLColor4& getColor() const { return mColor; }
  111. LL_INLINE void setMarkColor(const LLColor4& c) { mMarkColor = c; }
  112. LL_INLINE const LLColor4& getMarkColor() const { return mMarkColor; }
  113. LL_INLINE void setToolTip(const std::string& text)
  114. {
  115. mToolTip = text;
  116. }
  117. LL_INLINE const std::string& getToolTip() const
  118. {
  119. return mToolTip;
  120. }
  121. // Returns true if successful (mark is valid and set/displayed) or false
  122. // otherwise (with the mark reset to "X"). Note that reset the custom mark
  123. // (and stop displaying it in the radar if the avatar was not marked by the
  124. // user), you simply need to pass an empty string to this method.
  125. bool setMarkChar(const std::string& chr);
  126. LL_INLINE const std::string& getMarkChar() const
  127. {
  128. return mMarkChar;
  129. }
  130. LL_INLINE bool toggleMark() { mMarked = !mMarked; return mMarked; }
  131. LL_INLINE void setMarked() { mMarked = true; }
  132. private:
  133. typedef enum e_radar_alert_type
  134. {
  135. ALERT_TYPE_SIM = 0,
  136. ALERT_TYPE_DRAW = 1,
  137. ALERT_TYPE_SHOUTRANGE = 2,
  138. ALERT_TYPE_CHATRANGE = 3
  139. } ERadarAlertType;
  140. // Emits announcements about the avatar entering or leaving the various
  141. // ranges, in chat and/or private channel. Returns true when something was
  142. // actually posted in chat.
  143. bool reportAvatarStatus(ERadarAlertType type, bool entering);
  144. private:
  145. LLUUID mID;
  146. std::string mLegacyName;
  147. std::string mListedName;
  148. std::string mToolTip;
  149. std::string mMarkChar;
  150. LLColor4 mColor;
  151. LLColor4 mMarkColor;
  152. LLVector3d mPosition;
  153. LLVector3d mDrawPosition;
  154. // Timer to keep track of whether avatars are still there
  155. LLTimer mUpdateTimer;
  156. // Last frame when this avatar was updated
  157. U32 mFrame;
  158. // Last frame when this avatar was in sim
  159. U32 mInSimFrame;
  160. // Last frame when this avatar was in draw
  161. U32 mInDrawFrame;
  162. // Last frame when this avatar was in shout range
  163. U32 mInShoutFrame;
  164. // Last frame when this avatar was in chat range
  165. U32 mInChatFrame;
  166. bool mMuted;
  167. bool mDerendered;
  168. bool mFriend;
  169. bool mMarked;
  170. bool mCustomMark;
  171. bool mFocused;
  172. };
  173. class HBFloaterRadar final : public LLMuteListObserver,
  174. public LLFriendObserver,
  175. public LLFloater,
  176. public LLFloaterSingleton<HBFloaterRadar>
  177. {
  178. friend class LLUISingleton<HBFloaterRadar, VisibilityPolicy<LLFloater> >;
  179. friend class HBRadarListEntry; // For access to static cached strings
  180. protected:
  181. LOG_CLASS(HBFloaterRadar);
  182. void onClose(bool app_quitting) override;
  183. void onOpen() override;
  184. bool postBuild() override;
  185. // Mute list observer inteface
  186. void onChange() override;
  187. // Friends list observer inteface
  188. void changed(U32 mask) override;
  189. public:
  190. ~HBFloaterRadar() override;
  191. // Returns the entry for an avatar, if preset, NULL if not found.
  192. HBRadarListEntry* getAvatarEntry(const LLUUID& avid);
  193. // Returns a string with the selected names in the list
  194. std::string getSelectedNames(const std::string& separator = ", ");
  195. std::string getSelectedName();
  196. LLUUID getSelectedID();
  197. LL_INLINE bool isAvatarMarked(const LLUUID& avid)
  198. {
  199. return mMarkedAvatars.count(avid) > 0;
  200. }
  201. bool startTracker(const LLUUID& avid); // Returns true on success
  202. void stopTracker();
  203. typedef safe_hmap<LLUUID, HBRadarListEntry> avatar_list_t;
  204. // Used by hbviewerautomation.cpp
  205. LL_INLINE const avatar_list_t& getAvatarList() const
  206. {
  207. return mAvatars;
  208. }
  209. // Sets the color for the avatar name in the list; returns true when
  210. // successful (i.e. if the avatar is found in the currently active radar
  211. // list, or there is no open/running radar floater).
  212. static bool setAvatarNameColor(const LLUUID& avid, const LLColor4& color);
  213. // Updates the render status for a given avatar, or for all avatars if
  214. // avid is omitted or null. To use each time you modify the derendered
  215. // objects list (gObjectList.mBlackListedObjects) by adding or removing an
  216. // avatar. Using such a method prevents from having to check each listed
  217. // avatar render status at each avatar list update.
  218. static void setRenderStatusDirty(const LLUUID& avid = LLUUID::null);
  219. private:
  220. // Open only via LLFloaterSingleton interface, i.e. showInstance() or
  221. // toggleInstance().
  222. HBFloaterRadar(const LLSD&);
  223. // Updates the avatars list with the surounding avatars.
  224. void updateAvatarList();
  225. // Cleans up the avatars list, removing dead entries from it. This lets
  226. // dead entries remain for some time so that it is possible to trigger
  227. // actions on avtars passing by in the list.
  228. void expireAvatarList();
  229. enum AVATARS_COLUMN_ORDER
  230. {
  231. LIST_MARK,
  232. LIST_AVATAR_NAME,
  233. LIST_DISTANCE,
  234. LIST_POSITION,
  235. LIST_ALTITUDE
  236. };
  237. // Refreshes the avatars list
  238. void refreshAvatarList();
  239. // Loading and saving of the marked avatars list
  240. bool loadMarkedFromFile();
  241. bool saveMarkedToFile(bool force = false);
  242. // Removes focus status from all avatars in list
  243. void removeFocusFromAll();
  244. // Focuses the camera on current avatar
  245. void focusOnCurrent();
  246. // Focuses the camera on the previous avatar (marked ones only when
  247. // marked_only is true)
  248. void focusOnPrev(bool marked_only);
  249. // Focuses the camera on the next avatar (marked ones only when marked_only
  250. // is true)
  251. void focusOnNext(bool marked_only);
  252. void refreshTracker();
  253. static void connectRefreshCachedSettingsSafe(const char* name);
  254. static void refreshCachedSettings();
  255. static void onTabChanged(void* userdata, bool from_click);
  256. static void onClickProfile(void* userdata);
  257. static void onClickTrack(void* userdata);
  258. static void onClickIM(void* userdata);
  259. static void onClickTeleportOffer(void* userdata);
  260. static void onClickTeleportTo(void* userdata);
  261. static void onClickTeleportRequest(void* userdata);
  262. static void onDoubleClick(void* userdata);
  263. static void onClickFocus(void* userdata);
  264. static void onClickPrevInList(void* userdata);
  265. static void onClickNextInList(void* userdata);
  266. static void onClickMark(void* userdata);
  267. static void onClickPrevMarked(void* userdata);
  268. static void onClickNextMarked(void* userdata);
  269. static void onCheckRadarAlerts(LLUICtrl* ctrl, void* userdata);
  270. static void onCheckUseLegacyNames(LLUICtrl* ctrl, void* userdata);
  271. static void onSearchEdit(const std::string& search_string, void* userdata);
  272. static void onClickFreeze(void* userdata);
  273. static void onClickEject(void* userdata);
  274. static void onClickMute(void* userdata);
  275. static void onClickDerender(void* userdata);
  276. static void onClickAR(void* userdata);
  277. static void onClickEjectFromEstate(void* userdata);
  278. static void onClickGetKey(void* userdata);
  279. static void onClickClearSavedMarked(void* userdata);
  280. static void callbackFreeze(const LLSD& notification, const LLSD& response);
  281. static void callbackEject(const LLSD& notification, const LLSD& response);
  282. static void callbackAR(void* userdata);
  283. static void callbackEjectFromEstate(const LLSD& notification,
  284. const LLSD& response);
  285. static void onSelectName(LLUICtrl* ctrlp, void* userdata);
  286. static void onClickSendKeys(void* userdata);
  287. static void callbackIdle(void* userdata);
  288. typedef void (*avlist_command_t)(const LLUUID& avid);
  289. void doCommand(avlist_command_t cmd);
  290. private:
  291. uuid_vec_t mLastSelection;
  292. LLTabContainer* mTabContainer;
  293. LLScrollListCtrl* mAvatarList;
  294. LLButton* mProfileButton;
  295. LLButton* mTrackButton;
  296. LLButton* mIMButton;
  297. LLButton* mTPOfferButton;
  298. LLButton* mRequestTPButton;
  299. LLButton* mTeleportToButton;
  300. LLButton* mMarkButton;
  301. LLButton* mPrevMarkedButton;
  302. LLButton* mNextMarkedButton;
  303. LLButton* mFocusButton;
  304. LLButton* mPrevInListButton;
  305. LLButton* mNextInListButton;
  306. LLButton* mMuteButton;
  307. LLButton* mFreezeButton;
  308. LLButton* mARButton;
  309. LLButton* mEjectButton;
  310. LLButton* mEstateEjectButton;
  311. LLButton* mGetKeyButton;
  312. LLButton* mDerenderButton;
  313. LLButton* mRerenderButton;
  314. LLButton* mClearSavedMarkedButton;
  315. LLCheckBoxCtrl* mRadarAlertsCheck;
  316. LLCheckBoxCtrl* mSimAlertsCheck;
  317. LLCheckBoxCtrl* mDrawAlertsCheck;
  318. LLCheckBoxCtrl* mShoutAlertsCheck;
  319. LLCheckBoxCtrl* mChatAlertsCheck;
  320. LLCheckBoxCtrl* mUseLegacyNamesCheck;
  321. std::string mFilterString;
  322. avatar_list_t mAvatars;
  323. uuid_list_t mMarkedAvatars;
  324. LLUUID mFocusedAvatar; // Avatar the camera is focused on
  325. // Tracking data
  326. LLUUID mTrackedAvatar; // Who we are tracking
  327. bool mTracking; // Tracking ?
  328. static LLFrameTimer sUpdateTimer; // Update timer
  329. // Cached UI strings
  330. static std::string sTotalAvatarsStr;
  331. static std::string sNoAvatarStr;
  332. static std::string sLastKnownPosStr;
  333. protected:
  334. // Cached UI strings, colors and settings
  335. static std::string sCardinals;
  336. static std::string sHasEnteredStr;
  337. static std::string sHasLeftStr;
  338. static std::string sTheSimStr;
  339. static std::string sDrawDistanceStr;
  340. static std::string sShoutRangeStr;
  341. static std::string sChatRangeStr;
  342. static LLColor4 sMarkColor;
  343. static LLColor4 sNameColor;
  344. static LLColor4 sFriendNameColor;
  345. static LLColor4 sMutedNameColor;
  346. static LLColor4 sDerenderedNameColor;
  347. static LLColor4 sFarDistanceColor;
  348. static LLColor4 sShoutDistanceColor;
  349. static LLColor4 sChatDistanceColor;
  350. // Update rate (updates per second)
  351. static U32 sUpdatesPerSecond;
  352. static bool sRememberMarked;
  353. };
  354. #endif // LL_HBFLOATERRADAR_H