75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
|
|
/*
|
||
|
|
* @Author: WoNiu
|
||
|
|
* @Date: 2024-03-22 19:50:30
|
||
|
|
* @LastEditTime: 2024-03-23 00:39:47
|
||
|
|
* @LastEditors: WoNiu
|
||
|
|
* @Description: 选择卡片节点
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { _decorator, EventMouse, Node, Sprite, SpriteFrame, UITransform, v2 } from "cc";
|
||
|
|
import { NpkImage } from "../../Tool/NPKImage";
|
||
|
|
import { BaseSpriteFrame } from "../../GlobalScript/CommonComponent/BaseSpriteFrame";
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
@ccclass("CardNode")
|
||
|
|
export class CardNode extends Node {
|
||
|
|
//普通精灵帧
|
||
|
|
NormalSpriteFrame: SpriteFrame;
|
||
|
|
|
||
|
|
// 高亮精灵帧1
|
||
|
|
oneSpriteFrame: SpriteFrame;
|
||
|
|
|
||
|
|
//高亮精灵帧2
|
||
|
|
twoSpriteFrame: SpriteFrame;
|
||
|
|
|
||
|
|
//精灵对象
|
||
|
|
SpriteObj: Sprite;
|
||
|
|
|
||
|
|
// 是否按钮失效
|
||
|
|
Disable = false;
|
||
|
|
|
||
|
|
constructor() {
|
||
|
|
super();
|
||
|
|
|
||
|
|
if (!this.getComponent(Sprite)) {
|
||
|
|
this.addComponent(Sprite);
|
||
|
|
}
|
||
|
|
|
||
|
|
this.getComponent(UITransform).anchorPoint = v2(0, 1);
|
||
|
|
|
||
|
|
this.SpriteObj = this.getComponent(Sprite);
|
||
|
|
|
||
|
|
new BaseSpriteFrame(NpkImage.ingame, 47, (SpriteFrame: SpriteFrame) => {
|
||
|
|
this.NormalSpriteFrame = SpriteFrame;
|
||
|
|
this.SpriteObj.spriteFrame = SpriteFrame;
|
||
|
|
});
|
||
|
|
new BaseSpriteFrame(NpkImage.ingame, 48, (SpriteFrame: SpriteFrame) => {
|
||
|
|
this.oneSpriteFrame = SpriteFrame;
|
||
|
|
});
|
||
|
|
new BaseSpriteFrame(NpkImage.ingame, 49, (SpriteFrame: SpriteFrame) => {
|
||
|
|
this.twoSpriteFrame = SpriteFrame;
|
||
|
|
});
|
||
|
|
|
||
|
|
this.on(Node.EventType.MOUSE_ENTER, this.OnHever, this);
|
||
|
|
this.on(Node.EventType.MOUSE_LEAVE, this.OffHever, this);
|
||
|
|
this.on(Node.EventType.MOUSE_DOWN, this.OnDown, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
OffHever() {
|
||
|
|
if (this.Disable) return;
|
||
|
|
this.SpriteObj.spriteFrame = this.NormalSpriteFrame;
|
||
|
|
}
|
||
|
|
OnHever() {
|
||
|
|
if (this.Disable) return;
|
||
|
|
this.SpriteObj.spriteFrame = this.oneSpriteFrame;
|
||
|
|
}
|
||
|
|
|
||
|
|
OnDown(event: EventMouse) {
|
||
|
|
|
||
|
|
//必须是鼠标左键
|
||
|
|
if (event.getButton() != EventMouse.BUTTON_LEFT || this.Disable ) return;
|
||
|
|
this.SpriteObj.spriteFrame = this.twoSpriteFrame;
|
||
|
|
this.Disable = true;
|
||
|
|
}
|
||
|
|
}
|