123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { _decorator, AssetManager, Button, Component, instantiate, Node, Prefab, sp, Vec2 } from 'cc';
- import { allSkinList, getAllSkinKeys, Skin, SkinData } from '../../script/Manager/LocalDataMgr';
- import { SkinItem } from './SkinItem';
- import { LayerMgr } from '../../script/Manager/LayerMgr';
- import { BundleName } from '../../script/Config/EnumCfg';
- import EventMgr from '../../script/Manager/EventMgr';
- const { ccclass, property } = _decorator;
- @ccclass('SelectSkinPanel')
- export class SelectSkinPanel extends Component {
- @property(Node)
- itemRoot: Node = null;
- @property(Node)
- itemPrefab: Node = null;
- @property({type:Vec2,tooltip:"spine偏移量"})
- spineoffset:Vec2 = new Vec2(0,0);
- @property(Button)
- btnClose: Button = null;
- _skinData: SkinData = null
- _allSkinList:{ [key: number]: string };
- _items: Node[] = [];
- _hasCreatedItems:boolean = false;
- protected start(): void {
- this.btnClose.node.on(Node.EventType.TOUCH_END,this.onBtnCloseClick,this)
- }
- init() {
- if(this._hasCreatedItems) return;
- this._hasCreatedItems = true;
- this._allSkinList = allSkinList
- this._skinData = Skin.getSkinData();
- let allSkillKeys = getAllSkinKeys()
- let count = allSkillKeys.length;
- for (let i = 0; i < count; i++) {
- this.createItem(allSkillKeys[i], this.spineoffset);
- }
- }
- onBtnCloseClick()
- {
- this.node.active = false
- EventMgr.ins.dispatchEvent("regenerate")
- }
- createItem(key: number,spineOffset:Vec2) {
- let itemNode = instantiate(this.itemPrefab);
- itemNode.parent = this.itemRoot;
- this._items.push(itemNode);
- itemNode.active = true
- let spPath = allSkinList[key]
- this.loadSpineData("editor",spPath, (spine: Prefab) => {
- itemNode.getComponent(SkinItem).init(key,spine,"loop2",spineOffset,this.judgeSelect(key))
- })
- }
- onSingleSkinClick() {
- Skin.setSelectStatu(true)
- }
- onMultiSkinClick() {
- Skin.setSelectStatu(false)
- }
- judgeSelect(key)
- {
- let selSkins = this._skinData.selectedSkinList
- let index = selSkins.indexOf(key)
- return index !== -1
- }
- // spineDataMap: Map<string, sp.SkeletonData> = new Map();
- spineDataMap: Map<string, Prefab> = new Map();
- // /**
- // * 加载spine数据
- // * @param path spine数据路径
- // * @param callback 回调函数
- // */
- // loadSpineData(bundleName: BundleName | string, spinepath: string, callback: (spineData: sp.SkeletonData) => void) {
- // let bundle: AssetManager.Bundle = LayerMgr.instance.getBundle(bundleName)
- // if (bundle) {
- // bundle.load(spinepath, sp.SkeletonData, (err, res) => {
- // if (err) {
- // console.error(err)
- // return
- // }
- // let spineData: sp.SkeletonData = (res as sp.SkeletonData);
- // callback(spineData)
- // })
- // }
- // }
- loadSpineData(bundleName: BundleName | string, spinepath: string, callback: (sp:Prefab) => void) {
- let bundle: AssetManager.Bundle = LayerMgr.instance.getBundle(bundleName)
- if (bundle) {
- bundle.load(spinepath, Prefab, (err, res) => {
- if (err) {
- console.error(err)
- return
- }
- let spineData: Prefab = (res as Prefab);
- callback(spineData)
- })
- }
- }
- // loadSpine(path: string, callback: (spineData: sp.SkeletonData) => void) {
- // if (this.spineDataMap.has(path)) {
- // callback(this.spineDataMap.get(path));
- // return;
- // }
- // this.loadSpineData("editor", path, (spineData: sp.SkeletonData) => {
- // this.spineDataMap.set(path, spineData);
- // callback(spineData);
- // });
- // }
- loadSpine(path: string, callback: (sp:Prefab) => void) {
- if (this.spineDataMap.has(path)) {
- callback(this.spineDataMap.get(path));
- return;
- }
- this.loadSpineData("editor", path, (sp:Prefab) => {
- this.spineDataMap.set(path, sp);
- callback(sp);
- });
- }
- clearSelectAllSkins()
- {
- Skin.removeAllSelectSkin()
- this.refreshSkinSelectioin()
- EventMgr.ins.dispatchEvent("regenerate")
- }
- refreshSkinSelectioin()
- {
- let allSkillKeys = getAllSkinKeys()
- let count = allSkillKeys.length;
- for(let i = 0; i < count; i++){
- let item = this._items[i]
- item.getComponent(SkinItem).setSelectSkin(false)
- }
- }
- }
|