162 lines
5.2 KiB
TypeScript
162 lines
5.2 KiB
TypeScript
import SKUIUtil from "./gear_2.3.4/util/SKUIUtil";
|
|
import FGUtil from "./gear_2.3.4/fgui/FGUtil";
|
|
import MsgAlert from "./game/msg/MsgAlert";
|
|
import GameModel from "./core/GameModel";
|
|
import Contact from "./contact/Contact";
|
|
import ItemUtil from "./core/ItemUtil";
|
|
import SKDataUtil from "./gear_2.3.4/util/SKDataUtil";
|
|
import GameUtil from "./core/GameUtil";
|
|
const { ccclass, property } = cc._decorator;
|
|
@ccclass
|
|
export default class Debris extends cc.Component {
|
|
/**
|
|
* 單例實例
|
|
*/
|
|
public static Instance: Debris = null;
|
|
|
|
/**
|
|
* 主面板
|
|
*/
|
|
mainPanel: fgui.GComponent = null;
|
|
|
|
goodsList: any = null;
|
|
|
|
selectInfo: any = null;
|
|
onLoad() {
|
|
if (Debris.Instance === null) {
|
|
Debris.Instance = this;
|
|
} else {
|
|
this.destroy();
|
|
return;
|
|
}
|
|
}
|
|
|
|
getGoodsListByType(type: number): any[]{
|
|
let list = []
|
|
if(this.goodsList == null) return list
|
|
for (let index = 0; index < this.goodsList.length; index++) {
|
|
let goods = this.goodsList[index];
|
|
if(goods.type == type){
|
|
list.push(goods)
|
|
}
|
|
}
|
|
return list
|
|
}
|
|
|
|
clickType(){
|
|
let ctrl = FGUtil.getControl(this.mainPanel, "alert/ctr_select")
|
|
let type = ctrl.selectedIndex + 1
|
|
let list = this.getGoodsListByType(type)
|
|
let List = FGUtil.getList(this.mainPanel, "alert/list");
|
|
List.numItems = list.length
|
|
}
|
|
|
|
openShopMainPanel() {
|
|
if (!SKUIUtil.isFGUIValid(this.mainPanel)) {
|
|
this.mainPanel = FGUtil.create("main_ui", "debris_mall_panel_new");
|
|
FGUtil.root().addChild(this.mainPanel);
|
|
this.mainPanel.makeFullScreen();
|
|
GameModel.send("c2s_debris_mall", {})
|
|
}
|
|
|
|
FGUtil.getComponent(this.mainPanel, "mask").onClick(this.closeAll, this);
|
|
FGUtil.getButton(this.mainPanel, "alert/close").onClick(this.closeAll, this);
|
|
FGUtil.getButton(this.mainPanel, "alert/n27").onClick(this.buyBtn, this);
|
|
|
|
let List = FGUtil.getList(this.mainPanel, "alert/list");
|
|
List.itemRenderer = this.initGoodlItem.bind(this);
|
|
// 虛擬列表
|
|
List.setVirtual();
|
|
|
|
let ctrl = FGUtil.getControl(this.mainPanel, "alert/ctr_select")
|
|
ctrl.onChanged(this.clickType, this)
|
|
ctrl.selectedIndex = 0
|
|
this.clickType()
|
|
|
|
var trans: fgui.Transition = this.mainPanel.getTransition("drop");
|
|
trans.play();
|
|
|
|
var topMoney = FGUtil.getComponent(this.mainPanel, "top_money");
|
|
FGUtil.getControl(topMoney, "shopOther").selectedIndex = 1;
|
|
|
|
var otherItem = FGUtil.getButton(topMoney, "shopOther");
|
|
otherItem.icon = `ui://main_ui/8235`;
|
|
var num = ItemUtil.getBagItemCount(70004)
|
|
otherItem.title = `[color=${GameUtil.getNumColorRich(num)}]${num}[/color]`;
|
|
}
|
|
|
|
refreshPanel(list) {
|
|
this.goodsList = list
|
|
// let List = FGUtil.getList(this.mainPanel, "alert/list");
|
|
// List.numItems = this.goodsList.length;
|
|
this.clickType()
|
|
}
|
|
refreshDebrisNum(num) {
|
|
if (!SKUIUtil.isFGUIValid(this.mainPanel)) return;
|
|
FGUtil.getTextField(this.mainPanel, "top_money/shopOther/title").text = `[color=${GameUtil.getNumColorRich(num)}]${num}[/color]`;
|
|
}
|
|
initGoodlItem(idx, obj: fairygui.GObject) {
|
|
let item = obj.asCom;
|
|
|
|
let ctrl = FGUtil.getControl(this.mainPanel, "alert/ctr_select")
|
|
let type = ctrl.selectedIndex + 1
|
|
let list = this.getGoodsListByType(type)
|
|
|
|
cc.log(list[idx])
|
|
var itemData = ItemUtil.getItemData(list[idx].serial);
|
|
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${itemData.icon}`;
|
|
FGUtil.getTextField(item, "name").text = itemData.name;
|
|
FGUtil.getTextField(item, "num").text = `${list[idx].price}`;
|
|
item.node["data"] = itemData;
|
|
|
|
item.onClick(this.clickGoods, this);
|
|
}
|
|
|
|
|
|
showInfo(itemInfo) {
|
|
if (!this.mainPanel || !this.mainPanel.node) {
|
|
console.warn("未找到主面板");
|
|
return;
|
|
}
|
|
|
|
if (itemInfo != null) {
|
|
cc.loader.loadRes("Prefabs/BagItemDetail", cc.Prefab, (err, prefab) => {
|
|
if (err){
|
|
console.log(err)
|
|
return
|
|
}
|
|
if (itemInfo != null) {
|
|
let detail = cc.instantiate(prefab);
|
|
detail.parent = this.mainPanel.node;
|
|
detail.setPosition(this.mainPanel.node.width / 2, -this.mainPanel.node.height / 2)
|
|
detail.name = 'BagItemDetail';
|
|
detail.getComponent('BagItemDetail').loadInfo(itemInfo);
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
clickGoods(e: Event) {
|
|
if (!SKDataUtil.hasProperty(e.target, "data")) return;
|
|
var info = e.target["data"];
|
|
this.selectInfo = info
|
|
this.showInfo(info)
|
|
}
|
|
|
|
buyBtn() {
|
|
if (!this.selectInfo) {
|
|
MsgAlert.addMsg("請先選擇商品");
|
|
return
|
|
}
|
|
GameModel.send("c2s_debris_mall_convert", {
|
|
serial: this.selectInfo.id
|
|
})
|
|
}
|
|
|
|
closeAll() {
|
|
if (SKUIUtil.isFGUIValid(this.mainPanel)) {
|
|
FGUtil.dispose(this.mainPanel)
|
|
this.mainPanel = null
|
|
}
|
|
}
|
|
} |