Push latest changes

This commit is contained in:
zontreck 2024-08-01 17:52:22 -07:00
parent aa26ff7406
commit 17262bdaf0
2 changed files with 154 additions and 16 deletions

View file

@ -37,6 +37,50 @@ string EXIT_MENU = "-exit-";
string NEXT_MENU = "-->";
integer g_iDebugIndent=0;
DEBUG_FUNC(integer iEnter, string sLabel, list lParams) {
if(iEnter){
llOwnerSay(MakeIndent() + "ENTER " + sLabel + " [" + llList2CSV(lParams) + "]");
g_iDebugIndent++;
} else {
g_iDebugIndent --;
if(g_iDebugIndent<0)g_iDebugIndent=0;
llOwnerSay(MakeIndent() + "LEAVE " + sLabel + " [" + llList2CSV(lParams) + "]");
}
}
DEBUG_STMT(integer iEnter, string sLabel) {
if(iEnter) {
llOwnerSay(MakeIndent() + "STMT " + sLabel);
g_iDebugIndent ++;
}else {
g_iDebugIndent--;
if(g_iDebugIndent<0)g_iDebugIndent=0;
llOwnerSay(MakeIndent() + "RET " + sLabel);
}
}
DEBUG(string sMsg) {
llOwnerSay(MakeIndent() + " > " + sMsg);
}
string MakeIndent()
{
integer i = 0;
string sIndent = "";
for(i = 0;i<g_iDebugIndent;i++){
sIndent += " ";
}
return "[" + llGetScriptName() + "] " + sIndent;
}
string SLURL(key kID){
return "secondlife:///app/agent/"+(string)kID+"/about";
}
@ -258,6 +302,7 @@ integer calcMaxPages(string sMenu) {
}
string getPage(string sMenu, integer iPage, integer iCheckUUID) {
DEBUG_FUNC(TRUE, "getPage", [sMenu, iPage, iCheckUUID]);
// Retrieve buttons and utility lists from JSON
list lButtons = llJson2List(llJsonGetValue(sMenu, ["buttons"]));
list lUtility = llJson2List(llJsonGetValue(sMenu, ["utility"]));
@ -298,7 +343,7 @@ string getPage(string sMenu, integer iPage, integer iCheckUUID) {
i =0;
integer end = llGetListLength(lPageButtons);
integer idNum = 0;
string sExtraText = "";
string sExtraText = " ";
for(i=0;i<end;i++) {
string sButton = llList2String(lPageButtons, i);
if(IsLikelyAvatarID(sButton)) {
@ -310,7 +355,10 @@ string getPage(string sMenu, integer iPage, integer iCheckUUID) {
}
@returnMenu;
return llList2Json(JSON_OBJECT, ["text", sExtraText, "buttons", "~!~" + llDumpList2String(lPageButtons, "~!~") + "~!~"]);
DEBUG("Buttons list: " + llList2CSV(lPageButtons));
string jsReply=llList2Json(JSON_OBJECT, ["text", sExtraText, "buttons", "~!~" + llDumpList2String(lPageButtons, "~!~") + "~!~"]);
DEBUG_FUNC(FALSE, "getPage", [jsReply]);
return jsReply;
}
AppendMenuButton(string sMenu, string sButton) {
@ -355,17 +403,25 @@ default
listen(integer c,string n,key i,string m) {
// Get the menu path
DEBUG_FUNC(TRUE, "listen", [i,m]);
string sMenuID = getMenuID(i);
// Get the current page number
integer iPage = getPageNumber(i);
DEBUG("Get current page number for menu " + sMenuID + ": " + (string)iPage);
string sMenu = "";
if(sMenuID != "") readMenu(sMenuID);
integer iMaxPages = calcMaxPages(sMenu);
if(sMenuID != "") sMenu = readMenu(sMenuID);
DEBUG("Menu Json: " + sMenu);
integer iMaxPages = 0;
if(sMenuID != "") iMaxPages = calcMaxPages(sMenu);
DEBUG("Get max number of pages: " + (string)iMaxPages);
if(m == PREVIOUS_MENU) {
DEBUG_STMT(TRUE, "Previous Menu");
// Update the time remaining
updateTimer(i, MENU_TIMER);
@ -373,7 +429,7 @@ default
if(iPage < 0) iPage=0;
string sPage = getPage(sMenuID, iPage, TRUE);
string sPage = getPage(sMenu, iPage, TRUE);
list lPageButtons = llParseString2List(llJsonGetValue(sPage, ["buttons"]), ["~!~"], []);
@ -382,7 +438,9 @@ default
if(iMaxPages > 1) sAppend += "\n\nPage " + (string)iPage + "/" + (string)(iMaxPages-1);
llDialog(i, llJsonGetValue(sMenu, ["prompt"]) + sAppend, lPageButtons, getChannel(i));
DEBUG_STMT(FALSE, "Previous Menu");
} else if(m == NEXT_MENU) {
DEBUG_STMT(TRUE, "Next Menu");
// Update the time remaining
updateTimer(i, MENU_TIMER);
@ -390,7 +448,7 @@ default
if(iPage < iMaxPages-1) iPage=iMaxPages-1;
string sPage = getPage(sMenuID, iPage, TRUE);
string sPage = getPage(sMenu, iPage, TRUE);
list lPageButtons = llParseString2List(llJsonGetValue(sPage, ["buttons"]), ["~!~"], []);
@ -399,11 +457,13 @@ default
if(iMaxPages > 1) sAppend += "\n\nPage " + (string)iPage + "/" + (string)(iMaxPages-1);
llDialog(i, llJsonGetValue(sMenu, ["prompt"]) + sAppend, lPageButtons, getChannel(i));
DEBUG_STMT(FALSE, "Next Menu");
} else if(m == " ") {
DEBUG_STMT(TRUE, "Empty Button");
// Update the time remaining
updateTimer(i, MENU_TIMER);
string sPage = getPage(sMenuID, iPage, TRUE);
string sPage = getPage(sMenu, iPage, TRUE);
list lPageButtons = llParseString2List(llJsonGetValue(sPage, ["buttons"]), ["~!~"], []);
@ -412,13 +472,51 @@ default
if(iMaxPages > 1) sAppend += "\n\nPage " + (string)iPage + "/" + (string)(iMaxPages-1);
llDialog(i, llJsonGetValue(sMenu, ["prompt"]) + sAppend, lPageButtons, getChannel(i));
DEBUG_STMT(FALSE, "Empty Button");
} else if(m == EXIT_MENU) {
DEBUG_STMT(TRUE, "Exit Menu");
stopListen(i);
DEBUG_STMT(FALSE, "Exit Menu");
} else {
DEBUG_STMT(TRUE, "Process Response");
// Stop listening, and send a signal
string sPage = getPage(sMenuID, iPage, FALSE);
string sPage = "";
if(sMenu != "") sPage = getPage(sMenu, iPage, FALSE);
DEBUG("Parse Buttons");
// Check Message, if message is found in list, it isn't UUID.
// If message is not found, it is likely uuid
list lButtons = llParseString2List(llJsonGetValue(sPage, ["buttons"]), ["~!~"], []);
integer iIndex = llListFindList(lButtons, [m]);
DEBUG("Buttons : " + llDumpList2String(lButtons, " ~ "));
if(iIndex==-1 && sMenuID != "") {
// Loop over to find the index
integer iIDNum = (integer)m;
integer x = 0;
integer xe = llGetListLength(lButtons);
integer iID = 0;
for(x=0;x<xe;x++) {
string sButton = llList2String(lButtons, x);
if(IsLikelyAvatarID(sButton)) {
if(iIDNum == iID) {
llOwnerSay("Send button response signal over LM");
}
iID ++;
}
}
} else {
llOwnerSay("Send button response signal over LM");
// Send reply signal
}
DEBUG_STMT(FALSE, "Process Response");
}
DEBUG_FUNC(FALSE, "listen", []);
}
link_message(integer s,integer n,string m,key i) {
@ -427,29 +525,29 @@ default
startListen(i, iChan, "", "", GENERAL_TIMER);
llMessageLinked(LINK_SET, LINK_SIGNAL_CHANNEL_BACK, (string)iChan, "");
} else if(n == LINK_SIGNAL_SHOW_MENU) {
string sMenu = readMenu(llJsonGetValue(m,["menu"]));
string jsMenu = readMenu(llJsonGetValue(m,["menu"]));
integer iChan = generateChannel(FALSE);
startListen(i, iChan, m, llJsonGetValue(sMenu, ["prompt"]), MENU_TIMER);
startListen(i, iChan, llJsonGetValue(m,["menu"]), llJsonGetValue(jsMenu, ["prompt"]), MENU_TIMER);
// Show the dialog window now after constructing pages if needed.
integer maxPages = calcMaxPages(sMenu);
integer maxPages = calcMaxPages(jsMenu);
// Now show the dialog for page 1
integer iPage = 1;
if(jsonValueExists(m, ["page"])) iPage = (integer)llJsonGetValue(m,["page"]);
string sPage = getPage(sMenu, iPage, TRUE);
list lPageButtons = llParseString2List(llJsonGetValue(sPage, ["buttons"]), ["~!~"], []);
string jsPage = getPage(jsMenu, iPage, TRUE);
list lPageButtons = llParseString2List(llJsonGetValue(jsPage, ["buttons"]), ["~!~"], []);
updatePage(i, iPage);
string sAppend = llJsonGetValue(sPage, ["text"]);
string sAppend = llJsonGetValue(jsPage, ["text"]);
if(maxPages>1) sAppend += "\n\nPage " + (string)iPage+"/" + (string)(maxPages-1);
//llOwnerSay("DEBUG\n" + llJsonGetValue(sMenu, ["prompt"]) + sAppend + "\n\n" + llJsonGetValue(sPage, ["buttons"]));
llDialog(i, llJsonGetValue(sMenu, ["prompt"])+sAppend, lPageButtons, getChannel(i));
llDialog(i, llJsonGetValue(jsMenu, ["prompt"])+sAppend, lPageButtons, getChannel(i));
} else if(n == LINK_SIGNAL_REGISTER_MENU) {
string sMenuJson = llLinksetDataRead("menus." + (string)i);
if(sMenuJson == "" ) {
@ -460,7 +558,7 @@ default
}else sMenuJson = AddMenuButton(sMenuJson, m);
llLinksetDataWrite("menus."+(string)i, sMenuJson);
llSleep(0.1);
llSleep(0.5);
llMessageLinked(LINK_SET, LINK_SIGNAL_QUERY_MENU, (string)i + "/" + m, "");
} else if(n == LINK_SIGNAL_RESET) {
llResetScript();

View file

@ -59,4 +59,44 @@ SetMenuPrompt(string sMenu, string sPromptText) {
showMenu(key kID, string sMenu, integer iPage) {
llMessageLinked(LINK_SET, LINK_SIGNAL_SHOW_MENU, llList2Json(JSON_OBJECT, ["menu", sMenu, "page", iPage]), kID);
}
integer g_iDebugIndent=0;
DEBUG_FUNC(integer iEnter, string sLabel, list lParams) {
if(iEnter){
llOwnerSay(MakeIndent() + "ENTER " + sLabel + " [" + llList2CSV(lParams) + "]");
g_iDebugIndent++;
} else {
g_iDebugIndent --;
if(g_iDebugIndent<0)g_iDebugIndent=0;
llOwnerSay(MakeIndent() + "LEAVE " + sLabel + " [" + llList2CSV(lParams) + "]");
}
}
DEBUG_STMT(integer iEnter, string sLabel) {
if(iEnter) {
llOwnerSay(MakeIndent() + "STMT " + sLabel);
g_iDebugIndent ++;
}else {
g_iDebugIndent--;
if(g_iDebugIndent<0)g_iDebugIndent=0;
llOwnerSay(MakeIndent() + "RET " + sLabel);
}
}
DEBUG(string sMsg) {
llOwnerSay(MakeIndent() + " > " + sMsg);
}
string MakeIndent()
{
integer i = 0;
string sIndent = "";
for(i = 0;i<g_iDebugIndent;i++){
sIndent += " ";
}
return "[" + llGetScriptName() + "] " + sIndent;
}