//-----------------------------------------------------------------------------
// Handle events of GUI controls of the new player menu.
//-----------------------------------------------------------------------------

function onKey(%obj)
{
   NewPlayerMenuDlg.onKey(%obj);
}

function NewPlayerMenuDlg::onWake(%this)
{
//   %pXml = loadMenuXML();
//   parseNPMenuXML(%pXml);
//   %pXml.delete();

   if(isObject(newPlayerMap))
      newPlayerMap.delete();
   new ActionMap(newPlayerMap);

   newPlayerMap.bindCmd( keyboard, "a", "onKey(\"a\");", "" );
   newPlayerMap.bindCmd( keyboard, "b", "onKey(\"b\");", "" );
   newPlayerMap.bindCmd( keyboard, "c", "onKey(\"c\");", "" );
   newPlayerMap.bindCmd( keyboard, "d", "onKey(\"d\");", "" );
   newPlayerMap.bindCmd( keyboard, "e", "onKey(\"e\");", "" );
   newPlayerMap.bindCmd( keyboard, "f", "onKey(\"f\");", "" );
   newPlayerMap.bindCmd( keyboard, "g", "onKey(\"g\");", "" );
   newPlayerMap.bindCmd( keyboard, "h", "onKey(\"h\");", "" );
   newPlayerMap.bindCmd( keyboard, "i", "onKey(\"i\");", "" );
   newPlayerMap.bindCmd( keyboard, "j", "onKey(\"j\");", "" );
   newPlayerMap.bindCmd( keyboard, "k", "onKey(\"k\");", "" );
   newPlayerMap.bindCmd( keyboard, "l", "onKey(\"l\");", "" );
   newPlayerMap.bindCmd( keyboard, "m", "onKey(\"m\");", "" );
   newPlayerMap.bindCmd( keyboard, "n", "onKey(\"n\");", "" );
   newPlayerMap.bindCmd( keyboard, "o", "onKey(\"o\");", "" );
   newPlayerMap.bindCmd( keyboard, "p", "onKey(\"p\");", "" );
   newPlayerMap.bindCmd( keyboard, "q", "onKey(\"q\");", "" );
   newPlayerMap.bindCmd( keyboard, "r", "onKey(\"r\");", "" );
   newPlayerMap.bindCmd( keyboard, "s", "onKey(\"s\");", "" );
   newPlayerMap.bindCmd( keyboard, "t", "onKey(\"t\");", "" );
   newPlayerMap.bindCmd( keyboard, "u", "onKey(\"u\");", "" );
   newPlayerMap.bindCmd( keyboard, "v", "onKey(\"v\");", "" );
   newPlayerMap.bindCmd( keyboard, "w", "onKey(\"w\");", "" );
   newPlayerMap.bindCmd( keyboard, "x", "onKey(\"x\");", "" );
   newPlayerMap.bindCmd( keyboard, "y", "onKey(\"y\");", "" );
   newPlayerMap.bindCmd( keyboard, "z", "onKey(\"z\");", "" );

   newPlayerMap.bindCmd( keyboard, "A", "onKey(\"A\");", "" );
   newPlayerMap.bindCmd( keyboard, "B", "onKey(\"B\");", "" );
   newPlayerMap.bindCmd( keyboard, "C", "onKey(\"C\");", "" );
   newPlayerMap.bindCmd( keyboard, "D", "onKey(\"D\");", "" );
   newPlayerMap.bindCmd( keyboard, "E", "onKey(\"E\");", "" );
   newPlayerMap.bindCmd( keyboard, "F", "onKey(\"F\");", "" );
   newPlayerMap.bindCmd( keyboard, "G", "onKey(\"G\");", "" );
   newPlayerMap.bindCmd( keyboard, "H", "onKey(\"H\");", "" );
   newPlayerMap.bindCmd( keyboard, "I", "onKey(\"I\");", "" );
   newPlayerMap.bindCmd( keyboard, "J", "onKey(\"J\");", "" );
   newPlayerMap.bindCmd( keyboard, "K", "onKey(\"K\");", "" );
   newPlayerMap.bindCmd( keyboard, "L", "onKey(\"L\");", "" );
   newPlayerMap.bindCmd( keyboard, "M", "onKey(\"M\");", "" );
   newPlayerMap.bindCmd( keyboard, "N", "onKey(\"N\");", "" );
   newPlayerMap.bindCmd( keyboard, "O", "onKey(\"O\");", "" );
   newPlayerMap.bindCmd( keyboard, "P", "onKey(\"P\");", "" );
   newPlayerMap.bindCmd( keyboard, "Q", "onKey(\"Q\");", "" );
   newPlayerMap.bindCmd( keyboard, "R", "onKey(\"R\");", "" );
   newPlayerMap.bindCmd( keyboard, "S", "onKey(\"S\");", "" );
   newPlayerMap.bindCmd( keyboard, "T", "onKey(\"T\");", "" );
   newPlayerMap.bindCmd( keyboard, "U", "onKey(\"U\");", "" );
   newPlayerMap.bindCmd( keyboard, "V", "onKey(\"V\");", "" );
   newPlayerMap.bindCmd( keyboard, "W", "onKey(\"W\");", "" );
   newPlayerMap.bindCmd( keyboard, "X", "onKey(\"X\");", "" );
   newPlayerMap.bindCmd( keyboard, "Y", "onKey(\"Y\");", "" );
   newPlayerMap.bindCmd( keyboard, "Z", "onKey(\"Z\");", "" );

   newPlayerMap.bindCmd( keyboard, "1", "onKey(\"1\");", "" );
   newPlayerMap.bindCmd( keyboard, "2", "onKey(\"2\");", "" );
   newPlayerMap.bindCmd( keyboard, "3", "onKey(\"3\");", "" );
   newPlayerMap.bindCmd( keyboard, "4", "onKey(\"4\");", "" );
   newPlayerMap.bindCmd( keyboard, "5", "onKey(\"5\");", "" );
   newPlayerMap.bindCmd( keyboard, "6", "onKey(\"6\");", "" );
   newPlayerMap.bindCmd( keyboard, "7", "onKey(\"7\");", "" );
   newPlayerMap.bindCmd( keyboard, "8", "onKey(\"8\");", "" );
   newPlayerMap.bindCmd( keyboard, "9", "onKey(\"9\");", "" );
   newPlayerMap.bindCmd( keyboard, "0", "onKey(\"0\");", "" );

   newPlayerMap.bindCmd( keyboard, "space", "onKey(\" \");", "" );
   newPlayerMap.bindCmd( keyboard, "enter", "NewPlayerSelected();", "" );

   newPlayerMap.bindCmd( keyboard, "backspace", "onKey(backspace);", "" );

   // Update the action map
   newPlayerMap.push();

   %this.newName = "";
   %this.showCaret = true;
   %this.onUpdateText();
   %this.onUpdateCaret();
   
   Canvas.setWidescreen(NewPlayerMenuDlgCenter, 100, false);   
}

