RewardChapter.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { _decorator, Component, Label, Node, sp } from 'cc';
  2. import { BattleManager } from '../../../manager/BattleManager';
  3. import { BattleData } from '../../../data/BattleData';
  4. import { Framework } from '../../../../framework/Framework';
  5. import { GameEvent } from '../../../data/GameEvent';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('RewardChapter')
  8. export class RewardChapter extends Component {
  9. @property({type:Label,tooltip:'当前章节'})
  10. curChapterLabel:Label = null;
  11. @property({type:Label,tooltip:'当前章节是否可领取'})
  12. tipsChapterLabel:Label = null;
  13. curChapter:number = 0;
  14. protected onLoad(): void {
  15. Framework.event.addEvent(GameEvent.BattleDuplicateReward, ()=>{
  16. this.updateChapter()
  17. },this);
  18. }
  19. show() {
  20. this.curChapter = BattleData.duplicate.chapter
  21. this.node.active = true
  22. this.updateChapter()
  23. }
  24. private onTouchButton(event: Event) {
  25. //Framework.audio.playEffect(AudioID.Click);
  26. let target: any = event.target;
  27. switch (target.name) {
  28. case "get_btn":
  29. // this.node.active = false
  30. if(this.curChapter > BattleManager.getRewardChapter()){
  31. return
  32. }
  33. if(!BattleData.checkDuplicate(this.curChapter)){
  34. BattleManager.sendBattleDuplicateRewardMsg(this.curChapter)
  35. }
  36. break;
  37. case "left_btn":
  38. this.curChapter = this.curChapter > 1 ? this.curChapter - 1 : 1
  39. this.updateChapter()
  40. break;
  41. case "right_btn":
  42. this.curChapter = this.curChapter < BattleData.duplicate.chapter ? this.curChapter + 1 : BattleData.duplicate.chapter
  43. this.updateChapter()
  44. break;
  45. case "close_btn":
  46. this.node.active = false
  47. break;
  48. default:
  49. console.log("功能尚未开放")
  50. break;
  51. }
  52. }
  53. updateChapter()
  54. {
  55. this.curChapterLabel.string = `第 ${this.curChapter} 章`
  56. if(this.curChapter > BattleManager.getRewardChapter()){
  57. this.tipsChapterLabel.string = ""
  58. return
  59. }
  60. if(BattleData.checkDuplicate(this.curChapter)){
  61. this.tipsChapterLabel.string = "已领取"
  62. }
  63. else{
  64. this.tipsChapterLabel.string = "点击领取章节奖励"
  65. }
  66. }
  67. }