From 1ec2f0afc09255b9addc28acf5ce229f9c901f09 Mon Sep 17 00:00:00 2001 From: "DESKTOP-J7I1C4E\\a9350" Date: Mon, 18 Mar 2024 20:10:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E4=B8=8A=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E5=9D=97=E9=85=8D=E7=BD=AE=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/BoardRoot.ts | 20 +- assets/Script/MapTileController.ts | 3 +- assets/Script/MapTileData.ts | 362 ++++++++++++++++++++++++----- assets/Script/MapTileNode.ts | 73 ++++-- 4 files changed, 361 insertions(+), 97 deletions(-) diff --git a/assets/Script/BoardRoot.ts b/assets/Script/BoardRoot.ts index f5086d6..e4064b3 100644 --- a/assets/Script/BoardRoot.ts +++ b/assets/Script/BoardRoot.ts @@ -1,5 +1,5 @@ import { _decorator, Component, Node } from 'cc'; -import { MapTileType } from './MapTileData'; +import { MapTileType, MapTileTypes } from './MapTileData'; import { MapTileNode } from './MapTileNode'; const { ccclass, property } = _decorator; @@ -15,25 +15,13 @@ export class BoardRoot extends Component { /// 初始化 地图快 initMapTile(){ - // 从枚举类型 添加所有地块 - const types = Object.values(MapTileType); - console.log(types); - types.forEach((a,b) => { - const node = new MapTileNode(b); + // 从枚举类型 添加所有地块 + MapTileTypes.forEach((type) => { + const node = new MapTileNode(type); this.node.addChild(node); }); - - - // for( let i = 0; i < types.length ; i++){ - // const type = types[i]; - // const node = new MapTileNode(type); - // this.node.addChild(node); - // } - - // console.log('地图块初始化完成'); - // console.log(this.node); } update(deltaTime: number) { diff --git a/assets/Script/MapTileController.ts b/assets/Script/MapTileController.ts index 8b3547c..3a44971 100644 --- a/assets/Script/MapTileController.ts +++ b/assets/Script/MapTileController.ts @@ -30,7 +30,8 @@ export class MapTileController extends Component { /// 进入选择地下城状态,海上列车选择,决斗场选择 start() { - this.node.setPosition(0,0); + const location = this._tileData.location; + this.node.setPosition(location.x,location.y); } update(deltaTime: number) {} diff --git a/assets/Script/MapTileData.ts b/assets/Script/MapTileData.ts index 294fa62..1677f4d 100644 --- a/assets/Script/MapTileData.ts +++ b/assets/Script/MapTileData.ts @@ -1,10 +1,9 @@ import { Vec2, v2 } from "cc"; import { NpkImage } from "../Tool/NPKImage"; - /// 地块类型 export enum MapTileType { /// 赫顿玛尔 - HeDunMaEr, + HeDunMaEr = 0, /// 时间广场 ShiJianGuangChang, /// 兽人峡谷 @@ -18,14 +17,14 @@ export enum MapTileType { /// 月光酒馆 YueGuangJiuGuan, - /// 哈林的命运硬币(左边) - HaLinMingYunYinBi, /// 亡命杀阵 WangMingShaZhen, /// 皇家娱乐 HuangJaiYuLe, /// 黑暗都市 - AnHeiDuShi, + HeiAnDuShi, + /// 哈林的命运硬币(左边) + HaLinMingYunYinBi, /// 第九隔离区 DiJiuGeLiQu, @@ -44,18 +43,72 @@ export enum MapTileType { /// 海上列车 HaiShangLieChe, - /// 切斯特小镇的命运硬币(右边) - XiaoZhenMingYunYinBi, /// 暗黑神殿 AnHeiShenDian, /// 痛苦地下城 TongKuDiXiaChen, /// 无底坑道 WuDiKenDao, + /// 切斯特小镇的命运硬币(右边) + XiaoZhenMingYunYinBi, /// 记忆之地 JiYiZhiDi, } +export const MapTileTypes = [ + /// 赫顿玛尔 + MapTileType.HeDunMaEr, +/// 时间广场 +MapTileType.ShiJianGuangChang, +/// 兽人峡谷 +MapTileType.ShouRenXiaGu, +/// 超时空漩涡 +MapTileType.ChaoShiKongXuanWo, +/// 恐怖的栖息地 +MapTileType.KongBuDeQiXiDi, +/// 红色魔女之森 +MapTileType.HongSeMoNvZhiSen, + +/// 月光酒馆 +MapTileType.YueGuangJiuGuan, +/// 亡命杀阵 +MapTileType.WangMingShaZhen, +/// 皇家娱乐 +MapTileType.HuangJaiYuLe, +/// 黑暗都市 +MapTileType.HeiAnDuShi, +/// 哈林的命运硬币(左边) +MapTileType.HaLinMingYunYinBi, +/// 第九隔离区 +MapTileType.DiJiuGeLiQu, + +/// 决斗场 +MapTileType.JueDouChang, +/// 腐坏街道 +MapTileType.FuHuaiJieDao, +/// 溢血的地下城 +MapTileType.YiXueDeDiXiaChen, +/// 普雷·伊西斯 +MapTileType.PuLeiYiXiSi, +/// 沉重的礼拜堂 +MapTileType.ChenZhongDeLiBaiTang, +/// 螺旋王国 +MapTileType.LuoXuanWangGuo, + +/// 海上列车 +MapTileType.HaiShangLieChe, +/// 暗黑神殿 +MapTileType.AnHeiShenDian, +/// 痛苦地下城 +MapTileType.TongKuDiXiaChen, +/// 无底坑道 +MapTileType.WuDiKenDao, +/// 切斯特小镇的命运硬币(右边) +MapTileType.XiaoZhenMingYunYinBi, +/// 记忆之地 +MapTileType.JiYiZhiDi, +]; + /// 地块方向 export enum MapTileDirection { /// 横 @@ -74,8 +127,6 @@ export class MapTileData { npkPath: NpkImage; /// 地块背景index backgroundIndex: number; - /// 地块名称图片index - nameIndex: number; /// 地块方向 direction: MapTileDirection; /// 怪物相关数据 @@ -87,87 +138,272 @@ export class MapTileData { /// 占领许可 occupyLicense: boolean; - constructor({ - /// 坐标 - location, - /// 背景index - backgroundIndex, - /// 名称index - nameIndex, - /// 地块方向 - direction, - /// 占领许可 - occupyLicense = true, - /// 列车选择许可 - trainsSelectLicense, - /// 决斗场选择许可 - duelSelectLicense, - }: { - location: Vec2; - backgroundIndex?: number; - nameIndex?: number; - direction: MapTileDirection; - occupyLicense?: boolean; - trainsSelectLicense: boolean; - duelSelectLicense: boolean; - }) { - this.location = location; - this.npkPath = NpkImage.board; - this.backgroundIndex = backgroundIndex; - this.nameIndex = nameIndex; - this.direction = direction; + constructor({ + /// 坐标 + location, + /// 背景index + backgroundIndex, + /// 地块方向 + direction, + /// 占领许可 + occupyLicense, + /// 列车选择许可 + trainsSelectLicense, + /// 决斗场选择许可 + duelSelectLicense, + }: { + location: Vec2; + backgroundIndex?: number; + direction: MapTileDirection; + occupyLicense?: boolean; + trainsSelectLicense?: boolean; + duelSelectLicense?: boolean; + }) { + this.location = location; + this.npkPath = NpkImage.board; + this.backgroundIndex = backgroundIndex; + this.direction = direction; - this.trainsSelectLicense = trainsSelectLicense; - this.duelSelectLicense = duelSelectLicense; - this.occupyLicense = occupyLicense; - } + this.trainsSelectLicense = trainsSelectLicense ?? true; + this.duelSelectLicense = duelSelectLicense ?? true; + this.occupyLicense = occupyLicense ?? true; + } } export class MapTileFactory { - static getData(type: MapTileType): MapTileData{ - - // const tts = type as MapTileType; - // const ss = tts == MapTileType.HeDunMaEr; - // const nn = Number(type); - // const aa = +type; - // const tttt: MapTileType = MapTileType.HeDunMaEr; - + static getData(type: MapTileType): MapTileData { switch (type) { /// 赫顿玛尔 case MapTileType.HeDunMaEr: - console.log(type); return MapTileFactory.HeDunMaErData; /// 时间广场 case MapTileType.ShiJianGuangChang: - console.log(type); - return MapTileFactory.ShiJianGuangChangData; + return MapTileFactory.ShiJianGuangChangData; + /// 兽人峡谷 + case MapTileType.ShouRenXiaGu: + return MapTileFactory.ShouRenXiaGuData; + /// 超时空漩涡 + case MapTileType.ChaoShiKongXuanWo: + return MapTileFactory.ChaoShiKongXuanWoData; + /// 恐怖的栖息地 + case MapTileType.KongBuDeQiXiDi: + return MapTileFactory.KongBuDeQiXiDiData; + /// 红色魔女之森 + case MapTileType.HongSeMoNvZhiSen: + return MapTileFactory.HongSeMoNvZhiSenData; + /// 月光酒馆 + case MapTileType.YueGuangJiuGuan: + return MapTileFactory.YueGuangJiuGuanData; + /// 亡命杀镇子 + case MapTileType.WangMingShaZhen: + return MapTileFactory.WangMingShaZhenData; + /// 皇家娱乐 + case MapTileType.HuangJaiYuLe: + return MapTileFactory.HuangJaiYuLeData; + /// 黑暗都市 + case MapTileType.HeiAnDuShi: + return MapTileFactory.HeiAnDuShiData; + /// 哈林的命运硬币(左边) + case MapTileType.HaLinMingYunYinBi: + return MapTileFactory.HaLinMingYunYinBiData; + /// 第九隔离区 + case MapTileType.DiJiuGeLiQu: + return MapTileFactory.DiJiuGeLiQuData; + /// 决斗场 + case MapTileType.JueDouChang: + return MapTileFactory.JueDouChangData; + /// 腐坏街道 + case MapTileType.FuHuaiJieDao: + return MapTileFactory.FuHuaiJieDaoData; + /// 溢血的地下城 + case MapTileType.YiXueDeDiXiaChen: + return MapTileFactory.YiXueDeDiXiaChenData; + /// 普雷·伊西斯 + case MapTileType.PuLeiYiXiSi: + return MapTileFactory.PuLeiYiXiSiData; + /// 沉重的礼拜堂 + case MapTileType.ChenZhongDeLiBaiTang: + return MapTileFactory.ChenZhongDeLiBaiTangData; + /// 螺旋王国 + case MapTileType.LuoXuanWangGuo: + return MapTileFactory.LuoXuanWangGuoData; + /// 海上列车 + case MapTileType.HaiShangLieChe: + return MapTileFactory.HaiShangLieCheData; + /// 暗黑神殿 + case MapTileType.AnHeiShenDian: + return MapTileFactory.AnHeiShenDianData; + /// 痛苦地下城 + case MapTileType.TongKuDiXiaChen: + return MapTileFactory.TongKuDiXiaChenData; + /// 无底坑道 + case MapTileType.WuDiKenDao: + return MapTileFactory.WuDiKenDaoData; + /// 切斯特小镇的命运硬币(右边) + case MapTileType.XiaoZhenMingYunYinBi: + return MapTileFactory.XiaoZhenMingYunYinBiData; + /// 记忆之地 + case MapTileType.JiYiZhiDi: + return MapTileFactory.JiYiZhiDiData; } - - console.log(type); } // 赫顿玛尔 private static HeDunMaErData = new MapTileData({ - location: v2(507, -500), + location: v2(475, -448), direction: MapTileDirection.nook, - trainsSelectLicense: true, duelSelectLicense: false, occupyLicense: false, }); - /// 时间广场 + /// 时间广场 (55,34) private static ShiJianGuangChangData = new MapTileData({ - location: v2(507, -500), - backgroundIndex: 1, + location: v2(420, -414), direction: MapTileDirection.horizontal, - trainsSelectLicense: true, - duelSelectLicense: true, - occupyLicense: true, }); + /// 兽人峡谷 (52,34) + private static ShouRenXiaGuData = new MapTileData({ + location: v2(368, -380), + direction: MapTileDirection.horizontal, + }); + /// 超时空漩涡 (53,34) + private static ChaoShiKongXuanWoData = new MapTileData({ + location: v2(315, -346), + backgroundIndex: 32, + direction: MapTileDirection.horizontal, + }); + /// 恐怖的栖息地 (52,34) + private static KongBuDeQiXiDiData = new MapTileData({ + location: v2(262, -312), + direction: MapTileDirection.horizontal, + }); + /// 红色魔女之森 (52,34) + private static HongSeMoNvZhiSenData = new MapTileData({ + location: v2(209, -278), + direction: MapTileDirection.horizontal, + }); + // 月光酒馆(69,44) + private static YueGuangJiuGuanData = new MapTileData({ + location: v2(140, -234), + direction: MapTileDirection.nook, + duelSelectLicense: false, + occupyLicense: false, + }); + /// 亡命杀镇 (53,34) + private static WangMingShaZhenData = new MapTileData({ + location: v2(209, -198), + direction: MapTileDirection.vertical, + }); + + /// 皇家娱乐(53,34) + private static HuangJaiYuLeData = new MapTileData({ + location: v2(262, -164), + direction: MapTileDirection.vertical, + }); + + /// 黑暗都市 + private static HeiAnDuShiData = new MapTileData({ + location: v2(315, -130), + direction: MapTileDirection.vertical, + }); + /// 哈林的命运硬币(左边) + private static HaLinMingYunYinBiData = new MapTileData({ + location: v2(368, -96), + backgroundIndex: 34, + direction: MapTileDirection.vertical, + duelSelectLicense: false, + occupyLicense: false, + }); + /// 第九隔离区 + private static DiJiuGeLiQuData = new MapTileData({ + location: v2(421, -62), + direction: MapTileDirection.vertical, + }); + + // 决斗场(54,44) + private static JueDouChangData = new MapTileData({ + location: v2(475, -18), + direction: MapTileDirection.nook, + duelSelectLicense: false, + occupyLicense: false, + }); + + /// 腐坏街道(53,34) + private static FuHuaiJieDaoData = new MapTileData({ + location: v2(544, -62), + direction: MapTileDirection.horizontal, + }); + + /// 溢血的地下城(53,34) + private static YiXueDeDiXiaChenData = new MapTileData({ + location: v2(597, -96), + direction: MapTileDirection.horizontal, + }); + + /// 普雷·伊西斯 + private static PuLeiYiXiSiData = new MapTileData({ + location: v2(650, -130), + backgroundIndex: 33, + direction: MapTileDirection.horizontal, + }); + + /// 沉重的礼拜堂 + private static ChenZhongDeLiBaiTangData = new MapTileData({ + location: v2(703, -164), + direction: MapTileDirection.horizontal, + }); + + /// 螺旋王国 + private static LuoXuanWangGuoData = new MapTileData({ + location: v2(756, -198), + direction: MapTileDirection.horizontal, + }); + + // 海上列车(69,44) + private static HaiShangLieCheData = new MapTileData({ + location: v2(808, -234), + direction: MapTileDirection.nook, + trainsSelectLicense: false, + duelSelectLicense: false, + occupyLicense: false, + }); + + /// 暗黑神殿 + private static AnHeiShenDianData = new MapTileData({ + location: v2(756, -278), + direction: MapTileDirection.vertical, + }); + + /// 痛苦地下城 + private static TongKuDiXiaChenData = new MapTileData({ + location: v2(703, -312), + direction: MapTileDirection.vertical, + }); + + /// 无底坑道 + private static WuDiKenDaoData = new MapTileData({ + location: v2(650, -346), + direction: MapTileDirection.vertical, + }); + + /// 切斯特小镇的命运硬币(右边) + private static XiaoZhenMingYunYinBiData = new MapTileData({ + location: v2(597, -380), + backgroundIndex: 34, + direction: MapTileDirection.vertical, + duelSelectLicense: false, + occupyLicense: false, + }); + + /// 记忆之地 + private static JiYiZhiDiData = new MapTileData({ + location: v2(544, -414), + direction: MapTileDirection.vertical, + }); } diff --git a/assets/Script/MapTileNode.ts b/assets/Script/MapTileNode.ts index ae176ff..04917d7 100644 --- a/assets/Script/MapTileNode.ts +++ b/assets/Script/MapTileNode.ts @@ -27,6 +27,9 @@ export class MapTileNode extends Node { /// 鼠标操作变化的边框 private borderNode: Node; + /// 禁止选择 + private disableNode: Node; + /// 占领图标 private occupyIconNode: Node; @@ -45,7 +48,13 @@ export class MapTileNode extends Node { this.initNode(); } + /// 测试使用按钮 + initButtons(){ + + } + initNode() { + /// 背景 if (this.controller.tileData.backgroundIndex) { const node = new Node(); @@ -61,42 +70,72 @@ export class MapTileNode extends Node { } /// 名称 - if (this.controller.tileData.nameIndex) { - const node = new Node(); - this.addChild(node); + const node = new Node(); + this.addChild(node); - const bs = node.addComponent(BaseSprite); - bs.updateSpriteFrame(this.controller.tileData.npkPath, this.controller.tileData.nameIndex); + const bs = node.addComponent(BaseSprite); + bs.updateSpriteFrame( + this.controller.tileData.npkPath, + this.controller.tileType + ); - this.nameNode = node; - } + this.nameNode = node; /// 决斗场选择后的红色边框 // 四角和命运硬币 没有红框 if ( - this.controller.tileData.direction != MapTileDirection.nook || + this.controller.tileData.direction != MapTileDirection.nook && this.controller.tileType != (MapTileType.XiaoZhenMingYunYinBi || MapTileType.HaLinMingYunYinBi) ) { const node = new Node(); - // node.active = false; + node.active = false; this.addChild(node); - const bs = node.addComponent(BaseSprite); // 横向地块27 竖向28 + const bs = node.addComponent(BaseSprite); bs.updateSpriteFrame( this.controller.tileData.npkPath, this.controller.tileData.direction == MapTileDirection.horizontal ? 27 : 28 ); - this.nameNode = node; + this.fightNode = node; } - /// 鼠标选择边框 - const bordeNode = new Node(); - // bordeNode.active = false; - const bordeBS = bordeNode.addComponent(MapTileButtonComponent); - bordeBS.direction = this.controller.tileData.direction; - this.borderNode = bordeNode; + 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; + } + } + }