item_level.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Label, log, Node, Sprite } from 'cc';
  2. import { BundleName } from 'db://assets/script/Config/EnumCfg';
  3. import { GameCfg } from 'db://assets/script/Config/GameCfg';
  4. import { LayerMgr } from 'db://assets/script/Manager/LayerMgr';
  5. import { page_game } from './page_game';
  6. import { Today, User } from 'db://assets/script/Manager/LocalDataMgr';
  7. import EventMgr from 'db://assets/script/Manager/EventMgr';
  8. import { page_unlock } from './page_unlock';
  9. import { gamecfg } from '../dtta/interfaceMgr';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('item_level')
  12. export class item_level extends Component {
  13. @property(Label)
  14. txt_title: Label = null;
  15. @property(Sprite)
  16. img_show: Sprite = null
  17. @property(Node)
  18. node_lock: Node = null;
  19. data: gamecfg = null
  20. index: number = 0
  21. Init(data: gamecfg, index: number) {
  22. this.txt_title.string = data.title;
  23. this.data = data;
  24. this.index = index;
  25. LayerMgr.instance.ShowSprite(BundleName.hall, "image/levelbg/level" + data.unit, this.img_show.node)
  26. if (User.userData.unlockUnits.indexOf(data.unit) != -1 || Today.todayData.isUnlockAll) {
  27. this.node_lock.active = false;
  28. } else {
  29. this.node_lock.active = true;
  30. }
  31. EventMgr.ins.addEventListener("unlock_unit", (unit) => {
  32. if (unit == this.data.unit) {
  33. this.node_lock.active = false;
  34. }
  35. }, this)
  36. EventMgr.ins.addEventListener("unlock_all", (unit) => {
  37. this.node_lock.active = false;
  38. }, this)
  39. EventMgr.ins.addEventListener("daojishi_over", () => {
  40. if (User.userData.unlockUnits.indexOf(this.data.unit) == -1) {
  41. this.node_lock.active = true;
  42. }
  43. }, this)
  44. }
  45. OnClickThis() {
  46. if (User.userData.unlockUnits.indexOf(this.data.unit) != -1 || Today.todayData.isUnlockAll) {
  47. GameCfg.CurUnit = this.index;
  48. log(GameCfg.CurUnit + " " + this.index)
  49. LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_game", (node) => {
  50. node.getComponent(page_game).Init(this.data)
  51. })
  52. } else {
  53. console.error("没有解锁")
  54. LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_unlock", (node) => {
  55. node.getComponent(page_unlock).data = this.data
  56. })
  57. }
  58. }
  59. }