MailLayer.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. var List = require("List");
  2. import SoundMgr from "../base/SoundMgr";
  3. import UIMgr from "../base/UIMgr";
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. conNode: cc.Node,
  8. unList: List,
  9. readList: List,
  10. unRead: cc.Node,
  11. read: cc.Node,
  12. noMail: cc.Node,
  13. desNode: cc.Node,
  14. getNode: cc.Node,
  15. delNode: cc.Node,
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad () {
  19. this.adaptor();
  20. },
  21. start () {
  22. this.initData();
  23. },
  24. showMail(hallSceneJs){
  25. this.hallSceneJs = hallSceneJs;
  26. this.node.active = true;
  27. },
  28. initData(){
  29. this.itemOffData = []; //未读
  30. this.itemOnData = []; //已读
  31. for(let i=0; i < 10; i++){
  32. this.itemOffData.push(i);
  33. this.itemOnData.push(i*10);
  34. }
  35. this.unList.numItems = this.itemOffData.length;
  36. this.readList.numItems = this.itemOnData.length;
  37. this.onClickOnOff(-1,1);
  38. },
  39. onClickOnOff(event, bOff){
  40. bOff = bOff == 1;
  41. this.unRead.active = bOff;
  42. this.unList.node.active = bOff;
  43. this.read.active = !bOff;
  44. this.readList.node.active = !bOff;
  45. this.delNode.active = !bOff;
  46. if(this.unRead.active){
  47. this.noMail.active = this.itemOffData.length == 0;
  48. }
  49. if(this.read.active){
  50. this.noMail.active = this.itemOnData.length == 0;
  51. }
  52. },
  53. unListRender(item, idx){
  54. item.active = true;
  55. item.getComponent('ListItem').setInfo(this, this.itemOffData[idx]);
  56. },
  57. readListRender(item, idx){
  58. item.active = true;
  59. item.getComponent('ListItem').setInfo(this, this.itemOnData[idx]);
  60. },
  61. delUnRead(idx){
  62. let self = this;
  63. let func = function(idx){
  64. if (idx != null) {
  65. self.itemOffData.splice(idx, 1);
  66. self.unList.numItems = self.itemOffData.length;
  67. }
  68. }
  69. self.unList.aniDelItem(idx, func);
  70. },
  71. delAllRead(idx){
  72. let self = this;
  73. let func = function(idx){
  74. if (idx != null) {
  75. self.itemOnData.splice(0, self.itemOnData.length);
  76. self.readList.numItems = self.itemOnData.length;
  77. self.noMail.active = self.itemOnData.length == 0;
  78. }
  79. }
  80. self.readList.aniDelItem(idx, func);
  81. this.delNode.getChildByName('mask').active = true;
  82. },
  83. onClickDel(){
  84. SoundMgr.playClick();
  85. this.delAllRead(-1);
  86. },
  87. adaptor(){
  88. let desPos = this.desNode.convertToWorldSpaceAR(cc.v2(0,0));
  89. let lerp = (desPos.y -320) * 2;
  90. this.conNode.setContentSize(this.conNode.width, this.conNode.height + lerp);
  91. this.unList.node.setContentSize(this.unList.node.width, this.unList.node.height + lerp);
  92. let view1 = this.unList.node.getChildByName('view');
  93. view1.setContentSize(view1.width, view1.height + lerp);
  94. this.readList.node.setContentSize(this.readList.node.width, this.readList.node.height + lerp);
  95. let view2 = this.readList.node.getChildByName('view');
  96. view2.setContentSize(view2.width, view2.height + lerp);
  97. },
  98. onClickLook(idx){
  99. this.delUnRead(idx);
  100. UIMgr.openUI('prefabs/MailTipLayer', (pf)=>{
  101. // pf.getComponent('MailTipLayer').closeCb(()=>{
  102. // this.delUnRead(idx);
  103. // });
  104. });
  105. },
  106. onClose(){
  107. SoundMgr.playClick();
  108. this.node.active = false;
  109. this.hallSceneJs.showHides(true);
  110. },
  111. });