import FF from "../../FF"; import { GroupType } from "../../object/FObject"; import FSprite from "../../object/FSprite"; import { DialogAttrContent } from "../dialog/FDialogAttr"; import FDialogBox from "../dialog/FDialogBox"; /** * 对话测试 */ const {ccclass, property} = cc._decorator; @ccclass export default class FDialogTest1 extends cc.Component { @property(cc.Prefab) mDialog: cc.Prefab = null; private ff:FF; /** * 对话框 */ private dialogBox:FDialogBox; onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){ if(other.node.group == 'A'){ let obj = other.node.getComponent(FSprite); this.ff = obj.ff; if(obj == this.ff.mainSprite){ this.showButton(); } } } onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){ if(other.node.group == 'A'){ let obj = other.node.getComponent(FSprite); if(obj == this.ff.mainSprite){ this.closeButton(); } } } public showButton(){ this.ff.control.mEventButton.node.active = true; this.ff.control.mEventButton.setCallback(()=>{ this.showDialog(); }); } public closeButton(){ this.ff.control.mEventButton.node.active = false; } public exitDialog(){ this.dialogBox.node.destroy(); } public showDialog(){ /** * 对话1 */ let dialog1 = [ { name:'宙斯', name1:'众神之王', icon:'3', content:'1111111' }, { name:'宙斯', name1:'众神之王', icon:'3', content:'222222' }, { name:'宙斯', name1:'众神之王', icon:'3', content:'3333333' } ]; let node = cc.instantiate(this.mDialog); this.ff.main.viewManage.popView(node); this.dialogBox = node.getComponent(FDialogBox); this.dialogBox.setData(dialog1); this.dialogBox.setCallback(()=>{ this.showAttr(); }); } /** * 显示增加属性buff选择 */ private showAttr(){ let datas = [ { name:'附加攻击力', about:'普通攻击增加', icon:'attribute_icon_1', vaule:40, type:1,//添加属性类型 }, { name:'附加攻击力', about:'普通攻击增加', icon:'attribute_icon_1', vaule:40, type:1,//添加属性类型 }, { name:'附加攻击力', about:'普通攻击增加', icon:'attribute_icon_1', vaule:40, type:1,//添加属性类型 } ]; this.dialogBox.setAttr(datas); this.dialogBox.setAttrCallback((attr:DialogAttrContent)=>{ this.exitDialog(); this.node.destroy(); cc.log('选择增加属性类型:',attr); let ffs = this.ff.getGroupBy(GroupType.A); ffs.forEach(sprite => { this.addAttr(sprite,attr); }); }); } private addAttr(sprite:FSprite,attr:DialogAttrContent){ let data = sprite.attrData; if(attr.type == 1){ data.atk += Math.floor(data.atk*attr.vaule/100); } } }