Automatic_GIF_to_SL_script player.lsl 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // :CATEGORY:GIF
  2. // :NAME:GIF Player
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:54
  6. // :ID:348
  7. // :NUM:471
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // GIF to Sl
  12. // :CODE:
  13. // Put any texture converted by gif_2_SL_animation_v0.6.exe into a prim with this script to get it to play back automatically as a movie
  14. integer SIDE = ALL_SIDES; // change to 1,2,3 for just one side
  15. //Effect parameters: (can be put in list together, to make animation have all of said effects)
  16. //LOOP - loops the animation
  17. //SMOOTH - plays animation smoothly
  18. //REVERSE - plays animation in reverse
  19. //PING_PONG - plays animation in one direction, then cycles in the opposite direction
  20. list effects = [LOOP]; // LOOP for GIF89 movies
  21. //Movement parameters (choose one):
  22. //ROTATE - Rotates the texture
  23. //SCALE - Scales the texture
  24. //Set movement to 0 to slide animation in the X direction, without any special movement.
  25. integer movement = 0;
  26. integer face = ALL_SIDES; //Number representing the side to activate the animation on.
  27. integer sideX = 1; //Represents how many horizontal images (frames) are contained in your texture.
  28. integer sideY = 1; //Same as sideX, except represents vertical images (frames).
  29. float start = 0.0; //Frame to start animation on. (0 to start at the first frame of the texture)
  30. float length = 0.0; //Number of frames to animate, set to 0 to animate all frames.
  31. float speed = 10.0; //Frames per second to play.
  32. // menu stuff
  33. integer listen_id; // int of the current listener
  34. integer menuChannel; // int of the channel number
  35. // from the menu system http://wiki.secondlife.com/wiki/SimpleDialogMenuSystem
  36. integer N_DIALOG_CHOICES;
  37. integer MAX_DIALOG_CHOICES_PER_PG = 8; // if not offering back button, increase this to 9
  38. string PREV_PG_DIALOG_PREFIX = "< Page ";
  39. string NEXT_PG_DIALOG_PREFIX = "> Page ";
  40. string DIALOG_DONE_BTN = "Done";
  41. string DIALOG_BACK_BTN = "<< Back";
  42. integer pageNum;
  43. list DIALOG_CHOICES;
  44. giveDialog(key ID, integer pageNum) {
  45. list buttons;
  46. integer firstChoice;
  47. integer lastChoice;
  48. integer prevPage;
  49. integer nextPage;
  50. string OnePage;
  51. CancelListen();
  52. menuChannel = llCeil(llFrand(1000000) + 11000000);
  53. listen_id = llListen(menuChannel,"","","");
  54. llSetTimerEvent(60);
  55. N_DIALOG_CHOICES = llGetListLength(DIALOG_CHOICES);
  56. if (N_DIALOG_CHOICES <= 10) {
  57. buttons = DIALOG_CHOICES;
  58. OnePage = "Yes";
  59. }
  60. else {
  61. integer nPages = (N_DIALOG_CHOICES+MAX_DIALOG_CHOICES_PER_PG-1)/MAX_DIALOG_CHOICES_PER_PG;
  62. if (pageNum < 1 || pageNum > nPages) {
  63. pageNum = 1;
  64. }
  65. firstChoice = (pageNum-1)*MAX_DIALOG_CHOICES_PER_PG;
  66. lastChoice = firstChoice+MAX_DIALOG_CHOICES_PER_PG-1;
  67. if (lastChoice >= N_DIALOG_CHOICES) {
  68. lastChoice = N_DIALOG_CHOICES;
  69. }
  70. if (pageNum <= 1) {
  71. prevPage = nPages;
  72. nextPage = 2;
  73. }
  74. else if (pageNum >= nPages) {
  75. prevPage = nPages-1;
  76. nextPage = 1;
  77. }
  78. else {
  79. prevPage = pageNum-1;
  80. nextPage = pageNum+1;
  81. }
  82. buttons = llList2List(DIALOG_CHOICES, firstChoice, lastChoice);
  83. }
  84. // FYI, this puts the navigation button row first, so it is always at the bottom of the dialog
  85. list buttons01 = llList2List(buttons, 0, 2);
  86. list buttons02 = llList2List(buttons, 3, 5);
  87. list buttons03 = llList2List(buttons, 6, 8);
  88. list buttons04;
  89. if (OnePage == "Yes") {
  90. buttons04 = llList2List(buttons, 9, 11);
  91. }
  92. buttons = buttons04 + buttons03 + buttons02 + buttons01;
  93. if (OnePage == "Yes") {
  94. buttons = [ DIALOG_DONE_BTN, DIALOG_BACK_BTN ]+ buttons;
  95. //omit DIALOG_BACK_BTN in line above if not offering
  96. }
  97. else {
  98. buttons = [
  99. PREV_PG_DIALOG_PREFIX + (string)prevPage,
  100. DIALOG_BACK_BTN, NEXT_PG_DIALOG_PREFIX+(string)nextPage, DIALOG_DONE_BTN
  101. ]+buttons;
  102. //omit DIALOG_BACK_BTN in line above if not offering
  103. }
  104. llDialog(ID, "Page "+(string)pageNum+"\nChoose one:", buttons, menuChannel);
  105. }
  106. CancelListen() {
  107. llListenRemove(listen_id);
  108. }
  109. initAnim() //Call this when you want to change something in the texture animation.
  110. {
  111. integer effectBits;
  112. integer i;
  113. for(i = 0; i < llGetListLength(effects); i++)
  114. {
  115. effectBits = (effectBits | llList2Integer(effects,i));
  116. }
  117. integer params = (effectBits|movement);
  118. llSetTextureAnim(ANIM_ON|params,face,sideX,sideY, start,length,speed);
  119. }
  120. fetch(string texture)
  121. {
  122. integer i;
  123. integer j = llGetInventoryNumber(INVENTORY_TEXTURE);
  124. for (i = 0; i < j; i ++)
  125. {
  126. string myTexture = llGetInventoryName(INVENTORY_TEXTURE,i);
  127. list data = llParseString2List(myTexture,[";"],[]);
  128. string name = llList2String(data,0);
  129. if (name == texture) {
  130. string X = llList2String(data,1);
  131. string Y = llList2String(data,2);
  132. string Z = llList2String(data,3);
  133. sideX = (integer) X;
  134. sideY = (integer) Y;
  135. speed = (float) Z;
  136. //llOwnerSay("Name=" + myTexture + " X=" + X + " Y=" + Y + " Z = " + (string) Z);
  137. if (speed) {
  138. llSetTexture(myTexture,SIDE);
  139. initAnim();
  140. }
  141. }
  142. }
  143. }
  144. // Make a list of all bare names for the dialog
  145. list fetchAll()
  146. {
  147. list choices = [];
  148. integer i;
  149. integer j = llGetInventoryNumber(INVENTORY_TEXTURE);
  150. for (i = 0; i < j; i ++)
  151. {
  152. string texture = llGetInventoryName(INVENTORY_TEXTURE,i);
  153. list data = llParseString2List(texture,[";"],[]);
  154. choices += llList2String(data,0);
  155. }
  156. return choices;
  157. }
  158. default
  159. {
  160. state_entry()
  161. {
  162. }
  163. touch_start(integer who)
  164. {
  165. if (llDetectedKey(0) == llGetOwner() )
  166. {
  167. pageNum = 1;
  168. DIALOG_CHOICES = fetchAll();
  169. giveDialog(llGetOwner(), pageNum);
  170. }
  171. }
  172. listen(integer channel, string name, key id, string message)
  173. {
  174. integer where ;
  175. if ( message == DIALOG_DONE_BTN)
  176. {
  177. CancelListen();
  178. return;
  179. }
  180. else if (message == DIALOG_BACK_BTN)
  181. {
  182. pageNum = 1;
  183. DIALOG_CHOICES = fetchAll();
  184. giveDialog(llGetOwner(), pageNum);
  185. }
  186. else if (llSubStringIndex(message, PREV_PG_DIALOG_PREFIX) == 0)
  187. {
  188. pageNum = (integer)llGetSubString(message, llStringLength(PREV_PG_DIALOG_PREFIX), -1);
  189. giveDialog(llGetOwner(), pageNum);
  190. }
  191. else if (llSubStringIndex(message, NEXT_PG_DIALOG_PREFIX) == 0)
  192. {
  193. pageNum = (integer)llGetSubString(message, llStringLength(NEXT_PG_DIALOG_PREFIX), -1);
  194. giveDialog(llGetOwner(), pageNum);
  195. } else { //this is the section where you do stuff
  196. where = llListFindList(fetchAll(),[message]);
  197. if (where >= 0)
  198. {
  199. fetch(message);
  200. giveDialog(llGetOwner(), pageNum);
  201. }
  202. // add more buttons here
  203. }
  204. }
  205. }