FDialogTest_athena.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import FF from "../../FF";
  2. import FSprite from "../../object/FSprite";
  3. import { DialogAttrContent } from "../dialog/FDialogAttr";
  4. import FDialogBox from "../dialog/FDialogBox";
  5. /**
  6. * 对话测试
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FDialogTest1 extends cc.Component {
  11. @property(cc.Prefab)
  12. mDialog: cc.Prefab = null;
  13. private ff:FF;
  14. /**
  15. * 对话框
  16. */
  17. private dialogBox:FDialogBox;
  18. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  19. if(other.node.group == 'A'){
  20. let obj = other.node.getComponent(FSprite);
  21. this.ff = obj.ff;
  22. if(obj == this.ff.mainSprite){
  23. this.showButton();
  24. }
  25. }
  26. }
  27. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  28. if(other.node.group == 'A'){
  29. let obj = other.node.getComponent(FSprite);
  30. if(obj == this.ff.mainSprite){
  31. this.closeButton();
  32. }
  33. }
  34. }
  35. public showButton(){
  36. this.ff.control.mEventButton.node.active = true;
  37. this.ff.control.mEventButton.setCallback(()=>{
  38. this.showDialog();
  39. });
  40. }
  41. public closeButton(){
  42. this.ff.control.mEventButton.node.active = false;
  43. }
  44. public exitDialog(){
  45. this.dialogBox.node.destroy();
  46. }
  47. public showDialog(){
  48. /**
  49. * 对话1
  50. */
  51. let dialog1 = [
  52. {
  53. name:'雅典娜',
  54. name1:'智慧女神',
  55. icon:'role_half_12006',
  56. content:'来自奥林匹斯王国灰眼公主的祝福,燃烧吧,小宇宙'
  57. },
  58. ];
  59. let node = cc.instantiate(this.mDialog);
  60. this.ff.main.viewManage.popView(node);
  61. this.dialogBox = node.getComponent(FDialogBox);
  62. this.dialogBox.setData(dialog1);
  63. this.dialogBox.setCallback(()=>{
  64. this.showAttr();
  65. });
  66. }
  67. /**
  68. * 显示增加属性buff选择
  69. */
  70. private showAttr(){
  71. let datas = [
  72. {
  73. name:'附加攻击力',
  74. about:'普通攻击增加',
  75. icon:'attribute_icon_1',
  76. vaule:40,
  77. type:1,//添加属性类型
  78. },
  79. {
  80. name:'附加攻击力',
  81. about:'普通攻击增加',
  82. icon:'attribute_icon_1',
  83. vaule:40,
  84. type:1,//添加属性类型
  85. },
  86. {
  87. name:'附加攻击力',
  88. about:'普通攻击增加',
  89. icon:'attribute_icon_1',
  90. vaule:40,
  91. type:1,//添加属性类型
  92. }
  93. ];
  94. this.dialogBox.setAttr(datas);
  95. this.dialogBox.setAttrCallback((attr:DialogAttrContent)=>{
  96. this.exitDialog();
  97. this.node.destroy();
  98. //cc.log('选择增加属性类型:',attr);
  99. let sprite = this.ff.mainSprite;
  100. this.addAttr(sprite,attr);
  101. });
  102. }
  103. private addAttr(sprite:FSprite,attr:DialogAttrContent){
  104. let data = sprite.attrData;
  105. if(attr.type == 1){
  106. data.atk += Math.floor(data.atk*attr.vaule/100);
  107. }
  108. // if(sprite.behind){
  109. // this.addAttr(sprite.behind,attr);
  110. // }
  111. }
  112. }