using Public.File; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using XFramework.Objects; /// /// 教员端评估窗口控制基类 /// public class AppraiseWindowBase : MonoBehaviour { public Button button_Close; public Button button_send; protected PromptTextCtrl promptText_sendButton;//发送按钮的提示文字 public Button button_cunchu; protected PromptTextCtrl promptText_saveButton;//发送按钮的提示文字 public Button button_selectFile; public InputField inputField_path; public Text text_userTitle; public Text text_OperateMsg;//显示学员端传回的操作信息描述 public Dropdown dropdown_Appraise;//教员评价下拉菜单 OnlineStudent student;//学员的信息 NetAnswerSheet answerSheet;//学员传回的学习信息 string date;//传回记录的时间 用于生成记录时组合成为唯一键 protected NetAppraiseData netAppraiseData;//评价结果 bool sendAppraiseRes;//发送过了结果信息 // Start is called before the first frame update //创建时先绑定相关事件 protected virtual void Awake() { button_Close.onClick.AddListener(ClosePanelButton); button_send.onClick.AddListener(SendApptaiseButtonOn); button_cunchu.onClick.AddListener(SaveResult); promptText_saveButton = button_cunchu.GetComponentInChildren(); promptText_sendButton = button_send.GetComponentInChildren(); button_send.interactable = false; button_selectFile.onClick.AddListener(OpenWindowSelectFile); dropdown_Appraise.onValueChanged.AddListener(TeacherSelectAppraise); text_OperateMsg.text = ""; LocalizationManager.LanguageChanged += OnLanguageChanged; } private void OnLanguageChanged() { if (answerSheet == null) return; text_OperateMsg.text = ""; for (int i = 0; i < answerSheet.errors.Count; i++) { text_OperateMsg.text += $"{LocalizationManager.LocalizeOperateMsg(answerSheet.errors[i])}\r\n"; } } //选择了评价后 可以发送 void TeacherSelectAppraise( int value) { button_send.interactable = value != 0;//未选择时不可用 } //指定视频路径 private void OpenWindowSelectFile() { string filePath = OpenWindow.GetFilePath("指定录屏文件", null, "Video Files(*.mp4)\0*.mp4\0"); inputField_path.text = filePath; } //关闭按钮按下时 隐藏本界面 发送教员结束评价(无结果) 清空界面 protected void ClosePanelButton() { EventCenter.Instance.RemoveEnvetListener("StuCloseResultPanel", StudentClosePanel); if (!sendAppraiseRes) //没有发送过评价时 发送放弃评价消息 { netAppraiseData = new NetAppraiseData(); netAppraiseData.appraised = false; TCPManager.Instance.SendAppraise(student.ip, netAppraiseData); } Clear(); LocalizationManager.LanguageChanged -= OnLanguageChanged; ObjectPool.Instance.Destroy(this.gameObject); } /// /// 发送按钮按下时 发送评价结果到学员端 /// private void SendApptaiseButtonOn() { netAppraiseData = new NetAppraiseData(); if (dropdown_Appraise.value == 0)//未选择评价 { promptText_sendButton.SetPrompt(LocalizationManager.Get("未评价时无需发送!"), Color.red, 2f); return; } else { PrepareAppraiseResult(); } sendAppraiseRes = true; TCPManager.Instance.SendAppraise(student.ip, netAppraiseData); } //梳理评估结果 修理所展开时需base后重写 protected virtual void PrepareAppraiseResult() { netAppraiseData.appraised = true; netAppraiseData.appraiseLevel = dropdown_Appraise.captionText.text; } //存储结果 只能存储一次 存储成功后提示成功 失败时肯能是因为数据库的原因 可以再次尝试 private void SaveResult() { OperaterRecording recording = new OperaterRecording(); recording.user = student.user; recording.date = date; recording.appraiseLevel = dropdown_Appraise.captionText.text; switch (student.state) { case LearnState.learning: recording.learnType = "训练"; break; case LearnState.examing: recording.learnType = "考核"; break; default: recording.learnType = ""; break; } recording.useTime = answerSheet.totleTime; recording.operaterMsg = answerSheet.errors; recording.videoPath = inputField_path.text; recording.subName = student.subName; bool result= DBManager.Instance.InsterResultMsg(recording); if (result) { promptText_saveButton.SetPrompt(LocalizationManager.Get("保存成功!"), Color.green, 2f); button_cunchu.interactable = false; } else { promptText_saveButton.SetPrompt(LocalizationManager.Get("保存失败,数据库异常!"), Color.red, 2f); } } /// /// 外部注入成绩基础数据 /// /// public virtual void SetResultMsg(NetAnswerSheet value, OnlineStudent onlineStudent) { answerSheet = value; date = System.DateTime.Now.ToString("G"); student = onlineStudent; EventCenter.Instance.AddEventListener("StuCloseResultPanel", StudentClosePanel); ShowStudentMsg(onlineStudent,value.totleTime); ShowMsg(value); } //某学员关闭成绩显示面板 不在响应结果消息 private void StudentClosePanel(string ip) { if (ip == student.ip)//该学员关闭了成绩显示面板 { button_send.interactable = false; EventCenter.Instance.RemoveEnvetListener("StuCloseResultPanel", StudentClosePanel); } promptText_sendButton.SetPrompt(LocalizationManager.Get("学员已关闭成绩显示面板"), Color.red); } //显示学员训练概要信息 protected void ShowStudentMsg(OnlineStudent onlineStudent,string useTime) { string state = onlineStudent.state == LearnState.learning ? LocalizationManager.Get("训练") : LocalizationManager.Get("考核"); int totalSeconds; if (int.TryParse(useTime, out totalSeconds)) { int h = totalSeconds / 3600; int m = (totalSeconds % 3600) / 60; int s = totalSeconds % 60; if (h > 0) LocalizationManager.SetFormatted(text_userTitle, "学员:{0} 完成{1}科目({2}) 用时:{3}小时{4}分{5}秒", onlineStudent.user, state, LocalizationManager.DisplayName(onlineStudent.subName), h, m, s); else LocalizationManager.SetFormatted(text_userTitle, "学员:{0} 完成{1}科目({2}) 用时:{3}分:{4}秒", onlineStudent.user, state, LocalizationManager.DisplayName(onlineStudent.subName), m, s); } else { LocalizationManager.SetFormatted(text_userTitle, "学员:{0} 完成{1}科目({2}) 用时:{3}", onlineStudent.user, state, LocalizationManager.DisplayName(onlineStudent.subName), useTime); } } //显示学员端上传的结果数据 protected void ShowMsg(NetAnswerSheet netResult) { for (int i = 0; i < netResult.errors.Count; i++) { text_OperateMsg.text += $"{LocalizationManager.LocalizeOperateMsg(netResult.errors[i])}\r\n"; } } //清空界面数据 protected virtual void Clear() { inputField_path.text = ""; text_OperateMsg.text = ""; text_userTitle.text = ""; dropdown_Appraise.value = 0; sendAppraiseRes = false; button_cunchu.interactable = true; } }