hbviewerautomation.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /**
  2. * @file hbviewerautomation.h
  3. * @brief HBViewerAutomation class definition
  4. *
  5. * $LicenseInfo:firstyear=2016&license=viewergpl$
  6. *
  7. * Copyright (c) 2016-2024, Henri Beauchamp.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_HBVIEWERAUTOMATION_H
  33. #define LL_HBVIEWERAUTOMATION_H
  34. #include <deque>
  35. #include <set>
  36. #include "boost/signals2.hpp"
  37. #include "llmenugl.h"
  38. #include "llmutex.h"
  39. #include "llfloater.h"
  40. #include "lltimer.h"
  41. #include "llvector3d.h"
  42. class HBAutomationThread;
  43. class LLButton;
  44. class LLColor4;
  45. class LLControlVariable;
  46. class LLFriendObserver;
  47. class LLMessageSystem;
  48. class LLPickInfo;
  49. class LLSimInfo;
  50. class LLTextEditor;
  51. class LLViewerObject;
  52. struct lua_Debug;
  53. struct lua_State;
  54. class HBViewerAutomation
  55. {
  56. friend class HBLuaConsole;
  57. friend class HBLuaDialog;
  58. friend class HBLuaFloater;
  59. friend class HBLuaPieMenu;
  60. friend class HBIgnoreCallback;
  61. protected:
  62. LOG_CLASS(HBViewerAutomation);
  63. public:
  64. // Methods used for the resident gAutomationp interpreter in which the
  65. // automation script gets loaded
  66. static void start(std::string file_name = LLStringUtil::null);
  67. static void cleanup();
  68. // Method used to spawn transient interpreters for commands sent via the
  69. // chat input line, the llOwnersay() and llInstantMessage() LSL functions,
  70. // and the D-Bus commands. When use_print_buffer is true (used for D-Bus
  71. // commands), all print() and reportError() outputs are redirected to the
  72. // mPrintBuffer string and the contents of that string is returned by this
  73. // function (and otherwise an empty string).
  74. // When the command comes from an object script, that object's 'id' and
  75. // 'name' are passed (by checkLuaCommand()).
  76. // Note that viewer events are not transmitted to this type of interpreter.
  77. static std::string eval(const std::string& chunk,
  78. bool use_print_buffer = false,
  79. const LLUUID& id = LLUUID::null,
  80. const std::string& name = LLStringUtil::null);
  81. // Method used to interpret possible Lua commands in script messages.
  82. // Returns true if the message was indeed a Lua command.
  83. static bool checkLuaCommand(const std::string& message,
  84. const LLUUID& from_object_id,
  85. const std::string& from_object_name);
  86. // Method used to execute a Lua script file
  87. static void execute(const std::string& file_name);
  88. // Events transmitted by the viewer to the Lua automation script
  89. void onLogin();
  90. void onRegionChange();
  91. void onParcelChange();
  92. void onPositionChange(const LLVector3& pos_local,
  93. const LLVector3d& pos_global);
  94. void onAveragedFPS(F32 fps, bool limited, F32 frame_render_time);
  95. void onAgentOccupationChange(S32 type);
  96. void onAgentPush(const LLUUID& id, S32 type, F32 mag);
  97. bool onSendChat(std::string& text);
  98. void onReceivedChat(U8 chat_type, const LLUUID& from_id,
  99. const std::string& name, const std::string& text);
  100. bool onChatTextColoring(const LLUUID& from_id, const std::string& name,
  101. const std::string& text, LLColor4& color);
  102. void onInstantMsg(const LLUUID& session_id, const LLUUID& origin_id,
  103. const std::string& name, const std::string& text);
  104. void onAlertDialog(const std::string& dialog_name, const LLUUID& alert_id,
  105. const std::string& message,
  106. const std::vector<std::string>& buttons);
  107. void onScriptDialog(const LLUUID& notif_id, const std::string& message,
  108. const std::vector<std::string>& buttons);
  109. void onNotification(const std::string& dialog_name, const LLUUID& notif_id,
  110. const std::string& message);
  111. bool onSLURLDispatch(const std::string& slurl, const std::string& nav_type,
  112. bool trusted);
  113. U32 onURLDispatch(const std::string& url, const std::string& target,
  114. bool external_browser);
  115. void onFriendStatusChange(const LLUUID& id, U32 mask, bool is_online);
  116. void onAvatarRezzing(const LLUUID& id);
  117. void onAgentBaked();
  118. void onRadar(const LLUUID& id, const std::string& name, S32 range,
  119. bool marked);
  120. void onRadarSelection(const uuid_vec_t& ids);
  121. void onRadarMark(const LLUUID& id, const std::string& name, bool marked);
  122. void onRadarTrack(const LLUUID& id, const std::string& name, bool tracked);
  123. void onSideBarVisibilityChange(bool visible);
  124. void onAutoPilotFinished(const std::string& type, bool reached,
  125. bool user_cancel);
  126. void onTPStateChange(S32 state, const std::string& reason);
  127. void onFailedTPSimChange(S32 agents_count);
  128. void onWindlightChange(const std::string& sky_settings_name,
  129. const std::string& water_settings_name,
  130. const std::string& day_settings_name);
  131. void onCameraModeChange(S32 mode);
  132. void onJoystickButtons(S32 old_state, S32 new_state);
  133. void onRLVHandleCommand(const LLUUID& object_id, const std::string& behav,
  134. const std::string& option,
  135. const std::string& param);
  136. void onRLVAnswerOnChat(const LLUUID& object_id, S32 channel,
  137. const std::string& text);
  138. // Called by llviermessage.cpp when receiving object properties messages
  139. static void processObjectPropertiesFamily(LLMessageSystem* msg);
  140. // Called from llagent.cpp to keep track of the agent positions history
  141. static void addToAgentPosHistory(const LLVector3d& global_pos);
  142. protected:
  143. HBViewerAutomation(bool use_print_buffer = false);
  144. virtual ~HBViewerAutomation();
  145. LL_INLINE virtual bool isThreaded() const { return false; }
  146. LL_INLINE virtual U32 getLuaThreadID() const { return 0; }
  147. static HBViewerAutomation* findInstance(lua_State* state);
  148. void resetCallbackFlags();
  149. bool load(const std::string& file_name);
  150. bool loadString(const std::string& chunk);
  151. void reportError();
  152. // Callback method for the Lua warn() function
  153. static void reportWarning(void* data, const char* msg, int to_continue);
  154. bool registerCFunctions(); // Returns true on success
  155. S32 getGlobal(const std::string& global);
  156. void resetTimer();
  157. void pushGridSimAndPos();
  158. void pushParcelInfo();
  159. // Method used to pre-process Lua source files
  160. std::string preprocess(const std::string& file_name);
  161. // Callback for use with HBPreprocessor to load #include Lua files
  162. static S32 loadInclude(std::string& include_name, const std::string& path,
  163. std::string& buffer, void*);
  164. // Callback for use with HBPreprocessor to report warning and error
  165. // messages
  166. static void preprocessorMessageCB(const std::string& message,
  167. bool is_warning, void*);
  168. static bool callAutomationFunc(HBAutomationThread* threadp);
  169. // Idle callbacks.
  170. static void onIdleThread(void* userdata);
  171. static void onIdleSimChange(void* userdata);
  172. // Helper method to request object details. 'reason' must be 0 for muting,
  173. // 1 for un-muting, anything else for Lua GetObjectInfo().
  174. static bool requestObjectPropertiesFamily(const LLUUID& object_id,
  175. U32 reason);
  176. // Helper method to find an item or category UUID from its full path name
  177. // in the inventory. The path separator is the pipe symbol ('|') and was
  178. // choosen because it is not a valid/accepted character for inventory
  179. // objects names).
  180. static const LLUUID& getInventoryObjectId(const std::string& name,
  181. bool& is_category);
  182. // Watchdog timeout hook
  183. static void watchdog(lua_State* state, lua_Debug*);
  184. // Overridden print() Lua function
  185. static int print(lua_State* state);
  186. // New viewer-related Lua functions:
  187. static int hasThread(lua_State* state);
  188. static int startThread(lua_State* state);
  189. static int stopThread(lua_State* state);
  190. static int sendSignal(lua_State* state);
  191. static int getSourceFileName(lua_State* state);
  192. static int getWatchdogState(lua_State* state);
  193. static int isUUID(lua_State* state);
  194. static int isAvatar(lua_State* state);
  195. static int isObject(lua_State* state);
  196. static int isAgentFriend(lua_State* state);
  197. static int isAgentGroup(lua_State* state);
  198. static int getAvatarName(lua_State* state);
  199. static int getGroupName(lua_State* state);
  200. static int getAgentFriends(lua_State* state);
  201. static int getAgentGroups(lua_State* state);
  202. static int isAdmin(lua_State* state);
  203. static int getRadarList(lua_State* state);
  204. static int getRadarData(lua_State* state);
  205. static int setRadarTracking(lua_State* state);
  206. static int setRadarToolTip(lua_State* state);
  207. static int setRadarMarkChar(lua_State* state);
  208. static int setRadarMarkColor(lua_State* state);
  209. static int setRadarNameColor(lua_State* state);
  210. static int setAvatarMinimapColor(lua_State* state);
  211. static int setAvatarNameTagColor(lua_State* state);
  212. static int getAgentPosHistory(lua_State* state);
  213. static int getAgentInfo(lua_State* state);
  214. static int setAgentOccupation(lua_State* state);
  215. static int getAgentGroupData(lua_State* state);
  216. static int setAgentGroup(lua_State* state);
  217. static int agentGroupInvite(lua_State* state);
  218. static int agentSit(lua_State* state);
  219. static int agentStand(lua_State* state);
  220. static int setAgentTyping(lua_State* state);
  221. static int sendChat(lua_State* state);
  222. static int getIMSession(lua_State* state);
  223. static int closeIMSession(lua_State* state);
  224. static int sendIM(lua_State* state);
  225. static int alertDialogResponse(lua_State* state);
  226. static int scriptDialogResponse(lua_State* state);
  227. static int cancelNotification(lua_State* state);
  228. static int getObjectInfo(lua_State* state);
  229. static int browseToURL(lua_State* state);
  230. static int dispatchSLURL(lua_State* state);
  231. static int executeRLV(lua_State* state);
  232. static int openNotification(lua_State* state);
  233. static int openFloater(lua_State* state);
  234. static int closeFloater(lua_State* state);
  235. static int getFloaterInstances(lua_State* state);
  236. static int getFloaterControls(lua_State* state);
  237. static int getFloaterCtrlState(lua_State* state);
  238. static int getFloaterList(lua_State* state);
  239. static int showFloater(lua_State* state);
  240. static int makeDialog(lua_State* state);
  241. static int openLuaFloater(lua_State* state);
  242. static int showLuaFloater(lua_State* state);
  243. static int setLuaFloaterCommand(lua_State* state);
  244. static int getLuaFloaterValue(lua_State* state);
  245. static int getLuaFloaterValues(lua_State* state);
  246. static int setLuaFloaterValue(lua_State* state);
  247. static int setLuaFloaterInvFilter(lua_State* state);
  248. static int setLuaFloaterEnabled(lua_State* state);
  249. static int setLuaFloaterVisible(lua_State* state);
  250. static int closeLuaFloater(lua_State* state);
  251. static int overlayBarLuaButton(lua_State* state);
  252. static int statusBarLuaIcon(lua_State* state);
  253. static int sideBarButton(lua_State* state);
  254. static int sideBarButtonToggle(lua_State* state);
  255. static int sideBarHide(lua_State* state);
  256. static int sideBarHideOnRightClick(lua_State* state);
  257. static int sideBarButtonHide(lua_State* state);
  258. static int sideBarButtonDisable(lua_State* state);
  259. static int luaPieMenuSlice(lua_State* state);
  260. static int luaContextMenu(lua_State* state);
  261. static int pasteToContextHandler(lua_State* state);
  262. static int automationMessage(lua_State* state);
  263. static int automationRequest(lua_State* state);
  264. static int playUISound(lua_State* state);
  265. static int renderDebugInfo(lua_State* state);
  266. static int getDebugSetting(lua_State* state);
  267. static int setDebugSetting(lua_State* state);
  268. static int getFrameTimeSeconds(lua_State* state);
  269. static int getTimeStamp(lua_State* state);
  270. static int getClipBoardString(lua_State* state);
  271. static int setClipBoardString(lua_State* state);
  272. static int findInventoryObject(lua_State* state);
  273. static int giveInventory(lua_State* state);
  274. static int makeInventoryLink(lua_State* state);
  275. static int deleteInventoryLink(lua_State* state);
  276. static int newInventoryFolder(lua_State* state);
  277. static int listInventoryFolder(lua_State* state);
  278. static int moveToInventoryFolder(lua_State* state);
  279. static int pickInventoryItem(lua_State* state);
  280. static int pickAvatar(lua_State* state);
  281. static int getAgentAttachments(lua_State* state);
  282. static int getAgentWearables(lua_State* state);
  283. static int agentAutoPilotToPos(lua_State* state);
  284. static int agentAutoPilotFollow(lua_State* state);
  285. static int agentAutoPilotStop(lua_State* state);
  286. static int agentAutoPilotLoad(lua_State* state);
  287. static int agentAutoPilotSave(lua_State* state);
  288. static int agentAutoPilotRemove(lua_State* state);
  289. static int agentAutoPilotRecord(lua_State* state);
  290. static int agentAutoPilotReplay(lua_State* state);
  291. #if LL_PUPPETRY
  292. static int agentPuppetryStart(lua_State* state);
  293. static int agentPuppetryStop(lua_State* state);
  294. #endif
  295. static int agentRotate(lua_State* state);
  296. static int getAgentRotation(lua_State* state);
  297. static int teleportAgentHome(lua_State* state);
  298. static int teleportAgentToPos(lua_State* state);
  299. static int getGridSimAndPos(lua_State* state);
  300. static int getParcelInfo(lua_State* state);
  301. static int getCameraMode(lua_State* state);
  302. static int setCameraMode(lua_State* state);
  303. static int setCameraFocus(lua_State* state);
  304. static int setVisualMute(lua_State* state);
  305. static int addMute(lua_State* state);
  306. static int removeMute(lua_State* state);
  307. static int isMuted(lua_State* state);
  308. static int blockSound(lua_State* state);
  309. static int isBlockedSound(lua_State* state);
  310. static int getBlockedSounds(lua_State* state);
  311. static int derenderObject(lua_State* state);
  312. static int getDerenderedObjects(lua_State* state);
  313. static int getAgentPushes(lua_State* state);
  314. static int applyDaySettings(lua_State* state);
  315. static int applySkySettings(lua_State* state);
  316. static int applyWaterSettings(lua_State* state);
  317. static int setDayTime(lua_State* state);
  318. static int getEESettingsList(lua_State* state);
  319. static int getWLSettingsList(lua_State* state);
  320. static int getEnvironmentStatus(lua_State* state);
  321. static int getGlobalData(lua_State* state);
  322. static int setGlobalData(lua_State* state);
  323. static int getPerAccountData(lua_State* state);
  324. static int setPerAccountData(lua_State* state);
  325. static int callbackAfter(lua_State* state);
  326. static int forceQuit(lua_State* state);
  327. static int minimizeWindow(lua_State* state);
  328. // This is the callback used by callbackAfter() via doAfterInterval()
  329. static void doAfterIntervalCallback(lua_State* state, int ref);
  330. // This is the callback used by onAgentBaked() via doAfterInterval()
  331. static void doCallOnAgentBaked(lua_State* state);
  332. // This is the callback for the inventory item picker.
  333. static void onPickInventoryItem(const std::vector<std::string>& names,
  334. const uuid_vec_t& ids, void* userdata,
  335. bool on_close);
  336. // This is the callback for the avatar picker.
  337. static void onPickAvatar(const std::vector<std::string>& names,
  338. const uuid_vec_t& ids, void* userdata);
  339. // Helper methods used to de/serialize simple Lua tables from/into strings
  340. static bool serializeTable(lua_State* state, S32 stack_level = 1,
  341. std::string* output = NULL);
  342. static bool deserializeTable(lua_State* state, std::string data);
  343. void onObjectInfoReply(const LLUUID& object_id, const std::string& name,
  344. const std::string& desc, const LLUUID& owner_id,
  345. const LLUUID& group_id);
  346. // Events transmitted to the Lua automation script by Lua UI elements
  347. void onLuaDialogClose(const std::string& title, S32 button,
  348. const std::string& text);
  349. void onLuaFloaterAction(const std::string& floater_name,
  350. const std::string& ctrl_name,
  351. const std::string& value);
  352. void onLuaFloaterOpen(const std::string& floater_name,
  353. const std::string& parameter);
  354. void onLuaFloaterClose(const std::string& floater_name,
  355. const std::string& parameter);
  356. void onLuaPieMenu(U32 slice, S32 type, const LLPickInfo& pick);
  357. bool onContextMenu(U32 handler_id, S32 operation, const std::string& type);
  358. // This is the method passed as a callback to LLEditMenuHandler for custom
  359. // context menu entries.
  360. static void contextMenuCallback(HBContextMenuData* datap);
  361. protected:
  362. lua_State* mLuaState;
  363. // mFromObjectId is gAgentID unless the Lua interpreter is one set up for
  364. // a scripted object command, or (under Linux) for a D-Bus Lua command (in
  365. // which case mFromObjectId is set to sLuaDBusFakeObjectId).
  366. LLUUID mFromObjectId;
  367. std::string mFromObjectName;
  368. std::string mSourceFileName;
  369. LLTimer mWatchdogTimer;
  370. F32 mWatchdogTimeout;
  371. boost::signals2::connection mRegionChangedConnection;
  372. boost::signals2::connection mParcelChangedConnection;
  373. boost::signals2::connection mPositionChangedConnection;
  374. // These are used only in the automation script, by GetObjectInfo()
  375. uuid_list_t mObjectInfoRequests;
  376. // Internal print buffer for D-Bus or threaded Lua instances
  377. std::string mPrintBuffer;
  378. // Used to deal Lua warnings
  379. std::string mWarningPrefix;
  380. std::string mPendingWarningText;
  381. bool mPausedWarnings;
  382. bool mForceWarningsToChat;
  383. // 'true' when using the print buffer (D-Bus or threaded Lua instances)
  384. bool mUsePrintBuffer;
  385. // 'true' when using the Lua console output text for printing.
  386. bool mUseConsoleOutput;
  387. // Flags used to speed-up callbacks when they are not used in the
  388. // automation script, which is the only instance using them...
  389. bool mHasCallbacks;
  390. bool mHasOnSignal;
  391. bool mHasOnLogin;
  392. bool mHasOnRegionChange;
  393. bool mHasOnParcelChange;
  394. bool mHasOnPositionChange;
  395. bool mHasOnAveragedFPS;
  396. bool mHasOnAgentOccupationChange;
  397. bool mHasOnAgentPush;
  398. bool mHasOnSendChat;
  399. bool mHasOnReceivedChat;
  400. bool mHasOnChatTextColoring;
  401. bool mHasOnInstantMsg;
  402. bool mHasOnAlertDialog;
  403. bool mHasOnScriptDialog;
  404. bool mHasOnNotification;
  405. bool mHasOnSLURLDispatch;
  406. bool mHasOnURLDispatch;
  407. bool mHasOnFriendStatusChange;
  408. bool mHasOnAvatarRezzing;
  409. bool mHasOnAgentBaked;
  410. bool mHasOnRadar;
  411. bool mHasOnRadarSelection;
  412. bool mHasOnRadarMark;
  413. bool mHasOnRadarTrack;
  414. bool mHasOnLuaDialogClose;
  415. bool mHasOnLuaFloaterAction;
  416. bool mHasOnLuaFloaterOpen;
  417. bool mHasOnLuaFloaterClose;
  418. bool mHasOnSideBarVisibilityChange;
  419. bool mHasOnAutomationMessage;
  420. bool mHasOnAutomationRequest;
  421. bool mHasOnAutoPilotFinished;
  422. bool mHasOnTPStateChange;
  423. bool mHasOnFailedTPSimChange;
  424. bool mHasOnWindlightChange;
  425. bool mHasOnCameraModeChange;
  426. bool mHasOnJoystickButtons;
  427. bool mHasOnLuaPieMenu;
  428. bool mHasOnContextMenu;
  429. bool mHasOnRLVHandleCommand;
  430. bool mHasOnRLVAnswerOnChat;
  431. bool mHasOnObjectInfoReply;
  432. bool mHasOnPickInventoryItem;
  433. bool mHasOnPickAvatar;
  434. typedef fast_hmap<lua_State*, HBViewerAutomation*> instances_map_t;
  435. static instances_map_t sInstances;
  436. // We must protect the instance pointers and pending signals with a mutex !
  437. static LLMutex sThreadsMutex;
  438. typedef fast_hmap<U32, HBAutomationThread*> threads_list_t;
  439. static threads_list_t sThreadsInstances;
  440. static threads_list_t sDeadThreadsInstances;
  441. struct HBThreadSignals
  442. {
  443. std::vector<std::string> mSignals;
  444. U32 mThreadID;
  445. };
  446. typedef fast_hmap<HBAutomationThread*, HBThreadSignals*> signals_map_t;
  447. static signals_map_t sThreadsSignals;
  448. // Array of flags/counters used to avoid infinite recursion when dealing
  449. // with some Lua callbacks. They are used only by the automation script and
  450. // must be set (and automatically reset) via the HBIgnoreCallback helper
  451. // class.
  452. enum {
  453. E_ONSENDCHAT,
  454. E_ONINSTANTMSG,
  455. E_ONDISPATCHSLURL,
  456. E_ONDISPATCHURL,
  457. E_ONRADARTRACK,
  458. E_ONAGENTOCCUPATIONCHANGE,
  459. E_ONCAMERAMODECHANGE,
  460. E_ONWINDLIGHTCHANGE,
  461. E_IGN_CB_COUNT
  462. };
  463. static S32 sIgnoredCallbacks[E_IGN_CB_COUNT];
  464. // Used for the automation script, to observe friends status changes
  465. static LLFriendObserver* sFriendsObserver;
  466. // These are used internally; for any script, in order to fulfill the
  467. // objects (un)muting needs.
  468. static uuid_list_t sMuteObjectRequests;
  469. static uuid_list_t sUnmuteObjectRequests;
  470. static std::string sLastAutomationScriptFile;
  471. typedef std::deque<LLVector3d> pos_history_t;
  472. static pos_history_t sPositionsHistory;
  473. #if LL_LINUX
  474. public:
  475. static LLUUID sLuaDBusFakeObjectId;
  476. #endif
  477. };
  478. class HBLuaSideBar final : public LLPanel
  479. {
  480. protected:
  481. LOG_CLASS(HBLuaSideBar);
  482. public:
  483. HBLuaSideBar();
  484. ~HBLuaSideBar() override;
  485. void draw() override;
  486. void setVisible(bool visible) override;
  487. void reshape(S32 width, S32 height, bool from_parent = true) override;
  488. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  489. void setHidden(bool hidden);
  490. U32 setButton(U32 number, std::string icon, std::string command,
  491. const std::string& tooltip);
  492. S32 buttonToggle(U32 number, S32 toggle);
  493. void buttonSetControl(U32 number, LLControlVariable* control);
  494. void setButtonEnabled(U32 number, bool enabled);
  495. void setButtonVisible(U32 number, bool visible);
  496. void removeAllButtons();
  497. LL_INLINE void hideOnRightClick(bool b) { mHideOnRightClick = b; }
  498. private:
  499. void setShape();
  500. static bool handleSideChanged(const LLSD&);
  501. static void onButtonClicked(void* user_data);
  502. private:
  503. std::vector<std::string> mCommands;
  504. std::set<U32> mActiveButtons;
  505. U32 mNumberOfButtons;
  506. bool mLeftSide;
  507. bool mHidden;
  508. bool mHideOnRightClick;
  509. };
  510. class HBLuaPieMenu final : public LLPieMenu
  511. {
  512. protected:
  513. LOG_CLASS(HBLuaPieMenu);
  514. public:
  515. HBLuaPieMenu();
  516. ~HBLuaPieMenu() override;
  517. bool onPieMenu(const LLPickInfo& pick, LLViewerObject* object);
  518. void onPieSliceClick(U32 slice, const LLPickInfo& pick);
  519. void setSlice(S32 type, U32 slice, const std::string& label,
  520. const std::string& command);
  521. void removeAllSlices();
  522. private:
  523. // We have two methods so to avoid re-running here the same (costly) code
  524. // as the one executed in LLToolPie::handleRightClickPick() for finding the
  525. // avatar associated with an attachment...
  526. // This is the simpler method where "object" must never be another avatar's
  527. // attachment. It is called from onPieMenu() (istelf called from
  528. // LLToolPie::handleRightClickPick()) and from the method below.
  529. S32 getPickedType(const LLPickInfo& pick, LLViewerObject* object);
  530. // This is the full method (which calls the above one when needed) and it
  531. // uses a caching scheme.
  532. S32 getPickedType(const LLPickInfo& pick);
  533. private:
  534. std::vector<std::string> mCommands;
  535. std::vector<std::string> mLabels;
  536. LLUUID mLastPickId;
  537. S32 mLastPickType;
  538. };
  539. class HBLuaConsole final : public LLFloater,
  540. public LLFloaterSingleton<HBLuaConsole>
  541. {
  542. friend class LLUISingleton<HBLuaConsole, VisibilityPolicy<LLFloater> >;
  543. friend class HBViewerAutomation;
  544. protected:
  545. LOG_CLASS(HBLuaConsole);
  546. public:
  547. void loadFile(const std::string& filemane);
  548. protected:
  549. // Open only via LLFloaterSingleton interface, i.e. showInstance() or
  550. // toggleInstance().
  551. HBLuaConsole(const LLSD&);
  552. ~HBLuaConsole() override;
  553. // LLFloater overrides
  554. bool postBuild() override;
  555. void draw() override;
  556. bool handleKeyHere(KEY key, MASK mask) override;
  557. // LLFocusableElement override
  558. void onFocusReceived() override;
  559. // Returns true if the console exists and the text could be printed in it,
  560. // or false otherwise.
  561. static bool print(const std::string& text);
  562. private:
  563. static void onClearButton(LLUICtrl* ctrlp, void* userdata);
  564. static void onLoadButton(LLUICtrl*, void*);
  565. static void onBrowseButton(LLUICtrl* ctrlp, void* userdata);
  566. static void onExecuteButton(LLUICtrl*, void* userdata);
  567. static void onHelpButton(LLUICtrl*, void* userdata);
  568. static void onListButton(LLUICtrl*, void* userdata);
  569. private:
  570. LLLayoutStack* mInputLayout;
  571. LLTextEditor* mOutputText;
  572. LLTextEditor* mInputCode;
  573. LLButton* mClearOutput;
  574. LLButton* mClearInput;
  575. LLButton* mLoadCode;
  576. LLButton* mBackward;
  577. LLButton* mForward;
  578. LLButton* mExecute;
  579. LLRect mInputLayoutRect;
  580. std::string mTextBuffer;
  581. size_t mHistoryIndex;
  582. U32 mResizingAttempts;
  583. S32 mSizeDelta;
  584. // Static to keep the Lua commands history over the whole viewer session.
  585. static std::vector<std::string> sHistoryStorage;
  586. };
  587. // A mere wrapper function to avoid declaring HBLuaFloater in this header.
  588. // This function is used exclusively by LLUICtrl to register Lua commands from
  589. // UI controls in Lua floaters with a "lua_command" attribute.
  590. void register_ui_lua_command(LLUICtrl* ctrlp, LLView* parentp,
  591. const std::string& command);
  592. // Another wrapper, for the alert dialogs callback.
  593. void lua_alert_callback(const std::string& dialog_name, const LLUUID& alert_id,
  594. const std::string& message,
  595. const std::vector<std::string>& buttons);
  596. extern HBViewerAutomation* gAutomationp;
  597. extern HBLuaSideBar* gLuaSideBarp;
  598. extern HBLuaPieMenu* gLuaPiep;
  599. #endif // LL_HBVIEWERAUTOMATION_H