UI_LatticeFull.ts 3.5 KB

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