Procházet zdrojové kódy

设置难度,选择皮肤

baowen před 1 dnem
rodič
revize
6e37f24d66

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 281 - 418
assets/editor/prefab/SuperFindPanel.prefab


+ 32 - 0
assets/editor/script/DifficultyItem.ts

@@ -0,0 +1,32 @@
+import { _decorator, Component, EditBox, Label, Node } from 'cc';
+import { Difficulty, UserDifficutyData } from '../../script/Manager/LocalDataMgr';
+const { ccclass, property } = _decorator;
+
+@ccclass('DifficultyItem')
+export class DifficultyItem extends Component {
+    @property(Label)
+    labelInfo:Label = null;
+    @property(EditBox)
+    editBox:EditBox = null;
+
+    _index:number = 0;
+    init(index:number,scale:number)
+    {
+        this.labelInfo.string = `${index+1}号比例`
+        this.editBox.string = `${scale}`
+        this._index = index;
+    }
+
+    OnEditBoxChange(editBox:EditBox)
+    {
+        let scale = Number(editBox.string);
+        if(isNaN(scale))
+        {
+            return;
+        }
+        Difficulty.difficutyData.scales[this._index] = scale;
+        Difficulty.saveDifficutyData();
+    }
+}
+
+

+ 9 - 0
assets/editor/script/DifficultyItem.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "0c4723a8-a3e6-44a7-b648-c2447d0439ad",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 81 - 4
assets/editor/script/SelectDifficultyPanel.ts

@@ -1,14 +1,91 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, EditBox, instantiate, Node, Prefab } from 'cc';
+import { Difficulty, DifficutyData } from '../../script/Manager/LocalDataMgr';
+import { LayerMgr } from '../../script/Manager/LayerMgr';
+import { DifficultyItem } from './DifficultyItem';
 const { ccclass, property } = _decorator;
 
 @ccclass('SelectDifficultyPanel')
 export class SelectDifficultyPanel extends Component {
-    start() {
+    @property(Node)
+    itemRoot: Node = null;
+    @property(Node)
+    itemPrefab:Node = null;
+    @property(EditBox)
+    countEditBox:EditBox = null;
+    
+    _difficultyData: DifficutyData = null
+    _items: Node[] = [];
+    _itemPool: Node[] = [];
 
+    protected start(): void {
+        this.countEditBox.node.on('editing-did-ended', this.onEditChange, this);
     }
 
-    update(deltaTime: number) {
-        
+   init() {
+    this._difficultyData = Difficulty.getDifficutyData();
+    const targetCount = this._difficultyData.difficutyCount;
+    const currentCount = this._items.length;
+    
+    // 情况1:需要添加新项目
+    if(targetCount > currentCount) {
+        for (let i = currentCount; i < targetCount; i++) {
+            this.createItem(i);
+        }
+    }
+    // 情况2:需要删除多余项目
+    else if(targetCount < currentCount) {
+        const removeCount = currentCount - targetCount;
+        for (let i = 0; i < removeCount; i++) {
+            const item = this._items.pop();
+            item.removeFromParent();
+            item.active = false;
+            this._itemPool.push(item);
+        }
+    }
+    
+    // 更新所有项目的数据
+    for (let i = 0; i < this._items.length; i++) {
+        const scaleValue = i < this._difficultyData.scales.length 
+            ? this._difficultyData.scales[i] 
+            : 0;
+        this._items[i].getComponent(DifficultyItem).init(i, scaleValue);
+    }
+    
+    this.countEditBox.string = this._difficultyData.difficutyCount.toString();
+}
+
+    createItem(index: number) {
+        let itemNode = this._itemPool.length > 0? this._itemPool.pop(): instantiate(this.itemPrefab);
+        itemNode.parent = this.itemRoot;
+        this._items.push(itemNode);
+        itemNode.active = true
+        itemNode.getComponent(DifficultyItem).init(index, this._difficultyData.scales[index])
+    }
+
+    onEditChange(ed:EditBox)
+    {
+        let count = Number(ed.string);
+        if(isNaN(count))
+        {
+            return;
+        }
+        Difficulty.difficutyData.difficutyCount = count;
+        Difficulty.createOrDeleteOtherScale();
+        this.init()
+        Difficulty.saveDifficutyData();
+    }
+
+    onUseSysDataClick()
+    {
+        Difficulty.setDataToDefault();
+        Difficulty.createOrDeleteOtherScale(); // 重置时应用新逻辑
+        this.init(); // 刷新UI
+        this.node.active = false
+    }
+    
+    onUseCurrentData()
+    {
+        this.node.active = false
     }
 }
 

+ 105 - 14
assets/editor/script/SelectSkinPanel.ts

@@ -1,14 +1,105 @@
-import { _decorator, Component, Node } from 'cc';
-const { ccclass, property } = _decorator;
-
-@ccclass('SelectSkinPanel')
-export class SelectSkinPanel extends Component {
-    start() {
-
-    }
-
-    update(deltaTime: number) {
-        
-    }
-}
-

+import { _decorator, AssetManager, Button, Component, instantiate, Node, sp, Vec2 } from 'cc';
+import { getSelectAllKeys, selectedSkinList, Skin, SkinData } from '../../script/Manager/LocalDataMgr';
+import { SkinItem } from './SkinItem';
+import { LayerMgr } from '../../script/Manager/LayerMgr';
+import { BundleName } from '../../script/Config/EnumCfg';
+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[] = [];
+    _itemPool: Node[] = [];
+    _hasCreatedItems:boolean = false;
+
+    protected start(): void {
+        this.btnClose.node.on(Node.EventType.TOUCH_END,()=>this.node.active = false,this)
+    }
+
+    init() {
+        LayerMgr.instance.loadBundle("editor", () => {
+            this._allSkinList = selectedSkinList
+            this._skinData = Skin.getSkinData();
+            let allSkillKeys = getSelectAllKeys()
+            let count = allSkillKeys.length;
+            for(let i = 0; i < count; i++){
+                this.createItem(allSkillKeys[i],this.spineoffset);
+            }
+        });
+    }
+
+    createItem(key: number,spineOffset:Vec2) {
+        let itemNode = this._itemPool.length > 0 ? this._itemPool.pop() : instantiate(this.itemPrefab);
+        itemNode.parent = this.itemRoot;
+        this._items.push(itemNode);
+        itemNode.active = true
+        let skPath = selectedSkinList[key]
+        this.loadSpine(skPath, (spineData: sp.SkeletonData) => {
+            itemNode.getComponent(SkinItem).init(key,spineData,"loop2",spineOffset,this.judgeSelect(key))
+        })
+    }
+    onSingleSkinClick() {
+
+    }
+
+    onMultiSkinClick() {
+
+    }
+
+    judgeSelect(key)
+    {
+        let selSkins = this._skinData.selectedSkinList
+        let index = selSkins.indexOf(key)
+        return index !== -1
+    }
+
+
+
+    spineDataMap: Map<string, sp.SkeletonData> = 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)
+            })
+        }
+    }
+
+    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);
+        });
+    }
+
+    clearSelectAllSkins()
+    {
+        Skin.removeAllSelectSkin()
+    }
+}
+
+

