Difference between revisions of "Dialog Control"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
# 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);
# Standard dialog with an input box
#* '''dialogTextbox'''(key id, string message);
# To recall last dialog (only work if a dialog has been called before):
# To recall last dialog (only work if a dialog has been called before):
#* '''dialogReshow'''();
#* '''dialogReshow'''();
Line 41: Line 43:
====Dialog Usage====
====Dialog Usage====


<lsl>
<source lang="lsl2">
// READ ME:
// READ ME:
// To see this sample in action;
// To see this sample in action;
Line 49: Line 51:
// Dialog constants
// Dialog constants
integer lnkDialog = 14001;
integer lnkDialog = 14001;
integer lnkDialogTextbox = 14007;
integer lnkDialogResponse = 14002;
integer lnkDialogResponse = 14002;
integer lnkDialogTimeOut = 14003;
integer lnkDialogTimeOut = 14003;
Line 80: Line 83:
dialog(key id, string message, list buttons, list returns){
dialog(key id, string message, list buttons, list returns){
     llMessageLinked(LINK_THIS, lnkDialog, packDialogMessage(message, buttons, returns), id);
     llMessageLinked(LINK_THIS, lnkDialog, packDialogMessage(message, buttons, returns), id);
}


dialogTextbox(key id, string message){
    llMessageLinked(LINK_THIS, lnkDialogTextbox, message + seperator + (string)dialogTimeOut, id);
}
// ********** END DIALOG FUNCTIONS **********
// ********** END DIALOG FUNCTIONS **********


Line 113: Line 120:
     }
     }
}
}
</lsl>
</source>


====Menus Usage====
====Menus Usage====
<lsl>
<source lang="lsl2">
// READ ME:
// READ ME:
// To see this sample in action;
// To see this sample in action;
Line 124: Line 131:
// Dialog constants
// Dialog constants
integer lnkDialog = 14001;
integer lnkDialog = 14001;
integer lnkDialogNotify = 14004;
integer lnkDialogResponse = 14002;
integer lnkDialogResponse = 14002;
integer lnkDialogTimeOut = 14003;
integer lnkDialogTimeOut = 14003;
Line 153: Line 159:
     llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
     llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
     llSleep(1);
     llSleep(1);
}
dialogNotify(key id, string message){
    list rows;
   
    llMessageLinked(LINK_THIS, lnkDialogNotify,
        message + seperator + (string)dialogTimeOut + seperator,
        id);
}
}
// ********** END DIALOG FUNCTIONS **********
// ********** END DIALOG FUNCTIONS **********
Line 198: Line 196:
     link_message(integer sender_num, integer num, string str, key id){
     link_message(integer sender_num, integer num, string str, key id){
         if(num == lnkDialogTimeOut){
         if(num == lnkDialogTimeOut){
             dialogNotify(llGetOwner(), "Menu time-out. Please try again.");
             llOwnerSay("Menu time-out. Please try again.");
            state default;
         }else if(num == lnkDialogResponse){
         }else if(num == lnkDialogResponse){
             llWhisper(0, str);
             llWhisper(0, str);
Line 209: Line 206:
     }
     }
}
}
</lsl>
</source>


{{LSLC|Library|Dialog Control}}
{{LSLC|Library|Dialog Control}}

Latest revision as of 18:55, 24 January 2015

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. Standard dialog with an input box
    • dialogTextbox(key id, string message);
  3. To recall last dialog (only work if a dialog has been called before):
    • dialogReshow();
  4. 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 name 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

// 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 lnkDialogTextbox = 14007;
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);
}

dialogTextbox(key id, string message){
    llMessageLinked(LINK_THIS, lnkDialogTextbox, message + seperator + (string)dialogTimeOut, 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){
            llOwnerSay("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" ]
        );
    }
}

Menus Usage

// 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 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);
}
// ********** 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){
            llOwnerSay("Menu time-out. Please try again.");
        }else if(num == lnkDialogResponse){
            llWhisper(0, str);
        }
    }
    
    touch_start(integer num_detected){
        llMessageLinked(LINK_THIS, lnkMenuShow, "", llDetectedOwner(0));
    }
}