import {PanelResDic} from "../PrefabControl/PanelResDic";
import { DispatcherManager } from "../utils/DispatcherManager";
import {Singleton} from "../utils/Singleton";
import {ServerSocket} from "../WXSDK/ServerSocket";
import {RoleData} from "../Data/RoleData";

/*
* name;
*/
export class AgencyBaseControl extends Singleton
{
    private _objectPool: PanelResDic;

    private sp:Laya.Sprite;

    constructor(){
        super();
        this._objectPool = PanelResDic.Instance;
        this.initSelf();
    }
    protected initSelf():void
    {

    }

    /**********混淆 */
    private drawSomething(): void {
        this.sp = new Laya.Sprite();
        Laya.stage.addChild(this.sp);
        //画线
        this.sp.graphics.drawLine(10, 58, 146, 58, "#ff0000", 3);
        //画连续直线
        this.sp.graphics.drawLines(176, 58, [0, 0, 39, -50, 78, 0, 117, 50, 156, 0], "#ff0000", 5);
        //画曲线
        this.sp.graphics.drawCurves(352, 58, [0, 0, 19, -100, 39, 0, 58, 100, 78, 0, 97, -100, 117, 0, 136, 100, 156, 0], "#ff0000", 5);
        //画矩形
        this.sp.graphics.drawRect(10, 166, 166, 90, "#ffff00");
        //画多边形
        this.sp.graphics.drawPoly(264, 166, [0, 0, 60, 0, 78.48, 57, 30, 93.48, -18.48, 57], "#ffff00");
        //画三角形
        this.sp.graphics.drawPoly(400, 166, [0, 100, 50, 0, 100, 100], "#ffff00");
        //画圆
        this.sp.graphics.drawCircle(98, 332, 50, "#00ffff");
        //画扇形
        this.sp.graphics.drawPie(240, 290, 100, 10, 60, "#00ffff");
        //绘制圆角矩形，自定义路径
        this.sp.graphics.drawPath(400, 310, [["moveTo", 5, 0], ["lineTo", 105, 0], ["arcTo", 110, 0, 110, 5, 5], ["lineTo", 110, 55], ["arcTo", 110, 60, 105, 60, 5], ["lineTo", 5, 60], ["arcTo", 0, 60, 0, 55, 5], ["lineTo", 0, 5], ["arcTo", 0, 0, 5, 0, 5], ["closePath"]], {fillStyle: "#00ffff"});
    }
    /********** */

    /**
     *  注册全局侦听事件
     * 
     */
    protected DisOn( type:string, callbackobj:any, callbackHandler:Function ):void
    {
        DispatcherManager.addEventListener(type, callbackobj, callbackHandler );
    }

    /**
     *  抛出全局事件 
     */
    protected DisTrigger(type:string, data:any = null):void
	{
        DispatcherManager.dispatchEvent( type, data );
    }

    /**
     * 移除全局侦听事件
     */
    protected DisOff(type:string,callbackobj:any, callbackHandler:Function):void
    {
        DispatcherManager.removeEventListener(type, callbackobj, callbackHandler );
    }

    /************************** */
    private setup(): void {
        var textBox:Laya.Sprite = new Laya.Sprite();

        // 随机摆放文本
        var text:Laya.Text;
        for (var i: number = 0; i < 1000; i++) {
            text = new Laya.Text();
            text.fontSize = 20;
            text.text = (Math.random() * 100).toFixed(0);
            text.rotation = Math.random() * 360;
            text.color = "#CCCCCC";

            text.x = Math.random() * Laya.stage.width;
            text.y = Math.random() * Laya.stage.height;

            textBox.addChild(text);
        }
        //缓存为静态图像
        textBox.cacheAs = "bitmap";

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

    protected getSingleTon(ref:any):any
	{
        return this._objectPool.getSingleTon(ref);
    }

    protected sendMessage( act:string,data:any = null,isShowWait:boolean = true ):void
    {
        ServerSocket.Instance.sendMessage(act, data, isShowWait);
    }

    private roleData:RoleData;

    public get RoleData():RoleData
    {
        if (!this.roleData){
            this.roleData = RoleData.Instance;
        }
        return this.roleData;
    }
}