unityzgy/Assets/Scripts/UIScripts/Teacher/HistoryPanel.cs
ayuan9957 bf12e02276 feat: 多语言本地化系统 - 支持中/英/法/俄实时切换
- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg)
- LoginPanel: InputField placeholder本地化、字体颜色保持
- HistoryPanel: 用时数据本地化、placeholder本地化
- RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建)
- AppraiseWindowBase: 评价等级本地化、操作消息重建
- EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized
- StudentOperateRecorder: 新增InjectOperateMsgLocalized方法
- LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选
- 字体切换时保留颜色和verticalOverflow
2026-07-16 10:05:59 +08:00

253 lines
7.3 KiB
C#
Raw 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;
using XFramework;
public class HistoryPanel : BasePanel
{
const string panelName = "Panel_history";
Button button_return;
Button button_enquire;
Toggle toggle_selectTime;
InputField inputField_user;
InputField inputField_startDate;
InputField inputField_endDate;
PromptTextCtrl promptText;
List< OperaterRecording> allMsgs;//数据库中读取的所有数据
List<OperaterRecording> currentShowMsgs;//当前正在展示的所有数据
ShowMsgByPageBase pageCtrl;
public HistoryPanel() : base(new UIType(panelName))
{
}
protected override void InitEvent()
{
button_return = ActivePanel.Find("Button_return").GetComponent<Button>();
button_enquire = ActivePanel.Find("Button_enquire").GetComponent<Button>();
toggle_selectTime = ActivePanel.Find("Toggle_timeOn").GetComponent<Toggle>();
inputField_user = ActivePanel.Find("InputField_name").GetComponent<InputField>();
inputField_startDate = ActivePanel.Find("InputField_dateStart").GetComponent<InputField>();
inputField_endDate = ActivePanel.Find("InputField_dateFinished").GetComponent<InputField>();
promptText = ActivePanel.FindChildTrans("Text_Prompt").GetComponent<PromptTextCtrl>();
pageCtrl = ActivePanel.Find("Content").GetComponent<ShowMsgByPageBase>();
button_return.onClick.AddListener(ReturnLastPanel);
button_enquire.onClick.AddListener(EnquireRecord);
ConfigureInputFieldPlaceholders();
LocalizationManager.LanguageChanged += OnLanguageChanged;
}
private void ConfigureInputFieldPlaceholders()
{
InputField[] inputs = { inputField_user, inputField_startDate, inputField_endDate };
string[] keys = { "请输入姓名...", "日期格式xxxx-xx-xx", "日期格式xxxx-xx-xx" };
for (int i = 0; i < inputs.Length; i++)
{
if (inputs[i] != null && inputs[i].placeholder != null)
{
Text ph = inputs[i].placeholder.GetComponent<Text>();
if (ph != null)
{
Color c = ph.color;
ph.font = LocalizationManager.UIFont;
ph.color = c;
ph.verticalOverflow = VerticalWrapMode.Overflow;
ph.text = LocalizationManager.Get(keys[i]);
}
}
}
}
private void OnLanguageChanged()
{
ConfigureInputFieldPlaceholders();
// Force a refresh of visible rows to re-apply localized duration.
if (pageCtrl != null && currentShowMsgs != null)
pageCtrl.ShowData(currentShowMsgs.Count);
}
public override void OnStart()
{
base.OnStart();
// detailWindows.gameObject.SetActive(false);
currentShowMsgs = new List<OperaterRecording>();
allMsgs = new List<OperaterRecording>();
OperaterRecording [] operaters= DBManager.Instance.GetAllResultMsg();
if (operaters == null) return;//不存在数据
for (int i = 0; i < operaters.Length; i++)
{
allMsgs.Add(operaters[i]);
}
currentShowMsgs = allMsgs;
pageCtrl.InitPanel(currentShowMsgs.Count, InitChild,UpdateChild);
}
//子物体赋值更新方法 初始化后调用
private void UpdateChild(int index,GameObject go)
{
MessagePrefabCtrl prefabCtrl= go.GetComponent<MessagePrefabCtrl>();
prefabCtrl.SetTextMsg(index, new string[] { currentShowMsgs[index].user, currentShowMsgs[index].subName, currentShowMsgs[index].date, currentShowMsgs[index].learnType, currentShowMsgs[index].useTime, currentShowMsgs[index].appraiseLevel });
LocalizationManager.SetDuration(prefabCtrl.MessTexts[4], currentShowMsgs[index].useTime);
}
//初始化子物体 绑定子物体上的按钮监听案件 子物体创建时调用
private void InitChild(GameObject go)
{
MessagePrefabCtrl prefabCtrl = go.GetComponent<MessagePrefabCtrl>();
prefabCtrl.RegisteButtonEvent(ChildShowDetailButtonOn, ChildDeleteButtonOn);
}
//子物体删除按钮 index 是待删除的数据索引
private void ChildDeleteButtonOn(int index)
{
bool result= DBManager.Instance.DeleteRecord(currentShowMsgs[index]);
if (result)
{
if (currentShowMsgs == allMsgs)
{
currentShowMsgs.RemoveAt(index);
}
else
{
allMsgs.Remove(currentShowMsgs[index]);
currentShowMsgs.RemoveAt(index);
}
pageCtrl.RemoveChild(1);
}
else
{
Debug.Log("历史记录数据删除失败");
}
}
//子物体显示详情按钮 index 是待数据显示的索引
private void ChildShowDetailButtonOn(int index)
{
ShowDetailPanel(currentShowMsgs[index]);
Debug.Log($"展示{currentShowMsgs[index].user}在{currentShowMsgs[index].date}完成的训练信息");
//Push(new )//
}
//根据条件查找记录 未输入条件时显示所有记录
private void EnquireRecord()
{
//if (string.IsNullOrEmpty(inputField_user.text))
//{
// promptText.SetPrompt("请输入需查询的学员户名!", Color.red, 2f);
// return;
//}
string inputUser = inputField_user.text.Trim();
if (string.IsNullOrEmpty(inputUser) && currentShowMsgs != allMsgs)
{
currentShowMsgs = allMsgs;
pageCtrl.ShowData(currentShowMsgs.Count);
}
else
{
currentShowMsgs = new List<OperaterRecording>();
for (int i = 0; i < allMsgs.Count; i++)
{
if (allMsgs[i].user == inputUser)
currentShowMsgs.Add(allMsgs[i]);
}
if (currentShowMsgs.Count == 0)
promptText.SetPrompt(LocalizationManager.Get("未查询到符合条件的记录!"), Color.green, 2f);
pageCtrl.ShowData(currentShowMsgs.Count);
}
//if (toggle_selectTime.isOn)
//{
// DateTime dateTime;
// if (!DateTime.TryParse(inputField_startDate.text, out dateTime) || !DateTime.TryParse(inputField_endDate.text, out dateTime))
// {
// promptText.SetPrompt("请输入有效的起止日期格式为xxxx-xx-xx!", Color.red, 2f);
// return;
// }
// records = DBManager.Instance.GetAllResultMsg();
//}
//else
// records = DBManager.Instance.EnquireRecord(inputField_user.text);
}
//返回上一界面
private void ReturnLastPanel()
{
Pop();
Push(new DaoHangPanel()).Change((float)UserType.Teacher);
}
//显示详情信息
private void ShowDetailPanel(OperaterRecording recordClass)
{
Push(new RecordDetailPanel()).Change(recordClass);
//detailWindows.gameObject.SetActive(true);
}
public override void OnDestroy(bool isDestroy = false)
{
base.OnDestroy(isDestroy);
LocalizationManager.LanguageChanged -= OnLanguageChanged;
}
}