| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  | import type { DOStage } from "../models/DOStage" | 
					
						
							|  |  |  | import { config } from "../constants/config" | 
					
						
							|  |  |  | import { respath } from "../constants/respath" | 
					
						
							|  |  |  | import { EVENT_TYPES, EventManager } from "../models/EventManager" | 
					
						
							|  |  |  | import { StorageManager } from "../models/StorageManager" | 
					
						
							|  |  |  | import { UIManager } from "../models/UIManager" | 
					
						
							|  |  |  | import { Difficulty } from "./Difficulty" | 
					
						
							| 
									
										
										
										
											2025-06-05 17:00:48 +08:00
										 |  |  | import { ResourceManager } from "../models/ResourceManager" | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  | import { Utility_EaseOut, Utility_EaseOut_2 } from "../utils/utility" | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  | const { regClass, property } = Laya | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @regClass() | 
					
						
							|  |  |  | export class GameOver extends Laya.Script { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   declare owner: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-29 10:25:13 +08:00
										 |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public btn_second: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-29 10:25:13 +08:00
										 |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public btn_restart: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-29 10:25:13 +08:00
										 |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public btn_newOrClose: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-19 20:58:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Label) | 
					
						
							|  |  |  |   public label_newOrClose: Laya.Label | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |   private mask: Laya.Image | 
					
						
							|  |  |  |   private center: Laya.Box | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onAwake(): void { | 
					
						
							|  |  |  |     this.mask = this.owner.getChildByName("Image") as Laya.Image | 
					
						
							|  |  |  |     this.mask.alpha = 0 | 
					
						
							|  |  |  |     Laya.Tween.to(this.mask, {alpha: 0.6}, 400, Utility_EaseOut) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.center = this.owner.getChildByName("center") as Laya.Box | 
					
						
							|  |  |  |     this.center.scaleX = 0.8 | 
					
						
							|  |  |  |     this.center.scaleY = 0.8 | 
					
						
							|  |  |  |     Laya.Tween.to(this.center, {scaleX: 1, scaleY: 1}, 400, Utility_EaseOut) | 
					
						
							|  |  |  |     this.center.alpha = 0 | 
					
						
							|  |  |  |     Laya.Tween.to(this.center, {alpha: 1}, 400, Utility_EaseOut) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   destroyUI(): void { | 
					
						
							|  |  |  |     Laya.Tween.to(this.mask, {alpha: 0}, 400, Utility_EaseOut_2) | 
					
						
							|  |  |  |     Laya.Tween.to(this.center, {scaleX: 0.8, scaleY: 0.8}, 400, Utility_EaseOut_2) | 
					
						
							|  |  |  |     Laya.Tween.to(this.center, {alpha: 0}, 400, Utility_EaseOut_2, Laya.Handler.create(this, () => { | 
					
						
							|  |  |  |       this.owner.destroy() | 
					
						
							|  |  |  |     })) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   public onSetStageInfo(doStage: DOStage): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     this.btn_second.on(Laya.Event.CLICK, this, () => { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       doStage.set_mistake(doStage.get_mistake() - 1) | 
					
						
							|  |  |  |       EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE) | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |       this.destroyUI() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2025-05-19 20:58:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     this.btn_restart.on(Laya.Event.CLICK, this, () => { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       const stageID = doStage.get_stageID() | 
					
						
							|  |  |  |       const type = doStage.get_stageType() | 
					
						
							|  |  |  |       const difficulty = doStage.get_difficulty() | 
					
						
							|  |  |  |       StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty) | 
					
						
							|  |  |  |       UIManager.getInstance().loadStageUI(stageID) | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |       this.destroyUI() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2025-05-19 20:58:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     const type = doStage.get_stageType() | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |     if (type === config.STAGE_TYPE.MAIN) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       this.label_newOrClose.text = "New Game" | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |       this.btn_newOrClose.on(Laya.Event.CLICK, this, () => { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         if (config.H_SCREEN) { | 
					
						
							|  |  |  |           const user = StorageManager.getInstance().getUser() | 
					
						
							|  |  |  |           user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex() + 1)// 主线关卡更新难度进度
 | 
					
						
							|  |  |  |           const difficulty = doStage.get_difficulty() | 
					
						
							|  |  |  |           StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty) | 
					
						
							|  |  |  |           UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID) | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |           this.destroyUI() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2025-06-05 17:00:48 +08:00
										 |  |  |           ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any)=> { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             const prefab = go.create() | 
					
						
							|  |  |  |             const d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty) | 
					
						
							|  |  |  |             d.onInit((value: string) => { | 
					
						
							|  |  |  |               console.log("选择难度", value) | 
					
						
							|  |  |  |               StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value) | 
					
						
							|  |  |  |               UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID) | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |               this.destroyUI() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             }) | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       this.label_newOrClose.text = "Close" | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |       this.btn_newOrClose.on(Laya.Event.CLICK, this, () => { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         UIManager.getInstance().loadDCUI() | 
					
						
							|  |  |  |         UIManager.getInstance().closeStageUI() | 
					
						
							| 
									
										
										
										
											2025-06-06 16:05:54 +08:00
										 |  |  |         this.destroyUI() | 
					
						
							| 
									
										
										
										
											2025-05-14 12:17:47 +08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-05-26 19:57:17 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |