Revenge.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import ViewObject from "../../../main/ViewObject";
  2. import { HttpStateType, ReveData } from "../../../util/CHttp";
  3. import CUtilTime from "../../../util/CUtilTime";
  4. import GoodItem from "../../common/GoodItem";
  5. import TopMenu from "../TopMenu";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class Revenge extends ViewObject {
  9. // id: 1001
  10. // name: "复仇礼包"
  11. // needCount: 2000
  12. // needType: 1
  13. // reveCount0: 1000
  14. // reveCount1: 1
  15. // reveCount2: 1
  16. // reveCount3: 1
  17. // reveId1: 1005
  18. // reveId2: 1105
  19. // reveId3: 1205
  20. // reveType0: 1
  21. // reveType1: 3
  22. // reveType2: 3
  23. // reveType3: 3
  24. // needType 需要的货币类型,1:钻石;2:金币
  25. // reveType0 奖励的货币类型,1:钻石;2:金币
  26. // reveType1 奖励的道具类型,1:钻石;2:金币 ;3:装备;4:道具
  27. // reveType2 奖励的道具类型,1:钻石;2:金币 ;3:装备;4:道具
  28. // reveType3 奖励的道具类型,1:钻石;2:金币 ;3:装备;4:道具
  29. @property(cc.Label)
  30. title: cc.Label = null;
  31. @property(cc.Node)
  32. itemList: cc.Node[] = [];
  33. @property(cc.Node)
  34. goldIcon: cc.Node = null;
  35. @property(cc.Node)
  36. diamondIcon: cc.Node = null;
  37. @property(cc.Label)
  38. lbnum: cc.Label = null;
  39. @property(cc.Label)
  40. revengeTime: cc.Label = null;
  41. revengeData = null;
  42. clickIndex: number = 1;
  43. curClickNode: cc.Node = null;
  44. buyClickFunc: Function = null;
  45. setBuyClickFunc(func: Function) {
  46. this.buyClickFunc = func;
  47. }
  48. /**
  49. *
  50. * @param prev 父界面
  51. */
  52. public show(prev?: ViewObject) {
  53. if (prev) {
  54. this.prev = prev;
  55. this.prev.__close();
  56. }
  57. this.main.viewManage.popView1(this.node);
  58. if (this.main && this.main.gameHttp) {
  59. this.main.gameHttp.pushEvent(this);
  60. }
  61. }
  62. getRevengeData() {
  63. let msg = {};
  64. this.main.gameHttp.sendJson(`revenge/v1/data`, msg, (state, reve: ReveData) => {
  65. this.main.stopLoad();
  66. if (state == HttpStateType.SUCCESS) {
  67. if (reve.retCode == 0) {
  68. console.log("==reve=revengeData===", reve)
  69. this.revengeData = reve.data.list[0];
  70. this.initItem();
  71. this.show();
  72. } else {
  73. this.main.showTips(reve.message);
  74. }
  75. } else {
  76. this.main.showTips('网络异常');
  77. }
  78. });
  79. }
  80. initItem() {
  81. this.title.string = this.revengeData.name;
  82. this.goldIcon.active = this.revengeData.needType == 2;
  83. this.diamondIcon.active = this.revengeData.needType == 1;
  84. this.lbnum.string = this.revengeData.needCount;
  85. this.itemList.forEach((item, index) => {
  86. let node = item.getChildByName("item");
  87. let icon = node.getChildByName("icon").getComponent(cc.Sprite);
  88. let name = node.getChildByName("lbname").getComponent(cc.Label);
  89. let clickIcon = item.getChildByName("clickIcon");
  90. let count = node.getChildByName("count").getComponent(cc.Label);
  91. count.string = this.revengeData[`reveCount${index}`];
  92. if (index == 0) {
  93. let path = this.revengeData.reveType0 == 1 ? "3002" : "3001";
  94. this.initIcon(icon, "good/" + path);
  95. } else {
  96. if (this.revengeData[`reveType${index}`] == 3) {
  97. this.initIcon(icon, "equip/" + this.revengeData[`reveId${index}`]);
  98. let equip = this.main.sManage.getEquipById(this.revengeData[`reveId${index}`]);
  99. name.string = equip.name;
  100. } else {
  101. this.initIcon(icon, "good/" + this.revengeData[`reveId${index}`]);
  102. }
  103. }
  104. if (index == 1) {
  105. clickIcon.active = true;
  106. this.curClickNode = clickIcon;
  107. }
  108. if (index != 0) {
  109. item.getComponent(GoodItem).setCallback(() => {
  110. this.curClickNode.active = false;
  111. clickIcon.active = true;
  112. this.curClickNode = clickIcon;
  113. this.clickIndex = index;
  114. })
  115. }
  116. })
  117. }
  118. refreshTime(revengeTime: number) {
  119. if (this.revengeTime) {
  120. this.revengeTime.string = `${CUtilTime.getTimeString2(revengeTime)}后消失`;
  121. }
  122. }
  123. public initIcon(icon: cc.Sprite, path: string) {
  124. cc.resources.load(`icon/${path}`, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  125. if (err) {
  126. cc.error(err);
  127. } else {
  128. icon.spriteFrame = spriteFrame;
  129. }
  130. });
  131. }
  132. onClickBuy() {
  133. let msg = {
  134. id: this.revengeData.id,
  135. index: this.clickIndex - 1,
  136. };
  137. this.main.gameHttp.sendJson(`revenge/v1/buy`, msg, (state, reve: ReveData) => {
  138. this.main.stopLoad();
  139. if (state == HttpStateType.SUCCESS) {
  140. if (reve.retCode == 0) {
  141. this.buyClickFunc && this.buyClickFunc();
  142. this.exitDistroy();
  143. this.main.showReward(reve);
  144. this.main.topNode.getComponent(TopMenu).refresh();
  145. } else {
  146. this.main.showTips(reve.message);
  147. }
  148. } else {
  149. this.main.showTips('网络异常');
  150. }
  151. });
  152. }
  153. }