toolbar-menu.os.lslp 8.4 KB

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