Difference between revisions of "OnTouchSelectTexture"

From Second Life Wiki
Jump to navigation Jump to search
(New page: '''IMPORTANT NOTE:''' This menus control REQUIRED Nargus Dialog Control script and Nargus Menus Control script. You MUST have all three scripts ...)
 
 
Line 1: Line 1:
'''IMPORTANT NOTE:''' This menus control REQUIRED [[Dialog Control|Nargus Dialog Control script]] and [[Dialog Menus Control|Nargus Menus Control script]]. You MUST have all three scripts in the same prim for it to work.
'''IMPORTANT NOTE:''' This menus control REQUIRED [[Dialog Control|Nargus Dialog Control script]]. You MUST have all both the script and this one in the same prim for it to work.
 
==Read Me==
# These scripts were written by Tiyuk Quellmalz, with much help from Nargus Asturias' scripts from the Second Life Wiki: [[Dialog Menus Control]]
# The license is Public Domain because Nargus Asturias did not specify a license, and I both used and modified his code. If you extend this code, please credit both Nargus Asturias and Tiyuk Quellmalz for the work they have done thus far.
# Functionality: Drop this set of scripts (make sure you get all three) into a prim, along with one or more textures. All sides of the prim will have their texture changed to the name of the texture you select from the menu that appears when you touch the object.
# Bugs: Sometimes, just after an inventory refresh, the menu won't appear when you touch it. Wait a few seconds and try again.
# To-Do: Allow modifying the texture on only specific sides of the object. I don't really have a use case for this yet, so it's not implemented.


==Scripts==
==Scripts==
OnTouchSelectTexture.lsl
OnTouchSelectTexture.lsl
<lsl>
<lsl>
// READ ME:
// ********** DIALOG FUNCTIONS **********
// Put "NargusBase" and "NargusDMC" along with this script
// in a prim and touch.
//Credits go to Nargus Asturias for the core menu code.
//Texture selection code added by Tiyuk Quellmalz.
//This code is in the Public Domain.
 
// Dialog constants
// Dialog constants
integer lnkDialog = 14001;
integer lnkDialog = 14001;
Line 33: Line 20:
string seperator = "||";
string seperator = "||";
integer dialogTimeOut = 0;
integer dialogTimeOut = 0;
// ********** END DIALOG FUNCTIONS **********
// ********** DIALOG FUNCTIONS **********
 