+ 44 - 0
assets/editor/script/SkinItem.ts

@@ -0,0 +1,44 @@
+import { _decorator, Button, Component, Node, sp, Sprite, Vec2 } from 'cc';
+import { selectedSkinList, Skin } from '../../script/Manager/LocalDataMgr';
+import { LayerMgr } from '../../script/Manager/LayerMgr';
+const { ccclass, property } = _decorator;
+
+@ccclass('SkinItem')
+export class SkinItem extends Component {
+    @property(sp.Skeleton)
+    skin:sp.Skeleton = null;
+    @property(Sprite)
+    selectedSprite:Sprite = null;
+    
+    private _isSelected:boolean = false;
+    private _key:number = 0;
+
+    init(key: number,spineData:sp.SkeletonData,animName:string = "idle",spineOffset:Vec2 = new Vec2(0,0),isSelect:boolean = false)
+    {
+        this.skin.skeletonData = spineData;
+        this.skin.setAnimation(0,animName,true)
+        this.skin.node.position = this.skin.node.position.clone().add3f(spineOffset.x,spineOffset.y,0)
+        this.selectedSprite.node.active = isSelect
+        this._isSelected = isSelect
+        this._key = key
+    }
+
+    onClick()
+    {
+        this._isSelected = !this._isSelected
+        this.selectedSprite.node.active = this._isSelected
+        if(this._isSelected)
+        {
+            Skin.addSelectSkin(this._key)
+        }else
+        {
+            Skin.removeSelectSkin(this._key)
+        }
+    }
+
+    protected start(): void {
+        this.node.on(Node.EventType.TOUCH_END,this.onClick,this)
+    }
+}
+
+

+ 9 - 0
assets/editor/script/SkinItem.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "aeb1607a-4a18-4f05-a65b-ddb2881792c2",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 2 - 0
assets/editor/script/SuperFindPanel.ts

