Advertisement
salahzar

salxycell (to be used with CB110 Edmondo 2014)

Apr 11th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////
  2. // XyText v1.2 Script (5 Face, Single Texture)
  3. // Simplified Esperanto version
  4. //
  5. // Written by Xylor Baysklef
  6. //
  7. // Modified by Kermitt Quirk 19/01/2006
  8. // To add support for 5 face prim instead of 3
  9. //
  10. // Modified by Salahzar Stenvaag to show International UTF8 chars
  11. // May 2009
  12. // With easily personalization for each language
  13. // Nov 2012: adapted to fastprim and opensim
  14. //
  15. ////////////////////////////////////////////
  16. // Name this script SALXYCELL-1-5-8
  17. // meaning it handles channels from 1 up to 5 included, and each line is done with 8 cells
  18. // this makes it easy to split scripts in 2-3 so to make it load much fast
  19. // This script handles messages on channels
  20.  
  21. /////////////// CONSTANTS ///////////////////
  22.  
  23. debug(string x) {}
  24. //debug(string x) { llMessageLinked(LINK_SET,-2,llGetTimestamp()+" "+llGetScriptName()+":"+x,NULL_KEY); }
  25. //#define debug(x)
  26.  
  27. // This is an extended character escape sequence.
  28. string  ESCAPE_SEQUENCE = "\\e";
  29. string HELLO="Alle falde del\nKilimangiaro";
  30.  
  31. // This is used to get an index for the extended character.
  32. string  EXTENDED_INDEX  = "12345";
  33.  
  34. // Face numbers.
  35. integer FACE_1          = 3;
  36. integer FACE_2          = 7;
  37. integer FACE_3          = 4;
  38. integer FACE_4          = 6;
  39. integer FACE_5          = 1;
  40.  
  41.  
  42. // number of characters for each "line" in texture
  43. integer knum=10;                                  
  44.      
  45.  
  46. // adjusting offset + multipliers for columns and rows
  47. vector kcol=<-0.44,0.10,0>; // offset + multiplier for cols
  48. //vector krow=<0.422,-0.05,0>; // offset + multiplier for rows
  49. vector krow=<0.421,-0.05,0>; // offset + multiplier for rows
  50.  
  51.  
  52. // texture resizing for each face
  53. vector kmul1=<0.15, 0.05, 0>; // multiplicator for 1st char
  54. vector kmul2=<0.06, 0.05, 0>; // multiplicator for 2nd char
  55. vector kmul3=<-0.89, 0.05, 0>; // central char
  56. vector kmul4=<0.06, 0.05, 0>;
  57. vector kmul5=<0.15, 0.05, 0>;
  58.  
  59. // offset for each face
  60. vector koff1=<0.035, 0, 0>;
  61. vector koff2=<-0.012,0,0>;
  62. vector koff3=<-0.298, 0, 0>;
  63. vector koff4=<-0.012,0,0>;
  64. vector koff5=<-0.055, 0, 0>;
  65.  
  66.  
  67. list decode =
  68.            [ "%C3%87", "%C3%BC", "%C3%A9", "%C3%A2", "%C3%A4", "%C3%A0", "%C3%A5", "%C3%A7", "%C3%AA", "%C3%AB",
  69.              //           è         ï          î         ì         Ä         Å         É         æ         Æ    BLACK RIGHT-POINTING TRIANGLE
  70.                        "%C3%A8", "%C3%AF", "%C3%AE", "%C3%AC", "%C3%84", "%C3%85", "%C3%89", "%C3%A6", "%C3%AE", "%E2%96%B6",
  71.              //           ö         ò          û         ù         ÿ         Ö         Ü         ¢         £         ¥
  72.                        "%C3%B6", "%C3%B2", "%C3%BB", "%C3%B9", "%C3%BF", "%C3%96", "%C3%9C", "%C2%A2", "%C2%A3", "%C2%A5",
  73.              //           A^    copyright     á         í         ó         ú         ñ         Ñ         ª          º"
  74.                        "%C3%82", "%C2%A9", "%C3%A1", "%C3%AD", "%C3%B3", "%C3%BA", "%C3%B1", "%C3%91", "%C2%AA", "%C2%BA",
  75.              //            ¿        O^         ¬        ½         ¼          ¡         «        »       alfa          ß"
  76.                        "%C2%BF", "%C3%94", "%C2%AC", "%C2%BD", "%C2%BC", "%C2%A1", "%C2%AB", "%C2%BB", "%CE%B1", "%C3%9F",
  77.              //           gamma      pi      bigsigma  smsigma    mu  
  78.                        "%CE%93", "%CF%80", "%CE%A3", "%CF%83", "%C2%B5",
  79.                      
  80.              //                              tau       BIGfi      theta       omega   delta  
  81.              "%CF%84", "%CE%A6", "%CE%98", "%CE%A9", "%CE%B4",
  82.              //         Uu          uu       EPS         INTERS        3bars        +-         <=           >=        INTEGRUP   INTEGRDOWN
  83.                        "%C5%AC", "%C5%AD", "%CE%B5", "%E2%88%A9", "%E2%89%A1", "%C2%B1", "%E2%89%A5", "%E2%89%A4", "%E2%8C%A0", "%E2%8C%A1",
  84.              //           A/       A\        a~         A~       E^         I/        O/        o~       O~        o^
  85.                        "%C3%81", "%C3%80", "%C3%A3", "%C3%83", "%C3%8A", "%C3%8D", "%C3%93", "%C3%B5", "%C3%95", "%C3%B4" ];
  86.  
  87.  
  88.  
  89.  
  90. // Used to hide the text after a fade-out.
  91. key     TRANSPARENT     = "701917a8-d614-471f-13dd-5f4644e36e3c";
  92. ///////////// END CONSTANTS ////////////////
  93.  
  94. ///////////// GLOBAL VARIABLES ///////////////
  95. // This is the key of the font we are displaying.
  96. key     gFontTexture        = "font";
  97. // All displayable characters.  Default to ASCII order.
  98. string gCharIndex;
  99. // This is the channel to listen on while acting
  100. // as a cell in a larger display.
  101. integer gCellChannel        = -1;
  102. // This is the starting character position in the cell channel message
  103. // to render.
  104. integer gCellCharPosition   = 0;
  105. // This is whether or not to use the fade in/out special effect.
  106. integer gCellUseFading      = FALSE;
  107. // This is how long to display the text before fading out (if using
  108. // fading special effect).
  109. // Note: < 0  means don't fade out.
  110. float   gCellHoldDelay      = 1.0;
  111. /////////// END GLOBAL VARIABLES ////////////
  112.  
  113. ResetCharIndex() {
  114.  
  115.      gCharIndex  = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`";
  116.      gCharIndex += "abcdefghijklmnopqrstuvwxyz{|}~\n\n\n\n\n";
  117.  
  118.      //decode=[];
  119.      
  120. }
  121.  
  122. vector GetGridOffset(integer index) {
  123.    // Calculate the offset needed to display this character.
  124.    integer Row = index / knum - 1;
  125.    integer Col = index % knum;
  126.  
  127.    // Return the offset in the texture.
  128.    return < kcol.x + kcol.y * Col, krow.x + krow.y * Row, 0.0>;
  129. }
  130. ShowChars(integer linknum, vector grid_offset1, vector grid_offset2, vector grid_offset3, vector grid_offset4, vector grid_offset5) {
  131.    // Set the primitive textures directly.
  132.    
  133.    llSetLinkPrimitiveParamsFast( linknum, [
  134.         PRIM_TEXTURE, FACE_1, (string)gFontTexture, kmul1, grid_offset1 + koff1, 0.0,
  135.         PRIM_TEXTURE, FACE_2, (string)gFontTexture, kmul2, grid_offset2 + koff2, 0.0,
  136.         PRIM_TEXTURE, FACE_3, (string)gFontTexture, kmul3, grid_offset3 + koff3, 0.0,
  137.         PRIM_TEXTURE, FACE_4, (string)gFontTexture, kmul4, grid_offset4 + koff4, 0.0,
  138.         PRIM_TEXTURE, FACE_5, (string)gFontTexture, kmul5, grid_offset5 + koff5, 0.0
  139.         ]);
  140. }
  141.  
  142. // SALAHZAR intelligent procedure to extract UTF-8 codes and convert to index in our "cp850"-like table
  143. integer GetIndex(string char)
  144. {
  145.     integer  ret=llSubStringIndex(gCharIndex, char);
  146.    // llSay(0,"pos: "+(string)ret);
  147.     if(ret>=0) return ret;
  148.  
  149.     // special char do nice trick :)
  150.     string escaped=llEscapeURL(char);
  151.    // llSay(0,"char: "+escaped+" "+llList2CSV(decode));
  152.     integer found=llListFindList(decode, [escaped]);
  153.  
  154.     // Return blank if not found
  155.     if(found<0) return 0;
  156.  
  157.     // return correct index
  158.   //  llSay(0,"returning "+(string)(100+found));
  159.     return 100+found;
  160.  
  161. }
  162. // END SALAHZAR
  163.  
  164.  
  165. RenderString(integer linknum, string str) {
  166.    debug("Renderstring {"+str+"} on linknum "+(string)linknum);
  167.    // Get the grid positions for each pair of characters.
  168.    vector GridOffset1 = GetGridOffset( GetIndex(llGetSubString(str, 0, 0)) ); // SALAHZAR intermediate function
  169.    vector GridOffset2 = GetGridOffset( GetIndex(llGetSubString(str, 1, 1)) ); // SALAHZAR
  170.    vector GridOffset3 = GetGridOffset( GetIndex(llGetSubString(str, 2, 2)) ); // SALAHZAR
  171.    vector GridOffset4 = GetGridOffset( GetIndex(llGetSubString(str, 3, 3)) ); // SALAHZAR
  172.    vector GridOffset5 = GetGridOffset( GetIndex(llGetSubString(str, 4, 4)) ); // SALAHZAR
  173.  
  174.    // Use these grid positions to display the correct textures/offsets.
  175.    ShowChars(linknum, GridOffset1, GridOffset2, GridOffset3, GridOffset4, GridOffset5);
  176. }
  177.  
  178. integer ConvertIndex(integer index) {
  179.    // This converts from an ASCII based index to our indexing scheme.
  180.    if (index >= 32) // ' ' or higher
  181.        index -= 32;
  182.    else { // index < 32
  183.        // Quick bounds check.
  184.        if (index > 15)
  185.            index = 15;
  186.  
  187.        index += 94; // extended characters
  188.    }
  189.  
  190.    return index;
  191. }
  192.  
  193. integer NCELLS=4;
  194.  
  195. parseMessage(string m, integer row)
  196. {
  197.     debug("Parsing message {"+m+"} to row: "+(string)row);
  198.      
  199.       integer i; integer j;
  200.      
  201.      
  202.            for(j=0;j<g_length;j++)
  203.            {
  204.                string element=llGetSubString(m,j*5,(j+1)*5-1);
  205.                integer found=llListFindList(g_lookup,[ (string)(row+j) ]);
  206.                 if(found>=0){
  207.                  integer linknumber=llList2Integer(g_lookup,found+1);
  208.            
  209.                RenderString(linknumber,element);
  210.             }
  211.            }
  212.       // for(i=start;i<llGetNumberOfPrims();i++) RenderString(i+1,"    ");
  213. }
  214. string g_name;
  215. integer g_start;
  216. integer g_end;
  217. integer  g_length;
  218.  
  219. list g_lookup; // pairs name + linknumber
  220.  
  221. default {
  222.    state_entry() {
  223.        debug("Initialize");
  224.        // Initialize the character index.
  225.        list bits=llParseStringKeepNulls(llGetScriptName(),["-"],[]);
  226.         g_name=llList2String(bits,0);
  227.         g_start=(integer)llList2String(bits,1);
  228.         g_end=(integer)llList2String(bits,2);
  229.        
  230.         g_length=(integer)llList2String(bits,3);
  231.        debug("Start: "+(string)g_start+", End: "+(string)g_end+", length: "+(string)g_length);
  232.        ResetCharIndex();
  233.        integer i; g_lookup=[];
  234.        for(i=1;i<=llGetNumberOfPrims();i++)
  235.        {
  236.            string pname=llGetLinkName(i);
  237.            integer iname=(integer)pname;
  238.            if(iname>=g_start && iname<=g_end)
  239.            {
  240.                debug("adding "+pname+" link: "+(string)i);
  241.                g_lookup+=[ pname, i ];
  242.            }
  243.        }
  244.        debug("parsing");
  245.        llMessageLinked(LINK_SET,2000,"______",NULL_KEY);
  246.     }
  247.      
  248.     link_message(integer sender,integer channel,string str,key id)
  249.     {
  250.         if(channel>= g_start && channel <=g_end ) parseMessage(str,channel);
  251.     }
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement