toolbar-menu.lslp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. //////////
  4. //
  5. // Sloodle Toolbar menu script (v2.0)
  6. // Controls the Toolbar as a whole, and runs the Classroom Gestures
  7. // Part of the Sloodle project (www.sloodle.org)
  8. //
  9. // Copyright (c) 2006-8 Sloodle (various contributors)
  10. // Released under the GNU GPL
  11. //
  12. // Contributors:
  13. // - <unknown>
  14. // - Peter R. Bloomfield
  15. //
  16. //////////
  17. //
  18. // Versions:
  19. // 2.1 - added auto-hide feature (although it might not be very good yet... I think we need a better method!)
  20. // 2.0 - centralised animation control in this script (rather than separate scripts)
  21. // - <history unknown>
  22. //
  23. //////////
  24. //
  25. // Usage:
  26. // This script should be in the *root* prim of an object, and expects that a series of linked
  27. // child prims are given names such as "gesture:wave". These objects should *not* process their
  28. // own "touch_start" events, but should pass them back to the parent (this is the default behaviour).
  29. // When "touch_start" is called, this object will get the name of the prim that was touched, and
  30. // look it up in a list of animation data. It will start/stop the associated animation as appropriate.
  31. //
  32. // If the root prim is touched, then it flips between the two modes of operation.
  33. // If the "minimize_button" is touched, then it auto-hides or unhides itself.
  34. //
  35. //
  36. //////////
  37. // Name of the button objects
  38. string MINIMIZE_BUTTON = "minimize_button";
  39. string RESTORE_BUTTON = "restore_button";
  40. string HELP_BUTTON = "help_button";
  41. // Name of the help notecard
  42. string HELP_NOTECARD = "Sloodle Toolbar Help";
  43. // Is the toolbar flipped over? (i.e. is it on gestures?)
  44. integer flipped = 0;
  45. // Is the toolbar currently hidden ('minimized')?
  46. integer hidden = 0;
  47. // Sound to be played when the toolbar is touched
  48. string touchSound = "";
  49. // This list stores information in sets of 3:
  50. // {string:name of gesture button} {string:name of animation} {integer:playing?}
  51. // The name of the gesture button is also used as the name of a language string in the "toolbar" batch.
  52. // That language string will be echoed to chat.
  53. // The "playing?" item can have one of 3 values. If the animation only plays once at a time, it should be -1.
  54. // If the animation loops, but it is *not* currently playing, it should be 0. If it loops and is currently playing, it should be 1.
  55. list animdata = [ "gesture:handup", "LongRaise", 0,
  56. "gesture:wave", "Wave", 0,
  57. "gesture:clap", "clap", -1,
  58. "gesture:nodoff", "Nodoff", -1,
  59. "gesture:huh", "IDontUnderstand", -1,
  60. "gesture:gotit", "gotit", -1,
  61. "gesture:yes", "Yes", -1,
  62. "gesture:no", "No", -1
  63. ];
  64. ///// TRANSLATIONS /////
  65. // Link message channels
  66. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  67. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  68. // Translation output methods
  69. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  70. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  71. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  72. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  73. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  74. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  75. string SLOODLE_TRANSLATE_DIALOG = "dialog"; // Recipient avatar should be identified in link message keyval. At least 2 output parameters: first the channel number for the dialog, and then 1 to 12 button label strings.
  76. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  77. string SLOODLE_TRANSLATE_LOAD_URL_PARALLEL = "loadurlpar"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  78. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  79. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  80. // Used for sending parallel URL loading messages
  81. integer SLOODLE_CHANNEL_OBJECT_LOAD_URL = -1639270041;
  82. // Send a translation request link message
  83. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  84. {
  85. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  86. }
  87. ///// STATES /////
  88. default
  89. {
  90. state_entry()
  91. {
  92. // We need to get animation permissions
  93. llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  94. // Preload the touching sound
  95. if(touchSound != ""){
  96. llPreloadSound(touchSound);
  97. }
  98. }
  99. on_rez(integer param)
  100. {
  101. llSetRot(ZERO_ROTATION);
  102. llResetScript();
  103. }
  104. run_time_permissions(integer id)
  105. {
  106. }
  107. touch_start(integer total_number)
  108. {
  109. // Which link was touched?
  110. integer linknumber = llDetectedLinkNumber(0);
  111. string name = llGetLinkName(linknumber);
  112. // Is the toolbar currently hidden?
  113. if (hidden == 1) {
  114. // If the restore button was pressed, then unhide it. Otherwise, ignore the touch.
  115. if (name == RESTORE_BUTTON) {
  116. hidden = 0;
  117. if (flipped) llSetRot(llEuler2Rot(<0,PI,0>));
  118. else llSetRot(ZERO_ROTATION);
  119. }
  120. return;
  121. }
  122. // Was the minimize button pressed?
  123. if (name == MINIMIZE_BUTTON) {
  124. // Hide it
  125. hidden = 1;
  126. llSetRot(llEuler2Rot(<0,PI * 0.5,0>));
  127. return;
  128. }
  129. // Ignore any other touches if we are hidden
  130. if (hidden == 1) return;
  131. // So what else was touched?
  132. if (name == llGetObjectName()) {
  133. // The toggle tabs were touched
  134. // Toggle the rotation between gestures and blog
  135. if (!flipped)
  136. {
  137. llSetRot(llEuler2Rot(<0,PI,0>));
  138. flipped = 1;
  139. }
  140. else
  141. {
  142. llSetRot(ZERO_ROTATION);
  143. flipped = 0;
  144. }
  145. return;
  146. } else if (name == HELP_BUTTON) {
  147. // The help button was touched - give the help notecard
  148. if (llGetInventoryType(HELP_NOTECARD) == INVENTORY_NOTECARD) {
  149. llGiveInventory(llDetectedKey(0), HELP_NOTECARD);
  150. } else {
  151. // Nothing to give
  152. sloodle_translation_request(SLOODLE_TRANSLATE_OWNER_SAY, [], "helpnotecardnotfound", [HELP_NOTECARD], NULL_KEY, "toolbar");
  153. }
  154. return;
  155. }
  156. // Was this a gesture command?
  157. integer pos = llListFindList(animdata, [name]);
  158. if (pos >= 0) {
  159. // Make sure there is enough data (there should be 2 more elements beyond the button name)
  160. if ((pos + 2) >= llGetListLength(animdata)) return;
  161. // Extract the animation data
  162. string animname = llList2String(animdata, pos + 1);
  163. integer playing = llList2Integer(animdata, pos + 2);
  164. string avname = llKey2Name(llGetOwner());
  165. // What do we do?
  166. if (playing < 0) {
  167. // Play the animation once and echo the gesture to chat
  168. llStartAnimation(animname);
  169. llSay(0, avname + " " + animtext);
  170. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], name, [avname], NULL_KEY, "toolbar");
  171. } else if (playing == 0) {
  172. // Start playing the animation and echo the gesture to chat
  173. llStartAnimation(animname);
  174. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], name, [avname], NULL_KEY, "toolbar");
  175. // Set the "playing" flag to 1
  176. animdata = llListReplaceList(animdata, [1], (pos + 2), (pos + 2));
  177. // Highlight the button
  178. llSetLinkColor(linknumber, <1.0,1.0,0.0>, ALL_SIDES);
  179. } else if (playing > 0) {
  180. // Stop playing the animation
  181. llStopAnimation(animname);
  182. // Set the "playing" flag back to 0
  183. animdata = llListReplaceList(animdata, [0], (pos + 2), (pos + 2));
  184. // Deactivate the button highlight
  185. llSetLinkColor(linknumber, <1.0,1.0,1.0>, ALL_SIDES);
  186. }
  187. }
  188. }
  189. }
  190. // Please leave the following line intact to show where the script lives in Git:
  191. // SLOODLE LSL Script Git Location: mod/toolbar_giver-1.0/objects/toolbar/assets/toolbar-menu.lslp