/*

  ファイル選択機能

  写真画面ロード部分差分

  （特殊なので全部作りなおしかも）

  2001/04/10 M.Kobayashi

  $Id: xfileselp_load.c,v 1.2 2002/12/12 13:22:08 takaki Exp $



 */



#ifdef KP_XBOX //BP



#include	"gameheader.h"

#include	"xmcman.h"

#include 	"private.h"

#include	"../../kira/2D_action/layout_2d.h"

#include	"../../mode/codec/codecmem.h"

#include	"../../kano/titlescr/subtitle.h"

#include	"../../kano/titlescr/titlescr.h"

#include	"../../kano/resman/resman.h"



#define TEX_STRCODE	GV_StrCode( "node_font_alp_ovl" )



#define DISPLAY_FILE_MAX		10



#define FILENAME_X		62

#define FILENAME_Y		100

#define FILENAME_YSTEP	22

#define CURSOR_Y_OFFSET (-1)



#define NAME_X			(FILENAME_X + 8 * 5)



#define YES_X			386

#define YES_Y			322

#define SLASH_X			434

#define SLASH_Y			YES_Y

#define NO_X			450

#define NO_Y			YES_Y

#define PAGE_X			324

#define PAGE_Y			72

#define	PAGENUM_X		429

#define	PAGENUM_Y		PAGE_Y



#define PAGESLASH_X		429



#define PAGE_W			14

#define PAGE_H			10

#define PAGENUM_W		18

#define PAGENUM_H		14





#define OVER_WRITE_X	20

#define OVER_WRITE_Y	318

#define OVER_WRITE_U	0

#define OVER_WRITE_V	0

#define OVER_WRITE_UW	(SUBTITLE_FONT_WIDTH * 30)

#define OVER_WRITE_VH 	(SUBTITLE_FONT_HEIGHT * 1)

#define OVER_WRITE_W	( OVER_WRITE_UW * SUBTITLE_FONT_DISP_WIDTH / SUBTITLE_FONT_WIDTH )

#define OVER_WRITE_H 	( OVER_WRITE_VH * SUBTITLE_FONT_DISP_HEIGHT / SUBTITLE_FONT_HEIGHT )



#define FAILED_X	52	

#define FAILED_Y	286

#define FAILED_U	0

#define FAILED_V	0

#define FAILED_UW	(SUBTITLE_FONT_WIDTH * 30)

#define FAILED_VH 	(SUBTITLE_FONT_HEIGHT * 15 / 4)

#define FAILED_W	( FAILED_UW * SUBTITLE_FONT_DISP_WIDTH / SUBTITLE_FONT_WIDTH )

#define FAILED_H 	( FAILED_VH * SUBTITLE_FONT_DISP_HEIGHT / SUBTITLE_FONT_HEIGHT )



#define SAMPLE_X	279		

#define SAMPLE_Y	99

#define SAMPLE_W	200

#define SAMPLE_H	130

#define PHOTO_MAIN_WIDTH ( 512 )

#define PHOTO_MAIN_HEIGHT ( 128 )



#define PHOTO_TEX_W	256

#define PHOTO_TEX_H	256



#define JPEG_W		(DRAW_WIDTH)

#define JPEG_H		(DRAW_HEIGHT)



#define STR_COLOR		0x80555a50

#define NOFOCUS_A		0x30



#define SAVE_GAME_RESOURCE	5

#define RES_NEWDATA			9

#define RES_OVERWRITE		3



#define LOAD_GAME_RESOURCE	(loadgame_resource_name[GM_Language-GM_LANG_ENGLISH])		/* ロードゲームリソース */

#define J_LOADGAME_RESOURCE		0x00f8a329		/* ロードゲームリソース日本語 */

#define E_LOADGAME_RESOURCE		0x00c44fd2		/* ロードゲームリソース英語 */

#define F_LOADGAME_RESOURCE		0x001cd935		/* ロードゲームリソースフランス語 */

#define G_LOADGAME_RESOURCE		0x00018abf		/* ロードゲームリソースドイツ語 */

#define I_LOADGAME_RESOURCE		0x005b72b4		/* ロードゲームリソースイタリア語 */

