12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import UEBase from "../../frameWork/compment/UEBase";
- const { ccclass, property } = cc._decorator;
- export interface I_CellData {
- }
- @ccclass
- export default class UECell extends UEBase {
- static readonly BundleKey: string = "gridMap";
- static readonly PrefabUrl: string = "UECell";
- static readonly CLS: string = "UECell";
- @property(cc.Node)
- private itemNode: cc.Node = null!;
- @property(cc.Label)
- private lbt_num: cc.Label = null!;
- private itemType: number = 0; // 物品类型
- private itemLevel: number = 0; // 物品等级
- private originalPos: cc.Vec3 = cc.v3(0, 0);
- Init(idx: number) {
- this.lbt_num.string = idx.toString();
- this.originalPos = this.node.position;
- }
- hasItem(): boolean {
- return this.itemType !== 0;
- }
- startDrag(): void {
- if (this.itemNode) {
- this.itemNode.zIndex = 100;
- this.itemNode.opacity = 180;
- }
- }
- updateDragPosition(pos: cc.Vec3): void {
- if (this.itemNode) {
- this.itemNode.position = pos.sub(this.node.position);
- }
- }
- endDrag(): void {
- if (this.itemNode) {
- this.itemNode.zIndex = 1;
- this.itemNode.opacity = 255;
- this.itemNode.position = cc.Vec3.ZERO;
- }
- }
- canMergeWith(other: UECell): boolean {
- return this.itemType === other.itemType && this.itemLevel === other.itemLevel;
- }
- mergeFrom(other: UECell): void {
- if (this.canMergeWith(other)) {
- this.itemLevel++;
- // 更新显示
- this.updateItemDisplay();
- // 清空原来的格子
- other.clearItem();
- }
- }
- clearItem(): void {
- this.itemType = 0;
- this.itemLevel = 0;
- if (this.itemNode) {
- this.itemNode.active = false;
- }
- }
- private updateItemDisplay(): void {
- // 根据 itemType 和 itemLevel 更新物品显示
- if (this.itemNode) {
- this.itemNode.active = true;
- // TODO: 更新物品的具体显示效果
- }
- }
- }
|