ChangeEquip.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { AudioMgr, GameViewType } from "../../../main/ViewManage";
  2. import ViewObject from "../../../main/ViewObject";
  3. import { HttpStateType, ReveData } from "../../../util/CHttp";
  4. import GoodItem from "../../common/GoodItem";
  5. import PetIcon from "../../common/PetIcon";
  6. import Equip from "./Equip";
  7. import EquipInfo from "./EquipInfo";
  8. import EquipQH from "./EquipQH";
  9. const { ccclass, property } = cc._decorator;
  10. /**
  11. * 换装备界面
  12. */
  13. @ccclass
  14. export default class ChangeEquip extends ViewObject {
  15. @property(EquipInfo)
  16. public p1: EquipInfo = null;//左边
  17. @property(EquipInfo)
  18. public p2: EquipInfo = null;//右边
  19. @property(cc.Node)
  20. leftQHNode: cc.Node = null; // 左边强化按钮
  21. @property(cc.Node)
  22. mQHNode: cc.Node = null;//强化按钮节点
  23. @property(cc.Node)
  24. mUseNode: cc.Node = null;//装备按钮
  25. /**
  26. * 当前操作的伙伴
  27. */
  28. public petIcon: PetIcon;
  29. /**
  30. * 当前选择的装备
  31. */
  32. public goodItem: GoodItem;
  33. /**
  34. * 装备上的装备
  35. */
  36. public goodItem1: GoodItem;
  37. public equip: Equip;
  38. public inGuide = false
  39. public guideStep: number = 0;
  40. /**
  41. * @param pi 穿装备的伙伴
  42. * @param equipItem 选择的装备
  43. */
  44. public init(pi: PetIcon, goodItem: GoodItem, goodItem1: GoodItem) {
  45. this.petIcon = pi;
  46. this.goodItem = goodItem;
  47. this.goodItem1 = goodItem1
  48. this.p2.init(this.main, this.goodItem1, null)
  49. this.p1.init(this.main, this.goodItem, this.goodItem1);
  50. this.mQHNode.active = goodItem1.equipData && goodItem1.equipData.type <= 4;
  51. this.leftQHNode.active = goodItem.equipData.type <= 4;
  52. this.node.zIndex = 1
  53. if (this.inGuide) {
  54. if (this.guideStep == 0) {
  55. this.onGuide()
  56. }
  57. }
  58. }
  59. /**
  60. *
  61. * @param prev 父界面
  62. */
  63. public show(prev?: ViewObject) {
  64. if (prev) {
  65. this.prev = prev;
  66. this.prev.__close();
  67. }
  68. this.main.viewManage.popView1(this.node);
  69. if (this.main && this.main.gameHttp) {
  70. this.main.gameHttp.pushEvent(this);
  71. }
  72. }
  73. /**
  74. * 使用装备
  75. */
  76. public onclickUse() {
  77. let msg = {
  78. petId: this.petIcon.id,
  79. equipIndex: this.p1.equipItem.equip.__index,
  80. }
  81. this.main.gameHttp.sendJson('equip/v1/use', msg, (state, reve: ReveData) => {
  82. this.main.stopLoad();
  83. if (state == HttpStateType.SUCCESS) {
  84. if (reve.retCode == 0) {
  85. this.main.playerEffectByPath(AudioMgr.equip);
  86. this.equip.checkPet(this.petIcon)
  87. this.equip.mEquipPack.flushEquip();
  88. this.exitDistroy()
  89. if (this.inGuide) {
  90. this.equip.onGuideExit()
  91. }
  92. this.main.showTips('装备成功');
  93. } else {
  94. this.main.showTips(reve.message);
  95. }
  96. } else {
  97. this.main.showTips('网络异常');
  98. }
  99. });
  100. if (this.guideCallback) {
  101. this.guideCallback()
  102. }
  103. }
  104. public onclickLeftQH() {
  105. this.main.viewManage.loadFunc(GameViewType.IntensifyEquip, (viewObject: ViewObject) => {
  106. let equipQH: EquipQH = viewObject as EquipQH;
  107. equipQH.init(this.goodItem.equip, this.petIcon, this.equip)
  108. viewObject.show()
  109. this.exitDistroy()
  110. });
  111. }
  112. public onclickQH() {
  113. this.main.viewManage.loadFunc(GameViewType.IntensifyEquip, (viewObject: ViewObject) => {
  114. let equipQH: EquipQH = viewObject as EquipQH;
  115. equipQH.init(this.goodItem1.equip, this.petIcon, this.equip)
  116. viewObject.show()
  117. this.exitDistroy()
  118. });
  119. }
  120. /**
  121. * 引导中的点击回调
  122. */
  123. private guideCallback: () => void
  124. public setGuideCallback(guideCallback: () => void) {
  125. this.guideCallback = guideCallback
  126. }
  127. /**
  128. * 开始引导穿装备
  129. */
  130. private onGuide() {
  131. let guideMask = this.main.mGuideMask
  132. let targetNode = this.mUseNode
  133. guideMask.setTargetNode(targetNode)
  134. guideMask.show()
  135. this.setGuideCallback(() => {
  136. guideMask.close()
  137. })
  138. }
  139. }