2025-05-18 01:04:31 +08:00

214 lines
4.8 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-05-26
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "ArchiveBox.View" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
partial class ArchiveBox
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
GameObject _goLocal;
[KUIFlag]
GameObject _goCloud;
[KUIFlag]
Button _btnClose;
[KUIFlag]
Button _btnUpload;
[KUIFlag]
Button _btnDownload;
[KUIFlag]
TextMeshProUGUI _tmpCTime;
[KUIFlag]
TextMeshProUGUI _tmpCName;
[KUIFlag]
TextMeshProUGUI _tmpCGrade;
[KUIFlag]
TextMeshProUGUI _tmpCLevel;
[KUIFlag]
TextMeshProUGUI _tmpCForce;
[KUIFlag]
TextMeshProUGUI _tmpLTime;
[KUIFlag]
TextMeshProUGUI _tmpLName;
[KUIFlag]
TextMeshProUGUI _tmpLGrade;
[KUIFlag]
TextMeshProUGUI _tmpLLevel;
[KUIFlag]
TextMeshProUGUI _tmpLForce;
[KUIFlag]
TextMeshProUGUI _tmpAutoStatus;
[KUIFlag]
Toggle _tgAuto;
[KUIFlag]
Button _btnTitleTips;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Method
/// <summary>
///
/// </summary>
public void InitView()
{
SetViewData();
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
_btnUpload.onClick.AddListener(this.OnUploadBtnClick);
_btnDownload.onClick.AddListener(this.OnDownloadBtnClick);
_btnTitleTips.onClick.AddListener(this.OnAutoTipsClick);
_tgAuto.onValueChanged.AddListener(this.OnAutoToggleValueChanged);
}
/// <summary>
///
/// </summary>
public void RefreshView()
{
RefreshLocal();
RefreshCloud(this.data);
}
void RefreshLocal()
{
_tmpLName.text = PlayerProxy.Instance.nickName;
//_tmpLGrade.text = PlayerProxy.Instance.grade.ToString();
_tmpLLevel.text = LevelProxy.Instance.currentCompletedLevel.ToString();
_tmpLForce.text = PlayerProxy.Instance.combatValue.ToString();
//_tgAuto.isOn = ArchiveProxy.Instance.autoUploadArchive;
//_tmpAutoStatus.text = ArchiveProxy.Instance.autoUploadArchiveMessage;
}
void RefreshCloud(object data)
{
if (data is string)
{
var archiveInfo = new ArchiveProxy.ArchiveInfo();
archiveInfo.FromString(data as string);
_goCloud.SetActive(true);
if (!string.IsNullOrEmpty(archiveInfo.deviceId))
{
_tmpCName.text = archiveInfo.playerName;
_tmpCGrade.text = archiveInfo.playerGrade.ToString();
_tmpCLevel.text = archiveInfo.completedLevel.ToString();
_tmpCForce.text = archiveInfo.combatValue.ToString();
_tmpCTime.text = F.Utils.Time.ToDataTime(archiveInfo.timestamp).ToLocalTime().ToString();
}
}
else
{
_goCloud.SetActive(false);
}
}
//private int _uploadTimestamp;
private void OnUploadBtnClick()
{
//int second = _uploadTimestamp - Launch.Timestamp;
//if (second > 0)
//{
// ToastBox.ShowText($"不要频繁上传存档,剩余时间{F.Utils.Time.ToTimeString(second)}");
// return;
//}
MessageBox.ShowMessage("上传存档", "上传会覆盖云端存档",
() =>
{
//_uploadTimestamp = Launch.Timestamp + 300;
ArchiveProxy.Instance.Upload(false, OnUploadArchive);
OnCloseBtnClick();
},
() =>
{
});
}
private void OnUploadArchive(int error, string message)
{
if (error == 0)
{
ToastBox.ShowText("上传成功");
}
else
{
ToastBox.ShowText(message);
}
}
//private int _downloadTimestamp;
private void OnDownloadBtnClick()
{
//int second = _downloadTimestamp - Launch.Timestamp;
//if (second > 0)
//{
// ToastBox.ShowText($"不要频繁下载存档,剩余时间{F.Utils.Time.ToTimeString(second)}");
// return;
//}
MessageBox.ShowMessage("下载存档", "下载会覆盖本地存档",
() =>
{
//_downloadTimestamp = Launch.Timestamp + 3600;
ArchiveProxy.Instance.Download(OnDownloadArchive);
OnCloseBtnClick();
},
() =>
{
});
}
private void OnDownloadArchive(int error, string message)
{
if (error == 0)
{
ToastBox.ShowText("下载成功");
}
else
{
ToastBox.ShowText(message);
}
}
private void OnCloseBtnClick()
{
CloseWindow(this);
OpenWindow<SettingWindow>();
}
private void OnAutoTipsClick()
{
MessageBox.ShowMessage(KLocalization.GetLocalString(63), KLocalization.GetLocalString(64));
}
private void OnAutoToggleValueChanged(bool value)
{
//ArchiveProxy.Instance.autoUploadArchive = value;
}
#endregion
}
}