Difference between revisions of "Dialog Control"

From Second Life Wiki
Jump to navigation Jump to search
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
This is example of usage and function library needed in each scripts to use this dialog module.


==Functions List==
==Functions List==
===Basic Dialog Functionalities===
# 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.
# 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);
#* '''dialog'''(key id, string message, list buttons, list returns);
 
# Normal notification dialog, ie: dialog which requires no response from user.
#* dialogNotify(key id, string message);
 
# To display current dialog again:
# To display current dialog again:
#* dialogReshow();
#* '''dialogReshow'''();
# To cancel current dialog; Currently displayed dialog will give no response when clicked.
#* '''dialogCancel'''();


# To cancel current dialog; Currently displayed dialog will give no response when clicked.
===Menus Control===
#* dialogCancel();
# Initialize menus control using:
#* [[llMessageLinked]](LINK_THIS, lnkMenuClear, "", NULL_KEY);
# Using "packDialogMessage" function to generate new menu, and add it to menus list:
#* [[llMessageLinked]](LINK_THIS, lnkMenuAdd, '''packDialogMessage'''(....), "MenuName");
#* While "MenuName" is the same of this menu, ie: MainMenu
# To make a dialog button show a sub-menu, use following as return value of the button:
#* MENU_<name>
#* Replace "<name>" with the actual name of the added menu (without parenthesis).
# Repeat (2) and (3) for all menus you want
# To show a menu, use:
#* [[llMessageLinked]](LINK_THIS, lnkMenuShow, "MenuName", [[llGetOwner]]());
#* Where "MenuName" is the name of menu to show. To show last-used menu, leave this field empty.
# Dialog will return value the same way as usual call to Nargus Dialog Module script.


==Sample Scripts==
==Sample Scripts==
Line 28: Line 39:


===Basic Usage Examples===
===Basic Usage Examples===
====Basic Dialog Usage====
====Dialog Usage====


<lsl>
<lsl>
Line 113: Line 124:
</lsl>
</lsl>


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


Line 207: Line 218:
     }
     }
}
}
</lsl>
{{LSLC|Library|Dialog Control}}

Revision as of 04:48, 15 October 2009

Functions List

Basic Dialog Functionalities

  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);
  2. To display current dialog again:
    • dialogReshow();
  3. To cancel current dialog; Currently displayed dialog will give no response when clicked.
    • dialogCancel();

Menus Control

  1. Initialize menus control using:
  2. Using "packDialogMessage" function to generate new menu, and add it to menus list:
    • llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(....), "MenuName");
    • While "MenuName" is the same of this menu, ie: MainMenu
  3. To make a dialog button show a sub-menu, use following as return value of the button:
    • MENU_<name>
    • Replace "<name>" with the actual name of the added menu (without parenthesis).
  4. Repeat (2) and (3) for all menus you want
  5. To show a menu, use:
    • llMessageLinked(LINK_THIS, lnkMenuShow, "MenuName", llGetOwner());
    • Where "MenuName" is the name of menu to show. To show last-used menu, leave this field empty.
  6. Dialog will return value the same way as usual call to Nargus Dialog Module script.

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

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>

Menus Usage

<lsl> // READ ME: // To see this sample in action; // Put "Nargus Dialog Control v1.80" 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));
   }

} </lsl>