UI_HomePage.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { _decorator, Component, Node, tween, Vec3 } 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_HomePage } from './Layout_HomePage';
  6. import { UIManager } from '../UI/UIManager';
  7. import { toggleBreath, toggleSlideOutAndBack_Nodes } from '../../../module_extra/Customize/Customize_Ani';
  8. import { Root } from '../../game/process/Root';
  9. import { button_Sound, SoundName } from '../../../module_extra/Customize/Customize_Sound';
  10. import { Customize_RedPointMgr, NodeName } from '../../../module_extra/Customize/Customize_RedPointMgr';
  11. import { RedPointPersistType, RedPointState, RedPointType } from '../../../module_extra/Customize/Customize_RedPoint';
  12. import { UIName } from '../UI/UI_ClassManager';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('UI_HomePage')
  15. export class UI_HomePage extends ui_base {
  16. private offset: Vec3[] = [
  17. new Vec3(450, 0), // 向右
  18. new Vec3(-450, 0), // 向左
  19. new Vec3(0, -700), // 向下
  20. new Vec3(0, 1334) // 向上
  21. ];
  22. private duration: number = 0.3;
  23. luckyGift: string = "LuckyGift";
  24. subscriptionGift: string = "SubscriptionGift";
  25. piggyBank: string = "PiggyBank";
  26. count = 1;
  27. constructor() {
  28. super(ModuleDef.GAME, "ui/UI_HomePage/HomePage", GameUILayers.HUD, Layout_HomePage);
  29. }
  30. protected onCreated(): void {
  31. Root.getInstance().cancelBlurBg();
  32. const layout = this.getLayout<Layout_HomePage>();
  33. this.initRedPointTree();
  34. this.showPanel();
  35. }
  36. public showPanel(): void {
  37. super.showPanel();
  38. let flag: boolean = false;//是否需要做动画
  39. if (!UIManager.getInstance().Show_Ani) {
  40. UIManager.getInstance().Show_Ani = true;
  41. } else {
  42. flag = true;
  43. }
  44. const layout = this.getLayout<Layout_HomePage>();
  45. let count = 3;
  46. const onOneFinish = () => {
  47. count--;
  48. if (count === 0) {
  49. this.onButtonEvent(layout.Start_Btn, () => {
  50. button_Sound(SoundName.clickUI);
  51. Root.getInstance().Mode = 1;
  52. UIManager.getInstance().DestoryAllUI();
  53. UIManager.getInstance().pushUI(UIName.MAIN);
  54. })
  55. this.onButtonEvent(layout.LuckyGift_Btn, () => {
  56. button_Sound(SoundName.clickUI);
  57. UIManager.getInstance().pushUI(UIName.LUCKYGIFT, true);
  58. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.luckyGift, RedPointState.Hide);
  59. Customize_RedPointMgr.instance.SaveToLocal();
  60. });
  61. this.onButtonEvent(layout.SubscriptionGift_Btn, () => {
  62. button_Sound(SoundName.clickUI);
  63. // UIManager.getInstance().pushUI();
  64. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.subscriptionGift, RedPointState.Hide);
  65. Customize_RedPointMgr.instance.SaveToLocal();
  66. });
  67. this.onButtonEvent(layout.PiggyBank_Btn, () => {
  68. button_Sound(SoundName.clickUI);
  69. UIManager.getInstance().pushUI(UIName.PIGGYBANK, true);
  70. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.piggyBank, RedPointState.Hide);
  71. Customize_RedPointMgr.instance.SaveToLocal();
  72. });
  73. }
  74. };
  75. this.duration = flag ? this.duration : 0;
  76. toggleSlideOutAndBack_Nodes(layout.Left_Groups, this.offset[0], this.duration, onOneFinish);
  77. toggleSlideOutAndBack_Nodes(layout.Right_Groups, this.offset[1], this.duration, onOneFinish);
  78. toggleSlideOutAndBack_Nodes(layout.Down_Groups, this.offset[3], this.duration, onOneFinish);
  79. toggleBreath(layout.Start_Btn.node, 0.8);
  80. }
  81. public new_close() {
  82. const layout = this.getLayout<Layout_HomePage>();
  83. let count = 3;
  84. const onOneFinish = () => {
  85. count--;
  86. if (count === 0) {
  87. super.new_close();
  88. }
  89. };
  90. toggleSlideOutAndBack_Nodes(layout.Left_Groups, this.offset[0], 0.3, onOneFinish);
  91. toggleSlideOutAndBack_Nodes(layout.Right_Groups, this.offset[1], 0.3, onOneFinish);
  92. toggleSlideOutAndBack_Nodes(layout.Down_Groups, this.offset[3], 0.3, onOneFinish);
  93. }
  94. private initRedPointTree() {
  95. if (!Customize_RedPointMgr.instance.GetState(NodeName.homePage, this.luckyGift)) {
  96. console.log("添加");
  97. Customize_RedPointMgr.instance.Add(NodeName.homePage, this.luckyGift, NodeName.homePage, RedPointType.Enternal, RedPointPersistType.Temporary);
  98. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.luckyGift, this.count == 0 ? RedPointState.Hide : RedPointState.Show, this.count);
  99. }
  100. if (!Customize_RedPointMgr.instance.GetState(NodeName.homePage, this.subscriptionGift)) {
  101. console.log("添加");
  102. Customize_RedPointMgr.instance.Add(NodeName.homePage, this.subscriptionGift, NodeName.homePage, RedPointType.Enternal, RedPointPersistType.Temporary);
  103. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.subscriptionGift, this.count == 0 ? RedPointState.Hide : RedPointState.Show, this.count);
  104. }
  105. if (!Customize_RedPointMgr.instance.GetState(NodeName.homePage, this.piggyBank)) {
  106. console.log("添加");
  107. Customize_RedPointMgr.instance.Add(NodeName.homePage, this.piggyBank, NodeName.homePage, RedPointType.Enternal, RedPointPersistType.Temporary);
  108. Customize_RedPointMgr.instance.SetState(NodeName.homePage, this.piggyBank, this.count == 0 ? RedPointState.Hide : RedPointState.Show, this.count);
  109. }
  110. Customize_RedPointMgr.instance.Init(NodeName.homePage, this.luckyGift, this.OnLuckyGiftShow.bind(this));
  111. Customize_RedPointMgr.instance.Init(NodeName.homePage, this.subscriptionGift, this.OnSubscriptionGiftShow.bind(this));
  112. Customize_RedPointMgr.instance.Init(NodeName.homePage, this.piggyBank, this.OnPiggyBankShow.bind(this));
  113. }
  114. private OnLuckyGiftShow(state: RedPointState, data: number = 1) {
  115. const layout = this.getLayout<Layout_HomePage>();
  116. layout.LuckyGift_Btn.node.getChildByName('hint_point').active = state === RedPointState.Show;
  117. }
  118. private OnSubscriptionGiftShow(state: RedPointState, data: number = 1) {
  119. const layout = this.getLayout<Layout_HomePage>();
  120. layout.SubscriptionGift_Btn.node.getChildByName('hint_point').active = state === RedPointState.Show;
  121. }
  122. private OnPiggyBankShow(state: RedPointState, data: number = 1) {
  123. const layout = this.getLayout<Layout_HomePage>();
  124. layout.PiggyBank_Btn.node.getChildByName('hint_point').active = state === RedPointState.Show;
  125. }
  126. }