import FF from "../../FF"; 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:'role_half_12006', content:'来自奥林匹斯王国灰眼公主的祝福,燃烧吧,小宇宙' }, ]; 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 sprite = this.ff.mainSprite; 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); } // if(sprite.behind){ // this.addAttr(sprite.behind,attr); // } } }