PlantPanel.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. }
  16. getItemDataByID(id) {
  17. let len = this.list_data.length;
  18. for (var i = 0; i < len; i++) {
  19. if (this.list_data[i].picture == id) {
  20. return i;
  21. }
  22. }
  23. return 0;
  24. }
  25. update(dt)
  26. {
  27. if(gData.plantData.init_ani)
  28. {
  29. gData.plantData.init_ani = false;
  30. if (gData.gameData.playerProp.userFarmTaskInfo) {
  31. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  32. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  33. let addAni = cc.instantiate(this.node_ani);
  34. addAni.parent = this.node_ani.parent;
  35. addAni.getComponent(cc.Label).string = `百元红包:${com}/${count}`;
  36. cc.tween(addAni).delay(0.7).call(()=>{
  37. addAni.opacity = 255;
  38. }).by(0.8, {y : 100}).to(0.4, {opacity : 0}).call(()=>{
  39. addAni.destroy();
  40. }).start();
  41. }
  42. }
  43. }
  44. /**
  45. * 初始化滚动视图
  46. */
  47. private initScollView() {
  48. this.list_data = gData.plantData.productArr;
  49. this.tableView.node.emit('srollview-init', this.list_data)
  50. if(gData.plantData.productIndex > 1)
  51. {
  52. cc.tween(this).delay(0.2).call(()=>{
  53. if(this.list_data.length > 4)
  54. {
  55. if(gData.plantData.productIndex <= this.list_data.length-4)
  56. {
  57. this.tableView.contentMoveByIndex(gData.plantData.productIndex-1, 0.2);
  58. }else{
  59. //this.tableView.moveButtom();
  60. this.tableView.contentMoveByIndex(this.list_data.length-4, 0.2, true);
  61. }
  62. }
  63. }).start();
  64. }
  65. }
  66. onDestroy() {
  67. // this.tableView.clearItem();
  68. }
  69. public closeUI()
  70. {
  71. mk.event.emit("moveUpAndDownFarmMapUI", false);
  72. }
  73. }