//
//      このスクリプトの整形に「桜宮の部屋」のまあささんのスクリプトを
//      参考にさせていただきました｡
//      HP  ｢桜宮の部屋｣  http://oukyu.oheya.to/
//

//#############################################################################
//                      Fate 桜 Skin
//#############################################################################

//--------------------初期設定--------------------------------------------------

#include "std.mi"

/*******************************************************************************
//      自作関数宣言
*******************************************************************************/

Function fn_AlphaChange(Guiobject L,int TargetA,Float Speed); // テキストのフェード
Function fn_Time(); // 時間の表示

/*******************************************************************************
//      グローバル関数宣言
*******************************************************************************/

//グローバル関数//

Class  Text           txtTime;

Global Group          grpTimeGroup;
Global Group          grpTimeSmallGroup;
Global Group          grpTimeLargeGroup;
Global Group          grpTimeMinusGroup;
Global Group          grpTimeShadowGroup;

Global txtTime        txtTime_1;
Global txtTime        txtTime_2;
Global txtTime        txtTime_3;
Global txtTime        txtTime_4;
Global txtTime        txtTime_5;
Global txtTime        txtTime_6;
Global txtTime        txtTime_7;
Global txtTime        txtTime_8;

Global Layer          lyrShadow;

Global Timer          tmrSongTimeTimer;
Global Int            intTimeShowFLG;           //時間表示のモード 0:標準 1:マイナス 2:非表示
Global Boolean        blnCheckFLG;              //表示切り替え時のフェードチェック

/*******************************************************************************
//      #System.onScriptLoaded()
//      スクリプト起動時に実行される｡
//      初期設定
*******************************************************************************/

System.onScriptLoaded(){

        //オブジェクト設定
        grpTimeGroup         = getScriptGroup();
        grpTimeSmallGroup    = grpTimeGroup.findObject("Player.Timer.Small.Group");
        grpTimeLargeGroup    = grpTimeGroup.findObject("Player.Timer.Large.Group");
        grpTimeMinusGroup    = grpTimeGroup.findObject("Player.Timer.Minus.Group");
        grpTimeShadowGroup   = grpTimeGroup.findObject("Player.Timer.Shadow.Group");

        txtTime_1    = grpTimeMinusGroup.findObject("Time_1");
        txtTime_2    = grpTimeLargeGroup.findObject("Time_2");
        txtTime_3    = grpTimeLargeGroup.findObject("Time_3");
        txtTime_4    = grpTimeLargeGroup.findObject("Time_4");
        txtTime_5    = grpTimeLargeGroup.findObject("Time_5");
        txtTime_6    = grpTimeSmallGroup.findObject("Time_6");
        txtTime_7    = grpTimeSmallGroup.findObject("Time_7");
        txtTime_8    = grpTimeSmallGroup.findObject("Time_8");

        lyrShadow    = grpTimeSmallGroup.findObject("Timer.Shadow");

        //タイマー設定
        tmrSongTimeTimer = new Timer;
        tmrSongTimeTimer.setDelay(50);

        //前回の状態をロード
        intTimeShowFLG = System.getPrivateInt("Trans_Peace@Pieces", "Time", 0);

        if (getStatus() == 1 && intTimeShowFLG != 2) {//停止中で無く、非表示状態でなければ時間取得&表示
          fn_Time();
          fn_AlphaChange(txtTime_1,255,0.7);
          fn_AlphaChange(txtTime_2,255,0.7);
          fn_AlphaChange(txtTime_3,255,0.7);
          fn_AlphaChange(txtTime_4,255,0.7);
          fn_AlphaChange(txtTime_5,255,0.7);
          fn_AlphaChange(txtTime_6,255,0.7);
          fn_AlphaChange(txtTime_7,255,0.7);
          fn_AlphaChange(txtTime_8,255,0.7);
          fn_AlphaChange(lyrShadow,180,0.7);
          tmrSongTimeTimer.start();
        }

}


/*******************************************************************************
//      #System.onScriptUnLoaded()
//      スクリプト終了時に実行される｡
*******************************************************************************/

System.onScriptUnloading() {

        System.setPrivateInt("Trans_Peace@Pieces", "Time", intTimeShowFLG);//時間の表示状態の保存

        Delete tmrSongTimeTimer;
}


