import { _decorator, Component, instantiate, Node, SpringJoint2D, Sprite, SpriteFrame, TypeScript, UITransform, Vec2 } from 'cc';
import { resMgr } from '../../Frames/ResourcesMgr';
import { RoleList } from './RoleList';
import { RoleCard } from './RoleCard';
const { ccclass, property } = _decorator;

@ccclass('CharacterSlotMgr')
export class CharacterSlotMgr extends Component {
    private _roleList: Node = null;
    protected onLoad(): void {
        this._roleList = this.node.parent.parent.getChildByName("RoleList");
    }
    start() {

    }

    removeCardImg(pos: Vec2) {
        for (const element1 of this.node.children) {
            const box = element1.getComponent(UITransform).getBoundingBoxToWorld();
            if (box.contains(pos)) {
                let a: Node = element1.getChildByName('Sprite');
                if(!a.getComponent(Sprite).spriteFrame){
                    return;
                }
                for (const element2 of this._roleList.getChildByPath("view/content").children) {
                    if (element2.getChildByName("Role_Img").getComponent(Sprite).spriteFrame.name === a.getComponent(Sprite).spriteFrame.name) {
                        element2.getComponent(RoleCard).isOpenShadow(false);
                        a.getComponent(Sprite).spriteFrame = null;
                        return;
                    }
                }
            }
        }
    }
}


