UI_LatticeFull.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { _decorator, Component, Node } from 'cc';
  2. import ui_base from '../../../core/ui/ui_base';
  3. import { Layout_LatticeFull } from './Layout_LatticeFull';
  4. import { GameUILayers, gui } from '../../../core/ui/ui';
  5. import { ModuleDef } from '../../../Scripts/ModuleDef';
  6. import { UI_Fail } from '../UI_Fail/UI_Fail';
  7. import { ani_ui, UI_Main } from '../UI_Main/UI_Main';
  8. import ch_audio from '../../../ch/audio/audio';
  9. import { Hall } from '../../hall/Hall';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('UI_LatticeFull')
  12. export class UI_LatticeFull extends ui_base {
  13. constructor() {
  14. super(ModuleDef.GAME, 'ui/UI_LatticeFull/LatticeFull', GameUILayers.HUD, Layout_LatticeFull);
  15. }
  16. protected async onCreated() {
  17. const layout = this.getLayout<Layout_LatticeFull>();
  18. ani_ui(layout.Close_Btn.node.parent);
  19. let num1 = Hall.getInstance().player.get_item(1);
  20. if (num1 > 0) {
  21. layout.Empty_Ad.node.active = false;
  22. layout.Empty_RedPoint_num.node.parent.active = true;
  23. layout.Empty_RedPoint_num.string = num1.toString();
  24. } else {
  25. layout.Empty_Ad.node.active = true;
  26. layout.Empty_RedPoint_num.node.parent.active = false;
  27. }
  28. let num2 = Hall.getInstance().player.get_item(3);
  29. if (num2 > 0) {
  30. layout.Eliminate_Ad.node.active = false;
  31. layout.Eliminate_RedPoint_num.node.parent.active = true;
  32. layout.Eliminate_RedPoint_num.string = num2.toString();
  33. } else {
  34. layout.Eliminate_Ad.node.active = true;
  35. layout.Eliminate_RedPoint_num.node.parent.active = false;
  36. }
  37. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.pause);
  38. this.onButtonEvent(layout.Close_Btn, () => {
  39. gui.close(UI_LatticeFull);
  40. gui.show(UI_Fail);
  41. });
  42. this.onButtonEvent(layout.Eliminate, async () => {
  43. ch_audio.getInstance().playOneShot('sound/click_Btn');
  44. if (num1 <= 0) {
  45. const ret = await chsdk.playRewardAd('获得道具' + 1);
  46. if (ret) {
  47. Hall.getInstance().player.add_item(1, 1);
  48. Hall.getInstance().player.use_item(1);
  49. gui.close(UI_LatticeFull);
  50. //直接使用道具
  51. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  52. }
  53. }
  54. else {
  55. Hall.getInstance().player.use_item(1);
  56. gui.close(UI_LatticeFull);
  57. //直接使用道具
  58. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  59. }
  60. });
  61. this.onButtonEvent(layout.Empty, async () => {
  62. ch_audio.getInstance().playOneShot('sound/click_Btn');
  63. if (num2 <= 0) {
  64. const ret = await chsdk.playRewardAd('获得道具' + 3);
  65. if (ret) {
  66. Hall.getInstance().player.add_item(3, 1);
  67. Hall.getInstance().player.use_item(3);
  68. gui.close(UI_LatticeFull);
  69. //直接使用道具
  70. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  71. }
  72. }
  73. else {
  74. Hall.getInstance().player.use_item(3);
  75. gui.close(UI_LatticeFull);
  76. //直接使用道具
  77. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  78. }
  79. });
  80. this.onButtonEvent(layout.Click, () => {
  81. ch_audio.getInstance().playOneShot('sound/click_Btn');
  82. gui.close(UI_LatticeFull);
  83. //放弃此局,跳至结算界面
  84. gui.show(UI_Fail);
  85. });
  86. }
  87. }