RewardChapter.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }
  23. private onTouchButton(event: Event) {
  24. //Framework.audio.playEffect(AudioID.Click);
  25. let target: any = event.target;
  26. switch (target.name) {
  27. case "get_btn":
  28. // this.node.active = false
  29. if(!BattleData.checkDuplicate(this.curChapter)){
  30. BattleManager.sendBattleDuplicateRewardMsg(this.curChapter)
  31. }
  32. break;
  33. case "left_btn":
  34. this.curChapter = this.curChapter > 1 ? this.curChapter - 1 : 1
  35. this.updateChapter()
  36. break;
  37. case "right_btn":
  38. this.curChapter = this.curChapter < BattleData.duplicate.chapter ? this.curChapter + 1 : BattleData.duplicate.chapter
  39. this.updateChapter()
  40. break;
  41. case "close_btn":
  42. this.node.active = false
  43. break;
  44. default:
  45. console.log("功能尚未开放")
  46. break;
  47. }
  48. }
  49. updateChapter()
  50. {
  51. this.curChapterLabel.string = `第 ${this.curChapter} 章`
  52. if(BattleData.checkDuplicate(this.curChapter)){
  53. this.tipsChapterLabel.string = "已领取"
  54. }
  55. else{
  56. this.tipsChapterLabel.string = "点击领取章节奖励"
  57. }
  58. }
  59. }