| 
									
										
										
										
											2024-03-13 17:04:19 +08:00
										 |  |  | import { _decorator, BlockInputEvents, Button, Color, Director, director, EventMouse, Label, Node, sp, Sprite, UITransform, v2 } from 'cc'; | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  | import { BaseSprite } from '../GlobalScript/CommonComponent/BaseSprite'; | 
					
						
							|  |  |  | import { NpkImage } from '../Tool/NPKImage'; | 
					
						
							|  |  |  | import { BaseButton } from '../GlobalScript/CommonComponent/BaseButton'; | 
					
						
							|  |  |  | import { AnimationNode } from '../GlobalScript/Animation/AnimationNode'; | 
					
						
							| 
									
										
										
										
											2024-03-13 17:04:19 +08:00
										 |  |  | import { CharacterType, GamerNode } from './GamerNode'; | 
					
						
							|  |  |  | import { UIRoot } from './UIRoot'; | 
					
						
							| 
									
										
										
										
											2024-03-14 14:19:45 +08:00
										 |  |  | import {closeButtonNode } from './common/closeButtonNode'; | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  | const { ccclass } = _decorator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// 开始游戏按钮界面
 | 
					
						
							|  |  |  | @ccclass('StartGameUINode') | 
					
						
							|  |  |  | export class StartGameUINode extends Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 玩法介绍
 | 
					
						
							|  |  |  |     private _pressenNode: Node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     set pressenNode(node: Node){ | 
					
						
							|  |  |  |         if (this._pressenNode){ | 
					
						
							|  |  |  |             this._pressenNode.destroy(); | 
					
						
							|  |  |  |             this._pressenNode = null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this._pressenNode = node; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     get pressenNode(): Node{ | 
					
						
							|  |  |  |         return this._pressenNode; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |     constructor(){ | 
					
						
							|  |  |  |         super(); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         this.addComponent(UITransform).setContentSize(1067,600); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.init(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 初始化子节点
 | 
					
						
							|  |  |  |     init(){ | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         this.initBackground(); | 
					
						
							|  |  |  |         this.initTitle(); | 
					
						
							|  |  |  |         this.initStartButton(); | 
					
						
							|  |  |  |         this.initLabel(); | 
					
						
							|  |  |  |         this.initPressenButton(); | 
					
						
							| 
									
										
										
										
											2024-03-11 19:20:48 +08:00
										 |  |  |         this.initPressen(); | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 背景
 | 
					
						
							|  |  |  |     initBackground(){ | 
					
						
							|  |  |  |         /// 背景节点
 | 
					
						
							|  |  |  |         const backgroundNode = new Node('StartBackgroundNode'); | 
					
						
							|  |  |  |         this.addChild(backgroundNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// 给背景节点添加 baseSprite 组件
 | 
					
						
							|  |  |  |         const backgroundComponent = backgroundNode.addComponent( BaseSprite ); | 
					
						
							|  |  |  |         backgroundComponent.updateSpriteFrame(NpkImage.main,24); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 标题动画
 | 
					
						
							|  |  |  |     initTitle(){ | 
					
						
							|  |  |  |         let titleNode = new AnimationNode('ani/title_loop.ani'); | 
					
						
							|  |  |  |         titleNode.setPosition(544.5,-305); | 
					
						
							|  |  |  |         this.addChild(titleNode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 开始游戏
 | 
					
						
							|  |  |  |     initStartButton(){ | 
					
						
							|  |  |  |         /// 按钮节点
 | 
					
						
							|  |  |  |         const startButtonNode = new Node('StartButton'); | 
					
						
							|  |  |  |         startButtonNode.setPosition(441.5,-450); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         /// 给节点添加 button 组件
 | 
					
						
							|  |  |  |         const buttonComponent = startButtonNode.addComponent( BaseButton ); | 
					
						
							|  |  |  |         buttonComponent.ImgPath = NpkImage.main; | 
					
						
							|  |  |  |         buttonComponent.NormalImgIndex = 1; | 
					
						
							|  |  |  |         buttonComponent.HoverImgIndex = 2; | 
					
						
							|  |  |  |         buttonComponent.PressImgIndex = 3; | 
					
						
							|  |  |  |         buttonComponent.DisableImgIndex = 4; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  |         startButtonNode.addComponent( Button) | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         startButtonNode.on(Button.EventType.CLICK,this.startOnTouchEnd,this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.addChild(startButtonNode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 入场次数
 | 
					
						
							|  |  |  |     initLabel(){ | 
					
						
							|  |  |  |         const labelNode = new Node('Label'); | 
					
						
							|  |  |  |         labelNode.setPosition(550,-421); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         const labelComponent = labelNode.addComponent( Label ); | 
					
						
							|  |  |  |         labelComponent.string = '∞'; | 
					
						
							|  |  |  |         labelComponent.color = new Color('24a5cd'); | 
					
						
							|  |  |  |         labelComponent.fontSize = 18; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.addChild(labelNode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 玩法介绍按钮
 | 
					
						
							|  |  |  |     initPressenButton(){ | 
					
						
							|  |  |  |         /// 按钮节点
 | 
					
						
							|  |  |  |         const pressenButtonNode = new Node('PressenButton'); | 
					
						
							|  |  |  |         pressenButtonNode.setPosition(1020,-10); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         /// 给节点添加 button 组件
 | 
					
						
							|  |  |  |         const buttonComponent = pressenButtonNode.addComponent( BaseButton ); | 
					
						
							|  |  |  |         buttonComponent.ImgPath = NpkImage.main; | 
					
						
							|  |  |  |         buttonComponent.NormalImgIndex = 9; | 
					
						
							|  |  |  |         buttonComponent.HoverImgIndex = 10; | 
					
						
							|  |  |  |         buttonComponent.PressImgIndex = 11; | 
					
						
							|  |  |  |         buttonComponent.DisableImgIndex = 12; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pressenButtonNode.on(Node.EventType.MOUSE_UP,this.pressenOnTouchEnd,this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.addChild(pressenButtonNode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 玩法介绍
 | 
					
						
							|  |  |  |     initPressen(){ | 
					
						
							|  |  |  |         /// 节点
 | 
					
						
							|  |  |  |         this.pressenNode = new Node('Pressen'); | 
					
						
							| 
									
										
										
										
											2024-03-14 14:19:45 +08:00
										 |  |  |         this.pressenNode.active = false; | 
					
						
							|  |  |  |         this.addChild(this.pressenNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.pressenNode.setPosition(0,0); | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         this.pressenNode.addComponent( UITransform).setContentSize(1067,600); | 
					
						
							|  |  |  |         this.pressenNode.getComponent(UITransform).anchorPoint = v2(0, 1); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         /// 拦截下层的点击事件
 | 
					
						
							|  |  |  |         this.pressenNode.addComponent( BlockInputEvents ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  |         /// 给节点添加 img
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         const imgNode = new Node('PressenImage'); | 
					
						
							|  |  |  |         imgNode.setPosition(134,-21.5); | 
					
						
							|  |  |  |         const imgComponent = imgNode.addComponent( BaseSprite ); | 
					
						
							|  |  |  |         imgComponent.updateSpriteFrame(NpkImage.main,25); | 
					
						
							|  |  |  |         this.pressenNode.addChild(imgNode); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         /// 关闭按钮
 | 
					
						
							| 
									
										
										
										
											2024-03-14 14:19:45 +08:00
										 |  |  |         const closeNode = new closeButtonNode(this.closeOnTouchEnd.bind(this)); | 
					
						
							|  |  |  |         closeNode.setPosition(767,-10); | 
					
						
							|  |  |  |         imgNode.addChild(closeNode); | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 打开玩法介绍
 | 
					
						
							|  |  |  |     pressenOnTouchEnd(event:EventMouse){ | 
					
						
							|  |  |  |         if ( event.getButton() === EventMouse.BUTTON_LEFT ){ | 
					
						
							| 
									
										
										
										
											2024-03-14 14:19:45 +08:00
										 |  |  |             this.pressenNode.active = true; | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 10:55:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |     closeOnTouchEnd(event:EventMouse){ | 
					
						
							| 
									
										
										
										
											2024-03-14 14:19:45 +08:00
										 |  |  |         this.pressenNode.active = false; | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// 开始游戏
 | 
					
						
							|  |  |  |     startOnTouchEnd(event:Event){ | 
					
						
							| 
									
										
										
										
											2024-03-13 17:04:19 +08:00
										 |  |  |         const uiroot = this.parent.getComponent( UIRoot ); | 
					
						
							|  |  |  |         uiroot.initGameUI(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// 一帧结束之后销毁
 | 
					
						
							|  |  |  |         director.once(Director.EVENT_END_FRAME,()=>{ | 
					
						
							|  |  |  |             // 销毁
 | 
					
						
							|  |  |  |             this.destroy(); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2024-03-11 17:37:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         console.log('开始游戏'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |