811 lines
28 KiB
TypeScript
811 lines
28 KiB
TypeScript
import AudioUtil from "../core/AudioUtil";
|
|
import GameModel from "../core/GameModel";
|
|
import FGUtil from "../gear_2.3.4/fgui/FGUtil";
|
|
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
|
|
import SKLogger from "../gear_2.3.4/util/SKLogger"
|
|
import Transformation from "../transformation/Transformation"
|
|
import PopupManager from "../gear_2.3.4/manager/PopupManager";
|
|
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
|
|
import WingUtil from "../wing/WingUtil";
|
|
import ItemUtil from "../core/ItemUtil";
|
|
import MsgAlert from "../game/msg/MsgAlert";
|
|
import { ESkillQuality } from "../game/skill/core/SkillBase";
|
|
import FGAlert from "../gear_2.3.4/fgui/FGAlert";
|
|
import GameUtil from "../core/GameUtil";
|
|
import Appearance from "../appearance/Appearance";
|
|
import FactionTalent from "../FactionTalent";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
export default class Bag extends cc.Component {
|
|
|
|
/**
|
|
* 背包單例實例
|
|
*/
|
|
public static Instance: Bag = null;
|
|
|
|
/**
|
|
* 背包面板
|
|
*/
|
|
bagPanel: fgui.GComponent = null;
|
|
/**
|
|
*
|
|
*/
|
|
UIRoleNode: cc.Node = null;
|
|
/**
|
|
* 背包物品數據
|
|
*/
|
|
goodsList: any = [];
|
|
/**
|
|
* 選擇的物品下標
|
|
*/
|
|
selectGoodsIdx: number = -1;
|
|
/**
|
|
* 排序方式
|
|
*/
|
|
sortType: number = 0;
|
|
/**
|
|
* 顯示中的裝備id
|
|
*/
|
|
showEquipID: string = "";
|
|
/**
|
|
* 需要加載的預製體
|
|
*/
|
|
prefabObject: any = {};
|
|
|
|
onLoad() {
|
|
if (Bag.Instance === null) {
|
|
Bag.Instance = this;
|
|
this.loadPrefab();
|
|
} else {
|
|
this.destroy();
|
|
return;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 加載預製體
|
|
*/
|
|
loadPrefab() {
|
|
// 加載所需的預製體
|
|
var prefabList = [
|
|
{ url: "Prefabs/UIRole", name: "UIRole" },
|
|
{ url: "Prefabs/SchemePanel", name: "SchemePanel" },
|
|
{ url: "Prefabs/LockerPanel", name: "LockerPanel" },
|
|
{ url: "Prefabs/BagItemDetail", name: "BagItemDetail" },
|
|
{ url: "Prefabs/EquipItemDetail", name: "EquipItemDetail" },
|
|
{ url: "Prefabs/NpcShopUI", name: "NpcShopUI" },
|
|
]
|
|
this.prefabObject = {}
|
|
for (let item of prefabList) {
|
|
cc.loader.loadRes(item.url, cc.Prefab, (err, prefab) => {
|
|
if (err)
|
|
console.warn(err);
|
|
else {
|
|
this.prefabObject[item.name] = prefab;
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
openBagPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) {
|
|
this.bagPanel = FGUtil.create("main_ui", "bag_panel");
|
|
FGUtil.root().addChild(this.bagPanel);
|
|
this.bagPanel.makeFullScreen();
|
|
} else {
|
|
this.showBagPanel();
|
|
return;
|
|
}
|
|
|
|
// 註冊關閉事件
|
|
var mask = FGUtil.getComponent(this.bagPanel, "mask");
|
|
var close = FGUtil.getButton(this.bagPanel, "alert/close");
|
|
this.pushCloseEvent(mask, this.bagPanel, () => { this.goodsList = []; Transformation.Instance.closeTransPanel(); FactionTalent.Instance.closeFCBagPanel(); AudioUtil.playCloseAudio() });
|
|
this.pushCloseEvent(close, this.bagPanel, () => { this.goodsList = []; Transformation.Instance.closeTransPanel(); FactionTalent.Instance.closeFCBagPanel(); AudioUtil.playCloseAudio() });
|
|
|
|
// 套裝按鈕
|
|
// FGUtil.getButton(this.bagPanel, "alert/suit_btn").onClick(this.openSuitPanel, this);
|
|
FGUtil.getButton(this.bagPanel, "alert/suit_btn").visible = false
|
|
|
|
// 外觀按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/n102").onClick(this.openAppearance, this);
|
|
|
|
// 配飾圖鑑按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/library").onClick(this.openLibraryPanel, this);
|
|
|
|
// 顯示倉庫按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/ware_btn").onClick(this.openWarehousePanel, this);
|
|
|
|
// 排序遮罩組件
|
|
FGUtil.getComponent(this.bagPanel, "alert/sort/mask").onClick(this.hideSortPop, this);
|
|
|
|
FGUtil.getList(this.bagPanel, "alert/sort/sort_list").on(fgui.Event.CLICK_ITEM, this.sortDataList, this);
|
|
|
|
// 切換為裝備按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/switchCom/equip").onClick(this.swipeEquip, this);
|
|
|
|
// 切換為配飾按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/switchCom/access").onClick(this.swipeAccess, this);
|
|
|
|
// 配飾套裝技能按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/equip_access/access/suit_skill").onClick(this.clickSuitSkill, this);
|
|
|
|
// 變身卡按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/transCard").onClick(this.openTransCardPanel, this);
|
|
|
|
// 天演符按鈕
|
|
FGUtil.getButton(this.bagPanel, "alert/tianyan").onClick(this.openFactionTalentPanel, this);
|
|
|
|
// 顯示積分貨幣按鈕
|
|
FGUtil.getComponent(this.bagPanel, "top_money/integral").onClick(this.showOtherMoney, this);
|
|
|
|
// 隱藏積分貨幣按鈕
|
|
FGUtil.getComponent(this.bagPanel, "top_money/mask").onClick(this.hideOtherMoney, this);
|
|
|
|
// 兌換積分貨幣按鈕
|
|
FGUtil.getComponent(this.bagPanel, "top_money/other/n10").onClick(this.exchangeScore, this);
|
|
|
|
// 裝評字體和評分
|
|
var EquipScore = FGUtil.getTextField(this.bagPanel, "alert/score");
|
|
EquipScore.font = "xiuweiNum";
|
|
EquipScore.text = this.getEquipScore().toString();
|
|
|
|
// 顯示人物UI
|
|
this.addUIRole();
|
|
|
|
// 設置套裝名稱
|
|
this.setSchemeName();
|
|
|
|
// 刷新頂部貨幣
|
|
this.refreshTopMoney();
|
|
|
|
// 頂部金幣組件動畫
|
|
var trans: fgui.Transition = this.bagPanel.getTransition("drop");
|
|
trans.play();
|
|
|
|
// 設置物品列表初始化方法
|
|
var goodsList = FGUtil.getList(this.bagPanel, "alert/item_list");
|
|
goodsList.itemRenderer = this.initGoodsItem.bind(this);
|
|
// 虛擬列表
|
|
goodsList.setVirtual();
|
|
|
|
this.refreshBagPanel();
|
|
|
|
// GameModel.send('c2s_get_bagitem', {
|
|
// roleid: GameModel.player.roleid
|
|
// });
|
|
|
|
}
|
|
|
|
/**
|
|
* 刷新頂部貨幣
|
|
*/
|
|
refreshTopMoney() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return
|
|
var topMoney = FGUtil.getComponent(this.bagPanel, "top_money");
|
|
FGUtil.getRichTextField(topMoney, "shigong/title").text = `[color=${GameUtil.getNumColorRich(GameModel.player.gameData.bangscore)}]${GameModel.player.gameData.bangscore}[/color]`;
|
|
FGUtil.getRichTextField(topMoney, "yinliang/title").text = `[color=${GameUtil.getNumColorRich(GameModel.player.gameData.money)}]${GameModel.player.gameData.money}[/color]`;
|
|
FGUtil.getRichTextField(topMoney, "xianyu/title").text = `[color=${GameUtil.getNumColorRich(GameModel.player.gameData.jade)}]${GameModel.player.gameData.jade}[/color]`;
|
|
FGUtil.getRichTextField(topMoney, "bangding/title").text = `[color=${GameUtil.getNumColorRich(GameModel.player.gameData.bindjade)}]${GameModel.player.gameData.bindjade}[/color]`;
|
|
FGUtil.getRichTextField(topMoney, "other/score").text = `[color=${GameUtil.getNumColorRich(GameModel.player.gameData.shuilugj)}]${GameModel.player.gameData.shuilugj}[/color]`;
|
|
}
|
|
|
|
showOtherMoney() {
|
|
FGUtil.getControl(this.bagPanel, "top_money/showOther").selectedIndex = 1;
|
|
}
|
|
|
|
hideOtherMoney() {
|
|
FGUtil.getControl(this.bagPanel, "top_money/showOther").selectedIndex = 0;
|
|
}
|
|
|
|
exchangeScore() {
|
|
var NpcShopUI = cc.instantiate(this.prefabObject["NpcShopUI"]);
|
|
NpcShopUI.parent = cc.find('Canvas/MainUI');
|
|
let comUI = NpcShopUI.getComponent('NpcShopUI');
|
|
comUI.nNpcConfigID = 10242;// 魏徵id
|
|
this.closeBagPanel();
|
|
}
|
|
|
|
/**
|
|
* 初始化物品項目
|
|
*/
|
|
initGoodsItem(idx, obj: fairygui.GObject) {
|
|
var item = obj.asCom;
|
|
var info = this.goodsList[idx];
|
|
|
|
FGUtil.getControl(item, "type").selectedIndex = info.type;
|
|
FGUtil.getControl(item, "mask").selectedIndex = 0;
|
|
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
|
FGUtil.getTextField(item, "title").text = "";
|
|
if (info.type == 0) {
|
|
// 如果是道具
|
|
let data = ItemUtil.getItemData(info.itemid);
|
|
// 未找到該道具信息
|
|
if (data == null) {
|
|
FGUtil.getLoader(item, "icon").texture = ItemUtil.getItemIcon("1000");
|
|
return;
|
|
}
|
|
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${data.icon}`;
|
|
FGUtil.getTextField(item, "title").text = SKDataUtil.transform(info.count);
|
|
item.node["info"] = data;
|
|
} else if (info.type == 1) {
|
|
// 如果是裝備
|
|
var data = info.info;
|
|
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${data.Shape}`;
|
|
if (ItemUtil.isBaldric(data.EIndex)) {
|
|
FGUtil.getControl(item, "grade").selectedIndex = data.Grade;
|
|
FGUtil.getTextField(item, "title").text = data.Grade.toString();
|
|
if (data.flag == 1 || data.BaseAttr == "[]") {
|
|
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
|
FGUtil.getControl(item, "mask").selectedIndex = 1;
|
|
FGUtil.getTextField(item, "title").text = "";
|
|
}
|
|
}
|
|
else {
|
|
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
|
FGUtil.getTextField(item, "title").text = data.Grade.toString();
|
|
}
|
|
item.node["info"] = data;
|
|
} else if (info.type == 2) {
|
|
// 如果是解鎖
|
|
item.node["info"] = "locker";
|
|
} else if (info.type == 3) {
|
|
// 空
|
|
}
|
|
// 是否選中
|
|
FGUtil.getControl(item, "selected").selectedIndex = this.selectGoodsIdx == idx ? 1 : 0;
|
|
|
|
// 點擊後獲取的信息
|
|
item.node["type"] = info.type;
|
|
item.node["idx"] = idx;
|
|
|
|
item.onClick(this.clickGoodsItem, this);
|
|
}
|
|
|
|
/**
|
|
* 點擊背包物品
|
|
*/
|
|
clickGoodsItem(e: Event, id: number = 0) {
|
|
if (!SKDataUtil.hasProperty(e.target, "idx") || !SKDataUtil.hasProperty(e.target, "type") || !SKDataUtil.hasProperty(e.target, "info"))
|
|
return;
|
|
var idx, type, info;
|
|
idx = e.target["idx"];
|
|
type = e.target["type"];
|
|
info = e.target["info"];
|
|
|
|
// 空物品不可選中
|
|
if (type == 3) return;
|
|
this.selectGoodsIdx = idx;
|
|
var goodsList = FGUtil.getList(this.bagPanel, "alert/item_list");
|
|
goodsList.refreshVirtualList();
|
|
|
|
if (type == 0) {
|
|
this.showGoodsItemDetail(info);
|
|
} else if (type == 1) {
|
|
this.showEquipItemDetail(info);
|
|
} else if (type == 2) {
|
|
this.unlockBagContent();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 顯示物品詳細
|
|
*/
|
|
showGoodsItemDetail(info: any = null) {
|
|
if (info != null && this.prefabObject["BagItemDetail"] != null) {
|
|
let pNode = this.bagPanel.node;
|
|
if (pNode.getChildByName('BagItemDetail') == null) {
|
|
let detail = cc.instantiate(this.prefabObject["BagItemDetail"]);
|
|
detail.parent = pNode;
|
|
detail.setPosition(this.bagPanel.width / 2, -this.bagPanel.height / 2)
|
|
detail.name = 'BagItemDetail';
|
|
detail.getComponent('BagItemDetail').loadInfo(info);
|
|
detail.getComponent('BagItemDetail').showOperation();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 顯示穿戴的裝備詳細
|
|
*/
|
|
showWearEquip(e: Event) {
|
|
if (!SKDataUtil.hasProperty(e.target, "info"))
|
|
return;
|
|
var info = e.target["info"];
|
|
if (info)
|
|
this.showEquipItemDetail(info);
|
|
}
|
|
|
|
/**
|
|
* 顯示裝備詳細
|
|
*/
|
|
showEquipItemDetail(info: any = null) {
|
|
if (info != null && this.prefabObject["EquipItemDetail"] != null) {
|
|
if (ItemUtil.isBaldric(info.EIndex)) {
|
|
ItemUtil.showMenu = true;
|
|
ItemUtil.showAccessDetail(info);
|
|
return;
|
|
}
|
|
this.showEquipID = info.EquipID;
|
|
let pNode = this.bagPanel.node;
|
|
if (pNode.getChildByName('EquipItemDetail') == null) {
|
|
let detail = cc.instantiate(this.prefabObject["EquipItemDetail"]);
|
|
detail.parent = pNode;
|
|
detail.setPosition(this.bagPanel.width / 2, this.bagPanel.height / 2)
|
|
detail.name = "EquipItemDetail";
|
|
detail.getComponent("EquipItemDetail").loadInfo(info);
|
|
// detail.getComponent("EquipItemDetail").showOperation();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 獲取裝備數據後刷新
|
|
* @param info 裝備數據
|
|
* @returns
|
|
*/
|
|
public refreshEquipItenDetail(info: any = null) {
|
|
cc.log("調試輸出裝備信息info..................", info)
|
|
if (info.EquipID != this.showEquipID) return;
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
let detail = this.bagPanel.node.getChildByName('EquipItemDetail');
|
|
if (detail != null) {
|
|
detail.getComponent("EquipItemDetail").loadInfo(info);
|
|
detail.getComponent("EquipItemDetail").showOperation();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 解鎖背包容量
|
|
*/
|
|
unlockBagContent() {
|
|
var iconId = "", priceStr = "", color = "FF74FF";
|
|
if (GameModel.player.bagKindNum > 65) {
|
|
iconId = "9004";
|
|
priceStr = "500";
|
|
} else {
|
|
iconId = "90001";
|
|
var price = (((GameModel.player.bagKindNum - 50) / 5 * 500 + 500) * 50).toString();
|
|
priceStr = `[color=#${color}]${price}[/color]`;
|
|
}
|
|
FGAlert.show(`是否花費[img]ui://main_ui/${iconId}[/img]${priceStr}開啟5個格子?`, () => {
|
|
FGAlert.hide();
|
|
}, () => {
|
|
FGAlert.hide();
|
|
GameModel.send("c2c_open_backpack_grid", {
|
|
roleId: GameModel.player.roleid
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 刷新渲染背包
|
|
*/
|
|
public refreshBagPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
// 渲染穿戴裝備
|
|
this.refreshEquip();
|
|
// 渲染穿戴配飾
|
|
this.refreshAccess();
|
|
// 渲染背包物品
|
|
this.refreshGoods();
|
|
}
|
|
|
|
/**
|
|
* 渲染穿戴裝備
|
|
*/
|
|
private refreshEquip() {
|
|
var hasWing = false;
|
|
var equipBox = FGUtil.getComponent(this.bagPanel, "alert/equip_access/equip");
|
|
for (var i = 0; i < 6; i++) {
|
|
var equipId = GameModel.equipData.use[i + 1];
|
|
var equipItem = equipBox.getChildAt(i).asCom;
|
|
if (equipId && GameModel.equipData.info[equipId]) {
|
|
var data = GameModel.equipData.info[equipId];
|
|
cc.log("調試輸出裝備信息..................", data)
|
|
if (data.Grade == 5 && data.GemCnt >= 18) {
|
|
FGUtil.getComponent(equipItem, "n5").visible = true;
|
|
FGUtil.getComponent(equipItem, "n2").visible = true;
|
|
FGUtil.getComponent(equipItem, "n6").visible = true;
|
|
FGUtil.getComponent(equipItem, "n7").visible = true;
|
|
}
|
|
if (data.EquipType == 3) {
|
|
FGUtil.getComponent(equipItem, "n2").visible = true;
|
|
FGUtil.getComponent(equipItem, "n6").visible = true;
|
|
}
|
|
FGUtil.getControl(equipItem, "isWear").selectedIndex = 1;
|
|
FGUtil.getLoader(equipItem, "icon").url = `ui://main_ui/${data.Shape}`;
|
|
if (data.EIndex == 6) {
|
|
hasWing = true;
|
|
var wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", data.Shape, "id", 0);
|
|
WingUtil.playAni(this.UIRoleNode, GameModel.player.resid, 1, "stand", 0, wingId);
|
|
}
|
|
equipItem.node['info'] = data;
|
|
equipItem.onClick(this.showWearEquip, this);
|
|
} else {
|
|
FGUtil.getComponent(equipItem, "n5").visible = false;
|
|
FGUtil.getComponent(equipItem, "n2").visible = false;
|
|
FGUtil.getComponent(equipItem, "n6").visible = false;
|
|
FGUtil.getComponent(equipItem, "n7").visible = false;
|
|
FGUtil.getControl(equipItem, "isWear").selectedIndex = 0;
|
|
equipItem.clearClick();;
|
|
}
|
|
}
|
|
if (!hasWing) {
|
|
WingUtil.playAni(this.UIRoleNode, GameModel.player.resid, 1, "stand", 0, 0);
|
|
}
|
|
|
|
// 刷新裝備分數
|
|
var EquipScore = FGUtil.getTextField(this.bagPanel, "alert/score");
|
|
if (EquipScore)
|
|
EquipScore.text = this.getEquipScore().toString();
|
|
}
|
|
|
|
/**
|
|
* 渲染穿戴配飾
|
|
*/
|
|
private refreshAccess() {
|
|
var accessBox = FGUtil.getComponent(this.bagPanel, "alert/equip_access/access");
|
|
for (var i = 0; i < 6; i++) {
|
|
var accessId = GameModel.equipData.use[i + 7];
|
|
var accessItem = accessBox.getChildAt(i).asCom;
|
|
if (accessId && GameModel.equipData.info[accessId]) {
|
|
var data = GameModel.equipData.info[accessId];
|
|
FGUtil.getControl(accessItem, "isWear").selectedIndex = 1;
|
|
FGUtil.getLoader(accessItem, "icon").url = `ui://main_ui/${data.Shape}`;
|
|
accessItem.node['info'] = data;
|
|
accessItem.onClick(this.showWearEquip, this);
|
|
} else {
|
|
FGUtil.getControl(accessItem, "isWear").selectedIndex = 0;
|
|
accessItem.clearClick();
|
|
}
|
|
}
|
|
|
|
var suitSkill = ItemUtil.getBaldricSuitSkill();
|
|
if (suitSkill) {
|
|
// 這一部分是錯誤的,穿戴的時候再進行提示
|
|
// MsgAlert.addMsg(`您已激活套裝技能 [img]ui://main_ui/${suitSkill.icon}[/img][color=#00FF7F]【${suitSkill.name.split(".")[0]}】[/color]!`);
|
|
FGUtil.getControl(this.bagPanel, "alert/equip_access/access/showSuitSkill").selectedIndex = 1;
|
|
var suitSkillItem = FGUtil.getComponent(this.bagPanel, "alert/equip_access/access/suit_skill");
|
|
var suitLevel = suitSkill.quality == ESkillQuality.LOW ? 1 : suitSkill.quality == ESkillQuality.HIGH ? 2 : suitSkill.quality == ESkillQuality.FINAL ? 3 : 0
|
|
FGUtil.getControl(suitSkillItem, "suit_grade").selectedIndex = suitLevel;
|
|
FGUtil.getLoader(suitSkillItem, "icon").texture = ItemUtil.getItemIcon(suitSkill.icon)
|
|
FGUtil.getTextField(suitSkillItem, "title").text = '';
|
|
} else {
|
|
FGUtil.getControl(this.bagPanel, "alert/equip_access/access/showSuitSkill").selectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 整理背包物品數據
|
|
*/
|
|
private arrangeGoods(sortType: number = 0) {
|
|
var list = [];
|
|
if (sortType < 2) {
|
|
// 自然排序 裝備優先
|
|
this.arrangeEquipData(list);
|
|
this.arrangeItemData(list);
|
|
} else if (sortType == 2) {
|
|
// 其他優先
|
|
this.arrangeItemData(list);
|
|
this.arrangeEquipData(list);
|
|
} else if (sortType == 3) {
|
|
// 五行優先
|
|
this.arrangeItemData(list, 3);
|
|
this.arrangeEquipData(list);
|
|
} else if (sortType == 4) {
|
|
// 寶石優先
|
|
this.arrangeItemData(list, 4);
|
|
this.arrangeEquipData(list);
|
|
} else if (sortType == 5) {
|
|
// 技能優先
|
|
this.arrangeItemData(list, 5);
|
|
this.arrangeEquipData(list);
|
|
} else if (sortType == 6) {
|
|
// 藥品優先
|
|
this.arrangeItemData(list, 6);
|
|
this.arrangeEquipData(list);
|
|
} else {
|
|
// 未知
|
|
this.arrangeEquipData(list);
|
|
this.arrangeItemData(list);
|
|
}
|
|
|
|
// 補足空格子
|
|
let empty = GameModel.player.bagKindNum - list.length;
|
|
if (empty > 0) {
|
|
for (var k = 0; k < empty; k++) {
|
|
let info = {
|
|
type: 3
|
|
}
|
|
list.push(info);
|
|
}
|
|
}
|
|
|
|
// 上鎖格子
|
|
for (var i = 0; i < 5; i++) {
|
|
let info = {
|
|
type: 2
|
|
}
|
|
list.push(info);
|
|
}
|
|
|
|
this.goodsList = list;
|
|
if (list.length > GameModel.player.bagKindNum + 5) {
|
|
console.warn("背包數據長度錯誤");
|
|
}
|
|
}
|
|
|
|
private arrangeEquipData(list: any = []) {
|
|
var equipData = GameModel.equipData;
|
|
for (const equip of equipData.list) {
|
|
if (equipData.info[equip]) {
|
|
let info = {
|
|
itemid: equip,
|
|
info: GameModel.equipData.info[equip],
|
|
type: 1
|
|
};
|
|
list.push(info);
|
|
}
|
|
}
|
|
}
|
|
private arrangeItemData(list: any = [], sortType: number = 0) {
|
|
var tempList = [];
|
|
var itemList = GameModel.player.itemList;
|
|
for (var itemId in itemList) {
|
|
var count = SKDataUtil.valueForKey(GameModel.player.itemList, itemId);
|
|
if (count != null && count > 0) {
|
|
// 跳過不存在道具
|
|
if (!ItemUtil.getItemData(itemId)) continue;
|
|
// 跳過變身卡和變身卡升級道具
|
|
if (ItemUtil.getItemData(itemId).type == 15) continue;
|
|
if (ItemUtil.getItemData(itemId).type == 18) continue;
|
|
if (ItemUtil.getItemData(itemId).type == 19) continue;
|
|
if (parseInt(itemId) >= 1003010 && parseInt(itemId) <= 1003100) continue;
|
|
// 跳過天策符
|
|
if (parseInt(itemId) >= 100320 && parseInt(itemId) <= 100323) continue;
|
|
|
|
let info = {
|
|
itemid: itemId,
|
|
count: count,
|
|
type: 0
|
|
};
|
|
|
|
if (sortType > 2) {
|
|
// 特殊排序
|
|
var classify = ItemUtil.getItemData(itemId).classify;
|
|
if (classify == sortType - 1)
|
|
list.push(info);
|
|
else
|
|
tempList.push(info);
|
|
}
|
|
else
|
|
list.push(info);
|
|
}
|
|
}
|
|
if (sortType > 2)
|
|
list.push.apply(list, tempList)
|
|
}
|
|
|
|
/**
|
|
* 渲染背包物品
|
|
*/
|
|
private refreshGoods(sortType: number = this.sortType) {
|
|
this.arrangeGoods(sortType);
|
|
var goodsList = FGUtil.getList(this.bagPanel, "alert/item_list");
|
|
goodsList.numItems = this.goodsList.length;
|
|
}
|
|
|
|
/**
|
|
* 顯示背包面板(需要打開過背包並且是隱藏的)
|
|
*/
|
|
showBagPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
this.bagPanel.visible = true;
|
|
FGUtil.getControl(this.bagPanel, "alert/transTap").selectedIndex = 0;
|
|
}
|
|
|
|
/**
|
|
* 隱藏背包面板
|
|
*/
|
|
hideBagPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
this.bagPanel.visible = false;
|
|
}
|
|
|
|
/**
|
|
* 關閉背包面板
|
|
*/
|
|
closeBagPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
FGUtil.dispose(this.bagPanel)
|
|
this.bagPanel = null;
|
|
this.goodsList = [];
|
|
}
|
|
|
|
/**
|
|
* 變身卡/天演符打開背包
|
|
*/
|
|
openBagPanelByTrans() {
|
|
if (SKUIUtil.isFGUIValid(this.bagPanel)) {
|
|
this.bagPanel.visible = true;
|
|
FGUtil.getControl(this.bagPanel, "alert/transTap").selectedIndex = 0;
|
|
return;
|
|
}
|
|
this.openBagPanel();
|
|
}
|
|
|
|
|
|
/**
|
|
* 打開套裝編輯面板
|
|
*/
|
|
openSuitPanel() {
|
|
this.hideBagPanel();
|
|
if (this.prefabObject["SchemePanel"] == null) return;
|
|
var schemePanel = cc.instantiate(this.prefabObject["SchemePanel"]);
|
|
schemePanel.parent = cc.find('Canvas/MainUI');
|
|
}
|
|
|
|
/**
|
|
* 打開外觀
|
|
*/
|
|
openAppearance() {
|
|
this.hideBagPanel();
|
|
Appearance.Instance.openAppearancePanel();
|
|
}
|
|
|
|
/**
|
|
* 打開配飾圖鑑面板
|
|
*/
|
|
openLibraryPanel() {
|
|
this.hideBagPanel();
|
|
var url = `Prefabs/Accessory/AccessorySuit`;
|
|
cc.loader.loadRes(url, cc.Prefab, (error, prefab) => {
|
|
if (error) {
|
|
SKLogger.warn(`$警告:加載資源${url}錯誤!`);
|
|
return;
|
|
}
|
|
PopupManager.showView(prefab);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 打開倉庫面板
|
|
*/
|
|
openWarehousePanel() {
|
|
this.hideBagPanel();
|
|
var canvas = cc.find('Canvas');
|
|
if (!canvas.getChildByName('LockerPanel')) {
|
|
if (this.prefabObject["LockerPanel"] == null) return;
|
|
var locker = cc.instantiate(this.prefabObject["LockerPanel"]);
|
|
locker.parent = canvas;
|
|
locker.name = 'LockerPanel';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 顯示排序彈框
|
|
*/
|
|
hideSortPop() {
|
|
FGUtil.getControl(this.bagPanel, "alert/showSortView").selectedIndex = 0;
|
|
}
|
|
|
|
/**
|
|
* 滑動至裝備
|
|
*/
|
|
swipeEquip() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
FGUtil.getComponent(this.bagPanel, "alert/library").visible = false;
|
|
var trans: fgui.Transition = FGUtil.getComponent(this.bagPanel, "alert/switchCom").getTransition("toLeft");
|
|
trans.play();
|
|
var pageCom = FGUtil.getComponent(this.bagPanel, "alert/equip_access");
|
|
var scroll = pageCom.scrollPane;
|
|
scroll.setCurrentPageX(0, true);
|
|
}
|
|
|
|
/**
|
|
* 滑動至配飾
|
|
*/
|
|
swipeAccess() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
// 配飾圖鑑按鈕
|
|
FGUtil.getComponent(this.bagPanel, "alert/library").visible = true;
|
|
|
|
var trans: fgui.Transition = FGUtil.getComponent(this.bagPanel, "alert/switchCom").getTransition("toRight");
|
|
trans.play();
|
|
|
|
var pageCom = FGUtil.getComponent(this.bagPanel, "alert/equip_access");
|
|
var scroll: fairygui.ScrollPane = pageCom.scrollPane;
|
|
scroll.setCurrentPageX(1, true);
|
|
}
|
|
|
|
/**
|
|
* 添加人物UI
|
|
*/
|
|
addUIRole() {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel) || this.prefabObject["UIRole"] == null) return;
|
|
var roleNode = cc.instantiate(this.prefabObject["UIRole"]);
|
|
roleNode.setPosition(0, 0);
|
|
roleNode.scale = 0.765
|
|
roleNode.parent = FGUtil.getComponent(this.bagPanel, "alert/role").node;
|
|
roleNode.getComponent("UIRole").setInfo(GameModel.player);
|
|
this.UIRoleNode = roleNode;
|
|
}
|
|
|
|
/**
|
|
* 設置套裝名稱
|
|
*/
|
|
setSchemeName() {
|
|
if (GameModel.player.schemename && GameModel.player.schemename != '') {
|
|
if (!SKUIUtil.isFGUIValid(this.bagPanel)) return;
|
|
FGUtil.getTextField(this.bagPanel, "alert/suit_btn/title").text = GameModel.player.schemename;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 獲取裝評
|
|
* @returns 裝備評分
|
|
*/
|
|
getEquipScore() {
|
|
var score = 0;
|
|
if (GameModel.equipData) {
|
|
score = GameModel.equipData.score;
|
|
if (!score) {
|
|
score = 0;
|
|
}
|
|
return score;
|
|
}
|
|
return score;
|
|
}
|
|
/**
|
|
* 點擊配飾套裝技能
|
|
*/
|
|
clickSuitSkill(event: Event) {
|
|
ItemUtil.showSuitSkill(ItemUtil.suitId)
|
|
}
|
|
|
|
/**
|
|
* 背包排序
|
|
*/
|
|
sortDataList(item: fgui.GObject) {
|
|
var sortList = FGUtil.getList(this.bagPanel, "alert/sort/sort_list");
|
|
let index = sortList.getChildIndex(item);
|
|
this.refreshGoods(index);
|
|
this.hideSortPop();
|
|
}
|
|
|
|
/**
|
|
* 打開變身卡
|
|
*/
|
|
openTransCardPanel() {
|
|
AudioUtil.playFenyeAudio();
|
|
Transformation.Instance.openTransPanelByBag();
|
|
this.hideBagPanel();
|
|
}
|
|
|
|
/**
|
|
* 打開天演符
|
|
*/
|
|
openFactionTalentPanel() {
|
|
AudioUtil.playFenyeAudio();
|
|
FactionTalent.Instance.openFcBagByOther();
|
|
this.hideBagPanel();
|
|
}
|
|
|
|
/**
|
|
* 添加關閉事件
|
|
*/
|
|
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
|
|
if (!item) {
|
|
console.error("未找到節點");
|
|
return;
|
|
}
|
|
item.clearClick();
|
|
item.onClick(() => {
|
|
call && call()
|
|
FGUtil.dispose(target);
|
|
target = null;
|
|
}, this)
|
|
}
|
|
}
|