PlantPanel.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /** 可生产产品列表 */
  2. import TableView from "../../../game/component/TableView";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class PlantPanel extends cc.Component {
  6. @property({ type: TableView, displayName: '滚动视图' })
  7. private tableView: TableView = null;
  8. private list_data = null;
  9. @property({ type: cc.Node, tooltip: '文字动画' }) node_ani: cc.Node = null;
  10. start() {
  11. gData.plantData.init_itemIndex = -1;
  12. gData.plantData.init_lock = -1;
  13. this.initScollView();
  14. mk.event.emit("moveUpAndDownFarmMapUI", true);
  15. mk.event.register("close-panel", this.closeUI.bind(this), this);
  16. }
  17. getItemDataByID(id) {
  18. let len = this.list_data.length;
  19. for (var i = 0; i < len; i++) {
  20. if (this.list_data[i].picture == id) {
  21. return i;
  22. }
  23. }
  24. return 0;
  25. }
  26. update(dt)
  27. {
  28. if(gData.plantData.init_ani)
  29. {
  30. gData.plantData.init_ani = false;
  31. if (gData.gameData.playerProp.userFarmTaskInfo) {
  32. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  33. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  34. let addAni = cc.instantiate(this.node_ani);
  35. addAni.parent = this.node_ani.parent;
  36. addAni.getComponent(cc.Label).string = `百元红包:${com}/${count}`;
  37. cc.tween(addAni).delay(0.7).call(()=>{
  38. addAni.opacity = 255;
  39. }).by(0.8, {y : 100}).to(0.4, {opacity : 0}).call(()=>{
  40. addAni.destroy();
  41. }).start();
  42. }
  43. }
  44. }
  45. /**
  46. * 初始化滚动视图
  47. */
  48. private initScollView() {
  49. this.list_data = gData.plantData.productArr;
  50. this.tableView.node.emit('srollview-init', this.list_data)
  51. if(gData.plantData.productIndex > 1)
  52. {
  53. cc.tween(this).delay(0.2).call(()=>{
  54. if(this.list_data.length > 4)
  55. {
  56. if(gData.plantData.productIndex <= this.list_data.length-4)
  57. {
  58. this.tableView.contentMoveByIndex(gData.plantData.productIndex-1, 0.2);
  59. }else{
  60. //this.tableView.moveButtom();
  61. this.tableView.contentMoveByIndex(this.list_data.length-4, 0.2, true);
  62. }
  63. }
  64. }).start();
  65. }
  66. }
  67. onDestroy() {
  68. // this.tableView.clearItem();
  69. mk.event.remove("close-panel", this);
  70. }
  71. public closeUI()
  72. {
  73. mk.event.emit("moveUpAndDownFarmMapUI", false);
  74. }
  75. }