111 lines
4.1 KiB
TypeScript
111 lines
4.1 KiB
TypeScript
import { _decorator, instantiate, Prefab, UITransform } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { Items } from "../common/config/Items";
|
|
import { Item } from "./Item";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { RewardComp } from "./RewardComp";
|
|
import { SChipComp } from "../hero/SChipComp";
|
|
import { HChipComp } from "../hero/HChipComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('ShopHomeComp')
|
|
@ecs.register('ShopHomeComp', false)
|
|
export class ShopHomeComp extends CCComp {
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
this.get_items();
|
|
}
|
|
get_items(){
|
|
|
|
let goods = this.node.getChildByName("goods").getChildByName("view").getChildByName("content")
|
|
goods.getComponent(UITransform).height=5*200
|
|
console.log("smc.goods",smc.goods)
|
|
let free = goods.getChildByName("free").getChildByName("items");
|
|
let goods1 = goods.getChildByName("goods1").getChildByName("items");
|
|
let herochips = goods.getChildByName("herochips").getChildByName("items");
|
|
let skillchips = goods.getChildByName("skillchips").getChildByName("items");
|
|
for (let x = 0; x < smc.goods.free.length; x++) {
|
|
let item=ecs.getEntity<Item>(Item)
|
|
item.load(smc.goods.free[x].uuid,smc.goods.free[x].num,free)
|
|
}
|
|
for (let x = 0; x < smc.goods.goods1.length; x++) {
|
|
let item=ecs.getEntity<Item>(Item)
|
|
item.load(smc.goods.goods1[x].uuid,smc.goods.goods1[x].num,goods1)
|
|
}
|
|
for (let x = 0; x < smc.goods.herochips.length; x++) {
|
|
let path = "game/gui/hchip";
|
|
let prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
let node = instantiate(prefab);
|
|
node.parent=herochips
|
|
let hc= node.getComponent(HChipComp)
|
|
hc.update_data(smc.goods.herochips[x].uuid,smc.goods.herochips[x].num)
|
|
}
|
|
|
|
for (let x = 0; x < smc.goods.skillchips.length; x++) {
|
|
let path = "game/gui/schip";
|
|
let prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
let node = instantiate(prefab);
|
|
node.parent=skillchips
|
|
let sc= node.getComponent(SChipComp)
|
|
sc.update_data(smc.goods.skillchips[x].uuid,smc.goods.skillchips[x].num)
|
|
}
|
|
// for (let x = 0; x < smc.goods.goods4.length; x++) {
|
|
// let item=ecs.getEntity<Item>(Item)
|
|
// item.load(smc.goods.goods4[x].uuid,smc.goods.goods4[x].num,goods4)
|
|
// }
|
|
|
|
|
|
}
|
|
item_show(e:any,val:any){
|
|
oops.gui.open(UIID.ItemInfo, {uuid:val,type:0});
|
|
}
|
|
get_free(){
|
|
console.log("免费领取")
|
|
if(smc.vmdata.free.buy <= 0){
|
|
oops.gui.toast("今日领取次数已用完");
|
|
return
|
|
}
|
|
smc.vmdata.free.buy--
|
|
}
|
|
get_goods1(){
|
|
console.log("购买商品1")
|
|
if(smc.vmdata.goods1.buy <= 0){
|
|
oops.gui.toast("今日购买次数已用完");
|
|
return
|
|
}
|
|
smc.vmdata.goods1.buy--
|
|
}
|
|
get_goods2(){
|
|
console.log("购买商品2")
|
|
if(smc.vmdata.goods2.buy <= 0){
|
|
oops.gui.toast("今日购买次数已用完");
|
|
return
|
|
}
|
|
smc.vmdata.goods2.buy--
|
|
}
|
|
get_goods3(){
|
|
console.log("购买商品3")
|
|
if(smc.vmdata.goods3.buy <= 0){
|
|
oops.gui.toast("今日购买次数已用完");
|
|
return
|
|
}
|
|
smc.vmdata.goods3.buy--
|
|
}
|
|
get_goods4(){
|
|
console.log("购买商品4")
|
|
if(smc.vmdata.goods4.buy <= 0){
|
|
oops.gui.toast("今日购买次数已用完");
|
|
return
|
|
}
|
|
smc.vmdata.goods4.buy--
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |