SignTip.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** 签到提示 */
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class SignTip extends cc.Component {
  5. @property(cc.Node)
  6. bg_tip: cc.Node = null;
  7. @property(cc.Label)
  8. lbl_tip: cc.Label = null;
  9. private tipArr = ['次日签到直接领取50元',
  10. '完成签到直接领取50元',
  11. '7日签到领取100元现金大奖',
  12. '7日签到领取100元现金大奖',
  13. '再登录2天领取100元现金大奖',
  14. '再登录1天领取100元现金大奖',
  15. '完成签到即可领取100元现金大奖']
  16. private curTipStr = ''
  17. private totalTime = 0;
  18. private showTime = 10;
  19. private hideTime = 30;
  20. private isShow = null;
  21. onLoad() {
  22. let index = 0;
  23. if (gData.gameData.gameData.loginDays <= 7) {
  24. index = gData.gameData.gameData.loginDays - 1;
  25. }
  26. else {
  27. index = 6;
  28. }
  29. this.curTipStr = this.tipArr[index];
  30. this.lbl_tip.string = this.curTipStr;
  31. if (!gData.sign.haveSignDay()) {
  32. return;
  33. }
  34. this.setShow(true);
  35. }
  36. update(dt) {
  37. if (!gData.sign.haveSignDay()) {
  38. return;
  39. }
  40. this.totalTime += dt;
  41. if (this.isShow) {
  42. if (this.totalTime >= this.showTime) {
  43. this.setShow(false);
  44. }
  45. }
  46. else {
  47. if (this.totalTime >= this.hideTime) {
  48. this.setShow(true);
  49. }
  50. }
  51. }
  52. setShow(state) {
  53. if (this.isShow == state) {
  54. return
  55. }
  56. this.totalTime = 0;
  57. this.isShow = state;
  58. if (state) {
  59. this.bg_tip.active = true;
  60. }
  61. else {
  62. this.bg_tip.active = false;
  63. }
  64. }
  65. lateUpdate() {
  66. this.bg_tip.width = this.lbl_tip.node.width + 24;
  67. }
  68. }