dd
This commit is contained in:
2136
assets/resources/game/gui/goods.prefab
Normal file
2136
assets/resources/game/gui/goods.prefab
Normal file
File diff suppressed because it is too large
Load Diff
13
assets/resources/game/gui/goods.prefab.meta
Normal file
13
assets/resources/game/gui/goods.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "40d09ceb-c810-48fc-9264-1398cbfd5e8a",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "goods"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.2 MiB |
File diff suppressed because it is too large
Load Diff
@@ -54,13 +54,9 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
9005:{uuid:9005,lv:2,exp:0,slv:1,stone:0,num:80,x1:2,x10:0},
|
||||
9006:{uuid:9006,lv:3,exp:0,slv:2,stone:0,num:90,x1:3,x10:0},
|
||||
};
|
||||
goods:any={
|
||||
free: [ {uuid:9001,num:100000}, {uuid:9003,num:500}],
|
||||
goods1:[ {uuid:9003,num:1} ],
|
||||
herochips:[ {uuid:9001,num:2}, {uuid:9002,num:1} ],
|
||||
skillchips:[ {uuid:1001,num:100}, {uuid:1002,num:1} ],
|
||||
goods4:[ {uuid:9001,num:100}, {uuid:9002,num:1} ],
|
||||
};
|
||||
goods:any=[
|
||||
{uuid:9001,num:100000,type:0,cost:0,inventory:99},
|
||||
];
|
||||
items:any={
|
||||
1001:{uuid:1001,num:10,x1:1,x10:0},
|
||||
1002:{uuid:1002,num:10,x1:0,x10:0},
|
||||
|
||||
30
assets/script/game/map/Goods.ts
Normal file
30
assets/script/game/map/Goods.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { instantiate, Prefab } from "cc";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { GoodsComp } from "./GoodsComp";
|
||||
|
||||
/** Goods 模块 */
|
||||
@ecs.register(`Goods`)
|
||||
export class Goods extends ecs.Entity {
|
||||
|
||||
/** 实始添加的数据层组件 */
|
||||
protected init() {
|
||||
// this.addComponents<ecs.Comp>();
|
||||
}
|
||||
|
||||
load(smc_index:number,praent:any){
|
||||
var path = "game/gui/goods";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = praent
|
||||
let gc = node.getComponent(GoodsComp)!;
|
||||
gc.smc_index = smc_index
|
||||
gc.update_data()
|
||||
this.add(gc)
|
||||
}
|
||||
/** 模块资源释放 */
|
||||
destroy() {
|
||||
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/map/Goods.ts.meta
Normal file
9
assets/script/game/map/Goods.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "31a2bcbb-10ac-4a10-b6cf-dd1991e30f4d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
62
assets/script/game/map/GoodsComp.ts
Normal file
62
assets/script/game/map/GoodsComp.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { _decorator, instantiate, Label, Prefab } 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 { smc } from "../common/SingletonModuleComp";
|
||||
import { Item } from "./Item";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { HChipComp } from "../hero/HChipComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('GoodsComp')
|
||||
@ecs.register('GoodsComp', false)
|
||||
export class GoodsComp extends CCComp {
|
||||
type:number=0;
|
||||
g_uuid:number=0;
|
||||
num:number=0;
|
||||
inventory:number=0;
|
||||
cost:number=0;
|
||||
smc_index:number=0;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
}
|
||||
update_data(){
|
||||
let goods:any=smc.goods[this.smc_index]
|
||||
let gnode=this.node.getChildByName("item")
|
||||
switch (goods.type) {
|
||||
case 0:
|
||||
let item=ecs.getEntity<Item>(Item)
|
||||
item.load(goods.uuid,goods.num,gnode)
|
||||
this.node.getChildByName("inventory").getComponent(Label).string="库存:"+goods.inventory.toString()
|
||||
console.log("item",item)
|
||||
break;
|
||||
case 1:
|
||||
let path = "game/gui/hchip";
|
||||
let prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
let node = instantiate(prefab);
|
||||
node.parent=gnode
|
||||
let hc= node.getComponent(HChipComp)
|
||||
hc.update_data(goods.uuid,goods.num)
|
||||
break
|
||||
}
|
||||
if(goods.cost > 0){
|
||||
this.node.getChildByName("free").active=false
|
||||
this.node.getChildByName("buy").getChildByName("cost").getComponent(Label).string=goods.cost.toString()
|
||||
}else{
|
||||
this.node.getChildByName("free").active=true
|
||||
}
|
||||
}
|
||||
buy(){
|
||||
console.log("购买商品"+this.smc_index)
|
||||
}
|
||||
update_inventory(){
|
||||
this.node.getChildByName("inventory").getComponent(Label).string="库存:"+smc.goods[this.smc_index].inventory
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/map/GoodsComp.ts.meta
Normal file
9
assets/script/game/map/GoodsComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bbc0aec1-65da-473d-aff0-1b15312c912a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { smc } from "../common/SingletonModuleComp";
|
||||
import { RewardComp } from "./RewardComp";
|
||||
import { SChipComp } from "../hero/SChipComp";
|
||||
import { HChipComp } from "../hero/HChipComp";
|
||||
import { Goods } from "./Goods";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -21,133 +22,13 @@ export class ShopHomeComp extends CCComp {
|
||||
this.get_items();
|
||||
}
|
||||
get_items(){
|
||||
|
||||
let goods = this.node.getChildByName("goods").getChildByName("view").getChildByName("content")
|
||||
goods.getComponent(UITransform).height=5*200
|
||||
let goodsnode = this.node.getChildByName("goods").getChildByName("view").getChildByName("content")
|
||||
goodsnode.getComponent(UITransform).height=Math.floor(smc.goods.length/4*240)+50
|
||||
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.length; x++) {
|
||||
let goods=ecs.getEntity<Goods>(Goods)
|
||||
goods.load(x,goodsnode)
|
||||
}
|
||||
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
|
||||
}
|
||||
for (let x = 0; x < smc.goods.free.length; x++) {
|
||||
if(smc.goods.free[x].uuid ==9001){
|
||||
smc.vmdata.gold.num+=smc.goods.free[x].num
|
||||
}
|
||||
if(smc.goods.free[x].uuid ==9003){
|
||||
smc.vmdata.exp.num+=smc.goods.free[x].num
|
||||
}
|
||||
if(smc.goods.free[x].uuid < 9000){
|
||||
smc.items[smc.goods.free[x].uuid].num+=smc.goods.free[x].num
|
||||
}
|
||||
}
|
||||
smc.vmdata.free.buy--
|
||||
}
|
||||
get_goods1(){
|
||||
console.log("购买商品1")
|
||||
if(smc.vmdata.goods1.buy <= 0){
|
||||
oops.gui.toast("今日购买次数已用完");
|
||||
return
|
||||
}
|
||||
if(smc.vmdata.gold.num < smc.vmdata.goods1.cost){
|
||||
oops.gui.toast("金币不足");
|
||||
return
|
||||
}
|
||||
for (let x = 0; x < smc.goods.goods1.length; x++) {
|
||||
if(smc.goods.goods1[x].uuid ==9001){
|
||||
smc.vmdata.gold.num+=smc.goods.goods1[x].num
|
||||
}
|
||||
if(smc.goods.goods1[x].uuid ==9003){
|
||||
smc.vmdata.exp.num+=smc.goods.goods1[x].num
|
||||
}
|
||||
if(smc.goods.goods1[x].uuid < 9000){
|
||||
smc.items[smc.goods.goods1[x].uuid].num+=smc.goods.goods1[x].num
|
||||
}
|
||||
}
|
||||
smc.vmdata.goods1.buy--
|
||||
smc.vmdata.gold.num-=smc.vmdata.goods1.cost
|
||||
}
|
||||
get_goods2(){
|
||||
console.log("购买商品2")
|
||||
if(smc.vmdata.herochips.buy <= 0){
|
||||
oops.gui.toast("今日购买次数已用完");
|
||||
return
|
||||
}
|
||||
if(smc.vmdata.gold.num < smc.vmdata.herochips.cost){
|
||||
oops.gui.toast("金币不足");
|
||||
return
|
||||
}
|
||||
for (let x = 0; x < smc.goods.herochips.length; x++) {
|
||||
smc.heros[smc.goods.herochips[x].uuid].num += smc.goods.herochips[x].num
|
||||
}
|
||||
smc.vmdata.herochips.buy--
|
||||
smc.vmdata.gold.num-=smc.vmdata.herochips.cost
|
||||
}
|
||||
|
||||
get_goods3(){
|
||||
console.log("购买商品3")
|
||||
if(smc.vmdata.skillchips.buy <= 0){
|
||||
oops.gui.toast("今日购买次数已用完");
|
||||
return
|
||||
}
|
||||
if(smc.vmdata.gold.num < smc.vmdata.skillchips.cost){
|
||||
oops.gui.toast("金币不足");
|
||||
return
|
||||
}
|
||||
for (let x = 0; x < smc.goods.skillchips.length; x++) {
|
||||
smc.skills[smc.goods.skillchips[x].uuid].num += smc.goods.skillchips[x].num
|
||||
}
|
||||
smc.vmdata.skillchips.buy--
|
||||
smc.vmdata.gold.num-=smc.vmdata.skillchips.cost
|
||||
|
||||
}
|
||||
get_goods4(){
|
||||
console.log("购买商品4")
|
||||
if(smc.vmdata.goods4.buy <= 0){
|
||||
oops.gui.toast("今日购买次数已用完");
|
||||
return
|
||||
}
|
||||
smc.vmdata.goods4.buy--
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
|
||||
Reference in New Issue
Block a user