ChangeJob.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.onLevelUpSuccess();
  129. },
  130. (code, msg) => {
  131. this.onFail(msg);
  132. });
  133. break;
  134. }
  135. },
  136. close() {
  137. this.node.destroy();
  138. this.node.zIndex = 0;
  139. },
  140. nextChoose() {
  141. if (this.myActor && this.myActor.length > 0) {
  142. this.actorInfo = this.myActor.pop();
  143. this.bindChooseJob();
  144. } else {
  145. this.close();
  146. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  147. }
  148. },
  149. bindChooseJob() {
  150. this.user.getComponent('Actor').bind(this.actorInfo);
  151. },
  152. onChangeJobSuccess(msg) {
  153. let self = this;
  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. self.close();
  159. });
  160. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  161. },
  162. onLevelUpSuccess() {
  163. let self = this;
  164. this.levelUpSuccess = cc.instantiate(this.levelUpSuccessPrefab);
  165. this.levelUpSuccess = this.levelUpSuccess.getComponent('JobLevelUpSuccess');
  166. this.levelUpSuccess.show(this.node, '进阶成功', '恭喜你的艺人进阶成为:', this.upgradeLevel, this.upgradeName, () => {
  167. self.close();
  168. });
  169. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  170. },
  171. onFail(msg, callback) {
  172. this.fail = cc.instantiate(this.failPrefab);
  173. this.fail = this.fail.getComponent('JobPageFail');
  174. this.fail.show(this.node, msg, callback);
  175. },
  176. setNeedChooseJobUsers(users) {
  177. this.myActor = users;
  178. },
  179. pageviewChangeEvent() {
  180. console.log('page change: ', this.pageView.getCurrentPageIndex());
  181. },
  182. showTips(text) {
  183. this.tipsNode.active = true;
  184. this.tipsLabel.string = text;
  185. this.scheduleOnce(() => {
  186. this.tipsNode.active = false;
  187. }, 2);
  188. }
  189. // update (dt) {},
  190. });