home *** CD-ROM | disk | FTP | other *** search
/ Sony Community Place / circus2e.exe / DATA.Z / exit.java < prev    next >
Text File  |  1996-09-25  |  3KB  |  117 lines

  1. //
  2. // exit.java
  3. //    ok, cancel button & load initial color
  4. //
  5. // (c) Copyright 1996 Sony Corporation. All rights reserved.
  6.  
  7. import vrml.*;
  8. import vrml.field.*;
  9. import vrml.node.*;
  10. import vs.*;
  11.  
  12. public class exit extends Script {
  13.     final int PARTS_MAX = 18;
  14.     final int COLOR_MAX = 18;
  15.     SFColor diffuse[] = new SFColor[ PARTS_MAX ];
  16.     float f[] = new float[3] ;
  17.     final int cBase = '0';
  18.  
  19.     public void processEvent(Event e){
  20.     if( ((ConstSFBool)e.getValue()).getValue() == true ){
  21.         String code = "";
  22. //    System.out.println ( e.getName() );
  23.     if(e.getName().equals("clicked_ok")){
  24.         String str;
  25.         // get colors
  26.         SFInt32 colorno[] = new SFInt32 [ PARTS_MAX ];
  27.         for( int i = 0; i < PARTS_MAX; i++ ){
  28.             str = "part" + i + "_colorNo";
  29.             colorno[ i ] = (SFInt32) getField( str );
  30.             // generating codes
  31.             code += (char)( colorno[i].getValue() + cBase );
  32. //            System.out.println ( colorno[ i ] );
  33.         }
  34.  
  35.         // set registories 
  36.         System.out.println ( "code saved: " + code );
  37.         Vscp.setAvtroomAvatarColor( code );  
  38.  
  39.         // go to previous world
  40.         Vscp.goFromAvtroomToOriginalWorld();
  41. //        getBrowser().setDescription ( "press Back button to return" );        
  42.     }
  43.  
  44.     if(e.getName().equals("clicked_ng")){
  45.         // get initial colors
  46. //        System.out.println ( "cancel" );
  47.  
  48.         // restore colors
  49.         load();
  50.     }
  51.     if(e.getName().equals("init")){
  52.         // get initial colors
  53. //        System.out.println ( "initialize colors" );
  54.  
  55.         // restore colors
  56.         load();
  57.     }        
  58.       }
  59.     }
  60.     public void load ( ){
  61.     String colorString = Vscp.getAvtroomAvatarColor();
  62.     String str;
  63.     SFInt32 colorNo;
  64.     float f[] = new float[ 3 ];
  65.     int doll_no = 0;
  66.  
  67.     String avtURL = Vscp.getAvtroomAvatarURL();
  68.     if( avtURL.endsWith( "boy.wrl" )){
  69.         doll_no = 0;
  70.     }
  71.     else if ( avtURL.endsWith( "girl.wrl" )){
  72.         doll_no = 1;
  73.     }
  74. //    System.out.println ( "initialize colors: " + doll_no );
  75.     
  76.         
  77.     // decode
  78.     if ( colorString.length() < PARTS_MAX ){
  79.         // set default color
  80.         for ( int i = 0; i < PARTS_MAX; i++ ){
  81.             f = GenerateColor.getDefaultColor( i, doll_no );
  82.             diffuse[ i ].setValue( f );
  83.         }
  84.     }
  85.     else{
  86.         for ( int i = 0; i < PARTS_MAX; i++ ){
  87.             int decode = (int) colorString.charAt( i ) - cBase;
  88.  
  89.             // set colorNo
  90.             str = "part" + i + "_colorNo";
  91.             colorNo = (SFInt32) getField( str );
  92.             colorNo.setValue( decode );
  93.  
  94.             // set diffuse color
  95.             if ( decode < COLOR_MAX ){
  96.                 f = GenerateColor.getSFColor( decode );
  97.                 diffuse[ i ].setValue( f );
  98.             }
  99.             else{    // set default color
  100.                 f = GenerateColor.getDefaultColor( i, doll_no );
  101.                 diffuse[ i ].setValue( f );
  102.             }                
  103.         }
  104.     }
  105.     }
  106.  
  107.     public void initialize (){
  108.     String str;
  109.     for( int i = 0; i < PARTS_MAX; i++ ){
  110.         str = "part" + i + "_color";
  111.         diffuse[ i ] = ( SFColor ) getEventOut( str ) ;
  112.     }
  113.     }
  114. }
  115.  
  116.  
  117.