123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using Chiva.Toolkit.Function.NoBorder;
- using System.Collections.Generic;
- using System;
- using ChivaXR.Op;
- using System.Collections;
- using ChivaXR;
- using I2.Loc;
- using static SteamVR_TrackedObject;
- namespace QFramework
- {
- public class PC_OperatePanelData : UIPanelData
- {
- public string courseName = string.Empty;
- public bool OpenTitleBg;
- }
- public partial class PC_OperatePanel : UIPanel
- {
- List<OperationStepDataInfo> tmpStepListInfos;
- private string operateName;
- private AudioSource audioSource;
- /// <summary>
- /// 步骤数据代理
- /// </summary>
- private StepListProxy m_StepListProxy;
- #region 多语言适配
- private int CurrentStepID;
- public void RefrushLocalization()
- {
- if (LocalizationConfig.localization)
- {
- //左侧设备名称
- LocalizedString courseTitle = ScriptTerms.operatepanel.coursetitle;
- OperationTitle_Shadow.text = courseTitle;
- OperationTitle.text = courseTitle;
- RefrushOperationTitleUISize();
- //步骤标题
- LocalizedString SubTitle = CurrentStepID + "stepDescr";
- OperateStep.SubtitleText.text = SubTitle;
- }
- //TitleText.text = m_ParentIndex.ToString() + "." + m_Index.ToString() + " " + m_StepMsgInfo.stepName;
- }
- void OnEnable()
- {
- LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent;
- LocalizationManager_OnLocalizeEvent();
- }
- void OnDisEnable()
- {
- LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent;
- }
- private void LocalizationManager_OnLocalizeEvent()
- {
- if (LocalizationConfig.localization)
- {
- RefrushLocalization();
- }
- }
- #endregion
- protected override void OnInit(IUIData uiData = null)
- {
- m_StepListProxy = DAL.Instance.Get<StepListProxy>();
- mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData();
- OperationTitle_Shadow.text = mData.courseName;
- OperationTitle.text = mData.courseName;
- RefrushOperationTitleUISize();
- UserProxy tmpUserProxy = DAL.Instance.Get<UserProxy>();
- OperateStep.UserName.text = tmpUserProxy.userInfo.userName;
- OperateStep.HeadPortraitText.text = tmpUserProxy.userInfo.userName.Substring(0, 1);
- InitUI();
- InitLogic();
- }
- private void InitUI()
- {
- MinBtn.onClick.AddListener(() => WindowsSetting.Instance.OnMinBtnClick());
- SystemBtn.onClick.AddListener(() => UIKit.OpenPanel<PC_SettingPanel>());
- CloseBtn.onClick.AddListener(() =>
- {
- Application.Quit();
- });
- StartTips.gameObject.SetActive(true);
- }
- private void InitLogic()
- {
- audioSource = FindObjectOfType<AudioSource>();
- if (audioSource == null)
- {
- GameObject gameObject = new GameObject("AudioSource");
- audioSource = gameObject.AddComponent<AudioSource>();
- }
- switch (OperateSetting.Instance.m_CurrentOperationMode)
- {
- case OperationMode.Learn:
- operateName = "操作步骤";
- OperateStep.HelpBtn.gameObject.SetActive(false);
- OperateStep.AutoPlayBtn.gameObject.SetActive(true);
- OperateStep.ToolLibraryBtn.gameObject.SetActive(false);
- OperateStep.EndExam.gameObject.SetActive(false);
- //操作记录
- OperateStep.OperateLogBtn.gameObject.SetActive(false);
- //播放暂停
- StudyPanel.gameObject.SetActive(true);
- //关闭自动播放
- if (ProcessManagement.Instance.autoEnterNextProcess)
- {
- OperateStep.OnAutoPlayBtnClick();
- }
- break;
- case OperationMode.Practice:
- operateName = "操作步骤";
- OperateStep.HelpBtn.gameObject.SetActive(true);
- OperateStep.AutoPlayBtn.gameObject.SetActive(false);
- OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
- OperateStep.EndExam.gameObject.SetActive(false);
- break;
- case OperationMode.Exam:
- operateName = "操作步骤";
- TitleTextLayoutGroup.gameObject.SetActive(false);
- OperateStep.HelpBtn.gameObject.SetActive(false);
- OperateStep.AutoPlayBtn.gameObject.SetActive(false);
- OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
- OperateStep.EndExam.gameObject.SetActive(true);
- OperateStep.SubtitleBg.gameObject.SetActive(false);
- break;
- case OperationMode.Challenge:
- operateName = "操作步骤";
- OperateStep.HelpBtn.gameObject.SetActive(false);
- break;
- }
- tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(mData.courseName);
- Dictionary<string, List<OperationStepDataInfo>> tmpDicStepMsgInfos = m_StepListProxy.ProcessingData(tmpStepListInfos);
- OperateStep.gameObject.SetActive(true);
- //OperateStep.SetTitle(operateName);
- OperateStep.GenerateFirstStepItemList(tmpDicStepMsgInfos);
- if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
- {
- OperateStep.ExpandAllFirstStepItem();
- }
- }
- public void UpdateTitleText(string info)
- {
- TitleText.text = info;
- Mark.Init();
- if (TitleText.preferredWidth < 750)
- {
- Mark.GetComponent<RectTransform>().SetWidth(TitleText.preferredWidth);
- Mark.m_ParentWidth = 750;
- }
- else
- {
- Mark.GetComponent<RectTransform>().SetWidth(750);
- Mark.m_ParentWidth = 750;
- }
- LayoutRebuilder.ForceRebuildLayoutImmediate(TitleTextLayoutGroup);
- }
- public void RefrushOperationTitleUISize()
- {
- float width = OperationTitle.preferredWidth;
- TitleClampMask.Init();
- if (width < 450)
- {
- TitleClampMask.GetComponent<RectTransform>().SetWidth(width);
- TitleClampMask.m_ParentWidth = 450;
- }
- else
- {
- width = 450;
- TitleClampMask.GetComponent<RectTransform>().SetWidth(450);
- TitleClampMask.m_ParentWidth = 450;
- }
- TitleMask.rectTransform.SetWidth(width + 98);
- LeftLine.rectTransform.SetWidth(width + 100);
- RightLine.rectTransform.SetWidth(1920 - width - 75);
- }
- public void StartExam(int examTime)
- {
- ExamInfo.gameObject.SetActive(true);
- StartCoroutine(StartTime(examTime));
- OperateStep.StartOperation() ;
- }
- public void StartGame()
- {
- TitleTextLayoutGroup.gameObject.SetActive(true);
- OperateStep.StartOperation();
- }
- /// <summary>
- /// 计时器
- /// </summary>
- /// <returns></returns>
- public IEnumerator StartTime(int totolTime)
- {
- int sceond = totolTime * 60;
- while (sceond > 0)
- {
- yield return new WaitForSeconds(1);
- sceond--;
- ExamInfo.SetExamTime(sceond);
- }
- // 超时,弹出成绩单
- ExamManagerForPC.instance.ExamFinish();
- }
- OperationStepDataInfo tmpInfo;
- /// <summary>
- /// 据传进来的步骤ID处理展示具体的步骤名称
- /// </summary>
- /// <param name="stepID"></param>
- public void OnEnterProcessByStepID(int stepID)
- {
- //当前步骤ID
- CurrentStepID = stepID + 1;
- //刷新工具列表
- if (UIKit.GetPanel<ToolLibraryForm>() == null)
- {
- UIKit.OpenPanel<ToolLibraryForm>().Hide();
- }
- //流程进度
- OperateStep.ScheduleText.text = "<color=#20C7E3CC>" + CurrentStepID + "</color>" + "<color=#FFFFFF66>/" + ProcessManagement.Instance.processes.Count + "</color>";
- UIKit.GetPanel<ToolLibraryForm>().RefrushAllChoseTool();
- //刷新列表
- if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn)
- {
- OperateStep.ShowSecondStepItemByStepId(stepID + 1);
- }
- else
- {
- //学习模式
- OperateStep.SetSecondStepItemSelectByStepId(stepID + 1);
- if (StudyPanel.isPause)
- {
- StudyPanel.Play();
- }
- }
- //考核模式不显示字幕
- if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Exam)
- {
- tmpInfo = tmpStepListInfos.Find(info => int.Parse(info.id) == (stepID + 1));
- if (tmpInfo != null)
- {
- OperateStep.SubtitleBg.gameObject.SetActive(true);
- OperateStep.SubtitleText.text = tmpInfo.stepDescr;
- }
- }
- #region
- if (LocalizationConfig.localization)
- {
- RefrushLocalization();
- }
- #endregion
- }
- public void OnPrcessElementDisActive(ProcessElement processElement)
- {
- OperateStep.SubtitleBg.gameObject.SetActive(false);
- }
- /// <summary>
- /// 练习结束弹窗
- /// </summary>
- public void PracticeEnd()
- {
- PracticeResult.gameObject.SetActive(true);
- }
- /// <summary>
- /// 考核结束成绩表
- /// </summary>
- public void ExamEnd(List<ExamProcessElement> elements, float score, int useTime)
- {
- StopAllCoroutines();
- int index = ScoreInfo.transform.GetSiblingIndex();
- TitleBG.transform.SetSiblingIndex(index - 1);
- ScoreInfo.gameObject.SetActive(true);
- ScoreInfo.SetInfo(elements, score, useTime);
- }
- ///// <summary>
- ///// 设置练习模式提示按钮状态
- ///// </summary>
- ///// <param name="select"></param>
- //public void SetHelpBtnState(bool select)
- //{
- // OperateStep.SetHelpBtnState(select);
- //}
- protected override void OnOpen(IUIData uiData = null)
- {
- mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData();
- TitleBG.gameObject.SetActive(mData.OpenTitleBg);
- }
- protected override void OnShow()
- {
- }
- protected override void OnHide()
- {
- }
- protected override void OnClose()
- {
- if (UIKit.GetPanel<CameraPoseSetPanel>() != null) UIKit.ClosePanel<CameraPoseSetPanel>();
- }
- IEnumerator PlayAudioDelay(float duration, Action callBack)
- {
- yield return new WaitForSeconds(duration);
- callBack?.Invoke();
- }
- private void Update()
- {
- //打开设置相机位置
- if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F1))
- {
- if (UIKit.GetPanel<CameraPoseSetPanel>() == null) UIKit.OpenPanel<CameraPoseSetPanel>();
- }
- //题库设置单选/多选/判断
- else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F2))
- {
- }
- //题库设置图文
- else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F3))
- {
- }
- }
- }
- }
|