UI_Task_Item.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Button, Component, Label, Node, ProgressBar, Sprite, SpriteFrame } from 'cc';
  2. import { gui } from '../../../core/ui/ui';
  3. import { UI_Task } from './UI_Task';
  4. import { Toast } from '../../../core/util_class/Toast';
  5. import ch_audio from '../../../ch/audio/audio';
  6. import { Hall } from '../../hall/Hall';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('UI_Task_Item')
  9. export class UI_Task_Item extends Component {
  10. @property(ProgressBar)
  11. progressBar: ProgressBar;
  12. @property(Label)
  13. Des: Label;
  14. @property(Button)
  15. Get: Button;
  16. @property(Sprite)
  17. Get_Bg: Sprite;
  18. @property([SpriteFrame])
  19. Get_Bgs: SpriteFrame[] = [];
  20. config:any;
  21. @property
  22. index: number;
  23. state: boolean;
  24. start() {
  25. this.Get.node.on(Button.EventType.CLICK, this.add_Item, this);
  26. }
  27. update(deltaTime: number) {
  28. }
  29. //更新进度
  30. show(flag: boolean, config) {
  31. this.config=config;
  32. this.state = flag;
  33. switch (config.type) {
  34. //消除
  35. case 1: this.progressBar.progress = Hall.getInstance().player.get_use_item_num() / config.goal;
  36. this.Des.string = `${Hall.getInstance().player.get_use_item_num()}/${config.goal}`;
  37. break;
  38. //洗牌 合成
  39. case 2:
  40. this.progressBar.progress = Hall.getInstance().player.get_combine_num() / config.goal;
  41. this.Des.string = `${Hall.getInstance().player.get_combine_num()}/${config.goal}`;
  42. break;
  43. //清空 登陆
  44. case 3: this.progressBar.progress = Hall.getInstance().player.get_login_num() / config.goal;
  45. this.Des.string = `${Hall.getInstance().player.get_login_num()}/${config.goal}`;
  46. break;
  47. //铜币 过关
  48. case 4: this.progressBar.progress = Hall.getInstance().player.get_pass_level() / config.goal;
  49. this.Des.string = `${Hall.getInstance().player.get_pass_level()}/${config.goal}`;
  50. break;
  51. //时间 广告
  52. case 5: this.progressBar.progress = Hall.getInstance().player.get_watch_ad_num() / config.goal;
  53. this.Des.string = `${Hall.getInstance().player.get_watch_ad_num()}/${config.goal}`;
  54. break;
  55. }
  56. if (this.progressBar.progress == 1) {
  57. if (this.state) {
  58. this.Des.string = '已领取';
  59. this.Get.interactable = false;
  60. this.Get_Bg.spriteFrame = this.Get_Bgs[0]
  61. } else {
  62. this.Des.string = '可领取';
  63. this.Get.interactable = true;
  64. this.Get_Bg.spriteFrame = this.Get_Bgs[1];
  65. }
  66. } else {
  67. this.Get.interactable = false;
  68. this.Get_Bg.spriteFrame = this.Get_Bgs[0];
  69. }
  70. }
  71. //添加东西
  72. add_Item() {
  73. ch_audio.getInstance().playOneShot('sound/click_Btn');
  74. if (this.progressBar.progress == 1 && this.state == false) {
  75. if (this.config.type != 4) {
  76. Hall.getInstance().player.add_item(this.config.type, 1);
  77. Toast.makeText(gui.getLayerNode(5),'获得道具:'+this.config.name).show();
  78. }
  79. else if (this.config.type == 4) {
  80. Hall.getInstance().player.set_coin(Hall.getInstance().player.get_coin() + 100);
  81. Toast.makeText(gui.getLayerNode(5),'获得铜币:X'+this.config.num).show();
  82. }
  83. this.state = true;
  84. this.Des.string = '已领取';
  85. this.Get_Bg.spriteFrame = this.Get_Bgs[0];
  86. this.Get.interactable = false;
  87. gui.get(UI_Task).update_task_state(true, this.index);
  88. }
  89. }
  90. }