UECell.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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) {
  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. SetLock() {
  43. this.node_lock.active = this.cellData.unlock == HcUnlock.off;
  44. }
  45. GetZIndex() {
  46. return this.cellData.zIndex;
  47. }
  48. SetSelect(isSelect: boolean) {
  49. this.node_select.active = isSelect;
  50. }
  51. /** 是否有物品可以拖动 */
  52. CanDrag(): boolean {
  53. return !this.IsEmpty();
  54. }
  55. GetCube(): UECube {
  56. return this.cellData.ueCube;
  57. }
  58. /** 该棋格是否是空的 */
  59. IsEmpty(): boolean {
  60. return this.cellData.ueCube == null;
  61. }
  62. /** 清空棋格里的棋子 */
  63. ClearCube() {
  64. this.cellData.ueCube.unUse();
  65. this.cellData.ueCube = null;
  66. this.SetQuality();
  67. }
  68. MoveCubeToCell(toCell: UECell) {
  69. this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
  70. }
  71. }