import {AgencyBaseControl} from "./AgencyBaseControl";
import {SkinData} from "../Data/SkinData";
import { ViewManager } from "../View/ViewManager";
import {TrialPanel} from "../View/TrialPanel";
import {GameStateControl} from "../Control/GameStateControl";
import { AssetPath } from "../Config/AssetPath";
import {ResourceControl} from "../Control/ResourceControl";
import {SceneControl} from "../Control/SceneControl";
import { AgencyInGame } from "./AgencyInGame";
import { FYHD_Sdk } from "../WXSDK/FYHD_Sdk";
import EggView from "../View/EggPanel";
import EggPanel from "../View/EggPanel";
import { GameUtils } from "../utils/GameUtils";
import { PlayerAccount } from "../WXSDK/PlayerAccount";

export class AgencyTrial extends AgencyBaseControl 
{
    static key:string = "AgencyTrial";

    isshiyonging:boolean = false;

   private sprit:Laya.Sprite;
    
    constructor() 
    { 
        super(); 
    }

    public openview( arr:Array<SkinData> ):void
    {
        ViewManager.Instance.add( TrialPanel,arr );
    }

    /**退出界面 */
    public ExitPanel( _data:SkinData ):void
    {
        this.isshiyonging = _data ? true:false;
        this._selectvo = _data;
        if( _data )
        {
            var urlArr:Array<any> = [];
            urlArr.push( { url:AssetPath.get3DRoleModel( _data.roleCFG.name )} );
            ResourceControl.Instance.loader3DArr( urlArr,this,this.SceneCreateComplete,null,true );
        }
        else
        {
            // if(AgencyInGame.gamenum>1){
                let random = Math.random();
                if(PlayerAccount.CurrentAccount.CurAccountData.WhiteUser &&  random<= PlayerAccount.CurrentAccount.CurAccountData.HitEgg){
                    ViewManager.Instance.add(EggPanel);
                }
                else{
                    GameStateControl.Instance.entergame();
                }
            // }
            // else{
            //     GameStateControl.Instance.entergame();
            // }
            
        }
        ViewManager.Instance.close( TrialPanel );
    }

    private _selectvo:SkinData;

    /************************************************ */
    private createSprite(): void {
        this.sprit = new Laya.Sprite();
        this.sprit.graphics.drawRect(0, 0, 200, 200, "#D2691E");
        this.sprit.pivot(100, 100);

        this.sprit.x = Laya.stage.width / 2;
        this.sprit.y = Laya.stage.height / 2;

        this.sprit.size(200, 200);
        Laya.stage.addChild(this.sprit);

        // this.sp.on(Interaction_CustomEvent.ROTATE, this, this.onRotate);    // 侦听自定义的事件
        // this.sprit.on(Event.CLICK, this, this.onSpriteClick);
    }

    private onSpriteClick(e: Event): void {
        var randomAngle: number = Math.random() * 180;
        //发送自定义事件
        // this.sprit.event(Interaction_CustomEvent.ROTATE, [randomAngle]);
    }

    // 触发自定义的rotate事件
    private onRotate(newAngle: number): void {
        // Tween.to(this.sp, { "rotation": newAngle }, 1000, Ease.elasticOut);
    }
    /******************************* */

    private SceneCreateComplete():void
    {
        SceneControl.Instance.CreatePlayer(this._selectvo.roleCFG);
        if(AgencyInGame.gamenum>1){
            if(PlayerAccount.CurrentAccount.CurAccountData.WhiteUser){
                ViewManager.Instance.add(EggPanel);
            }
            else{
                GameStateControl.Instance.entergame();
            }
        }
        else{
            GameStateControl.Instance.entergame();
        }
    }


    /******************************* */
    private createText(): void {
        var txt: Laya.Text = new Laya.Text();
        //给文本的text属性赋值
        txt.text = "Layabox是性能最强的HTML5引擎技术提供商与优秀的游戏发行商，面向Flash开发者提供HTML5开发技术方案！";
        //设置宽度，高度自动匹配
        txt.width = 400;
        //自动换行
        txt.wordWrap = true;

        txt.align = "center";
        txt.fontSize = 40;
        txt.font = "Microsoft YaHei";
        txt.color = "#ff0000";
        txt.bold = true;
        txt.leading = 5;

        //设置描边属性
        txt.stroke = 2;
        txt.strokeColor = "#ffffff";

        txt.borderColor = "#00ff00"

        txt.x = (Laya.stage.width - txt.textWidth) / 2;
        txt.y = (Laya.stage.height - txt.textHeight) / 2;

        Laya.stage.addChild(txt);
    }
    /************************** */


    


    private createInput(): void {
        var inputText:Laya.Input = new Laya.Input();

        // 移动端输入提示符
        inputText.prompt = "Type some word...";

        //多行输入
        inputText.multiline = true;
        inputText.wordWrap = true;

        inputText.size(350, 100);
        inputText.x = Laya.stage.width - inputText.width >> 1;
        inputText.y = Laya.stage.height - inputText.height >> 1;
        inputText.padding = [2, 2, 2, 2];

        inputText.bgColor = "#666666";
        inputText.color = "#ffffff";
        inputText.fontSize = 20;

        Laya.stage.addChild(inputText);
    }
 
}