@@ -16,9 +16,11 @@ export class SuperFindPanel extends Component {
 
     OpenselDifPanel() {
         this.selDifPanel.node.active = true;
+        this.selDifPanel.init();
     }
     OpenSelSkinPanel() {
         this.selSkinPanel.node.active = true;
+        this.selSkinPanel.init();
     }
     OpenSelMapPanel() {
         this.selMapPanel.node.active = true;

+ 126 - 2
assets/script/Manager/LocalDataMgr.ts

@@ -137,9 +137,43 @@ export interface DifficutyData {
 export class UserDifficutyData {
     private _difficutyData: DifficutyData;
 
+   createOrDeleteOtherScale() {
+    const targetCount = this._difficutyData.difficutyCount;
+    const currentScales = this._difficutyData.scales;
+    const defaultScales = [1.18, 1.16, 1.14, 0.3976, 0.3690, 0.3029, 0.0667, 0.0766, 0.0531, 0.0716];
+
+    if (currentScales.length > targetCount) {
+        currentScales.splice(targetCount, currentScales.length - targetCount);
+    }
+    else if (currentScales.length < targetCount) {
+        for (let i = currentScales.length; i < targetCount; i++) {
+            let value: number;
+            if (i < defaultScales.length) {
+                value = defaultScales[i];
+            } else {
+                value = Math.random() * 0.035 + 0.04;
+            }
+            currentScales.push(value);
+        }
+    }
+
+    for (let i = 0; i < targetCount; i++) {
+        if (currentScales[i] === undefined || currentScales[i] === null) {
+            if (i < defaultScales.length) {
+                currentScales[i] = defaultScales[i];
+            } else {
+                currentScales[i] = Math.random() * 0.035 + 0.04;
+            }
+        }
+    }
+
+    // 保存修改后的数据
+    this.saveDifficutyData();
+}
+
     constructor() {
-        let defaultData: DifficutyData = {
-            difficutyCount: 0,
+        let defaultData = {
+            difficutyCount: 10,
             scales: [1.18, 1.16, 1.14, 0.3976, 0.3690, 0.3029,
                 0.0667, 0.0766, 0.0531, 0.0716]
         }
@@ -170,6 +204,17 @@ export class UserDifficutyData {
     public saveDifficutyData(): void {
         sys.localStorage.setItem("difficutyData", JSON.stringify(this._difficutyData));
     }
+
+    setDataToDefault()
+    {
+        let defaultData = {
+            difficutyCount: 10,
+            scales: [1.18, 1.16, 1.14, 0.3976, 0.3690, 0.3029,
+                0.0667, 0.0766, 0.0531, 0.0716]
+        }
+        this._difficutyData = defaultData;
+        this.saveDifficutyData();
+    }
 }
 export const Difficulty = new UserDifficutyData();
 
@@ -215,6 +260,43 @@ export class UserSkinData {
     public saveSkinData(): void {
         sys.localStorage.setItem("skinData", JSON.stringify(this._skinData));
     }
+
+    addSelectSkin(key:number)
+    {
+        let index = this._skinData.selectedSkinList.indexOf(key)
+        if(index == -1)
+        {
+            this._skinData.selectedSkinList.push(key)
+        }
+        this.saveSkinData()
+    }
+
+    removeSelectSkin(key:number)
+    {
+        let index = this._skinData.selectedSkinList.indexOf(key)
+        if(index != -1)
+        {
+            this._skinData.selectedSkinList.splice(index,1)
+        }
+        this.saveSkinData()
+    }
+
+    removeAllSelectSkin()
+    {
+        this._skinData.selectedSkinList = []
+        this.saveSkinData()
+    }
+
+    addAllSelectSkin()
+    {
+        this._skinData.selectedSkinList = []
+        let allSkinkeys = getSelectAllKeys()
+        for(let i = 0;i < allSkinkeys.length;i++)
+        {
+            this._skinData.selectedSkinList.push(allSkinkeys[i])
+        }
+        this.saveSkinData()
+    }
 }
 
 export const Skin = new UserSkinData();
@@ -305,5 +387,47 @@ export class UserSuperFindData {
     }
 }
 
+export const selectedSkinList: { [key: number]: string } = {
+    //假设30个数据
+    1: "spine/hecha",
+    2: "spine/hecha",
+    3: "spine/hecha",
+    4: "spine/hecha",
+    5: "spine/hecha",
+    6: "spine/hecha",
+    7: "spine/hecha",
+    8: "spine/hecha",
+    9: "spine/hecha",
+    10: "spine/hecha",
+    11: "spine/hecha",
+    12: "spine/hecha",
+    13: "spine/hecha",
+    14: "spine/hecha",
+    15: "spine/hecha",
+    16: "spine/hecha",
+    17: "spine/hecha",
+    18: "spine/hecha",
+    19: "spine/hecha",
+    20: "spine/hecha",
+    21: "spine/hecha",
+    22: "spine/hecha",
+    23: "spine/hecha",
+    24: "spine/hecha",
+    25: "spine/hecha",
+    26: "spine/hecha",
+    27: "spine/hecha",
+    28: "spine/hecha",
+    29: "spine/hecha",
+    30: "spine/hecha",
+};
+
+/**
+ * 获取 selectedSkinList 中所有的键
+ * @returns 包含所有键的数字数组
+ */
+export function getSelectAllKeys(): number[] {
+    return Object.keys(selectedSkinList).map(Number);
+}
+
 
 

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů