//-----------------------------------------------------------------------------

// Variables used by client scripts & code.  The ones marked with (c)
// are accessed from code.  Variables preceeded by Pref:: are client
// preferences and stored automatically in the ~/client/prefs.cs file
// in between sessions.
//
//    (c) Client::MissionFile             Mission file name
//    ( ) Client::Password                Password for server join

//    (?) Pref::Player::CurrentFOV
//    (?) Pref::Player::DefaultFov
//    ( ) Pref::Input::KeyboardTurnSpeed

//    (c) pref::Master[n]                 List of master servers
//    (c) pref::Net::RegionMask     
//    (c) pref::Client::ServerFavoriteCount
//    (c) pref::Client::ServerFavorite[FavoriteCount]
//    .. Many more prefs... need to finish this off

// Moves, not finished with this either...
//    (c) firstPerson
//    $mv*Action...

//-----------------------------------------------------------------------------
// These are variables used to control the shell scripts and
// can be overriden by mods:
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// loadMaterials - load all materials.cs files
//-----------------------------------------------------------------------------
function loadMaterials()
{
   for( %file = findFirstFile( "*/materials.cs" ); %file !$= ""; %file = findNextFile( "*/materials.cs" ))
   {
      exec( %file );
   }
}

function reloadMaterials()
{
   reloadTextures();
   loadMaterials();
   reInitMaterials();
}

//-----------------------------------------------------------------------------
function initClient()
{
   echo("\n--------- Initializing " @ $appName @ ": Client Scripts ---------");

   // Make sure this variable reflects the correct state.
   $Server::Dedicated = false;

   // Game information used to query the master server
   $Client::GameTypeQuery = $appName;
   $Client::MissionTypeQuery = "Any";

   exec("./ui/customProfiles.cs"); // override the base profiles if necessary

   // The common module provides basic client functionality
   initBaseClient();

   // Use our prefs to configure our Canvas/Window
   configureCanvas();

   // Set the window title
   if (isObject(Canvas))
//      Canvas.setWindowTitle(getEngineName() @ " (" @ getVersionString() @ ") - " @ $appName);
      
   /// Load client-side Audio Profiles/Descriptions
   exec("./scripts/audioProfiles.cs");

   // Load up the Game GUIs
   exec("./ui/defaultGameProfiles.cs");
   exec("./ui/PlayGui.gui");
   exec("./ui/ChatHud.gui");
   exec("./ui/playerList.gui");

   // Load up the shell GUIs

//-------------------------------------------------------------------------
// load customized PSR Outdoors GUI screens

   exec("./ui/psr_main.gui");
   exec("./ui/psr_hunts.gui");
   exec("./ui/psr_instructions.gui");
   exec("./ui/psr_trophy_room.gui");
   exec("./ui/psr_elk_gear.gui");
   exec("./ui/psr_deer_gear.gui");
   exec("./ui/psr_turkey_gear.gui");
   exec("./ui/psr_handle.gui");
   exec("./ui/psr_HUD_deer.gui");
   exec("./ui/psr_HUD_deer2.gui");
   exec("./ui/psr_reg_card1.gui");
   exec("./ui/psr_reg_card2.gui");

//-------------------------------------------------------------------------

   exec("./ui/mainMenuGui.gui");
   exec("./ui/aboutDlg.gui");
   exec("./ui/startMissionGui.gui");
   exec("./ui/joinServerGui.gui");
   exec("./ui/endGameGui.gui");
   exec("./ui/loadingGui.gui");
   exec("./ui/optionsDlg.gui");
   exec("./ui/remapDlg.gui");
   exec("./ui/StartupGui.gui");

   // Client scripts
   exec("./scripts/client.cs");
   exec("./scripts/game.cs");
   exec("./scripts/missionDownload.cs");
   exec("./scripts/serverConnection.cs");
   exec("./scripts/playerList.cs");
   exec("./scripts/loadingGui.cs");
   exec("./scripts/optionsDlg.cs");
   exec("./scripts/chatHud.cs");
   exec("./scripts/messageHud.cs");
   exec("./scripts/playGui.cs");
   exec("./scripts/centerPrint.cs");
   
   // Load useful Materials
   exec("./scripts/glowBuffer.cs");
   exec("./scripts/shaders.cs");
   exec("./scripts/commonMaterialData.cs" );

   // Default player key bindings
   exec("./scripts/default.bind.cs");

   if (isFile("./config.cs"))
      exec("./config.cs");

   loadMaterials();


//**************************************************************************
//*****     Define retical graphic based on firearm selected            ******
//**************************************************************************

  if ($firearm $= "r")  {
    crosshair.bitmap = "scriptsAndAssets/client/ui/psr_rifle_retical";
    crosshair.visible = 0;
  }

  if ($firearm $= "m_black"  ||  $firearm $= "m_camo"  ||  $firearm $= "s_black")  {
    crosshair.bitmap = "scriptsAndAssets/client/ui/psr_muzzle_retical";
    crosshair.visible = 0;
  }


 if ($firearm $= "s_camo")  {
    crosshair.bitmap = "scriptsAndAssets/client/ui/psr_turkey_retical";
    crosshair.visible = 0;
  }

//**************************************************************************


   // Really shouldn't be starting the networking unless we are
   // going to connect to a remote server, or host a multi-player
   // game.
   setNetPort(0);
   
   // Copy saved script prefs into C++ code.
   setDefaultFov( $pref::Player::defaultFov );
   setZoomSpeed( $pref::Player::zoomSpeed );

   // Start up the main menu... this is separated out into a 
   // method for easier mod override.


//----------------------------------------------------------------------------------------------
// commenting out so we can customize with our own menu here!!

//    // Connect to server if requested.
//    if ($JoinGameAddress !$= "") {
//       // If we are instantly connecting to an address, load the
//       // main menu then attempt the connect.
//       loadMainMenu();
//       connect($JoinGameAddress, "", $Pref::Player::Name);
//    }
//    else {
//       // Otherwise go to the splash screen.
//       Canvas.setCursor("DefaultCursor");
//       loadStartup();
//    }




   Canvas.setCursor("DefaultCursor");
   canvas.pushdialog(psr_main);


  datablock SFXDescription(music_Looping2D)
  {
     volume = 1.0;
     isLooping = true;
     is3D = false;
     channel = $SimAudioType;
  };

  datablock SFXProfile(music1)
  {
     filename = "~/data/sound/music_1.ogg";
     description = "music_Looping2D";
     preload = true;
  };


  $PSR_music = SFXPlay(music1);

//  SFXstop($PSR_music);


//----------------------------------------------------------------------------------------------

}


//-----------------------------------------------------------------------------

/// loading main navigation screen at startup
function loadMainMenu()
{

//Canvas.setContent(psr_gear);

   // Startup the client with the Main menu...
   if (isObject( MainMenuGui ))
      Canvas.setContent( MainMenuGui );
   else if (isObject( UnifiedMainMenuGui ))
      Canvas.setContent( UnifiedMainMenuGui );
   Canvas.setCursor("DefaultCursor");


}






// function loadPSRMission()
// {
//    Canvas.setCursor("DefaultCursor");
//    createServer( "SinglePlayer", expandFileName("~/data/missions/0_canada_lvl_119.mis") );
//    %conn = new GameConnection(ServerConnection);
//    RootGroup.add(ServerConnection);
//    %conn.setConnectArgs($pref::Player::Name);
//    %conn.setJoinPassword($Client::Password);
//    %conn.connectLocal();
// }
