/*
文件名:1_Select_Character.nut
路径:User/UI/Window/1_Select_Character.nut
创建日期:2024-12-13	15:45
文件用途:选择角色界面窗口
*/
class _Select_Character_SettingBackground_Object_Window extends Yosin_CommonUi {

    //蓝色悬停框
    RectMask = null;
    //黄色选中框
    SelectMask = null;
    //选中状态
    SelectFlag = false;


    constructor(x, y, width, height, Idx) {
        base.constructor(x, y, width, height);

        //注册绘制
        RegisterDraw(Idx);
    }

    function RegisterDraw(Idx) {
        //背景
        local Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/small/background_small_event.img", Idx);
        Background.SetScale(0.7, 0.7);
        Addchild(Background);

        RectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 18);
        RectMask.SetVisible(false);
        Addchild(RectMask);

        SelectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 19);
        SelectMask.SetPosition(-2, -2);
        SelectMask.SetVisible(false);
        Addchild(SelectMask);
    }

    //override
    function Proc(Dt) {
        base.Proc(Dt);
        if (isInRect && !SelectFlag) {
            RectMask.SetVisible(true);
        } else {
            RectMask.SetVisible(false);
        }

    }


    //鼠标左键单击回调
    function OnMouseLbClick(MousePos_X, MousePos_Y) {
        base.OnMouseLbClick(MousePos_X, MousePos_Y);
        if (isInRect) {
            SelectMask.SetVisible(true);
            SelectFlag = true;
        }
    }
}
class _Select_Character_SettingBackground_Window extends Yosin_Window {

    //是否为独立窗口
    IsIndependent = false;

    //是否可见
    Visible = false;

    constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
        base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);

        //注册绘制
        RegisterDraw();
    }

    function RegisterDraw() {
        //背景
        local Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17);
        Addchild(Background);

        for (local i = 0; i< 24; i++) {
            local Buf = _Select_Character_SettingBackground_Object_Window(10 + (101 * (i % 2)), 10 + (61 * (i / 2)), 91, 51, i);
            AddUIChild(Buf);
        }
    }


    //逻辑入口
    function Proc(Dt) {
        SyncPos(X, Y);
        base.Proc(Dt);
    }

}
class _Select_Character_Window extends Yosin_Window {
    //调试模式
    // DeBugMode = true;

    //不是窗口
    // NoWindow = true;

    //是否可见
    // Visible = false;

    //背景音乐
    BackGroundMusic = null

    //设置背景图片窗口
    SettingBackgroundWindow = null;
    //背景图片
    BackGround = null;

    //信息
    Info = null;


    constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
        base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
    }

    function Init(gInfo) {
        //接收参数信息
        Info = gInfo;

        //注册绘制
        RegisterDraw();
        //注册控件
        RegisterWidget();
        //注册窗口
        RegisterWindow();
        // OpenDeBug();

        //播放音乐
        PlayBackgroundMusic();
    }

    function PlayBackgroundMusic() {
        // BackGroundMusic = Sound("SoundPacks/Loop.ogg");
        // BackGroundMusic.Play();
    }

    function MusicLogic() {
        if (BackGroundMusic == null) return;
        if (!BackGroundMusic.IsPlaying()) BackGroundMusic.Play();
    }

    function RegisterWindow() {
        SettingBackgroundWindow = _Select_Character_SettingBackground_Window("选择角色_设置背景图片窗口", 850, 28, 212, 129, 0);
        AddUIChild(SettingBackgroundWindow);
    }

    function RegisterWidget() {
        //背景设置按钮
        local SettingButton = Yosin_BaseButton(984, 6, 77, 24 "sprite/interface2/ui/community/guild_2019/guildsetting/guildsetting.img", 29);
        //点击事件回调
        SettingButton.OnClick = function(Button) {
            SettingBackgroundWindow.SetVisible(!SettingBackgroundWindow.Visible)
        }.bindenv(this);
        AddUIChild(SettingButton);
        //登录按钮文本
        local LoginTextActor = FontAssetManager.GenerateNormal("背景设置", sq_RGBA(221, 197, 147, 255), true);
        LoginTextActor.SetPosition(23, 3);
        LoginTextActor.SetUpdateFunc(function(Text, Dt) {
            if (Text.Parent.State == 1 || Text.Parent.State == 2) {
                Text.SetFillColor(sq_RGBA(255, 255, 184, 255));
            } else if (Text.Parent.State == 0) {
                Text.SetFillColor(sq_RGBA(221, 197, 147, 255));
            }
        })
        SettingButton.Addchild(LoginTextActor);
    }

    function RegisterDraw() {
        //大背景 根据玩家的设定背景决定
        BackGround = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large.img", Info.Background);
        Addchild(BackGround);

    }


    //逻辑入口
    function Proc(Dt) {
        MusicLogic();

        SyncPos(X, Y);
        base.Proc(Dt);
    }

}