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.
243 lines
10 KiB
243 lines
10 KiB
//#region 文件引入
|
|
import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, SpriteFrame } from "cc";
|
|
import UIParse from "../../Mgr_UI/UIParse";
|
|
import WuGongData from "../../const/WuGongData";
|
|
import { GameTotalType, PropType } from "../../const/GameEnum";
|
|
import UIMgr from "../../Mgr_UI/UIMgr";
|
|
import { EUIForms } from "../../const/UIFormCnf";
|
|
import FrameLayout from "../../CComEx/FrameLayout";
|
|
import { IData } from "../../const/GameInterface";
|
|
import { COLOR_PARAMS } from "../../const/GGameData";
|
|
import StringUtils from "../../ExUtils/StringUtils";
|
|
import { IGongFa } from "../../Mgr_CSV/CsvEnum";
|
|
import { Global } from "../../Global";
|
|
import MesMgr from "../../MesEvent/MesMgr";
|
|
import { EGlobalEvent } from "../../MesEvent/EGlobalEvent";
|
|
//#endregion 文件引入
|
|
const {ccclass, property,menu} = _decorator;
|
|
@ccclass("wugongitem_Proxy")
|
|
export default class wugongitem_Proxy extends UIParse{
|
|
//#region 节点自动生成
|
|
@property(Label)
|
|
lab_Arr_num1: Label = null;
|
|
@property(Label)
|
|
lab_Arr_num2: Label = null;
|
|
@property(Label)
|
|
lab_Arr_num3: Label = null;
|
|
@property(Label)
|
|
lab_NeedCoin: Label = null;
|
|
@property(Button)
|
|
btn_UpArr: Button = null;
|
|
@property(Node)
|
|
n_need: Node = null;
|
|
@property(Label)
|
|
lab_upCondtion: Label = null;
|
|
@property(Node)
|
|
n_red: Node = null;
|
|
@property(Label)
|
|
lab_gongfaName: Label = null;
|
|
@property(Label)
|
|
lab_gongfaLv: Label = null;
|
|
@property(Sprite)
|
|
spr_gfbg: Sprite = null;
|
|
@property(Sprite)
|
|
spr_icon: Sprite = null;
|
|
@property(sp.Skeleton)
|
|
spi_redlight: sp.Skeleton = null;
|
|
@property(Sprite)
|
|
spr_gfpbg: Sprite = null;
|
|
@property(Node)
|
|
n_Select: Node = null;
|
|
//#endregion 节点自动生成
|
|
|
|
@property(FrameLayout)
|
|
private mArrStarLayout: FrameLayout;
|
|
|
|
@property({type:[SpriteFrame]})
|
|
protected mBgs: SpriteFrame[] = [];
|
|
@property({type:[SpriteFrame]})
|
|
protected mBgts: SpriteFrame[] = [];
|
|
|
|
|
|
private mGongFaTypeCnf:IGongFa;
|
|
private ArrZhNames:string[] =["上手","成长","基础"]
|
|
private ArrStarNums:number[]=[];
|
|
private canUpLv:boolean = true;
|
|
private mWGData:WuGongData = null;
|
|
|
|
private isLongPress:boolean = false; // 是否处于长按升级按钮状态
|
|
private duration:number = 0.2; // 长按升级时,触发升级效果的时间间隔
|
|
|
|
onButtonClick(button:Button){
|
|
|
|
/**点击事件触发*/
|
|
switch (button) {
|
|
case this.btn_UpArr:
|
|
if(!this.canUpLv) return;
|
|
this.upLevel();
|
|
// 成功则更新进度并进入冷却
|
|
this.canUpLv = false;
|
|
setTimeout(() => {
|
|
this.canUpLv = true;
|
|
}, 200);
|
|
break;
|
|
default:
|
|
ConsoleEx.Log(button);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
addEvent(): void {
|
|
// MesMgr.on(EGlobalEvent.GONGFA_REFRESH, this.refreshCondition, this);
|
|
this.mArrStarLayout.m_ItemRendererFuntion = this.ArrItemRender.bind(this)
|
|
CNodeUtils.addBtnLongpress(this.btn_UpArr, () => { this.pressDown()}, () => { this.pressUp()});
|
|
}
|
|
|
|
private pressDown(): void {
|
|
this.isLongPress = true;
|
|
this.schedule(() => {
|
|
if(this.isLongPress){
|
|
this.upLevel(true);
|
|
}
|
|
}, this.duration);
|
|
}
|
|
|
|
private pressUp(): void {
|
|
this.isLongPress = false;
|
|
this.unscheduleAllCallbacks();
|
|
}
|
|
|
|
private upLevel(auto:boolean = false): void {
|
|
const result = this.mDataMgr.Role.canUpgrade(this.mWGData.config.type, this.mWGData.id);
|
|
// 可升级
|
|
if(result.res === 0){
|
|
this.mDataMgr.Token.subToken(PropType.eGold, result.data.levelUp_paycoin);
|
|
this.mDataMgr.Role.levelUpWg(this.mWGData);
|
|
this.reflshWugongInfo();
|
|
this.refreshCondition();
|
|
// MesMgr.event(EGlobalEvent.GONGFA_REFRESH);
|
|
}else if(result.res == -1){
|
|
UIMgr.Ins.ShowTipsUI("升级失败,还没学会该功法");
|
|
}else if(result.res == 1){
|
|
// 钱不够,看视频免费升级
|
|
UIMgr.Ins.ShowUI(EUIForms.GongFaUpUI,{param:{
|
|
success:()=>{
|
|
// let wugong = this.mDataMgr.Role.getWugong(this.mWGData.config.type, this.mWGData.id);
|
|
if (this.mWGData) {
|
|
this.mDataMgr.Role.levelUpWg(this.mWGData);
|
|
this.reflshWugongInfo();
|
|
this.refreshCondition();
|
|
// MesMgr.event(EGlobalEvent.GONGFA_REFRESH);
|
|
}
|
|
},
|
|
fail:()=>{
|
|
UIMgr.Ins.ShowTipsUI("升级失败,铜币不足")
|
|
}}});
|
|
}else if(result.res == 2){
|
|
UIMgr.Ins.ShowTipsUI("升级失败,根基不足");
|
|
}
|
|
// 自动升级失败,则取消长按
|
|
if(auto && result.res !== 0){
|
|
this.pressUp();
|
|
}
|
|
}
|
|
|
|
initWGInfo(wginfo:WuGongData): void {
|
|
this.mWGData = wginfo;
|
|
this.mGongFaTypeCnf = Global.CsvMgr.GongFa_csv[this.mWGData.config.type];
|
|
this.spr_gfbg.spriteFrame = this.mBgs[this.mWGData.config.quality - 1];
|
|
this.spr_gfpbg.spriteFrame = this.mBgts[this.mWGData.config.quality - 1];
|
|
const iData:IData = {
|
|
type: GameTotalType.WUGONG,
|
|
id: this.mWGData.config.id,
|
|
num:1,
|
|
}
|
|
CNodeUtils.SwitchTextureByData(this.spr_icon, iData);
|
|
this.refreshCondition();
|
|
this.reflshWugongInfo();
|
|
}
|
|
|
|
// 刷新升级条件
|
|
private refreshCondition(){
|
|
const need = this.mWGData.levelUp_condition > 0;
|
|
CNodeUtils.setActive(this.n_need, need);
|
|
if(need){
|
|
this.lab_upCondtion.color = this.mDataMgr.Role.wuxue >= this.mWGData.levelUp_condition? COLOR_PARAMS.BLACK:COLOR_PARAMS.RED;
|
|
CNodeUtils.switchText(this.lab_upCondtion, this.mWGData.levelUp_condition);
|
|
}
|
|
}
|
|
|
|
// 刷新武功信息
|
|
reflshWugongInfo(){
|
|
// 是否启用
|
|
CNodeUtils.setActive(this.n_Select, this.mWGData.isUseing);
|
|
// 武功天赋值
|
|
this.ArrStarNums = [
|
|
this.mWGData.config.talent,
|
|
this.mWGData.config.grow,
|
|
this.mWGData.config.overAll,
|
|
];
|
|
|
|
this.mArrStarLayout.m_ItemCount = this.ArrZhNames.length;
|
|
// CNodeUtils.setActive(this.n_need, need);
|
|
// if(need){
|
|
// this.lab_upCondtion.color = this.mDataMgr.Role.wuxue >= this.mWGData.levelUp_condition? COLOR_PARAMS.BLACK:COLOR_PARAMS.RED;
|
|
// CNodeUtils.switchText(this.lab_upCondtion, this.mWGData.levelUp_condition);
|
|
// }
|
|
// 等级名字
|
|
CNodeUtils.switchText(this.lab_gongfaLv, `Lv.${this.mWGData.level}`);
|
|
CNodeUtils.switchText(this.lab_gongfaName, this.mWGData.config.name);
|
|
/**基础属性 */
|
|
CNodeUtils.switchText(this.lab_Arr_num1, `${this.mGongFaTypeCnf.key_name} ${this.mWGData.value_keyAtt}`);
|
|
/**属性1 */
|
|
CNodeUtils.switchText(this.lab_Arr_num2, `${this.mGongFaTypeCnf.prop1} +${this.mWGData.attainment}`);
|
|
/**属性2 */
|
|
const haveprop2 = this.mGongFaTypeCnf.prop2 && this.mGongFaTypeCnf.prop2.length > 0;
|
|
CNodeUtils.setActive(this.lab_Arr_num3, haveprop2);
|
|
if (haveprop2) {
|
|
CNodeUtils.switchText(this.lab_Arr_num3, `${this.mGongFaTypeCnf.prop2} +${this.mWGData.attainment}`);
|
|
}
|
|
// 升级消费
|
|
const enough = this.refreshNeedCoin();
|
|
/**红点 */
|
|
const need = this.mWGData.levelUp_condition > 0;
|
|
CNodeUtils.setActive(this.n_red, enough && (!need || this.mDataMgr.Role.wuxue >= this.mWGData.levelUp_condition));
|
|
|
|
|
|
// 品质特效
|
|
// if(this.mWGData.config.quality === 6){
|
|
// CNodeUtils.setActive(this.spi_redlight, true);
|
|
// this.spi_redlight.setAnimation(0, "idle", true);
|
|
// }else{
|
|
// CNodeUtils.setActive(this.spi_redlight, false);
|
|
// }
|
|
}
|
|
|
|
private refreshNeedCoin():boolean{
|
|
const cost = this.mWGData.levelUp_paycoin;
|
|
const enough = this.mDataMgr.Token.checkToken(PropType.eGold, cost);
|
|
this.lab_NeedCoin.color = enough? COLOR_PARAMS.BLACK:COLOR_PARAMS.RED;
|
|
CNodeUtils.switchText(this.lab_NeedCoin, StringUtils.formatLargeNumber(cost));
|
|
return enough;
|
|
}
|
|
|
|
private ArrItemRender(idx:number,tNode:Node){
|
|
const title = tNode.getChildByName("title");
|
|
CNodeUtils.switchText(title, this.ArrZhNames[idx])
|
|
const Layout = tNode.getChildByName("Layout").getComponent(FrameLayout);
|
|
Layout.m_ItemCount = this.ArrStarNums[idx];
|
|
}
|
|
|
|
//#region 刷新红点
|
|
refreshCoin() {
|
|
const enough = this.refreshNeedCoin();
|
|
CNodeUtils.setActive(this.n_red, enough && (this.mDataMgr.Role.wuxue >= this.mWGData.levelUp_condition));
|
|
}
|
|
refreshUseNew(oldwgid:number) {
|
|
if(oldwgid === this.mWGData.id){
|
|
CNodeUtils.setActive(this.n_Select, false);
|
|
}
|
|
}
|
|
//#endregion
|
|
}
|