/*=========================================================================
* Vignette.c : Load and display vignette (LDT)
* This is a part of the Game project.
*
* (c) Ubi Studios 1998
*=======================================================================*/
 
/*#define D_VIG_Input_VariableDefine*/
 
#define HieFriend
#include "ACP_Base.h"
#include "CPA_Expt.h"
#include "CPA_Std.h"
 
#include "DPT.h"
#include "GMT.h"
#include "GEO.h"
#include "GLI.h"
#include "LST.h"
#include "TMP.h"
#if !defined(U64)
#include "FIL.h"
#include "sna.h"
 
#endif /* U64 */
 
#include "VIG_Def.h"
#include "ErrVIG.h"
#include "acp_opfi.h"
 
#include "ldt.h"
 
#define lTagLoadLevelVignette		'eLda'
#define lTagLoadVignette				'iVda'
#define lTagInitVignette				'iVti'
#define lTagFreeVignette				'iVee'
#define lTagDisplayVignette			'alps'
#define lTagInitBar							'aBti'
#define lTagInitBarOutlineColor	'ltuO'
#define lTagInitBarInsideColor	'isnI'
#define lTagInitBarColor				'oloC'
#define lTagCreateBar						'etae'
#define lTagAddBar							'raBd'
#define lTagMaxValueBar					'laVx'
 
#if !defined(U64)
extern FIL_tdxHandleToConcatFile VIG_g_hConcatVignetteFile ;
#endif /* U64 */
 
