sign.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import LayerPanel, {UrlInfo} from "../../../../Common/manage/Layer/LayerPanel";
  2. import Tools from "../../../../Common/Tools";
  3. import gameConfig, {signData, signDataSeven} from "../common/config";
  4. import CacheMgr from "../../../../Common/manage/CacheMgr";
  5. import Constant from "../../../../Common/Constant";
  6. import PanelMgr from "../../../../Common/manage/PanelMgr";
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class Sign extends LayerPanel {
  10. @property([cc.SpriteFrame])
  11. type_spriteFrame: cc.SpriteFrame[] = []
  12. public static getUrl(): UrlInfo {
  13. return {
  14. bundle: "game",
  15. name: "sign"
  16. }
  17. }
  18. private items: cc.Node [] = []
  19. private get: cc.Node = null
  20. private double_get: cc.Node = null
  21. private close: cc.Node = null
  22. initUI() {
  23. this.get = this.getNode("get")
  24. this.onTouch(this.get, this.handle_get)
  25. this.double_get = this.getNode("double")
  26. this.onTouch(this.double_get, this.handle_double_get)
  27. this.close = this.getNode("btn")
  28. this.onTouch(this.close, () => {
  29. PanelMgr.INS.closePanel(Sign) ;
  30. })
  31. let content = this.node.children[0]
  32. for (let i = 0; i < content.childrenCount; i++) {
  33. this.items.push(content.children[i])
  34. if (i == 6) {
  35. // this.changeItem7(content.children[i], gameConfig.singData7)
  36. } else {
  37. this.changeItem(content.children[i], gameConfig.signData[i])
  38. }
  39. if (i == 6) {
  40. this.changeSignStatus7(content.children[i])
  41. } else {
  42. this.changeSignStatus(i, content.children[i])
  43. }
  44. }
  45. if (CacheMgr.setting.signNum >= 6 || CacheMgr.setting.lastSignNum == Tools.date_getTimeNum(new Date)) {
  46. this.hideBtn()
  47. }
  48. }
  49. private changeItem(node: cc.Node, data: signData) {
  50. // let one = node.children[0]
  51. node.children[1].getComponent(cc.Sprite).spriteFrame = this.type_spriteFrame[data.type]
  52. node.children[2].getComponent(cc.Label).string = data.title
  53. }
  54. private changeSignStatus(i: number, node: cc.Node) {
  55. if (i == -1) {
  56. node.getChildByName("mask").active = true
  57. node.getChildByName("签到").active = true
  58. return
  59. }
  60. if (CacheMgr.setting.signNum >= i) {
  61. node.getChildByName("mask").active = true
  62. node.getChildByName("签到").active = true
  63. } else {
  64. node.getChildByName("mask").active = false
  65. node.getChildByName("签到").active = false
  66. }
  67. }
  68. private changeSignStatus7(node: cc.Node, isFalse: boolean = false) {
  69. if (isFalse) {
  70. node.getChildByName("签到").active = true
  71. node.getChildByName("mask").active = true
  72. }
  73. if (CacheMgr.setting.signNum >= 6) {
  74. node.getChildByName("签到").active = true
  75. node.getChildByName("mask").active = true
  76. } else {
  77. node.getChildByName("签到").active = false
  78. node.getChildByName("mask").active = false
  79. }
  80. }
  81. private handle_get() {
  82. if (CacheMgr.setting.signNum == 5) {
  83. gameConfig.singData7.func(1)
  84. CacheMgr.setting.signNum++
  85. this.changeSignStatus7(this.items[6], true)
  86. } else {
  87. let data = gameConfig.signData[CacheMgr.setting.signNum + 1]
  88. CacheMgr.setting.signNum++
  89. this.changeSignStatus(-1, this.items[CacheMgr.setting.signNum])
  90. data.func(data.num)
  91. }
  92. CacheMgr.setting.lastSignNum = Tools.date_getTimeNum(new Date())
  93. CacheMgr.setting = CacheMgr.setting
  94. this.hideBtn()
  95. }
  96. private handle_double_get() {
  97. Tools.handleVideo().then((res) => {
  98. if (res) {
  99. if (CacheMgr.setting.signNum == 5) {
  100. gameConfig.singData7.func(2)
  101. CacheMgr.setting.signNum++
  102. this.changeSignStatus7(this.items[6], true)
  103. } else {
  104. let data = gameConfig.signData[CacheMgr.setting.signNum + 1]
  105. CacheMgr.setting.signNum++
  106. this.changeSignStatus(-1, this.items[CacheMgr.setting.signNum])
  107. data.func(data.num * 2)
  108. }
  109. CacheMgr.setting.lastSignNum = Tools.date_getTimeNum(new Date())
  110. CacheMgr.setting = CacheMgr.setting
  111. this.hideBtn()
  112. }
  113. })
  114. }
  115. private hideBtn() {
  116. this.get.active = false
  117. this.double_get.active = false
  118. }
  119. show(param: any): void {
  120. }
  121. hide() {
  122. }
  123. }