UI_item.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import { button_sound, GameLink, notify } from '../../game/GameLink';
  3. import { week_data_type } from '../../game/Player';
  4. import { gui } from '../../../core/ui/ui';
  5. import { UI_lsbx } from './UI_lsbx';
  6. import { UINotify } from '../../../module_basic/ui_notify/UINotify';
  7. import ch_util from '../../../ch/ch_util';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('UI_item')
  10. export class UI_item extends Component {
  11. @property(Button)
  12. private btn: Button = null;
  13. @property(Node)
  14. private wdl: Node = null;
  15. @property(Node)
  16. private have: Node = null;
  17. @property(Node)
  18. private mask: Node = null;
  19. @property({type:Number})
  20. public index:number;
  21. start() {
  22. }
  23. private onClick() {
  24. button_sound();
  25. GameLink.getInst().player.set_ylq_ls(1);
  26. this.get_reward();
  27. console.log(GameLink.getInst().player.get_ylq_ls());
  28. this.show_Have();
  29. }
  30. public show_Have() {
  31. this.have.active = true;
  32. this.btn.node.off(Button.EventType.CLICK, this.onClick, this);
  33. }
  34. public hide_Mask() {
  35. this.wdl.active = false;
  36. this.mask.active = false;
  37. }
  38. public unlock() {
  39. this.btn.node.on(Button.EventType.CLICK, this.onClick, this);
  40. }
  41. private get_reward(){
  42. if (gui.get(UI_lsbx).items_value[this.index][0] == 1) {
  43. GameLink.getInst().player.add_item(3, gui.get(UI_lsbx).items_value[this.index][1]);
  44. UINotify.show("提示道具+3");
  45. }
  46. else if (gui.get(UI_lsbx).items_value[this.index][0] == 2) {
  47. for (let i = 0; i < gui.get(UI_lsbx).items_value[this.index][1]; i++) {
  48. GameLink.getInst().player.lottery_random_add_skin_block(ch_util.getRandomInt(2,5));
  49. }
  50. UINotify.show("砖块+"+gui.get(UI_lsbx).items_value[this.index][1]);
  51. }
  52. else {
  53. GameLink.getInst().player.set_coin(GameLink.getInst().player.get_coin() + gui.get(UI_lsbx).items_value[this.index][1]);
  54. UINotify.show("金币+" + gui.get(UI_lsbx).items_value[this.index][1]);
  55. }
  56. GameLink.getInst().player.setDirty();
  57. GameLink.getInst().player.save();
  58. }
  59. }