/*******************************************************************************
//      #System.onPlay()
//      条件：再生開始時に呼び出される｡
//      機能：tmrSongTimeTimerをスタートさせる｡
*******************************************************************************/

// 再生開始時にタイマースタート
system.onplay() {

        if (intTimeShowFLG != 2) {

          tmrSongTimeTimer.start();

          //テキストのフェードイン
          fn_AlphaChange(txtTime_1,255,0.7);
          fn_AlphaChange(txtTime_2,255,0.7);
          fn_AlphaChange(txtTime_3,255,0.7);
          fn_AlphaChange(txtTime_4,255,0.7);
          fn_AlphaChange(txtTime_5,255,0.7);
          fn_AlphaChange(txtTime_6,255,0.7);
          fn_AlphaChange(txtTime_7,255,0.7);
          fn_AlphaChange(txtTime_8,255,0.7);
          fn_AlphaChange(lyrShadow,180,0.7);
        }
}


/*******************************************************************************
//      #System.onStop()
//      条件：再生停止時に呼び出される｡
//      機能：表示切替
*******************************************************************************/

system.onstop() {

        if (intTimeShowFLG != 2) {

          tmrSongTimeTimer.stop();

          //テキストのフェードアウト
          fn_AlphaChange(txtTime_1,0,0.7);
          fn_AlphaChange(txtTime_2,0,0.7);
          fn_AlphaChange(txtTime_3,0,0.7);
          fn_AlphaChange(txtTime_4,0,0.7);
          fn_AlphaChange(txtTime_5,0,0.7);
          fn_AlphaChange(txtTime_6,0,0.7);
          fn_AlphaChange(txtTime_7,0,0.7);
          fn_AlphaChange(txtTime_8,0,0.7);
          fn_AlphaChange(lyrShadow,0,0.7);
        }

}


/*******************************************************************************
//      #tmrSongTimeTimer.onTimer()
//      条件：tmrSongTimeTimerのスタート後50msごとに呼び出される｡
//      機能：表示時間の取得、更新
*******************************************************************************/

tmrSongTimeTimer.onTimer() {

        fn_Time();
}


/*******************************************************************************
//      #txtTime.onLeftButtonUp(
//        int x         //X軸
//        int y         //Y軸
//      )
//      条件：txtTimeでクリックされた時
//      機能：時間の表示方を切り替える
*******************************************************************************/

txtTime.onLeftButtonUp(int x, int y) {

        if (intTimeShowFLG == 0) intTimeShowFLG = 1;
        else if (intTimeShowFLG == 1) intTimeShowFLG = 2;
        else if (intTimeShowFLG == 2) intTimeShowFLG = 0;

        if (getStatus() != 0) { // 再生中なら･･･
          tmrSongTimeTimer.stop();
          if (intTimeShowFLG != 2) blnCheckFLG = 1;//切り替え時のフェードチェックON

          //テキストのフェードアウト
          fn_AlphaChange(txtTime_1,0,0.7);
          fn_AlphaChange(txtTime_2,0,0.7);
          fn_AlphaChange(txtTime_3,0,0.7);
          fn_AlphaChange(txtTime_4,0,0.7);
          fn_AlphaChange(txtTime_5,0,0.7);
          fn_AlphaChange(txtTime_6,0,0.7);
          fn_AlphaChange(txtTime_7,0,0.7);
          fn_AlphaChange(txtTime_8,0,0.7);
          fn_AlphaChange(lyrShadow,0,0.7);
        }
}


/*******************************************************************************
//      #txtTime_6.onTargetReached()
//      条件：txtTime_6 のフェードが止まった時
//      機能：表示変更時なら切り替え
*******************************************************************************/

txtTime_6.onTargetReached() {

        if (blnCheckFLG) {//切り替え時のフェードチェックが ON の時
          fn_Time();
        }
}


/*--------------自作関数------------------------------------------------------*/

/*******************************************************************************
//      #fn_AlphaChange(
//        Text     L        //フェードさせるテキスト
//        int      TargetA  //フェードするアルファ値
//        float    Speed    //フェードする時間(0.1 = 100ms)
//      )
//      機能：テキストのフェード
*******************************************************************************/

