Difference between revisions of "Dialog Control"

From Second Life Wiki
Jump to navigation Jump to search
Line 207: Line 207:
     }
     }
}
}
{{LSLC|Library|Dialog Control}}

Revision as of 04:37, 15 October 2009

This is example of usage and function library needed in each scripts to use this dialog module.

Functions List

  1. Standard dialog with buttons. If there are more than 12 buttons, BACK/NEXT button will be added automatically! In that case, the last button on the list will be used as Close/Cancel button.
    • dialog(key id, string message, list buttons, list returns);
  1. Normal notification dialog, ie: dialog which requires no response from user.
    • dialogNotify(key id, string message);
  1. To display current dialog again:
    • dialogReshow();
  1. To cancel current dialog; Currently displayed dialog will give no response when clicked.
    • dialogCancel();

Sample Scripts

  1. OnTouchSelectTexture (Tiyuk Quellmalz)


If anyone uses this module, please IM Nargus Asturias, I'd love to hear what you think.

Scripts

Basic Usage Examples

Basic Dialog Usage

<lsl> // READ ME: // To see this sample in action; // Put "Nargus Dialog Control" along with this script in a prim and touch.

// ********** DIALOG FUNCTIONS ********** // Dialog constants integer lnkDialog = 14001; integer lnkDialogNotify = 14004; integer lnkDialogResponse = 14002; integer lnkDialogTimeOut = 14003;

integer lnkDialogReshow = 14011; integer lnkDialogCancel = 14012;

string seperator = "||"; integer dialogTimeOut = 0;

string packDialogMessage(string message, list buttons, list returns){

   string packed_message = message + seperator + (string)dialogTimeOut;
   
   integer i;
   integer count = llGetListLength(buttons);
   for(i=0; i<count; i++){
       string button = llList2String(buttons, i);
       if(llStringLength(button) > 24) button = llGetSubString(button, 0, 23);
       packed_message += seperator + button + seperator + llList2String(returns, i);
   }
   return packed_message;

}

dialogReshow(){llMessageLinked(LINK_THIS, lnkDialogReshow, "", NULL_KEY);} dialogCancel(){

   llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
   llSleep(1);

}

dialog(key id, string message, list buttons, list returns){

   llMessageLinked(LINK_THIS, lnkDialog, packDialogMessage(message, buttons, returns), id);

}

dialogNotify(key id, string message){

   list rows;
   
   llMessageLinked(LINK_THIS, lnkDialogNotify,
       message + seperator + (string)dialogTimeOut + seperator,
       id);

} // ********** END DIALOG FUNCTIONS **********


default{

   state_entry(){
       llSetText("Touch me to show dialog", <1,1,1>, 1);
   }
   link_message(integer sender_num, integer num, string str, key id){
       if(num == lnkDialogTimeOut){
           dialogNotify(llGetOwner(), "Menu time-out. Please try again.");
           state default;
       }else if(num == lnkDialogResponse){
           llWhisper(0, str);
       }
   }
   
   touch_start(integer num_detected){
       dialog(llDetectedKey(0),
       
           // Dialog message here
           "Messages go here",
           
           // List of dialog buttons
           [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, "Close" ],
           // List of return value from the buttons, in same order
           // Note that this value do not need to be the same as button texts
           [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, "X" ]
       );
   }

} </lsl>

Basic Menus Usage

<lsl> // READ ME: // To see this sample in action; // Put "Nargus Dialog Control" and "Nargus Dialog Menus" along with this script // in a prim and touch.

// Dialog constants integer lnkDialog = 14001; integer lnkDialogNotify = 14004; integer lnkDialogResponse = 14002; integer lnkDialogTimeOut = 14003;

integer lnkDialogReshow = 14011; integer lnkDialogCancel = 14012;

integer lnkMenuClear = 15001; integer lnkMenuAdd = 15002; integer lnkMenuShow = 15003;

string seperator = "||"; integer dialogTimeOut = 0;

// ********** DIALOG FUNCTIONS ********** string packDialogMessage(string message, list buttons, list returns){

   string packed_message = message + seperator + (string)dialogTimeOut;
   
   integer i;
   integer count = llGetListLength(buttons);
   for(i=0; i<count; i++) packed_message += seperator + llList2String(buttons, i) + seperator + llList2String(returns, i);
   return packed_message;

}

dialogReshow(){llMessageLinked(LINK_THIS, lnkDialogReshow, "", NULL_KEY);} dialogCancel(){

   llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
   llSleep(1);

}

dialogNotify(key id, string message){

   list rows;
   
   llMessageLinked(LINK_THIS, lnkDialogNotify,
       message + seperator + (string)dialogTimeOut + seperator,
       id);

} // ********** END DIALOG FUNCTIONS **********


default{

   state_entry(){
       llMessageLinked(LINK_THIS, lnkMenuClear, "", NULL_KEY);
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Main Menu ]\n" +
           "Messages go here",
           [ "BUTTON_1", "BUTTON_2", "BUTTON_3", "BUTTON_X" ],
           [ "MENU_SubMenu1", "MENU_SubMenu2", "MENU_SubMenu3", "EXIT" ]
       ), "MainMenu");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 1 ]\n" +
           "Messages go here",
           [ "SUB_1_1", "SUB_1_2", "SUB_1_3", "MAIN MENU", "SUB_3", "BUTTON_X" ],
           [ "1.1", "1.2", "1.3", "MENU_MainMenu", "MENU_SubMenu3", "EXIT" ]
       ), "SubMenu1");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 2 ]\n" +
           "Messages go here",
           [ "SUB_2_1", "SUB_2_2", "SUB_2_3", "MAIN MENU", "SUB_1", "BUTTON_X" ],
           [ "2.1", "2.2", "2.3", "MENU_MainMenu", "MENU_SubMenu1", "EXIT" ]
       ), "SubMenu2");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 3 ]\n" +
           "Messages go here",
           [ "SUB_3_1", "SUB_3_2", "SUB_3_3", "MAIN MENU", "SUB_2", "BUTTON_X" ],
           [ "3.1", "3.2", "3.3", "MENU_MainMenu", "MENU_SubMenu2", "EXIT" ]
       ), "SubMenu3");
       
       llSetText("Touch me to show menu", <1,1,1>, 1);
   }
   link_message(integer sender_num, integer num, string str, key id){
       if(num == lnkDialogTimeOut){
           dialogNotify(llGetOwner(), "Menu time-out. Please try again.");
           state default;
       }else if(num == lnkDialogResponse){
           llWhisper(0, str);
       }
   }
   
   touch_start(integer num_detected){
       llMessageLinked(LINK_THIS, lnkMenuShow, "", llDetectedOwner(0));
   }

}