CutePet/Assets/Scripts/GameScene/Panel/GoldRealPanel.cs
2024-10-25 11:10:04 +08:00

110 lines
3.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GoldRealPanel : BasePanel
{
//关闭
public Button btnClose;
//立即提现
public Button btnRealized;
//提现记录
public Button btnRecord;
//金币余额
public Text txtGold;
//可提现额度
public Text txtMoney;
//本周提现上限
public Text txtUpper;
private DateTime timeNow;
//可提现金额
private int CanRealGold;
public override void Init()
{
//打开面板,就更新面板
UpdatePanel(GameDataMgr.Instance.player);
btnClose.onClick.AddListener(() =>
{
UIManager.Instance.HidePanel<GoldRealPanel>();
});
//点击立即提现做什么
btnRealized.onClick.AddListener(() =>
{
if (GameDataMgr.Instance.player.gold<1000|| GameDataMgr.Instance.player.weekGoldReal < 1000)
{
//提现失败面板显示,提现失败
UIManager.Instance.ShowPanel<GoldLosePanel>();
}
else
{
RealGold();
}
});
//点击提现记录做什么
btnRecord.onClick.AddListener(() =>
{
//打开提现记录面板
UIManager.Instance.ShowPanel<GoldRecordPanel>();
});
}
/// <summary>
/// 更新面板上的数据
/// </summary>
/// <param name="player"></param>
public void UpdatePanel(PlayerData player)
{
if (player.gold >= player.weekGoldReal&&player.weekGoldReal>=1000)
{
//可提现多少元
txtMoney.text = (player.weekGoldReal / 1000) + "元";
CanRealGold=player.weekGoldReal/1000*1000;
}
else if (player.gold<1000||player.weekGoldReal<1000)
{
//可提现多少元
txtMoney.text = 0 + "元";
}
else if (player.gold < player.weekGoldReal&&player.weekGoldReal>=1000)
{
txtMoney.text = player.gold / 1000 + "元";
CanRealGold = player.gold / 1000 * 1000;
}
//本周还可以提现多少额度
txtUpper.text = "本周全程提现上限100000/"+player.weekGoldReal;
//金币余额
txtGold.text = "金币余额:" + player.gold;
}
public void RealGold()
{
GameDataMgr.Instance.player.weekGoldReal -= CanRealGold;
GameDataMgr.Instance.player.gold -= CanRealGold;
//单独发送一条提现记录给服务器
timeNow = DateTime.Now;
string timeStr = timeNow.ToString("yyyy年MM月dd日 HH时mm分ss秒");
GoldRealMsg msg = new GoldRealMsg();
msg.openId = GameDataMgr.Instance.player.openId;
msg.realRecord = new Dictionary<string, string>();
msg.realRecord.Add(timeStr, "提现" + CanRealGold / 1000 + "元,共消耗" + CanRealGold / 1000 * 1000 + "金币。");
msg.money = CanRealGold / 1000;
msg.state = 0;
StartCoroutine(NetMgr.Instance.GoldRealPost(msg));
StartCoroutine(NetMgr.Instance.ChangeDataPost(GameDataMgr.Instance.player));
//显示提现成功提示面板
UIManager.Instance.ShowPanel<GoldSuccPanel>().UpdatePanel(CanRealGold/1000);
}
}