User:Thraxis Epsilon/control ui

From Second Life Wiki
Jump to navigation Jump to search

Purpose

This script replaces all the button scripts for controlling the LSL Test Harness it requires a modified controller.controller script.

Even though this is a test harness I felt it should follow a "best practice" of reducing unnecessary script usage when possible.

Usage

Create a root prim and place the controller_ui and controller.controller scripts inside it.

Add 17 "button" prims and name them as follows:

TestSelectedButton::unit
TestSelectedButton::group
SetTestSelected::ALL
SetReportType::STATS
SetReportType::VERBOSE
SetReportType::QUIET
SetReportType::NORMAL
ReportMethodButton::HTTP
ReportMethodButton::EMAIL
ReportMethodButton::CHAT
system::ActivateTest
system::ActivateReport
system::ActivateRegistration
system::BigRed
config::reset
config::controlChannelButton
config::broadcastChannelButton

SetReportType, ReportMethod and the SetTestSelected,TestSelectedButton tagged buttons work as radio groups. Only one item can be active at a time in the set. All others act as single buttons.

What next?

Add texture support for the buttons for readable labels. Ensure 100% functionality as a replacement for buttons. Allow for expandability with custom buttons.

<lsl> //******************************************************************** // Script Name: controller_ui.lsl // Purpose: // This is the User Interface control script for the LSL // TestHarness //******************************************************************** // GLOBAL VARIABLES //********************************************************************

integer toAllChannel = -255; // general channel - linked message integer fromAllChannel = -254;

// Lists list btnReportMethod; list btnReportType; list btnTestSelected; list btnAll;

string btnRegister; string btnReport; string btnTest; string btnBigRed;

//****************************************************************** // Build List of Buttons and Button Groups //****************************************************************** button_init() {

   integer x=1;
   integer max = llGetNumberOfPrims();
   for (;x<max+1;++x)
   {
       btnAll = (btnAll = []) + btnAll + llGetLinkName(x);
       if(llSubStringIndex(llGetLinkName(x), "ReportMethodButton::") != -1)
       {
           btnReportMethod = (btnReportMethod= []) + btnReportMethod + [x];
       }
       else if(llSubStringIndex(llGetLinkName(x), "SetReportType::") != -1)
       {
           btnReportType = (btnReportType= []) + btnReportType + [x];
       }
       else if ((llSubStringIndex(llGetLinkName(x), "SetTestSelected::") != -1) || (llSubStringIndex(llGetLinkName(x), "TestSelectedButton::") != -1))
       {
           btnTestSelected = (btnTestSelected= []) + btnTestSelected + [x];
       }
       else if(llSubStringIndex(llGetLinkName(x), "system::") != -1)
       {
           string button = llDeleteSubString( llGetLinkName(x) , 0, llSubStringIndex(llGetLinkName(x) , "::") + 1);
           if (button == "ActivateRegistration")
           {
               btnRegister = "1::"+(string)x;
               llSetLinkAlpha(x, 1.0, ALL_SIDES);                
           }
           else if (button == "ActivateReport")
           {
               btnReport = "0::"+(string)x;
               llSetLinkAlpha(x, 0.0, ALL_SIDES);                
           }
           else if (button == "ActivateTest")
           {
               btnTest = "0::"+(string)x;
               llSetLinkAlpha(x, 0.0, ALL_SIDES);
           }
           else if (button == "BigRed")
           {
               btnBigRed = "0::"+(string)x;
               llSetLinkAlpha(x, 1.0, ALL_SIDES);                
               llSetLinkColor(x, <255,0,0>, ALL_SIDES);
           }            
       }
   }    

}


