andsim

Untitled

Mar 12th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. string _notecard = "stations";
  2.  
  3. integer menuChannel = 93;
  4. string HELP_MSG = "Touch for Station Selection Dialog Menu";
  5.  
  6. list _radioURLs;
  7. list _radioStations;
  8. list theStations;
  9.  
  10. integer _linenum = 0;
  11. integer curStationOffset = 0;
  12. integer stationChunk = 6;
  13. integer curStationEnd = 5;
  14. integer totalStations = 0;
  15. integer dialogActive = 0;
  16. integer curIdx = -1;
  17. string dispStationStr = "";
  18.  
  19. string NEXT_MSG = "Next >>";
  20. string PREV_MSG = "<< Prev";
  21. string LIST_MSG = "List";
  22.  
  23. string CUR_SET = "c";
  24. string ALL_SET = "a";
  25.  
  26. list cmdNextChunk = [">>", "next", "Next"];
  27. list cmdPrevChunk = ["<<", "prev", "Prev"];
  28. list cmdLsCur = ["ls", "list"];
  29. list cmdLsAll = ["la", "listall"];
  30. list cmdSearch = ["s", "search"];
  31.  
  32. string newURL;
  33. string newDesc;
  34.  
  35. //-----------------------
  36.  
  37. reset_radio()
  38. {
  39. llSetText("starting radio ....",<1,0,0>,1.0 );
  40. llListen(77, "", "", "");
  41. curStationOffset = 0;
  42. curStationEnd = 5;
  43. _linenum = 0;
  44. dialogActive = 0;
  45. _radioURLs = [];
  46. _radioStations = [];
  47. totalStations = 0;
  48. curIdx = -1;
  49. dispStationStr = "";
  50. llGetNotecardLine(_notecard, _linenum);
  51. }
  52.  
  53. add_station(string line)
  54. {
  55. list words = llParseString2List(line, [" ", " ", "="], []);
  56. if (llGetListLength(words) < 2)
  57. {
  58. return;
  59. }
  60. string url = llList2String(words, llGetListLength(words) - 1);
  61. string station = "";
  62. integer i;
  63.  
  64. for (i=0; i<llGetListLength(words) - 1; i++)
  65. {
  66. if (llStringLength(station) > 0)
  67. {
  68. station += " ";
  69. }
  70. station += llList2String(words, i);
  71. }
  72.  
  73. _radioURLs += [url];
  74. _radioStations += [station];
  75. }
  76.  
  77.  
  78. curStations()
  79. {
  80. theStations = [PREV_MSG, LIST_MSG, NEXT_MSG];
  81.  
  82. integer i;
  83. dispStationStr = "";
  84.  
  85. for (i = curStationOffset; i <= curStationEnd; i++)
  86. {
  87. if (curIdx == i)
  88. {
  89. dispStationStr += "*";
  90. } else {
  91. dispStationStr += " ";
  92. }
  93. dispStationStr += (string) (i + 1) + ") ";
  94. dispStationStr += llList2String(_radioStations, i);
  95. dispStationStr += "\n";
  96.  
  97. theStations += (string)(i + 1);
  98. }
  99. }
  100.  
  101.  
  102. doNextSet()
  103. {
  104. curStationOffset += stationChunk;
  105. curStationEnd = curStationOffset + (stationChunk - 1);
  106.  
  107. if (curStationOffset >= totalStations)
  108. {
  109. curStationOffset = 0;
  110. curStationEnd = curStationOffset + (stationChunk - 1);
  111. }
  112.  
  113. if (curStationEnd >= totalStations)
  114. {
  115. curStationEnd = totalStations - 1;
  116. }
  117. }
  118.  
  119.  
  120. doPrevSet()
  121. {
  122. if (curStationOffset > 1 && ((curStationOffset - stationChunk) < 1))
  123. {
  124. curStationOffset = 0;
  125. } else {
  126. curStationOffset -= stationChunk;
  127. }
  128.  
  129. curStationEnd = curStationOffset + (stationChunk - 1);
  130.  
  131. if (curStationEnd >= totalStations)
  132. {
  133. curStationEnd = totalStations - 1;
  134. }
  135.  
  136. if (curStationOffset < 0)
  137. {
  138. curStationEnd = totalStations - 1;
  139. curStationOffset = totalStations - (stationChunk - 1);
  140. }
  141. }
  142.  
  143. doListStations(string mode)
  144. {
  145. integer i;
  146. integer startPos;
  147. integer endPos;
  148.  
  149. if (mode == "a")
  150. {
  151. startPos = 0;
  152. endPos = totalStations - 1;
  153. }
  154. else
  155. {
  156. startPos = curStationOffset;
  157. endPos = curStationEnd;
  158. }
  159.  
  160. for (i = startPos; i <= endPos; i++)
  161. {
  162. string newURL = llList2String(_radioURLs, i);
  163. string newDesc = llList2String(_radioStations, i);
  164. llSay(0, (string)(i + 1) + ": " + newDesc + " = " + newURL);
  165. }
  166. }
  167.  
  168.  
  169. doSearch(list theTerms)
  170. {
  171. integer i;
  172. string thePhrase = llToLower(llDumpList2String(theTerms, " "));
  173. llSay(0, "the term is " + thePhrase);
  174.  
  175. for (i = 0; i < totalStations; i++)
  176. {
  177. string curString = llList2String(_radioStations, i);
  178. if (llSubStringIndex(llToLower(curString), thePhrase) != -1)
  179. {
  180. string newURL = llList2String(_radioURLs, i);
  181. llSay(0, (string)(i + 1) + ": " + curString + " = " + newURL);
  182. }
  183. }
  184. }
  185.  
  186. //-----------------------
  187.  
  188. default
  189. {
  190. state_entry()
  191. {
  192. reset_radio();
  193. }
  194.  
  195. dataserver(key query_id, string data)
  196. {
  197. if (data != EOF)
  198. {
  199. add_station(data);
  200. _linenum++;
  201.  
  202. if (_linenum % 3 == 0)
  203. {
  204. llSetText("starting: \n" + (string)_linenum + " stations ...",
  205. <1,0,0>,1.0 );
  206. }
  207. llGetNotecardLine(_notecard, _linenum);
  208. return;
  209. }
  210.  
  211. llListen(menuChannel, "", NULL_KEY, "");
  212.  
  213. totalStations = llGetListLength(_radioURLs);
  214. llSay(0, HELP_MSG);
  215. dialogActive = 1;
  216. llSetText("", <1,0,0>, 1.0 );
  217. }
  218.  
  219. touch_start(integer touchNumber)
  220. {
  221. curStations();
  222.  
  223. llDialog(llDetectedKey(0),
  224. dispStationStr,
  225. theStations, menuChannel);
  226. }
  227.  
  228. listen(integer channel, string name, key id, string message)
  229. {
  230.  
  231. if (dialogActive == 0)
  232. {
  233. llWhisper(0, " ... still loading stations ...");
  234. return;
  235. }
  236.  
  237. if (message == "")
  238. {
  239. message = "cur";
  240. }
  241.  
  242. list words = llParseString2List(message, [" ", " ", "="], []);
  243. list testFind = llList2List(words, 0, 0);
  244.  
  245. if (llListFindList(cmdNextChunk, testFind) != -1)
  246. {
  247. doNextSet();
  248. curStations();
  249.  
  250. llDialog(id, dispStationStr,theStations, menuChannel);
  251. return;
  252. }
  253.  
  254. else if (llListFindList(cmdPrevChunk, testFind) != -1)
  255. {
  256. doPrevSet();
  257. curStations();
  258.  
  259. llDialog(id, dispStationStr, theStations, menuChannel);
  260. return;
  261. }
  262.  
  263. else if (llListFindList(cmdSearch, testFind) != -1)
  264. {
  265. doSearch(llList2List(words, 1, -1));
  266. return;
  267. }
  268.  
  269. else if (llListFindList(cmdLsAll, testFind) != -1)
  270. {
  271. doListStations(ALL_SET);
  272. return;
  273. }
  274.  
  275.  
  276. else if (llListFindList(cmdLsCur, testFind) != -1)
  277. {
  278. doListStations(CUR_SET);
  279. return;
  280. }
  281.  
  282. else if ((integer)message > 0 && (integer)message < 256)
  283. {
  284. curIdx = (integer)message - 1;
  285.  
  286. string newURL = llList2String(_radioURLs, curIdx);
  287. string newDesc = llList2String(_radioStations, curIdx);
  288.  
  289. llSay(0, "Setting Station " + message + ": " + newDesc);
  290. llSetText(newDesc, <0.0,0.0,0.8>, 1);
  291. // llSay(0, newDesc + " = " + newURL);
  292. llSetParcelMusicURL(newURL);
  293. }
  294. }
  295. }
Advertisement
Add Comment
Please, Sign In to add comment