UI_LatticeFull.ts 3.8 KB

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