string packDialogMessage(string message, list buttons, list returns){
string texturesDialog;
     string packed_message = message + seperator + (string)dialogTimeOut;
 
initTextures(){
// Please me reminded that Nargus Dialog script autometicly add Back/Next buttons for you.
// Optimised dialog generator script. Much more memory efficient than usage of Dialog+Menus control function
   
    llOwnerSay("Inventory change detected; re-initializing...");
   
     texturesDialog = "Click BACK/NEXT to change page.\n" +
        "Click a texture button to choose." +
        seperator + (string)dialogTimeOut;
   
    integer count = llGetInventoryNumber(INVENTORY_TEXTURE);
     integer i;
     integer i;
    integer count = llGetListLength(buttons);
     for(; i<count; ++i){
     for(i=0; i<count; i++) packed_message += seperator + llList2String(buttons, i) + seperator + llList2String(returns, i);
        string name = llGetInventoryName(INVENTORY_TEXTURE, i);
        texturesDialog += seperator + name + seperator + llGetSubString(name, 0, 15);
     return packed_message;
     }
}
    texturesDialog += seperator + "CLOSE" + seperator;
 
dialogReshow(){llMessageLinked(LINK_THIS, lnkDialogReshow, "", NULL_KEY);}
     llOwnerSay("Initializing completed.");
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{
default{
     state_entry(){
     state_entry(){
         integer numtexs = llGetInventoryNumber(INVENTORY_TEXTURE);
         initTextures();
        integer i;
    }
        integer first_list = TRUE;
   
        integer depth = 0;
    changed(integer changes){
        list texture_names;
        if(changes & CHANGED_INVENTORY) initTextures();
       
        llMessageLinked(LINK_THIS, lnkMenuClear, "", NULL_KEY);
       
        for(i = 0; i < numtexs; i++)
        {
            string curr = llGetSubString(llGetInventoryName(INVENTORY_TEXTURE, i), 0, 23);
            integer len = llGetListLength(texture_names);
            integer op_a = (first_list == FALSE && len == 10);
            integer op_b = (first_list == TRUE && len == 11);
            integer op_c = i == (numtexs - 1);
            if( op_a || op_b || op_c)
            {
                integer back_button;
                integer next_button;
                back_button = FALSE;
                next_button = FALSE;
               
                if(op_c && !(op_a || op_b))
                    texture_names += [ curr ];
                if(first_list == FALSE)
                {
                    texture_names = llListInsertList(texture_names, [ "Back" ], 0);
                    back_button = TRUE;
                }
                else
                {
                    first_list = FALSE;
                }
               
                if(i != (numtexs - 1)) //There are more menus to make
                {
                    texture_names = llListInsertList(texture_names, [ "Next" ], 2);
                    next_button = TRUE;
                }
                   
                list call_names = texture_names;
               
                if(back_button)
                {
                    call_names = llListReplaceList(call_names, [ "MENU_Menu" + ((string) (depth - 1)) ], 0, 0);
                }
               
                if(next_button)
                {
                    call_names = llListReplaceList(call_names, [ "MENU_Menu" + ((string) (depth + 1)) ], 2, 2); 
                }
           
                   
                llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
                    "[ Group " + (string) depth + " ]\n" +
                    "Select Texture",
                    texture_names,
                    call_names
                ), "Menu" + (string) depth);
                texture_names = [ curr ];
                depth++;
            }
            else
            {
                texture_names += [ curr ];
            }
        }
//      llSetText("Touch me to show menu", <1,1,1>, 1);
        llSay(0, "Initialization complete.");
     }
     }
   
   
     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 == lnkDialogResponse){
            dialogNotify(llGetOwner(), "Menu time-out. Please try again.");
             if(llGetInventoryType(str) == INVENTORY_TEXTURE) llSetTexture(str, ALL_SIDES);
            state default;
        }else if(num == lnkDialogResponse){
             if(llGetSubString(str, 0, 8) != "MENU_Menu")
            {
                llSetTexture(str, ALL_SIDES);              
            }
         }
         }
     }
     }
   
   
     touch_start(integer num_detected){
     touch_start(integer num_detected){
         llMessageLinked(LINK_THIS, lnkMenuShow, "", llDetectedOwner(0));
         llMessageLinked(LINK_THIS, lnkDialog, texturesDialog, llDetectedOwner(0));
    }
   
    on_rez(integer i)
    {
        llResetScript(); 
    }
   
    changed(integer change)
    {
        if(change == CHANGED_INVENTORY)
        {
            llSay(0, "Inventory change detected; re-initializing...");
            llResetScript();   
        } 
     }
     }
}
}
</lsl>
</lsl>

Latest revision as of 19:55, 6 January 2009

IMPORTANT NOTE: This menus control REQUIRED Nargus Dialog Control script. You MUST have all both the script and this one in the same prim for it to work.

Scripts

OnTouchSelectTexture.lsl <lsl> // ********** DIALOG FUNCTIONS ********** // 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; // ********** END DIALOG FUNCTIONS **********

string texturesDialog;

initTextures(){ // Please me reminded that Nargus Dialog script autometicly add Back/Next buttons for you. // Optimised dialog generator script. Much more memory efficient than usage of Dialog+Menus control function

   llOwnerSay("Inventory change detected; re-initializing...");
   
   texturesDialog = "Click BACK/NEXT to change page.\n" +
       "Click a texture button to choose." +
       seperator + (string)dialogTimeOut;
   
   integer count = llGetInventoryNumber(INVENTORY_TEXTURE);
   integer i;
   for(; i<count; ++i){
       string name = llGetInventoryName(INVENTORY_TEXTURE, i);
       texturesDialog += seperator + name + seperator + llGetSubString(name, 0, 15);
   }
   texturesDialog += seperator + "CLOSE" + seperator;
   llOwnerSay("Initializing completed.");

}

default{

   state_entry(){
       initTextures();
   }
   
   changed(integer changes){
       if(changes & CHANGED_INVENTORY) initTextures();
   }

   link_message(integer sender_num, integer num, string str, key id){
       if(num == lnkDialogResponse){
           if(llGetInventoryType(str) == INVENTORY_TEXTURE) llSetTexture(str, ALL_SIDES);
       }
   }

   touch_start(integer num_detected){
       llMessageLinked(LINK_THIS, lnkDialog, texturesDialog, llDetectedOwner(0));
   }

} </lsl>