//******************************************************************** // DEFAULT STATE //******************************************************************** default {

   state_entry()
   {
       button_init();
   }
   
   link_message(integer sender_number, integer number, string message, key id)
   {
       //if link message is on the correct channel
       if(number == fromAllChannel)
       {
           if(llSubStringIndex( message, "ActivateRegistration") != -1)
           {
               //Big Red Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),1), 0.0, ALL_SIDES);                
           }
           if(llSubStringIndex( message, "RegistrationComplete") != -1)
           {
               //Big Red Button    
               if((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),0)== 1)
               {
                      llMessageLinked(LINK_THIS, toAllChannel, "ActivateTest", NULL_KEY); 
               }
               //Register Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), 0.0, ALL_SIDES);
               btnRegister= "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);    
           }
           if(llSubStringIndex( message, "TestComplete") != -1)
           {
               //Big Red Button
                 if((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),0)== 1)
                 {
                   llMessageLinked(LINK_THIS, toAllChannel, "ActivateReport", NULL_KEY);
               }
               //Register Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), 0.0, ALL_SIDES);
               btnRegister= "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);    
           }
           if(llSubStringIndex( message, "ReportComplete") != -1)
           {
               //Big Red Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),1), 1.0, ALL_SIDES);                
               llSetLinkColor((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),1), <255,0,0>, ALL_SIDES);
               //Register Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), 1.0, ALL_SIDES);
               btnRegister= "1::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);                    
           }
           if(llSubStringIndex( message, "ActivateReport") != -1)
           {
               //Register Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), 0.0, ALL_SIDES);
               btnRegister= "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);            
           }
           if(llSubStringIndex( message, "ActivateTest") != -1)
           {
               //Register Button
               llSetLinkAlpha((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), 0.0, ALL_SIDES);
               btnRegister= "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);                
           }
           
           
           if( message == "reset" )
           {
             llResetScript();    
           }
           
       }
       
   } //end of link message
   touch_start(integer total_number)
   {
       integer link = llDetectedLinkNumber(0);
       string button = llGetLinkName(link);
       string cmdGroup = llDeleteSubString( button , llSubStringIndex(button , "::"), llStringLength(button) - 1);
       if (cmdGroup == "ReportMethodButton")
       {
           integer x = 0;
           for(;x<llGetListLength(btnReportMethod);++x)
           {
               llSetLinkColor((integer)llList2String(btnReportMethod,x),<0,0,0>,ALL_SIDES);
           }
           llSetLinkColor(link,<255,255,255>,ALL_SIDES);
           llMessageLinked(LINK_THIS, toAllChannel, button, NULL_KEY);
       }
       else if (cmdGroup == "SetReportType")
       {
           integer x = 0;
           for(;x<llGetListLength(btnReportType);++x)
           {
               llSetLinkColor((integer)llList2String(btnReportType ,x),<0,0,0>,ALL_SIDES);
           }
           llSetLinkColor(link,<255,255,255>,ALL_SIDES);
           llMessageLinked(LINK_THIS, toAllChannel, button, NULL_KEY);            
       }
       else if ((cmdGroup == "SetTestSelected") || (cmdGroup == "TestSelectedButton"))
       {
           integer x = 0;
           for(;x<llGetListLength(btnTestSelected);++x)
           {
               llSetLinkColor((integer)llList2String(btnTestSelected,x),<0,0,0>,ALL_SIDES);
           }
           llSetLinkColor(link,<255,255,255>,ALL_SIDES);
           llMessageLinked(LINK_THIS, toAllChannel, button, NULL_KEY);        
       }
       else if (cmdGroup == "config")
       {
           llMessageLinked(LINK_THIS, toAllChannel, llDeleteSubString( button, 0, llSubStringIndex(button, "::") + 1), NULL_KEY);            
       }
       else if (cmdGroup == "system")
       {
           string btnSystem = llDeleteSubString( button , 0, llSubStringIndex(button , "::") + 1);
           if (btnSystem == "ActivateRegistration")
           {
               if((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),0)== 1)
               {
                   llMessageLinked(LINK_THIS, toAllChannel, btnSystem, NULL_KEY);
                   btnRegister= "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnRegister, "::") + 1);
                   llSetLinkColor((integer)llList2String(llParseString2List(btnRegister,["::"],[]),1), <255,255,255>, ALL_SIDES);
               }
           }
           else if (btnSystem == "ActivateReport")
           {
               if((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),0)== 1)
               {
                   llMessageLinked(LINK_THIS, toAllChannel, btnSystem, NULL_KEY);
                   btnReport = "0::"  + llDeleteSubString( btnReport , 0, llSubStringIndex(btnReport , "::") + 1);
                   llSetLinkColor((integer)llList2String(llParseString2List(btnReport ,["::"],[]),1), <255,255,255>, ALL_SIDES);
               }            
           }
           else if (btnSystem == "ActivateTest")
           {
               if((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),0)== 1)
               {
                   llMessageLinked(LINK_THIS, toAllChannel, btnSystem, NULL_KEY);
                   btnTest = "0::"  + llDeleteSubString( btnRegister, 0, llSubStringIndex(btnTest , "::") + 1);
                   llSetLinkColor((integer)llList2String(llParseString2List(btnTest ,["::"],[]),1), <255,255,255>, ALL_SIDES);
               }
           }
           else if (btnSystem == "BigRed")
           {
               llMessageLinked(LINK_THIS, toAllChannel, "ActivateRegistration", NULL_KEY);
               btnBigRed = "1::"  + llDeleteSubString( btnBigRed , 0, llSubStringIndex(btnBigRed, "::") + 1);
               llSetLinkColor((integer)llList2String(llParseString2List(btnBigRed,["::"],[]),1), <255,255,255>, ALL_SIDES);
           }        
       }        
   }

} </lsl>