UI_treasure.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, Component, Node } from 'cc';
  2. import ui_base from '../../../core/ui/ui_base';
  3. import { ModuleDef } from '../../../scripts/ModuleDef';
  4. import { GameUILayers } from '../../../core/ui/ui';
  5. import { Layout_treasure } from './Layout_treasure';
  6. import { ani_ui, button_sound, GameLink } from '../../game/GameLink';
  7. import { ch } from '../../../ch/ch';
  8. import { data_type } from '../../game/Player';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('UI_treasure')
  11. export class UI_treasure extends ui_base {
  12. constructor() {
  13. super(ModuleDef.Link, 'ui/treasure/UI_treasure', GameUILayers.HUD, Layout_treasure);
  14. }
  15. protected async onCreated() {
  16. const layout = this.getLayout<Layout_treasure>();
  17. ani_ui(layout.cloose_btn.node.parent);
  18. this.onButtonEvent(layout.cloose_btn, (button: any) => {
  19. button_sound();
  20. this.close();
  21. }, this);
  22. this.onButtonEvent(layout.get_btn, async (button: any) => {
  23. button_sound();
  24. //广告链接看完之后执行以下内容
  25. const ret = await chsdk.playRewardAd('获得道具');
  26. if (ret) {
  27. ch.audio.playOneShot('sounds/sfx_add_item');
  28. GameLink.getInst().player.add_item(2, 1);//刷新
  29. GameLink.getInst().player.add_item(3, 2);//提示
  30. GameLink.getInst().player.setDirty();
  31. GameLink.getInst().player.save();
  32. //开始倒计时
  33. GameLink.getInst().player.set_bx_time(300);
  34. this.close();
  35. }
  36. }, this);
  37. }
  38. }