This commit is contained in:
2024-04-16 23:03:54 +08:00
commit 54580cc1b2
723 changed files with 103745 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import {
_decorator,
Component,
Label,
Node,
tween,
Vec3,
instantiate,
} from 'cc'
const { ccclass, property } = _decorator
import PrefabLoader from '../utils/PrefabLoader'
import { GameConfig } from '../../game/config/GameConfig'
import DialogBase from './DialogBase'
@ccclass('CommonTips')
export default class CommonTips extends Component {
public static TipsZorderIndex: number = 999
@property({ type: Label })
txtContent: Label | null = null
private tips: string = ''
private static showingNameList: Array<string> = []
onLoad() {}
start() {
tween(this.node)
.by(1.5, { position: new Vec3(0, 100, 0) })
.to(0.2, { /* opacity: 0*/ scale: Vec3.ZERO })
.call(() => {
this.node.destroy()
})
.start()
}
onDestroy() {
let index: number = CommonTips.showingNameList.indexOf(this.tips)
CommonTips.showingNameList.splice(index, 1)
this.unscheduleAllCallbacks()
}
public static showMsg(msg: string, parentNode: Node = null) {
PrefabLoader.loadPrefab(
`${GameConfig.GameName}/share/uicomponent/CommonTips`,
(loadedResource) => {
parentNode = parentNode || DialogBase.GetRootCanvas()
if (CommonTips.showingNameList.indexOf(msg) === -1) {
CommonTips.showingNameList.push(msg)
}
let dialogNode = instantiate(loadedResource)
dialogNode.setPosition(0, 0)
let dialogScript: CommonTips = dialogNode.getComponent(CommonTips)
dialogScript.tips = msg
dialogScript.txtContent.string = msg
parentNode.insertChild(dialogNode, CommonTips.TipsZorderIndex)
}
)
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4524f0ef-319a-4f20-9d62-fe359bbcbc71",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,30 @@
import { _decorator, Component, Prefab, Widget, instantiate, Node } from 'cc'
const { ccclass, property } = _decorator
import PrefabLoader from '../utils/PrefabLoader'
import { GameConfig } from '../../game/config/GameConfig'
import DialogBase from './DialogBase'
@ccclass('DarkLayer')
export default class DarkLayer extends Component {
private static prefab: Prefab
onLoad() {
this.getComponent(Widget).target = DialogBase.GetRootCanvas()
}
start() {}
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
`${GameConfig.GameName}/share/uicomponent/DarkLayer`,
(loadedResource) => {
DarkLayer.prefab = loadedResource
resolve()
}
)
})
}
public static getDarkLayer() {
let dialogNode: Node = instantiate(DarkLayer.prefab)
return dialogNode
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4fa811bd-9cd5-4ac6-ad87-d68f4a41dcdf",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,65 @@
import { _decorator, Component, Node, Widget, director } from 'cc'
const { ccclass } = _decorator
import DarkLayer from './DarkLayer'
import { UIRoot } from '../../game/utils/UIRoot'
@ccclass('DialogBase')
export default class DialogBase extends Component {
private static LocalZOrder: number = 5
private darkLayer: Node | null = null
//private static _canvas: Node;
public static GetRootCanvas(): Node {
//if(DialogBase._canvas == null)
// DialogBase._canvas = director.getScene().getChildByName('Canvas');
//return DialogBase._canvas;
return UIRoot.Instance.node
}
onLoad() {
DialogBase.LocalZOrder += 1
let closeLayer: Node = this.node.getChildByName('closeLayer')
if (closeLayer) {
let closeLayerWidget: Widget = closeLayer.getComponent(Widget)
if (closeLayerWidget) {
closeLayerWidget.target = DialogBase.GetRootCanvas()
closeLayerWidget.left = 0
closeLayerWidget.right = 0
closeLayerWidget.top = 0
closeLayerWidget.bottom = 0
}
}
this.onLoadMe()
}
onLoadMe() {}
start(isPlayMv: boolean = false) {
this.darkLayer = DarkLayer.getDarkLayer()
this.node.insertChild(this.darkLayer, 0) //this.node.addChild(this.darkLayer, -1);
if (isPlayMv) {
this.node.setScale(0, 0)
} else {
this.onStartMe()
}
}
onStartMe() {}
onClickClose() {
this.node.destroy()
}
update(dt) {
this.onUpdateMe(dt)
}
onUpdateMe(dt) {}
onDestroy() {
DialogBase.LocalZOrder -= 1
this.onDestroyMe()
}
onDestroyMe() {}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1fc7cf08-75c2-4ec4-b4c0-6f27eb483210",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,87 @@
import {
_decorator,
Component,
Node,
Prefab,
instantiate,
math,
Quat,
Vec3,
} from 'cc'
const { ccclass, property } = _decorator
import PrefabLoader from '../utils/PrefabLoader'
import { GameConfig } from '../../game/config/GameConfig'
import DialogBase from './DialogBase'
@ccclass('LoadingPrefab')
export default class LoadingPrefab extends Component {
public static instance: Node
private static prefab: Prefab
public static LoadingZorderIndex: number = 99
@property({ type: Node })
loadingSp: Node | null = null
private _quatCache: Quat
private _vec3Cache: Vec3
onLoad() {
this._quatCache = new Quat()
this._vec3Cache = new Vec3()
}
start() {}
public static close() {
if (!LoadingPrefab.instance) {
return
}
LoadingPrefab.instance.removeFromParent()
LoadingPrefab.instance.destroy()
LoadingPrefab.instance = null
}
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'share/uicomponent/LoadingPrefab',
(loadedResource) => {
LoadingPrefab.prefab = loadedResource
resolve()
}
)
})
}
private static createLoadingPrefab(parentNode: Node = null) {
let dialogNode: Node = instantiate(LoadingPrefab.prefab)
LoadingPrefab.instance = dialogNode
if (!parentNode) {
parentNode = DialogBase.GetRootCanvas()
}
parentNode.insertChild(dialogNode, LoadingPrefab.LoadingZorderIndex)
dialogNode.setPosition(0, 0)
}
public static async show(parentNode: Node = null) {
if (LoadingPrefab.instance) return
if (!LoadingPrefab.prefab) {
await LoadingPrefab.preLoad()
}
this.createLoadingPrefab(parentNode)
}
update(dt) {
this.loadingSp.getRotation(this._quatCache)
Quat.toEuler(this._vec3Cache, this._quatCache)
this._vec3Cache.z += 10
this.loadingSp.setRotationFromEuler(this._vec3Cache)
if (this._vec3Cache.z >= 360) {
this.loadingSp.getRotation(Quat.IDENTITY)
}
}
public static clear() {
LoadingPrefab.instance = null
LoadingPrefab.prefab = null
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "172559f4-6da9-4c5d-a0b4-af9f5116f021",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,90 @@
import { _decorator, Component, Node, Prefab, instantiate } from 'cc'
const { ccclass, property } = _decorator
import PrefabLoader from '../utils/PrefabLoader'
import Progress from './Progress'
import { GameConfig } from '../../game/config/GameConfig'
import DialogBase from './DialogBase'
@ccclass('LoadingScenePrefab')
export default class LoadingScenePrefab extends Component {
public static instance: Node
private static prefab: Prefab
public static LoadingZorderIndex: number = 99
@property({ type: Node })
private progressNode: Node | null = null
onLoad() {}
start() {}
public updateProgress(
completedCount: number,
totalCount: number,
item: any = null
) {
this.progressNode
.getComponent(Progress)
.updateProgress(
completedCount,
totalCount,
'消耗流量,预下载所有"鱼"类中,请耐心等待...'
)
}
public static updateLoading(
completedCount: number,
totalCount: number,
item: any = null
) {
if (LoadingScenePrefab.instance) {
let nodeTs: LoadingScenePrefab =
LoadingScenePrefab.instance.getComponent(LoadingScenePrefab)
if (nodeTs) {
nodeTs.updateProgress(completedCount, totalCount, item)
}
}
}
private static createPrefab(parentNode: Node = null) {
let dialogNode: Node = instantiate(LoadingScenePrefab.prefab)
LoadingScenePrefab.instance = dialogNode
if (!parentNode) {
parentNode = DialogBase.GetRootCanvas()
}
parentNode.insertChild(dialogNode, LoadingScenePrefab.LoadingZorderIndex)
dialogNode.setPosition(0, 0)
}
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'share/uicomponent/LoadingScenePrefab',
(loadedResource: Prefab) => {
LoadingScenePrefab.prefab = loadedResource
resolve()
}
)
})
}
public static close() {
if (!LoadingScenePrefab.instance) {
return
}
LoadingScenePrefab.instance.destroy()
LoadingScenePrefab.instance = null
}
public static async show(parentNode: Node = null) {
if (LoadingScenePrefab.instance) return
if (!LoadingScenePrefab.prefab) {
await LoadingScenePrefab.preLoad()
}
this.createPrefab(parentNode)
}
public static clear() {
LoadingScenePrefab.instance = null
LoadingScenePrefab.prefab = null
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e2e744b0-b723-4151-8de6-a2c222b8fe29",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,90 @@
import {
_decorator,
Component,
AssetManager,
AudioClip,
AudioSource,
instantiate,
Prefab,
} from 'cc'
const { ccclass, property } = _decorator
import { Logger } from '../utils/Logger'
import PrefabLoader from '../utils/PrefabLoader'
import LocalStorage from '../utils/LocalStorage'
import MusicConfig from '../config/MusicConfig'
import { GameConfig } from '../../game/config/GameConfig'
/**
* 背景音乐
*/
@ccclass('MusicPrefab')
export default class MusicPrefab extends Component {
private static instance: MusicPrefab
private static MUSIC_VOLUMN_KEY: string = 'musicVolumn'
public static musicVolumn: number = 1
public static play(key: string) {
let url: string = MusicConfig.musicKey2Path.get(key)
if (url) {
AssetManager.instance.resources.load(
url,
AudioClip,
(error: Error, clip: AudioClip) => {
if (error) {
Logger.warn(this, 'load music error===', error.message)
} else {
if (clip) {
this.instance.node.getComponent(AudioSource).clip = clip
this.instance.node.getComponent(AudioSource).volume =
this.musicVolumn
this.instance.node.getComponent(AudioSource).play()
this.instance.node.getComponent(AudioSource).loop = true
}
}
}
)
} else {
Logger.warn(this, '播放不存在的music=', key)
}
}
public static changeVolumn(nowVolumn: number) {
this.musicVolumn = nowVolumn
this.instance.node.getComponent(AudioSource).volume = nowVolumn
LocalStorage.setItem(
MusicPrefab.MUSIC_VOLUMN_KEY,
this.musicVolumn.toString()
)
}
private static preInit() {
this.musicVolumn = parseFloat(
LocalStorage.getItem(MusicPrefab.MUSIC_VOLUMN_KEY)
)
if (isNaN(this.musicVolumn)) {
this.musicVolumn = 1
}
}
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'share/uicomponent/MusicPrefab',
(loadedResource: Prefab) => {
MusicPrefab.instance =
instantiate(loadedResource).getComponent(MusicPrefab)
this.preInit()
resolve()
}
)
})
}
public static destory() {
if (MusicPrefab.instance) {
MusicPrefab.instance.getComponent(AudioSource).stop()
MusicPrefab.instance.destroy()
}
MusicPrefab.instance = null
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e947ef07-b958-4471-b5a5-f0acd7e299d2",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,57 @@
import { _decorator, Component, Label, ProgressBar } from 'cc'
const { ccclass, property } = _decorator
import { Logger } from '../utils/Logger'
@ccclass('Progress')
export default class Progress extends Component {
@property(Label)
public percentLable: Label
@property(ProgressBar)
public bar: ProgressBar
onLoad() {
this.bar.node.active = false
this.bar.progress = 0
}
start() {}
updatePercent(current, filePercent) {
//this.percentLable.string = filePercent.toFixed(2);
}
updatefileTotal(current, filePercent) {
if (!this.bar.node.active) this.bar.node.active = true
var nowPercent = Math.round((current / filePercent) * 100)
var curMB = this.getMB(current)
var totalMB = this.getMB(filePercent)
// this.percentLable.string = "正在更新 " + nowPercent + "%" + " ( " + curMB + " / "+totalMB +" MB)";
nowPercent = Math.min(nowPercent, 100)
this.percentLable.string = '正在更新 ' + nowPercent + '%'
var percent = current / filePercent
this.bar.progress = percent
}
public updateProgress(
current,
total,
msg: string = '正在加载资源,此过程不消耗流量...'
) {
this.bar.node.active = true
// this.setMsg(msg+ current + "/" + total);
this.setMsg(msg)
this.bar.progress = current / total
}
getMB(bytes) {
bytes /= 1024
bytes /= 1024
return bytes.toFixed(2)
}
public setMsg(msg: string = '游戏加载中,请稍后...') {
this.percentLable.string = msg
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ba38c648-abb9-41f8-a06b-830bb5aea91d",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,144 @@
import {
_decorator,
Component,
Prefab,
NodePool,
Node,
instantiate,
AssetManager,
AudioClip,
AudioSource,
} from 'cc'
const { ccclass, property } = _decorator
import { Logger } from '../utils/Logger'
import PrefabLoader from '../utils/PrefabLoader'
import LocalStorage from '../utils/LocalStorage'
import EventManager from '../utils/EventManager'
import CommonEvent from '../config/CommonEvent'
import MusicConfig from '../config/MusicConfig'
import { GameConfig } from '../../game/config/GameConfig'
// /**
// * 音效
// * Ios暂时有bug弃用
// */
@ccclass('SoundPrefab')
export default class SoundPrefab extends Component {
private static prefab: Prefab | null = null
private static SOUND_VOLUMN_KEY: string = 'soundVolumn'
public static soundVolumn: number = 1
private static Pool_Init_Num: number = 30
private static pool: NodePool = new NodePool()
private static nowAudioNodeList: Array<Node> = []
private audioName: string = ''
private audioUrl: string = ''
private static getAudioNode() {
let node: Node = null
// if (this.pool.size() > 0) {
// node = this.pool.get();
// } else {
node = instantiate(this.prefab)
// }
return node
}
public static play(key: string) {
let url: string = MusicConfig.musicKey2Path.get(key)
if (url) {
AssetManager.instance.resources.load(url, AudioClip, (error: Error, clip: AudioClip) => {
if (error) {
Logger.warn(this, 'load sound error===', error.message)
} else {
if (clip) {
let audioNode: Node = this.getAudioNode()
if (audioNode) {
audioNode.getComponent(AudioSource).clip = clip
audioNode.getComponent(AudioSource).volume =
SoundPrefab.soundVolumn
audioNode.getComponent(AudioSource).loop = false
audioNode.getComponent(AudioSource).currentTime = 0 //rewind();
audioNode.getComponent(AudioSource).play()
audioNode.getComponent(SoundPrefab).audioName = key
audioNode.getComponent(SoundPrefab).audioUrl = url
this.nowAudioNodeList.push(audioNode)
}
}
}
})
} else {
Logger.warn(this, '播放不存在的music=', key)
}
}
public static changeVolumn(nowVolumn: number) {
this.soundVolumn = nowVolumn
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
let audioNode: Node = this.nowAudioNodeList[i]
let audioSource: AudioSource = audioNode.getComponent(AudioSource)
if (audioSource.playing) {
audioSource.volume = nowVolumn
}
}
LocalStorage.setItem(
SoundPrefab.SOUND_VOLUMN_KEY,
SoundPrefab.soundVolumn.toString()
)
}
private static preInit() {
EventManager.instance.addListener(
CommonEvent.Event_FrameUpdate,
this.updateFrame,
this
)
SoundPrefab.soundVolumn = parseFloat(
LocalStorage.getItem(SoundPrefab.SOUND_VOLUMN_KEY)
)
if (isNaN(SoundPrefab.soundVolumn)) {
SoundPrefab.soundVolumn = 1
}
}
private static updateFrame() {
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
let audioNode: Node = this.nowAudioNodeList[i]
let audioSource: AudioSource = audioNode.getComponent(AudioSource)
if (!audioSource.playing) {
SoundPrefab.nowAudioNodeList.splice(i, 1)
}
}
}
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'share/uicomponent/SoundPrefab',
(loadedResource: Prefab) => {
SoundPrefab.prefab = loadedResource
this.preInit()
// for (let i = 0; i < this.Pool_Init_Num; i++) {
// let tempNode: cc.Node = cc.instantiate(loadedResource);
// this.pool.put(tempNode);
// }
resolve()
}
)
})
}
public static destory() {
EventManager.instance.removeListener(
CommonEvent.Event_FrameUpdate,
this.updateFrame
)
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
let audioNode: Node = this.nowAudioNodeList[i]
audioNode.getComponent(AudioSource).stop()
audioNode.getComponent(AudioSource).destroy()
}
this.nowAudioNodeList = []
this.pool.clear()
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d262f2b2-8af6-4db9-b1e4-0c08493efa10",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,20 @@
import { _decorator, Component, SpriteFrame } from 'cc'
const { ccclass, property } = _decorator
@ccclass('TextureMgr')
export default class TextureMgr extends Component {
@property({ type: [SpriteFrame] })
public Spriteset: SpriteFrame[] = []
@property({ type: [SpriteFrame] })
public Spriteset1: SpriteFrame[] = []
@property({ type: [SpriteFrame] })
public Spriteset2: SpriteFrame[] = []
@property({ type: [SpriteFrame] })
public Spriteset3: SpriteFrame[] = []
@property({ type: [SpriteFrame] })
public Spriteset4: SpriteFrame[] = []
onLoad() {
// // init logic
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1147cca4-2fe9-4d82-8850-0d97cb3318d5",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}