Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
view,
|
view,
|
||||||
} from "cc";
|
} from "cc";
|
||||||
import li_EventManager from "./li_EventManager";
|
import li_EventManager from "./li_EventManager";
|
||||||
|
import LanguageUtils from "./LanguageUtils";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -355,4 +356,22 @@ export default class Utils {
|
|||||||
console.log(`${key}消耗时间:${timecha}毫秒`);
|
console.log(`${key}消耗时间:${timecha}毫秒`);
|
||||||
Utils._eplTime = time;
|
Utils._eplTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取格式化字符串: vip失效时间
|
||||||
|
public static formatVipLeftTime(expiryTimestamp: number): string {
|
||||||
|
const dateNow = new Date();
|
||||||
|
const timeDiff = Math.abs(expiryTimestamp - dateNow.getTime());
|
||||||
|
const hours = Math.floor(timeDiff / (1000 * 60 * 60));
|
||||||
|
|
||||||
|
if (hours >= 24) {
|
||||||
|
return (
|
||||||
|
(hours % 24).toString() + LanguageUtils.getText("purchasepanel.day")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const minutes = Math.floor((timeDiff / (1000 * 60)) % 60);
|
||||||
|
//const seconds = Math.floor((timeDiff / 1000) % 60);
|
||||||
|
return `${hours}${LanguageUtils.getText(
|
||||||
|
"purchasepanel.hour"
|
||||||
|
)}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,24 @@ import { GButton } from "../../../Main/Common/GButton";
|
|||||||
import { PurchasePanelItem } from "../../uiitems/PurchasePanelItem";
|
import { PurchasePanelItem } from "../../uiitems/PurchasePanelItem";
|
||||||
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
||||||
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
||||||
import { InnerEventCode } from "../../../Main/Config/InnerMsgCode";
|
import { InnerEventCode, InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
||||||
|
import { DataManager, DataId } from "../../data/DataManager";
|
||||||
|
import { WalletData } from "../../data/WalletData";
|
||||||
|
import { ShopData } from "../../data/ShopData";
|
||||||
|
import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService";
|
||||||
|
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("PurchasePanel")
|
@ccclass("PurchasePanel")
|
||||||
export class PurchasePanel extends li_BaseView {
|
export class PurchasePanel extends li_BaseView {
|
||||||
private _nodeTab: any = {};
|
private _nodeTab: any = {};
|
||||||
|
private coinNum: Label;
|
||||||
private diamondCount: Label;
|
|
||||||
private vipLeftTime: Label;
|
private vipLeftTime: Label;
|
||||||
private vipPriceTag: Label;
|
private vipPrice7: Label;
|
||||||
|
private vipTime7: Label;
|
||||||
|
private vipPrice30: Label;
|
||||||
|
private vipTime30: Label;
|
||||||
private tryBuyId: number;
|
private tryBuyId: number;
|
||||||
|
|
||||||
@property([PurchasePanelItem])
|
@property([PurchasePanelItem])
|
||||||
@@ -25,34 +32,25 @@ export class PurchasePanel extends li_BaseView {
|
|||||||
|
|
||||||
onLoadCT(): void {
|
onLoadCT(): void {
|
||||||
Utils.parseNode(this.node, this._nodeTab);
|
Utils.parseNode(this.node, this._nodeTab);
|
||||||
|
this.coinNum = this._nodeTab.coinNum.getComponent(Label);
|
||||||
this.diamondCount = this._nodeTab.diamondNumber.getComponent(Label);
|
|
||||||
this.vipLeftTime = this._nodeTab.vipText.getComponent(Label);
|
this.vipLeftTime = this._nodeTab.vipText.getComponent(Label);
|
||||||
this.vipPriceTag = this._nodeTab.vipPrice.getComponent(Label);
|
this.vipPrice7 = this._nodeTab.vipPrice7.getComponent(Label);
|
||||||
|
this.vipTime7 = this._nodeTab.vipTime7.getComponent(Label);
|
||||||
|
this.vipPrice30 = this._nodeTab.vipPrice30.getComponent(Label);
|
||||||
|
this.vipTime30 = this._nodeTab.vipTime30.getComponent(Label);
|
||||||
this.bandBtn();
|
this.bandBtn();
|
||||||
|
|
||||||
//订阅商业化数据事件
|
//订阅商业化数据事件
|
||||||
Utils.addInnerEL(
|
Utils.addInnerEL(InnerMsgCode.BalanceChange, this, () => {
|
||||||
InnerEventCode.DiamondCountChanged,
|
this.onBalanceChange();
|
||||||
this,
|
});
|
||||||
this.onDiamondCountChanged
|
Utils.addInnerEL(InnerMsgCode.VipExpireChange, this, () => {
|
||||||
);
|
this.onVipExpireChange();
|
||||||
Utils.addInnerEL(
|
});
|
||||||
InnerEventCode.VipEndDayChange,
|
|
||||||
this,
|
|
||||||
this.onVipEndDayChange
|
|
||||||
);
|
|
||||||
|
|
||||||
//获取商业化数据
|
this.Show();
|
||||||
this.getPlayerMerData();
|
|
||||||
|
|
||||||
const cfg = ConfigManager.tables.TbPurchaseConfig;
|
|
||||||
for (let index = 0; index < this.items.length; index++) {
|
|
||||||
const element = this.items[index];
|
|
||||||
element.init(this, cfg.get(1001 + index));
|
|
||||||
}
|
|
||||||
this.updateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bandBtn() {
|
bandBtn() {
|
||||||
GButton.BandClick(
|
GButton.BandClick(
|
||||||
this._nodeTab.BuyVipBtn,
|
this._nodeTab.BuyVipBtn,
|
||||||
@@ -80,12 +78,42 @@ export class PurchasePanel extends li_BaseView {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async Show() {
|
||||||
|
// 请求商城数据
|
||||||
|
const reqData = {
|
||||||
|
|
||||||
|
};
|
||||||
|
let res = await ShopService.I.reqShopList(reqData);
|
||||||
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||||
|
// 保存数据
|
||||||
|
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||||
|
shopData.goods = res.data;
|
||||||
|
// 根据数据,刷新界面
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateView() {
|
updateView() {
|
||||||
this.getPlayerMerData();
|
this.getPlayerMerData();
|
||||||
|
|
||||||
const vipPrice = ConfigManager.tables.TbPurchaseConfig.get(2001).count;
|
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||||
this.vipPriceTag.string = `$ ${vipPrice}`;
|
// VIP会员
|
||||||
|
const memberIds = shopData.getMemberIds();
|
||||||
|
for (let i = 0; i < memberIds.length; i++) {
|
||||||
|
const id = memberIds[i];
|
||||||
|
const price = shopData.getOriginalPriceById(id);
|
||||||
|
if (i === 0) {
|
||||||
|
this.vipPrice7.string = `$ ${price}`;
|
||||||
|
} else if (i === 1) {
|
||||||
|
this.vipPrice30.string = `$ ${price}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 充值商品
|
||||||
|
const rechargeIds = shopData.getRechargeIds();
|
||||||
|
for (let index = 0; index < this.items.length; index++) {
|
||||||
|
const element = this.items[index];
|
||||||
|
element.init(this, rechargeIds[index]);
|
||||||
|
}
|
||||||
this.items.forEach((item) => item.show());
|
this.items.forEach((item) => item.show());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,35 +123,42 @@ export class PurchasePanel extends li_BaseView {
|
|||||||
|
|
||||||
getPlayerMerData() {
|
getPlayerMerData() {
|
||||||
//todo: 获取服务器玩家商业化数据
|
//todo: 获取服务器玩家商业化数据
|
||||||
this.diamondCount.string = CommercialData.Instance.diamondCount.toString();
|
this.refreshCoinNum();
|
||||||
const leftTime = CommercialData.Instance.getVipLeftTime();
|
this.refreshVipExpire();
|
||||||
this.vipLeftTime.string = LanguageUtils.getText(
|
|
||||||
"purchasepanel.vip_left"
|
|
||||||
).replace("${leftTime}", leftTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDiamondCountChanged(data: any) {
|
onBalanceChange() {
|
||||||
this.diamondCount.string = data.count.toString();
|
this.refreshCoinNum();
|
||||||
}
|
}
|
||||||
|
|
||||||
onVipEndDayChange(data: any) {
|
// 刷新余额
|
||||||
const leftTime = CommercialData.Instance.getVipLeftTime();
|
private refreshCoinNum() {
|
||||||
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||||
|
const balance = walletData.getOriginalBalance();
|
||||||
|
this.coinNum.string = balance.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
onVipExpireChange() {
|
||||||
|
this.refreshVipExpire();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新 vip失效时间戳
|
||||||
|
private refreshVipExpire() {
|
||||||
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||||
|
const vipExpire = walletData.vipExpire;
|
||||||
|
const leftTime = Utils.formatVipLeftTime(vipExpire);
|
||||||
this.vipLeftTime.string = LanguageUtils.getText(
|
this.vipLeftTime.string = LanguageUtils.getText(
|
||||||
"purchasepanel.vip_left"
|
"purchasepanel.vip_left"
|
||||||
).replace("${leftTime}", leftTime);
|
).replace("${leftTime}", leftTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
Utils.removeInnerEL(
|
Utils.removeInnerEL(InnerMsgCode.BalanceChange, this, () => {
|
||||||
InnerEventCode.DiamondCountChanged,
|
|
||||||
this,
|
});
|
||||||
this.onDiamondCountChanged
|
Utils.removeInnerEL(InnerMsgCode.VipExpireChange, this, () => {
|
||||||
);
|
|
||||||
Utils.removeInnerEL(
|
});
|
||||||
InnerEventCode.VipEndDayChange,
|
|
||||||
this,
|
|
||||||
this.onVipEndDayChange
|
|
||||||
);
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { _decorator, Component, Label, Node } from "cc";
|
import { _decorator, Component, Label, Node } from "cc";
|
||||||
import { PurchasePanel } from "../ui/panels/PurchasePanel";
|
import { PurchasePanel } from "../ui/panels/PurchasePanel";
|
||||||
import { PurchaseConfig } from "../../schema/schema";
|
import { PurchaseConfig } from "../../schema/schema";
|
||||||
|
import { DataManager, DataId } from "../data/DataManager";
|
||||||
|
import { ShopData } from "../data/ShopData";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("PurchasePanelItem")
|
@ccclass("PurchasePanelItem")
|
||||||
@@ -11,18 +13,22 @@ export class PurchasePanelItem extends Component {
|
|||||||
price: Label;
|
price: Label;
|
||||||
|
|
||||||
baseView: PurchasePanel;
|
baseView: PurchasePanel;
|
||||||
data: PurchaseConfig;
|
goodId: number;
|
||||||
public init(base: PurchasePanel, data: PurchaseConfig) {
|
public init(base: PurchasePanel, goodId: number) {
|
||||||
this.baseView = base;
|
this.baseView = base;
|
||||||
this.data = data;
|
this.goodId = goodId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public show() {
|
public show() {
|
||||||
this.count.string = this.data.count.toString();
|
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||||
this.price.string = this.data.price.toString();
|
const count = shopData.getCountById(this.goodId);
|
||||||
|
this.count.string = count.toString();
|
||||||
|
const price = shopData.getOriginalPriceById(this.goodId);
|
||||||
|
this.price.string = price.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickThis() {
|
onClickThis() {
|
||||||
this.baseView.setDiamondTag(this.data.id);
|
this.baseView.setDiamondTag(this.goodId);
|
||||||
|
console.log("点击了");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1219,7 +1219,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "vipPrice",
|
"_name": "vipPrice30",
|
||||||
"_objFlags": 512,
|
"_objFlags": 512,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": {
|
"_parent": {
|
||||||
@@ -1378,7 +1378,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "vipTime",
|
"_name": "vipTime30",
|
||||||
"_objFlags": 512,
|
"_objFlags": 512,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": {
|
"_parent": {
|
||||||
@@ -1753,7 +1753,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "vipPrice",
|
"_name": "vipPrice7",
|
||||||
"_objFlags": 512,
|
"_objFlags": 512,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": {
|
"_parent": {
|
||||||
@@ -1912,7 +1912,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "vipTime",
|
"_name": "vipTime7",
|
||||||
"_objFlags": 512,
|
"_objFlags": 512,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": {
|
"_parent": {
|
||||||
@@ -2777,7 +2777,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "text",
|
"_name": "vipText",
|
||||||
"_objFlags": 0,
|
"_objFlags": 0,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": {
|
"_parent": {
|
||||||
|
|||||||
Reference in New Issue
Block a user