Advertisement
Guest User

List2Dialog

a guest
May 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////llList2Dialog() Menu generator script ///////////////////
  2. // Script by RumbleR Boa
  3.  
  4. //Script is in NO RUNNING mode. Please mark box Running in lower left corner.
  5.  
  6. //This script is full perm. You may sell it as part of your products, but you MUST NOT sell it as individual script!
  7.  
  8.  
  9.  
  10.  
  11. //This list "MainMenu" is a system list, and its name must not be changed!
  12. //All other lists are flexible, and represent user created content
  13. //In this list you will write options that will appear in the Main menu
  14.  
  15. list MainMenu = [
  16. "Colors",
  17. "Textures",
  18. "Sounds"
  19. ];
  20.  
  21. //List "Colors" is here only as an example, it can be called how ever you want
  22. //You can put as many lists and options as you want, but you need to take care also about script's memory which is not unlimited
  23. list Colors = [
  24. "Red",
  25. "Green",
  26. "Blue",
  27. "White"
  28. ];
  29.  
  30. //List "Textures" is here only as an example, it can be called how ever you want
  31. //You can put as many lists and options as you want, but you need to take care also about script's memory which is not unlimited
  32. list Textures = [
  33. "Brick",
  34. "Rock",
  35. "Grass"
  36. ];
  37.  
  38. //List "Sounds" is here only as an example, it can be called how ever you want
  39. //You can put as many lists and options as you want, but you need to take care also about script's memory which is not unlimited
  40. list Sounds = [
  41. "Comedy",
  42. "Clap",
  43. "Whistle"
  44. ];
  45.  
  46.  
  47. list ActiveMenu; //Every time when we generate some menu or submenu, all the current menu options will be stored in this list
  48.                  //We can think about this as RAM and Hard Disc. ActiveMenu is Ram where we operate with options which we loaded from
  49.                  //other lists (Hard Disc)
  50.  
  51. integer NumberOfButtonsInTheMenu = 9; //This is the number of option buttons that will appear in the generated Dialog menu.
  52.                                       //Do not put number less than 2 and greater than 9!!!
  53.  
  54. list ShortMenuForButtons = [];          // in this list we will store the button names for the current Dialog menu
  55. integer NumberOfCurrentDialogMenu = 0;  // this is the "Serial" number of current Dialog menu
  56. integer NumberOfItemsInTheContent = 0;  // here we will store how many options there are in the ActiveMenu list
  57. integer MaximumNumberOfMenus = 0;       // in this variable we will see what is the maximum possible number of Dialog menus
  58.                                         // depending on the number of items in the ActiveMenu
  59. string ListOfItemNamesInStringForm = ""; // here we store the names of the files that will appear in the curent Dialog menu
  60. integer i = 0;                          //variable that we will use for a loop counter
  61. key PersonThatClicked;                  // Clicker :)
  62. integer channel;                        // channel for communication between Clicker and our Script
  63.  
  64.  
  65.  
  66. list order_buttons(list buttons)
  67. { // Code that will sort our -list ShortMenuForButtons- in the best "human" readable order
  68.     return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4)
  69.          + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
  70. }
  71.  
  72.  
  73.  
  74. generateMenu()  //Every time when we click on some sub menu, we need to generate new menu based on some params...
  75. {
  76.   NumberOfItemsInTheContent = llGetListLength(ActiveMenu); // we ask how many items are in the new (sub)menu
  77.        
  78.   MaximumNumberOfMenus = llFloor(NumberOfItemsInTheContent/NumberOfButtonsInTheMenu); // here by default we devide with 9 because we want 9 generated buttons for objects (remember that we put number 9 as default value: integer NumberOfButtonsInTheMenu = 9), but you can change this value how it suits you
  79.        
  80.        
  81.        
  82.         // This line here can look strange, but its purpose is very important. In the previous line, when we devided
  83.         // the NumberOfItemsInTheContent with NumberOfButtonsInTheMenu, we set llFloor in order to get the Lower value of integer
  84.         // number, BUT if it happens that during devision we have 0 as remaing decimal part after the "." we will have
  85.         // one "ghost" dialog menu that will not show any Item buttons. With this code we actually protect our selves
  86.         // from posible "bug".
  87.         if (NumberOfItemsInTheContent % NumberOfButtonsInTheMenu == 0) MaximumNumberOfMenus--;
  88.  
  89.        
  90.                        
  91.         NumberOfCurrentDialogMenu = 0; //we reset this variable because we want to start every new menu from the beggining
  92.                                        //(from first option)  
  93. }
  94.  
  95.  
  96.  
  97. showMenu() // Code that will create the menu
  98. {
  99.  
  100.     ShortMenuForButtons = [];         // Reset the starting variables to create a new menu
  101.     ListOfItemNamesInStringForm = ""; // Reset the starting variables to create a new menu
  102.  
  103.     i=0;
  104.     do {
  105.         // This part is IMPORTANT! Here we ask if "i" NAME for "i" menu option exists, and if it
  106.         // exists make button for that option, and put name in the -string ListOfItemNamesInStringForm-
  107.         if (llList2String(ActiveMenu, NumberOfCurrentDialogMenu*NumberOfButtonsInTheMenu+i) != "")
  108.         {
  109.             //here we generate buttons
  110.             ShortMenuForButtons += llList2String(ActiveMenu, NumberOfCurrentDialogMenu*NumberOfButtonsInTheMenu+i);
  111.            
  112.             //here we add name of the "i" item in the Text that will appear in the Dialog menu
  113.             //if you don't want this, you can simply deactivate this line. It is not neccessary in the rest of the code
  114.             ListOfItemNamesInStringForm += "\n" + (string)(NumberOfCurrentDialogMenu*NumberOfButtonsInTheMenu+i) + ") " +
  115.                         llList2String(ActiveMenu, NumberOfCurrentDialogMenu*NumberOfButtonsInTheMenu+i);
  116.         }
  117.     } while (i++ < NumberOfButtonsInTheMenu-1); //by default we want 9 buttons, but because we also count Zero we have to decrease for 1 (NumberOfButtonsInTheMenu-1 = 8)
  118.  
  119.     ShortMenuForButtons += "<---"; //We add arrow for left in our menu
  120.     ShortMenuForButtons += "MAIN MENU"; // We put "MAIN MENU" button so that we can easier go to first menu
  121.     ShortMenuForButtons += "--->"; //We add arrow for right in our menu
  122.  
  123.  
  124.     // Here we generate the ActiveMenu. We will add +1 on counters for NumberOfCurrentDialogMenu and MaximumNumberOfMenus
  125.     // to have better written results (i.e. Good -> Menu No.1/1 ; Bad -> Menu No.0/0)
  126.     llDialog(PersonThatClicked,
  127.              "\nPlease select item.  Menu No." + (string)( NumberOfCurrentDialogMenu+1) + "/" +
  128.              (string)(MaximumNumberOfMenus+1) + "\n"+ListOfItemNamesInStringForm,
  129.              order_buttons(ShortMenuForButtons),
  130.              channel);
  131. }
  132.  
  133.  
  134.  
  135.  
  136. default
  137. {
  138.     state_entry()
  139.     {
  140.  
  141.         channel = (integer)(llFrand(-1000000000.0) - 1000000000.0); //we generate random channel...
  142.         llListen(channel,"", "","");        //...and we start to listen it
  143.     }
  144.    
  145.     on_rez(integer start_param)
  146.     {
  147.         llResetScript();  
  148.     }
  149.    
  150.    
  151.    
  152.    
  153.    
  154.  
  155.  
  156.  
  157.     touch_start(integer total_number)
  158.     {
  159.         PersonThatClicked = llDetectedKey(0); //We take the UUID of person that clicked
  160.        
  161.         ActiveMenu = MainMenu; //We say that current active menu will be main menu
  162.         generateMenu(); //We process the params...
  163.         showMenu();     //...and we generate the menu
  164.     }
  165.    
  166.    
  167.    
  168.    
  169.     listen(integer _chan, string _name, key _id, string _option)
  170.     {
  171.              
  172.         //IMPORTANT!!! First we will code user interface part, and then at the end of the listening event we will take care of activities based on clicking the each Menu button
  173.  
  174.  
  175.         if (_option == "--->") // If arrow for Right is clicked...
  176.         {
  177.             if (NumberOfCurrentDialogMenu<MaximumNumberOfMenus) {NumberOfCurrentDialogMenu++; } else {NumberOfCurrentDialogMenu = 0;}
  178.             //...we ask if the current menu number is lower than number of total possible menus.
  179.             //If it is: ADD 1, and if it is not: RESET to ZERO
  180.             showMenu();
  181.         }
  182.        
  183.        
  184.        
  185.        
  186.         if (_option == "<---")  //If arrow for Left is clicked...
  187.         {
  188.      
  189.         if (NumberOfCurrentDialogMenu>0) {--NumberOfCurrentDialogMenu; } else {NumberOfCurrentDialogMenu =  MaximumNumberOfMenus;}
  190.         //...we ask if the current menu number is bigger than ZERO.
  191.         //If it is: SUBTRACT 1, and if it is not: SET to maximum number of menus
  192.  
  193.         showMenu();
  194.            
  195.         }
  196.        
  197.        
  198.          //As you can notice below, calling every (sub)menu is always done via 3 same operations
  199.         // a) ActiveMenu = name of submenu list;
  200.         // b) generateMenu();
  201.         // c) showMenu();  
  202.        
  203.         //Only difference between menus is in using IF function,
  204.         //...to check if name of a clicked button is the same as name of some submenu
  205.        
  206.        
  207.         if (_option == "Colors") //Here we ask if button that was clicked suits to name of our submenu "Colors"
  208.         {                         //...and if it does then we need to "copy" all items from menu/list  Colors to list ActiveMenu
  209.             ActiveMenu=Colors;
  210.             generateMenu();       //Since ActiveMenu list is now changed, we need to generate menu based on some params...
  211.             showMenu();           //...and to "shoot" menu to person who clicked the button
  212.         }
  213.        
  214.         if (_option == "Textures") //Here we ask if button that was clicked suits to name of our submenu "Textures"
  215.         {                         //...and if it does then we need to "copy" all items from menu/list  Textures to list ActiveMenu
  216.             ActiveMenu=Textures;
  217.             generateMenu();       //Since ActiveMenu list is now changed, we need to generate menu based on some params...
  218.             showMenu();           //...and to "shoot" menu to person who clicked the button
  219.         }
  220.        
  221.         if (_option == "Sounds") //Here we ask if button that was clicked suits to name of our submenu "Sounds"
  222.         {                         //...and if it does then we need to "copy" all items from menu/list  Sounds to list ActiveMenu
  223.             ActiveMenu=Sounds;
  224.             generateMenu();       //Since ActiveMenu list is now changed, we need to generate menu based on some params...
  225.             showMenu();           //...and to "shoot" menu to person who clicked the button
  226.         }
  227.        
  228.         if (_option == "MAIN MENU") //If button for Main menu was clicked, then we "shoot" the main menu to person who clicked
  229.         {
  230.           ActiveMenu = MainMenu;
  231.           generateMenu();
  232.           showMenu();  
  233.         }
  234.        
  235.        
  236.        //Except calling the submenus we can also execute some functions after the certain button was pressed
  237.        //To do this, we don't need to copy any list to ActiveMenu
  238.        //We will just ask "IF something"..."THEN do something"
  239.        
  240.        //Lets pick some option from list "Colors"
  241.        //For example "Red"
  242.        
  243.        if (_option == "Red")
  244.        {
  245.         llSetColor(<1,0,0>,ALL_SIDES); //As you can notice, here we have only one operation.
  246.                                        //To test this, click the prim, click the button "Colors", and then click the button "Red"
  247.                                        //...and you will see that prim changed color to red
  248.                                        
  249.          showMenu();
  250.        }
  251.        
  252.        if (_option == "Green")
  253.        {
  254.         llSetColor(<0,1,0>,ALL_SIDES);
  255.         showMenu();
  256.        }
  257.      
  258.        if (_option == "Blue")
  259.        {
  260.         llSetColor(<0,0,1>,ALL_SIDES);
  261.         showMenu();
  262.        }
  263.        
  264.        if (_option == "White")
  265.        {
  266.         llSetColor(<1,1,1>,ALL_SIDES);
  267.         showMenu();
  268.        }
  269.        
  270.      
  271.      
  272.        if (_option == "Brick")
  273.        {
  274.         llSetTexture("75c0ae9b-bd5a-12f7-bfce-311271475122",ALL_SIDES);
  275.         showMenu();
  276.        }
  277.        
  278.        if (_option == "Rock")
  279.        {
  280.         llSetTexture("ebb6d25a-7192-a65c-7a39-903468df57ca",ALL_SIDES);
  281.         showMenu();
  282.        }
  283.        
  284.        if (_option == "Grass")
  285.        {
  286.         llSetTexture("28b33b68-5fd2-8ffc-8e13-19cdfae50117",ALL_SIDES);
  287.         showMenu();
  288.        }
  289.        
  290.        
  291.        
  292.         if (_option == "Comedy")
  293.        {
  294.         llPlaySound("8c10b6f1-b659-03c5-deb3-9459040de4cf",1);
  295.         showMenu();
  296.        }
  297.        
  298.         if (_option == "Clap")
  299.        {
  300.         llPlaySound("6089e539-2b45-67b9-0c9f-8cfac82465a8",1);
  301.         showMenu();
  302.        }
  303.  
  304.         if (_option == "Whistle")
  305.        {
  306.         llPlaySound("977dac77-7f0b-d022-74db-62d1f6862844",1);
  307.         showMenu();
  308.        }
  309.        
  310.     }
  311.    
  312.    
  313.    
  314.    
  315.    
  316.    
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement