整理代码格式

This commit is contained in:
2025-06-10 18:24:50 +08:00
parent 285a1f9efe
commit 17c25ca099
18 changed files with 108 additions and 116 deletions

View File

@@ -70,10 +70,9 @@ export class ResourceManager {
console.log("预加载资源进度>>>>", resProg)
}))
Laya.timer.frameLoop(1, this, ()=>{
let removes: Array<any> = []
this.prefabReqs.forEach((list: Array<any>, path: string)=>{
Laya.timer.frameLoop(1, this, () => {
const removes: Array<any> = []
this.prefabReqs.forEach((list: Array<any>, path: string) => {
const obj = Laya.loader.getRes(path)
if (obj) {
removes.push(path)
@@ -157,5 +156,4 @@ export class ResourceManager {
}
}
}
}

View File

@@ -11,9 +11,8 @@ import { GameOver } from "../views/GameOver"
import { GamePause } from "../views/GamePause"
import { Stage } from "../views/Stage"
import { TopBar } from "../views/TopBar"
import { StorageManager } from "./StorageManager"
import { ResourceManager } from "./ResourceManager"
import Lottie from "lottie-web"
import { StorageManager } from "./StorageManager"
const { regClass, property } = Laya
@@ -82,14 +81,14 @@ export class UIManager extends Laya.Script {
}
public loadHomeUI(): void {
ResourceManager.getInstance().loadPrefab(respath.home_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.home_ui_res, (go: any) => {
const prefab = go.create()
this.getUIRoot().addChild(prefab)
})
}
public loadTopBarUI(): void {
ResourceManager.getInstance().loadPrefab(respath.topbar_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.topbar_ui_res, (go: any) => {
const prefab = go.create()
this.topbar = this.getUIRoot().addChild(prefab).getComponent(TopBar)
})
@@ -109,7 +108,7 @@ export class UIManager extends Laya.Script {
public loadDCUI(): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.dc_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.dc_ui_res(), (go: any) => {
const prefab = go.create()
this.dc_ui = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge)
if (this.dc_year <= 0 || this.dc_month <= 0) {
@@ -137,7 +136,7 @@ export class UIManager extends Laya.Script {
}
public loadTrophyClaimUI(record: TrophyRecord): void {
ResourceManager.getInstance().loadPrefab(respath.trophy_claim_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.trophy_claim_ui_res(), (go: any) => {
const prefab = go.create()
const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim)
obj.onSetShow(record)
@@ -146,7 +145,7 @@ export class UIManager extends Laya.Script {
public loadTrophyUI(): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.trophy_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.trophy_ui_res(), (go: any) => {
const prefab = go.create()
this.trophyRoom = this.getUIRoot().addChild(prefab).getComponent(TrophyRoom)
this.mask.visible = false
@@ -162,7 +161,7 @@ export class UIManager extends Laya.Script {
public loadTrophyShowUI(record: TrophyRecord): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.trophy_show_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.trophy_show_ui_res(), (go: any) => {
const prefab = go.create()
const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow)
obj.onSetShow(record)
@@ -174,7 +173,7 @@ export class UIManager extends Laya.Script {
if (this.stage) {
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
} else {
ResourceManager.getInstance().loadPrefab(respath.stage_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.stage_ui_res(), (go: any) => {
const prefab = go.create()
this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage)
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
@@ -191,7 +190,7 @@ export class UIManager extends Laya.Script {
public loadGamePauseUI(doStage: DOStage): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.gamepause_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.gamepause_ui_res(), (go: any) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GamePause)
ui.onSetStageInfo(doStage)
@@ -201,7 +200,7 @@ export class UIManager extends Laya.Script {
public loadGameOverUI(doStage: DOStage): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.gameover_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.gameover_ui_res(), (go: any) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GameOver)
ui.onSetStageInfo(doStage)
@@ -211,7 +210,7 @@ export class UIManager extends Laya.Script {
public loadGameDoneUI(isClassic: boolean, doStage: DOStage): void {
this.mask.visible = true
ResourceManager.getInstance().loadPrefab(respath.gamedone_ui_res(isClassic), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.gamedone_ui_res(isClassic), (go: any) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GameDone)
ui.onSetStageInfo(doStage)

View File

@@ -43,4 +43,4 @@ const bezier_ease_out_2 = BezierEasing(0.25, 0.1, 0.3, 1)
export function Utility_EaseOut_2(t: number, b: number, c: number, d: number) {
const p = bezier_ease_out_2(t / d)
return c * p + b
}
}

View File

@@ -3,11 +3,10 @@ import { ResourceManager } from "../models/ResourceManager"
import { UIManager } from "../models/UIManager"
import { Utility_EaseOut, Utility_EaseOut_2 } from "../utils/utility"
const { regClass, property } = Laya
export function G_ShowCommonTips(title: string, content: string, showToggle: boolean, func: any): void {
ResourceManager.getInstance().loadPrefab(respath.common_tips_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.common_tips_ui_res, (go: any) => {
const prefab = go.create()
const obj = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(CommonTips)
obj.showCommonTips(title, content, showToggle, func)
@@ -44,20 +43,20 @@ export class CommonTips extends Laya.Script {
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)
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)
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)
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, () => {
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()
}))
}

View File

@@ -1,11 +1,11 @@
import type { DOStage } from "../models/DOStage"
import { config } from "../constants/config"
import { respath } from "../constants/respath"
import { ResourceManager } from "../models/ResourceManager"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Utility_ConvertSecondToString } from "../utils/utility"
import { Difficulty } from "./Difficulty"
import { ResourceManager } from "../models/ResourceManager"
const { regClass, property } = Laya
@@ -53,9 +53,8 @@ export class GameDone extends Laya.Script {
public btn_continue: Laya.Box
onAwake(): void {
ResourceManager.getInstance().loadTexture(respath.bg_done, this.bg)
this.owner.x = 0
this.owner.y = 0
@@ -122,7 +121,7 @@ export class GameDone extends Laya.Script {
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.owner.destroy()
} else {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any) => {
const prefab = go.create()
const d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string) => {

View File

@@ -2,11 +2,11 @@ import type { DOStage } from "../models/DOStage"
import { config } from "../constants/config"
import { respath } from "../constants/respath"
import { EVENT_TYPES, EventManager } from "../models/EventManager"
import { ResourceManager } from "../models/ResourceManager"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Difficulty } from "./Difficulty"
import { ResourceManager } from "../models/ResourceManager"
import { Utility_EaseOut, Utility_EaseOut_2 } from "../utils/utility"
import { Difficulty } from "./Difficulty"
const { regClass, property } = Laya
@@ -32,25 +32,24 @@ export class GameOver extends Laya.Script {
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)
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)
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)
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, () => {
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()
}))
}
public onSetStageInfo(doStage: DOStage): void {
this.btn_second.on(Laya.Event.CLICK, this, () => {
doStage.set_mistake(doStage.get_mistake() - 1)
@@ -79,7 +78,7 @@ export class GameOver extends Laya.Script {
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.destroyUI()
} else {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any) => {
const prefab = go.create()
const d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string) => {

View File

@@ -30,14 +30,14 @@ export class GamePause extends Laya.Script {
this.mask = this.owner.getChildByName("Image") as Laya.Image
this.mask.alpha = 0
Laya.Tween.to(this.mask, {alpha: 0.6}, 400, Utility_EaseOut)
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)
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)
Laya.Tween.to(this.center, { alpha: 1 }, 400, Utility_EaseOut)
}
onDestroy(): void {
@@ -45,9 +45,9 @@ export class GamePause extends Laya.Script {
}
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, () => {
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()
}))
}
@@ -55,7 +55,7 @@ export class GamePause extends Laya.Script {
public onSetStageInfo(doStage: DOStage): void {
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_diffucuty.text = doStage.get_difficulty()
this.mask.on(Laya.Event.CLICK, this, () => {
this.destroyUI()
})

View File

@@ -139,7 +139,7 @@ export class Home extends Laya.Script {
}
public onClickNew(_evt: Laya.Event): void {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.difficulty_ui_res, (go: any) => {
const prefab = go.create()
const d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string) => {

View File

@@ -1,6 +1,6 @@
import { Utility_EaseOut } from "../utils/utility";
import BezierEasing from "bezier-easing"
import { Utility_EaseOut } from "../utils/utility"
import { AutoDestroy } from "./common/AutoDestroy"
import BezierEasing from 'bezier-easing';
const { regClass, property } = Laya
@@ -25,10 +25,9 @@ export class ScoreAdd extends Laya.Script {
}
onStart(): void {
// const filter: Laya.GlowFilter = new Laya.GlowFilter("#000000", 5, 0, 0);
// this.label.filters = [filter];
function bezierEaseLaya1(t: number, b: number, c: number, d: number) {
const bezier = BezierEasing(0.55, 1.8, 0.8, 0.95)
const p = bezier(t / d)

View File

@@ -182,6 +182,7 @@ export class Stage extends Laya.Script {
Stage._instance.onUpdatePaused(arg)
}
}
public onUpdatePaused(paused: boolean): void {
this.paused = paused
Stage._instance.obj_mask.visible = paused

View File

@@ -3,7 +3,7 @@ import { ResourceManager } from "../../models/ResourceManager"
import { ScoreAdd } from "../ScoreAdd"
export function G_ShowScoreTips(text: string, parent: any): void {
ResourceManager.getInstance().loadPrefab(respath.score_add_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.score_add_ui_res(), (go: any) => {
const prefab = go.create()
const score = parent.addChild(prefab).getComponent(ScoreAdd)
score.onSetText(text)

View File

@@ -1,62 +1,60 @@
import { ResourceManager } from "../../models/ResourceManager";
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class UISequenceAnimation extends Laya.Script {
declare owner : Laya.Image;
declare owner: Laya.Image
@property(String)
public prefix: string;
@property(String)
public prefix: string
@property(Number)
public beginIndex: number = 0
@property(Number)
public beginIndex: number = 0
@property(Number)
public endIndex: number
@property(Number)
public endIndex: number
@property(Boolean)
public playOnAwake: boolean = true
@property(Boolean)
public playOnAwake: boolean = true
@property(Boolean)
public loop: boolean = false
@property(Boolean)
public loop: boolean = false
private running: boolean = false
private currentIndex: number = 0
private running: boolean = false
private currentIndex: number = 0
onAwake(): void {
if (this.playOnAwake) {
this.running = true
} else {
this.running = false
}
onAwake(): void {
if (this.playOnAwake) {
this.running = true
} else {
this.running = false
}
this.currentIndex = this.beginIndex
}
onLateUpdate(): void {
if (this.running) {
if (this.currentIndex > this.endIndex) {
this.currentIndex = this.beginIndex
}
onLateUpdate(): void {
if (this.running) {
if (this.currentIndex > this.endIndex) {
this.currentIndex = this.beginIndex
if (this.loop === false) {
this.running = false
this.owner.visible = false
}
}
let endStr = this.currentIndex.toString()
if (this.currentIndex < 10) {
endStr = "00" + this.currentIndex
} else if (this.currentIndex < 100) {
endStr = "0" + this.currentIndex
}
let path = this.prefix + endStr + '.png'
// ResourceManager.getInstance().loadTexture(path, this.image)
this.owner.skin = path
this.currentIndex ++
if (this.loop === false) {
this.running = false
this.owner.visible = false
}
}
}
let endStr = this.currentIndex.toString()
if (this.currentIndex < 10) {
endStr = `00${this.currentIndex}`
} else if (this.currentIndex < 100) {
endStr = `0${this.currentIndex}`
}
const path = `${this.prefix + endStr}.png`
// ResourceManager.getInstance().loadTexture(path, this.image)
this.owner.skin = path
onSetRunning(running: boolean): void {
this.running = running
this.currentIndex++
}
}
}
onSetRunning(running: boolean): void {
this.running = running
}
}

View File

@@ -26,32 +26,32 @@ export class TrophyClaim extends Laya.Script {
onAwake(): void {
this.mask = this.owner.getChildByName("Image") as Laya.Image
this.mask.alpha = 0
Laya.Tween.to(this.mask, {alpha: 0.8}, 600)
Laya.Tween.to(this.mask, { alpha: 0.8 }, 600)
this.center = this.owner.getChildByName("center") as Laya.Box
const light = this.center.getChildByName("light") as Laya.Image
light.scaleX = 0
light.scaleY = 0
Laya.Tween.to(light, {scaleX: 1, scaleY: 1}, 200, Utility_EaseOut_2, null, 200)
Laya.Tween.to(light, { scaleX: 1, scaleY: 1 }, 200, Utility_EaseOut_2, null, 200)
const trophy = this.center.getChildByName("trophy") as Laya.Image
trophy.scaleX = 0
trophy.scaleY = 0
Laya.Tween.to(trophy, {scaleX: 1, scaleY: 1}, 200, Utility_EaseOut_2, null, 200)
Laya.Tween.to(trophy, { scaleX: 1, scaleY: 1 }, 200, Utility_EaseOut_2, null, 200)
const blossom = trophy.getChildByName("blossom").getComponent(UISequenceAnimation)
Laya.timer.once(400, this, ()=>{
Laya.timer.once(400, this, () => {
blossom.onSetRunning(true)
})
const label_titlle = this.center.getChildByName("label_titlle") as Laya.Label
label_titlle.alpha = 0
Laya.Tween.to(label_titlle, {alpha: 1}, 600, Laya.Ease.linearNone, null, 600)
Laya.Tween.to(label_titlle, { alpha: 1 }, 600, Laya.Ease.linearNone, null, 600)
const btn_close = this.center.getChildByName("btn_close") as Laya.Box
btn_close.alpha = 0
Laya.Tween.to(btn_close, {alpha: 1}, 600, Laya.Ease.linearNone, null, 800)
Laya.Tween.to(btn_close, { alpha: 1 }, 600, Laya.Ease.linearNone, null, 800)
}
public onSetShow(record: TrophyRecord): void {

View File

@@ -56,7 +56,7 @@ export class TrophyRoom extends Laya.Script {
list.push(obj)
}
console.log(">>>>>>>>>>>>years=", years)
ResourceManager.getInstance().loadPrefab(respath.trophy_year_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.trophy_year_ui_res(), (go: any) => {
for (let i = 1; i < years.length; i++) {
const obj_year = this.obj_items.getChildAt(i)
if (!obj_year) {
@@ -65,7 +65,7 @@ export class TrophyRoom extends Laya.Script {
}
}
ResourceManager.getInstance().loadPrefab(respath.trophy_cell_ui_res(), (go: any)=> {
ResourceManager.getInstance().loadPrefab(respath.trophy_cell_ui_res(), (go: any) => {
let itemsHeight = 0
for (let i = 0; i < years.length; i++) {
const list = monthMap.get(years[i])