140 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			140 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
| import { _decorator, Node } from "cc";
 | |
| import {
 | |
|   MapTileDirection,
 | |
|   MapTileType,
 | |
| } from "./MapTileData";
 | |
| import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite";
 | |
| import { MapTileButtonComponent } from "./MapTileButtonComponent";
 | |
| import { MapTileController } from "./MapTileController";
 | |
| 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();
 | |
|   }
 | |
| 
 | |
|   /// 测试使用按钮
 | |
|   initButtons(){
 | |
| 
 | |
|   }
 | |
| 
 | |
|   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;
 | |
|     }
 | |
| 
 | |
|     if (this.controller.tileData.trainsSelectLicense){
 | |
|       // 鼠标选择边框
 | |
|       const bordeNode = new Node();
 | |
|       this.addChild(bordeNode);
 | |
|       bordeNode.active = false;
 | |
|       const bordeBC = bordeNode.addComponent(MapTileButtonComponent);
 | |
|       bordeBC.direction = this.controller.tileData.direction;
 | |
|       this.borderNode = bordeNode;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /// 禁止选择
 | |
|     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;
 | |
|     }
 | |
|   }
 | |
| 
 | |
| }
 |