ChangeJob.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. const JobPageType = require('../utils/GameEnum').JobPageType;
  2. const JobApi = require('../net/JobApi');
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. titleText: cc.RichText,
  8. confirmText: cc.RichText,
  9. pageView: cc.PageView,
  10. levelUpNode: cc.Node,
  11. top: cc.Node,
  12. consume: cc.Node,
  13. user: cc.Node,
  14. myActor: [],
  15. changeJobSuccessPrefab: cc.Prefab,
  16. levelUpSuccessPrefab: cc.Prefab,
  17. failPrefab: cc.Prefab,
  18. tipsNode: cc.Node,
  19. tipsLabel: cc.Label,
  20. },
  21. // LIFE-CYCLE CALLBACKS:
  22. onLoad() {
  23. let offset = cc.view.getVisibleSize().height < 1624 ? 100 : 0;
  24. this.top.y = cc.view.getVisibleSize().height / 2 - this.top.height / 2 + offset;
  25. this.node.height = cc.view.getVisibleSize().height;
  26. },
  27. start() {
  28. },
  29. showFromTalent(type, actors) {
  30. this.myActor = actors;
  31. this.show(type, this.myActor.pop(), 0);
  32. },
  33. show(type, actorInfo, zIndex) {
  34. this.type = type;
  35. this.actorInfo = actorInfo;
  36. this.node.parent = cc.find('Canvas');
  37. this.node.active = true;
  38. this.node.zIndex = zIndex + 1;
  39. switch (type) {
  40. case JobPageType.ChangeJob:
  41. this.changeJob();
  42. break;
  43. case JobPageType.ChooseJob:
  44. this.chooseJob(actorInfo);
  45. break;
  46. case JobPageType.LevelUp:
  47. this.levelUp();
  48. break;
  49. }
  50. },
  51. changeJob() {
  52. this.consume.active = true;
  53. this.user.active = false;
  54. this.pageView.node.active = true;
  55. this.levelUpNode.active = false;
  56. this.pageView.node.y = -174;
  57. this.pageView.getComponent('PVCtrl').bind(this.actorInfo.jobId);
  58. this.titleText.string = '<outline color=#690802 width=3><b>职业转换</b></outline>';
  59. this.confirmText.string = '<outline color=#690802 width=1><b>转职</b></outline>';
  60. JobApi.changeJobList(this.actorInfo.uid,
  61. (response) => {
  62. // this.pageView.getComponent('PVCtrl').bindJobList(response.jobList);
  63. this.consume.getComponent('Consume').bindChangeJob(response.itemConsume, response.userPack);
  64. },
  65. (code, msg) => {
  66. this.showTips('网络错误');
  67. }
  68. );
  69. },
  70. chooseJob() {
  71. this.consume.active = false;
  72. this.user.active = true;
  73. this.pageView.node.active = true;
  74. this.levelUpNode.active = false;
  75. this.pageView.node.y = -380;
  76. this.pageView.getComponent('PVCtrl').bind();
  77. this.titleText.string = '<outline color=#690802 width=3><b>选择职业</b></outline>';
  78. this.confirmText.string = '<outline color=#690802 width=1><b>确定</b></outline>';
  79. this.bindChooseJob(this.actorInfo);
  80. },
  81. levelUp() {
  82. this.consume.active = true;
  83. this.user.active = false;
  84. this.pageView.node.active = false;
  85. this.levelUpNode.active = true;
  86. this.titleText.string = '<outline color=#690802 width=3><b>进阶</b></outline>';
  87. this.confirmText.string = '<outline color=#690802 width=1><b>进阶</b></outline>';
  88. let self = this;
  89. JobApi.levelUpInfo(this.actorInfo.uid,
  90. (response) => {
  91. this.consume.getComponent('Consume').bindDataLevelUp(response.itemConsume, response.userPack);
  92. this.levelUpNode.getComponent('LevelUp').bind(self.actorInfo, response.upgradeVo);
  93. this.upgradeName = response.upgradeVo.jobLevelName;
  94. this.upgradeLevel = self.actorInfo.jobLevel + 1;
  95. },
  96. (code, msg) => {
  97. this.showTips('网络错误');
  98. }
  99. );
  100. },
  101. confirmClick() {
  102. switch (this.type) {
  103. case JobPageType.ChangeJob:
  104. var job = this.pageView.getComponent('PVCtrl').getCurrentJob();
  105. JobApi.changeJob(this.actorInfo.uid, job.id,
  106. (response, msg) => {
  107. this.onChangeJobSuccess(msg);
  108. },
  109. (code, msg) => {
  110. this.onFail(msg);
  111. });
  112. break;
  113. case JobPageType.ChooseJob:
  114. var job = this.pageView.getComponent('PVCtrl').getCurrentJob();
  115. JobApi.chooseJob(this.actorInfo.uid, job.id,
  116. (response) => {
  117. this.onFail('选择成功', () => {
  118. this.nextChoose();
  119. });
  120. },
  121. (code, msg) => {
  122. this.onFail(msg);
  123. });
  124. break;
  125. case JobPageType.LevelUp:
  126. JobApi.levelUp(this.actorInfo.uid,
  127. (response) => {
  128. this.showTips(response.msg);
  129. this.onLevelUpSuccess();
  130. },
  131. (code, msg) => {
  132. this.onFail(msg);
  133. });
  134. break;
  135. }
  136. },
  137. close() {
  138. this.node.destroy();
  139. this.node.zIndex = 0;
  140. },
  141. nextChoose() {
  142. if (this.myActor && this.myActor.length > 0) {
  143. this.actorInfo = this.myActor.pop();
  144. this.bindChooseJob();
  145. } else {
  146. this.close();
  147. Global.GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  148. }
  149. },
  150. bindChooseJob() {
  151. this.user.getComponent('Actor').bind(this.actorInfo);
  152. },
  153. onChangeJobSuccess(msg) {
  154. var job = this.pageView.getComponent('PVCtrl').getCurrentJob();
  155. this.changeJobSuccess = cc.instantiate(this.changeJobSuccessPrefab);
  156. this.changeJobSuccess = this.changeJobSuccess.getComponent('ChangeJobSuccess');
  157. this.changeJobSuccess.show(this.node, this.actorInfo, job, msg, () => {
  158. this.close();
  159. });
  160. Global.GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  161. },
  162. onLevelUpSuccess() {
  163. this.levelUpSuccess = cc.instantiate(this.levelUpSuccessPrefab);
  164. this.levelUpSuccess = this.levelUpSuccess.getComponent('JobLevelUpSuccess');
  165. this.levelUpSuccess.show(this.node, '进阶成功', '恭喜你的艺人进阶成为:', this.upgradeLevel, this.upgradeName, () => {
  166. this.close();
  167. });
  168. Global.GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  169. },
  170. onFail(msg, callback) {
  171. this.fail = cc.instantiate(this.failPrefab);
  172. this.fail = this.fail.getComponent('JobPageFail');
  173. this.fail.show(this.node, msg, callback);
  174. },
  175. setNeedChooseJobUsers(users) {
  176. this.myActor = users;
  177. },
  178. pageviewChangeEvent() {
  179. console.log('page change: ', this.pageView.getCurrentPageIndex());
  180. },
  181. showTips(text) {
  182. this.tipsNode.active = true;
  183. this.tipsLabel.string = text;
  184. this.scheduleOnce(() => {
  185. this.tipsNode.active = false;
  186. }, 2);
  187. }
  188. // update (dt) {},
  189. });