PC_OperatePanel.cs 13 KB

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