#define S_LOADGAME_RESOURCE		0x0011bd70		/* ロードゲームリソーススペイン語 */

static const int loadgame_resource_name[]={

	E_LOADGAME_RESOURCE,

	F_LOADGAME_RESOURCE,

	G_LOADGAME_RESOURCE,

	I_LOADGAME_RESOURCE,

	S_LOADGAME_RESOURCE,

	0, //韓国語

	J_LOADGAME_RESOURCE,

};

#define RES_LOADING			3

#define RES_LOAD_FAILED		5

#define RES_LOAD_COMP		4





#define		STR_LAYOUT2		   (4691731)



#define CODE_OPENLISTSLOT1 (8280576)

#define CODE_OPENNOWLOAD (20148)

#define CODE_CLOSENOWLOAD (15611943)

#define CODE_CLOSEEDITSLOT1 (1900344)

#define CODE_DEFAULTACTION		0x0008a3fb		/* DefaultAction */



#define CODE_OBJ_ROOT		(2770484)

#define CODE_OBJ_CURSOR       (6756848)

#define CODE_OBJ_LOADING	(15047160)



static short Select2Y( int sel ) {

	return ((sel) % DISPLAY_FILE_MAX) * FILENAME_YSTEP + FILENAME_Y;

}



enum {	// 内部使用gui_state

	GUI_STATE_PAGE_FADEOUT = MCX_GUI_STATE_SYSTEMMAX,

	GUI_STATE_YES_NO,

};





static char*  str_table[] = {

//	 1---5----0----5----0----5

//	"00 PHOTO 001 ",		// 13,

	"00 DAMAGEDDATA",		// 14,

	"DATA SAVE/HARD DISK",	// 19,

	"YES",					// 3	

	"/",					// 1

	"NO",					// 2

	"PAGE",					// 4

	"00/00",				// 5

};



#define STR_TOTAL_LEN	( 14 * DISPLAY_FILE_MAX + 19 + 3 + 1 + 2 + 4 + 5)



#define FLAG_NO_NEWDATA		0x01		// newdata 表示なし

#define FLAG_OVERWRITE		0x02		// overwrite

#define FLAG_LOADING		0x04		// load 中

#define FLAG_LOADCOMP		0x08		// load 終了

#define FLAG_LOADINVALID	0x10		// load したものが正しくない

#define FLAG_LOADERROR		0x20		// ロードエラー

#define FLAG_AFTERERROR		0x40		// エラー直後



extern void MENU_DrawPictureTex( int x, int y, int w, int h, int color, DG_TEX_LIN *tex, int flag );



typedef struct MCX_FILE_SELECT_PHOTO_LOAD{

	MCX_FILE_SELECT		fs;

	MCX_STRINGS			str_filename[ DISPLAY_FILE_MAX ];

	MCX_MENU_STRINGS	mstr_failed;

	

	int	ctr;			// 画像表示ロード開始までの時間

	int l2d_action;

	DG_TEX_LIN*		pTexlin;	// 画像表示用テクスチャ



	MCX_INTERP		intrp_photo;



	u_int	col;		// サムネール写真色



} MCX_FILE_SELECT_PHOTO_LOAD;





//// ローカル使用関数

static void PhotoDisp( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps ) // 写真の描画

{

	int i;

	int j;

	u_int col;

			

	u_int* pImage = (u_int*)ps->pTexlin->image;

	u_int* pDataBuffer = (u_int*)(((u_int)pm->pDataBuffer + 0xff) & ~0xff);

	for ( i = 0 ; i < PHOTO_TEX_H ; i++ ) {

		for ( j = 0 ; j < PHOTO_TEX_W ; j++ ) {

			*pImage++ = *(pDataBuffer + JPEG_W * (i * JPEG_H / PHOTO_TEX_H ) + j * JPEG_W / PHOTO_TEX_W );

		}

	}

#ifdef KP_WINDOWS

	DG_LinerTextureSetImageDirty(ps->pTexlin) ;	// 変更適用

#endif

	

	col = (((int) ps->intrp_photo.fCurrent) << 24) | ps->col;



	MENU_DrawPictureTex( SAMPLE_X , SAMPLE_Y + 1, SAMPLE_W - 1, SAMPLE_H - 1, col, ps->pTexlin, 0 );

}

