aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/Test sim/objects/onefang's test bed/~menu
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/Test sim/objects/onefang's test bed/~menu')
-rw-r--r--LuaSL/Test sim/objects/onefang's test bed/~menu529
1 files changed, 529 insertions, 0 deletions
diff --git a/LuaSL/Test sim/objects/onefang's test bed/~menu b/LuaSL/Test sim/objects/onefang's test bed/~menu
new file mode 100644
index 0000000..ea19396
--- /dev/null
+++ b/LuaSL/Test sim/objects/onefang's test bed/~menu
@@ -0,0 +1,529 @@
1// MLPV2 Version 2.3, by Learjeff Innis, based on
2// MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License)
3// 15-color balls by Lizz Silverstar
4// OpenSim port by Jez Ember
5// Meta 7 fixes by onefang Rejected
6
7// 2.3: sequences
8// 6 avs
9// Adjusting state
10
11integer MAX_BALLS = 6;
12
13string Version = "MLPV2.5";
14
15integer b;
16integer b0;
17integer ballusers;
18list BallColors;
19integer ch;
20integer chat = 1;
21integer group;
22integer i;
23integer menu;
24integer menuusers;
25integer redo = 1;
26integer swap;
27integer visible;
28integer BallCount;
29integer SaneMenuOrder;
30integer ReloadOnRez;
31
32integer Adjusting;
33string LastPose;
34
35integer BallsNeeded;
36
37float alpha;
38string cmd;
39string pose;
40string Posemsg; // for 'AGAIN'
41key owner;
42key user;
43key user0;
44list buttons;
45list buttonindex;
46list commands;
47list menus;
48list balls;
49list users;
50
51list SoundNames;
52list Sounds;
53list LMButtons;
54list LMParms;
55list MenuStack = [0]; // indices to previous menus, for "BACK" command
56
57integer MenuPage; // which page of current menu we're on, 0 for first
58
59// Replacement for llListFindList which is currently broken in OSLSL
60integer myListFind(list a, string b) {
61 integer x;
62 integer l=llGetListLength(a);
63
64 for(x=0; x<l; x++) {
65 if(llList2String(a,x) == b) {
66 return x;
67 }
68 }
69
70 return -1;
71}
72
73stop() {
74 sendStand(); //msg to pos/pose
75 llMessageLinked(LINK_THIS, 1, "STOP", (key)"");
76 llSleep(0.2);
77 killBalls();
78 swap = 0;
79 Adjusting = FALSE;
80}
81
82
83check_poses() {
84 llOwnerSay("Checking configs");
85 llMessageLinked(LINK_THIS,0,"POSEB", (key)"CHECK1"); //msg to memory
86 integer ix;
87 string name;
88 for (ix = 0; ix < llGetListLength(buttons); ++ix) {
89 name = llList2String(buttons, ix);
90 if (((integer)llList2String(commands, ix)) != 0) {
91 llMessageLinked(LINK_THIS,0,"POSEB", (key)name); //msg to memory
92 }
93 }
94 llMessageLinked(LINK_THIS,0,"POSEB", (key)"CHECK2"); //msg to memory
95}
96
97// Return a channel number that's based on the prim's key -- unique per object
98integer channel() {
99 return (integer)("0x"+llGetSubString((string)llGetKey(),-4,-1));
100}
101
102
103// setup for a pose based on menu characteristics
104setup_pose() {
105 if (BallsNeeded) { // if submenu includes balls:
106 if (BallCount != BallsNeeded) {
107 rezBalls(); // if not enough balls present: create balls
108 llSleep(0.5);
109 }
110 integer ix;
111 for (ix = 0; ix < BallsNeeded; ++ix) {
112 llSay(ch + ix, llList2String(BallColors, ix) // to ball: color, ballnum, adjusting
113 + "|" + (string) ix
114 + "|" + (string) Adjusting);
115 }
116 if (ballusers) setBalls("GROUP"); //if group access only
117 }
118}
119
120
121unauth(string button, string who) {
122 llDialog(user0, "\n" + button + " button allowed only for " + who, ["OK"], -1);
123}
124
125continMenu(string str) {
126 llDialog(user0, "\n"+str+llKey2Name(user)+" is using the menu, continue?", ["Yes","Cancel"], ch - 1);
127}
128
129mainMenu() {
130 MenuPage = 0;
131 menu = 0;
132 doMenu(FALSE);
133}
134
135//menu partly based on Menu Engine by Zonax Delorean (BSD License)
136//llDialog(user, menuname, buttons(from index to nextindex-1), channel)
137doMenu(integer inhibit_showing) {
138 integer colors = llList2Integer(balls,menu);
139 integer ix;
140 integer mask = 0xf;
141 integer shift = 0;
142 BallsNeeded = 0;
143 BallColors = [];
144
145 for (ix = 0; ix < MAX_BALLS; ++ix) {
146 integer bc = (colors & mask) >> ix*4;
147 BallColors += (list)bc;
148 if (bc) {
149 BallsNeeded += 1;
150 }
151 mask = mask << 4;
152 }
153
154 if (inhibit_showing) {
155 return;
156 }
157
158 b0 = llList2Integer(buttonindex, menu); //position of first button for this (sub)menu
159 b = llList2Integer(buttonindex, menu+1); //position of first button for next (sub)menu
160
161 b0 += MenuPage * 12;
162 if (b - b0 > 12) {
163 b = b0 + 12;
164 }
165
166 list buttons1;
167 buttons1 = llList2List(buttons, b0, b - 1);
168 if (SaneMenuOrder) {
169 buttons1 =
170 llList2List(buttons1, -3, -1)
171 + llList2List(buttons1, -6, -4)
172 + llList2List(buttons1, -9, -7)
173 + llList2List(buttons1, -12, -10);
174 }
175 llDialog(user, Version + "\n\n" + llList2String(menus,menu), buttons1, ch - 1);
176 llResetTime();
177}
178
179say(string str) {
180 if (menuusers) llWhisper(0,str);
181 else llOwnerSay(str);
182}
183
184killBalls() {
185 integer ix;
186 for (ix = 0; ix < MAX_BALLS; ++ix) {
187 llSay(ch + ix, "DIE"); //msg to balls
188 }
189 BallCount = 0;
190 llSetTimerEvent(0.0);
191}
192
193setBalls(string cmd) {
194 integer ix;
195 for (ix = 0; ix < BallCount; ++ix) {
196 llSay(ch + ix, cmd); //msg to balls
197 }
198}
199
200
201rezBalls() {
202 integer current = BallCount;
203
204 if (BallsNeeded == BallCount) return;
205
206 if (BallCount == 0) {
207 killBalls(); // for reinitialization, if old balls are around
208 }
209
210 while (BallCount > BallsNeeded) {
211 --BallCount;
212 llSay(ch + BallCount, "DIE");
213 }
214
215 while (BallCount < BallsNeeded) {
216 llRezObject("~ball",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,ch+BallCount);
217 ++BallCount;
218 }
219
220 // Only do this if there were no balls
221 if (! current) {
222 llMessageLinked(LINK_THIS,0,"REPOS",(key)""); //msg to pos
223 }
224
225 llSetTimerEvent(30.0);
226}
227
228
229
230sendStand() {
231 llMessageLinked(LINK_THIS,0,"POSE","0,"+(string)BallCount); //msg to pos/pose
232 llMessageLinked(LINK_THIS,0,"POSEB", "stand");
233}
234
235touched(integer same_group) {
236 if (user0 == owner || (menuusers == 1 && same_group) || menuusers == 2) { //0=owner 1=group 2=all
237 if (user0 != user) {
238 if (llGetTime() < 60.0 && user != (key)"") {
239 continMenu("");
240 return;
241 }
242 user = user0;
243 group = same_group;
244 }
245 mainMenu();
246 }
247}
248
249
250// return TRUE if caller should do menu
251integer handle_cmd(string button, integer sequenced) {
252 b = myListFind(buttons, button); //find position of cmd
253 string cmd = llList2String(commands,b); //get command
254
255 if (cmd == "TOMENU") {
256 integer newmenu = myListFind(menus, button); //find submenu
257 if (newmenu == -1) return FALSE;
258 if (sequenced) {
259 integer oldmenu = menu;
260 menu = newmenu;
261 doMenu(TRUE);
262 setup_pose();
263 menu = oldmenu;
264 return FALSE;
265 }
266 i = llList2Integer(users, newmenu);
267 if (user == owner || (i == 1 && group) || i == 2) { //0=owner 1=group 2=all
268 MenuStack = (list)menu + MenuStack;
269 MenuPage = 0;
270 menu = newmenu;
271 doMenu(sequenced);
272 return FALSE;
273 }
274 if (i == 1) unauth(button, "group");
275 else unauth(button, "owner");
276 return FALSE;
277 } else if (cmd == "BACK") {
278 if (MenuPage) {
279 --MenuPage;
280 doMenu(sequenced);
281 return FALSE;
282 }
283 menu = llList2Integer(MenuStack,0);
284 MenuStack = llList2List(MenuStack,1,-1);
285 doMenu(sequenced);
286 return FALSE;
287 } else if (cmd == "MORE") {
288 ++MenuPage;
289 doMenu(sequenced);
290 return FALSE;
291 } else if (cmd == "CHECK") {
292 check_poses();
293 } else if ((integer)cmd > 0) { //POSE
294 if (Adjusting && button != pose) {
295 llMessageLinked(LINK_THIS,0,"SAVE",pose); //msg to pos/pose
296 llSleep(5.);
297 }
298 setup_pose();
299 Posemsg = cmd + "," + (string) BallCount;
300 llMessageLinked(LINK_THIS,0,"POSE", Posemsg); //msg to pose
301 llMessageLinked(LINK_THIS,0,"POSEB", (key)button); //msg to memory
302 if (chat) say(button);
303 pose = button;
304 } else if (cmd == "SWAP") {
305 swap += 1;
306 llMessageLinked(LINK_THIS,0,"SWAP",(key)((string)swap)); //msg to pos/pose
307 } else if (cmd == "STAND") {
308 sendStand(); //msg to pos/pose
309 if (chat) say(button);
310 pose = "stand";
311 } else if (cmd == "STOP") {
312 if (chat) say(button);
313 stop();
314 return FALSE;
315 } else if (cmd == "ADJUST") {
316 Adjusting = ! Adjusting;
317 setBalls("ADJUST|" + (string)Adjusting);
318 } else if (cmd == "HIDE") {
319 setBalls("0");
320 } else if (cmd == "SHOW") {
321 setBalls("SHOW");
322 } else if (cmd == "DUMP") {
323 llMessageLinked(LINK_THIS,1,"DUMP",(key)"");
324 } else if (cmd == "INVISIBLE") {
325 visible = !visible;
326 llSetAlpha((float)visible*alpha, ALL_SIDES);
327 } else if (cmd == "REDO") {
328 redo = !redo;
329 if (redo) say(button+" ON"); else say(button+" OFF");
330 } else if (cmd == "CHAT") {
331 chat = !chat;
332 if (chat) say(button+" ON"); else say(button+" OFF");
333 } else if (cmd == "BALLUSERS") {
334 ballusers = !ballusers;
335 if (ballusers) {
336 llOwnerSay(button+" GROUP");
337 setBalls("GROUP");
338 } else {
339 llOwnerSay(button+" ALL");
340 setBalls("ALL");
341 }
342 } else if (cmd == "MENUUSERS") {
343 if (user == owner) {
344 if (!menuusers) {
345 menuusers = 1;
346 llOwnerSay(button+" GROUP");
347 } else if (menuusers == 1) {
348 menuusers = 2;
349 llOwnerSay(button+" ALL");
350 } else if (menuusers == 2) {
351 menuusers = 0;
352 llOwnerSay(button+" OWNER");
353 }
354 } else unauth(button, "owner");
355 } else if (cmd == "RESET" || cmd == "RELOAD" || cmd == "RESTART") {
356 stop();
357 if (chat) say(button);
358 if (cmd == "RESET") {
359 llResetScript();
360 } else {
361 llResetOtherScript("~memory");
362 if (cmd == "RESTART") {
363 llResetScript();
364 }
365 }
366 } else if (cmd == "OFF") {
367 sendStand(); //msg to pos/pose
368 stop();
369 if (user == owner) {
370 llOwnerSay(button);
371 llResetOtherScript("~run");
372 llResetScript();
373 }
374 unauth(button, "owner");
375 return FALSE;
376 } else if (llGetSubString(cmd, 0, 0) == "Z" || (cmd == "SAVE")) { //SAVE or Z-adjust
377 llSay(0,"Z");
378 llMessageLinked(LINK_THIS,0,cmd,pose); //msg to pos/pose
379 doMenu(sequenced);
380 return FALSE;
381 } else if (cmd == "LINKMSG") {
382 // menu button to send LM to a non-MLPV2 script
383 integer ix = myListFind(LMButtons, button);
384 if (ix != -1) {
385 list lmparms = llCSV2List(llList2String(LMParms, ix));
386 llMessageLinked(
387 llList2Integer(lmparms, 1), // destination link#
388 llList2Integer(lmparms, 2), // 'num' arg
389 llList2String(lmparms, 3), // 'str' arg
390 user0); // key arg
391 if (llList2Integer(lmparms,0)) { // inhibit remenu?
392 return FALSE; // yes, bug out
393 }
394 }
395 } else if (cmd == "SOUND") {
396 integer ix = myListFind(SoundNames, button);
397 if (ix >= 0) {
398 llPlaySound(llList2String(Sounds, ix), 1.);
399 }
400 }
401 return TRUE;
402}
403
404default {
405 state_entry() {
406 ch = channel();
407 killBalls();
408 llSleep(2.0); // give ~run a chance to shut us down
409 llResetOtherScript("~menucfg");
410 llResetOtherScript("~pos");
411 llResetOtherScript("~pose");
412 llResetOtherScript("~poser");
413 llResetOtherScript("~poser 1");
414 llResetOtherScript("~poser 2");
415 llResetOtherScript("~poser 3");
416 llResetOtherScript("~poser 4");
417 llResetOtherScript("~poser 5");
418 alpha = llGetAlpha(0); //store object transparancy (alpha)
419 if (alpha < 0.1) alpha = 0.5; else visible = 1; //if invisible store a visible alpha
420 }
421
422 link_message(integer from, integer num, string str, key id) {
423 if (from != llGetLinkNumber()) { return; }
424 if (num >= 0) { return;}
425
426 // LMs from ~memory, passing configuration
427 if (num == -1) {
428 buttons = llCSV2List(str);
429 } else if (num == -2) {
430 commands = llCSV2List(str);
431 } else if (num == -3) {
432 menus = llCSV2List(str);
433 } else if (num == -4) {
434 buttonindex = llCSV2List(str);
435 } else if (num == -5) {
436 balls = llCSV2List(str);
437 } else if (num == -6) {
438 users = llCSV2List(str);
439 } else if (num == -7) {
440 LMButtons = llCSV2List(str);
441 } else if (num == -8) {
442 LMParms = llParseStringKeepNulls(str, ["|"], []);
443 } else if (num == -9) {
444 SoundNames = llCSV2List(str);
445 } else if (num == -10) {
446 Sounds = llCSV2List(str);
447 } else if (num == -20) {
448 list args = llCSV2List(str);
449 redo = llList2Integer(args,0);
450 chat = llList2Integer(args,1);
451 ballusers = llList2Integer(args,2);
452 menuusers = llList2Integer(args,3);
453 SaneMenuOrder = llList2Integer(args,4);
454 ReloadOnRez = llList2Integer(args,5);
455
456 state on;
457 }
458 }
459
460 state_exit() {
461 llOwnerSay("("+llGetScriptName()+": "+(string)llGetFreeMemory()+" bytes free)");
462 llWhisper(0, Version + ": READY");
463 }
464}
465
466state re_on {
467 state_entry() {
468 state on;
469 }
470}
471
472state on {
473 state_entry() {
474 ch = channel();
475 owner = llGetOwner();
476 llListen(ch - 1, "", NULL_KEY, ""); //listen for pressed buttons
477 // llWhisper(0, "Channel: " + (string)ch);
478 }
479
480 on_rez(integer arg) {
481 if (ReloadOnRez) {
482 llResetScript();
483 }
484 BallCount = 0;
485 llSetTimerEvent(0.0);
486 state re_on;
487 }
488
489 touch_start(integer tcount) {
490 user0 = llDetectedKey(0);
491 touched(llDetectedGroup(0));
492 }
493
494 listen(integer channel, string name, key id, string button) {
495 if (id != user) {
496 if (button == "Yes") {
497 user = id;
498 group = llSameGroup(user0);
499 mainMenu();
500 } else if (button != "Cancel") {
501 continMenu("Selection cancelled because ");
502 }
503 return;
504 }
505 if (handle_cmd(button, FALSE) && redo) doMenu(FALSE);
506 }
507
508
509 link_message(integer from, integer num, string str, key id) {
510 if (str == "PRIMTOUCH") {
511 user0 = id;
512 touched(num);
513 return;
514 }
515 if (num == 0 && str == "AGAIN") {
516 llMessageLinked(LINK_THIS,0,"POSE", Posemsg); //msg to pose
517 llMessageLinked(LINK_THIS,0,"POSEB", (key)pose); //msg to memory
518 return;
519 }
520 if (num == -12002) {
521 handle_cmd(str, TRUE);
522 return;
523 }
524 }
525
526 timer() {
527 setBalls("LIVE"); //msg to balls: stay alive
528 }
529}