//#region 文件引入
import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, ToggleContainer, instantiate, Toggle, SpriteFrame, Color } from "cc";
import BaseUIForm from "../../Mgr_UI/BaseUIForm";
import FrameLayout from "../../CComEx/FrameLayout";
import FrameScrollView from "../../CComEx/FrameScrollView";
import { EBagLogType, EBagLogTypeZh, EGongFaType, EGongFaTypeZh, EShopType, EWuGongArrTypeZh, GameTotalType, ITEM_TYPE, NEED_TYPE, PropType, WGMapping } from "../../const/GameEnum";
import { IItems } from "../../Mgr_CSV/CsvEnum";
import { Global } from "../../Global";
import BagListItem_Proxy from "./BagListItem_Proxy";
import MesMgr from "../../MesEvent/MesMgr";
import { EGlobalEvent } from "../../MesEvent/EGlobalEvent";
import { IData, IItemsData } from "../../const/GameInterface";
import { BagDataProxy } from "../../Mgr_LocalData/DataTypeProxy/BagDataProxy";
import UIMgr from "../../Mgr_UI/UIMgr";
import { EUIForms } from "../../const/UIFormCnf";
import { BAG_PARAMS, COLOR_PARAMS } from "../../const/GGameData";
import RoleDataMgr from "../../Mgr_LocalData/RoleDataMgr";
import { Utils } from "../../ExUtils/Utils";
import Language from "../../Language";
import { RedNotice } from "../../Mgr_RedPoint/RedNotice";
import { MainRedEnum } from "../../Mgr_RedPoint/RedEnumType";
import GDUtils from "../../ExCUtils/GDUtils";
//#endregion 文件引入
const {ccclass, property,menu} = _decorator;
@ccclass("BagUI_Proxy")
export default class BagUI_Proxy extends BaseUIForm{
//#region 节点自动生成
@property(Node)
n_GongFa: Node = null;
@property(Sprite)
spr_qbg: Sprite = null;
@property(sp.Skeleton)
spi_gfredlight: sp.Skeleton = null;
@property(Sprite)
spr_qtbg: Sprite = null;
@property(Node)
n_learned: Node = null;
@property(Label)
lab_gongfaName: Label = null;
@property(Label)
lab_gongfaTips: Label = null;
@property(RichText)
ric_need: RichText = null;
@property(Button)
btn_sell: Button = null;
@property(Button)
btn_compose: Button = null;
@property(RichText)
ric_des: RichText = null;
@property(Button)
btn_learn: Button = null;
@property(Button)
btn_exchange: Button = null;
@property(Label)
lab_exchcoin: Label = null;
@property(Node)
n_Weapon: Node = null;
@property(Sprite)
spr_wqbg: Sprite = null;
@property(sp.Skeleton)
spi_wqredlight: sp.Skeleton = null;
@property(Label)
lab_weapon_Name: Label = null;
@property(Label)
lab_weapon_arr: Label = null;
@property(RichText)
ric_weapon_need: RichText = null;
@property(Button)
btn_weapon_sell: Button = null;
@property(Button)
btn_QiangHua: Button = null;
@property(Label)
lab_strrate: Label = null;
@property(Label)
lab_strcoin: Label = null;
@property(Button)
btn_equip: Button = null;
@property(Button)
btn_remove: Button = null;
@property(Label)
lab_tip: Label = null;
@property(Node)
n_SellOnly: Node = null;
@property(Sprite)
spr_oqbg: Sprite = null;
@property(sp.Skeleton)
spi_othredlight: sp.Skeleton = null;
@property(Label)
lab_otherName: Label = null;
@property(Label)
lab_otherTips: Label = null;
@property(Button)
btn_other_sell: Button = null;
@property(Node)
n_emptxt: Node = null;
@property(Node)
n_hline: Node = null;
@property(RichText)
ric_tools: RichText = null;
@property(Label)
lab_expansionNum: Label = null;
@property(Button)
btn_expansion: Button = null;
//#endregion 节点自动生成
@property(ToggleContainer)
private mToggleGroup: ToggleContainer;
@property(FrameScrollView)
protected mScrollViewFrame: FrameScrollView;
@property(FrameLayout)
private mArrStarLayout: FrameLayout;
@property(FrameLayout)
private mStrStarLayout: FrameLayout;
@property({type:[SpriteFrame]})
protected mBgs: SpriteFrame[] = [];
@property({type:[SpriteFrame]})
protected mBgts: SpriteFrame[] = [];
/**需要显示的目标功法 */
private mShowTypes: EBagLogType[] = [EBagLogType.All,EBagLogType.装备,EBagLogType.材料,EBagLogType.典籍,EBagLogType.特殊];
/**当前选择的目标功法类型 */
private mSelectType: EBagLogType;
private mItems: IItemsData[] = [];
private mSelectItem:IItemsData;
private ArrZhNames: string[] = ["上手", "成长", "基础"]
private ArrStarNums: number[] = [];
private canStrength: boolean = true; // 是否可以强化
private BookPartStr: string[] = ["上", "中", "下"];
private mCurStarColor: Color = new Color(0, 0, 0);
onButtonClick(button:Button){
/**点击事件触发*/
switch (button) {
// 出售
case this.btn_sell:
case this.btn_weapon_sell:
case this.btn_other_sell:
const itemcfg = Global.CsvMgr.Items_csv[this.mSelectItem.id];
// 非铜币不打折
const price = (itemcfg.pricetype === 1)? Math.ceil(itemcfg.price / BAG_PARAMS.SELL_DISCOUNT) : itemcfg.price;
// 出售弹出框
UIMgr.Ins.ShowUI(EUIForms.MsgBoxUI,{
param:{
title:"出售提示",
content:"出售后可在商店购回,确认出售吗?",
coininfo: {desc: "出售价格", cointype:itemcfg.pricetype, coin: price},
okcallback:()=>{
if(BagDataProxy.Ins.soldItem(this.mSelectItem)){
this.setTypeList(this.mSelectType, true);
}
}
}
});
break;
// 合成,学习,兑换
case this.btn_learn:
case this.btn_compose:
case this.btn_exchange:
if (BagDataProxy.Ins.useItem(this.mSelectItem)){
this.setTypeList(this.mSelectType, true);
}
break;
// 穿装备
case this.btn_equip:
if (BagDataProxy.Ins.wearItem(this.mSelectItem)){
// this.reflshItemInfo();
this.setSelectConfig(this.mSelectItem);
}
break;
// 卸载装备
case this.btn_remove:
if (BagDataProxy.Ins.takeOffItem(this.mSelectItem)){
this.setSelectConfig(this.mSelectItem);
// this.reflshItemInfo();
}
break;
// 强化
case this.btn_QiangHua:
this.strItem();
break;
// 扩容
case this.btn_expansion:
// 出售弹出框
UIMgr.Ins.ShowUI(EUIForms.PopBgLvUpUI,{
param:{
okcallback:()=>{
if(BagDataProxy.Ins.upLevel()){
this.setTypeList(this.mSelectType, true);
this.refreshBagsizeInfo();
}
}
}
});
break;
default:
ConsoleEx.Log(button);
break;
}
}
addEvent(): void {
MesMgr.on(EGlobalEvent.ITEM_UPDATE, this.reflashScrollView, this);
this.mScrollViewFrame.m_ItemRendererFuntion = this.ItemRenderer.bind(this)
this.mArrStarLayout.m_ItemRendererFuntion = this.ArrItemRender.bind(this)
this.mStrStarLayout.m_ItemRendererFuntion = this.StrItemRender.bind(this)
this.CreateToggle();
}
protected start(): void {
this.setTypeList(EBagLogType.All);
this.refreshBagsizeInfo();
this.refreshRedPoint();
const levelid = this.mDataMgr.Scene.level.id;
// CNodeUtils.setActive(this.btn_sell, levelid > 1);
CNodeUtils.setActive(this.btn_weapon_sell, levelid > 1);
// CNodeUtils.setActive(this.btn_other_sell, levelid > 1);
}
refreshBagsizeInfo(){
CNodeUtils.switchText(this.lab_expansionNum,`容量:${BagDataProxy.Ins.data.items.length}/${BagDataProxy.Ins.data.size}`);
CNodeUtils.setActive(this.btn_expansion, BagDataProxy.Ins.data.level < BAG_PARAMS.MAX_LEVEL);
// 强化工具
const toolsnum = this.mDataMgr.Bag.getItemCountByType(ITEM_TYPE.TOOL);
const desc = toolsnum > 0 ? `拥有${toolsnum}个强化工具` : "拥有0个强化工具";
CNodeUtils.switchRichText(this.ric_tools,desc);
}
reflshItemInfo(){
CNodeUtils.setActive(this.n_GongFa,this.mSelectItem.catalog == EBagLogType.典籍)
CNodeUtils.setActive(this.n_Weapon,this.mSelectItem.catalog == EBagLogType.装备)
CNodeUtils.setActive(this.n_SellOnly,this.mSelectItem.catalog == EBagLogType.特殊 || this.mSelectItem.catalog == EBagLogType.材料)
switch (this.mSelectItem.catalog) {
case EBagLogType.装备:
this.setWeaponPlan();
break;
case EBagLogType.典籍:
this.setDianJiPlan();
break;
case EBagLogType.特殊:
case EBagLogType.材料:
this.setSellOnlyPlan();
break;
default:
break;
}
}
setDianJiPlan(){
const itemcfg = Global.CsvMgr.Items_csv[this.mSelectItem.id];
if(!itemcfg){return;}
this.spr_qbg.spriteFrame = this.mBgs[itemcfg.quality - 1];
const iData:IData = {
type: GameTotalType.ITEM,
id: this.mSelectItem.id,
num:1,
}
CNodeUtils.SwitchTextureByData(this.spr_qbg.node.getChildByName('icon'), iData);
CNodeUtils.switchText(this.lab_gongfaName, itemcfg.desc);
CNodeUtils.setActive(this.ric_need, itemcfg.conditionValue > 0);
CNodeUtils.setActive(this.btn_learn, itemcfg.type == ITEM_TYPE.WUGONG);
CNodeUtils.setActive(this.btn_compose, (itemcfg.type == ITEM_TYPE.WUGONG_PAGE || itemcfg.type == ITEM_TYPE.PAINTING_PAGE));
CNodeUtils.setActive(this.btn_exchange, itemcfg.type == ITEM_TYPE.PAINTING);
// 武功或武功残卷
if(itemcfg.type == ITEM_TYPE.WUGONG || itemcfg.type == ITEM_TYPE.WUGONG_PAGE){
CNodeUtils.setActive(this.spr_qtbg, true);
this.spr_qtbg.spriteFrame = this.mBgts[itemcfg.quality - 1];
const wgid = itemcfg.type == ITEM_TYPE.WUGONG_PAGE? Math.floor(this.mSelectItem.id / 10) : this.mSelectItem.id;
const WuGongCnf = Global.CsvMgr.WuGong_csv[wgid];
if(!WuGongCnf){return;}
this.ArrStarNums = [
WuGongCnf.talent,
WuGongCnf.grow,
WuGongCnf.overAll,
];
this.mArrStarLayout.m_ItemCount = this.ArrZhNames.length;
// 判断是否可以学习武功
let strcondition = "" + itemcfg.conditionValue;
const wgType = WGMapping[itemcfg.condition];
if (!wgType || RoleDataMgr.Ins.attainments[wgType] < itemcfg.conditionValue){
strcondition = "" + itemcfg.conditionValue + "";
}
CNodeUtils.switchText(this.lab_gongfaTips, itemcfg.type == ITEM_TYPE.WUGONG ? "可学会-" + itemcfg.name : "集齐上,中,下可合成完本");
CNodeUtils.switchRichText(this.ric_need, `要求${EWuGongArrTypeZh[itemcfg.condition]}:${strcondition}`);
}else{
// 其他典籍
CNodeUtils.setActive(this.spr_qtbg, false);
const cfgeff = Utils.StringUtils.formatLargeNumber(itemcfg.effect);
CNodeUtils.switchText(this.lab_exchcoin, cfgeff);
CNodeUtils.switchText(this.lab_gongfaTips, itemcfg.type == ITEM_TYPE.PAINTING ? `可兑换铜钱${cfgeff}两` : "集齐上,中,下可合成完本");
}
// 残卷提示文本处理
if(itemcfg.type == ITEM_TYPE.WUGONG_PAGE || itemcfg.type == ITEM_TYPE.PAINTING_PAGE){
let booknumstr = "";
const bookid = Math.floor(itemcfg.id / 10);
for(let i = 1; i <= 3; i++){
const num = this.mDataMgr.Bag.getItemCount(bookid * 10 + i);
booknumstr += (num > 0? `${this.BookPartStr[i - 1]}.`: `${this.BookPartStr[i - 1]}.`);
// this.mPageTxt[i - 1].color = num > 0 ? COLOR_PARAMS.BLACK : COLOR_PARAMS.WHITE;
}
CNodeUtils.switchRichText(this.ric_des, `需要集齐${booknumstr}三本`);
// switch(itemcfg.effect){
// case 1:
// CNodeUtils.switchRichText(this.ric_des, `需要集齐上.中.下.三本`);
// break;
// case 2:
// CNodeUtils.switchRichText(this.ric_des, `需要集齐上.中.下.三本`);
// break;
// case 3:
// CNodeUtils.switchRichText(this.ric_des, `需要集齐上.中.下.三本`)
// }
}
// 武功书处理
const iswgbook = (itemcfg.type == ITEM_TYPE.WUGONG || itemcfg.type == ITEM_TYPE.WUGONG_PAGE);
if(iswgbook){
const bookid = (itemcfg.type == ITEM_TYPE.WUGONG_PAGE)? Math.floor(itemcfg.id / 10) : itemcfg.id;
CNodeUtils.setActive(this.n_learned, RoleDataMgr.Ins.isLearned(bookid));
}else{
CNodeUtils.setActive(this.n_learned, false);
}
// 品质特效
// if(itemcfg.quality === 6){
// CNodeUtils.setActive(this.spi_gfredlight, true);
// this.spi_gfredlight.setAnimation(0, "idle", true);
// }else{
// CNodeUtils.setActive(this.spi_gfredlight, false);
// }
}
setWeaponPlan(){
const itemcfg = Global.CsvMgr.Items_csv[this.mSelectItem.id];
if(!itemcfg){return;}
this.spr_wqbg.spriteFrame = this.mBgs[itemcfg.quality - 1];
const iData:IData = {
type: GameTotalType.ITEM,
id: this.mSelectItem.id,
num:1,
}
CNodeUtils.SwitchTextureByData(this.spr_wqbg.node.getChildByName('icon'), iData);
// 防具默认加内力,其他武器加攻击力
const att_str = itemcfg.type == ITEM_TYPE.ARMOR? ("内力+" + this.mSelectItem.effect) : ("攻击力+" + this.mSelectItem.effect);
CNodeUtils.switchText(this.lab_weapon_Name, itemcfg.desc);
CNodeUtils.switchText(this.lab_weapon_arr, att_str);
// 处理护具装备
let strcondition = "" + itemcfg.conditionValue;
// 根据需求类型判断是否可以装备武器
if (itemcfg.type >= ITEM_TYPE.GLOVE && itemcfg.type <= ITEM_TYPE.KNIFE){
const wgType = WGMapping[itemcfg.condition];
if (!wgType || RoleDataMgr.Ins.attainments[wgType] < itemcfg.conditionValue){
strcondition = "" + itemcfg.conditionValue + "";
}
}else if (itemcfg.type === ITEM_TYPE.ARMOR && (itemcfg.condition !== NEED_TYPE.WUXUE || RoleDataMgr.Ins.wuxue < itemcfg.conditionValue)) {
strcondition = "" + itemcfg.conditionValue + "";
}
CNodeUtils.switchRichText(this.ric_weapon_need, `要求${EWuGongArrTypeZh[itemcfg.condition]}:${strcondition}`);
CNodeUtils.setActive(this.btn_equip, !this.mSelectItem.weared);
CNodeUtils.setActive(this.btn_remove, this.mSelectItem.weared);
// 强化相关 - 根据规则计算星星数量(每5级一个阶段,每个阶段最多5颗星)
const stage = Math.ceil(this.mSelectItem.str_level / 5);
this.mCurStarColor = this.mCurStarColor.fromHEX(GDUtils.GetQualityColorHEX(stage));
const starCount = this.mSelectItem.str_level % 5;
this.mStrStarLayout.m_ItemCount = (starCount == 0 && this.mSelectItem.str_level > 0)? 5 : starCount;
CNodeUtils.setActive(this.btn_QiangHua, this.mSelectItem.str_level < 5 * itemcfg.quality);
CNodeUtils.switchText(this.lab_strrate, `成功率:${this.mDataMgr.Bag.strProbability(this.mSelectItem)}%`);
// 强化成本
const cost = this.strengthenCost();
const success = this.mDataMgr.Token.checkToken(PropType.eGold, cost);
this.lab_strcoin.color = success? COLOR_PARAMS.BLACK : COLOR_PARAMS.RED;
CNodeUtils.switchText(this.lab_strcoin, cost);
// 品质特效
// if(itemcfg.quality === 6){
// CNodeUtils.setActive(this.spi_wqredlight, true);
// this.spi_wqredlight.setAnimation(0, "idle", true);
// }else{
// CNodeUtils.setActive(this.spi_wqredlight, false);
// }
}
setSellOnlyPlan(){
const itemcfg = Global.CsvMgr.Items_csv[this.mSelectItem.id];
if(!itemcfg){return;}
this.spr_oqbg.spriteFrame = this.mBgs[itemcfg.quality - 1];
const iData:IData = {
type: GameTotalType.ITEM,
id: this.mSelectItem.id,
num:1,
}
CNodeUtils.SwitchTextureByData(this.spr_oqbg.node.getChildByName('icon'), iData);
CNodeUtils.switchText(this.lab_otherName, itemcfg.desc);
const ex_str = itemcfg.type == ITEM_TYPE.TOOL? "%" : "";
if(itemcfg.effect){
CNodeUtils.switchText(this.lab_otherTips, (`${Language.getValue(itemcfg.effectDesc)} +${itemcfg.effect}${ex_str}`));
}
else{
CNodeUtils.switchText(this.lab_otherTips, itemcfg.effectDesc);
}
// 品质特效
// if(itemcfg.quality === 6){
// CNodeUtils.setActive(this.spi_othredlight, true);
// this.spi_othredlight.setAnimation(0, "idle", true);
// }else{
// CNodeUtils.setActive(this.spi_othredlight, false);
// }
}
// 上手天赋
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];
}
// 强化星星渲染
private StrItemRender(idx: number, tNode: Node) {
// 根据阶段设置星星颜色(这部分需要根据实际的图片或者颜色设置方法来调整)
const starIcon:Sprite = tNode.getComponent(Sprite);
if (starIcon) {
starIcon.color = this.mCurStarColor;
}
}
private setSelectConfig(item: IItemsData) {
this.mSelectItem = item;
this.mSelectItem && (this.mSelectItem.isnew = false);
this.reflshItemInfo();
this.reflashScrollView();
this.refreshRedPoint(this.mSelectItem.catalog);
}
//#region 拥有的目标功法类型 列表
ItemRenderer(idx: number, tNode: Node) {
const iteminfo = this.mItems[idx];
const itemcfg = Global.CsvMgr.Items_csv[iteminfo.id];
const ClassPoxy: BagListItem_Proxy = tNode.getComponent(BagListItem_Proxy);
// 使用严格相等比较,而不是只比较ID
const isselect = this.mSelectItem === iteminfo;
ClassPoxy.node.name = itemcfg.id.toString();
ClassPoxy.setInfo(itemcfg, iteminfo);
ClassPoxy.setShow(isselect);
CNodeUtils.addBtnComponent(tNode, this.ItemClick.bind(this, iteminfo), this);
}
private ItemClick(item: IItemsData) {
if (this.mSelectItem === item) { return; }
this.setSelectConfig(item);
}
private setTypeList(type: EBagLogType, fouce: boolean = false) {
if (this.mSelectType == type && !fouce) { return; }
this.mSelectType = type;
if (this.mSelectType == EBagLogType.All) {
this.mItems = BagDataProxy.Ins.data.items;
} else {
this.mItems = BagDataProxy.Ins.getItemsByCatalog(type);
}
const itemnum = this.mItems.length;
if (itemnum > 0){
this.setSelectConfig(this.mItems[0]);
}else{
this.mSelectItem = null;
CNodeUtils.setActive(this.n_GongFa, false);
CNodeUtils.setActive(this.n_Weapon, false);
CNodeUtils.setActive(this.n_SellOnly, false);
this.reflashScrollView();
}
CNodeUtils.setActive(this.n_emptxt, itemnum === 0);
CNodeUtils.setActive(this.n_hline, itemnum > 0);
// this.reflashScrollView();
}
private reflashScrollView() {
this.mScrollViewFrame.m_ItemCount = this.mItems.length;
}
//#region 功法Toggle列表
onToggle_ToggleGroup(toggle: Toggle) {
const type = +toggle.node.name;
ConsoleEx.Log("选择了,", type)
this.setTypeList(type);
}
private CreateToggle() {
const ToggleChild = this.mToggleGroup.node.children;
for (let i = 0; i < this.mShowTypes.length; i++) {
const Type = this.mShowTypes[i];
let tNode = ToggleChild[i];
if (!tNode) {
tNode = instantiate(ToggleChild[0]);
tNode.setParent(this.mToggleGroup.node);
tNode.setPosition(0, 0);
tNode.active = true;
}
tNode.name = `${Type}`;
const red = tNode.getChildByName("red");
const title = tNode.getChildByName("title");
const title2 = tNode.getChildByName("Checkmark").getChildByName("title");
CNodeUtils.switchText(title, EBagLogTypeZh[Type]);
CNodeUtils.switchText(title2, EBagLogTypeZh[Type]);
CNodeUtils.setActive(red, this.mDataMgr.Bag.hasNewItem(Type));
}
}
//#endregion
//#region 强化操作
/**
* 计算强化所需费用
* @returns 强化费用
*/
strengthenCost() {
const itemcfg = Global.CsvMgr.Items_csv[this.mSelectItem.id];
// 套装商品,固定使用品质4来计算
const islsshop = Global.CsvMgr.ShopItems_csv[EShopType.灵兽商店].items.includes(this.mSelectItem.id);
const quality = islsshop? 4 : itemcfg.quality;
let cost = 160
// 根据品质倍增费用
for (let i = 1; i < quality; i++) {
cost *= 5
}
return cost;
}
/**
* 强化物品
*/
strItem() {
if (!this.canStrength) return;
// 强化工具检查
if (RoleDataMgr.Ins.craft < 1) {
UIMgr.Ins.ShowTipsUI("缺少工具,前往商店购买");
return;
}
if (!BagDataProxy.Ins.canStrengthen(this.mSelectItem)) {
UIMgr.Ins.ShowTipsUI("强化等级已满");
return;
}
// 消耗检测
const success = this.mDataMgr.Token.checkToken(PropType.eGold, this.strengthenCost());
if (!success) {
UIMgr.Ins.ShowTipsUI("强化失败:铜钱不足!");
return;
}
// 成功则更新进度并进入冷却
this.canStrength = false;
setTimeout(() => {
this.canStrength = true;
}, 200);
const result = BagDataProxy.Ins.tryStrengthen(this.mSelectItem);
this.reflshItemInfo();
if (result) {
// this.playSound_succeed();
UIMgr.Ins.ShowTipsUI("强化成功!");
} else {
// this.playSound_fail();
UIMgr.Ins.ShowTipsUI("强化失败!");
}
}
//#endregion
//#region 刷新红点
refreshRedPoint(catalog:EBagLogType = EBagLogType.All){
if(catalog == EBagLogType.All){
for (let i = 0; i < this.mShowTypes.length; i++) {
let tNode = this.mToggleGroup.node.children[i];
const red = tNode.getChildByName("red");
CNodeUtils.setActive(red, this.mDataMgr.Bag.hasNewItem(this.mShowTypes[i]));
}
}else{
let tNode = this.mToggleGroup.node.children[this.mShowTypes.indexOf(catalog)];
const red = tNode.getChildByName("red");
CNodeUtils.setActive(red, this.mDataMgr.Bag.hasNewItem(catalog));
}
RedNotice.emit(EGlobalEvent.E_RED_UPDATE,[MainRedEnum.包裹]);
}
//#endregion
}