UI_Task_Item.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { _decorator, Button, Component, Label, Node, ProgressBar, Sprite, SpriteFrame } from 'cc';
  2. import { Hall } from '../../hall/Hall';
  3. import { UINotify } from '../../../module_basic/ui_notify/UINotify';
  4. import { gui } from '../../../core/ui/ui';
  5. import { UI_Task } from './UI_Task';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('UI_Task_Item')
  8. export class UI_Task_Item extends Component {
  9. @property(ProgressBar)
  10. progressBar: ProgressBar;
  11. @property(Label)
  12. Des: Label;
  13. @property(Button)
  14. Get: Button;
  15. @property(Sprite)
  16. Get_Bg: Sprite;
  17. @property([SpriteFrame])
  18. Get_Bgs: SpriteFrame[] = [];
  19. @property
  20. type: number = 0;
  21. @property
  22. index: number = 0;
  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, target: number) {
  31. this.state = flag;
  32. switch (this.type) {
  33. //消除
  34. case 1: this.progressBar.progress = Hall.getInstance().player.get_use_item_num() / target;
  35. this.Des.string = `${Hall.getInstance().player.get_use_item_num()}/${target}`;
  36. break;
  37. //洗牌 合成
  38. case 2:
  39. this.progressBar.progress = Hall.getInstance().player.get_combine_num() / target;
  40. this.Des.string = `${Hall.getInstance().player.get_combine_num()}/${target}`;
  41. break;
  42. //清空 登陆
  43. case 3: this.progressBar.progress = Hall.getInstance().player.get_login_num() / target;
  44. this.Des.string = `${Hall.getInstance().player.get_login_num()}/${target}`;
  45. break;
  46. //金币 过关
  47. case 4: this.progressBar.progress = Hall.getInstance().player.get_pass_level() / target;
  48. this.Des.string = `${Hall.getInstance().player.get_pass_level()}/${target}`;
  49. break;
  50. //时间 广告
  51. case 5: this.progressBar.progress = Hall.getInstance().player.get_watch_ad_num() / target;
  52. this.Des.string = `${Hall.getInstance().player.get_watch_ad_num()}/${target}`;
  53. break;
  54. }
  55. if (this.progressBar.progress == 1) {
  56. if (this.state) {
  57. this.Des.string = '已领取';
  58. this.Get_Bg.spriteFrame = this.Get_Bgs[0]
  59. } else {
  60. this.Des.string = '可领取';
  61. this.Get_Bg.spriteFrame = this.Get_Bgs[1];
  62. }
  63. } else {
  64. this.Get_Bg.spriteFrame = this.Get_Bgs[0];
  65. }
  66. }
  67. //添加东西
  68. add_Item() {
  69. if (this.progressBar.progress == 1 && this.state == false) {
  70. if (this.type != 4) {
  71. Hall.getInstance().player.add_item(this.type, 1);
  72. }
  73. else if (this.type == 4) {
  74. Hall.getInstance().player.set_coin(Hall.getInstance().player.get_coin() + 100);
  75. }
  76. this.state = true;
  77. this.Des.string = '已领取';
  78. this.state ? this.Get_Bg.spriteFrame = this.Get_Bgs[0] : this.Get_Bg.spriteFrame = this.Get_Bgs[1];
  79. gui.get(UI_Task).update_task_state(true, this.index);
  80. }
  81. }
  82. }