forked from OpenCollarTeam/AO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoc_ao_dialog.lsl
133 lines (124 loc) · 4.24 KB
/
oc_ao_dialog.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
This file is a part of OpenCollar.
Copyright ©2021
: Contributors :
Phidoux (taya.Maruti)
* June 3 2023 - Created oc_ao_dialog
this Script is based from oc_ao 2.0 Beta and oc_addon_template to create a stand alone menu system for addons.
*/
// stand alone dialog system based on oc_ao 2.0 beta and oc_addon_template.
integer DIALOG = -9000;
integer DIALOG_RESPONSE = -9001;
//integer DIALOG_TIMEOUT = -9002;
list g_lMenuIDs;
Dialog(key kID, string sPrompt, list lChoices, list lUtilityButtons, integer iAuth, string sName)
{
integer iChannel = llRound(llFrand(10000000)) + 100000;
while (~llListFindList(g_lMenuIDs, [iChannel]))
{
iChannel = llRound(llFrand(10000000)) + 100000;
}
integer iListener = llListen(iChannel, "",kID, "");
integer iTime = llGetUnixTime() + 180;
if(llGetListLength(g_lMenuIDs))
{
integer iIndex = llListFindList(g_lMenuIDs, [kID]);
if (~iIndex)
{
g_lMenuIDs = llListReplaceList(g_lMenuIDs,[kID, iChannel, iListener, iTime, sName, iAuth],iIndex,iIndex+5);
}
else
{
g_lMenuIDs += [kID, iChannel, iListener, iTime, sName, iAuth];
}
}
else
{
g_lMenuIDs += [kID, iChannel, iListener, iTime, sName, iAuth];
}
llSetTimerEvent(180);
llDialog(kID,sPrompt,SortButtons(lChoices,lUtilityButtons),iChannel);
}
list SortButtons(list lButtons, list lStaticButtons)
{
list lSpacers;
list lAllButtons = lButtons + lStaticButtons;
//cutting off too many buttons, no multi page menus as of now
while (llGetListLength(lAllButtons)>12)
{
lButtons = llDeleteSubList(lButtons,0,0);
lAllButtons = lButtons + lStaticButtons;
}
while (llGetListLength(lAllButtons) % 3 != 0 && llGetListLength(lAllButtons) < 12)
{
lSpacers += "-";
lAllButtons = lButtons + lSpacers + lStaticButtons;
}
integer i = llListFindList(lAllButtons, ["BACK"]);
if (~i)
{
lAllButtons = llDeleteSubList(lAllButtons, i, i);
}
list lOut = llList2List(lAllButtons, 9, 11);
lOut += llList2List(lAllButtons, 6, 8);
lOut += llList2List(lAllButtons, 3, 5);
lOut += llList2List(lAllButtons, 0, 2);
if (~i)
{
lOut = llListInsertList(lOut, ["BACK"], 2);
}
lAllButtons = [];
lButtons = [];
lSpacers = [];
lStaticButtons = [];
return lOut;
}
default
{
timer()
{
integer n = llGetListLength(g_lMenuIDs) - 5;
integer iNow = llGetUnixTime();
for ( n; n>=0; n=n-5 )
{
integer iDieTime = llList2Integer(g_lMenuIDs,n+3);
if ( iNow > iDieTime )
{
llInstantMessage(llList2Key(g_lMenuIDs,n-1),"Menu Timed out!");
llListenRemove(llList2Integer(g_lMenuIDs,n+2));
g_lMenuIDs = llDeleteSubList(g_lMenuIDs,n,n+5);
}
}
if(!llGetListLength(g_lMenuIDs))
{
llSetTimerEvent(0.0);
}
}
listen(integer iChannel, string sName, key kID, string sMsg)
{
if (llListFindList(g_lMenuIDs,[kID,iChannel]) != -1)
{
integer iMenuIndex = llListFindList(g_lMenuIDs, [kID]);
integer iAuth = llList2Integer(g_lMenuIDs,iMenuIndex+5);
string sMenu = llList2String(g_lMenuIDs, iMenuIndex+4);
llListenRemove(llList2Integer(g_lMenuIDs,iMenuIndex+2));
g_lMenuIDs = llDeleteSubList(g_lMenuIDs,iMenuIndex, iMenuIndex+5);
// Return the output.
llMessageLinked( LINK_SET, DIALOG_RESPONSE, (string)iAuth+","+sMenu+","+sMsg, kID);
}
}
link_message(integer iLink, integer iNum,string sMsg, key kID)
{
if( iNum == DIALOG )
{
// Process and display menu.
list lPar = llParseString2List(sMsg,[","],[]);
string sPrompt = llList2String(lPar,0);
list lButtons = llParseString2List(llList2String(lPar,1),["`"],[]);
list lUtilityButtons = llParseString2List(llList2String(lPar,2),["`"],[]);
integer iAuth = llList2Integer(lPar,3);
string sName = llList2String(lPar,4);
Dialog( kID, sPrompt, lButtons, lUtilityButtons, iAuth, sName);
}
}
}