fn_AlphaChange(Guiobject L,int TargetA,Float Speed) {

          L.setTargetA(TargetA);
          L.setTargetSpeed(Speed);
          L.gotoTarget();
}


/*******************************************************************************
//      #fn_Time()
//      機能：時間の表示
*******************************************************************************/

fn_Time() {

        string t;
        int len;
        int slid;
        //tmrSongTimeTimer.start();

        //時間取得
        if (intTimeShowFLG == 0) {//通常表示の時
          t = System.integerToTime(System.getPosition());
          grpTimeMinusGroup.hide();
          slid = 0;
        } else if (intTimeShowFLG == 1){//マイナス表示の時
          t = System.integerToTime(System.getPlayItemLength() - System.getPosition());
          //t = "-" + t;
          grpTimeMinusGroup.show();
          slid = 9;
        }

        len = System.strlen(t);

          txtTime_7.setText(System.strmid(t,len-1,1));
          txtTime_6.setText(System.strmid(t,len-2,1));
          //txtTime_5.setText("a");
          txtTime_4.setText(System.strmid(t,len-4,1));
          txtTime_3.setText(System.strmid(t,len-5,1));
          txtTime_2.setText(System.strmid(t,len-6,1));
          //txtTime_1.setText("b");

        if(len == 4) {
          grpTimeLargeGroup.setXMLparam("x" , integerToString( (-34) + slid ) );
          grpTimeLargeGroup.setXMLparam("y" , "17");
          grpTimeSmallGroup.setXMLparam("x" , integerToString( (26) + slid ) );
          grpTimeSmallGroup.setXMLparam("y" , "8");
          grpTimeShadowGroup.setXMLparam("x" , integerToString( (-42) + slid ) );
          grpTimeShadowGroup.setXMLparam("y" , "3");
        }

        else if(len == 5) {
          grpTimeLargeGroup.setXMLparam("x" , integerToString( (-17) + slid ) );
          grpTimeLargeGroup.setXMLparam("y" , "13");
          grpTimeSmallGroup.setXMLparam("x" , integerToString( (43) + slid ) );
          grpTimeSmallGroup.setXMLparam("y" , "4");
          grpTimeShadowGroup.setXMLparam("x" , integerToString( (-25) + slid ) );
          grpTimeShadowGroup.setXMLparam("y" , "-1");
        }

        else if(len == 6) {
          grpTimeLargeGroup.setXMLparam("x" , integerToString( (0) + slid ) );
          grpTimeLargeGroup.setXMLparam("y" , "9");
          grpTimeSmallGroup.setXMLparam("x" , integerToString( (60) + slid ) );
          grpTimeSmallGroup.setXMLparam("y" , "0");
          grpTimeShadowGroup.setXMLparam("x" , integerToString( (-8) + slid ) );
          grpTimeShadowGroup.setXMLparam("y" , "-5");
        }
/*
        else if(len == 7) {
          grpTimeLargeGroup.setXMLparam("x" , integerToString( (0) + slid ) );
          grpTimeLargeGroup.setXMLparam("y" , "0");
          grpTimeSmallGroup.setXMLparam("x" , integerToString( (69) + slid ) );
          grpTimeSmallGroup.setXMLparam("y" , "1");
          grpTimeShadowGroup.setXMLparam("x" , integerToString( (0) + slid ) );
          grpTimeShadowGroup.setXMLparam("y" , "-14");
        }
*/
        if (blnCheckFLG) {//切り替え時のフェードチェックが ON の時
          tmrSongTimeTimer.start();
          //フェードイン
          fn_AlphaChange(txtTime_1,255,0.7);
          fn_AlphaChange(txtTime_2,255,0.7);
          fn_AlphaChange(txtTime_3,255,0.7);
          fn_AlphaChange(txtTime_4,255,0.7);
          fn_AlphaChange(txtTime_5,255,0.7);
          fn_AlphaChange(txtTime_6,255,0.7);
          fn_AlphaChange(txtTime_7,255,0.7);
          fn_AlphaChange(txtTime_8,255,0.7);
          fn_AlphaChange(lyrShadow,180,0.7);
          blnCheckFLG = 0;//チェックOFF
        }


}
