normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / jaunter_button_pusher_v0.8.txt
1 
2 // huffware script: jaunter button pusher, by fred huffhines
3 //
4 // the button pusher script warped into service for jaunters.
5 //
6 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
7 // do not use it in objects without fully realizing you are implicitly accepting that license.
8 //
9
10 string JAUNT_NEXT_BUTTON_NAME = "next";
11 string JAUNT_MENU_BUTTON_NAME = "menu";
12
13 // the button pushing API.
14 //////////////
15 integer BUTTON_PUSHER_HUFFWARE_ID = 10029;
16     // a unique ID within the huffware system for this script.
17 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
18     // this pattern is an uncommon thing to see in text, so we use it to separate
19     // our commands in link messages.
20 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
21     // used to separate lists of items from each other when stored inside a parameter.
22     // this allows lists to be passed as single string parameters if needed.
23 integer REPLY_DISTANCE = 100008;  // offset added to service's huffware id in reply IDs.
24 //////////////
25 string BUTTON_PUSHED_ALERT = "#btnp";
26     // this event is generated when the button is pushed.  the number parameter will be
27     // the huffware id plus the reply distance.  the id parameter in the link message will
28     // contain the name of the button that was pushed.
29 //////////////
30
31 float MENU_TIMER_FOR_TOUCH = 0.8;  // click hold delay before we decide they want the menu.
32
33 key last_toucher;  // the last person who touched the jaunter.
34
35 integer sent_menu_event = FALSE;  // true when we just sent out a menu event.
36
37 //////////////
38
39 handle_timer()
40 {
41     if (last_toucher != NULL_KEY) {
42 //log_it("decided to send menu event!");
43         // this is a timer elapsing for a touch-hold menu event.
44         send_menu_button_event();
45         last_toucher = NULL_KEY;
46         llSetTimerEvent(0.0);
47         sent_menu_event = TRUE;
48         return;
49     }
50 }
51
52 // generates our next button alert, once the user has finished clicking on the button.
53 send_next_button_event()
54 {
55     llMessageLinked(LINK_SET, BUTTON_PUSHER_HUFFWARE_ID + REPLY_DISTANCE,
56         BUTTON_PUSHED_ALERT, JAUNT_NEXT_BUTTON_NAME);
57 }
58
59 // tells the jaunter to show the menu of places.
60 send_menu_button_event()
61 {
62     llMessageLinked(LINK_SET, BUTTON_PUSHER_HUFFWARE_ID + REPLY_DISTANCE,
63         BUTTON_PUSHED_ALERT, wrap_parameters([JAUNT_MENU_BUTTON_NAME, last_toucher]));
64 }
65
66
67 //////////////
68 // from hufflets...
69
70 integer debug_num = 0;
71
72 // a debugging output method.  can be disabled entirely in one place.
73 log_it(string to_say)
74 {
75     debug_num++;
76     // tell this to the owner.    
77     llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
78     // say this on open chat, but use an unusual channel.
79 //    llSay(108, (string)debug_num + "- " + to_say);
80 }
81
82 string wrap_parameters(list to_flatten)
83 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
84
85 ///////////////
86
87 default {
88     state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
89     on_rez(integer parm) { state rerun; }
90 }
91 state rerun { state_entry() { state default; } }
92
93 state real_default
94 {
95     state_entry()
96     {
97     }
98
99     touch_start(integer total_number) {
100         if (llDetectedLinkNumber(0) != llGetLinkNumber()) return;
101 //log_it("touch start");
102         llSetTimerEvent(MENU_TIMER_FOR_TOUCH);
103             // how long before "hold touch" kicks in and we show the destination menu.
104         last_toucher = llDetectedKey(0);
105     }
106
107     timer() { handle_timer(); }
108
109     touch_end(integer total_number)
110     {
111         if (llDetectedLinkNumber(0) != llGetLinkNumber()) return;
112 //log_it("touch end");
113         if (sent_menu_event) {
114             // don't send a click event if we popped the menu.            
115             sent_menu_event = FALSE;
116             return;
117         }
118         // clear timer since we got to here.
119         llSetTimerEvent(0.0);
120         last_toucher = NULL_KEY;
121         send_next_button_event();
122     }
123 }