597 lines
18 KiB
TypeScript
597 lines
18 KiB
TypeScript
import {_decorator, Component, director, instantiate, JsonAsset, Label, Node, Prefab, tween, v3, SpriteFrame, Sprite, PageView, Input, EventTouch} from 'cc';
|
|
import {UserMgr} from '../../module_basic/scripts/UserMgr';
|
|
import {
|
|
tgxAudioMgr,
|
|
tgxModuleContext,
|
|
tgxSceneUtil,
|
|
tgxUIAlert,
|
|
tgxUIMgr,
|
|
tgxUITipsBar,
|
|
tgxUIWaiting
|
|
} from '../../core_tgx/tgx';
|
|
import {SceneDef} from '../../scripts/SceneDef';
|
|
import {SceneUtil} from '../../core_tgx/base/SceneUtils';
|
|
import {UI_SearchingRival} from 'db://assets/module_arean/ui_searching_rival/UI_SearchingRival';
|
|
import {EventName} from '../../core_tgx/easy_ui_framework/EventName';
|
|
import {ModuleDef} from '../../scripts/ModuleDef';
|
|
import {resLoader} from '../../core_tgx/base/utils/ResLoader';
|
|
import {areanMgr} from './AreanManager';
|
|
import {AreanEvent, AreanNetMgr} from './AreanNetMgr';
|
|
import {UISetRoom} from "db://assets/module_arean/ui_set_room/UISetRoom";
|
|
import {EFightModel} from "db://assets/module_basic/shared/protocols/public/arean/AreanTypeDef";
|
|
import { SubGameMgr } from '../../module_basic/scripts/SubGameMgr';
|
|
import {UserLocalCache} from "db://assets/module_basic/scripts/UserLocalCache";
|
|
import {UserHead} from "db://assets/module_arean/scripts/UserHead";
|
|
import {EMusicDefine} from "db://assets/module_basic/Define/MusicDefine";
|
|
import {UIBag} from "db://assets/module_arean/ui_bag/UIBag";
|
|
import {IDanCfg} from "db://assets/module_basic/shared/configs/interface/IDanCfg";
|
|
import {CommonFun} from "db://assets/module_arean/scripts/CommonFun";
|
|
import {UIMail} from "db://assets/module_arean/ui_mail/UIMail";
|
|
import {UIMoreModel} from "db://assets/module_arean/ui_more_model/UIMoreModel";
|
|
import { UIShopScreen } from '../shop/ui_shop/UIShopScreen';
|
|
import {UISettings} from "db://assets/module_arean/ui_settings/UISettings";
|
|
import {EGameDefine} from "db://assets/module_arean/Define/GameDefine";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('AreanLobbyScene')
|
|
export class AreanLobbyScene extends Component {
|
|
|
|
private static isLoaded: boolean = true;
|
|
@property({ type: Node, displayName: ' loading选择' })
|
|
public loadingNode: Node | null = null;
|
|
|
|
|
|
@property({ type: Label })
|
|
public fightModel: Label;
|
|
|
|
@property({ type: Label })
|
|
public fightModel2: Label;
|
|
|
|
|
|
@property({ type: Label })
|
|
public rewardPool: Label;
|
|
|
|
@property(Node)
|
|
roleGroup: Node;
|
|
|
|
|
|
|
|
@property(Node)
|
|
headNode: Node;
|
|
|
|
|
|
|
|
|
|
// 动画节点
|
|
@property(Node)
|
|
actionNode: Node;
|
|
|
|
//
|
|
@property(Node)
|
|
arrowBtn: Node;
|
|
|
|
//
|
|
@property(Node)
|
|
chooseHeroBtn: Node;
|
|
|
|
// 段位信息节点
|
|
@property(Node)
|
|
danInfoNode: Node;
|
|
|
|
// banner节点
|
|
@property(Node)
|
|
bannerPageView: Node;
|
|
|
|
// banner cell
|
|
@property(Node)
|
|
bannerCell: Node;
|
|
|
|
private _isAction : boolean = false;
|
|
private _pageCount : number = 5;
|
|
private _canClick : boolean = true;
|
|
|
|
private currentReward: number = 0;
|
|
private targetReward: number = 0;
|
|
private readonly MIN_UPDATE_INTERVAL: number = 1; // 最小更新间隔1秒
|
|
private readonly MAX_UPDATE_INTERVAL: number = 3; // 最大更新间隔3秒
|
|
private readonly MIN_REWARD_INCREMENT: number = 5; // 最小增量5
|
|
private readonly MAX_REWARD_INCREMENT: number = 10; // 最大增量10
|
|
|
|
// 大额更新相关
|
|
private readonly MAJOR_UPDATE_INTERVAL: number = 10; // 每10秒大额更新
|
|
private readonly MIN_MAJOR_INCREMENT: number = 50; // 最小大额增量50
|
|
private readonly MAX_MAJOR_INCREMENT: number = 100; // 最大大额增量100
|
|
|
|
private readonly ANIMATION_DURATION: number = 0.5; // 动画持续时间
|
|
|
|
protected onLoad(): void {
|
|
this.initEventListener();
|
|
tgxModuleContext.setDefaultModule(ModuleDef.Arean);
|
|
tgxUIMgr.inst.closeAll();
|
|
}
|
|
|
|
async start() {
|
|
|
|
if (AreanLobbyScene.isLoaded) {
|
|
AreanNetMgr.inst.initNetMsgHandlers();
|
|
await AreanNetMgr.inst.sendMsg_GetUserData();
|
|
console.log("this == ",this,this.loadingNode);
|
|
this.loadingNode.active = true;
|
|
await this.loadData();
|
|
} else {
|
|
this.loadingNode.active = false;
|
|
this._updateHeadInfo();
|
|
}
|
|
this.onCompleteCallback().then();
|
|
this._updateFightModelName();
|
|
//this._initBannerPageView();
|
|
|
|
// 初始化奖池数字
|
|
this.initRewardPool();
|
|
// 启动小额更新
|
|
this.scheduleNextUpdate();
|
|
// 启动大额更新
|
|
this.schedule(this.updateMajorReward, this.MAJOR_UPDATE_INTERVAL);
|
|
}
|
|
|
|
async loadData(){
|
|
tgxUIWaiting.show('数据加载', true);
|
|
AreanLobbyScene.isLoaded = false;
|
|
if (!UserMgr.inst.userId) {
|
|
tgxSceneUtil.loadScene(SceneDef.START);
|
|
return;
|
|
}
|
|
// await this.loadLanguage();
|
|
await this.loadGameRes();
|
|
// await this.loadDatatables();
|
|
}
|
|
|
|
private initEventListener() {
|
|
director.on(AreanEvent.InBattleView, this.onStartGame, this);
|
|
}
|
|
|
|
|
|
/**
|
|
* 开始游戏
|
|
*/
|
|
private onStartGame(data:any) {
|
|
try {
|
|
let ui = tgxUIMgr.inst.getUI<UI_SearchingRival>(UI_SearchingRival);
|
|
let params = ui== null? UserMgr.inst.reTrayGameParmas:ui.params;
|
|
SubGameMgr.inst.enterSubGame(params,UserMgr.inst.uid,true);
|
|
} catch (error) {
|
|
console.log('开始游戏报错 error', error);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 多人匹配,自定义按钮动画
|
|
onBtnShowAction() : void{
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
this._updateArrow();
|
|
}
|
|
|
|
private _updateArrow() : void{
|
|
let angle = this.arrowBtn.getChildByName("arrow").angle;
|
|
// console.log("当前的角度 === ",angle);
|
|
if(angle == 180){
|
|
this.arrowBtn.getChildByName("arrow").angle = 0;
|
|
this.showAction(true);
|
|
}else{
|
|
this.arrowBtn.getChildByName("arrow").angle = 180;
|
|
this.showAction(false);
|
|
}
|
|
}
|
|
|
|
private showAction(open : boolean) : void{
|
|
if(this._isAction) return;
|
|
this._isAction = true;
|
|
let offsetY : number = open ? 280 : -280;
|
|
let time : number = 0.1;
|
|
if(offsetY > 0){
|
|
tween(this.actionNode)
|
|
.by(time,{position : v3(0,offsetY,0)},{easing: 'backOut'})
|
|
.call(()=>{
|
|
this._isAction = false;
|
|
})
|
|
.start()
|
|
}else{
|
|
tween(this.actionNode)
|
|
.by(time,{position : v3(0,offsetY,0)},{easing: 'backIn'})
|
|
.call(()=>{
|
|
this._isAction = false;
|
|
})
|
|
.start()
|
|
}
|
|
}
|
|
|
|
/** 是否可以点击 */
|
|
private setCanClick(flag : boolean) : void{
|
|
this._canClick = flag;
|
|
}
|
|
|
|
|
|
onBtnLobby() {
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
SceneUtil.loadScene(SceneDef.LOBBY);
|
|
}
|
|
|
|
onBtnQuickPlayClicked() {
|
|
if(!this._canClick) return;
|
|
this._canClick = false;
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
let curCoin = UserMgr.inst.userInfo.coin;
|
|
if(curCoin < EGameDefine.GameMatchCost){
|
|
tgxUITipsBar.show("金币不足,请前往商店购买!");
|
|
this._canClick = true;
|
|
return;
|
|
}
|
|
this._updateFightModel();
|
|
tgxUIWaiting.hide();
|
|
tgxUIMgr.inst.showUI(UI_SearchingRival, (ui: UI_SearchingRival) => {
|
|
this.scheduleOnce(() => {
|
|
ui.startMatch('arean',this.loadGame);
|
|
this.setCanClick(true);
|
|
}, 1.5);
|
|
});
|
|
}
|
|
|
|
private async loadGame(params?: any) {
|
|
await AreanNetMgr.inst.enterRoom(params,UserMgr.inst.uid);
|
|
}
|
|
|
|
|
|
|
|
onBtnCreate() {
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
// tgxAudioMgr.inst.playCommonBtn();
|
|
// tgxUIMgr.inst.showUI(UICreateRoom);
|
|
}
|
|
|
|
onBtnJoinRoom() {
|
|
if(!this._canClick) return;
|
|
this._canClick = false;
|
|
UserLocalCache.inst.setFightModel(EFightModel.Room);
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
tgxUIMgr.inst.showUI(UISetRoom,()=>{
|
|
this.setCanClick(true);
|
|
})
|
|
}
|
|
|
|
|
|
|
|
private _updateFightModel() : void{
|
|
let curModel = UserLocalCache.inst.fightModel;
|
|
if(curModel === EFightModel.Room){
|
|
let str = this.fightModel2.string;
|
|
let nextModel = str = EFightModel.Match ? EFightModel.Match : EFightModel.Ranking;
|
|
UserLocalCache.inst.setFightModel(nextModel);
|
|
}
|
|
}
|
|
|
|
|
|
// 刷新战斗模式
|
|
async onBtnRefreshFightModel(): Promise<void> {
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
let str = this.fightModel2.string;
|
|
let nextModel = str = EFightModel.Match ? EFightModel.Ranking : EFightModel.Match;
|
|
UserLocalCache.inst.setFightModel(nextModel);
|
|
this._updateFightModelName();
|
|
}
|
|
|
|
// 刷新战斗模式名字
|
|
private _updateFightModelName() : void{
|
|
// let curModel = UserLocalCache.inst.fightModel;
|
|
// this.fightModel.string = curModel === EFightModel.Match ? "匹配" : "排位";
|
|
// this.fightModel2.string = curModel === EFightModel.Match ? EFightModel.Match : EFightModel.Ranking;
|
|
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
|
|
|
|
|
|
}
|
|
|
|
private loadLanguage() {
|
|
this.modelName = "多语言模块加载";
|
|
return new Promise((resolve, reject) =>
|
|
{
|
|
resLoader.load(ModuleDef.Arean,'res/Config/Language',(err:Error,data:JsonAsset)=>{
|
|
if(err){
|
|
console.log('语言加载失败',err);
|
|
reject();
|
|
return;
|
|
}
|
|
|
|
resolve(data);
|
|
})
|
|
});
|
|
}
|
|
|
|
|
|
|
|
private async loadGameRes() {
|
|
this.modelName = "资源模块加载";
|
|
try {
|
|
return new Promise((resolve, reject) => {
|
|
resLoader.loadDir(ModuleDef.Arean, "res/", this.onProgressCallback.bind(this), resolve);
|
|
})
|
|
} catch (error) {
|
|
|
|
}
|
|
}
|
|
|
|
private progress: number = 0;
|
|
private modelName: string = '';
|
|
protected data: any = {
|
|
finished: 0,
|
|
total: 0,
|
|
progress: ""
|
|
};
|
|
private async loadDatatables() {
|
|
this.modelName = "数据模块加载";
|
|
return new Promise((resolve, reject) => {
|
|
areanMgr.cfgMgr.LoadAll(this.onProgressCallback.bind(this),resolve);
|
|
})
|
|
}
|
|
|
|
|
|
private onProgressCallback(finished: number, total: number, item: any) {
|
|
this.data.finished = finished;
|
|
this.data.total = total;
|
|
var progress = finished / total;
|
|
if (progress > this.progress) {
|
|
this.progress = progress;
|
|
this.data.progress = (progress * 100).toFixed(2);
|
|
}
|
|
director.emit(EventName.load_res, progress, this.modelName);
|
|
}
|
|
|
|
async onCompleteCallback() {
|
|
tgxUIWaiting.hide();
|
|
this.loadingNode.active = false;
|
|
director.emit(EventName.update_language);
|
|
console.log('数据加载完----------');
|
|
this._updateHeadInfo();
|
|
let isInRoom= UserMgr.inst.isInRoom();
|
|
if(isInRoom){
|
|
let ret2 = await UserMgr.inst.doTryEnterRoom(UserMgr.inst.roomId);
|
|
if (!ret2.isSucc) {
|
|
//进入大厅
|
|
let ret = await AreanNetMgr.inst.rpc_LeaveRoom();
|
|
if (ret.isSucc) {
|
|
|
|
console.log("退出房间成功");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 刷新头像节点段位
|
|
private _updateHeadInfo() : void{
|
|
this.headNode.getComponent(UserHead).updateDanImg();
|
|
}
|
|
|
|
|
|
|
|
/** 排行榜 */
|
|
public onBtnRankClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
/** 排行榜 */
|
|
public onBtnSetClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_OPEN);
|
|
tgxUIMgr.inst.showUI(UISettings);
|
|
}
|
|
|
|
/** 商店 */
|
|
public onBtnShopClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
// tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
tgxUIMgr.inst.showUI(UIShopScreen);
|
|
}
|
|
|
|
/** 活动 */
|
|
public onBtnActivityClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
/** 神话降临 */
|
|
public onBtnActivity2Clicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
|
|
|
|
/** 背包事件 */
|
|
onBtnBagClicked(){
|
|
if(!this._canClick) return;
|
|
this._canClick = false;
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_OPEN);
|
|
tgxUIMgr.inst.showUI(UIBag,()=>{
|
|
this.setCanClick(true);
|
|
});
|
|
}
|
|
|
|
/** 备战 */
|
|
onBtnWarClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
/** 图鉴 */
|
|
onBtnIllustrationClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
/** 好友 */
|
|
onBtnFriendClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_INVALID);
|
|
tgxUIAlert.show("研发团队加班中,敬请期待!");
|
|
}
|
|
|
|
/** 更多模式 */
|
|
onBtnMoreModelClicked(){
|
|
if(!this._canClick) return;
|
|
this._canClick = false;
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_OPEN);
|
|
tgxUIMgr.inst.showUI(UIMoreModel,()=>{
|
|
this.setCanClick(true);
|
|
});
|
|
}
|
|
|
|
/** 邮件 */
|
|
onBtnMailClicked(){
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_OPEN);
|
|
tgxUIMgr.inst.showUI(UIMail)
|
|
}
|
|
|
|
|
|
/** 获取页面通过索引 */
|
|
getPageByIndex(index: number): Node {
|
|
const pages = this.bannerPageView.getComponent(PageView).getPages();
|
|
return pages[index];
|
|
}
|
|
|
|
|
|
/** banner广告位 */
|
|
private _initBannerPageView() : void{
|
|
this.bannerPageView.on('page-turning', this._callback, this);
|
|
let len = this._pageCount;
|
|
let pageView = this.bannerPageView.getComponent(PageView);
|
|
pageView.removeAllPages();
|
|
for(let i = 0; i < len; i++){
|
|
let node = instantiate(this.bannerCell);
|
|
let attr = {
|
|
tag : i
|
|
}
|
|
node.attr(attr);
|
|
node.active = true;
|
|
node.getChildByName("lab").getComponent(Label).string = `第${i + 1}页`;
|
|
pageView.addPage(node);
|
|
node.on(Input.EventType.TOUCH_END,(e : EventTouch)=>{
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK)
|
|
let tag = e.target.tag;
|
|
this._openBannerLayer(tag);
|
|
},this)
|
|
}
|
|
// 是否循环
|
|
let flag = true;
|
|
if (flag) { //如果循环需要在最前边和最后边在放一页
|
|
let firstNode = instantiate(this.getPageByIndex(0));
|
|
let lastNode = instantiate(this.getPageByIndex(this._pageCount - 1));
|
|
pageView.insertPage(lastNode, 0);
|
|
pageView.addPage(firstNode);
|
|
console.log("this.pages:", pageView.getPages());
|
|
}
|
|
pageView.setCurrentPageIndex(1);
|
|
this.schedule(this._autoScrollToNextPage, 5);
|
|
}
|
|
|
|
/** 轮播图事件 */
|
|
private _openBannerLayer(index : number) {
|
|
console.log("点击的轮播图 === ",index);
|
|
}
|
|
|
|
/** 翻页回调 */
|
|
private _callback(pageView: PageView) : void{
|
|
let newIndex : number = pageView.getCurrentPageIndex();
|
|
if (newIndex == 0) {
|
|
pageView.scrollToPage(this._pageCount, 0);
|
|
pageView.setCurrentPageIndex(this._pageCount);
|
|
}
|
|
if (newIndex == this._pageCount + 1) {
|
|
pageView.scrollToPage(1, 0);
|
|
pageView.setCurrentPageIndex(1);
|
|
}
|
|
}
|
|
|
|
/** 自动翻页 */
|
|
private _autoScrollToNextPage() : void{
|
|
let pageView = this.bannerPageView.getComponent(PageView);
|
|
let currentIndex = pageView.getCurrentPageIndex();
|
|
let nextIndex = (currentIndex + 1) % (this._pageCount + 2);
|
|
pageView.scrollToPage(nextIndex,1);
|
|
}
|
|
|
|
private initRewardPool() {
|
|
// 设置初始奖池为1000-2000之间的随机数
|
|
this.currentReward = Math.floor(Math.random() * 10000) + 10000;
|
|
this.targetReward = this.currentReward;
|
|
this.rewardPool.string = this.currentReward.toString();
|
|
}
|
|
|
|
private scheduleNextUpdate() {
|
|
// 随机1-3秒后执行下一次更新
|
|
const nextInterval = Math.random() * (this.MAX_UPDATE_INTERVAL - this.MIN_UPDATE_INTERVAL) + this.MIN_UPDATE_INTERVAL;
|
|
this.scheduleOnce(this.updateRewardPool.bind(this), nextInterval);
|
|
}
|
|
|
|
private updateRewardPool() {
|
|
// 生成5-10之间的随机增量
|
|
const increment = Math.floor(Math.random() * (this.MAX_REWARD_INCREMENT - this.MIN_REWARD_INCREMENT + 1)) + this.MIN_REWARD_INCREMENT;
|
|
|
|
// 更新目标值
|
|
this.targetReward += increment;
|
|
|
|
// 创建数字滚动动画
|
|
this.animateRewardNumber();
|
|
|
|
// 安排下一次更新
|
|
this.scheduleNextUpdate();
|
|
}
|
|
|
|
private animateRewardNumber() {
|
|
if (this.rewardPool['_tween']) {
|
|
this.rewardPool['_tween'].stop();
|
|
}
|
|
|
|
const tweenObj = { value: this.currentReward };
|
|
|
|
this.rewardPool['_tween'] = tween(tweenObj)
|
|
.to(this.ANIMATION_DURATION, {
|
|
value: this.targetReward
|
|
}, {
|
|
onUpdate: () => {
|
|
this.currentReward = tweenObj.value;
|
|
this.updatePrizePool(Math.round(this.currentReward));
|
|
}
|
|
})
|
|
.start();
|
|
}
|
|
|
|
onDestroy() {
|
|
// 清理所有定时器
|
|
this.unscheduleAllCallbacks();
|
|
// 停止动画(如果有)
|
|
if (this.rewardPool['_tween']) {
|
|
this.rewardPool['_tween'].stop();
|
|
}
|
|
}
|
|
|
|
private updateMajorReward() {
|
|
// 生成50-100之间的随机增量
|
|
const increment = Math.floor(Math.random() * (this.MAX_MAJOR_INCREMENT - this.MIN_MAJOR_INCREMENT + 1)) + this.MIN_MAJOR_INCREMENT;
|
|
this.targetReward += increment;
|
|
this.animateRewardNumber();
|
|
}
|
|
|
|
private updatePrizePool(value: number) {
|
|
if (this.rewardPool) {
|
|
// 将数字转换为字符串并添加"B"后缀
|
|
this.rewardPool.string = `${value}b`;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|