FDialogTest_Zeus.ts 3.7 KB

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