PC_OperatePanel.cs 13 KB

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