大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

363 lines
15 KiB

//#region 文件引入
import { _decorator, Button, Component, Label, Node, sp, Sprite, Animation, RichText, tween, v3, UITransform, Vec2, Vec3, macro } from "cc";
import BaseUIForm from "../../Mgr_UI/BaseUIForm";
import { EUIForms } from "../../const/UIFormCnf";
import UIMgr from "../../Mgr_UI/UIMgr";
import { MainBtnPoxy } from "./MainBtnPoxy";
import MesMgr from "../../MesEvent/MesMgr";
import { EGlobalEvent } from "../../MesEvent/EGlobalEvent";
import RoleDataMgr from "../../Mgr_LocalData/RoleDataMgr";
import { FIGHTING_TYPE, ITEM_TYPE, MainBtnType, PropType, QualityType } from "../../const/GameEnum";
import SceneDataMgr from "../../Mgr_LocalData/SceneDataMgr";
import StringUtils from "../../ExUtils/StringUtils";
import { Utils } from "../../ExUtils/Utils";
import MathUtils from "../../ExUtils/MathUtils";
import { MainConfig } from "db://assets/Launch/_MainConfig";
import { Global } from "../../Global";
import { TXSDKMgr } from "../../Mgr_Ge/TXSDKMgr";
import PlatformManager from "../../Platform/PlatformManager";
//#endregion 文件引入
// enum MainBtnType {
// NUll,
// Gongfa,
// Invest,
// Battle,
// Shop,
// Bag,
// }
const { ccclass, property, menu } = _decorator;
@ccclass("MainTopUI_Proxy")
export default class MainTopUI_Proxy extends BaseUIForm {
//#region 节点自动生成
@property(Button)
btn_PlayerInfo: Button = null;
@property(Label)
lab_FightNum: Label = null;
@property(Button)
btn_AddCoin: Button = null;
@property(Label)
lab_coin_num: Label = null;
@property(Button)
btn_AddTjCoin: Button = null;
@property(Label)
lab_tj_num: Label = null;
@property(Node)
n_notice: Node = null;
@property(RichText)
ric_notice: RichText = null;
@property(Node)
n_buttom: Node = null;
@property(Node)
n_buttomLayout: Node = null;
@property(Button)
btn_GongFa: Button = null;
@property(Button)
btn_Invest: Button = null;
@property(Button)
btn_Battle: Button = null;
@property(Button)
btn_Shop: Button = null;
@property(Button)
btn_Bag: Button = null;
@property(Node)
n_mask: Node = null;
@property(Node)
n_effect: Node = null;
//#endregion 节点自动生成
protected mMainBtnType: MainBtnType = MainBtnType.NUll;
// 跑马灯物品类型列表
private mNotice_Weapon: string[] = []; // 武器装备
private mNotice_Treasure: string[] = []; // 宝物
private mNotice_WuXue: string[] = []; // 武学
private mNotice_Painting: string[] = []; // 书画
onButtonClick(button: Button) {
/**点击事件触发*/
switch (button) {
case this.btn_GongFa:
this.setMainBtnType(MainBtnType.Gongfa);
break;
case this.btn_Invest:
this.setMainBtnType(MainBtnType.Invest);
break;
case this.btn_Battle:
this.setMainBtnType(MainBtnType.Battle);
break;
case this.btn_Shop:
this.setMainBtnType(MainBtnType.Shop);
break;
case this.btn_Bag:
this.setMainBtnType(MainBtnType.Bag);
break;
case this.btn_AddCoin:
// -----------------备案包临时屏蔽----------------//
UIMgr.Ins.ShowUI(EUIForms.LookAdGetUI)
break;
case this.btn_AddTjCoin:
UIMgr.Ins.ShowUI(EUIForms.LookAdGetTJUI, {param:{isMain:true}});
break;
case this.btn_PlayerInfo:
// -----------------备案包临时屏蔽----------------//
UIMgr.Ins.ShowUI(EUIForms.PersonalDetailsUI)
break;
default:
ConsoleEx.Log(button);
break;
}
}
addEvent(): void {
MesMgr.on(EGlobalEvent.REFRESH_FIGHT,this.refreshFight,this)
MesMgr.on(EGlobalEvent.REFRESH_FIGHTING,this.refreshFightNum,this)
MesMgr.on(EGlobalEvent.E_UPDATE_TOKEN,this.refreshCoin,this)
MesMgr.on(EGlobalEvent.UNLOCK_MAINPAGE, this.refreshMainPage, this);
MesMgr.on(EGlobalEvent.RESTART_NEWGAME, this.start, this);
MesMgr.on(EGlobalEvent.SHOW_MAINTOP_BUTTOM, this.showBottomNode, this);
MesMgr.on(EGlobalEvent.CHANGE_FIGHTING_TYPE,this.refreshFightingType,this);
MesMgr.on(EGlobalEvent.E_FEED_ENTER_GAME,this.feedEnterGame,this);
MesMgr.on(EGlobalEvent.OPEN_MAINPAGE, this.setMainBtnType, this);
MesMgr.on(EGlobalEvent.PLAY_SUIT_SKILL, this.playSuitSkill, this);
this.setMainBtnType(MainBtnType.Battle);
this.reflashButtom();
TXSDKMgr.ins.onLevel_Enter(
{
level_id: this.mDataMgr.Scene.getRealLevel(),
enter_level_name:this.mDataMgr.Scene.level.displayName,
coin_amount:this.mDataMgr.Token.getTokenCount(PropType.eGold)
}
);
}
protected start(): void {
this.refreshFightNum();
this.refreshCoin(PropType.eGold);
this.refreshCoin(PropType.eTaiJi);
this.refreshFight();
this.refreshMainPage();
this.feedEnterGame();
this.playNotice();
if(window['ks'] && Global.CsvMgr.openInterstitalAd()){
this.schedule(()=>{
Global.ShowInterstitalAd();
},62,macro.REPEAT_FOREVER,40);
}
}
// 播放套装技能,改变spine节点
private playSuitSkill(spineNode: Node, duration: number) {
CNodeUtils.setActive(this.n_mask, true);
spineNode.setParent(this.n_effect);
this.scheduleOnce(()=>{
CNodeUtils.setActive(this.n_mask, false);
}, duration);
}
// 有任务完成,查看是否解锁主页面的功能
refreshMainPage(){
const curtaskid = Number(this.mDataMgr.Task.task.id);
CNodeUtils.setActive(this.btn_GongFa, curtaskid > 1);
CNodeUtils.setActive(this.btn_Bag, curtaskid > 2);
CNodeUtils.setActive(this.btn_Shop, curtaskid > 5);
CNodeUtils.setActive(this.btn_Invest, curtaskid > 12);
}
refreshFight(){
const Level = SceneDataMgr.Ins.level;
CNodeUtils.setActive(this.btn_AddCoin, Level.monster.fighting);
CNodeUtils.setActive(this.btn_AddTjCoin, Level.monster.fighting);
// -----------------备案包临时屏蔽----------------//
CNodeUtils.setActive(this.n_buttom, Level.monster.fighting);
// CNodeUtils.setActive(this.n_buttom, false);
// -------------------------------------//
}
refreshFightingType() {
if(this.mDataMgr.Scene.fighting_type !== FIGHTING_TYPE.PVE){
CNodeUtils.setActive(this.btn_AddCoin, false);
CNodeUtils.setActive(this.btn_AddTjCoin, false);
CNodeUtils.setActive(this.n_buttom, false);
}
}
showBottomNode(show:boolean){
CNodeUtils.setActive(this.n_buttom, show);
}
refreshFightNum(old:number = 0){
CNodeUtils.switchText(this.lab_FightNum,RoleDataMgr.Ins.fighting);
const curfighting = RoleDataMgr.Ins.fighting;
if(old > 0){
if(old==curfighting){return};
const tips = curfighting > old ? (`战斗力 <color=#218026>提高${curfighting - old}点</c>`) : (`战斗力 <color=#C82E2E>下降${old - curfighting}点</c>`);
UIMgr.Ins.ShowTipsUI(tips);
}
}
refreshCoin(type:PropType,num:number = 0){
const coin = num || this.mDataMgr.Token.getTokenCount(type);
switch (type) {
case PropType.eGold:
CNodeUtils.switchText(this.lab_coin_num, StringUtils.formatLargeNumber(coin));
break;
case PropType.eTaiJi:
CNodeUtils.switchText(this.lab_tj_num, StringUtils.formatLargeNumber(coin));
break;
default:
break;
}
}
setMainBtnType(type: MainBtnType) {
if (this.mMainBtnType == type) { return; }
let lastType = this.mMainBtnType;
this.mMainBtnType = type;
let lamuda = () => {
this.CloseOtherUI(lastType);
this.reflashButtom();
}
switch (this.mMainBtnType) {
case MainBtnType.Gongfa:
UIMgr.Ins.ShowUI(EUIForms.WuGongUI, { BackFun: lamuda })
break;
case MainBtnType.Invest:
UIMgr.Ins.ShowUI(EUIForms.InvestUI, { BackFun: lamuda })
break;
case MainBtnType.Battle:
UIMgr.Ins.ShowUI(EUIForms.MainUI, { BackFun: lamuda })
break;
case MainBtnType.Shop:
UIMgr.Ins.ShowUI(EUIForms.ShopUI, { BackFun: lamuda })
break;
case MainBtnType.Bag:
UIMgr.Ins.ShowUI(EUIForms.BagUI, { BackFun: lamuda })
break;
default:
lamuda();
break;
}
}
CloseOtherUI(type: MainBtnType) {
switch (type) {
case MainBtnType.Gongfa:
UIMgr.Ins.CloseUIFormsByType(EUIForms.WuGongUI);
break;
case MainBtnType.Invest:
UIMgr.Ins.CloseUIFormsByType(EUIForms.InvestUI);
break;
case MainBtnType.Battle:
MesMgr.event(EGlobalEvent.GUIDE_HIDE_FINGER);
UIMgr.Ins.CloseUIFormsByType(EUIForms.MainUI);
break;
case MainBtnType.Shop:
UIMgr.Ins.CloseUIFormsByType(EUIForms.ShopUI);
break;
case MainBtnType.Bag:
UIMgr.Ins.CloseUIFormsByType(EUIForms.BagUI);
break;
}
}
reflashButtom() {
this.setMainBtnPoxyInfo(this.btn_GongFa, this.mMainBtnType == MainBtnType.Gongfa);
this.setMainBtnPoxyInfo(this.btn_Invest, this.mMainBtnType == MainBtnType.Invest);
this.setMainBtnPoxyInfo(this.btn_Battle, this.mMainBtnType == MainBtnType.Battle);
this.setMainBtnPoxyInfo(this.btn_Shop, this.mMainBtnType == MainBtnType.Shop);
this.setMainBtnPoxyInfo(this.btn_Bag, this.mMainBtnType == MainBtnType.Bag);
}
private setMainBtnPoxyInfo(tBtn: Button, isSelect: boolean) {
tBtn.node.getComponent(MainBtnPoxy).select(isSelect);
let targetY = isSelect ? 10 : 0;
if (tBtn.node.position.y != targetY) {
tween(tBtn.node).to(0.1, { position: v3(tBtn.node.position.x, targetY) }).start();
}
}
protected update(dt: number): void {
SceneDataMgr.Ins.update(dt);
}
private playNotice(){
const itemsConfig = Global.CsvMgr.Items_csv;
for (const itemId in itemsConfig) {
const item = itemsConfig[itemId];
if (item.quality === QualityType.ORANGE) {
if(item.type >= ITEM_TYPE.GLOVE && item.type <= ITEM_TYPE.ARMOR){
this.mNotice_Weapon.push(item.name);
}else if(item.type === ITEM_TYPE.TALISMAN){
this.mNotice_Treasure.push(item.name)
}else if(item.type === ITEM_TYPE.WUGONG){
this.mNotice_WuXue.push(item.name)
}else if(item.type === ITEM_TYPE.PAINTING){
this.mNotice_Painting.push(item.name)
}
}
}
this.schedule(() => {
if(this.mMainBtnType !== MainBtnType.Gongfa && this.mMainBtnType !== MainBtnType.Bag){
let nickname = "神秘玩家";
const nameidx = MathUtils.randomRangeInt(0, this.mDataMgr.Rank.rankList.length - 1);
if(this.mDataMgr.Rank.rankList[nameidx].nickName !== MainConfig.UserInfo.nick_name){
nickname = this.mDataMgr.Rank.rankList[nameidx].nickName;
}
let noticstr = "";
const notictype = MathUtils.randomRangeInt(0, 3);
switch(notictype){
case 0:{
const idx = MathUtils.randomRangeInt(0, this.mNotice_Weapon.length - 1);
noticstr = `<outline color=black width=3>天道机缘:<color=#FFFFC3>「${nickname}」</c>偶得绝世神武<color=#FFFFC3>【"${this.mNotice_Weapon[idx]}"】</c>!此等神器出世,武林又将掀起波澜!</outline>`;
break;
}
case 1:{
const idx = MathUtils.randomRangeInt(0, this.mNotice_Treasure.length - 1);
noticstr = `<outline color=black width=3>天道机缘:<color=#FFFFC3>「${nickname}」</c>巧得稀世珍宝<color=#FFFFC3>【"${this.mNotice_Treasure[idx]}"】</c>!此等宝物出世,武林又将掀起波澜!</outline>`;
break;
}
case 2:{
const idx = MathUtils.randomRangeInt(0, this.mNotice_WuXue.length - 1);
noticstr = `<outline color=black width=3>天道机缘:<color=#FFFFC3>「${nickname}」</c>领悟旷古神通<color=#FFFFC3>【"${this.mNotice_WuXue[idx]}"】</c>!习得此秘籍,可撼山镇海!</outline>`;
break;
}
default:{
const idx = MathUtils.randomRangeInt(0, this.mNotice_Painting.length - 1);
noticstr = `<outline color=black width=3>小道消息:<color=#FFFFC3>「${nickname}」</c>偶得孤品墨宝<color=#FFFFC3>【"${this.mNotice_Painting[idx]}"】</c>!</outline>`;
break;
}
}
CNodeUtils.setActive(this.n_notice, true);
CNodeUtils.switchRichText(this.ric_notice, noticstr);
const width = this.n_notice.getComponent(UITransform).width - 100;
const w = this.ric_notice.getComponent(UITransform).width;
this.ric_notice.node.setPosition(.5 * width, this.ric_notice.node.position.y);
tween(this.ric_notice.node).to(8, {
position: new Vec3(-(.5 * width + w), this.ric_notice.node.position.y)
}).delay(0.5).call(()=> {
CNodeUtils.setActive(this.n_notice, false);
}).start();
}
}, 300);
}
// 推荐流直出
private feedEnterGame(){
const feed_game_scene = PlatformManager.PlatformInstance.GetFeedType();
// 获客广告,还未正式进入游戏,隐藏底部功能栏
if((feed_game_scene === 0 || feed_game_scene === 3) && !MainConfig.isFeedEnter){
CNodeUtils.setActive(this.n_buttom, false);
}else{
CNodeUtils.setActive(this.n_buttom, this.mDataMgr.Scene.level.monster.fighting);
}
}
}