DaFuWeng/assets/Script/MapTile/MapTileNode.ts

146 lines
3.7 KiB
TypeScript

import { _decorator, Node } from "cc";
import { MapTileDirection, MapTileType } from "./MapTileType";
import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite";
import { MapTileButtonComponent } from "./MapTileButtonComponent";
import { MapTileController } from "./MapTileController";
import { CloseButtonNode } from "../Common/CloseButtonNode";
import { MapTitleAction } from "./MapTitleAction";
import { LuckyType } from "../DialogRoot/LuckyCoinsNode";
const { ccclass } = _decorator;
/// 地块
@ccclass("MapTileNode")
export class MapTileNode extends Node {
/// -- Node
/// 背景节点
private backgroundNode: Node;
/// 地块名称
private nameNode: Node;
/// 决斗场选中的战斗边框
private fightNode: Node;
/// 鼠标操作变化的边框
private borderNode: Node;
/// 禁止选择
private disableNode: Node;
/// 占领图标
private occupyIconNode: Node;
/// 决斗场选中的图标 和倍数icon
private fightIconNode: Node;
/// 控制器
private controller: MapTileController;
constructor(type) {
super();
this.controller = this.addComponent(MapTileController);
this.controller.tileType = type;
this.initNode();
// todo 测试用按钮
this.initButton();
}
/// 测试使用按钮
initButton() {
const node = new CloseButtonNode(()=>{
MapTitleAction.lucky( LuckyType.GoThree );
})
this.addChild(node);
}
initNode() {
//* 背景
if (this.controller.tileData.backgroundIndex) {
const node = new Node();
this.addChild(node);
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(
this.controller.tileData.npkPath,
this.controller.tileData.backgroundIndex
);
this.backgroundNode = node;
}
//* 名称
const node = new Node();
this.addChild(node);
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(
this.controller.tileData.npkPath,
this.controller.tileType
);
this.nameNode = node;
//* 红色边框
// 决斗场选择后的红色边框,四角和命运硬币 没有红框
if (
this.controller.tileData.direction != MapTileDirection.nook &&
this.controller.tileType !=
(MapTileType.XiaoZhenMingYunYinBi || MapTileType.HaLinMingYunYinBi)
) {
const node = new Node();
node.active = false;
this.addChild(node);
// 横向地块27 竖向28
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(
this.controller.tileData.npkPath,
this.controller.tileData.direction == MapTileDirection.horizontal
? 27
: 28
);
this.fightNode = node;
}
//* 鼠标选择边框
const bordeNode = new Node();
this.addChild(bordeNode);
bordeNode.active = false;
const bordeBC = bordeNode.addComponent(MapTileButtonComponent);
bordeBC.direction = this.controller.tileData.direction;
this.borderNode = bordeNode;
//* 禁止选择node
const disableNode = new Node();
this.addChild(disableNode);
disableNode.active = false;
const disableBS = disableNode.addComponent(BaseSprite);
disableBS.updateSpriteFrame(
this.controller.tileData.npkPath,
this.controller.tileData.direction + 5
);
this.disableNode = disableNode;
}
//* 显示海上列车选择
shwTrainsSelect(show: boolean) {
if (this.borderNode) {
//* 许可选择
if (this.controller.tileData.trainsSelectLicense) {
this.borderNode.active = show;
} else {
this.disableNode.active = true;
}
} else {
this.disableNode.active = false;
this.borderNode.active = false;
}
}
}