Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
view,
|
||||
} from "cc";
|
||||
import li_EventManager from "./li_EventManager";
|
||||
import LanguageUtils from "./LanguageUtils";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -355,4 +356,22 @@ export default class Utils {
|
||||
console.log(`${key}消耗时间:${timecha}毫秒`);
|
||||
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 { ViewManager } from "../../../Main/Manager/ViewManager";
|
||||
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;
|
||||
|
||||
@ccclass("PurchasePanel")
|
||||
export class PurchasePanel extends li_BaseView {
|
||||
private _nodeTab: any = {};
|
||||
|
||||
private diamondCount: Label;
|
||||
private coinNum: Label;
|
||||
private vipLeftTime: Label;
|
||||
private vipPriceTag: Label;
|
||||
|
||||
private vipPrice7: Label;
|
||||
private vipTime7: Label;
|
||||
private vipPrice30: Label;
|
||||
private vipTime30: Label;
|
||||
private tryBuyId: number;
|
||||
|
||||
@property([PurchasePanelItem])
|
||||
@@ -25,34 +32,25 @@ export class PurchasePanel extends li_BaseView {
|
||||
|
||||
onLoadCT(): void {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
|
||||
this.diamondCount = this._nodeTab.diamondNumber.getComponent(Label);
|
||||
this.coinNum = this._nodeTab.coinNum.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();
|
||||
|
||||
//订阅商业化数据事件
|
||||
Utils.addInnerEL(
|
||||
InnerEventCode.DiamondCountChanged,
|
||||
this,
|
||||
this.onDiamondCountChanged
|
||||
);
|
||||
Utils.addInnerEL(
|
||||
InnerEventCode.VipEndDayChange,
|
||||
this,
|
||||
this.onVipEndDayChange
|
||||
);
|
||||
Utils.addInnerEL(InnerMsgCode.BalanceChange, this, () => {
|
||||
this.onBalanceChange();
|
||||
});
|
||||
Utils.addInnerEL(InnerMsgCode.VipExpireChange, this, () => {
|
||||
this.onVipExpireChange();
|
||||
});
|
||||
|
||||
//获取商业化数据
|
||||
this.getPlayerMerData();
|
||||
this.Show();
|
||||
}
|
||||
|
||||
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() {
|
||||
GButton.BandClick(
|
||||
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() {
|
||||
this.getPlayerMerData();
|
||||
|
||||
const vipPrice = ConfigManager.tables.TbPurchaseConfig.get(2001).count;
|
||||
this.vipPriceTag.string = `$ ${vipPrice}`;
|
||||
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
// 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());
|
||||
}
|
||||
|
||||
@@ -95,35 +123,42 @@ export class PurchasePanel extends li_BaseView {
|
||||
|
||||
getPlayerMerData() {
|
||||
//todo: 获取服务器玩家商业化数据
|
||||
this.diamondCount.string = CommercialData.Instance.diamondCount.toString();
|
||||
const leftTime = CommercialData.Instance.getVipLeftTime();
|
||||
this.vipLeftTime.string = LanguageUtils.getText(
|
||||
"purchasepanel.vip_left"
|
||||
).replace("${leftTime}", leftTime);
|
||||
this.refreshCoinNum();
|
||||
this.refreshVipExpire();
|
||||
}
|
||||
|
||||
onDiamondCountChanged(data: any) {
|
||||
this.diamondCount.string = data.count.toString();
|
||||
onBalanceChange() {
|
||||
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(
|
||||
"purchasepanel.vip_left"
|
||||
).replace("${leftTime}", leftTime);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
Utils.removeInnerEL(
|
||||
InnerEventCode.DiamondCountChanged,
|
||||
this,
|
||||
this.onDiamondCountChanged
|
||||
);
|
||||
Utils.removeInnerEL(
|
||||
InnerEventCode.VipEndDayChange,
|
||||
this,
|
||||
this.onVipEndDayChange
|
||||
);
|
||||
Utils.removeInnerEL(InnerMsgCode.BalanceChange, this, () => {
|
||||
|
||||
});
|
||||
Utils.removeInnerEL(InnerMsgCode.VipExpireChange, this, () => {
|
||||
|
||||
});
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { _decorator, Component, Label, Node } from "cc";
|
||||
import { PurchasePanel } from "../ui/panels/PurchasePanel";
|
||||
import { PurchaseConfig } from "../../schema/schema";
|
||||
import { DataManager, DataId } from "../data/DataManager";
|
||||
import { ShopData } from "../data/ShopData";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PurchasePanelItem")
|
||||
@@ -11,18 +13,22 @@ export class PurchasePanelItem extends Component {
|
||||
price: Label;
|
||||
|
||||
baseView: PurchasePanel;
|
||||
data: PurchaseConfig;
|
||||
public init(base: PurchasePanel, data: PurchaseConfig) {
|
||||
goodId: number;
|
||||
public init(base: PurchasePanel, goodId: number) {
|
||||
this.baseView = base;
|
||||
this.data = data;
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public show() {
|
||||
this.count.string = this.data.count.toString();
|
||||
this.price.string = this.data.price.toString();
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
const count = shopData.getCountById(this.goodId);
|
||||
this.count.string = count.toString();
|
||||
const price = shopData.getOriginalPriceById(this.goodId);
|
||||
this.price.string = price.toString();
|
||||
}
|
||||
|
||||
onClickThis() {
|
||||
this.baseView.setDiamondTag(this.data.id);
|
||||
this.baseView.setDiamondTag(this.goodId);
|
||||
console.log("点击了");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1219,7 +1219,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "vipPrice",
|
||||
"_name": "vipPrice30",
|
||||
"_objFlags": 512,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
@@ -1378,7 +1378,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "vipTime",
|
||||
"_name": "vipTime30",
|
||||
"_objFlags": 512,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
@@ -1753,7 +1753,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "vipPrice",
|
||||
"_name": "vipPrice7",
|
||||
"_objFlags": 512,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
@@ -1912,7 +1912,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "vipTime",
|
||||
"_name": "vipTime7",
|
||||
"_objFlags": 512,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
@@ -2777,7 +2777,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "text",
|
||||
"_name": "vipText",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
|
||||
Reference in New Issue
Block a user