UI_Life.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import ui_base from '../../../core/ui/ui_base';
  3. import { ModuleDef } from '../../../Scripts/ModuleDef';
  4. import { GameUILayers, gui } from '../../../core/ui/ui';
  5. import { Layout_Life } from './Layout_Life';
  6. import { Hall } from '../../hall/Hall';
  7. import ch_audio from '../../../ch/audio/audio';
  8. import { UI_Hall } from '../UI_Hall/UI_Hall';
  9. import { ani_ui } from '../UI_Main/UI_Main';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('UI_Life')
  12. export class UI_Life extends ui_base {
  13. constructor() {
  14. super(ModuleDef.GAME, 'ui/UI_Life/Life', GameUILayers.HUD, Layout_Life);
  15. }
  16. protected onCreated() {
  17. const layout= this.getLayout<Layout_Life>();
  18. ani_ui(layout.Close_Btn.node.parent);
  19. this.onButtonEvent(layout.Close_Btn, () => {
  20. gui.close(UI_Life);
  21. });
  22. this.onButtonEvent(layout.Free_Get_Btn, async() => {
  23. ch_audio.getInstance().pause();
  24. let res=await chsdk.playRewardAd('获得体力');
  25. if(res){
  26. Hall.getInstance().player.set_life(Hall.getInstance().player.get_life()+1);
  27. gui.get(UI_Hall).set_Life(Hall.getInstance().player.get_life());
  28. ch_audio.getInstance().resume();
  29. }
  30. });
  31. this.onButtonEvent(layout.No_Btn, async() => {
  32. gui.close(UI_Life);
  33. });
  34. }
  35. }