PC_OperatePanel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using QFramework;
  4. using Chiva.Toolkit.Function.NoBorder;
  5. using System.Collections.Generic;
  6. using System;
  7. using ChivaXR.Op;
  8. using System.Collections;
  9. using ChivaXR;
  10. using I2.Loc;
  11. using static SteamVR_TrackedObject;
  12. namespace QFramework
  13. {
  14. public class PC_OperatePanelData : UIPanelData
  15. {
  16. public string courseName = string.Empty;
  17. public bool OpenTitleBg;
  18. }
  19. public partial class PC_OperatePanel : UIPanel
  20. {
  21. List<OperationStepDataInfo> tmpStepListInfos;
  22. private string operateName;
  23. private AudioSource audioSource;
  24. /// <summary>
  25. /// 步骤数据代理
  26. /// </summary>
  27. private StepListProxy m_StepListProxy;
  28. #region 多语言适配
  29. private int CurrentStepID;
  30. public void RefrushLocalization()
  31. {
  32. if (LocalizationConfig.localization)
  33. {
  34. //左侧设备名称
  35. LocalizedString courseTitle = ScriptTerms.operatepanel.coursetitle;
  36. OperationTitle_Shadow.text = courseTitle;
  37. OperationTitle.text = courseTitle;
  38. RefrushOperationTitleUISize();
  39. //步骤标题
  40. LocalizedString SubTitle = CurrentStepID + "stepDescr";
  41. OperateStep.SubtitleText.text = SubTitle;
  42. }
  43. //TitleText.text = m_ParentIndex.ToString() + "." + m_Index.ToString() + " " + m_StepMsgInfo.stepName;
  44. }
  45. void OnEnable()
  46. {
  47. LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent;
  48. LocalizationManager_OnLocalizeEvent();
  49. }
  50. void OnDisEnable()
  51. {
  52. LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent;
  53. }
  54. private void LocalizationManager_OnLocalizeEvent()
  55. {
  56. if (LocalizationConfig.localization)
  57. {
  58. RefrushLocalization();
  59. }
  60. }
  61. #endregion
  62. protected override void OnInit(IUIData uiData = null)
  63. {
  64. m_StepListProxy = DAL.Instance.Get<StepListProxy>();
  65. mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData();
  66. OperationTitle_Shadow.text = mData.courseName;
  67. OperationTitle.text = mData.courseName;
  68. RefrushOperationTitleUISize();
  69. UserProxy tmpUserProxy = DAL.Instance.Get<UserProxy>();
  70. OperateStep.UserName.text = tmpUserProxy.userInfo.userName;
  71. OperateStep.HeadPortraitText.text = tmpUserProxy.userInfo.userName.Substring(0, 1);
  72. InitUI();
  73. InitLogic();
  74. }
  75. private void InitUI()
  76. {
  77. MinBtn.onClick.AddListener(() => WindowsSetting.Instance.OnMinBtnClick());
  78. SystemBtn.onClick.AddListener(() => UIKit.OpenPanel<PC_SettingPanel>());
  79. CloseBtn.onClick.AddListener(() =>
  80. {
  81. Application.Quit();
  82. });
  83. StartTips.gameObject.SetActive(true);
  84. }
  85. private void InitLogic()
  86. {
  87. audioSource = FindObjectOfType<AudioSource>();
  88. if (audioSource == null)
  89. {
  90. GameObject gameObject = new GameObject("AudioSource");
  91. audioSource = gameObject.AddComponent<AudioSource>();
  92. }
  93. switch (OperateSetting.Instance.m_CurrentOperationMode)
  94. {
  95. case OperationMode.Learn:
  96. operateName = "操作步骤";
  97. OperateStep.HelpBtn.gameObject.SetActive(false);
  98. OperateStep.AutoPlayBtn.gameObject.SetActive(true);
  99. OperateStep.ToolLibraryBtn.gameObject.SetActive(false);
  100. OperateStep.EndExam.gameObject.SetActive(false);
  101. //操作记录
  102. OperateStep.OperateLogBtn.gameObject.SetActive(false);
  103. //播放暂停
  104. StudyPanel.gameObject.SetActive(true);
  105. //关闭自动播放
  106. if (ProcessManagement.Instance.autoEnterNextProcess)
  107. {
  108. OperateStep.OnAutoPlayBtnClick();
  109. }
  110. break;
  111. case OperationMode.Practice:
  112. operateName = "操作步骤";
  113. OperateStep.HelpBtn.gameObject.SetActive(true);
  114. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  115. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  116. OperateStep.EndExam.gameObject.SetActive(false);
  117. break;
  118. case OperationMode.Exam:
  119. operateName = "操作步骤";
  120. TitleTextLayoutGroup.gameObject.SetActive(false);
  121. OperateStep.HelpBtn.gameObject.SetActive(false);
  122. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  123. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  124. OperateStep.EndExam.gameObject.SetActive(true);
  125. OperateStep.SubtitleBg.gameObject.SetActive(false);
  126. break;
  127. case OperationMode.Challenge:
  128. operateName = "操作步骤";
  129. OperateStep.HelpBtn.gameObject.SetActive(false);
  130. break;
  131. }
  132. tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(mData.courseName);
  133. Dictionary<string, List<OperationStepDataInfo>> tmpDicStepMsgInfos = m_StepListProxy.ProcessingData(tmpStepListInfos);
  134. OperateStep.gameObject.SetActive(true);
  135. //OperateStep.SetTitle(operateName);
  136. OperateStep.GenerateFirstStepItemList(tmpDicStepMsgInfos);
  137. if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
  138. {
  139. OperateStep.ExpandAllFirstStepItem();
  140. }
  141. }
  142. public void UpdateTitleText(string info)
  143. {
  144. TitleText.text = info;
  145. Mark.Init();
  146. if (TitleText.preferredWidth < 750)
  147. {
  148. Mark.GetComponent<RectTransform>().SetWidth(TitleText.preferredWidth);
  149. Mark.m_ParentWidth = 750;
  150. }
  151. else
  152. {
  153. Mark.GetComponent<RectTransform>().SetWidth(750);
  154. Mark.m_ParentWidth = 750;
  155. }
  156. LayoutRebuilder.ForceRebuildLayoutImmediate(TitleTextLayoutGroup);
  157. }
  158. public void RefrushOperationTitleUISize()
  159. {
  160. float width = OperationTitle.preferredWidth;
  161. TitleClampMask.Init();
  162. if (width < 450)
  163. {
  164. TitleClampMask.GetComponent<RectTransform>().SetWidth(width);
  165. TitleClampMask.m_ParentWidth = 450;
  166. }
  167. else
  168. {
  169. width = 450;
  170. TitleClampMask.GetComponent<RectTransform>().SetWidth(450);
  171. TitleClampMask.m_ParentWidth = 450;
  172. }
  173. TitleMask.rectTransform.SetWidth(width + 98);
  174. LeftLine.rectTransform.SetWidth(width + 100);
  175. RightLine.rectTransform.SetWidth(1920 - width - 75);
  176. }
  177. public void StartExam(int examTime)
  178. {
  179. ExamInfo.gameObject.SetActive(true);
  180. StartCoroutine(StartTime(examTime));
  181. OperateStep.StartOperation() ;
  182. }
  183. public void StartGame()
  184. {
  185. TitleTextLayoutGroup.gameObject.SetActive(true);
  186. OperateStep.StartOperation();
  187. }
  188. /// <summary>
  189. /// 计时器
  190. /// </summary>
  191. /// <returns></returns>
  192. public IEnumerator StartTime(int totolTime)
  193. {
  194. int sceond = totolTime * 60;
  195. while (sceond > 0)
  196. {
  197. yield return new WaitForSeconds(1);
  198. sceond--;
  199. ExamInfo.SetExamTime(sceond);
  200. }
  201. // 超时,弹出成绩单
  202. ExamManagerForPC.instance.ExamFinish();
  203. }
  204. OperationStepDataInfo tmpInfo;
  205. /// <summary>
  206. /// 据传进来的步骤ID处理展示具体的步骤名称
  207. /// </summary>
  208. /// <param name="stepID"></param>
  209. public void OnEnterProcessByStepID(int stepID)
  210. {
  211. //当前步骤ID
  212. CurrentStepID = stepID + 1;
  213. //刷新工具列表
  214. if (UIKit.GetPanel<ToolLibraryForm>() == null)
  215. {
  216. UIKit.OpenPanel<ToolLibraryForm>().Hide();
  217. }
  218. //流程进度
  219. OperateStep.ScheduleText.text = "<color=#20C7E3CC>" + CurrentStepID + "</color>" + "<color=#FFFFFF66>/" + ProcessManagement.Instance.processes.Count + "</color>";
  220. UIKit.GetPanel<ToolLibraryForm>().RefrushAllChoseTool();
  221. //刷新列表
  222. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn)
  223. {
  224. OperateStep.ShowSecondStepItemByStepId(stepID + 1);
  225. }
  226. else
  227. {
  228. //学习模式
  229. OperateStep.SetSecondStepItemSelectByStepId(stepID + 1);
  230. if (StudyPanel.isPause)
  231. {
  232. StudyPanel.Play();
  233. }
  234. }
  235. //考核模式不显示字幕
  236. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Exam)
  237. {
  238. tmpInfo = tmpStepListInfos.Find(info => int.Parse(info.id) == (stepID + 1));
  239. if (tmpInfo != null)
  240. {
  241. OperateStep.SubtitleBg.gameObject.SetActive(true);
  242. OperateStep.SubtitleText.text = tmpInfo.stepDescr;
  243. }
  244. }
  245. #region
  246. if (LocalizationConfig.localization)
  247. {
  248. RefrushLocalization();
  249. }
  250. #endregion
  251. }
  252. public void OnPrcessElementDisActive(ProcessElement processElement)
  253. {
  254. OperateStep.SubtitleBg.gameObject.SetActive(false);
  255. }
  256. /// <summary>
  257. /// 练习结束弹窗
  258. /// </summary>
  259. public void PracticeEnd()
  260. {
  261. PracticeResult.gameObject.SetActive(true);
  262. }
  263. /// <summary>
  264. /// 考核结束成绩表
  265. /// </summary>
  266. public void ExamEnd(List<ExamProcessElement> elements, float score, int useTime)
  267. {
  268. StopAllCoroutines();
  269. int index = ScoreInfo.transform.GetSiblingIndex();
  270. TitleBG.transform.SetSiblingIndex(index - 1);
  271. ScoreInfo.gameObject.SetActive(true);
  272. ScoreInfo.SetInfo(elements, score, useTime);
  273. }
  274. ///// <summary>
  275. ///// 设置练习模式提示按钮状态
  276. ///// </summary>
  277. ///// <param name="select"></param>
  278. //public void SetHelpBtnState(bool select)
  279. //{
  280. // OperateStep.SetHelpBtnState(select);
  281. //}
  282. protected override void OnOpen(IUIData uiData = null)
  283. {
  284. mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData();
  285. TitleBG.gameObject.SetActive(mData.OpenTitleBg);
  286. }
  287. protected override void OnShow()
  288. {
  289. }
  290. protected override void OnHide()
  291. {
  292. }
  293. protected override void OnClose()
  294. {
  295. if (UIKit.GetPanel<CameraPoseSetPanel>() != null) UIKit.ClosePanel<CameraPoseSetPanel>();
  296. }
  297. IEnumerator PlayAudioDelay(float duration, Action callBack)
  298. {
  299. yield return new WaitForSeconds(duration);
  300. callBack?.Invoke();
  301. }
  302. private void Update()
  303. {
  304. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F1))
  305. {
  306. if (UIKit.GetPanel<CameraPoseSetPanel>() == null) UIKit.OpenPanel<CameraPoseSetPanel>();
  307. }
  308. }
  309. }
  310. }