extern void VIG_fn_vLoadVignetteInStructure(struct VIG_tdstVignetteStructure_ *_p_stVignette,char *_szFileName,GLI_tdeVignetteFormat _eFormat);
extern void VIG_fn_vDisplayVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette);
extern void VIG_fn_vInitVignette(void);
extern void VIG_fn_vAddBarToVignette(struct VIG_tdstVignetteStructure_ *_p_stVignette);
 
 
/*****************************************************************
Function name   : fn_iLoadVignette
Description     : 
Author          : Ovidiu Scripa (oscripa@ubisoft.ro) - ROMTEAM
Creation Date   : 14-Oct-98
Modified        : 
Return type     : int 
Argument        : LDT_tdst_Link *pLink
*****************************************************************/
int fn_iLoadVignette( LDT_tdst_Link *pLink )
{
  LDT_tdeParseResult result=ParseResult_BeginSection;
 
 
  if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
     SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_VignetteDescTitle );
 
 
  while( result!=ParseResult_EndSection ) 
  {
  	result=LDT_GetNextEntry();
  	switch( result )
  	{
  	  case ParseResult_Entry: /* an entry */
  	  {
  	    char *szEntry=LDT_szGetEntryName();
  	    switch (*(long*)(szEntry+2))
  	    {
 
  	      case  lTagLoadLevelVignette : /*  */
  	      {
					 strcpy(VIG_g_stActualVignette.szLevelVignetteFileName,LDT_szGetParam(1));
					 VIG_fn_vLoadVignetteInStructure(&VIG_g_stActualVignette,LDT_szGetParam(1),GLI_EVF_BGR565_UL);
 
           if ( SNA_M_bTestSaveLevelDesc() )
                SNA_fn_vWriteStringEntryToCurrentDscFile( SNA_C_ul_LoadLevelVignette, LDT_szGetParam(1) );
 
  	      }
  	      break;
  	      case  lTagLoadVignette : /*  */
  	      {
					 VIG_fn_vFreeVignette(&VIG_g_stActualVignette);
					 VIG_fn_vLoadVignetteInStructure(&VIG_g_stActualVignette,LDT_szGetParam(1),GLI_EVF_BGR565_UL);
 
           if ( SNA_M_bTestSaveGameDesc() )
                SNA_fn_vWriteStringEntryToCurrentDscFile( SNA_C_ul_LoadVignette, LDT_szGetParam(1) );
 
  	      }
  	      break;
  	      case  lTagInitVignette : /*  */
  	      {
						VIG_fn_vInitVignette();	
 
             if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
                  SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitVignette );
 
  	      }
  	      break;
  	      case  lTagFreeVignette : /*  */
  	      {
						/*   VIG_fn_vFreeMemoryVignette(&VIG_g_stActualVignette);*/
 
            if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
              SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_FreeVignette );
 
  	      }
  	      break;
  	      case  lTagDisplayVignette : /*  */
  	      {
					 /**** To front buffer ****/
					 VIG_fn_vDisplayVignette(&VIG_g_stActualVignette);
					 /**** To back buffer ****/
					 VIG_fn_vDisplayVignette(&VIG_g_stActualVignette);
 
           if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
                SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_DisplayVignette );
 
 
  	      }
  	      break;
  	      case  lTagInitBar : /*  */
  	      {
 
  					switch (*(long*)(szEntry+7))
  					{
 
  						case  lTagInitBarOutlineColor : /*  */
  						{
							 VIG_g_stActualVignette.stOutsideColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(1))/255.0);
							 VIG_g_stActualVignette.stOutsideColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(2))/255.0);
							 VIG_g_stActualVignette.stOutsideColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(3))/255.0);
							 VIG_g_stActualVignette.stOutsideColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(4))/255.0);
 
               if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
               {
                    SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarOutlineColor );
                    SNA_fn_vWriteBlockToCurrentDscFile
                    ( 
                        (char *)&VIG_g_stActualVignette.stOutsideColor,
                        sizeof( GEO_tdstColor )
                    );
               }
 
 
  						}
  						break;
  						case  lTagInitBarInsideColor : /*  */
  						{
							 VIG_g_stActualVignette.stInsideColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(1))/255.0);
							 VIG_g_stActualVignette.stInsideColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(2))/255.0);
							 VIG_g_stActualVignette.stInsideColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(3))/255.0);
							 VIG_g_stActualVignette.stInsideColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(4))/255.0);
 
               if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
               {
                    SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarInsideColor );
                    SNA_fn_vWriteBlockToCurrentDscFile
                        ( (char *)&VIG_g_stActualVignette.stInsideColor, sizeof( GEO_tdstColor ) );
               }
 
  						}
  						break;
  						case  lTagInitBarColor : /*  */
  						{
							 VIG_g_stActualVignette.stUpLeftColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(1))/255.0);
							 VIG_g_stActualVignette.stUpLeftColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(2))/255.0);
							 VIG_g_stActualVignette.stUpLeftColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(3))/255.0);
							 VIG_g_stActualVignette.stUpLeftColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(4))/255.0);
							 VIG_g_stActualVignette.stUpRightColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(5))/255.0);
							 VIG_g_stActualVignette.stUpRightColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(6))/255.0);
							 VIG_g_stActualVignette.stUpRightColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(7))/255.0);
							 VIG_g_stActualVignette.stUpRightColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(8))/255.0);
							 VIG_g_stActualVignette.stDownLeftColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(9))/255.0);
							 VIG_g_stActualVignette.stDownLeftColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(10))/255.0);
							 VIG_g_stActualVignette.stDownLeftColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(11))/255.0);
							 VIG_g_stActualVignette.stDownLeftColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(12))/255.0);
							 VIG_g_stActualVignette.stDownRightColor.xR = (GEO_tdxColorValue)(atof(LDT_szGetParam(13))/255.0);
							 VIG_g_stActualVignette.stDownRightColor.xG = (GEO_tdxColorValue)(atof(LDT_szGetParam(14))/255.0);
							 VIG_g_stActualVignette.stDownRightColor.xB = (GEO_tdxColorValue)(atof(LDT_szGetParam(15))/255.0);
							 VIG_g_stActualVignette.stDownRightColor.xA = (GEO_tdxColorValue)(atof(LDT_szGetParam(16))/255.0);
 
               if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
               {
                    SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_InitBarColor );
                    SNA_fn_vWriteBlockToCurrentDscFile
                        ( (char *)&VIG_g_stActualVignette.stUpLeftColor, sizeof( GEO_tdstColor ) );
                    SNA_fn_vWriteBlockToCurrentDscFile
                        ( (char *)&VIG_g_stActualVignette.stUpRightColor, sizeof( GEO_tdstColor ) );
                    SNA_fn_vWriteBlockToCurrentDscFile
                        ( (char *)&VIG_g_stActualVignette.stDownLeftColor, sizeof( GEO_tdstColor ) );
                    SNA_fn_vWriteBlockToCurrentDscFile
                        ( (char *)&VIG_g_stActualVignette.stDownRightColor, sizeof( GEO_tdstColor ) );
               }
 
  						}
  						break;
  					}
 
  	      }
  	      break;
  	      case  lTagCreateBar : /*  */
  	      {
					 VIG_g_stActualVignette.ulOldBarValue = 0;
					 VIG_g_stActualVignette.ulNewBarValue = 0;
					 VIG_g_stActualVignette.ulBarXMinPos = (VIG_g_stActualVignette.ulWidth*atoi(LDT_szGetParam(1)))/640;
					 VIG_g_stActualVignette.ulBarYMinPos = (VIG_g_stActualVignette.ulHeight*atoi(LDT_szGetParam(2)))/480;
					 VIG_g_stActualVignette.ulBarXMaxPos = (VIG_g_stActualVignette.ulWidth*atoi(LDT_szGetParam(3)))/640;
					 VIG_g_stActualVignette.ulBarYMaxPos = (VIG_g_stActualVignette.ulHeight*atoi(LDT_szGetParam(4)))/480;
 
           if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
           {
                SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_CreateBar );
                SNA_fn_vWriteLongToCurrentDscFile( atoi(LDT_szGetParam(1)) );
                SNA_fn_vWriteLongToCurrentDscFile( atoi(LDT_szGetParam(2)) );
                SNA_fn_vWriteLongToCurrentDscFile( atoi(LDT_szGetParam(3)) );
                SNA_fn_vWriteLongToCurrentDscFile( atoi(LDT_szGetParam(4)) );
           }
 
  	      }
  	      break;
  	      case  lTagAddBar : /*  */
  	      {
					 VIG_fn_vAddBarToVignette(&VIG_g_stActualVignette);
					 VIG_g_stActualVignette.bDisplayBar = TRUE;
 
           if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
                SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ul_AddBar );
 
  	      }
  	      break;
  	      case  lTagMaxValueBar : /*  */
  	      {
					 VIG_g_stActualVignette.ulMaxBarValue = atoi(LDT_szGetParam(1));
					 VIG_g_stActualVignette.ulActualBarValue = 0;
 
           if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
                SNA_fn_vWriteLongEntryToCurrentDscFile( SNA_C_ul_MaxValueBar, atoi(LDT_szGetParam(1)) );
 
 
  	      }
  	      break;
 
  	    }
  	  }
  	}
  }
 
     if ( SNA_M_bTestSaveGameDesc() || SNA_M_bTestSaveLevelDesc() )
         SNA_fn_vWriteNoParamEntryToCurrentDscFile( SNA_C_ulEndOfDescSection );
 
 
  return 0;
}
 
 
 
 
