using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using XFramework;
///
/// 历史界面弹出显示记录详情信息
///
public class RecordDetailPanel : BasePanel
{
const string panelName = "Panel_RecordDeatail";
Text text_msg;//展示操作记录文字
Text text_Title;//记录标题
Text text_useTime;//录屏文件路径
Text text_videoPath;//录屏文件路径
Button button_playVideo;//播放录屏文件
OperaterRecording currentRecord;
public RecordDetailPanel() : base(new UIType(panelName))
{
}
//初始化界面引用和事件
protected override void InitEvent()
{
ActivePanel.FindChildTrans("Button_Close").GetComponent().onClick.AddListener(() => Pop());
text_msg = ActivePanel.FindChildTrans("Content_Text").GetComponent();
text_Title = ActivePanel.FindChildTrans("Text_title").GetComponent();
text_videoPath = ActivePanel.FindChildTrans("Text_videoPath").GetComponent();
text_useTime = ActivePanel.FindChildTrans("Text_useTime").GetComponent();
ActivePanel.FindChildTrans("Button_playVideo").gameObject.SetActive(false);/*GetComponent().onClick.AddListener(PlayVideo)*/; //赞不实现播放视频功能
LocalizationManager.LanguageChanged += OnLanguageChanged;
}
private void OnLanguageChanged()
{
if (currentRecord == null) return;
RebuildOperateMsg();
}
private void RebuildOperateMsg()
{
text_msg.text = "";
for (int i = 0; i < currentRecord.operaterMsg.Count; i++)
{
text_msg.text += $"{LocalizationManager.LocalizeOperateMsg(currentRecord.operaterMsg[i])}\r\n";
}
}
//根据数据初始化界面
public override void Change(object newData)
{
currentRecord = (OperaterRecording)newData;
OperaterRecording operaterRecording = currentRecord;
LocalizationManager.SetFormatted(text_Title, "{0} {1}完成{2}科目:{3}", operaterRecording.user, operaterRecording.date, LocalizationManager.DisplayName(operaterRecording.learnType), LocalizationManager.DisplayName(operaterRecording.subName));
int totalSeconds;
if (int.TryParse(operaterRecording.useTime, out totalSeconds))
{
int h = totalSeconds / 3600;
int m = (totalSeconds % 3600) / 60;
int s = totalSeconds % 60;
if (h > 0)
LocalizationManager.SetFormatted(text_useTime, "用时:{0}小时{1}分{2}秒", h, m, s);
else
LocalizationManager.SetFormatted(text_useTime, "用时:{0}分:{1}秒", m, s);
}
else
{
totalSeconds = LocalizationManager.ParseChineseDuration(operaterRecording.useTime);
if (totalSeconds >= 0)
{
int h = totalSeconds / 3600;
int m = (totalSeconds % 3600) / 60;
int s = totalSeconds % 60;
if (h > 0)
LocalizationManager.SetFormatted(text_useTime, "用时:{0}小时{1}分{2}秒", h, m, s);
else
LocalizationManager.SetFormatted(text_useTime, "用时:{0}分:{1}秒", m, s);
}
else
{
LocalizationManager.SetFormatted(text_useTime, "用时:{0}", operaterRecording.useTime);
}
}
RebuildOperateMsg();
if (!string.IsNullOrEmpty(operaterRecording.videoPath))//存在视频路径
{
if (File.Exists(operaterRecording.videoPath))//判断文件存在
{
LocalizationManager.SetFormatted(text_videoPath, "录屏视频:{0}", operaterRecording.videoPath);
//button_playVideo.interactable = true;
}
else //视频文件不存在
{
LocalizationManager.SetFormatted(text_videoPath, "录屏视频:{0}\r\n(视频文件已丢失,无法播放!)", operaterRecording.videoPath);
//button_playVideo.interactable = false;
}
}
else {
text_videoPath.text = LocalizationManager.Get("录屏视频:无");
//button_playVideo.interactable = false;
}
}
void PlayVideo()
{
}
public override void OnDestroy(bool isDestroy = false)
{
base.OnDestroy(isDestroy);
LocalizationManager.LanguageChanged -= OnLanguageChanged;
}
}