UECell.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import ResSprite from "../../frameWork/compment/ResSprite";
  2. import UEBase from "../../frameWork/compment/UEBase";
  3. import { HcUnlock } from "../../shared/hc/PtlHcInfo";
  4. import UECube from "./UECube";
  5. const { ccclass, property } = cc._decorator;
  6. export interface I_CellData {
  7. zIndex: number;
  8. ueCube: UECube;
  9. unlock: HcUnlock;
  10. }
  11. @ccclass
  12. export default class UECell extends UEBase {
  13. static readonly BundleKey: string = "gridMap";
  14. static readonly PrefabUrl: string = "UECell";
  15. static readonly CLS: string = "UECell";
  16. @property(cc.Node)
  17. private node_select: cc.Node = null!;
  18. @property(ResSprite)
  19. private sp_quality: ResSprite = null;
  20. @property(cc.Node)
  21. private node_lock: cc.Node = null;
  22. cellData: I_CellData = null!;
  23. Init(cellData: I_CellData) {
  24. this.cellData = cellData;
  25. this.node.zIndex = cellData.zIndex;
  26. this.SetQuality();
  27. this.SetLock();
  28. }
  29. SetCube(cube: UECube) {
  30. this.cellData.ueCube = cube;
  31. this.SetQuality();
  32. }
  33. SetQuality() {
  34. if (this.cellData.ueCube && !this.IsLock()) {
  35. this.cellData.ueCube.SetZIndex(this.cellData.zIndex);
  36. let quality = this.cellData.ueCube.GetQuality();
  37. this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban0${quality}`);
  38. } else {
  39. this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban00`);
  40. }
  41. }
  42. IsLock(): boolean {
  43. return this.cellData.unlock == HcUnlock.off;
  44. }
  45. ChangeLockState(unlock: HcUnlock) {
  46. this.cellData.unlock = unlock;
  47. this.SetLock();
  48. }
  49. SetLock() {
  50. if (this.cellData.unlock == HcUnlock.off) {
  51. this.node_lock.active = true;
  52. if (this.cellData.ueCube) {
  53. this.cellData.ueCube.node.active = false;
  54. }
  55. } else {
  56. this.node_lock.active = false;
  57. if (this.cellData.ueCube) {
  58. this.cellData.ueCube.node.active = true;
  59. }
  60. }
  61. }
  62. GetZIndex() {
  63. return this.cellData.zIndex;
  64. }
  65. SetSelect(isSelect: boolean) {
  66. this.node_select.active = isSelect;
  67. }
  68. /** 是否有物品可以拖动 */
  69. CanDrag(): boolean {
  70. return !this.IsEmpty() && this.cellData.ueCube.CanDrag() && !this.IsLock();
  71. }
  72. GetCube(): UECube {
  73. return this.cellData.ueCube;
  74. }
  75. /** 该棋格是否是空的 */
  76. IsEmpty(): boolean {
  77. return this.cellData.ueCube == null;
  78. }
  79. /** 清空棋格里的棋子 */
  80. ClearCube() {
  81. this.cellData.ueCube.unUse();
  82. this.cellData.ueCube = null;
  83. this.SetQuality();
  84. }
  85. MoveCubeToCell(toCell: UECell) {
  86. this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
  87. }
  88. }