function NewPlayerMenuDlg::onSleep(%this)
{
   newPlayerMap.pop();

   cancelScheduleLCA(%this.onUpdateTextID);
   cancelScheduleLCA(%this.onUpdateCaretID);
}

function NewPlayerMenuDlg::onResize(%this, %width, %height)
{  
   Canvas.setWidescreen(NewPlayerMenuDlgCenter, 2000, true);
}
/*
// Parse XML file looking for menu text tags
function parseNPMenuXML(%pXml)
{
   if(!isObject(%pXml))
      return;
      
   // Push the first child element named "newplayer" onto the XML document stack.
   if(!%pXml.pushFirstChildElement("newplayer"))
   {
      echo("Failed to load 'newplayer' tag.");
      return;
   }
   
   if(%pXml.pushFirstChildElement("title"))
   {
      NPTitleText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("accept"))
   {
      NPAcceptMenuButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("back"))
   {
      NPBackMenuButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
}

// Stop grow/shrink animation of all menu UI elements
function StopMenuShrinkGrowNewPlayerMenu()
{
   StopShrinkGrowGUI(NPAcceptMenuButton);
   StopShrinkGrowGUI(NPBackMenuButton);
}

function NPAcceptMenuButton::onMouseEnter(%this)
{
   NPAcceptMenuButtonText.color = "255 128 0 255";
   
   StopMenuShrinkGrowNewPlayerMenu();
   InitShrinkGrowGUI(%this);
}

function NPAcceptMenuButton::onMouseLeave(%this)
{
   NPAcceptMenuButtonText.color = "255 255 255 255";
}   

function NPBackMenuButton::onMouseEnter(%this)
{
   NPBackMenuButtonText.color = "255 128 0 255";
   
   StopMenuShrinkGrowNewPlayerMenu();
   InitShrinkGrowGUI(%this);
}

function NPBackMenuButton::onMouseLeave(%this)
{
   NPBackMenuButtonText.color = "255 0 0 255";
}   
*/
// Set new player name and exit to scene selection menu
function NewPlayerSelected()
{
   sfxPlay(AudioButtonPress); //Button Press Sound
   
   $CurPlayerName = NewPlayerMenuDlg.newName;
   
   // Can't allow repeated names
   if($CurPlayerName $= PlayerProfile.PlayerName1 ||
      $CurPlayerName $= PlayerProfile.PlayerName2 ||
      $CurPlayerName $= PlayerProfile.PlayerName3 ||
      $CurPlayerName $= PlayerProfile.PlayerName4)
   {
      $CurPlayerName = "";
      Canvas.pushDialog(DuplicateDlg);
      return;
   }
   
   %strippedText = stripChars($CurPlayerName, " ");
   if(strlen(%strippedText) $= 0)
      $CurPlayerName = "";
   
   $pref::Player::Name = $CurPlayerName;
   
   if($CurPlayerName $= "")
   {
      MainMenuGui.popThread();
      MainMenuGui.pushThread(new_player_menu_thread);
   }
   else
   {
      // Decide player number
      if(PlayerProfile.PlayerName1 $= "") $CurPlayerNum = 1;
      else if(PlayerProfile.PlayerName2 $= "") $CurPlayerNum = 2;
      else if(PlayerProfile.PlayerName3 $= "") $CurPlayerNum = 3;
      else if(PlayerProfile.PlayerName4 $= "") $CurPlayerNum = 4;
      
      %CurPlayerHints  = 5;
      $CurPlayerStars  = 0;
      $CurPlayerUScene = 1;      
      $CurPlayerGangsterUTake = 1;
      $CurPlayerSpyUTake      = 1;
      $CurPlayerKungFuUTake   = 1;
      $CurPlayerMusicalUTake  = 1;
      $CurPlayerDinosaurUTake = 1;
      $CurPlayerSciFiUTake    = 1;
      $CurPlayerWesternUTake  = 1;
      $CurPlayerMonsterUTake  = 1;
      
      switch$($CurPlayerNum)
      {
         case 1:
            PlayerProfile.MinigameStars1   = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
            PlayerProfile.StarsMini1 = 0;
            PlayerProfile.Insects1 = 0;
            PlayerProfile.Animals1 = 0;
            PlayerProfile.Toys1    = 0;
            PlayerProfile.RunMentor1 = 0;
            PlayerProfile.RunWMTut1 = 0;
            PlayerProfile.FirstPlay1 = 1;
            PlayerProfile.ObjectsTaken1 = "";
            PlayerProfile.PlayerName1          = $CurPlayerName;
            PlayerProfile.PlayerHints1         = %CurPlayerHints;
            PlayerProfile.PlayerStars1         = $CurPlayerStars;
            PlayerProfile.PlayerUScene1        = $CurPlayerUScene;
            PlayerProfile.PlayerGangsterUTake1 = $CurPlayerGangsterUTake;
            PlayerProfile.PlayerSpyUTake1      = $CurPlayerSpyUTake;
            PlayerProfile.PlayerKungFuUTake1   = $CurPlayerKungFuUTake;
            PlayerProfile.PlayerMusicalUTake1  = $CurPlayerMusicalUTake;
            PlayerProfile.PlayerDinosaurUTake1 = $CurPlayerDinosaurUTake;
            PlayerProfile.PlayerSciFiUTake1    = $CurPlayerSciFiUTake;
            PlayerProfile.PlayerWesternUTake1  = $CurPlayerWesternUTake;
            PlayerProfile.PlayerMonsterUTake1  = $CurPlayerMonsterUTake;
            PlayerProfile.PlayerGangsterStarsTake1  = "0 0 0 0";
            PlayerProfile.PlayerSpyStarsTake1       = "0 0 0 0";
            PlayerProfile.PlayerKungFuStarsTake1    = "0 0 0 0";
            PlayerProfile.PlayerMusicalStarsTake1   = "0 0 0 0";
            PlayerProfile.PlayerDinosaurStarsTake1  = "0 0 0 0";  
            PlayerProfile.PlayerSciFiStarsTake1     = "0 0 0 0";  
            PlayerProfile.PlayerWesternStarsTake1   = "0 0 0 0";
            PlayerProfile.PlayerMonsterStarsTake1   = "0 0 0 0";
            
            PlayerProfile.Award_600_objects_1         = 0;
            PlayerProfile.Award_takes_game_1          = 0;
            PlayerProfile.Award_150_stars_1           = 0;
            PlayerProfile.Award_all_hint_objects_1    = 0;
            PlayerProfile.Award_5star_take_1          = 0;
            PlayerProfile.Award_all_items_2minutes_1  = 0;
            PlayerProfile.Award_2objects_3seconds_1   = 0;
            PlayerProfile.Award_3objects_3seconds_1   = 0;
            PlayerProfile.Award_insects_1             = 0;
            PlayerProfile.Award_toys_1                = 0;
            PlayerProfile.Award_wildlife_1            = 0;
            PlayerProfile.Award_takes_movie_1         = 0;
            PlayerProfile.Award_no_wrong_items_1      = 0;
            PlayerProfile.Award_no_hints_1            = 0;
            PlayerProfile.Award_paris_1               = 0;
            PlayerProfile.Award_tokyo_1               = 0;
            PlayerProfile.Award_newyork_1             = 0;
            PlayerProfile.Award_hollywood_1           = 0;
            PlayerProfile.Award_hongkong_1            = 0;
            PlayerProfile.Award_mexico_1              = 0;
            PlayerProfile.Award_london_1              = 0;
            PlayerProfile.Award_fiji_1                = 0;
            
            PlayerProfile.CorrectObjs_1               = 0;
            PlayerProfile.HintObjs_1                  = 0;
            
            PlayerProfile.Minigame1_1                 = 0;
            PlayerProfile.Minigame2_1                 = 0;
            PlayerProfile.Minigame3_1                 = 0;
            PlayerProfile.Minigame4_1                 = 0;
            PlayerProfile.Minigame5_1                 = 0;
            PlayerProfile.Minigame6_1                 = 0;
            PlayerProfile.Minigame7_1                 = 0;
            PlayerProfile.Minigame8_1                 = 0;
            PlayerProfile.Minigame9_1                 = 0;
            PlayerProfile.Minigame10_1                = 0;
            PlayerProfile.Minigame11_1                = 0;
            PlayerProfile.Minigame12_1                = 0;
            PlayerProfile.Minigame13_1                = 0;
            PlayerProfile.Minigame14_1                = 0;
            PlayerProfile.Minigame15_1                = 0;
            PlayerProfile.Minigame16_1                = 0;
            
         case 2:
            PlayerProfile.MinigameStars2 = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
            PlayerProfile.StarsMini2 = 0;
            PlayerProfile.Insects2 = 0;
            PlayerProfile.Animals2 = 0;
            PlayerProfile.Toys2    = 0;         
            PlayerProfile.RunMentor2 = 0;
            PlayerProfile.RunWMTut2 = 0;
            PlayerProfile.FirstPlay2 = 1;
            PlayerProfile.ObjectsTaken2 = "";
            PlayerProfile.PlayerName2          = $CurPlayerName;
            PlayerProfile.PlayerHints2         = %CurPlayerHints;
            PlayerProfile.PlayerStars2         = $CurPlayerStars;
            PlayerProfile.PlayerUScene2        = $CurPlayerUScene;
            PlayerProfile.PlayerGangsterUTake2 = $CurPlayerGangsterUTake;
            PlayerProfile.PlayerSpyUTake2      = $CurPlayerSpyUTake;
            PlayerProfile.PlayerKungFuUTake2   = $CurPlayerKungFuUTake;
            PlayerProfile.PlayerMusicalUTake2  = $CurPlayerMusicalUTake;
            PlayerProfile.PlayerDinosaurUTake2 = $CurPlayerDinosaurUTake;
            PlayerProfile.PlayerSciFiUTake2    = $CurPlayerSciFiUTake;
            PlayerProfile.PlayerWesternUTake2  = $CurPlayerWesternUTake;
            PlayerProfile.PlayerMonsterUTake2  = $CurPlayerMonsterUTake;
            PlayerProfile.PlayerGangsterStarsTake2  = "0 0 0 0";
            PlayerProfile.PlayerSpyStarsTake2       = "0 0 0 0";
            PlayerProfile.PlayerKungFuStarsTake2    = "0 0 0 0";
            PlayerProfile.PlayerMusicalStarsTake2   = "0 0 0 0";
            PlayerProfile.PlayerDinosaurStarsTake2  = "0 0 0 0";  
            PlayerProfile.PlayerSciFiStarsTake2     = "0 0 0 0";  
            PlayerProfile.PlayerWesternStarsTake2   = "0 0 0 0";  
            PlayerProfile.PlayerMonsterStarsTake2   = "0 0 0 0";
            
            PlayerProfile.Award_600_objects_2         = 0;
            PlayerProfile.Award_takes_game_2          = 0;
            PlayerProfile.Award_150_stars_2           = 0;
            PlayerProfile.Award_all_hint_objects_2    = 0;
            PlayerProfile.Award_5star_take_2          = 0;
            PlayerProfile.Award_all_items_2minutes_2  = 0;
            PlayerProfile.Award_2objects_3seconds_2   = 0;
            PlayerProfile.Award_3objects_3seconds_2   = 0;
            PlayerProfile.Award_insects_2             = 0;
            PlayerProfile.Award_toys_2                = 0;
            PlayerProfile.Award_wildlife_2            = 0;
            PlayerProfile.Award_takes_movie_2         = 0;
            PlayerProfile.Award_no_wrong_items_2      = 0;
            PlayerProfile.Award_no_hints_2            = 0;
            PlayerProfile.Award_paris_2               = 0;
            PlayerProfile.Award_tokyo_2               = 0;
            PlayerProfile.Award_newyork_2             = 0;
            PlayerProfile.Award_hollywood_2           = 0;
            PlayerProfile.Award_hongkong_2            = 0;
            PlayerProfile.Award_mexico_2              = 0;
            PlayerProfile.Award_london_2              = 0;
            PlayerProfile.Award_fiji_2                = 0;
            
            PlayerProfile.CorrectObjs_2               = 0;
            PlayerProfile.HintObjs_2                  = 0;
            
            PlayerProfile.Minigame1_2                 = 0;
            PlayerProfile.Minigame2_2                 = 0;
            PlayerProfile.Minigame3_2                 = 0;
            PlayerProfile.Minigame4_2                 = 0;
            PlayerProfile.Minigame5_2                 = 0;
            PlayerProfile.Minigame6_2                 = 0;
            PlayerProfile.Minigame7_2                 = 0;
            PlayerProfile.Minigame8_2                 = 0;
            PlayerProfile.Minigame9_2                 = 0;
            PlayerProfile.Minigame10_2                = 0;
            PlayerProfile.Minigame11_2                = 0;
            PlayerProfile.Minigame12_2                = 0;
            PlayerProfile.Minigame13_2                = 0;
            PlayerProfile.Minigame14_2                = 0;
            PlayerProfile.Minigame15_2                = 0;
            PlayerProfile.Minigame16_2                = 0;
                                    
         case 3:
            PlayerProfile.MinigameStars3 = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
            PlayerProfile.StarsMini3 = 0;
            PlayerProfile.Insects3 = 0;
            PlayerProfile.Animals3 = 0;
            PlayerProfile.Toys3    = 0;         
            PlayerProfile.RunMentor3 = 0;
            PlayerProfile.RunWMTut3 = 0;
            PlayerProfile.FirstPlay3 = 1; 
            PlayerProfile.ObjectsTaken3 = "";
            PlayerProfile.PlayerName3          = $CurPlayerName;
            PlayerProfile.PlayerHints3         = %CurPlayerHints;
            PlayerProfile.PlayerStars3         = $CurPlayerStars;
            PlayerProfile.PlayerUScene3        = $CurPlayerUScene;
            PlayerProfile.PlayerGangsterUTake3 = $CurPlayerGangsterUTake;
            PlayerProfile.PlayerSpyUTake3      = $CurPlayerSpyUTake;
            PlayerProfile.PlayerKungFuUTake3   = $CurPlayerKungFuUTake;
            PlayerProfile.PlayerMusicalUTake3  = $CurPlayerMusicalUTake;
            PlayerProfile.PlayerDinosaurUTake3 = $CurPlayerDinosaurUTake;
            PlayerProfile.PlayerSciFiUTake3    = $CurPlayerSciFiUTake;
            PlayerProfile.PlayerWesternUTake3  = $CurPlayerWesternUTake;
            PlayerProfile.PlayerMonsterUTake3  = $CurPlayerMonsterUTake;
            PlayerProfile.PlayerGangsterStarsTake3  = "0 0 0 0";
            PlayerProfile.PlayerSpyStarsTake3       = "0 0 0 0";
            PlayerProfile.PlayerKungFuStarsTake3    = "0 0 0 0";
            PlayerProfile.PlayerMusicalStarsTake3   = "0 0 0 0";
            PlayerProfile.PlayerDinosaurStarsTake3  = "0 0 0 0";     
            PlayerProfile.PlayerSciFiStarsTake3     = "0 0 0 0";  
            PlayerProfile.PlayerWesternStarsTake3   = "0 0 0 0";  
            PlayerProfile.PlayerMonsterStarsTake3   = "0 0 0 0";
            
            PlayerProfile.Award_600_objects_3         = 0;
            PlayerProfile.Award_takes_game_3          = 0;
            PlayerProfile.Award_150_stars_3           = 0;
            PlayerProfile.Award_all_hint_objects_3    = 0;
            PlayerProfile.Award_5star_take_3          = 0;
            PlayerProfile.Award_all_items_2minutes_3  = 0;
            PlayerProfile.Award_2objects_3seconds_3   = 0;
            PlayerProfile.Award_3objects_3seconds_3   = 0;
            PlayerProfile.Award_insects_3             = 0;
            PlayerProfile.Award_toys_3                = 0;
            PlayerProfile.Award_wildlife_3            = 0;
            PlayerProfile.Award_takes_movie_3         = 0;
            PlayerProfile.Award_no_wrong_items_3      = 0;
            PlayerProfile.Award_no_hints_3            = 0;
            PlayerProfile.Award_paris_3               = 0;
            PlayerProfile.Award_tokyo_3               = 0;
            PlayerProfile.Award_newyork_3             = 0;
            PlayerProfile.Award_hollywood_3           = 0;
            PlayerProfile.Award_hongkong_3            = 0;
            PlayerProfile.Award_mexico_3              = 0;
            PlayerProfile.Award_london_3              = 0;
            PlayerProfile.Award_fiji_3                = 0;
            
            PlayerProfile.CorrectObjs_3               = 0;
            PlayerProfile.HintObjs_3                  = 0;
            
            PlayerProfile.Minigame1_3                 = 0;
            PlayerProfile.Minigame2_3                 = 0;
            PlayerProfile.Minigame3_3                 = 0;
            PlayerProfile.Minigame4_3                 = 0;
            PlayerProfile.Minigame5_3                 = 0;
            PlayerProfile.Minigame6_3                 = 0;
            PlayerProfile.Minigame7_3                 = 0;
            PlayerProfile.Minigame8_3                 = 0;
            PlayerProfile.Minigame9_3                 = 0;
            PlayerProfile.Minigame10_3                = 0;
            PlayerProfile.Minigame11_3                = 0;
            PlayerProfile.Minigame12_3                = 0;
            PlayerProfile.Minigame13_3                = 0;
            PlayerProfile.Minigame14_3                = 0;
            PlayerProfile.Minigame15_3                = 0;
            PlayerProfile.Minigame16_3                = 0;
                  
         case 4:
            PlayerProfile.MinigameStars4 = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
            PlayerProfile.StarsMini4 = 0;
            PlayerProfile.Insects4 = 0;
            PlayerProfile.Animals4 = 0;
            PlayerProfile.Toys4    = 0;
            PlayerProfile.RunMentor4 = 0;
            PlayerProfile.RunWMTut4 = 0;
            PlayerProfile.FirstPlay4 = 1;
            PlayerProfile.ObjectsTaken4 = "";
            PlayerProfile.PlayerName4          = $CurPlayerName;
            PlayerProfile.PlayerHints4         = %CurPlayerHints;
            PlayerProfile.PlayerStars4         = $CurPlayerStars;
            PlayerProfile.PlayerUScene4        = $CurPlayerUScene;
            PlayerProfile.PlayerGangsterUTake4 = $CurPlayerGangsterUTake;
            PlayerProfile.PlayerSpyUTake4      = $CurPlayerSpyUTake;
            PlayerProfile.PlayerKungFuUTake4   = $CurPlayerKungFuUTake;
            PlayerProfile.PlayerMusicalUTake4  = $CurPlayerMusicalUTake;
            PlayerProfile.PlayerDinosaurUTake4 = $CurPlayerDinosaurUTake;
            PlayerProfile.PlayerSciFiUTake4    = $CurPlayerSciFiUTake;
            PlayerProfile.PlayerWesternUTake4  = $CurPlayerWesternUTake;
            PlayerProfile.PlayerMonsterUTake4  = $CurPlayerMonsterUTake;
            PlayerProfile.PlayerGangsterStarsTake4  = "0 0 0 0";
            PlayerProfile.PlayerSpyStarsTake4       = "0 0 0 0";
            PlayerProfile.PlayerKungFuStarsTake4    = "0 0 0 0";
            PlayerProfile.PlayerMusicalStarsTake4   = "0 0 0 0";
            PlayerProfile.PlayerDinosaurStarsTake4  = "0 0 0 0";
            PlayerProfile.PlayerSciFiStarsTake4     = "0 0 0 0";  
            PlayerProfile.PlayerWesternStarsTake4   = "0 0 0 0";  
            PlayerProfile.PlayerMonsterStarsTake4   = "0 0 0 0";
            
            PlayerProfile.Award_600_objects_4         = 0;
            PlayerProfile.Award_takes_game_4          = 0;
            PlayerProfile.Award_150_stars_4           = 0;
            PlayerProfile.Award_all_hint_objects_4    = 0;
            PlayerProfile.Award_5star_take_4          = 0;
            PlayerProfile.Award_all_items_2minutes_4  = 0;
            PlayerProfile.Award_2objects_3seconds_4   = 0;
            PlayerProfile.Award_3objects_3seconds_4   = 0;
            PlayerProfile.Award_insects_4             = 0;
            PlayerProfile.Award_toys_4                = 0;
            PlayerProfile.Award_wildlife_4            = 0;
            PlayerProfile.Award_takes_movie_4         = 0;
            PlayerProfile.Award_no_wrong_items_4      = 0;
            PlayerProfile.Award_no_hints_4            = 0;
            PlayerProfile.Award_paris_4               = 0;
            PlayerProfile.Award_tokyo_4               = 0;
            PlayerProfile.Award_newyork_4             = 0;
            PlayerProfile.Award_hollywood_4           = 0;
            PlayerProfile.Award_hongkong_4            = 0;
            PlayerProfile.Award_mexico_4              = 0;
            PlayerProfile.Award_london_4              = 0;
            PlayerProfile.Award_fiji_4                = 0;
            
            PlayerProfile.CorrectObjs_4               = 0;
            PlayerProfile.HintObjs_4                  = 0;
            
            PlayerProfile.Minigame1_4                 = 0;
            PlayerProfile.Minigame2_4                 = 0;
            PlayerProfile.Minigame3_4                 = 0;
            PlayerProfile.Minigame4_4                 = 0;
            PlayerProfile.Minigame5_4                 = 0;
            PlayerProfile.Minigame6_4                 = 0;
            PlayerProfile.Minigame7_4                 = 0;
            PlayerProfile.Minigame8_4                 = 0;
            PlayerProfile.Minigame9_4                 = 0;
            PlayerProfile.Minigame10_4                = 0;
            PlayerProfile.Minigame11_4                = 0;
            PlayerProfile.Minigame12_4                = 0;
            PlayerProfile.Minigame13_4                = 0;
            PlayerProfile.Minigame14_4                = 0;
            PlayerProfile.Minigame15_4                = 0;
            PlayerProfile.Minigame16_4                = 0;
      }

//      unlockAll();

      $pref::Player::Name = $CurPlayerName;
      $pref::Player::Num  = $CurPlayerNum;

      SavePlayerProfile();
      MainMenuGui.popThread();
//      MainMenuGui.pushThread(scene_menu_thread);

      //MapGui.update(false); // when mapGui onWake, it update itself
      //MainMenuGui.pushThread(map_menu_thread);
      showWorldMap(false);
   }
}

// Handle keys
function NewPlayerMenuDlg::onKey(%this, %key)
{
   if(%key $= backspace)
   {
      %len = strlen(%this.newName);
      if(%len > 0)
      {
         %newStr = getSubStr(%this.newName, 0, %len-1);
         %this.newName = %newStr;
      }
   }
   else
   {
      if(strlen(%this.newName) < 12)
         %this.newName = %this.newName @ %key;
   }
}

// Called every 30ms to update text edit
function NewPlayerMenuDlg::onUpdateText(%this)
{
   %text = %this.newName;
   
   if(%this.showCaret)
      %text = %text @ "|";
   else
      %text = %text @ " ";
   
   NPText.setText(%text);
   
   %this.onUpdateTextID = scheduleObjLCA(%this, "HO", 30, "onUpdateText", 0);   
}

// Called every 500ms to blink the caret
function NewPlayerMenuDlg::onUpdateCaret(%this)
{
   %this.showCaret = !%this.showCaret;
   %this.onUpdateCaretID = scheduleObjLCA(%this, "HO", 400, "onUpdateCaret", 0);   
}