////



static void ShowCurrentPage( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{	// 現在のページを制作して表示

	int start_file = DISPLAY_FILE_MAX * (ps->fs.curpage - 1);

	int i;

	for( i = start_file ; i < pm->nData && i < start_file + DISPLAY_FILE_MAX; i++ ) {

		if( MCX_GetFileInfo( i )->flag & MCX_FILEPROP_FLAG_DAMAGED ) {

			MCX_StringsPrintf( &ps->str_filename[ i - start_file ], "%02d DAMAGEDDATA",

							   MCX_GetFileInfo( i )->id );

		} else {

			MCX_StringsPrintf( &ps->str_filename[ i - start_file ], "%02d %s",

							   MCX_GetFileInfo( i )->id, MCX_GetFileInfo( i )->info.photoinfo.name );

		}

		MCX_StringsMove( &ps->str_filename[ i - start_file ], 3, NAME_X );

		if( ps->fs.cursel == i ) {

			MCX_StringsShow( &ps->str_filename[ i - start_file ], T_SHORT );

		} else {

			MCX_StringsNofocus( &ps->str_filename[ i - start_file ], T_SHORT );

		}

	}

	// ページ番号を表示

	MCX_StringsPrintf(&ps->fs.str_pagenum, "%02d/%02d", ps->fs.curpage, ps->fs.maxpage );

	{	// '/' の位置が合うように調整

		int diff;

		diff = PAGESLASH_X - (int)(ps->fs.str_pagenum.ppObj[ 2 ])->sprite.pos.x;

		for ( i = 0 ; i < ps->fs.str_pagenum.len ; i ++ ){

			(ps->fs.str_pagenum.ppObj[ i ])->sprite.pos.x += diff;

		}

	}

	MCX_StringsShow( &ps->fs.str_pagenum, T_SHORT );

	ps->fs.pIntrpJudge = &ps->str_filename[ 0 ].intrp_alpha;

}



static void HideCurrentPage( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{

	int i;

	for( i = 0 ; i < DISPLAY_FILE_MAX ; i++ ) {

		MCX_StringsHide( &ps->str_filename[ i ] , DIRECT_TICK( 10 ) );

	}



	ps->fs.pIntrpJudge = &ps->str_filename[ 0 ].intrp_alpha;

}



static void GuiLocal( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{	// ＧＵＩ非共通部分

	// カーソル

	SPR_SHOW( ps->fs.pSprcursor[ 0 ] );

	SPR_SHOW( ps->fs.pSprcursor[ 1 ] );

	ps->fs.pSprcursor[ 0 ]->empty.pos.y = ps->fs.intrp_cursor_y.fCurrent + CURSOR_Y_OFFSET;

	ps->fs.pSprcursor[ 1 ]->sprite.col.a = (u_char)ps->fs.intrp_cursor_a.fCurrent;



	if( ps->fs.flag & FLAG_LOADCOMP ) {

		// JPEGデータを表示する

		PhotoDisp( pm, ps );

	}

	if( ps->l2d_action != 0 && L2D_ActionStatus( pm->l2d_handle ) == L2D_STAT_ACK ) {

		L2D_EvokeAction( pm->l2d_handle, ps->l2d_action );

		ps->l2d_action = 0;

	}

}



static void GuiActive( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{

	// 	MCX_GUI_STATE_ACTIVE 時の処理

	//  photo load が特殊なために仮想化



	if( ps->fs.flag & FLAG_LOADERROR ) {	// エラー処理

		if( MCX_MStringsIsShow( &ps->mstr_failed ) 

			&& (pm->press & PAD_OK) ) {

			ps->fs.flag &= ~( FLAG_LOADERROR );

			ps->fs.flag |= FLAG_AFTERERROR;

			ps->fs.ShowCurrentPage( pm, ps );

			ps->fs.intrp_cursor_a.target = 0x80;

			ps->fs.intrp_cursor_a.ctr = T_MID;

			MCX_MStringsHide( &ps->mstr_failed, T_SHORT );

		}

		return;

	}



	if( ps->fs.intrp_cursor_y.ctr == 0

		&& L2D_ActionStatus( pm->l2d_handle ) == L2D_STAT_ACK )  {	// カーソルが移動中でない条件

		u_short press = pm->press;

		if( ps->fs.CursorMove( pm, ps, press ) ) {

			ps->ctr = 0;

			ps->fs.flag |= FLAG_LOADINVALID;

			ps->fs.flag &= ~FLAG_AFTERERROR;

			ps->intrp_photo.target = 0;

			ps->intrp_photo.ctr = DIRECT_TICK(10);

			return;

		}

		// ファイル決定判定

		if( press & PAD_OK ) {

			if( !(ps->fs.flag & FLAG_LOADINVALID)

				&& (ps->fs.flag & FLAG_LOADCOMP ) ) {

				HideCurrentPage( pm, ps );

				MCX_StringsHide( &ps->fs.str_page, DIRECT_TICK( 10 ) );

				MCX_StringsHide( &ps->fs.str_pagenum, DIRECT_TICK( 10 ) );

				SPR_HIDE( ps->fs.pSprcursor[ 0 ] );

				pm->pCurfile = MCX_GetFileInfo( ps->fs.cursel );

				MCX_ChangeState( &ps->fs.state, MCX_STATE_SL );

				SE_OK();

			}

		} else if ( press & PAD_CANCEL ) {

			// キャンセル

			pm->result = SAVEGAME_ANS_FAILED_CANCEL;

			MCX_ClearStart( MCX_STATE_FILE_SELECT );

			MCX_ChangeState( &ps->fs.state, MCX_STATE_END );

			SE_CANCEL();

			return;

		}

	}

	

	// 画像ロード開始判定

	if( ps->ctr++ > DIRECT_TICK( 30 ) && !( ps->fs.flag & FLAG_LOADING )

		&& ( !(ps->fs.flag & FLAG_LOADCOMP) || (ps->fs.flag & FLAG_LOADINVALID ) )

		&& !( ps->fs.flag & FLAG_AFTERERROR ) ){

		// HDD は早いので途中でキャンセルなし

		// 読み込んだあとにカーソルがあっていれば表示する

		pm->pCurfile = MCX_GetFileInfo( ps->fs.cursel );

		ps->l2d_action =  CODE_OPENNOWLOAD;

		MCX_QueueRequest( MCX_REQUEST_SAVE_GAME );

		ps->fs.flag |= FLAG_LOADING;

		ps->fs.flag &= ~(FLAG_LOADINVALID | FLAG_LOADCOMP );

		ps->ctr = 0;

	}

}



static void EnterYesNo( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps, int bNewdata )

{

}



static void ExitYesNo( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{

}



static void SetFileName( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{

	// ファイル名決定

	if( ps->fs.flag & FLAG_OVERWRITE ) {

		pm->pCurfile = MCX_GetFileInfo( ps->fs.cursel );

	} 

}



static void MoveFocus( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps, int prevsel )

{

	MCX_StringsShow( &ps->str_filename[ ps->fs.cursel % DISPLAY_FILE_MAX ], DIRECT_TICK( 10 ) );

	MCX_StringsNofocus( &ps->str_filename[ prevsel % DISPLAY_FILE_MAX ], DIRECT_TICK( 10 ) );

}



static void ClearStart( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{	// フェードアウト開始

	SPR_OBJ* pspr;

	int i;

	

	for ( i = 0 ; i < DISPLAY_FILE_MAX ; i++ ) {

		MCX_StringsHide( &ps->str_filename[ i ], DIRECT_TICK(20) );

	}

	MCX_StringsHide( &ps->fs.str_yes, DIRECT_TICK(20) );

	MCX_StringsHide( &ps->fs.str_slash, DIRECT_TICK(20) );

	MCX_StringsHide( &ps->fs.str_no, DIRECT_TICK(20));

	MCX_StringsHide( &ps->fs.str_page, DIRECT_TICK(20) );

	MCX_StringsHide( &ps->fs.str_pagenum, DIRECT_TICK(20) );

#if 0

	MCX_MStringsHide( &ps->fs.mstr_create, DIRECT_TICK(20) );

	MCX_MStringsHide( &ps->fs.mstr_overwrite, DIRECT_TICK(20) );

#endif

	MCX_MStringsHide( &ps->mstr_failed, T_MID );



//	L2D_EvokeAction( pm->l2d_handle, CODE_OPENSELFILE1 );

	L2D_EvokeAction( pm->l2d_handle, CODE_CLOSELIST );

//	L2D_EvokeAction( pm->l2d_handle, CODE_CLOSEALL );



	pspr = L2D_GetObject( pm->l2d_handle, CODE_OBJ_LOADING );

	SPR_HIDE( pspr );



	ps->fs.intrp_cursor_a.target = 0;

	ps->fs.intrp_cursor_a.ctr = DIRECT_TICK(20) ;



	ps->intrp_photo.target = 0;

	ps->intrp_photo.ctr = T_SHORT;

	

	if( pm->result != SAVEGAME_ANS_SUCCESS ) {

		SE_WINCLOSE();

	}

	

}



static void Handler( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps, int event )

{	// イベントハンドラ



	switch( event ) {

	case MCX_EVENT_MC_NULL:		// フォーカス中メモリカードが抜けた

	{

		pm->curdev = DEV_HDD;	// 次に移る（ＭＣに対応しないので組まない）

		break;

	}

	case MCX_EVENT_SL_SUCCESS:

	{

		// ロード成功

		ps->fs.flag |= FLAG_LOADCOMP;

		ps->fs.flag &= ~FLAG_LOADING;

		ps->l2d_action = CODE_CLOSENOWLOAD;

		if( !(ps->fs.flag & FLAG_LOADINVALID) ) {

			MCX_PHOTO_INFO* pInfo = &MCX_GetFileInfo( ps->fs.cursel )->info.photoinfo;

			

			ps->intrp_photo.target = 0x80;

			ps->intrp_photo.ctr = DIRECT_TICK( 20 );

			ps->col = pInfo->col[ 0 ] | ( pInfo->col[ 1 ] << 8 ) | ( pInfo->col[ 2 ] << 16 );

		}

		break;

	}

	case MCX_EVENT_SL_ERROR:

	{	// リトライするべき？

		char dataname[ MCX_MAX_GAMENAME ];

		ps->fs.flag |= FLAG_LOADERROR;

		ps->fs.flag &= ~(FLAG_LOADING | FLAG_LOADCOMP );



		// failed 時メッセージ

		sprintf( dataname, "%s %02d", FILE_NAME_PHOTO, pm->pCurfile->id );

		MCX_MStringsClearLine( &ps->mstr_failed);

		MCX_MStringsPrintf( &ps->mstr_failed,

							GetLocalResource( LOAD_GAME_RESOURCE, RES_LOAD_FAILED ) ,

							dataname );

		

		MCX_MStringsShow( &ps->mstr_failed, T_SHORT );

		ps->fs.HideCurrentPage( pm, ps );

		ps->l2d_action = CODE_CLOSENOWLOAD;

		

		ps->fs.intrp_cursor_a.target = 0;

		ps->fs.intrp_cursor_a.ctr = T_MID;

		break;

	}

	default:

		;

	}

}

	

static void Enter( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{	//

	int i;



	if( ps->fs.state.gui_state == MCX_GUI_STATE_IDLE ) {

		// 初回・初期化必要

		// L2D準備

		ps->fs.flag = 0;

		

//		pm->l2d_handle2 = L2D_LoadLayout( STR_LAYOUT2 , DG_CHANL_MENU , 1, 0 ) ; // 後に黒枠がくるため

//		L2D_EvokeAction( pm->l2d_handle2, CODE_DEFAULTACTION );

		

		// 文字準備

		ps->fs.ppobjbuf = (SPR_OBJ**)MCX_Malloc( sizeof(SPR_OBJ*) * STR_TOTAL_LEN );

		MCX_StringsInitBuffer( ps->fs.ppobjbuf, STR_TOTAL_LEN, pm->font_tri_handle,

							   TEX_STRCODE );

		for( i = 0 ; i < DISPLAY_FILE_MAX ; i++ ) {

			MCX_StringsCreate( &ps->str_filename[ i ], str_table[ 0 ], FILENAME_X, FILENAME_Y + FILENAME_YSTEP * i, STR_COLOR,

							   NOFOCUS_A );

		}

		MCX_StringsCreate( &ps->fs.str_yes, str_table[ 2 ], YES_X, YES_Y, STR_COLOR, NOFOCUS_A );

		MCX_StringsCreate( &ps->fs.str_slash, str_table[ 3 ], SLASH_X, SLASH_Y, STR_COLOR, NOFOCUS_A );

		MCX_StringsCreate( &ps->fs.str_no, str_table[ 4 ], NO_X, NO_Y, STR_COLOR, NOFOCUS_A );

		MCX_StringsCreate( &ps->fs.str_page, str_table[ 5 ], PAGE_X, PAGE_Y, STR_COLOR, NOFOCUS_A );

		MCX_StringsCreate( &ps->fs.str_pagenum, str_table[ 6 ], PAGENUM_X, PAGENUM_Y, STR_COLOR, NOFOCUS_A );



#if 0		

		MCX_MStringsCreate( &ps->fs.mstr_create, GM_GetResource( SAVE_GAME_RESOURCE, RES_NEWDATA ),

							OVER_WRITE_X, OVER_WRITE_Y, OVER_WRITE_W, OVER_WRITE_H,

							OVER_WRITE_U, OVER_WRITE_V, OVER_WRITE_UW, OVER_WRITE_VH, STR_COLOR );

		MCX_MStringsCreate( &ps->fs.mstr_overwrite, GM_GetResource( SAVE_GAME_RESOURCE, RES_OVERWRITE ),

							OVER_WRITE_X, OVER_WRITE_Y, OVER_WRITE_W, OVER_WRITE_H,

							OVER_WRITE_U, OVER_WRITE_V + OVER_WRITE_VH,

							OVER_WRITE_UW, OVER_WRITE_VH, STR_COLOR );

#endif		

		MCX_MStringsCreate( &ps->mstr_failed, GetLocalResource( LOAD_GAME_RESOURCE, RES_LOAD_FAILED ),

							FAILED_X, FAILED_Y, FAILED_W, FAILED_H,

							FAILED_U, FAILED_V, FAILED_UW, FAILED_VH, STR_COLOR );





		// str_page の大きさを変える

		(*ps->fs.str_page.ppObj)->sprite.dw = PAGE_W;

		(*ps->fs.str_page.ppObj)->sprite.dh = PAGE_H;

		MCX_StringsPrintf( &ps->fs.str_page, str_table[ 5 ] );

		// str_pagenum の大きさを変える

		(*ps->fs.str_pagenum.ppObj)->sprite.dw = PAGENUM_W;

		(*ps->fs.str_pagenum.ppObj)->sprite.dh = PAGENUM_H;



		// ページ数計算

		ps->fs.maxpage = (pm->nData - 1)/ DISPLAY_FILE_MAX + 1;

		ps->fs.flag |= FLAG_NO_NEWDATA;

		

//		ps->fs.curpage = ps->fs.maxpage;

		ps->fs.nselection = pm->nData;

//		ps->fs.cursel = ps->fs.nselection - 1;

		ps->fs.cursel = pm->latestfile;

		ps->fs.curpage = (ps->fs.cursel / DISPLAY_FILE_MAX) + 1;



		MCX_AddInterpService( &ps->fs.intrp_cursor_y );

		MCX_AddInterpService( &ps->fs.intrp_cursor_a );

		MCX_AddInterpService( &ps->intrp_photo );

		

		ps->l2d_action = CODE_OPENLISTSLOT1;



		// テクスチャ準備

		ps->pTexlin = DG_MakeLinerTexture( PHOTO_TEX_W, PHOTO_TEX_H, DG_TEXLIN_FORMAT_A8R8G8B8 );

	} else {

		// エディットからキャンセルされた

		ps->fs.flag &= FLAG_NO_NEWDATA;

		ps->l2d_action = CODE_CLOSEEDITSLOT1;

	}



	MCX_StringsShow( &ps->fs.str_page , DIRECT_TICK ( 30 ) );



	ShowCurrentPage( pm, ps );



	// カーソル準備

	ps->fs.pSprcursor[ 0 ] = L2D_GetObject( pm->l2d_handle, CODE_OBJ_CURSOR );

	ps->fs.pSprcursor[ 1 ] = ps->fs.pSprcursor[ 0 ]->head.child;

	SPR_SHOW( ps->fs.pSprcursor[ 0 ] );

	SPR_SHOW( ps->fs.pSprcursor[ 1 ] );

	

	ps->fs.pSprcursor[ 1 ] ->sprite.col.a = 0;

	ps->fs.intrp_cursor_y.fCurrent = (float) Select2Y( ps->fs.cursel );

	ps->fs.intrp_cursor_y.ctr = 0;

	ps->fs.intrp_cursor_a.fCurrent = 0.f;

	ps->fs.intrp_cursor_a.target = 0x80;

	ps->fs.intrp_cursor_a.ctr = DIRECT_TICK( 30 );



	ps->ctr = 0;



	ps->intrp_photo.fCurrent = 0.f;

	ps->intrp_photo.ctr = 0;



	ps->col = 0x808080;



	MCX_SetAutoRepeat( 10 );



#if 0	

	{	// 仮・前の画面を消しとく

		SPR_OBJ*	pspr;

		pspr = L2D_GetObject( pm->l2d_handle, CODE_OBJ_ROOT );

		SPR_HIDE( pspr );

	}

#endif	

}



static void Exit( MCX_MAN* pm, MCX_FILE_SELECT_PHOTO_LOAD* ps )

{	//

	int i;

	for ( i = 0 ; i < DISPLAY_FILE_MAX ; i++ ) {

		MCX_StringsDelete( &ps->str_filename[ i ] );

	}

	MCX_StringsDelete( &ps->fs.str_yes );

	MCX_StringsDelete( &ps->fs.str_slash );

	MCX_StringsDelete( &ps->fs.str_no );

	MCX_StringsDelete( &ps->fs.str_page );

	MCX_StringsDelete( &ps->fs.str_pagenum );



#if 0	

	MCX_MStringsDelete( &ps->fs.mstr_create );

	MCX_MStringsDelete( &ps->fs.mstr_overwrite );

#endif	

	MCX_MStringsDelete( &ps->mstr_failed );



	MCX_DeleteInterp( &ps->fs.intrp_cursor_y );

	MCX_DeleteInterp( &ps->fs.intrp_cursor_a );

	MCX_DeleteInterp( &ps->intrp_photo );

	MCX_Free( ps->fs.ppobjbuf );

	DG_FreeLinerTexture( ps->pTexlin );

	

//	L2D_ReleaseLayout( pm->l2d_handle2 );

}



MCX_STATE*	MCX_GetFileSelectPhotoLoad( void )

{

	MCX_FILE_SELECT_PHOTO_LOAD* ps;



	ps = (MCX_FILE_SELECT_PHOTO_LOAD *)MCX_Malloc( sizeof( MCX_FILE_SELECT_PHOTO_LOAD ) );



	MCX_SetFileSelect( &ps->fs );



	// override

	ps->fs.state.Enter = Enter;

	ps->fs.state.Exit = Exit;

	ps->fs.state.ClearStart = ClearStart;

	ps->fs.state.Handler = Handler;

	ps->fs.ShowCurrentPage = ShowCurrentPage;

	ps->fs.HideCurrentPage = HideCurrentPage;

	ps->fs.EnterYesNo = EnterYesNo;

	ps->fs.ExitYesNo = ExitYesNo;

	ps->fs.SetFileName = SetFileName;

	ps->fs.MoveFocus = MoveFocus;

	ps->fs.GuiLocal = GuiLocal;

	ps->fs.FileComplete = NULL;

	ps->fs.Select2Y = Select2Y;



	ps->fs.GuiActive = GuiActive;

	

	return &ps->fs.state;

}



#endif //BP