Commit 393643ca authored by haiyoucuv's avatar haiyoucuv

init

parent 1d0c9d27
import { _decorator, Button, Component, Label, Node, Size, Sprite, } from 'cc';
import { observer, render } from '../store/decorators';
import { _decorator, Button, Label, Node, Size, Sprite, } from "cc";
import { observer } from "../store/decorators";
import Panel from "../../Module/Panel";
import { changeScene, hideWaiting, showWaiting } from '../../Module/UIFast';
import { _asyncThrottle, dateFormatter, strFormat } from '../Utils/Utils';
import { HomeScene } from '../Scenes/HomeScene';
import { sendWebNet, sendWebNetWithToken, WebNetName } from '../Utils/WebNet/WebNet';
import { YXCollectionView, YXFlowLayout, YXIndexPath } from '../../Component/YXList/lib';
import { url } from 'inspector';
import { PropPage } from '../Scenes/PropPage';
import store from '../store/store';
import { changeScene, hideWaiting, showWaiting } from "../../Module/UIFast";
import { _asyncThrottle, dateFormatter, strFormat } from "../Utils/Utils";
import { sendWebNet, sendWebNetWithToken, WebNetName } from "../Utils/WebNet/WebNet";
import { YXCollectionView, YXFlowLayout, YXIndexPath } from "../../Component/YXList/lib";
import { PropPage } from "../Scenes/PropPage";
import store from "../store/store";
const { ccclass, property } = _decorator;
enum TAB {
PRIZE = "PRIZE",
TOOL = "TOOL",
PRIZE = "PRIZE",
TOOL = "TOOL",
}
@observer
@ccclass('MyBagPanel')
@ccclass("MyBagPanel")
export class MyBagPanel extends Panel {
static bundle: string = "MyBagPanel";
static skin: string = "MyBagPanel";
static bundle: string = "MyBagPanel";
static skin: string = "MyBagPanel";
@property(Node) closeBtn: Node = null;
@property(Node) closeBtn: Node = null;
@property(Node) Prize: Node = null;
@property(Node) Tool: Node = null;
@property(Node) Prize: Node = null;
@property(Node) Tool: Node = null;
@property(Node) prize_yes: Node = null;
@property(Node) prize_btn: Node = null;
@property(Node) tool_yes: Node = null;
@property(Node) tool_btn: Node = null;
@property(Node) prize_yes: Node = null;
@property(Node) prize_btn: Node = null;
@property(Node) tool_yes: Node = null;
@property(Node) tool_btn: Node = null;
@property(YXCollectionView) Prize_List: YXCollectionView = null;
@property(Node) None_list: Node = null;
@property(YXCollectionView) Tool_List: YXCollectionView = null;
@property(YXCollectionView) Prize_List: YXCollectionView = null;
@property(Node) None_list: Node = null;
@property(YXCollectionView) Tool_List: YXCollectionView = null;
private _tab: TAB = TAB.PRIZE;
set tab(tab: TAB) { // 设置tab切换
this._tab = tab;
const isPrize = tab == TAB.PRIZE;
const isTool = tab == TAB.TOOL;
private _tab: TAB = TAB.PRIZE;
set tab(tab: TAB) { // 设置tab切换
this._tab = tab;
const isPrize = tab == TAB.PRIZE;
const isTool = tab == TAB.TOOL;
this.prize_yes.active = isPrize;
this.tool_yes.active = isTool;
this.prize_yes.active = isPrize;
this.tool_yes.active = isTool;
this.Prize.active = isPrize;
this.Tool.active = isTool;
}
this.Prize.active = isPrize;
this.Tool.active = isTool;
}
get tab() {
return this._tab;
}
get tab() {
return this._tab;
}
prizeDate: any[] = [];
toolDate: any[] = [];
prizeDate: any[] = [];
toolDate: any[] = [];
onLoad() {
this.tab = TAB.PRIZE;
onLoad() {
this.tab = TAB.PRIZE;
this.closeBtn.on(Button.EventType.CLICK, this.clickClose, this);
this.prize_btn.on(Button.EventType.CLICK, this.clickSheng, this);
this.tool_btn.on(Button.EventType.CLICK, this.clickSingle, this);
}
this.closeBtn.on(Button.EventType.CLICK, this.clickClose, this);
this.prize_btn.on(Button.EventType.CLICK, this.clickSheng, this);
this.tool_btn.on(Button.EventType.CLICK, this.clickSingle, this);
}
async start() {
const { tab = "" } = this.data
if (tab && tab == "TOOL") {
this.tab = TAB.TOOL;
}
async start() {
const { tab = "" } = this.data;
if (tab && tab == "TOOL") {
this.tab = TAB.TOOL;
}
this.Prize_List.numberOfItems = () => this.prizeDate.length;
this.Prize_List.onCellDisplay = this.onShengCellDisplay;
this.Prize_List.numberOfItems = () => this.prizeDate.length;
this.Prize_List.onCellDisplay = this.onShengCellDisplay;
const shengLayout = new YXFlowLayout();
shengLayout.itemSize = new Size(820, 140);
this.Prize_List.layout = shengLayout;
this.Prize_List.reloadData();
const shengLayout = new YXFlowLayout();
shengLayout.itemSize = new Size(820, 140);
this.Prize_List.layout = shengLayout;
this.Prize_List.reloadData();
this.Tool_List.numberOfItems = () => this.toolDate.length;
this.Tool_List.onCellDisplay = this.onSingleCellDisplay;
this.Tool_List.numberOfItems = () => this.toolDate.length;
this.Tool_List.onCellDisplay = this.onSingleCellDisplay;
const singleLayout = new YXFlowLayout();
singleLayout.itemSize = new Size(820, 140);
this.Tool_List.layout = singleLayout;
this.Tool_List.reloadData();
const singleLayout = new YXFlowLayout();
singleLayout.itemSize = new Size(820, 140);
this.Tool_List.layout = singleLayout;
this.Tool_List.reloadData();
showWaiting(true);
await Promise.all([
this.updateSheng(),
this.updateSingle(),
]);
hideWaiting();
showWaiting(true);
await Promise.all([
this.updateSheng(),
this.updateSingle(),
]);
hideWaiting();
}
}
update(deltaTime: number) {
update(deltaTime: number) {
}
}
clickClose = () => {
this.hidePanel();
}
clickClose = () => {
this.hidePanel();
};
// 点击奖品
clickSheng() {
this.tab = TAB.PRIZE;
// this.Prize.getChildByName(`goCheck`).active = true;
}
// 道具
clickSingle() {
if (!store.checkActTime()) return;
// 点击奖品
clickSheng() {
this.tab = TAB.PRIZE;
// this.Prize.getChildByName(`goCheck`).active = true;
}
this.tab = TAB.TOOL;
}
// 道具
clickSingle() {
if (!store.checkActTime()) return;
/****** 数据 ******/
// 刷新道具
async updateSheng() {
const { success, data } = await sendWebNet(WebNetName.queryGameItem);
if (!success) return;
this.tab = TAB.TOOL;
}
this.prizeDate = data.spInfo;
this.Prize_List.reloadData();
/****** 数据 ******/
// 刷新道具
async updateSheng() {
const { success, data } = await sendWebNet(WebNetName.queryGameItem);
if (!success) return;
this.Prize_List.node.active = this.prizeDate.length > 0;
}
this.prizeDate = data.spInfo;
this.Prize_List.reloadData();
// 刷新奖品
async updateSingle() {
const { success, data = [] } = await sendWebNet(WebNetName.prizeDetail);
this.Prize_List.node.active = this.prizeDate.length > 0;
}
if (!success) return;
prizeIdType = {};
// 刷新奖品
async updateSingle() {
const { success, data = [] } = await sendWebNet(WebNetName.prizeDetail);
const excludeSp = true; //排除道具
const { success: suc, data: d } = await sendWebNet(WebNetName.prizeType);
let records = []
if (!success) return;
for (let item of data) {
if (!suc) return;
const { extra: { name, icon, type }, id, prizeId, gmtCreate } = item;
if (excludeSp && type === 1) {
continue;
}
const excludeSp = true; //排除道具
records.push({
id,
prizeId,
name,
icon,
gmtCreate,
data: item,
});
}
let records = [];
if (records.length == 0) {
this.None_list.active = true;
}
const idType = {};
d.forEach((item) => {
this.prizeIdType[item.prizeId] = item.prizeType;
});
this.toolDate = records;
this.Tool_List.reloadData();
this.Tool_List.node.active = this.toolDate.length > 0;
}
// 给每个cell设置数据
onShengCellDisplay = (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => {
const data = this.prizeDate[indexPath.item];
this.onCellDisplay(cell, data, TAB.TOOL);
}
onSingleCellDisplay = (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => {
const data = this.toolDate[indexPath.item];
this.onCellDisplay(cell, data, TAB.PRIZE);
}
onCellDisplay = (cell: Node, data, type) => {
let { icon = 0, id = "", url = "", gmtCreate = 0, name = "", spId = "", spName = "", spNum = 0, spImg = "", dressingStatus = 0 } = data;
const isPrize = type == TAB.PRIZE;
const isTool = type == TAB.TOOL;
const goCheck = cell.getChildByName("goCheck")
const goBuy = cell.getChildByName("goBuy")
const goDress = cell.getChildByName("goDress")
const Derssed = cell.getChildByName("Derssed")
goCheck.on(Button.EventType.CLICK, () => this.clickToCheck(url, id)) // 奖品-去查看
goBuy.on(Button.EventType.CLICK, () => this.clickToBuy()) // 道具-去购买
goDress.on(Button.EventType.CLICK, () => this.clickToDress()) // 道具-去装扮
Derssed.on(Button.EventType.CLICK, () => this.clickToDefaultDress()) // 道具-换回默认装扮
goCheck.active = isPrize;
goBuy.active = isTool && spId != "sp_skin_snake_year"; // 不是蛇皮肤,去购买
goDress.active = isTool && spId == "sp_skin_snake_year" && dressingStatus == 0; // 已装扮
cell.getChildByName(`Derssed`).active = isTool && spId == "sp_skin_snake_year" && dressingStatus == 1; // 未装扮
cell.getChildByName(`name`).getComponent(Label).string = strFormat(name || spName, 32);
cell.getChildByName(`time`).getComponent(Label).string = gmtCreate ? dateFormatter(gmtCreate, "yyyy.MM.dd hh:mm") : "剩余数量:" + spNum;
cell.getChildByName("img").getComponent(Sprite).spriteFrame = icon || spImg;
}
clickToCheck = (url, id) => {
// return _asyncThrottle(
// () => {
if (url) {
window.location.href = url;
} else {
window.location.href = `/aaw/projectx/takePrize?projectOrderNo=${id}`;
}
// }
// )
for (let item of data) {
}
const { extra: { name, icon, type }, id, prizeId, gmtCreate } = item;
if (excludeSp && type === 1) {
continue;
}
clickToBuy = _asyncThrottle(async () => {
this.hidePanel()
await changeScene(PropPage,{isFrom:MyBagPanel,isPop:true})
})
records.push({
id,
prizeId,
name,
icon,
gmtCreate,
data: item,
});
}
// clickToDress = async (spId) => {
clickToDress = _asyncThrottle(async () => {
const { success, data } = await sendWebNetWithToken(WebNetName.doDress, { spId: "sp_skin_snake_year" });
if (!success) return;
if (records.length == 0) {
this.None_list.active = true;
}
console.log("换上了新皮肤");
this.hidePanel()
})
this.toolDate = records;
this.Tool_List.reloadData();
clickToDefaultDress = _asyncThrottle(async () => {
const { success, data } = await sendWebNetWithToken(WebNetName.doDress, { spId: "sp_decoration_default" });
if (!success) return;
this.Tool_List.node.active = this.toolDate.length > 0;
}
console.log("换回了原皮肤");
this.hidePanel()
})
// 给每个cell设置数据
onShengCellDisplay = (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => {
const data = this.prizeDate[indexPath.item];
this.onCellDisplay(cell, data, TAB.TOOL);
};
onSingleCellDisplay = (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => {
const data = this.toolDate[indexPath.item];
this.onCellDisplay(cell, data, TAB.PRIZE);
};
onCellDisplay = (cell: Node, data, type) => {
let {
icon = 0,
id = "",
url = "",
gmtCreate = 0,
name = "",
spId = "",
spName = "",
spNum = 0,
spImg = "",
dressingStatus = 0
} = data;
const isPrize = type == TAB.PRIZE;
const isTool = type == TAB.TOOL;
const goCheck = cell.getChildByName("goCheck");
const goBuy = cell.getChildByName("goBuy");
const goDress = cell.getChildByName("goDress");
const Derssed = cell.getChildByName("Derssed");
goCheck.on(Button.EventType.CLICK, () => this.clickToCheck(url, id)); // 奖品-去查看
goBuy.on(Button.EventType.CLICK, () => this.clickToBuy()); // 道具-去购买
goDress.on(Button.EventType.CLICK, () => this.clickToDress()); // 道具-去装扮
Derssed.on(Button.EventType.CLICK, () => this.clickToDefaultDress()); // 道具-换回默认装扮
goCheck.active = isPrize;
goBuy.active = isTool && spId != "sp_skin_snake_year"; // 不是蛇皮肤,去购买
goDress.active = isTool && spId == "sp_skin_snake_year" && dressingStatus == 0; // 已装扮
cell.getChildByName(`Derssed`).active = isTool && spId == "sp_skin_snake_year" && dressingStatus == 1; // 未装扮
cell.getChildByName(`name`).getComponent(Label).string = strFormat(name || spName, 32);
cell.getChildByName(`time`).getComponent(Label).string = gmtCreate ? dateFormatter(gmtCreate, "yyyy.MM.dd hh:mm") : "剩余数量:" + spNum;
cell.getChildByName("img").getComponent(Sprite).spriteFrame = icon || spImg;
};
clickToCheck = (url, id) => {
// return _asyncThrottle(
// () => {
if (url) {
window.location.href = url;
} else {
window.location.href = `/aaw/projectx/takePrize?projectOrderNo=${id}`;
}
// }
// )
};
clickToBuy = _asyncThrottle(async () => {
this.hidePanel();
await changeScene(PropPage, { isFrom: MyBagPanel, isPop: true });
});
// clickToDress = async (spId) => {
clickToDress = _asyncThrottle(async () => {
const { success, data } = await sendWebNetWithToken(WebNetName.doDress, { spId: "sp_skin_snake_year" });
if (!success) return;
console.log("换上了新皮肤");
this.hidePanel();
});
clickToDefaultDress = _asyncThrottle(async () => {
const { success, data } = await sendWebNetWithToken(WebNetName.doDress, { spId: "sp_decoration_default" });
if (!success) return;
console.log("换回了原皮肤");
this.hidePanel();
});
}
......@@ -156,7 +156,7 @@ export class HomeScene extends Scene {
sendLog(LOG_TYPE.CLICK, 5)
if (!store.checkActTime()) return;
await gameStore.startGame();
await gameStore.startGame(true);
changeScene(MainGame);
});
......
......@@ -166,7 +166,7 @@ export class MainGame extends Scene {
if (currentStage == 1) {
const submitSuc = await gameStore.submitOne();
if (submitSuc) {
const gameSuc = await gameStore.startGame();
const gameSuc = await gameStore.startGame(false);
if (gameSuc) {
await changeScene(MainGame);
} else {
......@@ -179,7 +179,7 @@ export class MainGame extends Scene {
if (MainGame.ins.player.length >= length) {
const submitSuc = await gameStore.submitTwo();
if (submitSuc) {
const gameSuc = await gameStore.startGame();
const gameSuc = await gameStore.startGame(false);
if (gameSuc) {
await changeScene(MainGame);
} else {
......@@ -278,7 +278,7 @@ export class MainGame extends Scene {
this.isOver = true;
const submitSuc = await gameStore.submitTwo();
if (submitSuc) {
const gameSuc = await gameStore.startGame();
const gameSuc = await gameStore.startGame(false);
if (gameSuc) {
await changeScene(MainGame);
} else {
......
......@@ -47,9 +47,11 @@ class GameStore {
startInfo: IStartInfo = null;
async startGame() {
async startGame(isNew: boolean) {
showWaiting();
const { success, data } = await sendWebNetWithToken(WebNetName.startGame);
const { success, data } = await sendWebNetWithToken(WebNetName.startGame, {
isNew: isNew,
});
hideWaiting();
if (!success) {
......
{
"data": [
{
"prizeType": 1,
"prizeId": "g4c4c3edd"
},
{
"prizeType": 2,
"prizeId": "g0e432eeb"
},
{
"prizeType": 3,
"prizeId": "g900c8442"
},
{
"prizeType": 4,
"prizeId": "g4c7ba888"
}
],
"success": true
}
\ No newline at end of file
......@@ -106,6 +106,5 @@
"prizeId": "g0e432eeb"
}
],
"data":[],
"success": true
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment