PC_OperatePanel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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.ToolBackPackBtn.gameObject.SetActive(false);
  101. OperateStep.EndExam.gameObject.SetActive(false);
  102. //操作记录
  103. OperateStep.OperateLogBtn.gameObject.SetActive(false);
  104. OperateStep.CheckBtn.gameObject.SetActive(false);
  105. OperateStep.InstructBtn.gameObject.SetActive(false);
  106. //播放暂停
  107. StudyPanel.gameObject.SetActive(true);
  108. //关闭自动播放
  109. if (ProcessManagement.Instance.autoEnterNextProcess)
  110. {
  111. OperateStep.OnAutoPlayBtnClick();
  112. }
  113. break;
  114. case OperationMode.Practice:
  115. operateName = "操作步骤";
  116. OperateStep.HelpBtn.gameObject.SetActive(true);
  117. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  118. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  119. OperateStep.ToolBackPackBtn.gameObject.SetActive(true);
  120. OperateStep.EndExam.gameObject.SetActive(false);
  121. OperateStep.CheckBtn.gameObject.SetActive(false);
  122. OperateStep.InstructBtn.gameObject.SetActive(false);
  123. break;
  124. case OperationMode.Exam:
  125. operateName = "操作步骤";
  126. TitleTextLayoutGroup.gameObject.SetActive(false);
  127. OperateStep.HelpBtn.gameObject.SetActive(false);
  128. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  129. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  130. OperateStep.ToolBackPackBtn.gameObject.SetActive(true);
  131. OperateStep.EndExam.gameObject.SetActive(true);
  132. OperateStep.SubtitleBg.gameObject.SetActive(false);
  133. OperateStep.CheckBtn.gameObject.SetActive(false);
  134. OperateStep.InstructBtn.gameObject.SetActive(false);
  135. break;
  136. case OperationMode.FreeParctice:
  137. operateName = "操作步骤";
  138. OperateStep.HelpBtn.gameObject.SetActive(false);
  139. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  140. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  141. OperateStep.EndExam.gameObject.SetActive(false);
  142. OperateStep.CheckBtn.gameObject.SetActive(true);
  143. OperateStep.InstructBtn.gameObject.SetActive(true);
  144. break;
  145. case OperationMode.FreeExam:
  146. operateName = "操作步骤";
  147. TitleTextLayoutGroup.gameObject.SetActive(false);
  148. OperateStep.HelpBtn.gameObject.SetActive(false);
  149. OperateStep.AutoPlayBtn.gameObject.SetActive(false);
  150. OperateStep.ToolLibraryBtn.gameObject.SetActive(true);
  151. OperateStep.EndExam.gameObject.SetActive(true);
  152. OperateStep.SubtitleBg.gameObject.SetActive(false);
  153. OperateStep.CheckBtn.gameObject.SetActive(true);
  154. OperateStep.InstructBtn.gameObject.SetActive(true);
  155. break;
  156. case OperationMode.Challenge:
  157. operateName = "操作步骤";
  158. OperateStep.HelpBtn.gameObject.SetActive(false);
  159. break;
  160. }
  161. tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(mData.courseName);
  162. Dictionary<string, List<OperationStepDataInfo>> tmpDicStepMsgInfos = m_StepListProxy.ProcessingData(tmpStepListInfos);
  163. OperateStep.gameObject.SetActive(true);
  164. OperateStep.GenerateFirstStepItemList(tmpDicStepMsgInfos);
  165. if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn)
  166. {
  167. OperateStep.ExpandAllFirstStepItem();
  168. }
  169. }
  170. public void UpdateTitleText(string info)
  171. {
  172. TitleText.text = info;
  173. Mark.Init();
  174. if (TitleText.preferredWidth < 750)
  175. {
  176. Mark.GetComponent<RectTransform>().SetWidth(TitleText.preferredWidth);
  177. Mark.m_ParentWidth = 750;
  178. }
  179. else
  180. {
  181. Mark.GetComponent<RectTransform>().SetWidth(750);
  182. Mark.m_ParentWidth = 750;
  183. }
  184. LayoutRebuilder.ForceRebuildLayoutImmediate(TitleTextLayoutGroup);
  185. }
  186. public void RefrushOperationTitleUISize()
  187. {
  188. float width = OperationTitle.preferredWidth;
  189. TitleClampMask.Init();
  190. if (width < 450)
  191. {
  192. TitleClampMask.GetComponent<RectTransform>().SetWidth(width);
  193. TitleClampMask.m_ParentWidth = 450;
  194. }
  195. else
  196. {
  197. width = 450;
  198. TitleClampMask.GetComponent<RectTransform>().SetWidth(450);
  199. TitleClampMask.m_ParentWidth = 450;
  200. }
  201. TitleMask.rectTransform.SetWidth(width + 98);
  202. LeftLine.rectTransform.SetWidth(width + 100);
  203. RightLine.rectTransform.SetWidth(1920 - width - 75);
  204. }
  205. public void StartExam(int examTime)
  206. {
  207. ExamInfo.gameObject.SetActive(true);
  208. StartCoroutine(StartTime(examTime));
  209. OperateStep.StartOperation();
  210. }
  211. public void StartGame()
  212. {
  213. TitleTextLayoutGroup.gameObject.SetActive(true);
  214. //练习模式开启提示功能
  215. if(OperateSetting.Instance.m_CurrentOperationMode==OperationMode.Practice)
  216. {
  217. OperateStep.OnHelpBtnClick();
  218. }
  219. OperateStep.StartOperation();
  220. }
  221. /// <summary>
  222. /// 计时器
  223. /// </summary>
  224. /// <returns></returns>
  225. public IEnumerator StartTime(int totolTime)
  226. {
  227. int sceond = totolTime * 60;
  228. while (sceond > 0)
  229. {
  230. yield return new WaitForSeconds(1);
  231. sceond--;
  232. ExamInfo.SetExamTime(sceond);
  233. }
  234. // 超时,弹出成绩单
  235. ExamManagerForPC.instance.ExamFinish();
  236. }
  237. OperationStepDataInfo tmpInfo;
  238. /// <summary>
  239. /// 据传进来的步骤ID处理展示具体的步骤名称
  240. /// </summary>
  241. /// <param name="stepID"></param>
  242. public void OnEnterProcessByStepID(int stepID)
  243. {
  244. //当前步骤ID
  245. CurrentStepID = stepID + 1;
  246. //刷新工具列表
  247. //if (UIKit.GetPanel<ToolLibraryForm>() == null)
  248. //{
  249. // UIKit.OpenPanel<ToolLibraryForm>().Hide();
  250. //}
  251. //流程进度
  252. OperateStep.ScheduleText.text = "<color=#20C7E3CC>" + CurrentStepID + "</color>" + "<color=#FFFFFF66>/" + ProcessManagement.Instance.processes.Count + "</color>";
  253. //if (UIKit.GetPanel<ToolLibraryForm>() != null)
  254. //{
  255. // UIKit.GetPanel<ToolLibraryForm>().RefrushAllChoseTool();
  256. //}
  257. ToolLibraryForm.RefrushAllChoseTool();
  258. //刷新列表
  259. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn)
  260. {
  261. OperateStep.ShowSecondStepItemByStepId(stepID + 1);
  262. }
  263. else
  264. {
  265. //学习模式
  266. OperateStep.SetSecondStepItemSelectByStepId(stepID + 1);
  267. if (StudyPanel.isPause)
  268. {
  269. StudyPanel.Play();
  270. }
  271. }
  272. //考核模式不显示字幕
  273. if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Exam)
  274. {
  275. tmpInfo = tmpStepListInfos.Find(info => int.Parse(info.id) == (stepID + 1));
  276. if (tmpInfo != null)
  277. {
  278. OperateStep.SubtitleBg.gameObject.SetActive(true);
  279. OperateStep.SubtitleText.text = tmpInfo.stepDescr;
  280. }
  281. }
  282. #region
  283. if (LocalizationConfig.localization)
  284. {
  285. RefrushLocalization();
  286. }
  287. #endregion
  288. }
  289. public void OnPrcessElementDisActive(ProcessElement processElement)
  290. {
  291. OperateStep.SubtitleBg.gameObject.SetActive(false);
  292. }
  293. /// <summary>
  294. /// 练习结束弹窗
  295. /// </summary>
  296. public void PracticeEnd()
  297. {
  298. PracticeResult.gameObject.SetActive(true);
  299. }
  300. /// <summary>
  301. /// 考核结束成绩表
  302. /// </summary>
  303. public void ExamEnd(List<ExamProcessElement> elements, float score, int useTime)
  304. {
  305. StopAllCoroutines();
  306. int index = ScoreInfo.transform.GetSiblingIndex();
  307. TitleBG.transform.SetSiblingIndex(index - 1);
  308. ScoreInfo.gameObject.SetActive(true);
  309. ScoreInfo.SetInfo(elements, score, useTime);
  310. }
  311. ///// <summary>
  312. ///// 设置练习模式提示按钮状态
  313. ///// </summary>
  314. ///// <param name="select"></param>
  315. //public void SetHelpBtnState(bool select)
  316. //{
  317. // OperateStep.SetHelpBtnState(select);
  318. //}
  319. protected override void OnOpen(IUIData uiData = null)
  320. {
  321. mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData();
  322. TitleBG.gameObject.SetActive(mData.OpenTitleBg);
  323. }
  324. protected override void OnShow()
  325. {
  326. }
  327. protected override void OnHide()
  328. {
  329. }
  330. protected override void OnClose()
  331. {
  332. if (UIKit.GetPanel<CameraPoseSetPanel>() != null) UIKit.ClosePanel<CameraPoseSetPanel>();
  333. }
  334. IEnumerator PlayAudioDelay(float duration, Action callBack)
  335. {
  336. yield return new WaitForSeconds(duration);
  337. callBack?.Invoke();
  338. }
  339. private void Update()
  340. {
  341. //打开设置相机位置
  342. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F1))
  343. {
  344. if (UIKit.GetPanel<CameraPoseSetPanel>() == null) UIKit.OpenPanel<CameraPoseSetPanel>();
  345. }
  346. //题库设置单选/多选/判断
  347. else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F2))
  348. {
  349. if (UIKit.GetPanel<QuestionSetPanel>() != null) return;
  350. if (UIKit.GetPanel<ImageAndTextNameSetPanel>() != null)
  351. {
  352. UIKit.ClosePanel<ImageAndTextNameSetPanel>();
  353. }
  354. UIKit.OpenPanel<QuestionSetPanel>(UILevel.PopUI, new QuestionSetPanelData());
  355. }
  356. //题库设置图文
  357. else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F3))
  358. {
  359. if (UIKit.GetPanel<ImageAndTextNameSetPanel>() != null) return;
  360. if (UIKit.GetPanel<QuestionSetPanel>() != null)
  361. {
  362. UIKit.ClosePanel<QuestionSetPanel>();
  363. }
  364. UIKit.OpenPanel<ImageAndTextNameSetPanel>(UILevel.PopUI);
  365. }
  366. }
  367. }
  368. }