//#region 文件引入 import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, EditBox, UITransform, Color, Layers } from "cc"; import BaseUIForm from "../../Mgr_UI/BaseUIForm"; import { MainConfig } from "db://assets/Launch/_MainConfig"; import { GameTotalType, PropType } from "../../const/GameEnum"; import GDUtils from "../../ExCUtils/GDUtils"; import { Global } from "../../Global"; import MesMgr from "../../MesEvent/MesMgr"; import { EGlobalEvent } from "../../MesEvent/EGlobalEvent"; import UIMgr from "../../Mgr_UI/UIMgr"; import { MUTATE_PARAMS } from "../../const/GGameData"; //#endregion 文件引入 const {ccclass, property,menu} = _decorator; @ccclass("DebugUI_Proxy") export default class DebugUI_Proxy extends BaseUIForm{ //#region 节点自动生成 @property(Node) n_gm: Node = null; @property(Button) btn_NoAd: Button = null; @property(Label) lab_ad: Label = null; @property(Button) btn_Send: Button = null; @property(Button) btn_uplv: Button = null; @property(Button) btn_downlv: Button = null; @property(Button) btn_level: Button = null; @property(Button) btn_passedlevel: Button = null; @property(Button) btn_addcoin: Button = null; @property(Button) btn_addcoin2: Button = null; @property(Button) btn_addcoin3: Button = null; @property(Button) btn_addcoin4: Button = null; @property(Button) btn_addcoin5: Button = null; @property(Button) btn_addcoin6: Button = null; @property(Button) btn_addcoin7: Button = null; @property(Button) btn_ok: Button = null; @property(Button) btn_no: Button = null; @property(Button) btn_ResetTrial: Button = null; @property(Button) btn_func1: Button = null; @property(Button) btn_func2: Button = null; @property(Button) btn_open: Button = null; //#endregion 节点自动生成 @property(EditBox) ed_itemid: EditBox = null; @property(EditBox) ed_itemnum: EditBox = null; @property(EditBox) ed_level: EditBox = null; @property(EditBox) ed_coin: EditBox = null; @property(EditBox) ed_coin2: EditBox = null; @property(EditBox) ed_coin3: EditBox = null; @property(EditBox) ed_fun: EditBox = null; @property(Node) searchResultsParent:Node = null; private searchResultNodes: Node[] = []; // 存储搜索结果节点 private debounceTimer: ReturnType | null = null; // 防抖定时器 onButtonClick(button:Button){ /**点击事件触发*/ switch (button) { case this.btn_NoAd: MainConfig.isNoAD = !MainConfig.isNoAD; this.lab_ad.string = MainConfig.isNoAD ? "关" : "开"; break; case this.btn_Send: this.onSendItem(); break; case this.btn_ResetTrial: this.mDataMgr.Trial.ClearData(); break; case this.btn_addcoin: const coin = Number(this.ed_coin.string); if(coin){ this.mDataMgr.Token.addToken(PropType.eGold,coin); } break; case this.btn_addcoin2: const coin2 = Number(this.ed_coin.string); if(coin2){ this.mDataMgr.Token.addToken(PropType.eAdopt,coin2); } break; case this.btn_addcoin3: const coin3 = Number(this.ed_coin.string); if(coin3){ this.mDataMgr.Token.addToken(PropType.eTaiJi,coin3); } break; case this.btn_addcoin4: const coin4 = Number(this.ed_coin.string); if(coin4){ this.mDataMgr.Token.addToken(PropType.eJXStone,coin4); } break; case this.btn_addcoin5: const coin5 = Number(this.ed_coin.string); if(coin5){ this.mDataMgr.Token.addToken(PropType.eZRStone,coin5); } break; case this.btn_addcoin6: const coin6 = Number(this.ed_coin.string); if(coin6){ this.mDataMgr.Token.addToken(PropType.eQRYStone,coin6); } break; case this.btn_addcoin7: const coin7 = Number(this.ed_coin.string); if(coin7){ this.mDataMgr.Token.addToken(PropType.eSLStone,coin7); } break; case this.btn_func1: const fun1 = Number(this.ed_fun.string); if(fun1){ this.mDataMgr.Game.FreeChallengeTimes = fun1; } break; case this.btn_func2: const fun2 = Number(this.ed_fun.string); if(this.ed_fun.string.length > 0){ const level = this.mDataMgr.Scene.level; this.mDataMgr.Mutate.triggerMTFightByGM(level.boss.config, true, fun2); } break; case this.btn_open: // this.n_gm.active = !this.n_gm.active; this.CloseUI(); break; case this.btn_level: const level = parseInt(this.ed_level.string); if(level && level > 0){ if(level > 21){ UIMgr.Ins.ShowTipsUI("已超过最大关卡序号") } const finalLevel = level > 21 ? 21 : level; this.mDataMgr.Scene.level.task_count = 0; this.mDataMgr.Scene.level.id = finalLevel; // 异兽解锁检查 if (!this.mDataMgr.Mutate.unlock && this.mDataMgr.Scene.level.id === MUTATE_PARAMS.UNLOCK_LEVEL){ this.mDataMgr.Mutate.unlockMT(); } this.mDataMgr.Scene.onSummaryComplete(true); } break; case this.btn_uplv: this.mDataMgr.Scene.level.task_count = 0; this.mDataMgr.Scene.level.id -= 1; this.mDataMgr.Scene.onSummaryComplete(true); break; case this.btn_downlv: this.mDataMgr.Scene.level.task_count = 0; this.mDataMgr.Scene.level.id += 1; // 异兽解锁检查 if (!this.mDataMgr.Mutate.unlock && this.mDataMgr.Scene.level.id === MUTATE_PARAMS.UNLOCK_LEVEL){ this.mDataMgr.Mutate.unlockMT(); } this.mDataMgr.Scene.onSummaryComplete(true); break; case this.btn_passedlevel: this.onPassedGame(); break; default: ConsoleEx.Log(button); break; } } protected start(): void { this.lab_ad.string = MainConfig.isNoAD ? "关" : "开"; this.ed_itemid.node.on(EditBox.EventType.TEXT_CHANGED, this.onItemSearchInputChanged, this); CNodeUtils.setActive(this.btn_ResetTrial, MainConfig.isTrialOpen) CNodeUtils.setActive(this.btn_addcoin4, MainConfig.isTrialOpen) CNodeUtils.setActive(this.btn_addcoin5, MainConfig.isTrialOpen) CNodeUtils.setActive(this.btn_addcoin6, MainConfig.isTrialOpen) } private onItemSearchInputChanged() { if (this.debounceTimer) { clearTimeout(this.debounceTimer); } this.debounceTimer = setTimeout(() => { this.performItemSearch(); }, 300); } // 执行物品搜索 private performItemSearch() { const inputText = this.ed_itemid.string.trim(); if (!inputText) { this.hideSearchResults(); return; } // 模糊匹配物品 const allItems = Global.CsvMgr.Items_csv; const matchingItems = []; for (const itemId in allItems) { const item = allItems[itemId]; if (item.name && typeof item.name === 'string' && item.name.toLowerCase().includes(inputText.toLowerCase())) { matchingItems.push({ id: parseInt(itemId), name: item.name }); // 限制最多显示15个结果 if (matchingItems.length >= 15) { break; } } } // 显示搜索结果 this.showSearchResults(matchingItems); } private showSearchResults(matchingItems: Array<{id: number, name: string}>) { console.log(`找到 ${matchingItems.length} 个匹配项`, matchingItems); this.clearSearchResults(); if (matchingItems.length === 0) { console.log("没有匹配项,隐藏搜索结果"); this.hideSearchResults(); return; } const parentUITransform = this.searchResultsParent.getComponent(UITransform); this.searchResultsParent.active = true; const inputWorldPos= this.ed_itemid.node.worldPosition; const inputUITransform = this.ed_itemid.node.getComponent(UITransform); if (inputUITransform) { this.searchResultsParent.setWorldPosition( inputWorldPos.x, inputWorldPos.y - inputUITransform.height / 2 - parentUITransform.height / 2, // 在输入框下方 inputWorldPos.z ); } // 创建搜索结果节点 // 创建搜索结果节点 for (let i = 0; i < matchingItems.length; i++) { const item = matchingItems[i]; // 创建背景底板节点 const bgNode = new Node(`Bg_${i}`); bgNode.layer = Layers.Enum.UI_2D; const bgUITransform = bgNode.addComponent(UITransform); // 设置底板大小(使用父节点的宽度,高度固定) if (parentUITransform) { bgUITransform.width = parentUITransform.width - 10; // 留一点边距 bgUITransform.height = 30; } else { bgUITransform.width = 300; bgUITransform.height = 30; } bgNode.setPosition(0, -i * 35, 0); // 设置位置,留出间距 // 创建按钮节点 const button = new Node(`BUTTON_${i}`); button.layer = Layers.Enum.UI_2D; const buttonUITransform = button.addComponent(UITransform); buttonUITransform.width = bgUITransform.width; buttonUITransform.height = bgUITransform.height; button.addComponent(Button); // 添加标签显示物品名称 const label = button.addComponent(Label); label.string = `${item.name} (ID: ${item.id})`; // 显示名称和ID label.color = Color.BLACK; label.fontSize = 40; // 适当减小字体以适应空间 // label.overflow = Label.Overflow.RESIZE_HEIGHT; // 设置按钮的交互效果 const buttonComponent = button.getComponent(Button); buttonComponent.transition = Button.Transition.COLOR; // 颜色变化过渡 buttonComponent.normalColor = Color.BLACK; // 正常状态颜色 buttonComponent.pressedColor = Color.RED; // 按下状态颜色 buttonComponent.hoverColor = Color.RED; // 悬停状态颜色 // 绑定点击事件 button.on(Button.EventType.CLICK, () => { this.selectSearchResult(item.name, item.id); }, this); // 将按钮作为背景节点的子节点 button.parent = bgNode; // 添加到底板父节点 bgNode.parent = this.searchResultsParent; this.searchResultNodes.push(bgNode); // 将背景节点加入数组,方便清理 } console.log("搜索结果显示完成,共创建", matchingItems.length, "个结果节点"); } // 选择搜索结果 private selectSearchResult(name: string, id: number) { // 将选中的物品名称填入输入框 if (this.ed_itemid) { this.ed_itemid.string = name; } // 隐藏搜索结果 this.hideSearchResults(); } // 清空搜索结果 private clearSearchResults() { for (const node of this.searchResultNodes) { if (node && node.isValid) { node.destroy(); } } this.searchResultNodes = []; } private hideSearchResults() { // 清空搜索结果 this.clearSearchResults(); // 隐藏父节点 if (this.searchResultsParent) { this.searchResultsParent.active = false; } } onSendItem(){ const inputText = this.ed_itemid.string.trim(); const num = parseInt(this.ed_itemnum.string) || 1; if (!inputText) { UIMgr.Ins.ShowTipsUI("请输入物品ID或名称"); return; } if (!num) { UIMgr.Ins.ShowTipsUI("请输入正确的数量"); return; } // 查找物品ID let itemId = parseInt(inputText); // 如果输入的是纯数字,直接使用 if (isNaN(itemId)) { // 否则通过名称查找 const allItems = Global.CsvMgr.Items_csv; for (const id in allItems) { const item = allItems[id]; if (item.name === inputText) { itemId = parseInt(id); break; } } } if (itemId && itemId > 0) { const itemData = Global.CsvMgr.Items_csv[itemId]; if (itemData) { GDUtils.DistributeRewards({id: itemId, num: num, type: GameTotalType.ITEM}); UIMgr.Ins.ShowTipsUI(`已发送物品: ${itemData.name}, 数量: ${num}`); } else { UIMgr.Ins.ShowTipsUI(`未找到物品ID: ${itemId}`); } } else { UIMgr.Ins.ShowTipsUI(`无效的物品ID或名称: ${inputText}`); } // 隐藏搜索结果 this.hideSearchResults(); } // 通关,进入下一周目 onPassedGame(){ // this.n_gm.active = false; // 关卡 const levelKeys = Object.keys(Global.CsvMgr.Level_csv); const lastLevelId = Number(levelKeys[levelKeys.length - 1]); this.mDataMgr.Scene.level.id = lastLevelId + 1; this.mDataMgr.Scene.level.task_count = 0; this.mDataMgr.Scene.level.passed = true; this.mDataMgr.Scene.isPassedState = true; // 任务 const taskKeys = Object.keys(Global.CsvMgr.tasks_csv); const lastTaskId = Number(taskKeys[taskKeys.length - 1]); this.mDataMgr.Task.task.id = lastTaskId.toString(); this.mDataMgr.Scene.refreshTaskProgress(); this.mDataMgr.Scene.onSummaryComplete(true); // 异兽解锁检查 if (!this.mDataMgr.Mutate.unlock && this.mDataMgr.Scene.level.id === MUTATE_PARAMS.UNLOCK_LEVEL){ this.mDataMgr.Mutate.unlockMT(); } // 首次通关,奖励一个玄武符 if(this.mDataMgr.Pass.passed_times === 1){ this.mDataMgr.Token.addToken(PropType.eAdopt, 1); UIMgr.Ins.ShowTipsUI("恭喜首次通关,奖励:玄武符+1"); }else{ UIMgr.Ins.ShowTipsUI("恭喜通关!!"); } // this.CloseUI(); } }