ClubActiveNode.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import GameM, { AUDIO_TYPE } from "../../manager/GameM";
  2. import PoolMgr, { NODEPOOLPREFABTYPE } from "../../manager/PoolMgr";
  3. import UiM from "../../manager/UiM";
  4. import Random from "../../utils/Random";
  5. import ClubMain from "../ClubMain";
  6. import EffectNode from "../EffectNode";
  7. import ClubShouquShanggong from "./ClubShouquShanggong";
  8. import ClubTixianNode from "./ClubTixianNode";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class ClubActiveNode extends cc.Component {
  12. @property(cc.Node)
  13. bubleOne: cc.Node = null;
  14. @property(cc.Node)
  15. bubleTwo: cc.Node = null;
  16. @property(cc.Node)
  17. bubleThree: cc.Node = null;
  18. @property(cc.Label)
  19. moneyLabel: cc.Label = null
  20. @property(cc.Label)
  21. moneyTwoLabel: cc.Label = null
  22. @property(cc.Node)
  23. dailyNode: cc.Node = null
  24. @property(cc.Node)
  25. otherNode: cc.Node = null
  26. @property(sp.Skeleton)
  27. bubbleBreak: sp.Skeleton = null
  28. @property(cc.Node)
  29. iconNode: cc.Node = null
  30. @property(cc.Node)
  31. bgNode: cc.Node = null
  32. @property(cc.Node)
  33. bubblePNode: cc.Node = null
  34. @property(cc.Node)
  35. bigBubbleNode: cc.Node = null
  36. @property(cc.Node)
  37. dangweiNode: cc.Node = null
  38. @property(cc.Node)
  39. bigBubbleIcon:cc.Node = null
  40. @property([cc.SpriteFrame])
  41. tixianSpriteFrame:cc.SpriteFrame[] = []
  42. bubleDataOne = null
  43. bubleDataTwo = null
  44. bubleDataThree = null
  45. private dailyTixianInfo = null
  46. private maxTixianInfo = null
  47. // LIFE-CYCLE CALLBACKS:
  48. // onLoad () {}
  49. start() {
  50. this.bubleOne.active = false
  51. this.bubleTwo.active = false
  52. this.bubleThree.active = false
  53. let addY = cc.winSize.height - 1334
  54. // this.bgNode.height += addY
  55. this.bubblePNode.y = this.bubblePNode.y - addY * 0.25
  56. this.bigBubbleNode.y = this.bigBubbleNode.y - addY * 0.25
  57. this.dangweiNode.y = this.dangweiNode.y - addY * 0.25
  58. GameM.ClubData.requestClubMyBubbleData()
  59. GameM.ClubData.requestClubWithdrawDenominations()
  60. this.updateMoney()
  61. }
  62. updateTimes() {
  63. // this.leftTimesLabel.string = "剩余提现次数:" + GameM.commonData.roleData.clubLeijiTixian + "/2"
  64. }
  65. updateView(data) {
  66. if (data == null || data == undefined) {
  67. this.showEmptyBubble()
  68. this.downTime = -1
  69. return
  70. }
  71. this.bubleOne.active = false
  72. this.bubleTwo.active = false
  73. this.bubleThree.active = false
  74. if (data.length == 0) {
  75. this.showEmptyBubble()
  76. this.downTime = -1
  77. return
  78. }
  79. for (let i = 0; i < 3; i++) {
  80. let node: cc.Node = null
  81. if (i == 0) {
  82. node = this.bubleOne
  83. this.bubleDataOne = data[i]
  84. } else if (i == 1) {
  85. node = this.bubleTwo
  86. this.bubleDataTwo = data[i]
  87. } else if (i == 2) {
  88. node = this.bubleThree
  89. this.bubleDataThree = data[i]
  90. }
  91. this.initBubleNode(node, data[i])
  92. }
  93. }
  94. showEmptyBubble() {
  95. this.bubleOne.active = false
  96. this.bubleTwo.active = true
  97. this.bubleThree.active = false
  98. this.bubleDataTwo = null
  99. this.bubleTwo.getChildByName("num").getComponent(cc.Label).string = "结算中"
  100. this.bubleTwo.getChildByName("time").getComponent(cc.Label).string = ""
  101. this.bubleTwo.getChildByName("icon").getComponent(cc.Button).interactable = true
  102. this.bubleTwo.getChildByName("qipaoNormal").active = true
  103. this.bubleTwo.getChildByName("qipaoGrey").active = false
  104. this.bubleTwo.getChildByName("desc").getComponent(cc.Label).string = ""
  105. }
  106. initBubleNode(node: cc.Node, info) {
  107. if (info == null || info == undefined) {
  108. return
  109. }
  110. node.active = true
  111. node.getChildByName("num").getComponent(cc.Label).string = info.coinNum
  112. if (info.expired) {
  113. node.getChildByName("qipaoNormal").active = false
  114. node.getChildByName("qipaoGrey").active = true
  115. node.getChildByName("time").getComponent(cc.Label).string = "已过期"
  116. node.getChildByName("icon").getComponent(cc.Button).interactable = false
  117. node.getChildByName("desc").getComponent(cc.Label).string = ""
  118. node.getChildByName("desc").color = cc.Color.WHITE
  119. } else {
  120. node.getChildByName("qipaoNormal").active = true
  121. node.getChildByName("qipaoGrey").active = false
  122. node.getChildByName("time").getComponent(cc.Label).string = ""
  123. node.getChildByName("icon").getComponent(cc.Button).interactable = true
  124. let num = Number(info.generation)
  125. node.getChildByName("desc").color = cc.color(255,253,88)
  126. let str = ""
  127. if(num == 1){
  128. str = "一代贡献"
  129. }else if(num == 2){
  130. str = "二代贡献"
  131. }else if(num == 3){
  132. str = "三代贡献"
  133. }else if(num == 4){
  134. str = "四代贡献"
  135. }else if(num == 5){
  136. str = "五代贡献"
  137. }
  138. node.getChildByName("desc").getComponent(cc.Label).string = str
  139. if(this.downTime <= 0){
  140. if(this.downTime <= 0){
  141. let currentTime = Date.now()
  142. let hours = new Date(currentTime).getHours()
  143. let minitus = new Date(currentTime).getMinutes()
  144. let second = new Date(currentTime).getSeconds()
  145. let leftTime = -1
  146. if (hours > 12) {
  147. leftTime = 36*3600 - hours*3600 - minitus*60 - second
  148. }else{
  149. leftTime = 12*3600 - hours*3600 - minitus*60 - second
  150. }
  151. let time = leftTime
  152. this.downTime = time
  153. }
  154. }
  155. }
  156. }
  157. initTixianBtn(data) {
  158. if (data == null || data == undefined) {
  159. return
  160. }
  161. this.dailyTixianInfo = null
  162. this.maxTixianInfo = null
  163. let count = 0
  164. for (let entry of data) {
  165. if (entry.gearNo == 0) {
  166. this.dailyTixianInfo = entry
  167. this.setNodeInfo(this.dailyNode, entry)
  168. } else {
  169. count ++
  170. //设置累计提现档位,用于统计上报
  171. //每日统计不记录档位
  172. entry.umIndex = count
  173. if (entry.status == 1) {
  174. this.maxTixianInfo = entry
  175. this.setNodeInfo(this.otherNode, entry)
  176. }
  177. }
  178. }
  179. if (this.maxTixianInfo == null) {
  180. for (let i = 0; i < data.length; i++) {
  181. if (data[i].gearNo != 0 && data[i].withdrawTimestamp != 0 && data[i + 1] && data[i + 1].withdrawTimestamp == 0) {
  182. this.maxTixianInfo = data[i + 1]
  183. this.setNodeInfo(this.otherNode, data[i + 1])
  184. break
  185. }
  186. }
  187. }
  188. if (this.maxTixianInfo == null) {
  189. this.maxTixianInfo = data[data.length - 1]
  190. this.setNodeInfo(this.otherNode, data[data.length - 1])
  191. }
  192. }
  193. setNodeInfo(node: cc.Node, info) {
  194. if (info.amount % 10000 != 0) {
  195. node.getChildByName("moneyLabel").getComponent(cc.Label).string = (info.amount / 10000).toFixed(2) + "元"
  196. } else {
  197. node.getChildByName("moneyLabel").getComponent(cc.Label).string = (info.amount / 10000) + "元"
  198. }
  199. if (info.status == 0) {
  200. // node.getComponent(cc.Button).interactable = true
  201. node.getComponent(cc.Sprite).spriteFrame = this.tixianSpriteFrame[2]
  202. } else {
  203. if(info.gearNo == 0){
  204. node.getComponent(cc.Sprite).spriteFrame = this.tixianSpriteFrame[1]
  205. }else{
  206. node.getComponent(cc.Sprite).spriteFrame = this.tixianSpriteFrame[0]
  207. }
  208. // node.getComponent(cc.Button).interactable = false
  209. }
  210. if (info.gearNo == 0) {
  211. node.getChildByName("tishi").getChildByName("tishiLabel").getComponent(cc.Label).string = "每日"
  212. } else {
  213. if (GameM.ClubData.clubBaseInfo.currentAddition > 0) {
  214. node.getChildByName("tishi").active = true
  215. node.getChildByName("tishi").getChildByName("tishiLabel").getComponent(cc.Label).string = "多" + GameM.ClubData.clubBaseInfo.currentAddition + "%"
  216. } else {
  217. node.getChildByName("tishi").active = false
  218. }
  219. }
  220. }
  221. updateMoney() {
  222. if (GameM.ClubData.clubBaseInfo) {
  223. let totalMoney = GameM.ClubData.clubBaseInfo.pool
  224. this.moneyLabel.string = ""
  225. this.moneyTwoLabel.string = (totalMoney / 10000).toFixed(2) + "元"
  226. }
  227. }
  228. showShouyiNode() {
  229. GameM.audioM.playEffect(AUDIO_TYPE.button);
  230. cc.loader.loadRes('prefabs/club/clubShouyiInfo', cc.Prefab, (err, assets) => {
  231. if (err) {
  232. cc.error(err);
  233. return;
  234. }
  235. let node: cc.Node = cc.instantiate(assets)
  236. node.parent = UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode
  237. })
  238. }
  239. showBubleOne() {
  240. // return
  241. GameM.audioM.playEffect(AUDIO_TYPE.button);
  242. this.showShangGongView(this.bubleDataOne, this.bubleOne)
  243. }
  244. showBubleTwo() {
  245. GameM.audioM.playEffect(AUDIO_TYPE.button);
  246. if (this.bubleDataTwo == null || this.bubleDataTwo == undefined) {
  247. this.showShouyiNode()
  248. return
  249. }
  250. // UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode.getComponent(ClubActiveNode).showIconFly(this.bubleTwo)
  251. // return
  252. this.showShangGongView(this.bubleDataTwo, this.bubleTwo)
  253. }
  254. showBubleThree() {
  255. // UiM.Instance.clubMainNode.getComponent(ClubMain).topNode.getComponent(ClubTopNode).showLevelUp()
  256. // return
  257. GameM.audioM.playEffect(AUDIO_TYPE.button);
  258. this.showShangGongView(this.bubleDataThree, this.bubleThree)
  259. }
  260. showShangGongView(info, bubbleNode) {
  261. if (info == null || info == undefined) {
  262. return
  263. }
  264. cc.loader.loadRes('prefabs/club/clubShouquShanggong', cc.Prefab, (err, assets) => {
  265. if (err) {
  266. cc.error(err);
  267. return;
  268. }
  269. let node: cc.Node = cc.instantiate(assets)
  270. node.parent = UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode
  271. node.getComponent(ClubShouquShanggong).initView(info, bubbleNode)
  272. })
  273. }
  274. clickDailyTixian() {
  275. // this.showIconFly(this.bubleTwo)
  276. // UiM.Instance.clubMainNode.getComponent(ClubMain).topNode.getComponent(ClubTopNode).showLevelUp()
  277. // return
  278. GameM.audioM.playEffect(AUDIO_TYPE.button);
  279. if(this.dailyTixianInfo.status == 0){
  280. EffectNode.instance.PlayTip("今日已提现")
  281. return
  282. }
  283. if (GameM.ClubData.clubBaseInfo.pool < this.dailyTixianInfo.amount) {
  284. EffectNode.instance.PlayTip("功德币不足")
  285. return
  286. }
  287. this.readyToLingqu(1 + "", this.dailyTixianInfo.amount / 10000, GameM.ClubData.clubBaseInfo.totalRecruitNum,-1)
  288. // GameM.ClubData.requestClubDoWithdraw(GameM.commonData.version, 1 + "", GameM.ClubData.clubBaseInfo.totalRecruitNum, this.dailyTixianInfo.amount / 10000)
  289. }
  290. clickOtherTixian() {
  291. GameM.audioM.playEffect(AUDIO_TYPE.button);
  292. if(this.maxTixianInfo.status == 0){
  293. EffectNode.instance.PlayTip("今日提现次数不足")
  294. return
  295. }
  296. if (GameM.ClubData.clubBaseInfo.pool < this.maxTixianInfo.amount) {
  297. EffectNode.instance.PlayTip("功德币不足")
  298. return
  299. }
  300. let money = (1+GameM.ClubData.clubBaseInfo.currentAddition/100)*this.maxTixianInfo.amount
  301. if(money % 10000 != 0){
  302. let tempMoney = (money/10000).toFixed(2)
  303. money = Number(tempMoney)
  304. }else{
  305. money = Math.floor(money/10000)
  306. }
  307. this.readyToLingqu(2 + "", money, GameM.ClubData.clubBaseInfo.totalRecruitNum,this.maxTixianInfo.umIndex)
  308. // GameM.ClubData.requestClubDoWithdraw(GameM.commonData.version, 2 + "", GameM.ClubData.clubBaseInfo.totalRecruitNum, this.maxTixianInfo.amount / 10000)
  309. }
  310. updateTixianInfo(type) {
  311. if (type == 1) {
  312. this.dailyNode.getComponent(cc.Button).interactable = false
  313. } else {
  314. this.otherNode.getComponent(cc.Button).interactable = false
  315. }
  316. }
  317. showBubbleBreak(bubbleNode: cc.Node,callback=null) {
  318. bubbleNode.active = false
  319. this.bubbleBreak.node.position = bubbleNode.position
  320. this.bubbleBreak.node.active = true
  321. this.bubbleBreak.setAnimation(0, 'animation', false);
  322. this.scheduleOnce(() => {
  323. GameM.ClubData.requestClubMyBubbleData()
  324. }, 1)
  325. }
  326. showIconFly(bubbleNode: cc.Node) {
  327. // this.iconNode.position = bubbleNode.position
  328. // this.iconNode.active = true
  329. let targetPos = cc.v2(5, 18)
  330. this.showBubbleBreak(bubbleNode)
  331. bubbleNode.active = false
  332. this.PlayCoinAnim(12, 20, cc.v2(bubbleNode.position));
  333. // this.iconNode.runAction(cc.sequence(cc.moveTo(0.5, targetPos), cc.callFunc(() => {
  334. // this.iconNode.active = false
  335. // GameM.ClubData.requestClubMyBubbleData()
  336. // })))
  337. }
  338. readyToLingqu(type, money, peopleNum,index) {
  339. GameM.audioM.playEffect(AUDIO_TYPE.button)
  340. // this.tixianNode.active = true
  341. cc.loader.loadRes('prefabs/club/ClubTixianNode', cc.Prefab, (err, assets) => {
  342. if (err) {
  343. cc.error(err);
  344. return;
  345. }
  346. let node: cc.Node = cc.instantiate(assets)
  347. node.parent = UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode
  348. UiM.Instance.openPanel(node)
  349. node.getComponent(ClubTixianNode).initView(type, money, peopleNum,index)
  350. })
  351. }
  352. /**
  353. * @param type 类型,0 金币,1 红包币 3 鲜花 5 活跃
  354. */
  355. public PlayCoinAnim(type: number = 0, num: number, pos: cc.Vec2, fly: boolean = true) {
  356. let cam_pos;
  357. let tempPos3D = pos
  358. pos = cc.v2(tempPos3D.x, tempPos3D.y);
  359. for (let i = 0; i < num; i++) {
  360. //FC:-
  361. //let copyCoin = cc.instantiate(this.eftPrefabs[type]);//type == 0 ? this.coinPrefab : this.goldPrefab);
  362. //FC:+ 对象池
  363. let copyCoin = null;
  364. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.ClubIcon);
  365. copyCoin.setParent(this.node);
  366. copyCoin.scale = Random.Range(0.8, 1.2, false);
  367. copyCoin.angle = Random.Range(-45, 45, false);
  368. let dir = cc.v2(Random.Range(-1, 1, false), Random.Range(-1, 1, false));
  369. dir = dir.normalize();
  370. let deltaInit = cc.v2(Random.Range(10, 160, false) * dir.x, Random.Range(10, 160, false) * dir.y);
  371. //FC:-无效计算
  372. //let deltaEnd = cc.v2(Random.Range(250, 800, false) * dir.x, Random.Range(250, 800, false) * dir.y);
  373. let initPos = pos.add(deltaInit);
  374. //copyCoin.setPosition(initPos);
  375. copyCoin.setPosition(pos);
  376. this.FlyIn(type, copyCoin, initPos, fly);
  377. }
  378. }
  379. FlyIn(type: number = 0, target: cc.Node, end: cc.Vec2, fly: boolean) {
  380. let ac1
  381. if (fly) {
  382. ac1 = cc.moveTo(Random.Range(0.3, 1, false), end).easing(cc.easeSineOut());
  383. }
  384. else {
  385. ac1 = cc.moveTo(Random.Range(0.3, 0.6, false), end).easing(cc.easeSineOut());
  386. }
  387. let callback = cc.callFunc(() => {
  388. //target.destroy();
  389. if (fly) {
  390. let tarWorldPos = this.bigBubbleIcon.parent.convertToWorldSpaceAR(this.bigBubbleIcon.position)
  391. let curLocalPos = this.node.convertToNodeSpaceAR(tarWorldPos)
  392. this.scheduleOnce(() => { this.FlyOut(type, target, cc.v2(curLocalPos) )}, 0);
  393. }
  394. });
  395. let total = cc.sequence(ac1, callback);
  396. target.runAction(total);
  397. }
  398. FlyOut(type: number = 0, target: cc.Node, end: cc.Vec2) {
  399. let dur = Random.Range(0.3, 1, false);
  400. target.runAction(cc.scaleTo(dur, 0.8));
  401. let ac1 = cc.moveTo(dur, end).easing(cc.easeSineOut());
  402. let callback = cc.callFunc(() => {
  403. //FC:-
  404. //target.destroy();
  405. //FC:+ 对象池
  406. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ClubIcon, target);
  407. //type == 0 ? this.CoinIconAni() : this.RedMoneyIconAni();
  408. });
  409. let total = cc.sequence(ac1, callback);
  410. target.runAction(total);
  411. }
  412. private downTime = -1
  413. private secondTime = 0
  414. update (dt) {
  415. if(this.downTime<0){
  416. return
  417. }
  418. this.secondTime+=dt
  419. if(this.secondTime >=1){
  420. this.downTime -= this.secondTime
  421. this.secondTime = 0
  422. if(this.downTime <0 ){
  423. GameM.ClubData.requestClubMyBubbleData()
  424. return
  425. }
  426. this.checkNeedShowTime()
  427. }
  428. }
  429. checkNeedShowTime(){
  430. let timeStr = this.getTimeTxt()
  431. if(this.bubleDataOne && !this.bubleDataOne.expired){
  432. this.bubleOne.getChildByName("time").getComponent(cc.Label).string = timeStr
  433. }
  434. if(this.bubleDataTwo && !this.bubleDataTwo.expired){
  435. this.bubleTwo.getChildByName("time").getComponent(cc.Label).string = timeStr
  436. }
  437. if(this.bubleDataThree && !this.bubleDataThree.expired){
  438. this.bubleThree.getChildByName("time").getComponent(cc.Label).string = timeStr
  439. }
  440. }
  441. getTimeTxt():string{
  442. if(this.downTime<=0){
  443. return ""
  444. }
  445. let hour = Math.floor(this.downTime/3600)
  446. let minitue = Math.floor((this.downTime%3600)/60)
  447. let second = Math.floor(this.downTime%60)
  448. let hourstr = ""
  449. let minituesStr = ""
  450. let secondsStr = ""
  451. if(hour <10){
  452. hourstr = "0"+hour
  453. }else{
  454. hourstr = hour+""
  455. }
  456. if(minitue<10){
  457. minituesStr = "0"+minitue
  458. }else{
  459. minituesStr = minitue+""
  460. }
  461. if(second<10){
  462. secondsStr ="0"+ second
  463. }else{
  464. secondsStr = second+""
  465. }
  466. return hourstr+":"+minituesStr+":"+secondsStr
  467. }
  468. }