LevelItem.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import hallScene from "../../hallScene";
  2. import { App } from "../../Manager/App";
  3. import SuperListItem from "../SuperScrollview/SuperListItem";
  4. import TipPanel from "../tipPanel/TipPanel";
  5. import TipPanelMediator from "../tipPanel/TipPanelMediator";
  6. import NodeLevel from "./NodeLevel";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class LevelItem extends SuperListItem {
  10. @property(cc.Label)
  11. label: cc.Label = null;
  12. private level: number = 1;
  13. @property(cc.Node)
  14. lock: cc.Node = null;
  15. @property(cc.Node)
  16. open: cc.Node = null;
  17. @property(cc.Node)
  18. pass: cc.Node = null;
  19. @property([cc.Node])
  20. star: cc.Node[] = [];
  21. @property(cc.Node)
  22. key: cc.Node = null;
  23. private isPass: boolean = false;
  24. // LIFE-CYCLE CALLBACKS:
  25. onLoad() {
  26. // this.lock.on(cc.Node.EventType.TOUCH_END, this.btnClickCallBack.bind(this), this);
  27. this.open.on(cc.Node.EventType.TOUCH_END, this.btnClickCallBack.bind(this), this);
  28. this.pass.on(cc.Node.EventType.TOUCH_END, this.btnClickCallBack.bind(this), this);
  29. }
  30. setData(data: any) {
  31. // console.log('LevelItem:', data)
  32. this.label.string = data;
  33. this.level = Number(data);
  34. // 判断这一关是都通过,通过是否有值
  35. this.isPass = (App.DataManager.PassProgress[this.level]) ? true : false;
  36. this.lock.active = !this.isPass;
  37. this.label.node.active = this.isPass;
  38. if(this.isPass){
  39. if(App.DataManager.PassProgress[this.level] > 3){
  40. this.pass.active = true;
  41. }
  42. else if(App.DataManager.PassProgress[this.level] > 1){
  43. this.pass.active = true;
  44. }
  45. else{
  46. this.open.active = true;
  47. this.pass.active = false;
  48. }
  49. for(let i = 0; i < 3; i++){
  50. let star = this.node.getChildByName("star" + i);
  51. let passStar = Number(App.DataManager.PassProgress[this.level]);
  52. star.active = passStar - 1 > i;
  53. }
  54. }
  55. else{
  56. for(let i = 0; i < 3; i++){
  57. let star = this.node.getChildByName("star" + i);
  58. star.active = false;
  59. }
  60. }
  61. console.log('是否通关', App.DataManager.PassProgress[this.level]);
  62. this.key.active = App.DataManager.PassProgress[this.level] > App.DataManager.keyPos[this.level];
  63. }
  64. btnClickCallBack(){
  65. if (this.isPass) {
  66. if(App.DataManager.PassProgress[this.level] > 3){
  67. console.log('Game level pass~');
  68. App.Facade.popView(TipPanelMediator, TipPanel, "Game level pass~", false);
  69. return;
  70. }
  71. else{
  72. cc.find("Canvas/ChooseLevelPanel/nodeLevel").getComponent(NodeLevel).freshLevelNum(this.level);
  73. // console.log("aaa---------------", cc.find("Canvas/ChooseLevelPanel/nodeLevel").name);
  74. }
  75. }
  76. else{
  77. console.log('Level not unlocked~');
  78. App.Facade.popView(TipPanelMediator, TipPanel, "Level not unlocked~", false);
  79. return;
  80. }
  81. }
  82. }