UI_Task_Item.ts 3.6 KB

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