PlayerInfoUI.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { EVENT_TYPE } from "../../game/data/GameData";
  2. import GameConst from "../data/GameConst";
  3. import PlayerConst from "../data/PlayerConst";
  4. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  5. import GameLogic from "../util/GameLogic";
  6. import Util from "../util/Util";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class PlayerInfoUI extends cc.Component {
  10. @property(cc.Node)
  11. node_rectBg: cc.Node = null;
  12. @property(cc.Node)
  13. node_closeBtn: cc.Node = null;
  14. @property(cc.Sprite)
  15. spr_head: cc.Sprite = null;
  16. @property(cc.Label)
  17. label_nickName: cc.Label = null;
  18. @property(cc.Label)
  19. label_inviteCode: cc.Label = null;
  20. @property(cc.Node)
  21. node_copyInviteCodeBtn: cc.Node = null;
  22. @property(cc.Node)
  23. node_inputInviteCodeBtn: cc.Node = null;
  24. @property(cc.Label)
  25. label_cashNum: cc.Label = null;
  26. @property(cc.Node)
  27. node_caseOutBtn: cc.Node = null;
  28. @property(cc.Node)
  29. node_inviteBtn: cc.Node = null;
  30. @property(cc.Node)
  31. node_serviceBookBtn: cc.Node = null;
  32. @property(cc.Node)
  33. node_privacyRuleBtn: cc.Node = null;
  34. @property(cc.Node)
  35. node_gameRuleBtn: cc.Node = null;
  36. @property(cc.Node)
  37. node_contactBtn: cc.Node = null;
  38. @property(cc.Node)
  39. node_serviceBookUI: cc.Node = null;
  40. @property(cc.Node)
  41. node_privacyRuleUI: cc.Node = null;
  42. @property(cc.Node)
  43. node_gameRuleUI: cc.Node = null;
  44. @property(cc.Node)
  45. node_contactUI: cc.Node = null;
  46. @property(cc.Label)
  47. label_version: cc.Label = null;
  48. // LIFE-CYCLE CALLBACKS:
  49. // onLoad () {}
  50. start() {
  51. this.addapt();
  52. this.initView();
  53. this.initEvent();
  54. }
  55. // update (dt) {}
  56. onEnable() {
  57. GameMgr.Inst.sendEvent(UI_NAME.PlayerInfoUI, "进入玩家信息界面");
  58. // //显示广告
  59. // AdMgr.Inst.showNativeAd(4, true);
  60. this.initCaseNum();
  61. this.initHead();
  62. this.initNickName();
  63. }
  64. onDisable() {
  65. // //显示广告
  66. // AdMgr.Inst.destroyNativeAd();
  67. }
  68. addapt() {
  69. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  70. }
  71. initView() {
  72. this.initHead();
  73. this.initNickName();
  74. this.initInviteCode();
  75. this.label_version.string = `v${GameConst.appVersion}`;
  76. }
  77. initEvent() {
  78. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  79. this.node_copyInviteCodeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  80. this.node_inputInviteCodeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  81. this.node_caseOutBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  82. this.node_inviteBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  83. this.node_serviceBookBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  84. this.node_privacyRuleBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  85. this.node_gameRuleBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  86. this.node_contactBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  87. if (!GameConst.isAuth) {
  88. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  89. }
  90. }
  91. onClick(event: cc.Event.EventTouch) {
  92. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  93. mk.audio.playEffect("button");
  94. switch (event.currentTarget) {
  95. case this.node_closeBtn:
  96. this.onClickCloseBtn();
  97. break;
  98. case this.node_copyInviteCodeBtn:
  99. this.onClickCopyInviteCodeBtn();
  100. break;
  101. case this.node_inviteBtn:
  102. this.onClickInviteBtn();
  103. break;
  104. case this.node_serviceBookBtn:
  105. this.onClickServiceBookBtn();
  106. break;
  107. case this.node_privacyRuleBtn:
  108. this.onClickPrivacyRuleBtn();
  109. break;
  110. case this.node_gameRuleBtn:
  111. this.onClickGameRuleBtn();
  112. break;
  113. case this.node_contactBtn:
  114. this.onClickContactBtn();
  115. break;
  116. }
  117. }
  118. initHead() {
  119. GameLogic.loadHeadImg("" + "?aaa=aa.jpg", this.spr_head, 95);
  120. }
  121. initNickName() {
  122. this.label_nickName.string = "PlayerConst.nickName";
  123. }
  124. initInviteCode() {
  125. this.label_inviteCode.string = Util.cutStr(GameConst.uin, 8);
  126. }
  127. initCaseNum() {
  128. // let num = Util.numberFixed(PlayerConst.cashNum, 2);
  129. // this.label_cashNum.string = `¥ ${num}`;
  130. }
  131. onClickCloseBtn() {
  132. GameMgr.Inst.sendEvent(UI_NAME.PlayerInfoUI, "点击关闭按钮");
  133. // this.node.active = false;
  134. mk.ui.closePanel("PlayerInfoUI")
  135. }
  136. onClickCopyInviteCodeBtn() {
  137. }
  138. onClickInviteBtn() {
  139. }
  140. onClickServiceBookBtn() {
  141. this.node_serviceBookUI.active = true;
  142. }
  143. onClickPrivacyRuleBtn() {
  144. this.node_privacyRuleUI.active = true;
  145. }
  146. onClickGameRuleBtn() {
  147. this.node_gameRuleBtn.active = true;
  148. }
  149. onClickContactBtn() {
  150. // GameMgr.Inst.sendEvent(UI_NAME.PlayerInfoUI, "点击提现按钮");
  151. this.node_contactBtn.active = true;
  152. }
  153. //自定义事件------------------------------------------------------------------------
  154. /**微信授权返回 */
  155. onWxAuthBack() {
  156. this.initHead();
  157. this.initNickName();
  158. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  159. }
  160. }