UECell.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. SetLock() {
  46. if (this.cellData.unlock == HcUnlock.off) {
  47. this.node_lock.active = true;
  48. if (this.cellData.ueCube) {
  49. this.cellData.ueCube.node.active = false;
  50. }
  51. } else {
  52. this.node_lock.active = false;
  53. if (this.cellData.ueCube) {
  54. this.cellData.ueCube.node.active = true;
  55. }
  56. }
  57. }
  58. GetZIndex() {
  59. return this.cellData.zIndex;
  60. }
  61. SetSelect(isSelect: boolean) {
  62. this.node_select.active = isSelect;
  63. }
  64. /** 是否有物品可以拖动 */
  65. CanDrag(): boolean {
  66. return !this.IsEmpty() && this.cellData.ueCube.CanDrag() && !this.IsLock();
  67. }
  68. GetCube(): UECube {
  69. return this.cellData.ueCube;
  70. }
  71. /** 该棋格是否是空的 */
  72. IsEmpty(): boolean {
  73. return this.cellData.ueCube == null;
  74. }
  75. /** 清空棋格里的棋子 */
  76. ClearCube() {
  77. this.cellData.ueCube.unUse();
  78. this.cellData.ueCube = null;
  79. this.SetQuality();
  80. }
  81. MoveCubeToCell(toCell: UECell) {
  82. this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
  83. }
  84. }