#include <all.inc>
#include "../message.inc"

main() {


/*--------------------------------------------------------------------*/
	{
		static info[128] = "";
		static str_bd[128] = "../sound/HuCH_bom_bgm.bde";
		static str_hd[128] = "../sound/HuCH_bom_bgm.hde";
		static str_sq[128] = "../sound/HuCH_bom_bgm.sqe";
		static str_se_bd[128] = "../sound/HuCH_bom_se.bde";
		static str_se_hd[128] = "../sound/HuCH_bom_se.hde";

	 	soundGetInfo( SOUND_INFO_BGM_STATE, info ); // 再生中かどうか

		//  再生中
		if( info[0]!=SOUND_BGM_STATE_STOP ) {
			new bool:is_changed = true;

			xmlMakeFullPath( str_bd, sizeof str_bd );
			xmlMakeFullPath( str_hd, sizeof str_hd );
			xmlMakeFullPath( str_sq, sizeof str_sq );

			soundGetInfo( SOUND_INFO_BGM_BD_PATH, info ); // bd の uri
			if( strcmp(info,str_bd) == 0 ) { is_changed = false; }
			soundGetInfo( SOUND_INFO_BGM_HD_PATH, info ); // hd の uri
			if( strcmp(info,str_hd) == 0 ) { is_changed = false; }
			soundGetInfo( SOUND_INFO_BGM_SQ_PATH, info ); // sq の uri
			if( strcmp(info,str_sq) == 0 ) { is_changed = false; }

			if( is_changed ) { // BGMを読み込み、再生する必要があるか
				soundBgmStop();
				soundBgmLoadStart( str_bd, str_hd, str_sq );
				soundBgmLoadWait();
				soundSeLoadStart( str_se_bd, str_se_hd );
				soundSeLoadWait();
				soundBgmSeek(0);
				soundBgmPlay();
			}
	
		//  停止中ならリロード＆再生
		} else {
			soundBgmLoadStart( str_bd, str_hd, str_sq );
			soundBgmLoadWait();
			soundSeLoadStart( str_se_bd, str_se_hd );
			soundSeLoadWait();
			soundBgmSeek(0);
			soundBgmPlay();
		}
	}
/*--------------------------------------------------------------------*/

	/* ＢＧが違ってれば再ロード *//* <20030627> */
	new name[128];
	if(wndGetName(WND_BG, name) && !strcmp(name, "main")){
		xmlLoadStart( "../bg.xml", "main", _, XMLLOAD_MODE_BG );
		xmlLoadWait();
	}

  SetSystemParam( SYSTEM_PARAM_PADHELP_ONOFF, PAD_HELP_RD );

  SendMessage( wndGetScene( WND_BG ), BG_CHANGE_TEXTURE, 1 );
  SendMessage( wndGetScene( WND_BG ), BG_FADEIN );

  new obj:news = CreateNull( Disp2D() );
  SetPos( news, 120.0, 155.0, 1.0 );
  AttachScript( news, _, "textbox", "id=news" );
  SetPubVar( news, "visible", 10 );
  SetPubVar( news, "height", 15.0 );
  SetPubVar( news, "width", 400.0 );
  SetPubVar( news, "length", 210.0+40.0 );
  SetPubVar( news, "bg_red", 0.2 );
  SetPubVar( news, "bg_green", 0.6 );
  SetPubVar( news, "bg_blue", 1.0 );
  //	SetPubVar( news, "bg_alpha", 0.2 );
  SetPubVar( news, "bg_alpha", 0.6 );

  new obj:mask = CreatePlane3x3( Disp2D() );
  SetPos( mask, 320.0, 224.0, 1.0 );
  SetScale( mask, 640.0, 448.0, 0.0 );
  SetColor( mask, 0.0, 0.0, 0.0, 0.0 );
  SetOptionI( mask, TAG("ZSRT"), ZSORT_BOTTOM_MOST );

  for(new float:i=0.0;i<0.7;i+=0.02){
    SetColor( mask, 0.0, 0.0, 0.0, i );
    sleep;
  }
  SetColor( mask, 0.0, 0.0, 0.0, 0.7 );

  for(;;) {
    new paddata;
    PadState( _, paddata );

    if( paddata & ePADRdown ) {
      soundSePlay( 15, 127 );
      SendMessage( wndGetScene( WND_BG ), BG_FADEOUT );
      Destroy( news );
      SetSystemParam( SYSTEM_PARAM_PADHELP_ONOFF, PAD_HELP_RR | PAD_HELP_RD );

      xmlLoadStart( "../huch.xml" );
      xmlLoadWait();

      break;
    }
    sleep;
  }
  return;
}
